Skip to content

Commit 21c01f0

Browse files
mprahlopenshift-merge-robot
authored andcommitted
Create the cluster namespace when a hub is imported by a global hub
When syncPoliciesOnMulticlusterHub is true, it's indicating that the hub is imported by a global hub. The namespace must be created on the hub to sync policies from the global hub. The namespace also needs to be cleaned up when uninstalled, so the clean up pod is now enabled in this scenario too. Relates: https://issues.redhat.com/browse/ACM-7655 Signed-off-by: mprahl <[email protected]>
1 parent 5b33b43 commit 21c01f0

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

pkg/addon/policyframework/manifests/managedclusterchart/templates/cleanup_pod.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright Contributors to the Open Cluster Management project
22

3-
{{- if or (not .Values.onMulticlusterHub) (eq .Values.installMode "Hosted") }}
3+
{{- if or (not .Values.onMulticlusterHub) (eq .Values.installMode "Hosted") (.Values.args.syncPoliciesOnMulticlusterHub) }}
44
apiVersion: v1
55
kind: Pod
66
metadata:

pkg/addon/policyframework/manifests/managedclusterchart/templates/namespace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright Contributors to the Open Cluster Management project
22

3-
{{- if and (not .Values.onMulticlusterHub) (ne .Values.installMode "Hosted") }}
3+
{{- if or (and (not .Values.onMulticlusterHub) (ne .Values.installMode "Hosted")) (and .Values.onMulticlusterHub .Values.args.syncPoliciesOnMulticlusterHub) }}
44
apiVersion: v1
55
kind: Namespace
66
metadata:

test/e2e/case1_framework_deployment_test.go

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,6 @@ var _ = Describe("Test framework deployment", func() {
331331
cluster.clusterName,
332332
"policy.open-cluster-management.io/sync-policies-on-multicluster-hub=true",
333333
)
334-
DeferCleanup(
335-
Kubectl,
336-
"annotate",
337-
"ManagedCluster",
338-
cluster.clusterName,
339-
"policy.open-cluster-management.io/sync-policies-on-multicluster-hub-",
340-
)
341334

342335
// This is a hack to trigger a reconcile.
343336
Kubectl(
@@ -347,8 +340,11 @@ var _ = Describe("Test framework deployment", func() {
347340
"ManagedClusterAddOn",
348341
case1ManagedClusterAddOnName,
349342
"trigger-reconcile="+time.Now().Format(time.RFC3339),
343+
"--overwrite",
350344
)
351345

346+
By(logPrefix + "verifying that the spec sync is not disabled")
347+
352348
Eventually(func(g Gomega) {
353349
deploy = GetWithTimeout(
354350
cluster.clusterClient, gvrDeployment, case1DeploymentName, addonNamespace, true, 60,
@@ -365,6 +361,52 @@ var _ = Describe("Test framework deployment", func() {
365361
g.Expect(arg).ToNot(Equal("--disable-spec-sync=true"))
366362
}
367363
}, 60, 5).Should(Succeed())
364+
365+
By(logPrefix + "cleaning up")
366+
367+
Kubectl("annotate", "-n", cluster.clusterName, "-f", case1ManagedClusterAddOnCR, "policy-addon-pause=true")
368+
369+
// This is hacky but this sets the ManifestWork to orphan everything so that we can remove the
370+
// policy.open-cluster-management.io/sync-policies-on-multicluster-hub annotation and not have it delete
371+
// the cluster namespace. This will get reset to SelectivelyOrphan when the addon controller is reconciled
372+
// below.
373+
Eventually(func(g Gomega) {
374+
mw := GetWithTimeout(clientDynamic, gvrManifestWork, case1MWName, cluster.clusterName, true, 15)
375+
376+
err := unstructured.SetNestedField(mw.Object, "Orphan", "spec", "deleteOption", "propagationPolicy")
377+
g.Expect(err).ToNot(HaveOccurred())
378+
379+
_, err = cluster.clusterClient.Resource(gvrManifestWork).Namespace(cluster.clusterName).Update(
380+
context.TODO(), mw, metav1.UpdateOptions{},
381+
)
382+
g.Expect(err).ToNot(HaveOccurred())
383+
}, 30, 5).Should(Succeed())
384+
385+
Kubectl(
386+
"annotate",
387+
"ManagedCluster",
388+
cluster.clusterName,
389+
"policy.open-cluster-management.io/sync-policies-on-multicluster-hub-",
390+
)
391+
392+
Kubectl("annotate", "-n", cluster.clusterName, "-f", case1ManagedClusterAddOnCR, "policy-addon-pause-")
393+
394+
// Wait for the ManifestWork to be updated to not reference the cluster namespace.
395+
Eventually(func(g Gomega) {
396+
mw := GetWithTimeout(clientDynamic, gvrManifestWork, case1MWName, cluster.clusterName, true, 15)
397+
manifests, _, _ := unstructured.NestedSlice(mw.Object, "spec", "workload", "manifests")
398+
399+
for _, manifest := range manifests {
400+
g.Expect(manifest.(map[string]interface{})["kind"]).ToNot(Equal("Namespace"))
401+
}
402+
}, 30, 5).Should(Succeed())
403+
404+
By(logPrefix + "deleting the managedclusteraddon")
405+
Kubectl("delete", "-n", cluster.clusterName, "-f", case1ManagedClusterAddOnCR, "--timeout=90s")
406+
deploy = GetWithTimeout(
407+
cluster.clusterClient, gvrDeployment, case1DeploymentName, addonNamespace, false, 30,
408+
)
409+
Expect(deploy).To(BeNil())
368410
})
369411

370412
It("should use the onMulticlusterHub value set in the custom annotation", func() {

0 commit comments

Comments
 (0)