Skip to content

Commit

Permalink
added awsmachinepool controller and types
Browse files Browse the repository at this point in the history
Co-authored-by: Nicole Yson <[email protected]>
Co-authored-by: Andrew Rudoi <[email protected]>

Co-authored-by: mnguyen <[email protected]>

Co-authored-by: Naadir Jeewa <[email protected]>
  • Loading branch information
2 people authored and mytunguyen committed Sep 29, 2020
1 parent 3048405 commit f05273a
Show file tree
Hide file tree
Showing 35 changed files with 6,994 additions and 32 deletions.
342 changes: 342 additions & 0 deletions config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachinepools.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ resources:
- bases/infrastructure.cluster.x-k8s.io_awsclusters.yaml
- bases/infrastructure.cluster.x-k8s.io_awsmachinetemplates.yaml
- bases/infrastructure.cluster.x-k8s.io_awsmanagedclusters.yaml
- bases/infrastructure.cluster.x-k8s.io_awsmachinepools.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand Down
8 changes: 8 additions & 0 deletions config/crd/patches/cainjection_in_awsmachinepools.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/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: awsmachinepools.infrastructure.cluster.x-k8s.io
17 changes: 17 additions & 0 deletions config/crd/patches/webhook_in_awsmachinepools.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The following patch enables conversion webhook for CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: awsmachinepools.infrastructure.cluster.x-k8s.io
spec:
conversion:
strategy: Webhook
webhookClientConfig:
# 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
2 changes: 1 addition & 1 deletion config/manager/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ spec:
args:
- "--metrics-addr=127.0.0.1:8080"
- "--enable-leader-election"
- "--feature-gates=EKS=${EXP_EKS:=false}"
- "--feature-gates=EKS=${EXP_EKS:=false},MachinePool=${EXP_MACHINE_POOL:=false}"
29 changes: 29 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ rules:
- get
- list
- watch
- apiGroups:
- exp.cluster.x-k8s.io
resources:
- machinepools
- machinepools/status
verbs:
- get
- list
- watch
- apiGroups:
- infrastructure.cluster.x-k8s.io
resources:
Expand All @@ -76,6 +85,26 @@ rules:
- get
- patch
- update
- apiGroups:
- infrastructure.cluster.x-k8s.io
resources:
- awsmachinepools
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- infrastructure.cluster.x-k8s.io
resources:
- awsmachinepools/status
verbs:
- get
- patch
- update
- apiGroups:
- infrastructure.cluster.x-k8s.io
resources:
Expand Down
5 changes: 5 additions & 0 deletions controllers/awsmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ type AWSMachineReconciler struct {
secretsManagerServiceFactory func(cloud.ClusterScoper) services.SecretsManagerInterface
}

const (
// AWSManagedControlPlaneRefKind is the string value indicating that a cluster is AWS managed
AWSManagedControlPlaneRefKind = "AWSManagedControlPlane"
)

