From df640e8035e0b61d00f4305b071fc2327e61e328 Mon Sep 17 00:00:00 2001 From: David Justice Date: Sat, 18 Apr 2020 11:04:48 -0700 Subject: [PATCH] add machinepool flavor --- ...e.cluster.x-k8s.io_azuremachinepools.yaml} | 6 +- config/crd/kustomization.yaml | 2 +- .../cainjection_in_azuremachinepools.yaml | 2 +- .../patches/webhook_in_azuremachinepools.yaml | 2 +- exp/PROJECT | 2 +- exp/api/v1alpha3/groupversion_info.go | 4 +- .../azuremachinepool_controller.go | 4 +- templates/cluster-template-machinepool.yaml | 196 ++++++++++++++++++ .../flavors/machinepool/kustomization.yaml | 3 + .../machinepool/machine-pool-deployment.yaml | 76 +++++++ 10 files changed, 286 insertions(+), 11 deletions(-) rename config/crd/bases/{exp.cluster.x-k8s.io_azuremachinepools.yaml => exp.infrastructure.cluster.x-k8s.io_azuremachinepools.yaml} (98%) create mode 100644 templates/cluster-template-machinepool.yaml create mode 100644 templates/flavors/machinepool/kustomization.yaml create mode 100644 templates/flavors/machinepool/machine-pool-deployment.yaml diff --git a/config/crd/bases/exp.cluster.x-k8s.io_azuremachinepools.yaml b/config/crd/bases/exp.infrastructure.cluster.x-k8s.io_azuremachinepools.yaml similarity index 98% rename from config/crd/bases/exp.cluster.x-k8s.io_azuremachinepools.yaml rename to config/crd/bases/exp.infrastructure.cluster.x-k8s.io_azuremachinepools.yaml index d9942fc38c8..e7799f8e013 100644 --- a/config/crd/bases/exp.cluster.x-k8s.io_azuremachinepools.yaml +++ b/config/crd/bases/exp.infrastructure.cluster.x-k8s.io_azuremachinepools.yaml @@ -4,11 +4,11 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.2.6 + controller-gen.kubebuilder.io/version: v0.2.8 creationTimestamp: null - name: azuremachinepools.exp.cluster.x-k8s.io + name: azuremachinepools.exp.infrastructure.cluster.x-k8s.io spec: - group: exp.cluster.x-k8s.io + group: exp.infrastructure.cluster.x-k8s.io names: kind: AzureMachinePool listKind: AzureMachinePoolList diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 2a9b52e04f8..f69440c90e0 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -8,7 +8,7 @@ resources: - bases/infrastructure.cluster.x-k8s.io_azuremachines.yaml - bases/infrastructure.cluster.x-k8s.io_azureclusters.yaml - bases/infrastructure.cluster.x-k8s.io_azuremachinetemplates.yaml - - bases/exp.cluster.x-k8s.io_azuremachinepools.yaml + - bases/exp.infrastructure.cluster.x-k8s.io_azuremachinepools.yaml # +kubebuilder:scaffold:crdkustomizeresource patchesStrategicMerge: diff --git a/config/crd/patches/cainjection_in_azuremachinepools.yaml b/config/crd/patches/cainjection_in_azuremachinepools.yaml index 8f3496108a1..1a7f89e993e 100644 --- a/config/crd/patches/cainjection_in_azuremachinepools.yaml +++ b/config/crd/patches/cainjection_in_azuremachinepools.yaml @@ -5,4 +5,4 @@ kind: CustomResourceDefinition metadata: annotations: cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) - name: azuremachinepools.exp.cluster.x-k8s.io + name: azuremachinepools.exp.infrastructure.cluster.x-k8s.io diff --git a/config/crd/patches/webhook_in_azuremachinepools.yaml b/config/crd/patches/webhook_in_azuremachinepools.yaml index 1013745624a..d15c8280f0c 100644 --- a/config/crd/patches/webhook_in_azuremachinepools.yaml +++ b/config/crd/patches/webhook_in_azuremachinepools.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: azuremachinepools.exp.cluster.x-k8s.io + name: azuremachinepools.exp.infrastructure.cluster.x-k8s.io spec: conversion: strategy: Webhook diff --git a/exp/PROJECT b/exp/PROJECT index eb4fb899910..3ad048cebeb 100644 --- a/exp/PROJECT +++ b/exp/PROJECT @@ -2,6 +2,6 @@ domain: x-k8s.io repo: sigs.k8s.io/cluster-api-provider-azure/exp version: "2" resources: -- group: exp +- group: exp.infrastructure kind: AzureMachinePool version: v1alpha3 diff --git a/exp/api/v1alpha3/groupversion_info.go b/exp/api/v1alpha3/groupversion_info.go index 832a031e9ff..897b515a0ce 100644 --- a/exp/api/v1alpha3/groupversion_info.go +++ b/exp/api/v1alpha3/groupversion_info.go @@ -16,7 +16,7 @@ limitations under the License. // Package v1alpha3 contains API Schema definitions for the exp v1alpha3 API group // +kubebuilder:object:generate=true -// +groupName=exp.cluster.x-k8s.io +// +groupName=exp.infrastructure.cluster.x-k8s.io package v1alpha3 import ( @@ -26,7 +26,7 @@ import ( var ( // GroupVersion is group version used to register these objects - GroupVersion = schema.GroupVersion{Group: "exp.cluster.x-k8s.io", Version: "v1alpha3"} + GroupVersion = schema.GroupVersion{Group: "exp.infrastructure.cluster.x-k8s.io", Version: "v1alpha3"} // SchemeBuilder is used to add go types to the GroupVersionKind scheme SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} diff --git a/exp/controllers/azuremachinepool_controller.go b/exp/controllers/azuremachinepool_controller.go index f850c8c8d62..5417a94456a 100644 --- a/exp/controllers/azuremachinepool_controller.go +++ b/exp/controllers/azuremachinepool_controller.go @@ -78,8 +78,8 @@ type ( } ) -// +kubebuilder:rbac:groups=exp.cluster.x-k8s.io,resources=azuremachinepools,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=exp.cluster.x-k8s.io,resources=azuremachinepools/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=exp.infrastructure.cluster.x-k8s.io,resources=azuremachinepools,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=exp.infrastructure.cluster.x-k8s.io,resources=azuremachinepools/status,verbs=get;update;patch // +kubebuilder:rbac:groups=exp.cluster.x-k8s.io,resources=machinespools;machinepools/status,verbs=get;list;watch // +kubebuilder:rbac:groups="",resources=events,verbs=get;list;watch;create;update;patch // +kubebuilder:rbac:groups="",resources=secrets;,verbs=get;list;watch diff --git a/templates/cluster-template-machinepool.yaml b/templates/cluster-template-machinepool.yaml new file mode 100644 index 00000000000..2e27ad9284a --- /dev/null +++ b/templates/cluster-template-machinepool.yaml @@ -0,0 +1,196 @@ +apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3 +kind: KubeadmConfigTemplate +metadata: + name: ${CLUSTER_NAME}-mp-0 +spec: + template: + spec: + files: + - content: | + { + "cloud": "AzurePublicCloud", + "tenantId": "${AZURE_TENANT_ID}", + "subscriptionId": "${AZURE_SUBSCRIPTION_ID}", + "aadClientId": "${AZURE_CLIENT_ID}", + "aadClientSecret": "${AZURE_CLIENT_SECRET}", + "resourceGroup": "${CLUSTER_NAME}", + "securityGroupName": "${CLUSTER_NAME}-node-nsg", + "location": "${AZURE_LOCATION}", + "vmType": "standard", + "vnetName": "${CLUSTER_NAME}-vnet", + "vnetResourceGroup": "${CLUSTER_NAME}", + "subnetName": "${CLUSTER_NAME}-node-subnet", + "routeTableName": "${CLUSTER_NAME}-node-routetable", + "loadBalancerSku": "standard", + "maximumLoadBalancerRuleCount": 250, + "useManagedIdentityExtension": false, + "useInstanceMetadata": true + } + owner: root:root + path: /etc/kubernetes/azure.json + permissions: "0644" + joinConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-config: /etc/kubernetes/azure.json + cloud-provider: azure + name: '{{ ds.meta_data["local_hostname"] }}' +--- +apiVersion: cluster.x-k8s.io/v1alpha3 +kind: Cluster +metadata: + name: ${CLUSTER_NAME} + namespace: default +spec: + clusterNetwork: + pods: + cidrBlocks: + - 192.168.0.0/16 + controlPlaneRef: + apiVersion: controlplane.cluster.x-k8s.io/v1alpha3 + kind: KubeadmControlPlane + name: ${CLUSTER_NAME}-control-plane + infrastructureRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3 + kind: AzureCluster + name: ${CLUSTER_NAME} +--- +apiVersion: controlplane.cluster.x-k8s.io/v1alpha3 +kind: KubeadmControlPlane +metadata: + name: ${CLUSTER_NAME}-control-plane + namespace: default +spec: + infrastructureTemplate: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3 + kind: AzureMachineTemplate + name: ${CLUSTER_NAME}-control-plane + kubeadmConfigSpec: + clusterConfiguration: + apiServer: + extraArgs: + cloud-config: /etc/kubernetes/azure.json + cloud-provider: azure + extraVolumes: + - hostPath: /etc/kubernetes/azure.json + mountPath: /etc/kubernetes/azure.json + name: cloud-config + readOnly: true + timeoutForControlPlane: 20m + controllerManager: + extraArgs: + allocate-node-cidrs: "false" + cloud-config: /etc/kubernetes/azure.json + cloud-provider: azure + extraVolumes: + - hostPath: /etc/kubernetes/azure.json + mountPath: /etc/kubernetes/azure.json + name: cloud-config + readOnly: true + files: + - content: | + { + "cloud": "AzurePublicCloud", + "tenantId": "${AZURE_TENANT_ID}", + "subscriptionId": "${AZURE_SUBSCRIPTION_ID}", + "aadClientId": "${AZURE_CLIENT_ID}", + "aadClientSecret": "${AZURE_CLIENT_SECRET}", + "resourceGroup": "${AZURE_RESOURCE_GROUP}", + "securityGroupName": "${CLUSTER_NAME}-node-nsg", + "location": "${AZURE_LOCATION}", + "vmType": "standard", + "vnetName": "${CLUSTER_NAME}-vnet", + "vnetResourceGroup": "${CLUSTER_NAME}", + "subnetName": "${CLUSTER_NAME}-node-subnet", + "routeTableName": "${CLUSTER_NAME}-node-routetable", + "userAssignedID": "${CLUSTER_NAME}", + "loadBalancerSku": "standard", + "maximumLoadBalancerRuleCount": 250, + "useManagedIdentityExtension": false, + "useInstanceMetadata": true + } + owner: root:root + path: /etc/kubernetes/azure.json + permissions: "0644" + initConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-config: /etc/kubernetes/azure.json + cloud-provider: azure + name: '{{ ds.meta_data["local_hostname"] }}' + joinConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-config: /etc/kubernetes/azure.json + cloud-provider: azure + name: '{{ ds.meta_data["local_hostname"] }}' + useExperimentalRetryJoin: true + replicas: ${CONTROL_PLANE_MACHINE_COUNT} + version: ${KUBERNETES_VERSION} +--- +apiVersion: exp.cluster.x-k8s.io/v1alpha3 +kind: MachinePool +metadata: + name: ${CLUSTER_NAME}-mp-0 +spec: + clusterName: ${CLUSTER_NAME} + replicas: ${WORKER_MACHINE_COUNT} + template: + spec: + bootstrap: + configRef: + apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3 + kind: KubeadmConfigTemplate + name: ${CLUSTER_NAME}-mp-0 + clusterName: ${CLUSTER_NAME} + infrastructureRef: + apiVersion: exp.infrastructure.cluster.x-k8s.io/v1alpha3 + kind: AzureMachinePool + name: ${CLUSTER_NAME}-amp-0 + version: ${KUBERNETES_VERSION} +--- +apiVersion: exp.infrastructure.cluster.x-k8s.io/v1alpha3 +kind: AzureMachinePool +metadata: + name: ${CLUSTER_NAME}-amp-0 +spec: + template: + spec: + location: ${AZURE_LOCATION} + template: + osDisk: + diskSizeGB: 30 + managedDisk: + storageAccountType: Premium_LRS + osType: Linux + sshPublicKey: ${AZURE_SSH_PUBLIC_KEY} + vmSize: ${AZURE_NODE_MACHINE_TYPE} +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3 +kind: AzureCluster +metadata: + name: ${CLUSTER_NAME} + namespace: default +spec: + location: ${AZURE_LOCATION} + networkSpec: + vnet: + name: ${AZURE_VNET_NAME} + resourceGroup: ${AZURE_RESOURCE_GROUP} +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3 +kind: AzureMachineTemplate +metadata: + name: ${CLUSTER_NAME}-control-plane + namespace: default +spec: + template: + spec: + location: ${AZURE_LOCATION} + osDisk: + diskSizeGB: 128 + managedDisk: + storageAccountType: Premium_LRS + osType: Linux + sshPublicKey: ${AZURE_SSH_PUBLIC_KEY} + vmSize: ${AZURE_CONTROL_PLANE_MACHINE_TYPE} diff --git a/templates/flavors/machinepool/kustomization.yaml b/templates/flavors/machinepool/kustomization.yaml new file mode 100644 index 00000000000..63d889cfb0e --- /dev/null +++ b/templates/flavors/machinepool/kustomization.yaml @@ -0,0 +1,3 @@ +resources: + - ../base + - machine-pool-deployment.yaml \ No newline at end of file diff --git a/templates/flavors/machinepool/machine-pool-deployment.yaml b/templates/flavors/machinepool/machine-pool-deployment.yaml new file mode 100644 index 00000000000..e49f23975a8 --- /dev/null +++ b/templates/flavors/machinepool/machine-pool-deployment.yaml @@ -0,0 +1,76 @@ +--- +apiVersion: exp.cluster.x-k8s.io/v1alpha3 +kind: MachinePool +metadata: + name: "${CLUSTER_NAME}-mp-0" +spec: + clusterName: "${CLUSTER_NAME}" + replicas: ${WORKER_MACHINE_COUNT} + template: + spec: + clusterName: "${CLUSTER_NAME}" + version: "${KUBERNETES_VERSION}" + bootstrap: + configRef: + name: "${CLUSTER_NAME}-mp-0" + apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3 + kind: KubeadmConfigTemplate + infrastructureRef: + name: "${CLUSTER_NAME}-amp-0" + apiVersion: exp.infrastructure.cluster.x-k8s.io/v1alpha3 + kind: AzureMachinePool +--- +apiVersion: exp.infrastructure.cluster.x-k8s.io/v1alpha3 +kind: AzureMachinePool +metadata: + name: "${CLUSTER_NAME}-amp-0" +spec: + template: + spec: + location: ${AZURE_LOCATION} + template: + vmSize: ${AZURE_NODE_MACHINE_TYPE} + osDisk: + osType: "Linux" + diskSizeGB: 30 + managedDisk: + storageAccountType: "Premium_LRS" + sshPublicKey: ${AZURE_SSH_PUBLIC_KEY} +--- +apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3 +kind: KubeadmConfigTemplate +metadata: + name: "${CLUSTER_NAME}-mp-0" +spec: + template: + spec: + joinConfiguration: + nodeRegistration: + name: '{{ ds.meta_data["local_hostname"] }}' + kubeletExtraArgs: + cloud-provider: azure + cloud-config: /etc/kubernetes/azure.json + files: + - path: /etc/kubernetes/azure.json + owner: "root:root" + permissions: "0644" + content: | + { + "cloud": "AzurePublicCloud", + "tenantId": "${AZURE_TENANT_ID}", + "subscriptionId": "${AZURE_SUBSCRIPTION_ID}", + "aadClientId": "${AZURE_CLIENT_ID}", + "aadClientSecret": "${AZURE_CLIENT_SECRET}", + "resourceGroup": "${CLUSTER_NAME}", + "securityGroupName": "${CLUSTER_NAME}-node-nsg", + "location": "${AZURE_LOCATION}", + "vmType": "standard", + "vnetName": "${CLUSTER_NAME}-vnet", + "vnetResourceGroup": "${CLUSTER_NAME}", + "subnetName": "${CLUSTER_NAME}-node-subnet", + "routeTableName": "${CLUSTER_NAME}-node-routetable", + "loadBalancerSku": "standard", + "maximumLoadBalancerRuleCount": 250, + "useManagedIdentityExtension": false, + "useInstanceMetadata": true + } \ No newline at end of file