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