Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update addon template examples #192

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,23 @@ deploy-helloworld-template: ensure-kustomize
$(KUBECTL) create namespace $(MANAGED_CLUSTER_NAME) --dry-run=client -o yaml | $(KUBECTL) apply -f -
cp examples/deploy/addon/helloworld-template/kustomization.yaml examples/deploy/addon/helloworld-template/kustomization.yaml.tmp
cd examples/deploy/addon/helloworld-template && ../../../../$(KUSTOMIZE) edit set image quay.io/open-cluster-management/addon-examples=$(EXAMPLE_IMAGE_NAME)
$(KUSTOMIZE) build examples/deploy/addon/helloworld-template | $(KUBECTL) apply -f -
$(KUSTOMIZE) build examples/deploy/addon/helloworld-template | sed -e "s,cluster1,$(MANAGED_CLUSTER_NAME)," | $(KUBECTL) apply -f -
mv examples/deploy/addon/helloworld-template/kustomization.yaml.tmp examples/deploy/addon/helloworld-template/kustomization.yaml

deploy-kubernetes-dashboard: ensure-kustomize
$(KUBECTL) create namespace $(MANAGED_CLUSTER_NAME) --dry-run=client -o yaml | $(KUBECTL) apply -f -
cp examples/deploy/addon/kubernetes-dashboard/kustomization.yaml examples/deploy/addon/kubernetes-dashboard/kustomization.yaml.tmp
cd examples/deploy/addon/kubernetes-dashboard && ../../../../$(KUSTOMIZE) edit set image quay.io/open-cluster-management/addon-examples=$(EXAMPLE_IMAGE_NAME)
$(KUSTOMIZE) build examples/deploy/addon/kubernetes-dashboard | sed -e "s,cluster1,$(MANAGED_CLUSTER_NAME)," | $(KUBECTL) apply -f -
mv examples/deploy/addon/kubernetes-dashboard/kustomization.yaml.tmp examples/deploy/addon/kubernetes-dashboard/kustomization.yaml

undeploy-addon:
$(KUBECTL) delete -f examples/deploy/addon/helloworld-hosted/resources/helloworld_hosted_clustermanagementaddon.yaml --ignore-not-found
$(KUBECTL) delete -f examples/deploy/addon/helloworld-helm/resources/helloworld_helm_clustermanagementaddon.yaml --ignore-not-found
$(KUBECTL) delete -f examples/deploy/addon/helloworld/resources/helloworld_clustermanagementaddon.yaml --ignore-not-found
$(KUBECTL) delete -f examples/deploy/addon/busybox/resources/busybox_clustermanagementaddon.yaml --ignore-not-found
$(KUBECTL) delete -f examples/deploy/addon/helloworld-template/resources/cluster_management_addon.yaml --ignore-not-found
$(KUBECTL) delete -f examples/deploy/addon/kubernetes-dashboard/resources/cluster_management_addon.yaml --ignore-not-found

undeploy-busybox: ensure-kustomize
$(KUSTOMIZE) build examples/deploy/addon/busybox | $(KUBECTL) delete --ignore-not-found -f -
Expand All @@ -108,6 +117,12 @@ undeploy-helloworld-helm: ensure-kustomize
undeploy-helloworld-hosted: ensure-kustomize
$(KUSTOMIZE) build examples/deploy/addon/helloworld-hosted | $(KUBECTL) delete --ignore-not-found -f -

undeploy-helloworld-template: ensure-kustomize
$(KUSTOMIZE) build examples/deploy/addon/helloworld-template | $(KUBECTL) delete --ignore-not-found -f -

undeploy-kubernetes-dashboard: ensure-kustomize
$(KUSTOMIZE) build examples/deploy/addon/kubernetes-dashboard | $(KUBECTL) delete --ignore-not-found -f -

build-e2e:
go test -c ./test/e2e

Expand Down
70 changes: 65 additions & 5 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@

We have several AddOn examples for user to understand how Addon works and how to develop an AddOn.

