sigs.k8s.io/cluster-api-provider-aws@v1.5.5/exp/api/v1beta1/awsmanagedmachinepool_types.go (about)

     1  /*
     2  Copyright 2021 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1beta1
    18  
    19  import (
    20  	"fmt"
    21  
    22  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    23  
    24  	infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
    25  	iamv1 "sigs.k8s.io/cluster-api-provider-aws/iam/api/v1beta1"
    26  	clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
    27  	"sigs.k8s.io/cluster-api/errors"
    28  )
    29  
    30  // ManagedMachineAMIType specifies which AWS AMI to use for a managed MachinePool.
    31  type ManagedMachineAMIType string
    32  
    33  const (
    34  	// Al2x86_64 is the default AMI type.
    35  	Al2x86_64 ManagedMachineAMIType = "AL2_x86_64"
    36  	// Al2x86_64GPU is the x86-64 GPU AMI type.
    37  	Al2x86_64GPU ManagedMachineAMIType = "AL2_x86_64_GPU"
    38  	// Al2Arm64 is the Arm AMI type.
    39  	Al2Arm64 ManagedMachineAMIType = "AL2_ARM_64"
    40  )
    41  
    42  // ManagedMachinePoolCapacityType specifies the capacity type to be used for the managed MachinePool.
    43  type ManagedMachinePoolCapacityType string
    44  
    45  const (
    46  	// ManagedMachinePoolCapacityTypeOnDemand is the default capacity type, to launch on-demand instances.
    47  	ManagedMachinePoolCapacityTypeOnDemand ManagedMachinePoolCapacityType = "onDemand"
    48  	// ManagedMachinePoolCapacityTypeSpot is the spot instance capacity type to launch spot instances.
    49  	ManagedMachinePoolCapacityTypeSpot ManagedMachinePoolCapacityType = "spot"
    50  )
    51  
    52  var (
    53  	// DefaultEKSNodegroupRole is the name of the default IAM role to use for EKS nodegroups
    54  	// if no other role is supplied in the spec and if iam role creation is not enabled. The default
    55  	// can be created using clusterawsadm or created manually.
    56  	DefaultEKSNodegroupRole = fmt.Sprintf("eks-nodegroup%s", iamv1.DefaultNameSuffix)
    57  )
    58  
    59  // AWSManagedMachinePoolSpec defines the desired state of AWSManagedMachinePool.
    60  type AWSManagedMachinePoolSpec struct {
    61  	// EKSNodegroupName specifies the name of the nodegroup in AWS
    62  	// corresponding to this MachinePool. If you don't specify a name
    63  	// then a default name will be created based on the namespace and
    64  	// name of the managed machine pool.
    65  	// +optional
    66  	EKSNodegroupName string `json:"eksNodegroupName,omitempty"`
    67  
    68  	// AvailabilityZones is an array of availability zones instances can run in
    69  	AvailabilityZones []string `json:"availabilityZones,omitempty"`
    70  
    71  	// SubnetIDs specifies which subnets are used for the
    72  	// auto scaling group of this nodegroup
    73  	// +optional
    74  	SubnetIDs []string `json:"subnetIDs,omitempty"`
    75  
    76  	// AdditionalTags is an optional set of tags to add to AWS resources managed by the AWS provider, in addition to the
    77  	// ones added by default.
    78  	// +optional
    79  	AdditionalTags infrav1.Tags `json:"additionalTags,omitempty"`
    80  
    81  	// RoleAdditionalPolicies allows you to attach additional polices to
    82  	// the node group role. You must enable the EKSAllowAddRoles
    83  	// feature flag to incorporate these into the created role.
    84  	// +optional
    85  	RoleAdditionalPolicies []string `json:"roleAdditionalPolicies,omitempty"`
    86  
    87  	// RoleName specifies the name of IAM role for the node group.
    88  	// If the role is pre-existing we will treat it as unmanaged
    89  	// and not delete it on deletion. If the EKSEnableIAM feature
    90  	// flag is true and no name is supplied then a role is created.
    91  	// +optional
    92  	RoleName string `json:"roleName,omitempty"`
    93  
    94  	// AMIVersion defines the desired AMI release version. If no version number
    95  	// is supplied then the latest version for the Kubernetes version
    96  	// will be used
    97  	// +kubebuilder:validation:MinLength:=2
    98  	// +optional
    99  	AMIVersion *string `json:"amiVersion,omitempty"`
   100  
   101  	// AMIType defines the AMI type
   102  	// +kubebuilder:validation:Enum:=AL2_x86_64;AL2_x86_64_GPU;AL2_ARM_64
   103  	// +kubebuilder:default:=AL2_x86_64
   104  	// +optional
   105  	AMIType *ManagedMachineAMIType `json:"amiType,omitempty"`
   106  
   107  	// Labels specifies labels for the Kubernetes node objects
   108  	// +optional
   109  	Labels map[string]string `json:"labels,omitempty"`
   110  
   111  	// Taints specifies the taints to apply to the nodes of the machine pool
   112  	// +optional
   113  	Taints Taints `json:"taints,omitempty"`
   114  
   115  	// DiskSize specifies the root disk size
   116  	// +optional
   117  	DiskSize *int32 `json:"diskSize,omitempty"`
   118  
   119  	// InstanceType specifies the AWS instance type
   120  	// +optional
   121  	InstanceType *string `json:"instanceType,omitempty"`
   122  
   123  	// Scaling specifies scaling for the ASG behind this pool
   124  	// +optional
   125  	Scaling *ManagedMachinePoolScaling `json:"scaling,omitempty"`
   126  
   127  	// RemoteAccess specifies how machines can be accessed remotely
   128  	// +optional
   129  	RemoteAccess *ManagedRemoteAccess `json:"remoteAccess,omitempty"`
   130  
   131  	// ProviderIDList are the provider IDs of instances in the
   132  	// autoscaling group corresponding to the nodegroup represented by this
   133  	// machine pool
   134  	// +optional
   135  	ProviderIDList []string `json:"providerIDList,omitempty"`
   136  
   137  	// CapacityType specifies the capacity type for the ASG behind this pool
   138  	// +kubebuilder:validation:Enum:=onDemand;spot
   139  	// +kubebuilder:default:=onDemand
   140  	// +optional
   141  	CapacityType *ManagedMachinePoolCapacityType `json:"capacityType,omitempty"`
   142  
   143  	// UpdateConfig holds the optional config to control the behaviour of the update
   144  	// to the nodegroup.
   145  	// +optional
   146  	UpdateConfig *UpdateConfig `json:"updateConfig,omitempty"`
   147  }
   148  
   149  // ManagedMachinePoolScaling specifies scaling options.
   150  type ManagedMachinePoolScaling struct {
   151  	MinSize *int32 `json:"minSize,omitempty"`
   152  	MaxSize *int32 `json:"maxSize,omitempty"`
   153  }
   154  
   155  // ManagedRemoteAccess specifies remote access settings for EC2 instances.
   156  type ManagedRemoteAccess struct {
   157  	// SSHKeyName specifies which EC2 SSH key can be used to access machines.
   158  	// If left empty, the key from the control plane is used.
   159  	SSHKeyName *string `json:"sshKeyName,omitempty"`
   160  
   161  	// SourceSecurityGroups specifies which security groups are allowed access
   162  	SourceSecurityGroups []string `json:"sourceSecurityGroups,omitempty"`
   163  
   164  	// Public specifies whether to open port 22 to the public internet
   165  	Public bool `json:"public,omitempty"`
   166  }
   167  
   168  // AWSManagedMachinePoolStatus defines the observed state of AWSManagedMachinePool.
   169  type AWSManagedMachinePoolStatus struct {
   170  	// Ready denotes that the AWSManagedMachinePool nodegroup has joined
   171  	// the cluster
   172  	// +kubebuilder:default=false
   173  	Ready bool `json:"ready"`
   174  
   175  	// Replicas is the most recently observed number of replicas.
   176  	// +optional
   177  	Replicas int32 `json:"replicas"`
   178  
   179  	// FailureReason will be set in the event that there is a terminal problem
   180  	// reconciling the MachinePool and will contain a succinct value suitable
   181  	// for machine interpretation.
   182  	//
   183  	// This field should not be set for transitive errors that a controller
   184  	// faces that are expected to be fixed automatically over
   185  	// time (like service outages), but instead indicate that something is
   186  	// fundamentally wrong with the Machine's spec or the configuration of
   187  	// the controller, and that manual intervention is required. Examples
   188  	// of terminal errors would be invalid combinations of settings in the
   189  	// spec, values that are unsupported by the controller, or the
   190  	// responsible controller itself being critically misconfigured.
   191  	//
   192  	// Any transient errors that occur during the reconciliation of MachinePools
   193  	// can be added as events to the MachinePool object and/or logged in the
   194  	// controller's output.
   195  	// +optional
   196  	FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"`
   197  
   198  	// FailureMessage will be set in the event that there is a terminal problem
   199  	// reconciling the MachinePool and will contain a more verbose string suitable
   200  	// for logging and human consumption.
   201  	//
   202  	// This field should not be set for transitive errors that a controller
   203  	// faces that are expected to be fixed automatically over
   204  	// time (like service outages), but instead indicate that something is
   205  	// fundamentally wrong with the MachinePool's spec or the configuration of
   206  	// the controller, and that manual intervention is required. Examples
   207  	// of terminal errors would be invalid combinations of settings in the
   208  	// spec, values that are unsupported by the controller, or the
   209  	// responsible controller itself being critically misconfigured.
   210  	//
   211  	// Any transient errors that occur during the reconciliation of MachinePools
   212  	// can be added as events to the MachinePool object and/or logged in the
   213  	// controller's output.
   214  	// +optional
   215  	FailureMessage *string `json:"failureMessage,omitempty"`
   216  
   217  	// Conditions defines current service state of the managed machine pool
   218  	// +optional
   219  	Conditions clusterv1.Conditions `json:"conditions,omitempty"`
   220  }
   221  
   222  // +kubebuilder:object:root=true
   223  // +kubebuilder:resource:path=awsmanagedmachinepools,scope=Namespaced,categories=cluster-api,shortName=awsmmp
   224  // +kubebuilder:storageversion
   225  // +kubebuilder:subresource:status
   226  // +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="MachinePool ready status"
   227  // +kubebuilder:printcolumn:name="Replicas",type="integer",JSONPath=".status.replicas",description="Number of replicas"
   228  
   229  // AWSManagedMachinePool is the Schema for the awsmanagedmachinepools API.
   230  type AWSManagedMachinePool struct {
   231  	metav1.TypeMeta   `json:",inline"`
   232  	metav1.ObjectMeta `json:"metadata,omitempty"`
   233  
   234  	Spec   AWSManagedMachinePoolSpec   `json:"spec,omitempty"`
   235  	Status AWSManagedMachinePoolStatus `json:"status,omitempty"`
   236  }
   237  
   238  // GetConditions returns the observations of the operational state of the AWSManagedMachinePool resource.
   239  func (r *AWSManagedMachinePool) GetConditions() clusterv1.Conditions {
   240  	return r.Status.Conditions
   241  }
   242  
   243  // SetConditions sets the underlying service state of the AWSManagedMachinePool to the predescribed clusterv1.Conditions.
   244  func (r *AWSManagedMachinePool) SetConditions(conditions clusterv1.Conditions) {
   245  	r.Status.Conditions = conditions
   246  }
   247  
   248  // +kubebuilder:object:root=true
   249  
   250  // AWSManagedMachinePoolList contains a list of AWSManagedMachinePools.
   251  type AWSManagedMachinePoolList struct {
   252  	metav1.TypeMeta `json:",inline"`
   253  	metav1.ListMeta `json:"metadata,omitempty"`
   254  	Items           []AWSManagedMachinePool `json:"items"`
   255  }
   256  
   257  func init() {
   258  	SchemeBuilder.Register(&AWSManagedMachinePool{}, &AWSManagedMachinePoolList{})
   259  }