func (r *AWSMachineReconciler) getEC2Service(scope scope.EC2Scope) services.EC2MachineInterface {
if r.ec2ServiceFactory != nil {
return r.ec2ServiceFactory(scope)
Expand Down
7 changes: 6 additions & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import (

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha3"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
logf "sigs.k8s.io/controller-runtime/pkg/log"

expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha3"
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha3"
// +kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -75,6 +77,9 @@ var _ = BeforeSuite(func(done Done) {
Expect(clusterv1.AddToScheme(scheme.Scheme)).To(Succeed())
Expect(infrav1.AddToScheme(scheme.Scheme)).To(Succeed())

err = expinfrav1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())

// +kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
Expand Down
175 changes: 175 additions & 0 deletions exp/api/v1alpha3/awsmachinepool_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha3

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha3"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
"sigs.k8s.io/cluster-api/errors"
)

const (
MachinePoolFinalizer = "awsmachinepool.infrastructure.cluster.x-k8s.io"
LaunchTemplateLatestVersion = "$Latest"
)

// AWSMachinePoolSpec defines the desired state of AWSMachinePool
type AWSMachinePoolSpec struct {
// ProviderID is the ARN of the associated ASG
// +optional
ProviderID string `json:"providerID,omitempty"`

// The minimum size of the group.
// +kubebuilder:default=1
// +kubebuilder:validation:Minimum=1
MinSize int32 `json:"minSize"`

// The maximum size of the group.
// +kubebuilder:default=1
// +kubebuilder:validation:Minimum=1
MaxSize int32 `json:"maxSize"`

// AvailabilityZones is an array of availability zones instances can run in
AvailabilityZones []string `json:"availabilityZones,omitempty"`

// Subnets is an array of subnet configurations
Subnets []infrav1.AWSResourceReference `json:"subnets,omitempty"`

// AdditionalTags is an optional set of tags to add to an instance, in addition to the ones added by default by the
// AWS provider.
// +optional
AdditionalTags infrav1.Tags `json:"additionalTags,omitempty"`

// AWSLaunchTemplate specifies the launch template and version to use when an instance is launched.
// +kubebuilder:validation:Required
AWSLaunchTemplate AWSLaunchTemplate `json:"awsLaunchTemplate"`

// MixedInstancesPolicy describes how multiple instance types will be used by the ASG.
MixedInstancesPolicy *MixedInstancesPolicy `json:"mixedInstancesPolicy,omitempty"`

// 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.
// +optional
ProviderIDList []string `json:"providerIDList,omitempty"`
}

// AWSMachinePoolStatus defines the observed state of AWSMachinePool
type AWSMachinePoolStatus struct {
// Ready is true when the provider resource is ready.
// +optional
Ready bool `json:"ready"`

// Replicas is the most recently observed number of replicas
// +optional
Replicas int32 `json:"replicas"`

// Conditions defines current service state of the AWSMachinePool.
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`

// The ID of the launch template
LaunchTemplateID string `json:"launchTemplateID,omitempty"`

// FailureReason will be set in the event that there is a terminal problem
// reconciling the Machine and will contain a succinct value suitable
// for machine interpretation.
//
// 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 Machine'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.
//
// Any transient errors that occur during the reconciliation of Machines
// can be added as events to the Machine object and/or logged in the
// controller's output.
// +optional
FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"`

// FailureMessage will be set in the event that there is a terminal problem
// reconciling the Machine and will contain a more verbose string suitable
// for logging and human consumption.
//
// 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 Machine'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.
//
// Any transient errors that occur during the reconciliation of Machines
// can be added as events to the Machine object and/or logged in the
// controller's output.
// +optional
FailureMessage *string `json:"failureMessage,omitempty"`

ASGStatus *ASGStatus `json:"asgStatus,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=awsmachinepools,scope=Namespaced,categories=cluster-api
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Machine ready status"
// +kubebuilder:printcolumn:name="Replicas",type="integer",JSONPath=".status.replicas",description="Machine ready status"
// +kubebuilder:printcolumn:name="MinSize",type="integer",JSONPath=".spec.minSize",description="Minimum instanes in ASG"
// +kubebuilder:printcolumn:name="MaxSize",type="integer",JSONPath=".spec.maxSize",description="Maximum instanes in ASG"
// +kubebuilder:printcolumn:name="LaunchTemplate ID",type="string",JSONPath=".status.launchTemplateID",description="Launch Template ID"

// AWSMachinePool is the Schema for the awsmachinepools API
type AWSMachinePool struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec AWSMachinePoolSpec `json:"spec,omitempty"`
Status AWSMachinePoolStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// AWSMachinePoolList contains a list of AWSMachinePool
type AWSMachinePoolList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []AWSMachinePool `json:"items"`
}

func init() {
SchemeBuilder.Register(&AWSMachinePool{}, &AWSMachinePoolList{})
}

func (r *AWSMachinePool) GetConditions() clusterv1.Conditions {
return r.Status.Conditions
}

func (r *AWSMachinePool) SetConditions(conditions clusterv1.Conditions) {
r.Status.Conditions = conditions
}

func (r *AWSMachinePool) GetObjectKind() schema.ObjectKind {
return &r.TypeMeta
}

func (r *AWSMachinePoolList) GetObjectKind() schema.ObjectKind {
return &r.TypeMeta
}
37 changes: 37 additions & 0 deletions exp/api/v1alpha3/conditions_consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha3

import clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"

const (
// ASGReadyCondition reports on current status of the autoscaling group. Ready indicates the group is provisioned
ASGReadyCondition clusterv1.ConditionType = "ASGReady"
// ASGNotFoundReason used when the autoscaling group couldn't be retrieved.
ASGNotFoundReason = "ASGNotFound"
// ASGProvisionFailedReason used for failures during autoscaling group provisioning.
ASGProvisionFailedReason = "ASGProvisionFailed"
// ASGDeletionInProgress ASG is in a deletion in progress state.
ASGDeletionInProgress = "ASGDeletionInProgress"

// LaunchTemplateReadyCondition represents the status of an AWSMachinePool's associated Launch Template
LaunchTemplateReadyCondition clusterv1.ConditionType = "LaunchTemplateReady"
// LaunchTemplateNotFoundReason is used when an associated Launch Template can't be found
LaunchTemplateNotFoundReason = "LaunchTemplateNotFound"
// LaunchTemplateCreateFailedReason used for failures during Launch Template creation
LaunchTemplateCreateFailedReason = "LaunchTemplateCreateFailed"
)
Loading

0 comments on commit f05273a

Please sign in to comment.