The [helloworld example](helloworld) is implemented using Go templates, and the [helloworld_helm example](helloworld_helm) is implemented using Helm Chart.
- the [helloworld example](helloworld) is implemented using Go templates
- the [helloworld_helm example](helloworld_helm) is implemented using Helm Chart.
- the [helloworld_hosted example](helloworld_hosted) is implemented using Go templateds, and support running the agent
deployment on a hosting cluster cluster.
- the [helloworld-template example](deplpy/addon/helloworld-template) is implemented using the AddOnTemplate API, it
is managed by the global addon-manager, so there is no dedicated addon-manager pod running on the hub cluster for it.
- the [kubernetes-dashboard](deplpy/addon/kubernetes-dashboard) is another addon implemented using the AddOnTemplate API
to install [a kubernetes dashboard](https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/)
for a managed cluster.

You can get more details in the [docs](../docs).

Expand Down Expand Up @@ -40,26 +48,75 @@ And then deploy the example AddOns controller on hub cluster.
```sh
make deploy-helloworld
make deploy-helloworld-helm
make deploy-helloworld-hosted
```

The helloworld AddOn controller will create one `ManagedClusterAddOn` for each managed cluster automatically to install the helloworld agent on the managed cluster.
**helloworld addon**

After a successful deployment, check on the managed cluster and see the helloworld AddOn agent has been deployed from the hub cluster.
The helloworld AddOn controller will create one `ManagedClusterAddOn` for each managed cluster automatically to install
the helloworld agent on the managed cluster.

After a successful deployment, check on the managed cluster and see the helloworld AddOn agent has been deployed from
the hub cluster.
```sh
kubectl --kubeconfig </path/to/managed_cluster/kubeconfig> -n default get pods
NAME READY STATUS RESTARTS AGE
helloworld-agent-b99d47f76-v2j6h 1/1 Running 0 53s
```

**helloworld_helm addon**

The helloworld_helm AddOn controller cannot create `ManagedClusterAddOn` automatically.

We can create a `ManagedClusterAddOn` in the managedCluster namespace on the Hub cluster to enable the installation of the AddOn on the managed cluster.
We can create a `ManagedClusterAddOn` in the managedCluster namespace on the Hub cluster to enable the installation of
the AddOn on the managed cluster.
```sh
kubectl apply -f examples/deploy/addon-cr/helloworld_helm_addon_cr.yaml
export MANAGED_CLUSTER_NAME=<managed-cluster-name> && \
sed -e "s,cluster1,$MANAGED_CLUSTER_NAME," examples/deploy/addon-cr/helloworld_helm_addon_cr.yaml | \
kubectl apply -f -
```

We can check the helloworld_helm AddOn agent is deployed in the `installNamespace` on the managed cluster.

**helloworld_hosted addon**

The helloworld_hosted AddOn controller also cannot create `ManagedClusterAddOn` automatically.

We can create a `ManagedClusterAddOn` in the managedCluster namespace on the Hub cluster to enable the installation of
the AddOn on the managed cluster.

Note: when installing the addon in Hosted mode, the klusterlet installation mode of the managed cluster should also be
in Hosted mode. here we should specify the HOSTING_CLUSTER_NAME, it should be a managed cluster of the hub and the same
hosting cluster of the klustelet.

```sh
export MANAGED_CLUSTER_NAME=<managed-cluster-name> && \
export HOSTING_CLUSTER_NAME=<hosting-cluster-name> && \
sed -e "s,cluster1,$MANAGED_CLUSTER_NAME," -e "s,hosting1,$HOSTING_CLUSTER_NAME," examples/deploy/addon-cr/helloworld_hosted_addon_cr.yaml | \
kubectl apply -f -
```

Then create a `helloworldhosted-managed-kubeconfig` secret containing the kubeconfig of the managed cluster in the
`installNamespace` on the hosting cluster:

```sh
oc create secret generic helloworldhosted-managed-kubeconfig -n <installNamespace> --from-file=kubeconfig=<managed-cluster-kubeconfig-file>
```

