@@ -16,14 +16,15 @@ import (
1616)
1717
1818const (
19- case2ManagedClusterAddOnName string = "config-policy-controller"
20- case2ManagedClusterAddOnCR string = "../resources/config_policy_addon_cr.yaml"
21- case2ClusterManagementAddOnCR string = "../resources/config_policy_clustermanagementaddon.yaml"
22- case2DeploymentName string = "config-policy-controller"
23- case2PodSelector string = "app=config-policy-controller"
24- case2OpenShiftClusterClaim string = "../resources/openshift_cluster_claim.yaml"
25- policyCrdName string = "policies.policy.open-cluster-management.io"
26- deletionOrphanAnnotationKey string = "addon.open-cluster-management.io/deletion-orphan"
19+ case2ManagedClusterAddOnName string = "config-policy-controller"
20+ case2ManagedClusterAddOnCR string = "../resources/config_policy_addon_cr.yaml"
21+ case2ManagedClusterCustomNsAddOnCR string = "../resources/config_policy_addon_custom_ns.yaml"
22+ case2ClusterManagementAddOnCR string = "../resources/config_policy_clustermanagementaddon.yaml"
23+ case2DeploymentName string = "config-policy-controller"
24+ case2PodSelector string = "app=config-policy-controller"
25+ case2OpenShiftClusterClaim string = "../resources/openshift_cluster_claim.yaml"
26+ policyCrdName string = "policies.policy.open-cluster-management.io"
27+ deletionOrphanAnnotationKey string = "addon.open-cluster-management.io/deletion-orphan"
2728)
2829
2930func verifyConfigPolicyDeployment (
@@ -369,7 +370,7 @@ var _ = Describe("Test config-policy-controller deployment", func() {
369370 By (logPrefix + "verifying that the metrics ServiceMonitor exists" )
370371 Eventually (func (g Gomega ) {
371372 sm , err := cluster .clusterClient .Resource (gvrServiceMonitor ).Namespace (addonNamespace ).Get (
372- context .TODO (), "ocm-config-policy-controller-" + addonNamespace + "- metrics" , metav1.GetOptions {},
373+ context .TODO (), "ocm-config-policy-controller-metrics" , metav1.GetOptions {},
373374 )
374375 g .Expect (err ).ToNot (HaveOccurred ())
375376
@@ -405,18 +406,12 @@ var _ = Describe("Test config-policy-controller deployment", func() {
405406 It ("should create a config-policy-controller deployment with metrics monitoring on OpenShift clusters" , func () {
406407 Expect (managedClusterList ).ToNot (BeEmpty ())
407408 hubClient := managedClusterList [0 ].clusterClient
409+ // A custom namespace is used to see if the openshift.io/cluster-monitoring label is set.
410+ addonNamespace := "e2e-test-config-policy-controller"
408411
409412 for i , cluster := range managedClusterList {
410413 logPrefix := cluster .clusterType + " " + cluster .clusterName + ": "
411414
412- By (logPrefix + "creating the openshift-monitoring namespace" )
413- Kubectl (
414- "create" ,
415- "namespace" ,
416- "openshift-monitoring" ,
417- fmt .Sprintf ("--kubeconfig=%s%d.kubeconfig" , kubeconfigFilename , i + 1 ),
418- )
419-
420415 By (logPrefix + "setting the product.open-cluster-management.io ClusterClaim to OpenShift" )
421416 Kubectl (
422417 "apply" ,
@@ -451,7 +446,7 @@ var _ = Describe("Test config-policy-controller deployment", func() {
451446 // The status doesn't need to be checked on the deployment because the deployment requires a cert that
452447 // is auto-generated by OpenShift, which won't be present.
453448 By (logPrefix + "deploying the default config-policy-controller managedclusteraddon" )
454- Kubectl ("apply" , "-n" , cluster .clusterName , "-f" , case2ManagedClusterAddOnCR )
449+ Kubectl ("apply" , "-n" , cluster .clusterName , "-f" , case2ManagedClusterCustomNsAddOnCR )
455450 deploy := GetWithTimeout (
456451 cluster .clusterClient , gvrDeployment , case2DeploymentName , addonNamespace , true , 30 ,
457452 )
@@ -464,8 +459,8 @@ var _ = Describe("Test config-policy-controller deployment", func() {
464459
465460 By (logPrefix + "verifying that the metrics ServiceMonitor exists" )
466461 Eventually (func (g Gomega ) {
467- sm , err := cluster .clusterClient .Resource (gvrServiceMonitor ).Namespace ("openshift-monitoring" ).Get (
468- context .TODO (), "ocm-config-policy-controller-" + addonNamespace + "- metrics" , metav1.GetOptions {},
462+ sm , err := cluster .clusterClient .Resource (gvrServiceMonitor ).Namespace (addonNamespace ).Get (
463+ context .TODO (), "ocm-config-policy-controller-metrics" , metav1.GetOptions {},
469464 )
470465 g .Expect (err ).ToNot (HaveOccurred ())
471466
@@ -488,6 +483,16 @@ var _ = Describe("Test config-policy-controller deployment", func() {
488483 g .Expect (port ["targetPort" ].(int64 )).To (Equal (int64 (8443 )))
489484 }, 120 , 3 ).Should (Succeed ())
490485
486+ By (logPrefix + "verifying that the addon namespace has the openshift.io/cluster-monitoring label set" )
487+ Eventually (func (g Gomega ) {
488+ ns , err := cluster .clusterClient .Resource (gvrNamespace ).Get (
489+ context .TODO (), addonNamespace , metav1.GetOptions {},
490+ )
491+ g .Expect (err ).ToNot (HaveOccurred ())
492+
493+ g .Expect (ns .GetLabels ()["openshift.io/cluster-monitoring" ]).To (Equal ("true" ))
494+ }, 30 , 3 ).Should (Succeed ())
495+
491496 By (logPrefix + "cleaning up" )
492497 Kubectl (
493498 "delete" ,
@@ -503,14 +508,6 @@ var _ = Describe("Test config-policy-controller deployment", func() {
503508 )
504509 Expect (deploy ).To (BeNil ())
505510
506- Kubectl (
507- "delete" ,
508- "namespace" ,
509- "openshift-monitoring" ,
510- fmt .Sprintf ("--kubeconfig=%s%d.kubeconfig" , kubeconfigFilename , i + 1 ),
511- "--timeout=15s" ,
512- )
513-
514511 By (logPrefix + "waiting for the ClusterClaim to not be in the ManagedCluster status" )
515512 Eventually (func (g Gomega ) {
516513 managedCluster , err := hubClient .Resource (gvrManagedCluster ).Get (
0 commit comments