@@ -28,6 +28,7 @@ import (
28
28
const (
29
29
nodePlacementDeploymentConfigName = "node-placement-deploy-config"
30
30
imageOverrideDeploymentConfigName = "image-override-deploy-config"
31
+ namespaceOverrideConfigName = "namespace-override-config"
31
32
originalImageValue = "quay.io/open-cluster-management/addon-examples:latest"
32
33
overrideImageValue = "quay.io/ocm/addon-examples:latest"
33
34
customSignerName = "example.com/signer-name"
@@ -476,6 +477,55 @@ var _ = ginkgo.Describe("Enable addon management feature gate", ginkgo.Ordered,
476
477
477
478
})
478
479
480
+ ginkgo .It ("Template type addon should be configured by addon deployment config for namespace" , func () {
481
+ ginkgo .By ("Prepare a AddOnDeploymentConfig for namespace config" )
482
+ overrideNamespace := & corev1.Namespace {
483
+ ObjectMeta : metav1.ObjectMeta {
484
+ Name : "another-addon-namespace" ,
485
+ },
486
+ }
487
+ _ , err := t .SpokeKubeClient .CoreV1 ().Namespaces ().Create (context .TODO (), overrideNamespace , metav1.CreateOptions {})
488
+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
489
+ gomega .Eventually (func () error {
490
+ return prepareInstallNamespace (clusterName , overrideNamespace .Name )
491
+ }, eventuallyTimeout , eventuallyInterval ).ShouldNot (gomega .HaveOccurred ())
492
+
493
+ ginkgo .By ("Add the configs to ManagedClusterAddOn" )
494
+ gomega .Eventually (func () error {
495
+ addon , err := t .AddOnClinet .AddonV1alpha1 ().ManagedClusterAddOns (clusterName ).Get (
496
+ context .Background (), addOnName , metav1.GetOptions {})
497
+ if err != nil {
498
+ return err
499
+ }
500
+ newAddon := addon .DeepCopy ()
501
+ newAddon .Spec .Configs = []addonapiv1alpha1.AddOnConfig {
502
+ {
503
+ ConfigGroupResource : addonapiv1alpha1.ConfigGroupResource {
504
+ Group : "addon.open-cluster-management.io" ,
505
+ Resource : "addondeploymentconfigs" ,
506
+ },
507
+ ConfigReferent : addonapiv1alpha1.ConfigReferent {
508
+ Namespace : clusterName ,
509
+ Name : namespaceOverrideConfigName ,
510
+ },
511
+ },
512
+ }
513
+ _ , err = t .AddOnClinet .AddonV1alpha1 ().ManagedClusterAddOns (clusterName ).Update (
514
+ context .Background (), newAddon , metav1.UpdateOptions {})
515
+ if err != nil {
516
+ return err
517
+ }
518
+ return nil
519
+ }, eventuallyTimeout , eventuallyInterval ).ShouldNot (gomega .HaveOccurred ())
520
+
521
+ ginkgo .By ("Make sure addon is configured" )
522
+ gomega .Eventually (func () error {
523
+ _ , err := t .SpokeKubeClient .AppsV1 ().Deployments (overrideNamespace .Name ).Get (
524
+ context .Background (), "hello-template-agent" , metav1.GetOptions {})
525
+ return err
526
+ }, eventuallyTimeout , eventuallyInterval ).ShouldNot (gomega .HaveOccurred ())
527
+ })
528
+
479
529
ginkgo .It ("Template type addon's image should be overrode by cluster annotation" , func () {
480
530
ginkgo .By ("Prepare cluster annotation for addon image override config" )
481
531
overrideRegistries := addonapiv1alpha1.AddOnDeploymentConfigSpec {
@@ -564,6 +614,32 @@ var _ = ginkgo.Describe("Enable addon management feature gate", ginkgo.Ordered,
564
614
565
615
})
566
616
617
+ func prepareInstallNamespace (namespace , installNamespace string ) error {
618
+ _ , err := t .AddOnClinet .AddonV1alpha1 ().AddOnDeploymentConfigs (namespace ).Get (
619
+ context .Background (), namespaceOverrideConfigName , metav1.GetOptions {})
620
+ if errors .IsNotFound (err ) {
621
+ if _ , err := t .AddOnClinet .AddonV1alpha1 ().AddOnDeploymentConfigs (namespace ).Create (
622
+ context .Background (),
623
+ & addonapiv1alpha1.AddOnDeploymentConfig {
624
+ ObjectMeta : metav1.ObjectMeta {
625
+ Name : namespaceOverrideConfigName ,
626
+ Namespace : namespace ,
627
+ },
628
+ Spec : addonapiv1alpha1.AddOnDeploymentConfigSpec {
629
+ AgentInstallNamespace : installNamespace ,
630
+ },
631
+ },
632
+ metav1.CreateOptions {},
633
+ ); err != nil {
634
+ return err
635
+ }
636
+
637
+ return nil
638
+ }
639
+
640
+ return err
641
+ }
642
+
567
643
func prepareImageOverrideAddOnDeploymentConfig (namespace , installNamespace string ) error {
568
644
_ , err := t .AddOnClinet .AddonV1alpha1 ().AddOnDeploymentConfigs (namespace ).Get (
569
645
context .Background (), imageOverrideDeploymentConfigName , metav1.GetOptions {})
@@ -588,11 +664,7 @@ func prepareImageOverrideAddOnDeploymentConfig(namespace, installNamespace strin
588
664
return nil
589
665
}
590
666
591
- if err != nil {
592
- return err
593
- }
594
-
595
- return nil
667
+ return err
596
668
}
597
669
598
670
func prepareNodePlacementAddOnDeploymentConfig (namespace , installNamespace string ) error {
@@ -622,11 +694,7 @@ func prepareNodePlacementAddOnDeploymentConfig(namespace, installNamespace strin
622
694
return nil
623
695
}
624
696
625
- if err != nil {
626
- return err
627
- }
628
-
629
- return nil
697
+ return err
630
698
}
631
699
632
700
func copySignerSecret (ctx context.Context , kubeClient kubernetes.Interface , srcNs , srcName , dstNs , dstName string ) error {
0 commit comments