sigs.k8s.io/cluster-api-provider-aws@v1.5.5/api/v1beta1/awsmachine_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  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    21  
    22  	clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
    23  	"sigs.k8s.io/cluster-api/errors"
    24  )
    25  
    26  const (
    27  	// MachineFinalizer allows ReconcileAWSMachine to clean up AWS resources associated with AWSMachine before
    28  	// removing it from the apiserver.
    29  	MachineFinalizer = "awsmachine.infrastructure.cluster.x-k8s.io"
    30  
    31  	// DefaultIgnitionVersion represents default Ignition version generated for machine userdata.
    32  	DefaultIgnitionVersion = "2.3"
    33  )
    34  
    35  // SecretBackend defines variants for backend secret storage.
    36  type SecretBackend string
    37  
    38  var (
    39  	// SecretBackendSSMParameterStore defines AWS Systems Manager Parameter Store as the secret backend.
    40  	SecretBackendSSMParameterStore = SecretBackend("ssm-parameter-store")
    41  
    42  	// SecretBackendSecretsManager defines AWS Secrets Manager as the secret backend.
    43  	SecretBackendSecretsManager = SecretBackend("secrets-manager")
    44  )
    45  
    46  // AWSMachineSpec defines the desired state of an Amazon EC2 instance.
    47  type AWSMachineSpec struct {
    48  	// ProviderID is the unique identifier as specified by the cloud provider.
    49  	ProviderID *string `json:"providerID,omitempty"`
    50  
    51  	// InstanceID is the EC2 instance ID for this machine.
    52  	InstanceID *string `json:"instanceID,omitempty"`
    53  
    54  	// AMI is the reference to the AMI from which to create the machine instance.
    55  	AMI AMIReference `json:"ami,omitempty"`
    56  
    57  	// ImageLookupFormat is the AMI naming format to look up the image for this
    58  	// machine It will be ignored if an explicit AMI is set. Supports
    59  	// substitutions for {{.BaseOS}} and {{.K8sVersion}} with the base OS and
    60  	// kubernetes version, respectively. The BaseOS will be the value in
    61  	// ImageLookupBaseOS or ubuntu (the default), and the kubernetes version as
    62  	// defined by the packages produced by kubernetes/release without v as a
    63  	// prefix: 1.13.0, 1.12.5-mybuild.1, or 1.17.3. For example, the default
    64  	// image format of capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-* will end up
    65  	// searching for AMIs that match the pattern capa-ami-ubuntu-?1.18.0-* for a
    66  	// Machine that is targeting kubernetes v1.18.0 and the ubuntu base OS. See
    67  	// also: https://golang.org/pkg/text/template/
    68  	// +optional
    69  	ImageLookupFormat string `json:"imageLookupFormat,omitempty"`
    70  
    71  	// ImageLookupOrg is the AWS Organization ID to use for image lookup if AMI is not set.
    72  	ImageLookupOrg string `json:"imageLookupOrg,omitempty"`
    73  
    74  	// ImageLookupBaseOS is the name of the base operating system to use for
    75  	// image lookup the AMI is not set.
    76  	ImageLookupBaseOS string `json:"imageLookupBaseOS,omitempty"`
    77  
    78  	// InstanceType is the type of instance to create. Example: m4.xlarge
    79  	// +kubebuilder:validation:Required
    80  	// +kubebuilder:validation:MinLength:=2
    81  	InstanceType string `json:"instanceType"`
    82  
    83  	// AdditionalTags is an optional set of tags to add to an instance, in addition to the ones added by default by the
    84  	// AWS provider. If both the AWSCluster and the AWSMachine specify the same tag name with different values, the
    85  	// AWSMachine's value takes precedence.
    86  	// +optional
    87  	AdditionalTags Tags `json:"additionalTags,omitempty"`
    88  
    89  	// IAMInstanceProfile is a name of an IAM instance profile to assign to the instance
    90  	// +optional
    91  	IAMInstanceProfile string `json:"iamInstanceProfile,omitempty"`
    92  
    93  	// PublicIP specifies whether the instance should get a public IP.
    94  	// Precedence for this setting is as follows:
    95  	// 1. This field if set
    96  	// 2. Cluster/flavor setting
    97  	// 3. Subnet default
    98  	// +optional
    99  	PublicIP *bool `json:"publicIP,omitempty"`
   100  
   101  	// AdditionalSecurityGroups is an array of references to security groups that should be applied to the
   102  	// instance. These security groups would be set in addition to any security groups defined
   103  	// at the cluster level or in the actuator. It is possible to specify either IDs of Filters. Using Filters
   104  	// will cause additional requests to AWS API and if tags change the attached security groups might change too.
   105  	// +optional
   106  	AdditionalSecurityGroups []AWSResourceReference `json:"additionalSecurityGroups,omitempty"`
   107  
   108  	// FailureDomain is the failure domain unique identifier this Machine should be attached to, as defined in Cluster API.
   109  	// For this infrastructure provider, the ID is equivalent to an AWS Availability Zone.
   110  	// If multiple subnets are matched for the availability zone, the first one returned is picked.
   111  	FailureDomain *string `json:"failureDomain,omitempty"`
   112  
   113  	// Subnet is a reference to the subnet to use for this instance. If not specified,
   114  	// the cluster subnet will be used.
   115  	// +optional
   116  	Subnet *AWSResourceReference `json:"subnet,omitempty"`
   117  
   118  	// SSHKeyName is the name of the ssh key to attach to the instance. Valid values are empty string (do not use SSH keys), a valid SSH key name, or omitted (use the default SSH key name)
   119  	// +optional
   120  	SSHKeyName *string `json:"sshKeyName,omitempty"`
   121  
   122  	// RootVolume encapsulates the configuration options for the root volume
   123  	// +optional
   124  	RootVolume *Volume `json:"rootVolume,omitempty"`
   125  
   126  	// Configuration options for the non root storage volumes.
   127  	// +optional
   128  	NonRootVolumes []Volume `json:"nonRootVolumes,omitempty"`
   129  
   130  	// NetworkInterfaces is a list of ENIs to associate with the instance.
   131  	// A maximum of 2 may be specified.
   132  	// +optional
   133  	// +kubebuilder:validation:MaxItems=2
   134  	NetworkInterfaces []string `json:"networkInterfaces,omitempty"`
   135  
   136  	// UncompressedUserData specify whether the user data is gzip-compressed before it is sent to ec2 instance.
   137  	// cloud-init has built-in support for gzip-compressed user data
   138  	// user data stored in aws secret manager is always gzip-compressed.
   139  	//
   140  	// +optional
   141  	UncompressedUserData *bool `json:"uncompressedUserData,omitempty"`
   142  
   143  	// CloudInit defines options related to the bootstrapping systems where
   144  	// CloudInit is used.
   145  	// +optional
   146  	CloudInit CloudInit `json:"cloudInit,omitempty"`
   147  
   148  	// Ignition defined options related to the bootstrapping systems where Ignition is used.
   149  	// +optional
   150  	Ignition *Ignition `json:"ignition,omitempty"`
   151  
   152  	// SpotMarketOptions allows users to configure instances to be run using AWS Spot instances.
   153  	// +optional
   154  	SpotMarketOptions *SpotMarketOptions `json:"spotMarketOptions,omitempty"`
   155  
   156  	// Tenancy indicates if instance should run on shared or single-tenant hardware.
   157  	// +optional
   158  	// +kubebuilder:validation:Enum:=default;dedicated;host
   159  	Tenancy string `json:"tenancy,omitempty"`
   160  }
   161  
   162  // CloudInit defines options related to the bootstrapping systems where
   163  // CloudInit is used.
   164  type CloudInit struct {
   165  	// InsecureSkipSecretsManager, when set to true will not use AWS Secrets Manager
   166  	// or AWS Systems Manager Parameter Store to ensure privacy of userdata.
   167  	// By default, a cloud-init boothook shell script is prepended to download
   168  	// the userdata from Secrets Manager and additionally delete the secret.
   169  	InsecureSkipSecretsManager bool `json:"insecureSkipSecretsManager,omitempty"`
   170  
   171  	// SecretCount is the number of secrets used to form the complete secret
   172  	// +optional
   173  	SecretCount int32 `json:"secretCount,omitempty"`
   174  
   175  	// SecretPrefix is the prefix for the secret name. This is stored
   176  	// temporarily, and deleted when the machine registers as a node against
   177  	// the workload cluster.
   178  	// +optional
   179  	SecretPrefix string `json:"secretPrefix,omitempty"`
   180  
   181  	// SecureSecretsBackend, when set to parameter-store will utilize the AWS Systems Manager
   182  	// Parameter Storage to distribute secrets. By default or with the value of secrets-manager,
   183  	// will use AWS Secrets Manager instead.
   184  	// +optional
   185  	// +kubebuilder:validation:Enum=secrets-manager;ssm-parameter-store
   186  	SecureSecretsBackend SecretBackend `json:"secureSecretsBackend,omitempty"`
   187  }
   188  
   189  // Ignition defines options related to the bootstrapping systems where Ignition is used.
   190  type Ignition struct {
   191  	// Version defines which version of Ignition will be used to generate bootstrap data.
   192  	//
   193  	// +optional
   194  	// +kubebuilder:default="2.3"
   195  	// +kubebuilder:validation:Enum="2.3"
   196  	Version string `json:"version,omitempty"`
   197  }
   198  
   199  // AWSMachineStatus defines the observed state of AWSMachine.
   200  type AWSMachineStatus struct {
   201  	// Ready is true when the provider resource is ready.
   202  	// +optional
   203  	Ready bool `json:"ready"`
   204  
   205  	// Interruptible reports that this machine is using spot instances and can therefore be interrupted by CAPI when it receives a notice that the spot instance is to be terminated by AWS.
   206  	// This will be set to true when SpotMarketOptions is not nil (i.e. this machine is using a spot instance).
   207  	// +optional
   208  	Interruptible bool `json:"interruptible,omitempty"`
   209  
   210  	// Addresses contains the AWS instance associated addresses.
   211  	Addresses []clusterv1.MachineAddress `json:"addresses,omitempty"`
   212  
   213  	// InstanceState is the state of the AWS instance for this machine.
   214  	// +optional
   215  	InstanceState *InstanceState `json:"instanceState,omitempty"`
   216  
   217  	// FailureReason will be set in the event that there is a terminal problem
   218  	// reconciling the Machine and will contain a succinct value suitable
   219  	// for machine interpretation.
   220  	//
   221  	// This field should not be set for transitive errors that a controller
   222  	// faces that are expected to be fixed automatically over
   223  	// time (like service outages), but instead indicate that something is
   224  	// fundamentally wrong with the Machine's spec or the configuration of
   225  	// the controller, and that manual intervention is required. Examples
   226  	// of terminal errors would be invalid combinations of settings in the
   227  	// spec, values that are unsupported by the controller, or the
   228  	// responsible controller itself being critically misconfigured.
   229  	//
   230  	// Any transient errors that occur during the reconciliation of Machines
   231  	// can be added as events to the Machine object and/or logged in the
   232  	// controller's output.
   233  	// +optional
   234  	FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"`
   235  
   236  	// FailureMessage will be set in the event that there is a terminal problem
   237  	// reconciling the Machine and will contain a more verbose string suitable
   238  	// for logging and human consumption.
   239  	//
   240  	// This field should not be set for transitive errors that a controller
   241  	// faces that are expected to be fixed automatically over
   242  	// time (like service outages), but instead indicate that something is
   243  	// fundamentally wrong with the Machine's spec or the configuration of
   244  	// the controller, and that manual intervention is required. Examples
   245  	// of terminal errors would be invalid combinations of settings in the
   246  	// spec, values that are unsupported by the controller, or the
   247  	// responsible controller itself being critically misconfigured.
   248  	//
   249  	// Any transient errors that occur during the reconciliation of Machines
   250  	// can be added as events to the Machine object and/or logged in the
   251  	// controller's output.
   252  	// +optional
   253  	FailureMessage *string `json:"failureMessage,omitempty"`
   254  
   255  	// Conditions defines current service state of the AWSMachine.
   256  	// +optional
   257  	Conditions clusterv1.Conditions `json:"conditions,omitempty"`
   258  }
   259  
   260  // +kubebuilder:object:root=true
   261  // +kubebuilder:resource:path=awsmachines,scope=Namespaced,categories=cluster-api,shortName=awsm
   262  // +kubebuilder:storageversion
   263  // +kubebuilder:subresource:status
   264  // +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this AWSMachine belongs"
   265  // +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.instanceState",description="EC2 instance state"
   266  // +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Machine ready status"
   267  // +kubebuilder:printcolumn:name="InstanceID",type="string",JSONPath=".spec.providerID",description="EC2 instance ID"
   268  // +kubebuilder:printcolumn:name="Machine",type="string",JSONPath=".metadata.ownerReferences[?(@.kind==\"Machine\")].name",description="Machine object which owns with this AWSMachine"
   269  // +k8s:defaulter-gen=true
   270  
   271  // AWSMachine is the schema for Amazon EC2 machines.
   272  type AWSMachine struct {
   273  	metav1.TypeMeta   `json:",inline"`
   274  	metav1.ObjectMeta `json:"metadata,omitempty"`
   275  
   276  	Spec   AWSMachineSpec   `json:"spec,omitempty"`
   277  	Status AWSMachineStatus `json:"status,omitempty"`
   278  }
   279  
   280  // GetConditions returns the observations of the operational state of the AWSMachine resource.
   281  func (r *AWSMachine) GetConditions() clusterv1.Conditions {
   282  	return r.Status.Conditions
   283  }
   284  
   285  // SetConditions sets the underlying service state of the AWSMachine to the predescribed clusterv1.Conditions.
   286  func (r *AWSMachine) SetConditions(conditions clusterv1.Conditions) {
   287  	r.Status.Conditions = conditions
   288  }
   289  
   290  // +kubebuilder:object:root=true
   291  
   292  // AWSMachineList contains a list of Amazon EC2 machines.
   293  type AWSMachineList struct {
   294  	metav1.TypeMeta `json:",inline"`
   295  	metav1.ListMeta `json:"metadata,omitempty"`
   296  	Items           []AWSMachine `json:"items"`
   297  }
   298  
   299  func init() {
   300  	SchemeBuilder.Register(&AWSMachine{}, &AWSMachineList{})
   301  }