Skip to content

Commit

Permalink
feat: implement AzureMachinePool
Browse files Browse the repository at this point in the history
  • Loading branch information
devigned committed Apr 6, 2020
1 parent d6121a1 commit 2a8537a
Show file tree
Hide file tree
Showing 27 changed files with 2,314 additions and 14 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
TOOLS_DIR := hack/tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
BIN_DIR := bin
EXP_DIR := exp

# Binaries.
CLUSTERCTL := $(BIN_DIR)/clusterctl
Expand Down Expand Up @@ -162,26 +163,30 @@ generate: ## Generate code

.PHONY: generate-go
generate-go: $(CONTROLLER_GEN) $(MOCKGEN) $(CONVERSION_GEN) ## Runs Go related generate targets
go generate ./...
$(CONTROLLER_GEN) \
paths=./api/... \
paths=./$(EXP_DIR)/api/... \
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt

$(CONVERSION_GEN) \
--input-dirs=./api/v1alpha2 \
--output-file-base=zz_generated.conversion \
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt

go generate ./...

.PHONY: generate-manifests
generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
$(CONTROLLER_GEN) \
paths=./api/... \
paths=./$(EXP_DIR)/api/... \
crd:crdVersions=v1 \
output:crd:dir=$(CRD_ROOT) \
output:webhook:dir=$(WEBHOOK_ROOT) \
webhook
$(CONTROLLER_GEN) \
paths=./controllers/... \
paths=./$(EXP_DIR)/controllers/... \
output:rbac:dir=$(RBAC_ROOT) \
rbac:roleName=manager-role

