From 481de03a42c846dd79028282ddfb7270041d5dcd Mon Sep 17 00:00:00 2001 From: Cecile Robert-Michon Date: Tue, 19 Oct 2021 16:06:25 -0700 Subject: [PATCH] Audit API to follow CAPI conventions --- api/v1alpha3/zz_generated.conversion.go | 58 --------- api/v1alpha4/zz_generated.conversion.go | 58 --------- api/v1beta1/azurecluster_types.go | 4 +- api/v1beta1/azuremachine_types.go | 3 + api/v1beta1/types.go | 121 +++++++++++------- api/v1beta1/zz_generated.deepcopy.go | 29 ----- azure/converters/vm.go | 25 +++- .../virtualmachines/virtualmachines.go | 2 +- .../virtualmachines/virtualmachines_test.go | 13 +- ...ucture.cluster.x-k8s.io_azureclusters.yaml | 53 +++++++- ...ter.x-k8s.io_azuremachinepoolmachines.yaml | 1 + ...re.cluster.x-k8s.io_azuremachinepools.yaml | 1 + ...ucture.cluster.x-k8s.io_azuremachines.yaml | 1 + ...er.x-k8s.io_azuremanagedcontrolplanes.yaml | 1 + .../v1beta1/azuremanagedcontrolplane_types.go | 11 +- .../v1beta1/azuremanagedmachinepool_types.go | 1 + 16 files changed, 169 insertions(+), 213 deletions(-) diff --git a/api/v1alpha3/zz_generated.conversion.go b/api/v1alpha3/zz_generated.conversion.go index 687c5b5de30..921b7d26858 100644 --- a/api/v1alpha3/zz_generated.conversion.go +++ b/api/v1alpha3/zz_generated.conversion.go @@ -290,16 +290,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*VM)(nil), (*v1beta1.VM)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha3_VM_To_v1beta1_VM(a.(*VM), b.(*v1beta1.VM), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta1.VM)(nil), (*VM)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_VM_To_v1alpha3_VM(a.(*v1beta1.VM), b.(*VM), scope) - }); err != nil { - return err - } if err := s.AddConversionFunc((*AzureClusterIdentitySpec)(nil), (*v1beta1.AzureClusterIdentitySpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_AzureClusterIdentitySpec_To_v1beta1_AzureClusterIdentitySpec(a.(*AzureClusterIdentitySpec), b.(*v1beta1.AzureClusterIdentitySpec), scope) }); err != nil { @@ -1549,54 +1539,6 @@ func Convert_v1beta1_UserAssignedIdentity_To_v1alpha3_UserAssignedIdentity(in *v return autoConvert_v1beta1_UserAssignedIdentity_To_v1alpha3_UserAssignedIdentity(in, out, s) } -func autoConvert_v1alpha3_VM_To_v1beta1_VM(in *VM, out *v1beta1.VM, s conversion.Scope) error { - out.ID = in.ID - out.Name = in.Name - out.AvailabilityZone = in.AvailabilityZone - out.VMSize = in.VMSize - if err := Convert_v1alpha3_Image_To_v1beta1_Image(&in.Image, &out.Image, s); err != nil { - return err - } - if err := Convert_v1alpha3_OSDisk_To_v1beta1_OSDisk(&in.OSDisk, &out.OSDisk, s); err != nil { - return err - } - out.StartupScript = in.StartupScript - out.State = v1beta1.ProvisioningState(in.State) - out.Identity = v1beta1.VMIdentity(in.Identity) - out.Tags = *(*v1beta1.Tags)(unsafe.Pointer(&in.Tags)) - out.Addresses = *(*[]v1.NodeAddress)(unsafe.Pointer(&in.Addresses)) - return nil -} - -// Convert_v1alpha3_VM_To_v1beta1_VM is an autogenerated conversion function. -func Convert_v1alpha3_VM_To_v1beta1_VM(in *VM, out *v1beta1.VM, s conversion.Scope) error { - return autoConvert_v1alpha3_VM_To_v1beta1_VM(in, out, s) -} - -func autoConvert_v1beta1_VM_To_v1alpha3_VM(in *v1beta1.VM, out *VM, s conversion.Scope) error { - out.ID = in.ID - out.Name = in.Name - out.AvailabilityZone = in.AvailabilityZone - out.VMSize = in.VMSize - if err := Convert_v1beta1_Image_To_v1alpha3_Image(&in.Image, &out.Image, s); err != nil { - return err - } - if err := Convert_v1beta1_OSDisk_To_v1alpha3_OSDisk(&in.OSDisk, &out.OSDisk, s); err != nil { - return err - } - out.StartupScript = in.StartupScript - out.State = VMState(in.State) - out.Identity = VMIdentity(in.Identity) - out.Tags = *(*Tags)(unsafe.Pointer(&in.Tags)) - out.Addresses = *(*[]v1.NodeAddress)(unsafe.Pointer(&in.Addresses)) - return nil -} - -// Convert_v1beta1_VM_To_v1alpha3_VM is an autogenerated conversion function. -func Convert_v1beta1_VM_To_v1alpha3_VM(in *v1beta1.VM, out *VM, s conversion.Scope) error { - return autoConvert_v1beta1_VM_To_v1alpha3_VM(in, out, s) -} - func autoConvert_v1alpha3_VnetSpec_To_v1beta1_VnetSpec(in *VnetSpec, out *v1beta1.VnetSpec, s conversion.Scope) error { out.ResourceGroup = in.ResourceGroup out.ID = in.ID diff --git a/api/v1alpha4/zz_generated.conversion.go b/api/v1alpha4/zz_generated.conversion.go index 09b1c705bc3..83616ef0083 100644 --- a/api/v1alpha4/zz_generated.conversion.go +++ b/api/v1alpha4/zz_generated.conversion.go @@ -501,16 +501,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*VM)(nil), (*v1beta1.VM)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_VM_To_v1beta1_VM(a.(*VM), b.(*v1beta1.VM), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta1.VM)(nil), (*VM)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_VM_To_v1alpha4_VM(a.(*v1beta1.VM), b.(*VM), scope) - }); err != nil { - return err - } if err := s.AddConversionFunc((*VnetSpec)(nil), (*v1beta1.VnetSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha4_VnetSpec_To_v1beta1_VnetSpec(a.(*VnetSpec), b.(*v1beta1.VnetSpec), scope) }); err != nil { @@ -1938,54 +1928,6 @@ func Convert_v1beta1_UserAssignedIdentity_To_v1alpha4_UserAssignedIdentity(in *v return autoConvert_v1beta1_UserAssignedIdentity_To_v1alpha4_UserAssignedIdentity(in, out, s) } -func autoConvert_v1alpha4_VM_To_v1beta1_VM(in *VM, out *v1beta1.VM, s conversion.Scope) error { - out.ID = in.ID - out.Name = in.Name - out.AvailabilityZone = in.AvailabilityZone - out.VMSize = in.VMSize - if err := Convert_v1alpha4_Image_To_v1beta1_Image(&in.Image, &out.Image, s); err != nil { - return err - } - if err := Convert_v1alpha4_OSDisk_To_v1beta1_OSDisk(&in.OSDisk, &out.OSDisk, s); err != nil { - return err - } - out.StartupScript = in.StartupScript - out.State = v1beta1.ProvisioningState(in.State) - out.Identity = v1beta1.VMIdentity(in.Identity) - out.Tags = *(*v1beta1.Tags)(unsafe.Pointer(&in.Tags)) - out.Addresses = *(*[]corev1.NodeAddress)(unsafe.Pointer(&in.Addresses)) - return nil -} - -// Convert_v1alpha4_VM_To_v1beta1_VM is an autogenerated conversion function. -func Convert_v1alpha4_VM_To_v1beta1_VM(in *VM, out *v1beta1.VM, s conversion.Scope) error { - return autoConvert_v1alpha4_VM_To_v1beta1_VM(in, out, s) -} - -func autoConvert_v1beta1_VM_To_v1alpha4_VM(in *v1beta1.VM, out *VM, s conversion.Scope) error { - out.ID = in.ID - out.Name = in.Name - out.AvailabilityZone = in.AvailabilityZone - out.VMSize = in.VMSize - if err := Convert_v1beta1_Image_To_v1alpha4_Image(&in.Image, &out.Image, s); err != nil { - return err - } - if err := Convert_v1beta1_OSDisk_To_v1alpha4_OSDisk(&in.OSDisk, &out.OSDisk, s); err != nil { - return err - } - out.StartupScript = in.StartupScript - out.State = ProvisioningState(in.State) - out.Identity = VMIdentity(in.Identity) - out.Tags = *(*Tags)(unsafe.Pointer(&in.Tags)) - out.Addresses = *(*[]corev1.NodeAddress)(unsafe.Pointer(&in.Addresses)) - return nil -} - -// Convert_v1beta1_VM_To_v1alpha4_VM is an autogenerated conversion function. -func Convert_v1beta1_VM_To_v1alpha4_VM(in *v1beta1.VM, out *VM, s conversion.Scope) error { - return autoConvert_v1beta1_VM_To_v1alpha4_VM(in, out, s) -} - func autoConvert_v1alpha4_VnetSpec_To_v1beta1_VnetSpec(in *VnetSpec, out *v1beta1.VnetSpec, s conversion.Scope) error { out.ResourceGroup = in.ResourceGroup out.ID = in.ID diff --git a/api/v1beta1/azurecluster_types.go b/api/v1beta1/azurecluster_types.go index 0c9e50e9303..e3d980452ae 100644 --- a/api/v1beta1/azurecluster_types.go +++ b/api/v1beta1/azurecluster_types.go @@ -34,6 +34,7 @@ const ( // AzureClusterSpec defines the desired state of AzureCluster. type AzureClusterSpec struct { // NetworkSpec encapsulates all things related to Azure network. + // +optional NetworkSpec NetworkSpec `json:"networkSpec,omitempty"` // +optional @@ -46,7 +47,7 @@ type AzureClusterSpec struct { // ControlPlaneEndpoint represents the endpoint used to communicate with the control plane. // +optional - ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"` + ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint,omitempty"` // AdditionalTags is an optional set of tags to add to Azure resources managed by the Azure provider, in addition to the // ones added by default. @@ -87,6 +88,7 @@ type AzureClusterStatus struct { // the cluster is more resilient to failure. // See: https://docs.microsoft.com/en-us/azure/availability-zones/az-overview // This list will be used by Cluster API to try and spread the machines across the failure domains. + // +optional FailureDomains clusterv1.FailureDomains `json:"failureDomains,omitempty"` // Ready is true when the provider resource is ready. diff --git a/api/v1beta1/azuremachine_types.go b/api/v1beta1/azuremachine_types.go index 7478d7c369c..e8b9a0a365a 100644 --- a/api/v1beta1/azuremachine_types.go +++ b/api/v1beta1/azuremachine_types.go @@ -40,6 +40,7 @@ type AzureMachineSpec struct { // FailureDomain is the failure domain unique identifier this Machine should be attached to, // as defined in Cluster API. This relates to an Azure Availability Zone + // +optional FailureDomain *string `json:"failureDomain,omitempty"` // Image is used to provide details of an image to use during VM creation. @@ -74,6 +75,7 @@ type AzureMachineSpec struct { OSDisk OSDisk `json:"osDisk"` // DataDisk specifies the parameters that are used to add one or more data disks to the machine + // +optional DataDisks []DataDisk `json:"dataDisks,omitempty"` SSHPublicKey string `json:"sshPublicKey"` @@ -128,6 +130,7 @@ type AzureMachineStatus struct { Ready bool `json:"ready"` // Addresses contains the Azure instance associated addresses. + // +optional Addresses []v1.NodeAddress `json:"addresses,omitempty"` // VMState is the provisioning state of the Azure virtual machine. diff --git a/api/v1beta1/types.go b/api/v1beta1/types.go index 85637aa49fe..3720a21189f 100644 --- a/api/v1beta1/types.go +++ b/api/v1beta1/types.go @@ -18,7 +18,6 @@ package v1beta1 import ( "github.com/pkg/errors" - corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" ) @@ -59,7 +58,7 @@ type Future struct { Name string `json:"name"` // Data is the base64 url encoded json Azure AutoRest Future. - Data string `json:"data,omitempty"` + Data string `json:"data"` } // NetworkSpec specifies what the Azure networking resources should look like. @@ -94,9 +93,12 @@ type NetworkSpec struct { type VnetSpec struct { // ResourceGroup is the name of the resource group of the existing virtual network // or the resource group where a managed virtual network should be created. + // +optional ResourceGroup string `json:"resourceGroup,omitempty"` - // ID is the identifier of the virtual network this provider should use to create resources. + // ID is the Azure resource ID of the virtual network. + // READ-ONLY + // +optional ID string `json:"id,omitempty"` // Name defines a name for the virtual network resource. @@ -138,23 +140,35 @@ type Subnets []SubnetSpec // SecurityGroup defines an Azure security group. type SecurityGroup struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` + // ID is the Azure resource ID of the security group. + // READ-ONLY + // +optional + ID string `json:"id,omitempty"` + Name string `json:"name"` + // +optional SecurityRules SecurityRules `json:"securityRules,omitempty"` - Tags Tags `json:"tags,omitempty"` + // +optional + Tags Tags `json:"tags,omitempty"` } // RouteTable defines an Azure route table. type RouteTable struct { + // ID is the Azure resource ID of the route table. + // READ-ONLY + // +optional ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` + Name string `json:"name"` } // NatGateway defines an Azure Nat Gateway. // NAT gateway resources are part of Vnet NAT and provide outbound Internet connectivity for subnets of a virtual network. type NatGateway struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` + // ID is the Azure resource ID of the nat gateway. + // READ-ONLY + // +optional + ID string `json:"id,omitempty"` + Name string `json:"name"` + // +optional NatGatewayIP PublicIPSpec `json:"ip,omitempty"` } @@ -196,14 +210,19 @@ type SecurityRule struct { // +kubebuilder:validation:Enum=Inbound;Outbound Direction SecurityRuleDirection `json:"direction"` // Priority is a number between 100 and 4096. Each rule should have a unique value for priority. Rules are processed in priority order, with lower numbers processed before higher numbers. Once traffic matches a rule, processing stops. + // +optional Priority int32 `json:"priority,omitempty"` // SourcePorts specifies source port or range. Integer or range between 0 and 65535. Asterix '*' can also be used to match all ports. + // +optional SourcePorts *string `json:"sourcePorts,omitempty"` // DestinationPorts specifies the destination port or range. Integer or range between 0 and 65535. Asterix '*' can also be used to match all ports. + // +optional DestinationPorts *string `json:"destinationPorts,omitempty"` // Source specifies the CIDR or source IP range. Asterix '*' can also be used to match all source IPs. Default tags such as 'VirtualNetwork', 'AzureLoadBalancer' and 'Internet' can also be used. If this is an ingress rule, specifies where network traffic originates from. + // +optional Source *string `json:"source,omitempty"` // Destination is the destination address prefix. CIDR or destination IP range. Asterix '*' can also be used to match all source IPs. Default tags such as 'VirtualNetwork', 'AzureLoadBalancer' and 'Internet' can also be used. + // +optional Destination *string `json:"destination,omitempty"` } @@ -212,14 +231,22 @@ type SecurityRules []SecurityRule // LoadBalancerSpec defines an Azure load balancer. type LoadBalancerSpec struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - SKU SKU `json:"sku,omitempty"` + // ID is the Azure resource ID of the load balancer. + // READ-ONLY + // +optional + ID string `json:"id,omitempty"` + Name string `json:"name"` + // +optional + SKU SKU `json:"sku,omitempty"` + // +optional FrontendIPs []FrontendIP `json:"frontendIPs,omitempty"` - Type LBType `json:"type,omitempty"` + // +optional + Type LBType `json:"type,omitempty"` // FrontendIPsCount specifies the number of frontend IP addresses for the load balancer. + // +optional FrontendIPsCount *int32 `json:"frontendIPsCount,omitempty"` // IdleTimeoutInMinutes specifies the timeout for the TCP idle connection. + // +optional IdleTimeoutInMinutes *int32 `json:"idleTimeoutInMinutes,omitempty"` } @@ -285,26 +312,6 @@ const ( Deleted ProvisioningState = "Deleted" ) -// VM describes an Azure virtual machine. -type VM struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - AvailabilityZone string `json:"availabilityZone,omitempty"` - // Hardware profile - VMSize string `json:"vmSize,omitempty"` - // Storage profile - Image Image `json:"image,omitempty"` - OSDisk OSDisk `json:"osDisk,omitempty"` - StartupScript string `json:"startupScript,omitempty"` - // State - The provisioning state, which only appears in the response. - State ProvisioningState `json:"vmState,omitempty"` - Identity VMIdentity `json:"identity,omitempty"` - Tags Tags `json:"tags,omitempty"` - - // Addresses contains the addresses associated with the Azure VM. - Addresses []corev1.NodeAddress `json:"addresses,omitempty"` -} - // Image defines information about the image to use for VM creation. // There are three ways to specify an image: by ID, Marketplace Image or SharedImageGallery // One of ID, SharedImage or Marketplace should be set. @@ -445,8 +452,9 @@ type OSDisk struct { DiskSizeGB *int32 `json:"diskSizeGB,omitempty"` // ManagedDisk specifies the Managed Disk parameters for the OS disk. // +optional - ManagedDisk *ManagedDiskParameters `json:"managedDisk,omitempty"` - DiffDiskSettings *DiffDiskSettings `json:"diffDiskSettings,omitempty"` + ManagedDisk *ManagedDiskParameters `json:"managedDisk,omitempty"` + // +optional + DiffDiskSettings *DiffDiskSettings `json:"diffDiskSettings,omitempty"` // CachingType specifies the caching requirements. // +optional // +kubebuilder:validation:Enum=None;ReadOnly;ReadWrite @@ -465,6 +473,7 @@ type DataDisk struct { ManagedDisk *ManagedDiskParameters `json:"managedDisk,omitempty"` // Lun Specifies the logical unit number of the data disk. This value is used to identify data disks within the VM and therefore must be unique for each data disk attached to a VM. // The value must be between 0 and 63. + // +optional Lun *int32 `json:"lun,omitempty"` // CachingType specifies the caching requirements. // +optional @@ -483,6 +492,7 @@ type ManagedDiskParameters struct { // DiskEncryptionSetParameters defines disk encryption options. type DiskEncryptionSetParameters struct { // ID defines resourceID for diskEncryptionSet resource. It must be in the same subscription + // +optional ID string `json:"id,omitempty"` } @@ -508,9 +518,10 @@ const ( // SubnetSpec configures an Azure subnet. type SubnetSpec struct { // Role defines the subnet role (eg. Node, ControlPlane) - Role SubnetRole `json:"role,omitempty"` + Role SubnetRole `json:"role"` - // ID defines a unique identifier to reference this resource. + // ID is the Azure resource ID of the subnet. + // READ-ONLY // +optional ID string `json:"id,omitempty"` @@ -573,6 +584,7 @@ type SecurityProfile struct { // This field indicates whether Host Encryption should be enabled // or disabled for a virtual machine or virtual machine scale // set. Default is disabled. + // +optional EncryptionAtHost *bool `json:"encryptionAtHost,omitempty"` } @@ -584,17 +596,24 @@ type AddressRecord struct { // CloudProviderConfigOverrides represents the fields that can be overridden in azure cloud provider config. type CloudProviderConfigOverrides struct { + // +optional RateLimits []RateLimitSpec `json:"rateLimits,omitempty"` - BackOffs BackOffConfig `json:"backOffs,omitempty"` + // +optional + BackOffs BackOffConfig `json:"backOffs,omitempty"` } // BackOffConfig indicates the back-off config options. type BackOffConfig struct { - CloudProviderBackoff bool `json:"cloudProviderBackoff,omitempty"` - CloudProviderBackoffRetries int `json:"cloudProviderBackoffRetries,omitempty"` + // +optional + CloudProviderBackoff bool `json:"cloudProviderBackoff,omitempty"` + // +optional + CloudProviderBackoffRetries int `json:"cloudProviderBackoffRetries,omitempty"` + // +optional CloudProviderBackoffExponent *resource.Quantity `json:"cloudProviderBackoffExponent,omitempty"` - CloudProviderBackoffDuration int `json:"cloudProviderBackoffDuration,omitempty"` - CloudProviderBackoffJitter *resource.Quantity `json:"cloudProviderBackoffJitter,omitempty"` + // +optional + CloudProviderBackoffDuration int `json:"cloudProviderBackoffDuration,omitempty"` + // +optional + CloudProviderBackoffJitter *resource.Quantity `json:"cloudProviderBackoffJitter,omitempty"` } // RateLimitSpec represents the rate limit configuration for a particular kind of resource. @@ -606,17 +625,23 @@ type BackOffConfig struct { type RateLimitSpec struct { // Name is the name of the rate limit spec. // +kubebuilder:validation:Enum=defaultRateLimit;routeRateLimit;subnetsRateLimit;interfaceRateLimit;routeTableRateLimit;loadBalancerRateLimit;publicIPAddressRateLimit;securityGroupRateLimit;virtualMachineRateLimit;storageAccountRateLimit;diskRateLimit;snapshotRateLimit;virtualMachineScaleSetRateLimit;virtualMachineSizesRateLimit;availabilitySetRateLimit - Name string `json:"name,omitempty"` + Name string `json:"name"` + // +optional Config RateLimitConfig `json:"config,omitempty"` } // RateLimitConfig indicates the rate limit config options. type RateLimitConfig struct { - CloudProviderRateLimit bool `json:"cloudProviderRateLimit,omitempty"` - CloudProviderRateLimitQPS *resource.Quantity `json:"cloudProviderRateLimitQPS,omitempty"` - CloudProviderRateLimitBucket int `json:"cloudProviderRateLimitBucket,omitempty"` - CloudProviderRateLimitQPSWrite *resource.Quantity `json:"cloudProviderRateLimitQPSWrite,omitempty"` - CloudProviderRateLimitBucketWrite int `json:"cloudProviderRateLimitBucketWrite,omitempty"` + // +optional + CloudProviderRateLimit bool `json:"cloudProviderRateLimit,omitempty"` + // +optional + CloudProviderRateLimitQPS *resource.Quantity `json:"cloudProviderRateLimitQPS,omitempty"` + // +optional + CloudProviderRateLimitBucket int `json:"cloudProviderRateLimitBucket,omitempty"` + // +optional + CloudProviderRateLimitQPSWrite *resource.Quantity `json:"cloudProviderRateLimitQPSWrite,omitempty"` + // +optional + CloudProviderRateLimitBucketWrite int `json:"cloudProviderRateLimitBucketWrite,omitempty"` } const ( diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 440e3f4590b..3742baf07c7 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -1268,35 +1268,6 @@ func (in *UserAssignedIdentity) DeepCopy() *UserAssignedIdentity { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *VM) DeepCopyInto(out *VM) { - *out = *in - in.Image.DeepCopyInto(&out.Image) - in.OSDisk.DeepCopyInto(&out.OSDisk) - if in.Tags != nil { - in, out := &in.Tags, &out.Tags - *out = make(Tags, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - if in.Addresses != nil { - in, out := &in.Addresses, &out.Addresses - *out = make([]v1.NodeAddress, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VM. -func (in *VM) DeepCopy() *VM { - if in == nil { - return nil - } - out := new(VM) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VnetPeeringSpec) DeepCopyInto(out *VnetPeeringSpec) { *out = *in diff --git a/azure/converters/vm.go b/azure/converters/vm.go index 514327e2f6c..b54a2408c66 100644 --- a/azure/converters/vm.go +++ b/azure/converters/vm.go @@ -19,12 +19,33 @@ package converters import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-04-01/compute" "github.com/Azure/go-autorest/autorest/to" + corev1 "k8s.io/api/core/v1" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) +// VM describes an Azure virtual machine. +type VM struct { + ID string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + AvailabilityZone string `json:"availabilityZone,omitempty"` + // Hardware profile + VMSize string `json:"vmSize,omitempty"` + // Storage profile + Image infrav1.Image `json:"image,omitempty"` + OSDisk infrav1.OSDisk `json:"osDisk,omitempty"` + StartupScript string `json:"startupScript,omitempty"` + // State - The provisioning state, which only appears in the response. + State infrav1.ProvisioningState `json:"vmState,omitempty"` + Identity infrav1.VMIdentity `json:"identity,omitempty"` + Tags infrav1.Tags `json:"tags,omitempty"` + + // Addresses contains the addresses associated with the Azure VM. + Addresses []corev1.NodeAddress `json:"addresses,omitempty"` +} + // SDKToVM converts an Azure SDK VirtualMachine to the CAPZ VM type. -func SDKToVM(v compute.VirtualMachine) (*infrav1.VM, error) { - vm := &infrav1.VM{ +func SDKToVM(v compute.VirtualMachine) (*VM, error) { + vm := &VM{ ID: to.String(v.ID), Name: to.String(v.Name), State: infrav1.ProvisioningState(to.String(v.ProvisioningState)), diff --git a/azure/services/virtualmachines/virtualmachines.go b/azure/services/virtualmachines/virtualmachines.go index ec6969d55aa..3828ae048e8 100644 --- a/azure/services/virtualmachines/virtualmachines.go +++ b/azure/services/virtualmachines/virtualmachines.go @@ -232,7 +232,7 @@ func (s *Service) Delete(ctx context.Context) error { } // getExisting provides information about a virtual machine. -func (s *Service) getExisting(ctx context.Context, name string) (*infrav1.VM, error) { +func (s *Service) getExisting(ctx context.Context, name string) (*converters.VM, error) { ctx, _, done := tele.StartSpanWithLogger(ctx, "virtualmachines.Service.getExisting") defer done() diff --git a/azure/services/virtualmachines/virtualmachines_test.go b/azure/services/virtualmachines/virtualmachines_test.go index a4461ca6143..9a8210d7263 100644 --- a/azure/services/virtualmachines/virtualmachines_test.go +++ b/azure/services/virtualmachines/virtualmachines_test.go @@ -34,6 +34,7 @@ import ( infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" + "sigs.k8s.io/cluster-api-provider-azure/azure/converters" "sigs.k8s.io/cluster-api-provider-azure/azure/services/availabilitysets/mock_availabilitysets" "sigs.k8s.io/cluster-api-provider-azure/azure/services/networkinterfaces/mock_networkinterfaces" "sigs.k8s.io/cluster-api-provider-azure/azure/services/publicips/mock_publicips" @@ -46,14 +47,14 @@ func TestGetExistingVM(t *testing.T) { testcases := []struct { name string vmName string - result *infrav1.VM + result *converters.VM expectedError string expect func(s *mock_virtualmachines.MockVMScopeMockRecorder, m *mock_virtualmachines.MockClientMockRecorder, mnic *mock_networkinterfaces.MockClientMockRecorder, mpip *mock_publicips.MockClientMockRecorder) }{ { name: "get existing vm", vmName: "my-vm", - result: &infrav1.VM{ + result: &converters.VM{ ID: "my-id", Name: "my-vm", State: "Succeeded", @@ -124,7 +125,7 @@ func TestGetExistingVM(t *testing.T) { { name: "vm not found", vmName: "my-vm", - result: &infrav1.VM{}, + result: &converters.VM{}, expectedError: "#: Not found: StatusCode=404", expect: func(s *mock_virtualmachines.MockVMScopeMockRecorder, m *mock_virtualmachines.MockClientMockRecorder, mnic *mock_networkinterfaces.MockClientMockRecorder, mpip *mock_publicips.MockClientMockRecorder) { s.ResourceGroup().AnyTimes().Return("my-rg") @@ -135,7 +136,7 @@ func TestGetExistingVM(t *testing.T) { { name: "vm retrieval fails", vmName: "my-vm", - result: &infrav1.VM{}, + result: &converters.VM{}, expectedError: "#: Internal Server Error: StatusCode=500", expect: func(s *mock_virtualmachines.MockVMScopeMockRecorder, m *mock_virtualmachines.MockClientMockRecorder, mnic *mock_networkinterfaces.MockClientMockRecorder, mpip *mock_publicips.MockClientMockRecorder) { s.ResourceGroup().AnyTimes().Return("my-rg") @@ -146,7 +147,7 @@ func TestGetExistingVM(t *testing.T) { { name: "get existing vm: error getting public IP", vmName: "my-vm", - result: &infrav1.VM{}, + result: &converters.VM{}, expectedError: "#: Internal Server Error: StatusCode=500", expect: func(s *mock_virtualmachines.MockVMScopeMockRecorder, m *mock_virtualmachines.MockClientMockRecorder, mnic *mock_networkinterfaces.MockClientMockRecorder, mpip *mock_publicips.MockClientMockRecorder) { s.ResourceGroup().AnyTimes().Return("my-rg") @@ -195,7 +196,7 @@ func TestGetExistingVM(t *testing.T) { { name: "get existing vm: public IP not found", vmName: "my-vm", - result: &infrav1.VM{}, + result: &converters.VM{}, expectedError: "#: Not Found: StatusCode=404", expect: func(s *mock_virtualmachines.MockVMScopeMockRecorder, m *mock_virtualmachines.MockClientMockRecorder, mnic *mock_networkinterfaces.MockClientMockRecorder, mpip *mock_publicips.MockClientMockRecorder) { s.ResourceGroup().AnyTimes().Return("my-rg") diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_azureclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_azureclusters.yaml index ca58419f291..153f81376fd 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_azureclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_azureclusters.yaml @@ -1336,8 +1336,8 @@ spec: type: string type: array id: - description: ID defines a unique identifier to reference - this resource. + description: ID is the Azure resource ID of the subnet. + READ-ONLY type: string name: description: Name defines a name for the subnet resource. @@ -1346,6 +1346,8 @@ spec: description: NatGateway associated with this subnet. properties: id: + description: ID is the Azure resource ID of the nat + gateway. READ-ONLY type: string ip: description: PublicIPSpec defines the inputs to create @@ -1360,6 +1362,8 @@ spec: type: object name: type: string + required: + - name type: object role: description: Role defines the subnet role (eg. Node, ControlPlane) @@ -1369,15 +1373,21 @@ spec: be attached to this subnet. properties: id: + description: ID is the Azure resource ID of the route + table. READ-ONLY type: string name: type: string + required: + - name type: object securityGroup: description: SecurityGroup defines the NSG (network security group) that should be attached to this subnet. properties: id: + description: ID is the Azure resource ID of the security + group. READ-ONLY type: string name: type: string @@ -1463,9 +1473,12 @@ spec: type: string description: Tags defines a map of tags. type: object + required: + - name type: object required: - name + - role type: object type: object type: object @@ -1555,6 +1568,8 @@ spec: - virtualMachineSizesRateLimit - availabilitySetRateLimit type: string + required: + - name type: object type: array type: object @@ -1651,6 +1666,8 @@ spec: format: int32 type: integer id: + description: ID is the Azure resource ID of the load balancer. + READ-ONLY type: string idleTimeoutInMinutes: description: IdleTimeoutInMinutes specifies the timeout for @@ -1665,6 +1682,8 @@ spec: type: description: LBType defines an Azure load balancer Type. type: string + required: + - name type: object controlPlaneOutboundLB: description: ControlPlaneOutboundLB is the configuration for the @@ -1703,6 +1722,8 @@ spec: format: int32 type: integer id: + description: ID is the Azure resource ID of the load balancer. + READ-ONLY type: string idleTimeoutInMinutes: description: IdleTimeoutInMinutes specifies the timeout for @@ -1717,6 +1738,8 @@ spec: type: description: LBType defines an Azure load balancer Type. type: string + required: + - name type: object nodeOutboundLB: description: NodeOutboundLB is the configuration for the node @@ -1753,6 +1776,8 @@ spec: format: int32 type: integer id: + description: ID is the Azure resource ID of the load balancer. + READ-ONLY type: string idleTimeoutInMinutes: description: IdleTimeoutInMinutes specifies the timeout for @@ -1767,6 +1792,8 @@ spec: type: description: LBType defines an Azure load balancer Type. type: string + required: + - name type: object privateDNSZoneName: description: PrivateDNSZoneName defines the zone name for the @@ -1785,8 +1812,8 @@ spec: type: string type: array id: - description: ID defines a unique identifier to reference - this resource. + description: ID is the Azure resource ID of the subnet. + READ-ONLY type: string name: description: Name defines a name for the subnet resource. @@ -1795,6 +1822,8 @@ spec: description: NatGateway associated with this subnet. properties: id: + description: ID is the Azure resource ID of the nat + gateway. READ-ONLY type: string ip: description: PublicIPSpec defines the inputs to create @@ -1809,6 +1838,8 @@ spec: type: object name: type: string + required: + - name type: object role: description: Role defines the subnet role (eg. Node, ControlPlane) @@ -1818,15 +1849,21 @@ spec: be attached to this subnet. properties: id: + description: ID is the Azure resource ID of the route + table. READ-ONLY type: string name: type: string + required: + - name type: object securityGroup: description: SecurityGroup defines the NSG (network security group) that should be attached to this subnet. properties: id: + description: ID is the Azure resource ID of the security + group. READ-ONLY type: string name: type: string @@ -1909,9 +1946,12 @@ spec: type: string description: Tags defines a map of tags. type: object + required: + - name type: object required: - name + - role type: object type: array vnet: @@ -1925,8 +1965,8 @@ spec: type: string type: array id: - description: ID is the identifier of the virtual network this - provider should use to create resources. + description: ID is the Azure resource ID of the virtual network. + READ-ONLY type: string name: description: Name defines a name for the virtual network resource. @@ -2077,6 +2117,7 @@ spec: create, delete, etc. type: string required: + - data - name - serviceName - type diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremachinepoolmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremachinepoolmachines.yaml index f23b5b6f626..f619efd9d8d 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremachinepoolmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremachinepoolmachines.yaml @@ -406,6 +406,7 @@ spec: create, delete, etc. type: string required: + - data - name - serviceName - type diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremachinepools.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremachinepools.yaml index c21b814d88c..55e446c7807 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremachinepools.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremachinepools.yaml @@ -2024,6 +2024,7 @@ spec: create, delete, etc. type: string required: + - data - name - serviceName - type diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremachines.yaml index 0387d03356c..031d91fffea 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremachines.yaml @@ -1485,6 +1485,7 @@ spec: create, delete, etc. type: string required: + - data - name - serviceName - type diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml index 7d94f8ac9ab..679a2a795ac 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml @@ -776,6 +776,7 @@ spec: create, delete, etc. type: string required: + - data - name - serviceName - type diff --git a/exp/api/v1beta1/azuremanagedcontrolplane_types.go b/exp/api/v1beta1/azuremanagedcontrolplane_types.go index 18431b085e5..381e99c4ddc 100644 --- a/exp/api/v1beta1/azuremanagedcontrolplane_types.go +++ b/exp/api/v1beta1/azuremanagedcontrolplane_types.go @@ -48,9 +48,11 @@ type AzureManagedControlPlaneSpec struct { NodeResourceGroupName string `json:"nodeResourceGroupName,omitempty"` // VirtualNetwork describes the vnet for the AKS cluster. Will be created if it does not exist. + // +optional VirtualNetwork ManagedControlPlaneVirtualNetwork `json:"virtualNetwork,omitempty"` // SubscriptionID is the GUID of the Azure subscription to hold this cluster. + // +optional SubscriptionID string `json:"subscriptionID,omitempty"` // Location is a string matching one of the canonical Azure region names. Examples: "westus2", "eastus". @@ -58,7 +60,7 @@ type AzureManagedControlPlaneSpec struct { // ControlPlaneEndpoint represents the endpoint used to communicate with the control plane. // +optional - ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"` + ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint,omitempty"` // AdditionalTags is an optional set of tags to add to Azure resources managed by the Azure provider, in addition to the // ones added by default. @@ -174,9 +176,10 @@ type APIServerAccessProfile struct { // ManagedControlPlaneVirtualNetwork describes a virtual network required to provision AKS clusters. type ManagedControlPlaneVirtualNetwork struct { - Name string `json:"name"` - CIDRBlock string `json:"cidrBlock"` - Subnet ManagedControlPlaneSubnet `json:"subnet,omitempty"` + Name string `json:"name"` + CIDRBlock string `json:"cidrBlock"` + // +optional + Subnet ManagedControlPlaneSubnet `json:"subnet,omitempty"` } // ManagedControlPlaneSubnet describes a subnet for an AKS cluster. diff --git a/exp/api/v1beta1/azuremanagedmachinepool_types.go b/exp/api/v1beta1/azuremanagedmachinepool_types.go index 21fdb66080b..b18dc8df004 100644 --- a/exp/api/v1beta1/azuremanagedmachinepool_types.go +++ b/exp/api/v1beta1/azuremanagedmachinepool_types.go @@ -51,6 +51,7 @@ type AzureManagedMachinePoolSpec struct { // OSDiskSizeGB is the disk size for every machine in this agent pool. // If you specify 0, it will apply the default osDisk size according to the vmSize specified. + // +optional OSDiskSizeGB *int32 `json:"osDiskSizeGB,omitempty"` // ProviderIDList is the unique identifier as specified by the cloud provider.