Skip to content

Commit

Permalink
Use install strategy in addon example and e2e
Browse files Browse the repository at this point in the history
Signed-off-by: Jian Qiu <[email protected]>
  • Loading branch information
qiujian16 committed Mar 21, 2024
1 parent e8778a9 commit aa091af
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 13 deletions.
7 changes: 5 additions & 2 deletions cmd/example/helloworld/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/example/helloworld_helm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
4 changes: 3 additions & 1 deletion examples/deploy/addon/helloworld/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: addon.open-cluster-management.io/v1alpha1
kind: AddOnDeploymentConfig
metadata:
name: global
spec:
agentInstallNamespace: default
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@ 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
description: "helloworld is an example addon created by go template"
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: cluster.open-cluster-management.io/v1beta2
kind: ManagedClusterSetBinding
metadata:
name: global
spec:
clusterSet: global
10 changes: 10 additions & 0 deletions examples/deploy/addon/helloworld/resources/placement.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: cluster.open-cluster-management.io/v1beta1
kind: Placement
metadata:
name: global
spec:
clusterSets:
- global
predicates:
- requiredClusterSelector:
labelSelector: {}
1 change: 0 additions & 1 deletion examples/helloworld/helloworld.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
6 changes: 2 additions & 4 deletions test/e2e/helloworld_helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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")
Expand Down
9 changes: 6 additions & 3 deletions test/e2e/helloworld_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -441,6 +441,7 @@ func prepareAddOnDeploymentConfig(namespace string) error {
NodeSelector: nodeSelector,
Tolerations: tolerations,
},
AgentInstallNamespace: addonInstallNamespace,
},
},
metav1.CreateOptions{},
Expand All @@ -466,7 +467,8 @@ func prepareImageOverrideAddOnDeploymentConfig(namespace string) error {
Namespace: namespace,
},
Spec: addonapiv1alpha1.AddOnDeploymentConfigSpec{
Registries: registries,
Registries: registries,
AgentInstallNamespace: addonInstallNamespace,
},
},
metav1.CreateOptions{},
Expand All @@ -491,7 +493,8 @@ func prepareProxyConfigAddOnDeploymentConfig(namespace string) error {
Namespace: namespace,
},
Spec: addonapiv1alpha1.AddOnDeploymentConfigSpec{
ProxyConfig: proxyConfig,
ProxyConfig: proxyConfig,
AgentInstallNamespace: addonInstallNamespace,
},
},
metav1.CreateOptions{},
Expand Down

0 comments on commit aa091af

Please sign in to comment.