diff --git a/cmd/example/helloworld/main.go b/cmd/example/helloworld/main.go index 53fabf6ba..b933922a5 100644 --- a/cmd/example/helloworld/main.go +++ b/cmd/example/helloworld/main.go @@ -21,7 +21,6 @@ import ( "open-cluster-management.io/addon-framework/examples/helloworld_agent" "open-cluster-management.io/addon-framework/pkg/addonfactory" "open-cluster-management.io/addon-framework/pkg/addonmanager" - addonagent "open-cluster-management.io/addon-framework/pkg/agent" cmdfactory "open-cluster-management.io/addon-framework/pkg/cmd/factory" "open-cluster-management.io/addon-framework/pkg/utils" "open-cluster-management.io/addon-framework/pkg/version" @@ -109,7 +108,11 @@ func runController(ctx context.Context, kubeConfig *rest.Config) error { ), ). WithAgentRegistrationOption(registrationOption). - WithInstallStrategy(addonagent.InstallAllStrategy(helloworld.InstallationNamespace)). + WithAgentInstallNamespace( + utils.AgentInstallNamespaceFromDeploymentConfigFunc( + utils.NewAddOnDeploymentConfigGetter(addonClient), + ), + ). WithAgentHealthProber(helloworld.AgentHealthProber()). BuildTemplateAgentAddon() if err != nil { diff --git a/cmd/example/helloworld_helm/main.go b/cmd/example/helloworld_helm/main.go index 2e416adf6..099523226 100644 --- a/cmd/example/helloworld_helm/main.go +++ b/cmd/example/helloworld_helm/main.go @@ -115,12 +115,12 @@ func runController(ctx context.Context, kubeConfig *rest.Config) error { WithGetValuesFuncs( helloworld_helm.GetDefaultValues, addonfactory.GetAddOnDeploymentConfigValues( - addonfactory.NewAddOnDeploymentConfigGetter(addonClient), + utils.NewAddOnDeploymentConfigGetter(addonClient), addonfactory.ToAddOnNodePlacementValues, addonfactory.ToAddOnProxyConfigValues, ), addonfactory.GetAgentImageValues( - addonfactory.NewAddOnDeploymentConfigGetter(addonClient), + utils.NewAddOnDeploymentConfigGetter(addonClient), "global.imageOverrides.helloWorldHelm", helloworld.DefaultHelloWorldExampleImage, ), diff --git a/examples/deploy/addon/helloworld/kustomization.yaml b/examples/deploy/addon/helloworld/kustomization.yaml index 53f17d7fc..1b32ca87f 100644 --- a/examples/deploy/addon/helloworld/kustomization.yaml +++ b/examples/deploy/addon/helloworld/kustomization.yaml @@ -4,10 +4,12 @@ resources: - resources/cluster_role.yaml - resources/cluster_role_binding.yaml - resources/service_account.yaml +- resources/managed_clusterset_binding.yaml +- resources/placement.yaml +- resources/addon_deployment_config.yaml - resources/helloworld_clustermanagementaddon.yaml - resources/helloworld_controller.yaml - images: - name: quay.io/open-cluster-management/addon-examples newName: quay.io/open-cluster-management/addon-examples diff --git a/examples/deploy/addon/helloworld/resources/addon_deployment_config.yaml b/examples/deploy/addon/helloworld/resources/addon_deployment_config.yaml new file mode 100644 index 000000000..204518b39 --- /dev/null +++ b/examples/deploy/addon/helloworld/resources/addon_deployment_config.yaml @@ -0,0 +1,6 @@ +apiVersion: addon.open-cluster-management.io/v1alpha1 +kind: AddOnDeploymentConfig +metadata: + name: global +spec: + agentInstallNamespace: default diff --git a/examples/deploy/addon/helloworld/resources/helloworld_clustermanagementaddon.yaml b/examples/deploy/addon/helloworld/resources/helloworld_clustermanagementaddon.yaml index ba46bb733..77bf16d68 100644 --- a/examples/deploy/addon/helloworld/resources/helloworld_clustermanagementaddon.yaml +++ b/examples/deploy/addon/helloworld/resources/helloworld_clustermanagementaddon.yaml @@ -2,6 +2,8 @@ apiVersion: addon.open-cluster-management.io/v1alpha1 kind: ClusterManagementAddOn metadata: name: helloworld + annotations: + "addon.open-cluster-management.io/lifecycle": "addon-manager" spec: addOnMeta: displayName: helloworld @@ -9,3 +11,13 @@ spec: supportedConfigs: - group: addon.open-cluster-management.io resource: addondeploymentconfigs + installStrategy: + type: Placements + placements: + - name: global + namespace: open-cluster-management + configs: + - group: addon.open-cluster-management.io + resource: addondeploymentconfigs + name: global + namespace: open-cluster-management diff --git a/examples/deploy/addon/helloworld/resources/managed_clusterset_binding.yaml b/examples/deploy/addon/helloworld/resources/managed_clusterset_binding.yaml new file mode 100644 index 000000000..7b1ce9ca7 --- /dev/null +++ b/examples/deploy/addon/helloworld/resources/managed_clusterset_binding.yaml @@ -0,0 +1,6 @@ +apiVersion: cluster.open-cluster-management.io/v1beta2 +kind: ManagedClusterSetBinding +metadata: + name: global +spec: + clusterSet: global diff --git a/examples/deploy/addon/helloworld/resources/placement.yaml b/examples/deploy/addon/helloworld/resources/placement.yaml new file mode 100644 index 000000000..da500bac2 --- /dev/null +++ b/examples/deploy/addon/helloworld/resources/placement.yaml @@ -0,0 +1,10 @@ +apiVersion: cluster.open-cluster-management.io/v1beta1 +kind: Placement +metadata: + name: global +spec: + clusterSets: + - global + predicates: + - requiredClusterSelector: + labelSelector: {} diff --git a/examples/helloworld/helloworld.go b/examples/helloworld/helloworld.go index efcb53c80..7623b116f 100644 --- a/examples/helloworld/helloworld.go +++ b/examples/helloworld/helloworld.go @@ -30,7 +30,6 @@ func NewRegistrationOption(kubeConfig *rest.Config, addonName, agentName string) CSRConfigurations: agent.KubeClientSignerConfigurations(addonName, agentName), CSRApproveCheck: utils.DefaultCSRApprover(agentName), PermissionConfig: rbac.AddonRBAC(kubeConfig), - Namespace: InstallationNamespace, } } diff --git a/test/e2e/helloworld_helm_test.go b/test/e2e/helloworld_helm_test.go index c36d50e3a..d4f9a91d7 100644 --- a/test/e2e/helloworld_helm_test.go +++ b/test/e2e/helloworld_helm_test.go @@ -30,9 +30,7 @@ var _ = ginkgo.Describe("install/uninstall helloworld helm addons", func() { ObjectMeta: metav1.ObjectMeta{ Name: helloWorldHelmAddonName, }, - Spec: addonapiv1alpha1.ManagedClusterAddOnSpec{ - InstallNamespace: addonInstallNamespace, - }, + Spec: addonapiv1alpha1.ManagedClusterAddOnSpec{}, } ginkgo.BeforeEach(func() { @@ -135,7 +133,7 @@ var _ = ginkgo.Describe("install/uninstall helloworld helm addons", func() { if err == nil { errd := hubKubeClient.CoreV1().Namespaces().Delete(context.Background(), agentInstallNamespaceConfig, metav1.DeleteOptions{}) - if errd != nil { + if errd != nil && !errors.IsNotFound(errd) { return errd } return fmt.Errorf("ns is deleting, need re-check if namespace is not found") diff --git a/test/e2e/helloworld_test.go b/test/e2e/helloworld_test.go index 88a0f434f..429ae1b64 100644 --- a/test/e2e/helloworld_test.go +++ b/test/e2e/helloworld_test.go @@ -108,7 +108,7 @@ var _ = ginkgo.Describe("install/uninstall helloworld addons", func() { return err } - if cma.Annotations[addonapiv1alpha1.AddonLifecycleAnnotationKey] != addonapiv1alpha1.AddonLifecycleSelfManageAnnotationValue { + if cma.Annotations[addonapiv1alpha1.AddonLifecycleAnnotationKey] != addonapiv1alpha1.AddonLifecycleAddonManagerAnnotationValue { return fmt.Errorf("addon should have annotation, but get %v", cma.Annotations) } @@ -441,6 +441,7 @@ func prepareAddOnDeploymentConfig(namespace string) error { NodeSelector: nodeSelector, Tolerations: tolerations, }, + AgentInstallNamespace: addonInstallNamespace, }, }, metav1.CreateOptions{}, @@ -466,7 +467,8 @@ func prepareImageOverrideAddOnDeploymentConfig(namespace string) error { Namespace: namespace, }, Spec: addonapiv1alpha1.AddOnDeploymentConfigSpec{ - Registries: registries, + Registries: registries, + AgentInstallNamespace: addonInstallNamespace, }, }, metav1.CreateOptions{}, @@ -491,7 +493,8 @@ func prepareProxyConfigAddOnDeploymentConfig(namespace string) error { Namespace: namespace, }, Spec: addonapiv1alpha1.AddOnDeploymentConfigSpec{ - ProxyConfig: proxyConfig, + ProxyConfig: proxyConfig, + AgentInstallNamespace: addonInstallNamespace, }, }, metav1.CreateOptions{},