Skip to content

Commit

Permalink
modify helloworld addon
Browse files Browse the repository at this point in the history
Signed-off-by: haoqing0110 <[email protected]>
  • Loading branch information
haoqing0110 committed Mar 21, 2024
1 parent 7caafd5 commit 0cd8cd4
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 12 deletions.
6 changes: 6 additions & 0 deletions cmd/example/helloworld/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ func runController(ctx context.Context, kubeConfig *rest.Config) error {
),
).
WithAgentRegistrationOption(registrationOption).
WithAgentInstallNamespace(
// Set agent install namespace from addon deployment config if it exists
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apiVersion: addon.open-cluster-management.io/v1alpha1
kind: ClusterManagementAddOn
metadata:
name: helloworldhelm
annotations:
addon.open-cluster-management.io/lifecycle: addon-manager
spec:
addOnMeta:
displayName: helloworldhelm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apiVersion: addon.open-cluster-management.io/v1alpha1
kind: ClusterManagementAddOn
metadata:
name: helloworldhosted
annotations:
addon.open-cluster-management.io/lifecycle: addon-manager
spec:
addOnMeta:
displayName: helloworldhosted
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: default
configs:
- group: addon.open-cluster-management.io
resource: addondeploymentconfigs
name: global
namespace: default
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: cluster.open-cluster-management.io/v1beta2
kind: ManagedClusterSetBinding
metadata:
name: global
namespace: default
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
10 changes: 5 additions & 5 deletions test/e2e/helloworld_helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ var _ = ginkgo.Describe("install/uninstall helloworld helm addons", func() {
})

ginkgo.It("addon should be available", func() {
ginkgo.By("Make sure cma annotation is not added since no install strategy defined")
ginkgo.By("Make sure cma annotation is added since no install strategy defined")
gomega.Eventually(func() error {
cma, err := hubAddOnClient.AddonV1alpha1().ClusterManagementAddOns().Get(context.Background(), helloWorldHelmAddonName, metav1.GetOptions{})
if err != nil {
return err
}

if _, exist := cma.Annotations[addonapiv1alpha1.AddonLifecycleAnnotationKey]; exist {
return fmt.Errorf("addon should not have annotation, but get %v", cma.Annotations)
if cma.Annotations[addonapiv1alpha1.AddonLifecycleAnnotationKey] != addonapiv1alpha1.AddonLifecycleAddonManagerAnnotationValue {
return fmt.Errorf("addon should have annotation, but get %v", cma.Annotations)
}

return nil
Expand Down Expand Up @@ -338,7 +338,7 @@ var _ = ginkgo.Describe("install/uninstall helloworld helm addons", func() {

ginkgo.By("Make sure addon is configured")
gomega.Eventually(func() error {
agentDeploy, err := hubKubeClient.AppsV1().Deployments(addonInstallNamespace).Get(context.Background(), "helloworldhelm-agent", metav1.GetOptions{})
agentDeploy, err := hubKubeClient.AppsV1().Deployments(metav1.NamespaceDefault).Get(context.Background(), "helloworldhelm-agent", metav1.GetOptions{})
if err != nil {
return err
}
Expand Down Expand Up @@ -581,7 +581,7 @@ var _ = ginkgo.Describe("install/uninstall helloworld helm addons", func() {

ginkgo.By("Make sure addon is configured")
gomega.Eventually(func() error {
agentDeploy, err := hubKubeClient.AppsV1().Deployments(addonInstallNamespace).Get(
agentDeploy, err := hubKubeClient.AppsV1().Deployments(metav1.NamespaceDefault).Get(
context.Background(), "helloworldhelm-agent", metav1.GetOptions{})
if err != nil {
return err
Expand Down
8 changes: 5 additions & 3 deletions test/e2e/helloworld_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ var _ = ginkgo.Describe("install/uninstall helloworld addons", func() {
})

ginkgo.It("addon should be worked", func() {
ginkgo.By("Make sure cma annotation managed by self is added")
ginkgo.By("Make sure cma annotation managed by addon-manager is added")
gomega.Eventually(func() error {
cma, err := hubAddOnClient.AddonV1alpha1().ClusterManagementAddOns().Get(context.Background(), addonName, metav1.GetOptions{})
if err != nil {
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: metav1.NamespaceDefault,
},
},
metav1.CreateOptions{},
Expand Down Expand Up @@ -491,7 +492,8 @@ func prepareProxyConfigAddOnDeploymentConfig(namespace string) error {
Namespace: namespace,
},
Spec: addonapiv1alpha1.AddOnDeploymentConfigSpec{
ProxyConfig: proxyConfig,
ProxyConfig: proxyConfig,
AgentInstallNamespace: metav1.NamespaceDefault,
},
},
metav1.CreateOptions{},
Expand Down

0 comments on commit 0cd8cd4

Please sign in to comment.