We can check the helloworld_hosted AddOn agent is deployed in the `installNamespace` on the hosting cluster.

**helloworld_template addon**

```sh
MANAGED_CLUSTER_NAME=<managed-cluster-name> make deploy-helloworld-template
```

**kubernetes-dashboard addon**

```sh
MANAGED_CLUSTER_NAME=<managed-cluster-name> make deploy-kubernetes-dashboard
```

## Configure the example add-ons

The helloworld add-on supports configuring the nodeSelector and tolerations for its agent with `AddOnDeploymentConfig` and the helloworld_helm add-on supports configuring image and imagePullPolicy for its agent with `ConfigMap` and also supports configuring node selector and tolerations for its agent.
Expand Down Expand Up @@ -123,6 +180,9 @@ Undeploy example AddOn controllers from hub cluster after all managedClusterAddo
```sh
make undeploy-helloworld
make undeploy-helloworld-helm
make undeploy-helloworld-hosted
make undeploy-helloworld-template
make undeploy-kubernetes-dashboard
```

Remove the AddOn CR from hub cluster. It will undeploy the AddOn agent from the managed cluster as well.
Expand Down
9 changes: 9 additions & 0 deletions examples/deploy/addon-cr/helloworld_hosted_addon_cr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: addon.open-cluster-management.io/v1alpha1
kind: ManagedClusterAddOn
metadata:
name: helloworldhosted
namespace: cluster1
annotations:
addon.open-cluster-management.io/hosting-cluster-name: hosting1
spec:
installNamespace: open-cluster-management-agent-addon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: hub
namespace: cluster1

resources:
- resources/addon_deployment_config.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: addon.open-cluster-management.io/v1alpha1
kind: AddOnDeploymentConfig
metadata:
name: hello-template
namespace: hub
namespace: cluster1
spec:
customizedVariables:
- name: LOG_LEVEL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ spec:
metadata:
name: hello-template-agent
namespace: open-cluster-management-agent-addon
annotations:
"addon.open-cluster-management.io/deletion-orphan": ""
labels:
app: hello-template-agent
spec:
Expand Down Expand Up @@ -60,33 +58,6 @@ spec:
- kind: ServiceAccount
name: hello-template-agent-sa
namespace: open-cluster-management-agent-addon
- kind: Job
apiVersion: batch/v1
metadata:
name: hello-template-cleanup-configmap
namespace: open-cluster-management-agent-addon
annotations:
"addon.open-cluster-management.io/addon-pre-delete": ""
spec:
manualSelector: true
selector:
matchLabels:
job: hello-template-cleanup-configmap
template:
metadata:
labels:
job: hello-template-cleanup-configmap
spec:
serviceAccountName: hello-template-agent-sa
restartPolicy: Never
containers:
- name: hello-template-agent
image: quay.io/open-cluster-management/addon-examples
imagePullPolicy: IfNotPresent
args:
- "/helloworld_helm"
- "cleanup"
- "--addon-namespace=open-cluster-management-agent-addon"
registration:
# kubeClient or custom signer, if kubeClient, user and group is in a certain format.
# user is "system:open-cluster-management:cluster:{clusterName}:addon:{addonName}:agent:{agentName}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ spec:
resource: addondeploymentconfigs
defaultConfig:
name: hello-template
namespace: hub
namespace: cluster1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ apiVersion: addon.open-cluster-management.io/v1alpha1
kind: ManagedClusterAddOn
metadata:
name: hello-template
namespace: hub
namespace: cluster1
spec:
installNamespace: open-cluster-management-agent-addon
18 changes: 18 additions & 0 deletions examples/deploy/addon/kubernetes-dashboard/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: cluster1

resources:
- resources/addon_template.yaml
- resources/cluster_management_addon.yaml
- resources/managed_cluster_addon.yaml


images:
- name: kubernetesui/dashboard
newName: kubernetesui/dashboard
newTag: v2.7.0
- name: kubernetesui/metrics-scraper
newName: kubernetesui/metrics-scraper
newTag: v1.0.8
Loading
Loading