sigs.k8s.io/cluster-api-provider-azure@v1.17.0/api/v1beta1/azuremachine_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  	corev1 "k8s.io/api/core/v1"
    21  	"k8s.io/apimachinery/pkg/api/resource"
    22  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    23  	clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
    24  	"sigs.k8s.io/cluster-api/errors"
    25  )
    26  
    27  const (
    28  	// MachineFinalizer allows ReconcileAzureMachine to clean up Azure resources associated with AzureMachine before
    29  	// removing it from the apiserver.
    30  	MachineFinalizer = "azuremachine.infrastructure.cluster.x-k8s.io"
    31  )
    32  
    33  // AzureMachineSpec defines the desired state of AzureMachine.
    34  type AzureMachineSpec struct {
    35  	// ProviderID is the unique identifier as specified by the cloud provider.
    36  	// +optional
    37  	ProviderID *string `json:"providerID,omitempty"`
    38  
    39  	VMSize string `json:"vmSize"`
    40  
    41  	// FailureDomain is the failure domain unique identifier this Machine should be attached to,
    42  	// as defined in Cluster API. This relates to an Azure Availability Zone
    43  	// +optional
    44  	FailureDomain *string `json:"failureDomain,omitempty"`
    45  
    46  	// Image is used to provide details of an image to use during VM creation.
    47  	// If image details are omitted the image will default the Azure Marketplace "capi" offer,
    48  	// which is based on Ubuntu.
    49  	// +kubebuilder:validation:nullable
    50  	// +optional
    51  	Image *Image `json:"image,omitempty"`
    52  
    53  	// Identity is the type of identity used for the virtual machine.
    54  	// The type 'SystemAssigned' is an implicitly created identity.
    55  	// The generated identity will be assigned a Subscription contributor role.
    56  	// The type 'UserAssigned' is a standalone Azure resource provided by the user
    57  	// and assigned to the VM
    58  	// +kubebuilder:default=None
    59  	// +optional
    60  	Identity VMIdentity `json:"identity,omitempty"`
    61  
    62  	// UserAssignedIdentities is a list of standalone Azure identities provided by the user
    63  	// The lifecycle of a user-assigned identity is managed separately from the lifecycle of
    64  	// the AzureMachine.
    65  	// See https://learn.microsoft.com/azure/active-directory/managed-identities-azure-resources/how-to-manage-ua-identity-cli
    66  	// +optional
    67  	UserAssignedIdentities []UserAssignedIdentity `json:"userAssignedIdentities,omitempty"`
    68  
    69  	// SystemAssignedIdentityRole defines the role and scope to assign to the system-assigned identity.
    70  	// +optional
    71  	SystemAssignedIdentityRole *SystemAssignedIdentityRole `json:"systemAssignedIdentityRole,omitempty"`
    72  
    73  	// Deprecated: RoleAssignmentName should be set in the systemAssignedIdentityRole field.
    74  	// +optional
    75  	RoleAssignmentName string `json:"roleAssignmentName,omitempty"`
    76  
    77  	// OSDisk specifies the parameters for the operating system disk of the machine
    78  	OSDisk OSDisk `json:"osDisk"`
    79  
    80  	// DataDisk specifies the parameters that are used to add one or more data disks to the machine
    81  	// +optional
    82  	DataDisks []DataDisk `json:"dataDisks,omitempty"`
    83  
    84  	// SSHPublicKey is the SSH public key string, base64-encoded to add to a Virtual Machine. Linux only.
    85  	// Refer to documentation on how to set up SSH access on Windows instances.
    86  	// +optional
    87  	SSHPublicKey string `json:"sshPublicKey,omitempty"`
    88  
    89  	// AdditionalTags is an optional set of tags to add to an instance, in addition to the ones added by default by the
    90  	// Azure provider. If both the AzureCluster and the AzureMachine specify the same tag name with different values, the
    91  	// AzureMachine's value takes precedence.
    92  	// +optional
    93  	AdditionalTags Tags `json:"additionalTags,omitempty"`
    94  
    95  	// AdditionalCapabilities specifies additional capabilities enabled or disabled on the virtual machine.
    96  	// +optional
    97  	AdditionalCapabilities *AdditionalCapabilities `json:"additionalCapabilities,omitempty"`
    98  
    99  	// AllocatePublicIP allows the ability to create dynamic public ips for machines where this value is true.
   100  	// +optional
   101  	AllocatePublicIP bool `json:"allocatePublicIP,omitempty"`
   102  
   103  	// EnableIPForwarding enables IP Forwarding in Azure which is required for some CNI's to send traffic from a pods on one machine
   104  	// to another. This is required for IpV6 with Calico in combination with User Defined Routes (set by the Azure Cloud Controller
   105  	// manager). Default is false for disabled.
   106  	// +optional
   107  	EnableIPForwarding bool `json:"enableIPForwarding,omitempty"`
   108  
   109  	// Deprecated: AcceleratedNetworking should be set in the networkInterfaces field.
   110  	// +kubebuilder:validation:nullable
   111  	// +optional
   112  	AcceleratedNetworking *bool `json:"acceleratedNetworking,omitempty"`
   113  
   114  	// Diagnostics specifies the diagnostics settings for a virtual machine.
   115  	// If not specified then Boot diagnostics (Managed) will be enabled.
   116  	// +optional
   117  	Diagnostics *Diagnostics `json:"diagnostics,omitempty"`
   118  
   119  	// SpotVMOptions allows the ability to specify the Machine should use a Spot VM
   120  	// +optional
   121  	SpotVMOptions *SpotVMOptions `json:"spotVMOptions,omitempty"`
   122  
   123  	// SecurityProfile specifies the Security profile settings for a virtual machine.
   124  	// +optional
   125  	SecurityProfile *SecurityProfile `json:"securityProfile,omitempty"`
   126  
   127  	// Deprecated: SubnetName should be set in the networkInterfaces field.
   128  	// +optional
   129  	SubnetName string `json:"subnetName,omitempty"`
   130  
   131  	// DNSServers adds a list of DNS Server IP addresses to the VM NICs.
   132  	// +optional
   133  	DNSServers []string `json:"dnsServers,omitempty"`
   134  
   135  	// DisableExtensionOperations specifies whether extension operations should be disabled on the virtual machine.
   136  	// Use this setting only if VMExtensions are not supported by your image, as it disables CAPZ bootstrapping extension used for detecting Kubernetes bootstrap failure.
   137  	// This may only be set to True when no extensions are configured on the virtual machine.
   138  	// +optional
   139  	DisableExtensionOperations *bool `json:"disableExtensionOperations,omitempty"`
   140  
   141  	// VMExtensions specifies a list of extensions to be added to the virtual machine.
   142  	// +optional
   143  	VMExtensions []VMExtension `json:"vmExtensions,omitempty"`
   144  
   145  	// NetworkInterfaces specifies a list of network interface configurations.
   146  	// If left unspecified, the VM will get a single network interface with a
   147  	// single IPConfig in the subnet specified in the cluster's node subnet field.
   148  	// The primary interface will be the first networkInterface specified (index 0) in the list.
   149  	// +optional
   150  	NetworkInterfaces []NetworkInterface `json:"networkInterfaces,omitempty"`
   151  
   152  	// CapacityReservationGroupID specifies the capacity reservation group resource id that should be
   153  	// used for allocating the virtual machine.
   154  	// The field size should be greater than 0 and the field input must start with '/'.
   155  	// The input for capacityReservationGroupID must be similar to '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/capacityReservationGroups/{capacityReservationGroupName}'.
   156  	// The keys which are used should be among 'subscriptions', 'providers' and 'resourcegroups' followed by valid ID or names respectively.
   157  	// It is optional but may not be changed once set.
   158  	// +optional
   159  	CapacityReservationGroupID *string `json:"capacityReservationGroupID,omitempty"`
   160  }
   161  
   162  // SpotVMOptions defines the options relevant to running the Machine on Spot VMs.
   163  type SpotVMOptions struct {
   164  	// MaxPrice defines the maximum price the user is willing to pay for Spot VM instances
   165  	// +optional
   166  	MaxPrice *resource.Quantity `json:"maxPrice,omitempty"`
   167  
   168  	// EvictionPolicy defines the behavior of the virtual machine when it is evicted. It can be either Delete or Deallocate.
   169  	// +optional
   170  	EvictionPolicy *SpotEvictionPolicy `json:"evictionPolicy,omitempty"`
   171  }
   172  
   173  // SystemAssignedIdentityRole defines the role and scope to assign to the system assigned identity.
   174  type SystemAssignedIdentityRole struct {
   175  	// Name is the name of the role assignment to create for a system assigned identity. It can be any valid UUID.
   176  	// If not specified, a random UUID will be generated.
   177  	// +optional
   178  	Name string `json:"name,omitempty"`
   179  
   180  	// DefinitionID is the ID of the role definition to create for a system assigned identity. It can be an Azure built-in role or a custom role.
   181  	// Refer to built-in roles: https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles
   182  	// +optional
   183  	DefinitionID string `json:"definitionID,omitempty"`
   184  
   185  	// Scope is the scope that the role assignment or definition applies to. The scope can be any REST resource instance.
   186  	// If not specified, the scope will be the subscription.
   187  	// +optional
   188  	Scope string `json:"scope,omitempty"`
   189  }
   190  
   191  // AzureMachineStatus defines the observed state of AzureMachine.
   192  type AzureMachineStatus struct {
   193  	// Ready is true when the provider resource is ready.
   194  	// +optional
   195  	Ready bool `json:"ready"`
   196  
   197  	// Addresses contains the Azure instance associated addresses.
   198  	// +optional
   199  	Addresses []corev1.NodeAddress `json:"addresses,omitempty"`
   200  
   201  	// VMState is the provisioning state of the Azure virtual machine.
   202  	// +optional
   203  	VMState *ProvisioningState `json:"vmState,omitempty"`
   204  
   205  	// ErrorReason will be set in the event that there is a terminal problem
   206  	// reconciling the Machine and will contain a succinct value suitable
   207  	// for machine interpretation.
   208  	//
   209  	// This field should not be set for transitive errors that a controller
   210  	// faces that are expected to be fixed automatically over
   211  	// time (like service outages), but instead indicate that something is
   212  	// fundamentally wrong with the Machine's spec or the configuration of
   213  	// the controller, and that manual intervention is required. Examples
   214  	// of terminal errors would be invalid combinations of settings in the
   215  	// spec, values that are unsupported by the controller, or the
   216  	// responsible controller itself being critically misconfigured.
   217  	//
   218  	// Any transient errors that occur during the reconciliation of Machines
   219  	// can be added as events to the Machine object and/or logged in the
   220  	// controller's output.
   221  	// +optional
   222  	FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"`
   223  
   224  	// ErrorMessage will be set in the event that there is a terminal problem
   225  	// reconciling the Machine and will contain a more verbose string suitable
   226  	// for logging and human consumption.
   227  	//
   228  	// This field should not be set for transitive errors that a controller
   229  	// faces that are expected to be fixed automatically over
   230  	// time (like service outages), but instead indicate that something is
   231  	// fundamentally wrong with the Machine's spec or the configuration of
   232  	// the controller, and that manual intervention is required. Examples
   233  	// of terminal errors would be invalid combinations of settings in the
   234  	// spec, values that are unsupported by the controller, or the
   235  	// responsible controller itself being critically misconfigured.
   236  	//
   237  	// Any transient errors that occur during the reconciliation of Machines
   238  	// can be added as events to the Machine object and/or logged in the
   239  	// controller's output.
   240  	// +optional
   241  	FailureMessage *string `json:"failureMessage,omitempty"`
   242  
   243  	// Conditions defines current service state of the AzureMachine.
   244  	// +optional
   245  	Conditions clusterv1.Conditions `json:"conditions,omitempty"`
   246  
   247  	// LongRunningOperationStates saves the states for Azure long-running operations so they can be continued on the
   248  	// next reconciliation loop.
   249  	// +optional
   250  	LongRunningOperationStates Futures `json:"longRunningOperationStates,omitempty"`
   251  }
   252  
   253  // AdditionalCapabilities enables or disables a capability on the virtual machine.
   254  type AdditionalCapabilities struct {
   255  	// UltraSSDEnabled enables or disables Azure UltraSSD capability for the virtual machine.
   256  	// Defaults to true if Ultra SSD data disks are specified,
   257  	// otherwise it doesn't set the capability on the VM.
   258  	// +optional
   259  	UltraSSDEnabled *bool `json:"ultraSSDEnabled,omitempty"`
   260  }
   261  
   262  // +kubebuilder:object:root=true
   263  // +kubebuilder:printcolumn:name="Cluster",type="string",priority=1,JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this AzureMachine belongs"
   264  // +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
   265  // +kubebuilder:printcolumn:name="Severity",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].severity"
   266  // +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].reason"
   267  // +kubebuilder:printcolumn:name="Message",type="string",priority=1,JSONPath=".status.conditions[?(@.type=='Ready')].message"
   268  // +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.vmState",description="Azure VM provisioning state"
   269  // +kubebuilder:printcolumn:name="Machine",type="string",priority=1,JSONPath=".metadata.ownerReferences[?(@.kind==\"Machine\")].name",description="Machine object to which this AzureMachine belongs"
   270  // +kubebuilder:printcolumn:name="VM ID",type="string",priority=1,JSONPath=".spec.providerID",description="Azure VM ID"
   271  // +kubebuilder:printcolumn:name="VM Size",type="string",priority=1,JSONPath=".spec.vmSize",description="Azure VM Size"
   272  // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of this AzureMachine"
   273  // +kubebuilder:resource:path=azuremachines,scope=Namespaced,categories=cluster-api
   274  // +kubebuilder:storageversion
   275  // +kubebuilder:subresource:status
   276  
   277  // AzureMachine is the Schema for the azuremachines API.
   278  type AzureMachine struct {
   279  	metav1.TypeMeta   `json:",inline"`
   280  	metav1.ObjectMeta `json:"metadata,omitempty"`
   281  
   282  	Spec   AzureMachineSpec   `json:"spec,omitempty"`
   283  	Status AzureMachineStatus `json:"status,omitempty"`
   284  }
   285  
   286  // +kubebuilder:object:root=true
   287  
   288  // AzureMachineList contains a list of AzureMachine.
   289  type AzureMachineList struct {
   290  	metav1.TypeMeta `json:",inline"`
   291  	metav1.ListMeta `json:"metadata,omitempty"`
   292  	Items           []AzureMachine `json:"items"`
   293  }
   294  
   295  // GetConditions returns the list of conditions for an AzureMachine API object.
   296  func (m *AzureMachine) GetConditions() clusterv1.Conditions {
   297  	return m.Status.Conditions
   298  }
   299  
   300  // SetConditions will set the given conditions on an AzureMachine object.
   301  func (m *AzureMachine) SetConditions(conditions clusterv1.Conditions) {
   302  	m.Status.Conditions = conditions
   303  }
   304  
   305  // GetFutures returns the list of long running operation states for an AzureMachine API object.
   306  func (m *AzureMachine) GetFutures() Futures {
   307  	return m.Status.LongRunningOperationStates
   308  }
   309  
   310  // SetFutures will set the given long running operation states on an AzureMachine object.
   311  func (m *AzureMachine) SetFutures(futures Futures) {
   312  	m.Status.LongRunningOperationStates = futures
   313  }
   314  
   315  func init() {
   316  	SchemeBuilder.Register(&AzureMachine{}, &AzureMachineList{})
   317  }