sigs.k8s.io/cluster-api-provider-azure@v1.14.3/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"`
    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  	// VMExtensions specifies a list of extensions to be added to the virtual machine.
   136  	// +optional
   137  	VMExtensions []VMExtension `json:"vmExtensions,omitempty"`
   138  
   139  	// NetworkInterfaces specifies a list of network interface configurations.
   140  	// If left unspecified, the VM will get a single network interface with a
   141  	// single IPConfig in the subnet specified in the cluster's node subnet field.
   142  	// The primary interface will be the first networkInterface specified (index 0) in the list.
   143  	// +optional
   144  	NetworkInterfaces []NetworkInterface `json:"networkInterfaces,omitempty"`
   145  }
   146  
   147  // SpotVMOptions defines the options relevant to running the Machine on Spot VMs.
   148  type SpotVMOptions struct {
   149  	// MaxPrice defines the maximum price the user is willing to pay for Spot VM instances
   150  	// +optional
   151  	MaxPrice *resource.Quantity `json:"maxPrice,omitempty"`
   152  
   153  	// EvictionPolicy defines the behavior of the virtual machine when it is evicted. It can be either Delete or Deallocate.
   154  	// +optional
   155  	EvictionPolicy *SpotEvictionPolicy `json:"evictionPolicy,omitempty"`
   156  }
   157  
   158  // SystemAssignedIdentityRole defines the role and scope to assign to the system assigned identity.
   159  type SystemAssignedIdentityRole struct {
   160  	// Name is the name of the role assignment to create for a system assigned identity. It can be any valid UUID.
   161  	// If not specified, a random UUID will be generated.
   162  	// +optional
   163  	Name string `json:"name,omitempty"`
   164  
   165  	// 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.
   166  	// Refer to built-in roles: https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles
   167  	// +optional
   168  	DefinitionID string `json:"definitionID,omitempty"`
   169  
   170  	// Scope is the scope that the role assignment or definition applies to. The scope can be any REST resource instance.
   171  	// If not specified, the scope will be the subscription.
   172  	// +optional
   173  	Scope string `json:"scope,omitempty"`
   174  }
   175  
   176  // AzureMachineStatus defines the observed state of AzureMachine.
   177  type AzureMachineStatus struct {
   178  	// Ready is true when the provider resource is ready.
   179  	// +optional
   180  	Ready bool `json:"ready"`
   181  
   182  	// Addresses contains the Azure instance associated addresses.
   183  	// +optional
   184  	Addresses []corev1.NodeAddress `json:"addresses,omitempty"`
   185  
   186  	// VMState is the provisioning state of the Azure virtual machine.
   187  	// +optional
   188  	VMState *ProvisioningState `json:"vmState,omitempty"`
   189  
   190  	// ErrorReason will be set in the event that there is a terminal problem
   191  	// reconciling the Machine and will contain a succinct value suitable
   192  	// for machine interpretation.
   193  	//
   194  	// This field should not be set for transitive errors that a controller
   195  	// faces that are expected to be fixed automatically over
   196  	// time (like service outages), but instead indicate that something is
   197  	// fundamentally wrong with the Machine's spec or the configuration of
   198  	// the controller, and that manual intervention is required. Examples
   199  	// of terminal errors would be invalid combinations of settings in the
   200  	// spec, values that are unsupported by the controller, or the
   201  	// responsible controller itself being critically misconfigured.
   202  	//
   203  	// Any transient errors that occur during the reconciliation of Machines
   204  	// can be added as events to the Machine object and/or logged in the
   205  	// controller's output.
   206  	// +optional
   207  	FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"`
   208  
   209  	// ErrorMessage will be set in the event that there is a terminal problem
   210  	// reconciling the Machine and will contain a more verbose string suitable
   211  	// for logging and human consumption.
   212  	//
   213  	// This field should not be set for transitive errors that a controller
   214  	// faces that are expected to be fixed automatically over
   215  	// time (like service outages), but instead indicate that something is
   216  	// fundamentally wrong with the Machine's spec or the configuration of
   217  	// the controller, and that manual intervention is required. Examples
   218  	// of terminal errors would be invalid combinations of settings in the
   219  	// spec, values that are unsupported by the controller, or the
   220  	// responsible controller itself being critically misconfigured.
   221  	//
   222  	// Any transient errors that occur during the reconciliation of Machines
   223  	// can be added as events to the Machine object and/or logged in the
   224  	// controller's output.
   225  	// +optional
   226  	FailureMessage *string `json:"failureMessage,omitempty"`
   227  
   228  	// Conditions defines current service state of the AzureMachine.
   229  	// +optional
   230  	Conditions clusterv1.Conditions `json:"conditions,omitempty"`
   231  
   232  	// LongRunningOperationStates saves the states for Azure long-running operations so they can be continued on the
   233  	// next reconciliation loop.
   234  	// +optional
   235  	LongRunningOperationStates Futures `json:"longRunningOperationStates,omitempty"`
   236  }
   237  
   238  // AdditionalCapabilities enables or disables a capability on the virtual machine.
   239  type AdditionalCapabilities struct {
   240  	// UltraSSDEnabled enables or disables Azure UltraSSD capability for the virtual machine.
   241  	// Defaults to true if Ultra SSD data disks are specified,
   242  	// otherwise it doesn't set the capability on the VM.
   243  	// +optional
   244  	UltraSSDEnabled *bool `json:"ultraSSDEnabled,omitempty"`
   245  }
   246  
   247  // +kubebuilder:object:root=true
   248  // +kubebuilder:printcolumn:name="Cluster",type="string",priority=1,JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this AzureMachine belongs"
   249  // +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
   250  // +kubebuilder:printcolumn:name="Severity",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].severity"
   251  // +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].reason"
   252  // +kubebuilder:printcolumn:name="Message",type="string",priority=1,JSONPath=".status.conditions[?(@.type=='Ready')].message"
   253  // +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.vmState",description="Azure VM provisioning state"
   254  // +kubebuilder:printcolumn:name="Machine",type="string",priority=1,JSONPath=".metadata.ownerReferences[?(@.kind==\"Machine\")].name",description="Machine object to which this AzureMachine belongs"
   255  // +kubebuilder:printcolumn:name="VM ID",type="string",priority=1,JSONPath=".spec.providerID",description="Azure VM ID"
   256  // +kubebuilder:printcolumn:name="VM Size",type="string",priority=1,JSONPath=".spec.vmSize",description="Azure VM Size"
   257  // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of this AzureMachine"
   258  // +kubebuilder:resource:path=azuremachines,scope=Namespaced,categories=cluster-api
   259  // +kubebuilder:storageversion
   260  // +kubebuilder:subresource:status
   261  
   262  // AzureMachine is the Schema for the azuremachines API.
   263  type AzureMachine struct {
   264  	metav1.TypeMeta   `json:",inline"`
   265  	metav1.ObjectMeta `json:"metadata,omitempty"`
   266  
   267  	Spec   AzureMachineSpec   `json:"spec,omitempty"`
   268  	Status AzureMachineStatus `json:"status,omitempty"`
   269  }
   270  
   271  // +kubebuilder:object:root=true
   272  
   273  // AzureMachineList contains a list of AzureMachine.
   274  type AzureMachineList struct {
   275  	metav1.TypeMeta `json:",inline"`
   276  	metav1.ListMeta `json:"metadata,omitempty"`
   277  	Items           []AzureMachine `json:"items"`
   278  }
   279  
   280  // GetConditions returns the list of conditions for an AzureMachine API object.
   281  func (m *AzureMachine) GetConditions() clusterv1.Conditions {
   282  	return m.Status.Conditions
   283  }
   284  
   285  // SetConditions will set the given conditions on an AzureMachine object.
   286  func (m *AzureMachine) SetConditions(conditions clusterv1.Conditions) {
   287  	m.Status.Conditions = conditions
   288  }
   289  
   290  // GetFutures returns the list of long running operation states for an AzureMachine API object.
   291  func (m *AzureMachine) GetFutures() Futures {
   292  	return m.Status.LongRunningOperationStates
   293  }
   294  
   295  // SetFutures will set the given long running operation states on an AzureMachine object.
   296  func (m *AzureMachine) SetFutures(futures Futures) {
   297  	m.Status.LongRunningOperationStates = futures
   298  }
   299  
   300  func init() {
   301  	SchemeBuilder.Register(&AzureMachine{}, &AzureMachineList{})
   302  }