Expand Down
1 change: 1 addition & 0 deletions cloud/services/virtualmachines/virtualmachines.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {

klog.V(2).Infof("creating vm %s ", vmSpec.Name)

// TODO[dj]: Probably shouldn't be defaulting ssh and password. Password should be off and ssh key should be mandatory
sshKeyData := vmSpec.SSHKeyData
if sshKeyData == "" {
privateKey, perr := rsa.GenerateKey(rand.Reader, 2048)
Expand Down
258 changes: 258 additions & 0 deletions config/crd/bases/exp.cluster.x-k8s.io_azuremachinepools.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.6
creationTimestamp: null
name: azuremachinepools.exp.cluster.x-k8s.io
spec:
group: exp.cluster.x-k8s.io
names:
kind: AzureMachinePool
listKind: AzureMachinePoolList
plural: azuremachinepools
singular: azuremachinepool
scope: Namespaced
versions:
- additionalPrinterColumns:
- description: AzureMachinePool replicas count
jsonPath: .status.replicas
name: Replicas
type: string
- description: AzureMachinePool replicas count
jsonPath: .status.ready
name: Ready
type: string
name: v1alpha3
schema:
openAPIV3Schema:
description: AzureMachinePool is the Schema for the azuremachinepools API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: AzureMachinePoolSpec defines the desired state of AzureMachinePool
properties:
additionalTags:
additionalProperties:
type: string
description: AdditionalTags is an optional set of tags to add to an
instance, in addition to the ones added by default by the Azure
provider. If both the AzureCluster and the AzureMachine specify
the same tag name with different values, the AzureMachine's value
takes precedence.
type: object
location:
description: Location is the Azure region location e.g. westus2
type: string
providerID:
description: ProviderID is the identification ID of the Virtual Machine
Scale Set
type: string
providerIDList:
description: ProviderIDList are the identification IDs of machine
instances provided by the provider. This field must match the provider
IDs as seen on the node objects corresponding to a machine pool's
machine instances.
items:
type: string
type: array
template:
description: Template contains the details used to build a replica
virtual machine within the Machine Pool
properties:
image:
description: Image is used to provide details of an image to use
during Virtual Machine creation. If image details are omitted
the image will default the Azure Marketplace "capi" offer, which
is based on Ubuntu.
properties:
id:
description: ID specifies an image to use by ID
type: string
marketplace:
description: Marketplace specifies an image to use from the
Azure Marketplace
properties:
offer:
description: Offer specifies the name of a group of related
images created by the publisher. For example, UbuntuServer,
WindowsServer
minLength: 1
type: string
publisher:
description: Publisher is the name of the organization
that created the image
minLength: 1
type: string
sku:
description: SKU specifies an instance of an offer, such
as a major release of a distribution. For example, 18.04-LTS,
2019-Datacenter
minLength: 1
type: string
version:
description: Version specifies the version of an image
sku. The allowed formats are Major.Minor.Build or 'latest'.
Major, Minor, and Build are decimal numbers. Specify
'latest' to use the latest version of an image available
at deploy time. Even if you use 'latest', the VM image
will not automatically update after deploy time even
if a new version becomes available.
minLength: 1
type: string
required:
- offer
- publisher
- sku
- version
type: object
sharedGallery:
description: SharedGallery specifies an image to use from
an Azure Shared Image Gallery
properties:
gallery:
description: Gallery specifies the name of the shared
image gallery that contains the image
minLength: 1
type: string
name:
description: Name is the name of the image
minLength: 1
type: string
resourceGroup:
description: ResourceGroup specifies the resource group
containing the shared image gallery
minLength: 1
type: string
subscriptionID:
description: SubscriptionID is the identifier of the subscription
that contains the shared image gallery
minLength: 1
type: string
version:
description: Version specifies the version of the marketplace
image. The allowed formats are Major.Minor.Build or
'latest'. Major, Minor, and Build are decimal numbers.
Specify 'latest' to use the latest version of an image
available at deploy time. Even if you use 'latest',
the VM image will not automatically update after deploy
time even if a new version becomes available.
minLength: 1
type: string
required:
- gallery
- name
- resourceGroup
- subscriptionID
- version
type: object
type: object
osDisk:
description: OSDisk contains the operating system disk information
for a Virtual Machine
properties:
diskSizeGB:
format: int32
type: integer
managedDisk:
properties:
storageAccountType:
type: string
required:
- storageAccountType
type: object
osType:
type: string
required:
- diskSizeGB
- managedDisk
- osType
type: object
sshPublicKey:
description: SSHPublicKey is the SSH public key string base64
encoded to add to a Virtual Machine
type: string
vmSize:
description: VMSize is the size of the Virtual Machine to build.
See https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/createorupdate#virtualmachinesizetypes
type: string
required:
- osDisk
- sshPublicKey
- vmSize
type: object
required:
- location
- template
type: object
status:
description: AzureMachinePoolStatus defines the observed state of AzureMachinePool
properties:
failureMessage:
description: "ErrorMessage will be set in the event that there is
a terminal problem reconciling the MachinePool and will contain
a more verbose string suitable for logging and human consumption.
\n This field should not be set for transitive errors that a controller
faces that are expected to be fixed automatically over time (like
service outages), but instead indicate that something is fundamentally
wrong with the MachinePool's spec or the configuration of the controller,
and that manual intervention is required. Examples of terminal errors
would be invalid combinations of settings in the spec, values that
are unsupported by the controller, or the responsible controller
itself being critically misconfigured. \n Any transient errors that
occur during the reconciliation of MachinePools can be added as
events to the MachinePool object and/or logged in the controller's
output."
type: string
failureReason:
description: "ErrorReason will be set in the event that there is a
terminal problem reconciling the MachinePool and will contain a
succinct value suitable for machine interpretation. \n This field
should not be set for transitive errors that a controller faces
that are expected to be fixed automatically over time (like service
outages), but instead indicate that something is fundamentally wrong
with the MachinePool's spec or the configuration of the controller,
and that manual intervention is required. Examples of terminal errors
would be invalid combinations of settings in the spec, values that
are unsupported by the controller, or the responsible controller
itself being critically misconfigured. \n Any transient errors that
occur during the reconciliation of MachinePools can be added as
events to the MachinePool object and/or logged in the controller's
output."
type: string
provisioningState:
description: VMState is the provisioning state of the Azure virtual
machine.
type: string
ready:
description: Ready is true when the provider resource is ready.
type: boolean
replicas:
description: Replicas is the most recently observed number of replicas.
format: int32
type: integer
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +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
# +kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand All @@ -16,13 +17,15 @@ patchesStrategicMerge:
- patches/webhook_in_azuremachines.yaml
- patches/webhook_in_azureclusters.yaml
- patches/webhook_in_azuremachinetemplates.yaml
- patches/webhook_in_azuremachinepools.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
- patches/cainjection_in_azuremachines.yaml
- patches/cainjection_in_azureclusters.yaml
- patches/cainjection_in_azuremachinetemplates.yaml
- patches/cainjection_in_azuremachinepools.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
8 changes: 8 additions & 0 deletions config/crd/patches/cainjection_in_azuremachinepools.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: azuremachinepools.exp.cluster.x-k8s.io
19 changes: 19 additions & 0 deletions config/crd/patches/webhook_in_azuremachinepools.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# The following patch enables conversion webhook for CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: azuremachinepools.exp.cluster.x-k8s.io
spec:
conversion:
strategy: Webhook
webhook:
conversionReviewVersions: ["v1", "v1beta1"]
clientConfig:
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
caBundle: Cg==
service:
namespace: system
name: webhook-service
path: /convert
29 changes: 29 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,35 @@ rules:
- get
- list
- watch
- apiGroups:
- exp.cluster.x-k8s.io
resources:
- azuremachinepools
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- exp.cluster.x-k8s.io
resources:
- azuremachinepools/status
verbs:
- get
- patch
- update
- apiGroups:
- exp.cluster.x-k8s.io
resources:
- machinepools/status
- machinespools
verbs:
- get
- list
- watch
- apiGroups:
- infrastructure.cluster.x-k8s.io
resources:
Expand Down
Loading

0 comments on commit 2a8537a

Please sign in to comment.