-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix namespace target customization support with no defaults (#3052)
* Improve namespace target customization tests These tests now verify that the created namespace does bear expected labels and annotations. This commit also paves the way for additional tests with customizations over unconfigured namespace labels and annotations, which currently cause a panic. * Initialise options maps when empty This prevents panics when namespace labels or annotations are configured as target customizations over nonexistent defaults. * Use main branch of `rancher/fleet-test-data The required changes made in that repo have been merged.
- Loading branch information
Showing
5 changed files
with
200 additions
and
102 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
e2e/assets/single-cluster/ns-labels-target-customization-no-defaults.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
kind: GitRepo | ||
apiVersion: fleet.cattle.io/v1alpha1 | ||
metadata: | ||
name: test | ||
namespace: fleet-local | ||
spec: | ||
repo: https://github.com/rancher/fleet-test-data | ||
branch: master | ||
paths: | ||
- target-customization-namespace-labels/without-default-values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
package singlecluster_test | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/rancher/fleet/e2e/testenv" | ||
"github.com/rancher/fleet/e2e/testenv/kubectl" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Helm deploy options", func() { | ||
var ( | ||
asset string | ||
k kubectl.Command | ||
) | ||
BeforeEach(func() { | ||
k = env.Kubectl.Namespace(env.Namespace) | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
out, err := k.Apply("-f", testenv.AssetPath(asset)) | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
}) | ||
|
||
AfterEach(func() { | ||
out, err := k.Delete("-f", testenv.AssetPath(asset)) | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
}) | ||
|
||
Describe("namespace labels and annotations in target customizations", func() { | ||
When("namespaceLabels and namespaceAnnotations override existing root configuration", func() { | ||
BeforeEach(func() { | ||
asset = "single-cluster/ns-labels-target-customization.yaml" | ||
}) | ||
|
||
It("deploys the bundledeployment with the merged namespaceLabels and namespaceAnnotations", func() { | ||
By("setting the namespaces and annotations on the bundle deployment") | ||
out, err := k.Get("cluster", "local", "-o", "jsonpath={.status.namespace}") | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
|
||
clusterNS := strings.TrimSpace(out) | ||
clusterK := k.Namespace(clusterNS) | ||
|
||
var bundleDeploymentName string | ||
|
||
Eventually(func(g Gomega) { | ||
bundleDeploymentNames, _ := clusterK.Get( | ||
"bundledeployments", | ||
"-o", | ||
"jsonpath={.items[*].metadata.name}", | ||
) | ||
|
||
for _, bdName := range strings.Split(bundleDeploymentNames, " ") { | ||
if strings.HasPrefix(bdName, "test-target-customization-namespace-labels") { | ||
bundleDeploymentName = bdName | ||
break | ||
} | ||
} | ||
|
||
g.Expect(bundleDeploymentName).ToNot(BeEmpty()) | ||
}).Should(Succeed()) | ||
|
||
Eventually(func(g Gomega) { | ||
labels, err := clusterK.Get( | ||
"bundledeployments", | ||
bundleDeploymentName, | ||
"-o", | ||
"jsonpath={.spec.options.namespaceLabels}", | ||
) | ||
|
||
g.Expect(err).ToNot(HaveOccurred()) | ||
g.Expect(labels).To(Equal(`{"foo":"bar","this.is/a":"test"}`)) | ||
|
||
annot, err := clusterK.Get( | ||
"bundledeployments", | ||
bundleDeploymentName, | ||
"-o", | ||
"jsonpath={.spec.options.namespaceAnnotations}", | ||
) | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
g.Expect(annot).To(Equal(`{"foo":"bar","this.is/another":"test"}`)) | ||
}).Should(Succeed()) | ||
|
||
By("setting the namespaces and annotations on the created namespace") | ||
Eventually(func(g Gomega) { | ||
labels, err := k.Get("ns", "ns-1", "-o", "jsonpath={.metadata.labels}") | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
g.Expect(labels).To(Equal(`{"foo":"bar","kubernetes.io/metadata.name":"ns-1","this.is/a":"test"}`)) | ||
|
||
ann, err := k.Get("ns", "ns-1", "-o", "jsonpath={.metadata.annotations}") | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
g.Expect(ann).To(Equal(`{"foo":"bar","this.is/another":"test"}`)) | ||
}).Should(Succeed()) | ||
}) | ||
}) | ||
|
||
When("namespaceLabels and namespaceAnnotations override empty root configuration", func() { | ||
BeforeEach(func() { | ||
asset = "single-cluster/ns-labels-target-customization-no-defaults.yaml" | ||
}) | ||
|
||
It("deploys the bundledeployment with the merged namespaceLabels and namespaceAnnotations", func() { | ||
By("setting the namespaces and annotations on the bundle deployment") | ||
out, err := k.Get("cluster", "local", "-o", "jsonpath={.status.namespace}") | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
|
||
clusterNS := strings.TrimSpace(out) | ||
clusterK := k.Namespace(clusterNS) | ||
|
||
var bundleDeploymentName string | ||
|
||
Eventually(func(g Gomega) { | ||
bundleDeploymentNames, _ := clusterK.Get( | ||
"bundledeployments", | ||
"-o", | ||
"jsonpath={.items[*].metadata.name}", | ||
) | ||
|
||
for _, bdName := range strings.Split(bundleDeploymentNames, " ") { | ||
if strings.HasPrefix(bdName, "test-target-customization-namespace-labels") { | ||
bundleDeploymentName = bdName | ||
break | ||
} | ||
} | ||
|
||
g.Expect(bundleDeploymentName).ToNot(BeEmpty()) | ||
}).Should(Succeed()) | ||
|
||
Eventually(func(g Gomega) { | ||
labels, err := clusterK.Get( | ||
"bundledeployments", | ||
bundleDeploymentName, | ||
"-o", | ||
"jsonpath={.spec.options.namespaceLabels}", | ||
) | ||
|
||
g.Expect(err).ToNot(HaveOccurred()) | ||
g.Expect(labels).To(Equal(`{"this.is/a":"test"}`)) | ||
|
||
annot, err := clusterK.Get( | ||
"bundledeployments", | ||
bundleDeploymentName, | ||
"-o", | ||
"jsonpath={.spec.options.namespaceAnnotations}", | ||
) | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
g.Expect(annot).To(Equal(`{"this.is/another":"test"}`)) | ||
}).Should(Succeed()) | ||
|
||
By("setting the namespaces and annotations on the created namespace") | ||
Eventually(func(g Gomega) { | ||
labels, err := k.Get("ns", "no-defaults-ns-1", "-o", "jsonpath={.metadata.labels}") | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
g.Expect(labels).To(Equal(`{"kubernetes.io/metadata.name":"no-defaults-ns-1","this.is/a":"test"}`)) | ||
|
||
ann, err := k.Get("ns", "no-defaults-ns-1", "-o", "jsonpath={.metadata.annotations}") | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
g.Expect(ann).To(Equal(`{"this.is/another":"test"}`)) | ||
}).Should(Succeed()) | ||
}) | ||
}) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters