Skip to content

Commit

Permalink
fix label selector issue
Browse files Browse the repository at this point in the history
  • Loading branch information
DexterYan committed Nov 6, 2024
1 parent 147fb0a commit c80a99f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/supportbundle/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func runRemoteHostCollectors(ctx context.Context, hostCollectors []*troubleshoot

klog.V(2).Infof("Created Remote Host Collector Daemonset %s", ds.Name)
pods, err := clientset.CoreV1().Pods(ds.Namespace).List(ctx, metav1.ListOptions{
LabelSelector: selectorLabelKey + "=" + selectorLabelValue,
LabelSelector: selectorLabelKey + "=" + ds.Name,
TimeoutSeconds: new(int64),
Limit: 0,
})
Expand Down Expand Up @@ -489,11 +489,12 @@ func createHostCollectorsSpec(hostCollectors []*troubleshootv1beta2.HostCollect)
}

func createHostCollectorDS(ctx context.Context, clientset kubernetes.Interface, labels map[string]string) (*appsv1.DaemonSet, error) {
dsName := names.SimpleNameGenerator.GenerateName("remote-host-collector" + "-")
ns := "default"
imageName := "replicated/troubleshoot:latest"
imagePullPolicy := corev1.PullAlways

labels[selectorLabelKey] = selectorLabelValue
labels[selectorLabelKey] = dsName

podSpec := corev1.PodSpec{
HostNetwork: true,
Expand Down Expand Up @@ -531,7 +532,7 @@ func createHostCollectorDS(ctx context.Context, clientset kubernetes.Interface,

ds := &appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Name: names.SimpleNameGenerator.GenerateName("remote-host-collector" + "-"),
Name: dsName,
Namespace: ns,
Labels: labels,
},
Expand All @@ -542,7 +543,7 @@ func createHostCollectorDS(ctx context.Context, clientset kubernetes.Interface,
{
Key: selectorLabelKey,
Operator: "In",
Values: []string{selectorLabelValue},
Values: []string{dsName},
},
},
},
Expand All @@ -556,6 +557,7 @@ func createHostCollectorDS(ctx context.Context, clientset kubernetes.Interface,
}

createdDS, err := clientset.AppsV1().DaemonSets(ns).Create(ctx, ds, metav1.CreateOptions{})

if err != nil {
return nil, errors.Wrap(err, "failed to create Remote Host Collector Pod")
}
Expand Down

0 comments on commit c80a99f

Please sign in to comment.