diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 924d6f090..882ffaf4f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,6 +16,12 @@ repos: language: system files: "^docs/" pass_filenames: false + - id: examples-sync + name: examples-sync + entry: make examples.sync + language: system + files: "^hack/examples/" + pass_filenames: false - repo: https://github.com/tekwizely/pre-commit-golang rev: v1.0.0-rc.1 hooks: @@ -102,7 +108,7 @@ repos: name: License headers - YAML and Makefiles stages: [commit] files: (^Makefile|\.(ya?ml|mk))$ - exclude: ^pkg/handlers/.+/embedded/.+\.ya?ml$ + exclude: ^(pkg/handlers/.+/embedded|examples)/.+\.ya?ml$ args: - --license-filepath - hack/license-header.txt diff --git a/README.md b/README.md index 6af3335e3..b94323c0a 100644 --- a/README.md +++ b/README.md @@ -26,45 +26,61 @@ make SKIP_BUILD=true dev.run-on-kind To create the ClusterClass and it's Templates with this runtime extension enabled, run: ```shell -kubectl apply --server-side -f examples/capi-quick-start/capd-cluster-class.yaml +kubectl apply --server-side -f examples/capi-quick-start/docker-cluster-class.yaml +``` + +If creating an AWS cluster using the example files, you will also need to create a secret with your AWS credentials: + +```shell +kubectl apply --server-side -f - < capd-kubeconfig +clusterctl get kubeconfig docker-quick-start > docker-kubeconfig ``` If you are not on Linux, you will also need to fix the generated kubeconfig's `server`, run: ```shell -kubectl config set-cluster capd-quick-start \ - --kubeconfig capd-kubeconfig \ - --server=https://$(docker port capd-quick-start-lb 6443/tcp) +kubectl config set-cluster docker-quick-start \ + --kubeconfig docker-kubeconfig \ + --server=https://$(docker port docker-quick-start-lb 6443/tcp) ``` Wait until all nodes are ready (this indicates that CNI has been deployed successfully): ```shell -kubectl --kubeconfig capd-kubeconfig wait nodes --all --for=condition=Ready --timeout=5m +kubectl --kubeconfig docker-kubeconfig wait nodes --all --for=condition=Ready --timeout=5m ``` Show that Calico is running successfully on the workload cluster: ```shell -kubectl --kubeconfig capd-kubeconfig get daemonsets -n calico-system +kubectl --kubeconfig docker-kubeconfig get daemonsets -n calico-system ``` Deploy kube-vip to provide service load-balancer: @@ -78,29 +94,29 @@ kubectl create configmap \ --namespace kube-system kubevip \ --from-literal "range-global=${kind_subnet_prefix}100.0-${kind_subnet_prefix}100.20" \ --dry-run=client -oyaml | - kubectl --kubeconfig capd-kubeconfig apply --server-side -n kube-system -f - + kubectl --kubeconfig docker-kubeconfig apply --server-side -n kube-system -f - helm upgrade kube-vip-cloud-provider kube-vip/kube-vip-cloud-provider --version 0.2.2 \ --install \ --wait --wait-for-jobs \ --namespace kube-system \ - --kubeconfig capd-kubeconfig \ + --kubeconfig docker-kubeconfig \ --set-string=image.tag=v0.0.6 helm upgrade kube-vip kube-vip/kube-vip --version 0.4.2 \ --install \ --wait --wait-for-jobs \ --namespace kube-system \ - --kubeconfig capd-kubeconfig \ + --kubeconfig docker-kubeconfig \ --set-string=image.tag=v0.6.0 ``` Deploy traefik as a LB service: ```shell -helm --kubeconfig capd-kubeconfig repo add traefik https://helm.traefik.io/traefik +helm --kubeconfig docker-kubeconfig repo add traefik https://helm.traefik.io/traefik helm repo update &>/dev/null -helm --kubeconfig capd-kubeconfig upgrade --install traefik traefik/traefik \ +helm --kubeconfig docker-kubeconfig upgrade --install traefik traefik/traefik \ --version v10.9.1 \ --wait --wait-for-jobs \ --set ports.web.hostPort=80 \ @@ -111,13 +127,13 @@ helm --kubeconfig capd-kubeconfig upgrade --install traefik traefik/traefik \ Watch for traefik LB service to get an external address: ```shell -watch -n 0.5 kubectl --kubeconfig capd-kubeconfig get service/traefik +watch -n 0.5 kubectl --kubeconfig docker-kubeconfig get service/traefik ``` To delete the workload cluster, run: ```shell -kubectl delete cluster capd-quick-start +kubectl delete cluster docker-quick-start ``` Notice that the traefik service is deleted before the cluster is actually finally deleted. diff --git a/devbox.json b/devbox.json index 795bbe28a..a7322c86e 100644 --- a/devbox.json +++ b/devbox.json @@ -3,6 +3,7 @@ "actionlint@latest", "chart-testing@3.8.0", "clusterctl@latest", + "coreutils@latest", "crane@latest", "envsubst@latest", "findutils@latest", diff --git a/devbox.lock b/devbox.lock index 78c81c48b..c68b32b5a 100644 --- a/devbox.lock +++ b/devbox.lock @@ -19,6 +19,12 @@ "source": "devbox-search", "version": "1.5.1" }, + "coreutils@latest": { + "last_modified": "2023-09-17T10:54:49Z", + "resolved": "github:NixOS/nixpkgs/5148520bfab61f99fd25fb9ff7bfbb50dad3c9db#coreutils", + "source": "devbox-search", + "version": "9.3" + }, "crane@latest": { "last_modified": "2023-08-08T03:07:33Z", "resolved": "github:NixOS/nixpkgs/844ffa82bbe2a2779c86ab3a72ff1b4176cec467#crane", diff --git a/examples/capi-quick-start/aws-cluster-class.yaml b/examples/capi-quick-start/aws-cluster-class.yaml new file mode 100644 index 000000000..2766b89df --- /dev/null +++ b/examples/capi-quick-start/aws-cluster-class.yaml @@ -0,0 +1,155 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: ClusterClass +metadata: + labels: + cluster.x-k8s.io/provider: aws + name: aws-quick-start +spec: + controlPlane: + machineInfrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: AWSMachineTemplate + name: aws-quick-start-control-plane + ref: + apiVersion: controlplane.cluster.x-k8s.io/v1beta1 + kind: KubeadmControlPlaneTemplate + name: aws-quick-start-control-plane + infrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: AWSClusterTemplate + name: aws-quick-start + patches: + - external: + discoverVariablesExtension: clusterconfigvars.capi-runtime-extensions + generateExtension: clusterconfigpatch.capi-runtime-extensions + name: cluster-config + - definitions: + - jsonPatches: + - op: add + path: /spec/template/spec/region + valueFrom: + template: | + {{ if .region }}{{ .region }}{{ else }}us-west-2{{ end }} + selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: AWSClusterTemplate + matchResources: + infrastructureCluster: true + description: aws region to target for cluster creation + name: region + - definitions: + - jsonPatches: + - op: add + path: /spec/template/spec/identityRef + valueFrom: + template: | + kind: AWSClusterStaticIdentity + name: {{ .builtin.cluster.name }} + selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: AWSClusterTemplate + matchResources: + infrastructureCluster: true + description: AWSClusterStaticIdentity identityRef to use when creating the cluster + name: identityRef + variables: + - name: region + schema: + openAPIV3Schema: + default: us-west-2 + description: aws region to target for cluster creation + example: us-west-2 + type: string + workers: + machineDeployments: + - class: default-worker + template: + bootstrap: + ref: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 + kind: KubeadmConfigTemplate + name: aws-quick-start-worker-bootstraptemplate + infrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: AWSMachineTemplate + name: aws-quick-start-worker-machinetemplate +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 +kind: AWSClusterTemplate +metadata: + labels: + cluster.x-k8s.io/provider: aws + name: aws-quick-start +spec: + template: + spec: {} +--- +apiVersion: controlplane.cluster.x-k8s.io/v1beta1 +kind: KubeadmControlPlaneTemplate +metadata: + labels: + cluster.x-k8s.io/provider: aws + name: aws-quick-start-control-plane +spec: + template: + spec: + kubeadmConfigSpec: + clusterConfiguration: + apiServer: + extraArgs: + cloud-provider: aws + controllerManager: + extraArgs: + cloud-provider: aws + initConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-provider: aws + name: '{{ ds.meta_data.local_hostname }}' + joinConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-provider: aws + name: '{{ ds.meta_data.local_hostname }}' +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 +kind: AWSMachineTemplate +metadata: + labels: + cluster.x-k8s.io/provider: aws + name: aws-quick-start-control-plane +spec: + template: + spec: + iamInstanceProfile: control-plane.cluster-api-provider-aws.sigs.k8s.io + instanceType: m5.xlarge +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 +kind: AWSMachineTemplate +metadata: + labels: + cluster.x-k8s.io/provider: aws + name: aws-quick-start-worker-machinetemplate +spec: + template: + spec: + iamInstanceProfile: nodes.cluster-api-provider-aws.sigs.k8s.io + instanceType: m5.2xlarge +--- +apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 +kind: KubeadmConfigTemplate +metadata: + labels: + cluster.x-k8s.io/provider: aws + name: aws-quick-start-worker-bootstraptemplate +spec: + template: + spec: + joinConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-provider: aws + name: '{{ ds.meta_data.local_hostname }}' diff --git a/examples/capi-quick-start/aws-cluster.yaml b/examples/capi-quick-start/aws-cluster.yaml new file mode 100644 index 000000000..1271090ed --- /dev/null +++ b/examples/capi-quick-start/aws-cluster.yaml @@ -0,0 +1,44 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + labels: + cluster.x-k8s.io/provider: aws + name: aws-quick-start +spec: + clusterNetwork: + pods: + cidrBlocks: + - 192.168.0.0/16 + serviceDomain: cluster.local + services: + cidrBlocks: + - 10.128.0.0/12 + topology: + class: aws-quick-start + controlPlane: + replicas: 1 + variables: + - name: clusterConfig + value: + addons: + cni: + provider: calico + nfd: {} + version: v1.27.5 + workers: + machineDeployments: + - class: default-worker + name: md-0 + replicas: 1 +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: AWSClusterStaticIdentity +metadata: + labels: + cluster.x-k8s.io/provider: aws + name: aws-quick-start +spec: + allowedNamespaces: + list: + - default + secretRef: aws-quick-start-creds diff --git a/examples/capi-quick-start/capd-cluster-class.yaml b/examples/capi-quick-start/docker-cluster-class.yaml similarity index 79% rename from examples/capi-quick-start/capd-cluster-class.yaml rename to examples/capi-quick-start/docker-cluster-class.yaml index 1029323e9..4cec328b6 100644 --- a/examples/capi-quick-start/capd-cluster-class.yaml +++ b/examples/capi-quick-start/docker-cluster-class.yaml @@ -1,26 +1,25 @@ -# Copyright 2023 D2iQ, Inc. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - apiVersion: cluster.x-k8s.io/v1beta1 kind: ClusterClass metadata: - name: capd-quick-start + labels: + cluster.x-k8s.io/provider: docker + name: docker-quick-start spec: controlPlane: machineInfrastructure: ref: apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: DockerMachineTemplate - name: capd-quick-start-control-plane + name: docker-quick-start-control-plane ref: apiVersion: controlplane.cluster.x-k8s.io/v1beta1 kind: KubeadmControlPlaneTemplate - name: capd-quick-start-control-plane + name: docker-quick-start-control-plane infrastructure: ref: apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: DockerClusterTemplate - name: capd-quick-start-cluster + name: docker-quick-start-cluster patches: - external: discoverVariablesExtension: clusterconfigvars.capi-runtime-extensions @@ -58,17 +57,19 @@ spec: ref: apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 kind: KubeadmConfigTemplate - name: capd-quick-start-default-worker-bootstraptemplate + name: docker-quick-start-default-worker-bootstraptemplate infrastructure: ref: apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: DockerMachineTemplate - name: capd-quick-start-default-worker-machinetemplate + name: docker-quick-start-default-worker-machinetemplate --- apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: DockerClusterTemplate metadata: - name: capd-quick-start-cluster + labels: + cluster.x-k8s.io/provider: docker + name: docker-quick-start-cluster spec: template: spec: {} @@ -76,7 +77,9 @@ spec: apiVersion: controlplane.cluster.x-k8s.io/v1beta1 kind: KubeadmControlPlaneTemplate metadata: - name: capd-quick-start-control-plane + labels: + cluster.x-k8s.io/provider: docker + name: docker-quick-start-control-plane spec: template: spec: @@ -99,7 +102,9 @@ spec: apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: DockerMachineTemplate metadata: - name: capd-quick-start-control-plane + labels: + cluster.x-k8s.io/provider: docker + name: docker-quick-start-control-plane spec: template: spec: @@ -110,7 +115,9 @@ spec: apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: DockerMachineTemplate metadata: - name: capd-quick-start-default-worker-machinetemplate + labels: + cluster.x-k8s.io/provider: docker + name: docker-quick-start-default-worker-machinetemplate spec: template: spec: @@ -121,7 +128,9 @@ spec: apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 kind: KubeadmConfigTemplate metadata: - name: capd-quick-start-default-worker-bootstraptemplate + labels: + cluster.x-k8s.io/provider: docker + name: docker-quick-start-default-worker-bootstraptemplate spec: template: spec: diff --git a/examples/capi-quick-start/capd-cluster.yaml b/examples/capi-quick-start/docker-cluster.yaml similarity index 80% rename from examples/capi-quick-start/capd-cluster.yaml rename to examples/capi-quick-start/docker-cluster.yaml index 7c45a0790..43d7fd6ba 100644 --- a/examples/capi-quick-start/capd-cluster.yaml +++ b/examples/capi-quick-start/docker-cluster.yaml @@ -1,10 +1,9 @@ -# Copyright 2023 D2iQ, Inc. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - apiVersion: cluster.x-k8s.io/v1beta1 kind: Cluster metadata: - name: capd-quick-start + labels: + cluster.x-k8s.io/provider: docker + name: docker-quick-start spec: clusterNetwork: pods: @@ -15,7 +14,7 @@ spec: cidrBlocks: - 10.128.0.0/12 topology: - class: capd-quick-start + class: docker-quick-start controlPlane: metadata: {} replicas: 1 diff --git a/hack/examples/bases/aws/AWSClusterStaticIdentity.yaml b/hack/examples/bases/aws/AWSClusterStaticIdentity.yaml new file mode 100644 index 000000000..e33290f7e --- /dev/null +++ b/hack/examples/bases/aws/AWSClusterStaticIdentity.yaml @@ -0,0 +1,13 @@ +# Copyright 2023 D2iQ, Inc. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: AWSClusterStaticIdentity +metadata: + name: "quick-start" +spec: + secretRef: aws-quick-start-creds + allowedNamespaces: + list: + - "default" diff --git a/hack/examples/bases/aws/kustomization.yaml.tmpl b/hack/examples/bases/aws/kustomization.yaml.tmpl new file mode 100644 index 000000000..77f770318 --- /dev/null +++ b/hack/examples/bases/aws/kustomization.yaml.tmpl @@ -0,0 +1,121 @@ +# Copyright 2023 D2iQ, Inc. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: +- https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/${CAPA_VERSION}/cluster-template-simple-clusterclass.yaml +- AWSClusterStaticIdentity.yaml + +namePrefix: aws- + +commonLabels: + cluster.x-k8s.io/provider: aws + +patches: +- target: + group: cluster.x-k8s.io + kind: Cluster + patch: |- + - op: "add" + path: "/metadata/name" + value: "quick-start" + - op: "add" + path: "/spec/topology/class" + value: "aws-quick-start" + - op: "remove" + path: "/metadata/labels/cni" +- target: + group: cluster.x-k8s.io + kind: ClusterClass + patch: |- + - op: "add" + path: "/spec/controlPlane/machineInfrastructure/ref/name" + value: "aws-quick-start-control-plane" + - op: "add" + path: "/spec/controlPlane/ref/name" + value: "aws-quick-start-control-plane" + - op: "add" + path: "/spec/infrastructure/ref/name" + value: "aws-quick-start" + - op: "add" + path: "/spec/workers/machineDeployments/0/template/bootstrap/ref/name" + value: "aws-quick-start-worker-bootstraptemplate" + - op: "add" + path: "/spec/workers/machineDeployments/0/template/infrastructure/ref/name" + value: "aws-quick-start-worker-machinetemplate" + - op: "add" + path: "/spec/patches" + value: + - name: region + definitions: + - jsonPatches: + - op: add + path: /spec/template/spec/region + valueFrom: + template: | + {{ if .region }}{{ .region }}{{ else }}us-west-2{{ end }} + selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: AWSClusterTemplate + matchResources: + infrastructureCluster: true + description: aws region to target for cluster creation + - name: identityRef + definitions: + - jsonPatches: + - op: add + path: /spec/template/spec/identityRef + valueFrom: + template: | + kind: AWSClusterStaticIdentity + name: {{ .builtin.cluster.name }} + selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: AWSClusterTemplate + matchResources: + infrastructureCluster: true + description: AWSClusterStaticIdentity identityRef to use when creating the cluster + - op: "add" + path: "/spec/variables" + value: + - name: region + schema: + openAPIV3Schema: + description: aws region to target for cluster creation + example: us-west-2 + type: string + default: us-west-2 +- target: + group: infrastructure.cluster.x-k8s.io + kind: AWSMachineTemplate + name: quick-start-worker-machinetemplate + patch: |- + - op: "add" + path: "/spec/template/spec/instanceType" + value: "m5.2xlarge" +- target: + group: infrastructure.cluster.x-k8s.io + kind: AWSMachineTemplate + name: quick-start-control-plane + patch: |- + - op: "add" + path: "/spec/template/spec/instanceType" + value: "m5.xlarge" +- target: + kind: ConfigMap + patch: | + $$patch: delete + apiVersion: v1 + kind: ConfigMap + metadata: + name: aws-cni-$${CLUSTER_NAME}-crs-0 +- target: + kind: ClusterResourceSet + patch: | + $$patch: delete + apiVersion: addons.cluster.x-k8s.io/v1beta1 + kind: ConfigMap + metadata: + name: aws-$${CLUSTER_NAME}-crs-0 diff --git a/hack/examples/bases/capd/kustomization.yaml.tmpl b/hack/examples/bases/capd/kustomization.yaml.tmpl deleted file mode 100644 index 57a5111c3..000000000 --- a/hack/examples/bases/capd/kustomization.yaml.tmpl +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2023 D2iQ, Inc. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization - -configurations: -- kustomizeconfig.yaml - -resources: -- https://github.com/kubernetes-sigs/cluster-api/releases/download/${CLUSTERCTL_VERSION}/clusterclass-quick-start.yaml -- https://github.com/kubernetes-sigs/cluster-api/releases/download/${CLUSTERCTL_VERSION}/cluster-template-development.yaml - -namePrefix: capd- - -patches: -- target: - group: cluster.x-k8s.io - kind: Cluster - patch: |- - - op: "add" - path: "/metadata/name" - value: "quick-start" diff --git a/hack/examples/bases/capd/kustomizeconfig.yaml b/hack/examples/bases/capd/kustomizeconfig.yaml deleted file mode 100644 index fcfe205f7..000000000 --- a/hack/examples/bases/capd/kustomizeconfig.yaml +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2023 D2iQ, Inc. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - -nameReference: -- group: infrastructure.cluster.x-k8s.io - kind: DockerMachineTemplate - name: quick-start-control-plane - fieldSpecs: - - group: cluster.x-k8s.io - kind: ClusterClass - path: spec/controlPlane/machineInfrastructure/ref/name -- group: controlplane.cluster.x-k8s.io - kind: KubeadmControlPlaneTemplate - fieldSpecs: - - group: cluster.x-k8s.io - kind: ClusterClass - path: spec/controlPlane/ref/name -- group: infrastructure.cluster.x-k8s.io - kind: DockerClusterTemplate - fieldSpecs: - - group: cluster.x-k8s.io - kind: ClusterClass - path: spec/infrastructure/ref/name -- group: bootstrap.cluster.x-k8s.io - kind: KubeadmConfigTemplate - fieldSpecs: - - group: cluster.x-k8s.io - kind: ClusterClass - path: spec/workers/machineDeployments/template/bootstrap/ref/name -- group: infrastructure.cluster.x-k8s.io - kind: DockerMachineTemplate - name: quick-start-default-worker-machinetemplate - fieldSpecs: - - group: cluster.x-k8s.io - kind: ClusterClass - path: spec/workers/machineDeployments/template/infrastructure/ref/name -- group: cluster.x-k8s.io - kind: ClusterClass - fieldSpecs: - - group: cluster.x-k8s.io - kind: Cluster - path: spec/topology/class diff --git a/hack/examples/bases/docker/kustomization.yaml.tmpl b/hack/examples/bases/docker/kustomization.yaml.tmpl new file mode 100644 index 000000000..c9c2478c0 --- /dev/null +++ b/hack/examples/bases/docker/kustomization.yaml.tmpl @@ -0,0 +1,76 @@ +# Copyright 2023 D2iQ, Inc. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: +- https://github.com/kubernetes-sigs/cluster-api/releases/download/${CLUSTERCTL_VERSION}/clusterclass-quick-start.yaml +- https://github.com/kubernetes-sigs/cluster-api/releases/download/${CLUSTERCTL_VERSION}/cluster-template-development.yaml + +namePrefix: docker- + +commonLabels: + cluster.x-k8s.io/provider: docker + +patches: +- target: + group: cluster.x-k8s.io + kind: Cluster + patch: |- + - op: "remove" + path: "/metadata/namespace" + - op: "add" + path: "/metadata/name" + value: "quick-start" + - op: "add" + path: "/spec/topology/class" + value: "docker-quick-start" +- target: + group: cluster.x-k8s.io + kind: ClusterClass + patch: |- + - op: "add" + path: "/spec/controlPlane/machineInfrastructure/ref/name" + value: "docker-quick-start-control-plane" + - op: "add" + path: "/spec/controlPlane/ref/name" + value: "docker-quick-start-control-plane" + - op: "add" + path: "/spec/infrastructure/ref/name" + value: "docker-quick-start-cluster" + - op: "add" + path: "/spec/workers/machineDeployments/0/template/bootstrap/ref/name" + value: "docker-quick-start-default-worker-bootstraptemplate" + - op: "add" + path: "/spec/workers/machineDeployments/0/template/infrastructure/ref/name" + value: "docker-quick-start-default-worker-machinetemplate" + - op: "add" + path: "/spec/patches" + value: + - name: customKinDNodeImageForWorkers + definitions: + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + kind: DockerMachineTemplate + matchResources: + machineDeploymentClass: + names: + - "*" + jsonPatches: + - op: add + path: /spec/template/spec/customImage + valueFrom: + template: ghcr.io/mesosphere/kind-node:{{ .builtin.machineDeployment.version }} + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + kind: DockerMachineTemplate + matchResources: + controlPlane: true + jsonPatches: + - op: add + path: /spec/template/spec/customImage + valueFrom: + template: ghcr.io/mesosphere/kind-node:{{ .builtin.controlPlane.version }} + - op: "remove" + path: "/spec/variables" diff --git a/hack/examples/kustomization.yaml.tmpl b/hack/examples/kustomization.yaml.tmpl index 399e5ec61..2ee0ac9d1 100644 --- a/hack/examples/kustomization.yaml.tmpl +++ b/hack/examples/kustomization.yaml.tmpl @@ -8,7 +8,8 @@ sortOptions: order: fifo resources: -- ./bases/capd +- ./bases/docker +- ./bases/aws patches: - target: @@ -16,62 +17,28 @@ patches: kind: ClusterClass patch: |- - op: "add" - path: "/spec/patches" + path: "/spec/patches/0" value: - - name: "cluster-config" - external: - generateExtension: "clusterconfigpatch.capi-runtime-extensions" - discoverVariablesExtension: "clusterconfigvars.capi-runtime-extensions" - - op: "remove" - path: "/spec/variables" -- target: - group: cluster.x-k8s.io - kind: ClusterClass - name: capd-quick-start - patch: |- - - op: "add" - path: "/spec/patches/-" - value: - name: customKinDNodeImageForWorkers - definitions: - - selector: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 - kind: DockerMachineTemplate - matchResources: - machineDeploymentClass: - names: - - "*" - jsonPatches: - - op: add - path: /spec/template/spec/customImage - valueFrom: - template: ghcr.io/mesosphere/kind-node:{{ .builtin.machineDeployment.version }} - - selector: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 - kind: DockerMachineTemplate - matchResources: - controlPlane: true - jsonPatches: - - op: add - path: /spec/template/spec/customImage - valueFrom: - template: ghcr.io/mesosphere/kind-node:{{ .builtin.controlPlane.version }} + name: "cluster-config" + external: + generateExtension: "clusterconfigpatch.capi-runtime-extensions" + discoverVariablesExtension: "clusterconfigvars.capi-runtime-extensions" - target: group: cluster.x-k8s.io kind: Cluster patch: |- - - op: "remove" - path: "/metadata/namespace" - op: "add" path: "/spec/topology/version" value: "${KUBERNETES_VERSION}" - op: "add" - path: "/spec/clusterNetwork/pods/cidrBlocks" + path: "/spec/clusterNetwork/pods" value: + cidrBlocks: - "192.168.0.0/16" - op: "add" - path: "/spec/clusterNetwork/services/cidrBlocks" + path: "/spec/clusterNetwork/services" value: + cidrBlocks: - "10.128.0.0/12" - op: "add" path: "/spec/clusterNetwork/serviceDomain" diff --git a/hack/examples/sync.sh b/hack/examples/sync.sh index fb9e77d89..35acd7b54 100755 --- a/hack/examples/sync.sh +++ b/hack/examples/sync.sh @@ -9,20 +9,16 @@ IFS=$'\n\t' SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly SCRIPT_DIR -readonly EXAMPLES_KUSTOMIZATION_FILE="${SCRIPT_DIR}/kustomization.yaml" -readonly CAPD_KUSTOMIZATION_FILE="${SCRIPT_DIR}/bases/capd/kustomization.yaml" +trap 'find "${SCRIPT_DIR}" -name kustomization.yaml -delete' EXIT -trap 'rm -rf ${CAPD_KUSTOMIZATION_FILE} ${EXAMPLES_KUSTOMIZATION_FILE}' EXIT -# download the quick-start files that match the clusterctl version -CLUSTERCTL_VERSION=$(clusterctl version -o short 2>/dev/null) envsubst \ - <"${CAPD_KUSTOMIZATION_FILE}.tmpl" >"${CAPD_KUSTOMIZATION_FILE}" -# replace the kubernetes version -envsubst -no-unset <"${EXAMPLES_KUSTOMIZATION_FILE}.tmpl" >"${EXAMPLES_KUSTOMIZATION_FILE}" +find "${SCRIPT_DIR}" -name kustomization.yaml.tmpl \ + -exec bash -ec 'envsubst -no-unset <"{}" >"$(dirname {})/$(basename -s .tmpl {})"' \; mkdir -p examples/capi-quick-start -# Sync ClusterClass and all Templates +# Sync ClusterClasses (including Templates) and Clusters to separate files kustomize build ./hack/examples | - gojq --yaml-input --yaml-output '. | select(.kind != "Cluster")' >examples/capi-quick-start/capd-cluster-class.yaml -# Sync Cluster -kustomize build ./hack/examples | - gojq --yaml-input --yaml-output '. | select(.kind == "Cluster")' >examples/capi-quick-start/capd-cluster.yaml + tee >(gojq --yaml-input --yaml-output '. | select(.metadata.labels["cluster.x-k8s.io/provider"] == "docker" and .kind != "Cluster")' >examples/capi-quick-start/docker-cluster-class.yaml) \ + >(gojq --yaml-input --yaml-output '. | select(.metadata.labels["cluster.x-k8s.io/provider"] == "docker" and .kind == "Cluster")' >examples/capi-quick-start/docker-cluster.yaml) \ + >(gojq --yaml-input --yaml-output '. | select(.metadata.labels["cluster.x-k8s.io/provider"] == "aws" and ( .kind != "Cluster" and .kind != "AWSClusterStaticIdentity"))' >examples/capi-quick-start/aws-cluster-class.yaml) \ + >(gojq --yaml-input --yaml-output '. | select(.metadata.labels["cluster.x-k8s.io/provider"] == "aws" and ( .kind == "Cluster" or .kind == "AWSClusterStaticIdentity"))' >examples/capi-quick-start/aws-cluster.yaml) \ + >/dev/null diff --git a/make/clusterctl.mk b/make/clusterctl.mk index c522cffd8..dec74d364 100644 --- a/make/clusterctl.mk +++ b/make/clusterctl.mk @@ -6,9 +6,11 @@ clusterctl.init: env CLUSTER_TOPOLOGY=true \ EXP_RUNTIME_SDK=true \ EXP_CLUSTER_RESOURCE_SET=true \ + EXP_MACHINE_POOL=true \ + AWS_B64ENCODED_CREDENTIALS= \ clusterctl init \ --kubeconfig=$(KIND_KUBECONFIG) \ - --infrastructure docker \ + --infrastructure docker,aws \ --wait-providers .PHONY: clusterctl.delete diff --git a/make/examples.mk b/make/examples.mk index d59316755..5e8568359 100644 --- a/make/examples.mk +++ b/make/examples.mk @@ -1,9 +1,11 @@ # Copyright 2023 D2iQ, Inc. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -KUBERNETES_VERSION := v1.27.5 +export KUBERNETES_VERSION := v1.27.5 + +export CLUSTERCTL_VERSION := $(shell clusterctl version -o short 2>/dev/null) +export CAPA_VERSION := v2.2.2 .PHONY: examples.sync -examples.sync: export KUBERNETES_VERSION := $(KUBERNETES_VERSION) examples.sync: ## Syncs the examples by fetching upstream examples and applying kustomize patches hack/examples/sync.sh