From e6a0049c0b9dc9c3ce54d961f6efd2d1bd91676c Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Thu, 18 Mar 2021 18:57:52 +0530 Subject: [PATCH] e2e: add getDaemonSetLabelSelector() to utils getDaemonSetLabelSelector returns labels of daemonset given name and namespace dynamically, needed since labels are not same for helm and non-helm deployments. Signed-off-by: Prasanna Kumar Kalever Signed-off-by: Rakshith R --- e2e/pod.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/e2e/pod.go b/e2e/pod.go index 2687e98b2..cfcd4e931 100644 --- a/e2e/pod.go +++ b/e2e/pod.go @@ -18,6 +18,23 @@ import ( e2elog "k8s.io/kubernetes/test/e2e/framework/log" ) +// getDaemonSetLabelSelector returns labels of daemonset given name and namespace dynamically, +// needed since labels are not same for helm and non-helm deployments. +func getDaemonSetLabelSelector(f *framework.Framework, ns, daemonSetName string) (string, error) { + ds, err := f.ClientSet.AppsV1().DaemonSets(ns).Get(context.TODO(), daemonSetName, metav1.GetOptions{}) + if err != nil { + e2elog.Logf("Error getting daemonsets with name %s in namespace %s", daemonSetName, ns) + return "", err + } + s, err := metav1.LabelSelectorAsSelector(ds.Spec.Selector) + if err != nil { + e2elog.Logf("Error parsing %s daemonset selector in namespace %s", daemonSetName, ns) + return "", err + } + e2elog.Logf("LabelSelector for %s daemonsets in namespace %s: %s", daemonSetName, ns, s.String()) + return s.String(), nil +} + func waitForDaemonSets(name, ns string, c kubernetes.Interface, t int) error { timeout := time.Duration(t) * time.Minute start := time.Now()