Skip to content

Commit f7279ec

Browse files
authored
Add the informer for getting a Pod by the node name (#1903)
1 parent 149ab80 commit f7279ec

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

controllers/cluster_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ func (r *FoundationDBClusterReconciler) SetupWithManager(mgr ctrl.Manager, maxCo
252252
if err != nil {
253253
return err
254254
}
255+
255256
labelSelectorPredicate, err := predicate.LabelSelectorPredicate(selector)
256257
if err != nil {
257258
return err

kubectl-fdb/cmd/cordon.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ func cordonNode(cmd *cobra.Command, kubeClient client.Client, inputClusterName s
182182
if len(errors) > 0 {
183183
return fmt.Errorf("following operation failed, please check and retry: \n, %s", errors)
184184
}
185+
185186
return nil
186187
}
187188

@@ -211,6 +212,7 @@ func fetchPods(kubeClient client.Client, clusterName string, namespace string, n
211212
if err != nil {
212213
return pods, fmt.Errorf("unable to fetch pods. Error: %w", err)
213214
}
215+
214216
return pods, nil
215217
}
216218

kubectl-fdb/cmd/k8s_client.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ func getKubeClient(ctx context.Context, o *fdbBOptions) (client.Client, error) {
8686
return nil, err
8787
}
8888

89+
// Setup index field to allow access to the node name more efficiently. The indexer must be created before the
90+
// informer is started.
91+
err = internalCache.IndexField(ctx, &corev1.Pod{}, "spec.nodeName", func(object client.Object) []string {
92+
return []string{object.(*corev1.Pod).Spec.NodeName}
93+
})
94+
95+
if err != nil {
96+
return nil, err
97+
}
98+
8999
// Make sure the internal cache is started.
90100
go func() {
91101
_ = internalCache.Start(ctx)

0 commit comments

Comments
 (0)