sigs.k8s.io/cluster-api-provider-aws@v1.5.5/exp/api/v1alpha4/awsmachinepool_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 v1alpha4
    18  
    19  import (
    20  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    21  	"k8s.io/apimachinery/pkg/runtime/schema"
    22  
    23  	infrav1alpha4 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha4"
    24  	clusterv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4"
    25  	"sigs.k8s.io/cluster-api/errors"
    26  )
    27  
    28  // Constants block.
    29  const (
    30  	// MachinePoolFinalizer is the finalizer for the machine pool.
    31  	MachinePoolFinalizer = "awsmachinepool.infrastructure.cluster.x-k8s.io"
    32  
    33  	// LaunchTemplateLatestVersion defines the launching of the latest version of the template.
    34  	LaunchTemplateLatestVersion = "$Latest"
    35  )
    36  
    37  // AWSMachinePoolSpec defines the desired state of AWSMachinePool
    38  type AWSMachinePoolSpec struct {
    39  	// ProviderID is the ARN of the associated ASG
    40  	// +optional
    41  	ProviderID string `json:"providerID,omitempty"`
    42  
    43  	// MinSize defines the minimum size of the group.
    44  	// +kubebuilder:default=1
    45  	// +kubebuilder:validation:Minimum=1
    46  	MinSize int32 `json:"minSize"`
    47  
    48  	// MaxSize defines the maximum size of the group.
    49  	// +kubebuilder:default=1
    50  	// +kubebuilder:validation:Minimum=1
    51  	MaxSize int32 `json:"maxSize"`
    52  
    53  	// AvailabilityZones is an array of availability zones instances can run in
    54  	AvailabilityZones []string `json:"availabilityZones,omitempty"`
    55  
    56  	// Subnets is an array of subnet configurations
    57  	// +optional
    58  	Subnets []infrav1alpha4.AWSResourceReference `json:"subnets,omitempty"`
    59  
    60  	// AdditionalTags is an optional set of tags to add to an instance, in addition to the ones added by default by the
    61  	// AWS provider.
    62  	// +optional
    63  	AdditionalTags infrav1alpha4.Tags `json:"additionalTags,omitempty"`
    64  
    65  	// AWSLaunchTemplate specifies the launch template and version to use when an instance is launched.
    66  	// +kubebuilder:validation:Required
    67  	AWSLaunchTemplate AWSLaunchTemplate `json:"awsLaunchTemplate"`
    68  
    69  	// MixedInstancesPolicy describes how multiple instance types will be used by the ASG.
    70  	MixedInstancesPolicy *MixedInstancesPolicy `json:"mixedInstancesPolicy,omitempty"`
    71  
    72  	// ProviderIDList are the identification IDs of machine instances provided by the provider.
    73  	// This field must match the provider IDs as seen on the node objects corresponding to a machine pool's machine instances.
    74  	// +optional
    75  	ProviderIDList []string `json:"providerIDList,omitempty"`
    76  
    77  	// The amount of time, in seconds, after a scaling activity completes before another scaling activity can start.
    78  	// If no value is supplied by user a default value of 300 seconds is set
    79  	// +optional
    80  	DefaultCoolDown metav1.Duration `json:"defaultCoolDown,omitempty"`
    81  
    82  	// RefreshPreferences describes set of preferences associated with the instance refresh request.
    83  	// +optional
    84  	RefreshPreferences *RefreshPreferences `json:"refreshPreferences,omitempty"`
    85  
    86  	// Enable or disable the capacity rebalance autoscaling group feature
    87  	// +optional
    88  	CapacityRebalance bool `json:"capacityRebalance,omitempty"`
    89  }
    90  
    91  // RefreshPreferences defines the specs for instance refreshing.
    92  type RefreshPreferences struct {
    93  	// The strategy to use for the instance refresh. The only valid value is Rolling.
    94  	// A rolling update is an update that is applied to all instances in an Auto
    95  	// Scaling group until all instances have been updated.
    96  	// +optional
    97  	Strategy *string `json:"strategy,omitempty"`
    98  
    99  	// The number of seconds until a newly launched instance is configured and ready
   100  	// to use. During this time, the next replacement will not be initiated.
   101  	// The default is to use the value for the health check grace period defined for the group.
   102  	// +optional
   103  	InstanceWarmup *int64 `json:"instanceWarmup,omitempty"`
   104  
   105  	// The amount of capacity as a percentage in ASG that must remain healthy
   106  	// during an instance refresh. The default is 90.
   107  	// +optional
   108  	MinHealthyPercentage *int64 `json:"minHealthyPercentage,omitempty"`
   109  }
   110  
   111  // AWSMachinePoolStatus defines the observed state of AWSMachinePool
   112  type AWSMachinePoolStatus struct {
   113  	// Ready is true when the provider resource is ready.
   114  	// +optional
   115  	Ready bool `json:"ready"`
   116  
   117  	// Replicas is the most recently observed number of replicas
   118  	// +optional
   119  	Replicas int32 `json:"replicas"`
   120  
   121  	// Conditions defines current service state of the AWSMachinePool.
   122  	// +optional
   123  	Conditions clusterv1alpha4.Conditions `json:"conditions,omitempty"`
   124  
   125  	// Instances contains the status for each instance in the pool
   126  	// +optional
   127  	Instances []AWSMachinePoolInstanceStatus `json:"instances,omitempty"`
   128  
   129  	// The ID of the launch template
   130  	LaunchTemplateID string `json:"launchTemplateID,omitempty"`
   131  
   132  	// FailureReason will be set in the event that there is a terminal problem
   133  	// reconciling the Machine and will contain a succinct value suitable
   134  	// for machine interpretation.
   135  	//
   136  	// This field should not be set for transitive errors that a controller
   137  	// faces that are expected to be fixed automatically over
   138  	// time (like service outages), but instead indicate that something is
   139  	// fundamentally wrong with the Machine's spec or the configuration of
   140  	// the controller, and that manual intervention is required. Examples
   141  	// of terminal errors would be invalid combinations of settings in the
   142  	// spec, values that are unsupported by the controller, or the
   143  	// responsible controller itself being critically misconfigured.
   144  	//
   145  	// Any transient errors that occur during the reconciliation of Machines
   146  	// can be added as events to the Machine object and/or logged in the
   147  	// controller's output.
   148  	// +optional
   149  	FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"`
   150  
   151  	// FailureMessage will be set in the event that there is a terminal problem
   152  	// reconciling the Machine and will contain a more verbose string suitable
   153  	// for logging and human consumption.
   154  	//
   155  	// This field should not be set for transitive errors that a controller
   156  	// faces that are expected to be fixed automatically over
   157  	// time (like service outages), but instead indicate that something is
   158  	// fundamentally wrong with the Machine's spec or the configuration of
   159  	// the controller, and that manual intervention is required. Examples
   160  	// of terminal errors would be invalid combinations of settings in the
   161  	// spec, values that are unsupported by the controller, or the
   162  	// responsible controller itself being critically misconfigured.
   163  	//
   164  	// Any transient errors that occur during the reconciliation of Machines
   165  	// can be added as events to the Machine object and/or logged in the
   166  	// controller's output.
   167  	// +optional
   168  	FailureMessage *string `json:"failureMessage,omitempty"`
   169  
   170  	ASGStatus *ASGStatus `json:"asgStatus,omitempty"`
   171  }
   172  
   173  // AWSMachinePoolInstanceStatus defines the status of the AWSMachinePoolInstance.
   174  type AWSMachinePoolInstanceStatus struct {
   175  	// InstanceID is the identification of the Machine Instance within ASG
   176  	// +optional
   177  	InstanceID string `json:"instanceID,omitempty"`
   178  
   179  	// Version defines the Kubernetes version for the Machine Instance
   180  	// +optional
   181  	Version *string `json:"version,omitempty"`
   182  }
   183  
   184  // +kubebuilder:object:root=true
   185  // +kubebuilder:subresource:status
   186  // +kubebuilder:resource:path=awsmachinepools,scope=Namespaced,categories=cluster-api,shortName=awsmp
   187  // +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Machine ready status"
   188  // +kubebuilder:printcolumn:name="Replicas",type="integer",JSONPath=".status.replicas",description="Machine ready status"
   189  // +kubebuilder:printcolumn:name="MinSize",type="integer",JSONPath=".spec.minSize",description="Minimum instanes in ASG"
   190  // +kubebuilder:printcolumn:name="MaxSize",type="integer",JSONPath=".spec.maxSize",description="Maximum instanes in ASG"
   191  // +kubebuilder:printcolumn:name="LaunchTemplate ID",type="string",JSONPath=".status.launchTemplateID",description="Launch Template ID"
   192  
   193  // AWSMachinePool is the Schema for the awsmachinepools API
   194  type AWSMachinePool struct {
   195  	metav1.TypeMeta   `json:",inline"`
   196  	metav1.ObjectMeta `json:"metadata,omitempty"`
   197  
   198  	Spec   AWSMachinePoolSpec   `json:"spec,omitempty"`
   199  	Status AWSMachinePoolStatus `json:"status,omitempty"`
   200  }
   201  
   202  // +kubebuilder:object:root=true
   203  
   204  // AWSMachinePoolList contains a list of AWSMachinePool.
   205  type AWSMachinePoolList struct {
   206  	metav1.TypeMeta `json:",inline"`
   207  	metav1.ListMeta `json:"metadata,omitempty"`
   208  	Items           []AWSMachinePool `json:"items"`
   209  }
   210  
   211  func init() {
   212  	SchemeBuilder.Register(&AWSMachinePool{}, &AWSMachinePoolList{})
   213  }
   214  
   215  // GetConditions returns the observations of the operational state of the AWSMachinePool resource.
   216  func (r *AWSMachinePool) GetConditions() clusterv1alpha4.Conditions {
   217  	return r.Status.Conditions
   218  }
   219  
   220  // SetConditions sets the underlying service state of the AWSMachinePool to the predescribed clusterv1alpha4.Conditions.
   221  func (r *AWSMachinePool) SetConditions(conditions clusterv1alpha4.Conditions) {
   222  	r.Status.Conditions = conditions
   223  }
   224  
   225  // GetObjectKind will return the ObjectKind of an AWSMachinePool.
   226  func (r *AWSMachinePool) GetObjectKind() schema.ObjectKind {
   227  	return &r.TypeMeta
   228  }
   229  
   230  // GetObjectKind will return the ObjectKind of an AWSMachinePoolList.
   231  func (r *AWSMachinePoolList) GetObjectKind() schema.ObjectKind {
   232  	return &r.TypeMeta
   233  }