Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #68793: Fix DS tests to set their namespaces to empty node selectors #69912

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 31 additions & 1 deletion test/e2e/apps/daemon_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const (
daemonsetColorLabel = daemonsetLabelPrefix + "color"
)

// The annotation key scheduler.alpha.kubernetes.io/node-selector is for assigning
// node selectors labels to namespaces
var NamespaceNodeSelectors = []string{"scheduler.alpha.kubernetes.io/node-selector"}

// This test must be run in serial because it assumes the Daemon Set pods will
// always get scheduled. If we run other tests in parallel, this may not
// happen. In the future, running in parallel may work if we have an eviction
Expand Down Expand Up @@ -100,7 +104,13 @@ var _ = SIGDescribe("Daemon set [Serial]", func() {
ns = f.Namespace.Name

c = f.ClientSet
err := clearDaemonSetNodeLabels(c)

updatedNS, err := updateNamespaceAnnotations(c, ns)
Expect(err).NotTo(HaveOccurred())

ns = updatedNS.Name

err = clearDaemonSetNodeLabels(c)
Expect(err).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -495,6 +505,26 @@ func clearDaemonSetNodeLabels(c clientset.Interface) error {
return nil
}

// updateNamespaceAnnotations sets node selectors related annotations on tests namespaces to empty
func updateNamespaceAnnotations(c clientset.Interface, nsName string) (*v1.Namespace, error) {
nsClient := c.CoreV1().Namespaces()

ns, err := nsClient.Get(nsName, metav1.GetOptions{})
if err != nil {
return nil, err
}

if ns.Annotations == nil {
ns.Annotations = make(map[string]string)
}

for _, n := range NamespaceNodeSelectors {
ns.Annotations[n] = ""
}

return nsClient.Update(ns)
}

func setDaemonSetNodeLabels(c clientset.Interface, nodeName string, labels map[string]string) (*v1.Node, error) {
nodeClient := c.CoreV1().Nodes()
var newNode *v1.Node
Expand Down