diff --git a/config/master-machine.yaml b/config/master-machine.yaml index d99b6fb89ab..1a114346c9f 100644 --- a/config/master-machine.yaml +++ b/config/master-machine.yaml @@ -11,7 +11,7 @@ spec: controlPlane: 1.13.4 providerSpec: value: - apiVersion: azureprovider/v1alpha1 + apiVersion: azureprovider/v1beta1 kind: AzureMachineProviderSpec roles: - Master diff --git a/config/worker-machineset.yaml b/config/worker-machineset.yaml index 5c07c74ff1e..dcc6c743e70 100644 --- a/config/worker-machineset.yaml +++ b/config/worker-machineset.yaml @@ -22,7 +22,7 @@ spec: node-role.kubernetes.io/compute: "" providerSpec: value: - apiVersion: azureprovider/v1alpha1 + apiVersion: azureprovider/v1beta1 kind: AzureMachineProviderSpec roles: - Master diff --git a/pkg/apis/addtoscheme_azureprovider_v1alpha1.go b/pkg/apis/addtoscheme_azureprovider_v1alpha1.go deleted file mode 100644 index 07f25e8c003..00000000000 --- a/pkg/apis/addtoscheme_azureprovider_v1alpha1.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package apis - -import ( - "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1alpha1" -) - -func init() { - // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back - AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme) -} diff --git a/pkg/apis/azureprovider/v1alpha1/azureclusterproviderconfig_types.go b/pkg/apis/azureprovider/v1alpha1/azureclusterproviderconfig_types.go deleted file mode 100644 index 8a9a17e5bd3..00000000000 --- a/pkg/apis/azureprovider/v1alpha1/azureclusterproviderconfig_types.go +++ /dev/null @@ -1,134 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// AzureClusterProviderSpec is the providerConfig for Azure in the cluster. -// +k8s:openapi-gen=true -type AzureClusterProviderSpec struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - // NetworkSpec encapsulates all things related to Azure network. - NetworkSpec NetworkSpec `json:"networkSpec,omitempty"` - - ResourceGroup string `json:"resourceGroup"` - NetworkResourceGroup string `json:"networkResourceGroup"` - Location string `json:"location"` - - // CAKeyPair is the key pair for CA certs. - CAKeyPair KeyPair `json:"caKeyPair,omitempty"` - - // EtcdCAKeyPair is the key pair for etcd. - EtcdCAKeyPair KeyPair `json:"etcdCAKeyPair,omitempty"` - - // FrontProxyCAKeyPair is the key pair for the front proxy. - FrontProxyCAKeyPair KeyPair `json:"frontProxyCAKeyPair,omitempty"` - - // SAKeyPair is the service account key pair. - SAKeyPair KeyPair `json:"saKeyPair,omitempty"` - - // AdminKubeconfig generated using the certificates part of the spec - // do not move to status, since it uses on disk ca certs, which causes issues during regeneration - AdminKubeconfig string `json:"adminKubeconfig,omitempty"` - - // DiscoveryHashes generated using the certificates part of the spec, used by master and nodes bootstrapping - // this never changes until ca is rotated - // do not move to status, since it uses on disk ca certs, which causes issues during regeneration - DiscoveryHashes []string `json:"discoveryHashes,omitempty"` -} - -// KeyPair is how operators can supply custom keypairs for kubeadm to use. -type KeyPair struct { - // base64 encoded cert and key - Cert []byte `json:"cert"` - Key []byte `json:"key"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -func init() { - SchemeBuilder.Register(&AzureClusterProviderSpec{}) -} - -// HasCertAndKey returns whether a keypair contains cert and key of non-zero length. -func (kp *KeyPair) HasCertAndKey() bool { - return len(kp.Cert) != 0 && len(kp.Key) != 0 -} - -// NetworkSpec encapsulates all things related to Azure network. -type NetworkSpec struct { - // Vnet configuration. - // +optional - Vnet VnetSpec `json:"vpc,omitempty"` - - // Subnets configuration. - // +optional - Subnets Subnets `json:"subnets,omitempty"` -} - -// VnetSpec configures an Azure virtual network. -type VnetSpec struct { - // ID is the identifier of the virtual network this provider should use to create resources. - ID string `json:"id,omitempty"` - - // Name defines a name for the virtual network resource. - Name string `json:"name"` - - // CidrBlock is the CIDR block to be used when the provider creates a managed virtual network. - CidrBlock string `json:"cidrBlock,omitempty"` - - // Tags is a collection of tags describing the resource. - // TODO: Uncomment once tagging is implemented. - //Tags tags.Map `json:"tags,omitempty"` -} - -// IsProvided returns true if the virtual network is not managed by Cluster API. -// TODO: Uncomment once tagging is implemented. -/* -func (v *VnetSpec) IsProvided() bool { - return v.ID != "" && !v.Tags.HasManaged() -} -*/ - -// SubnetSpec configures an Azure subnet. -type SubnetSpec struct { - // ID defines a unique identifier to reference this resource. - ID string `json:"id,omitempty"` - - // Name defines a name for the subnet resource. - Name string `json:"name"` - - // VnetID defines the ID of the virtual network this subnet should be built in. - VnetID string `json:"vnetId"` - - // CidrBlock is the CIDR block to be used when the provider creates a managed Vnet. - CidrBlock string `json:"cidrBlock,omitempty"` - - // SecurityGroup defines the NSG (network security group) that should be attached to this subnet. - SecurityGroup SecurityGroup `json:"securityGroup"` - - // Tags is a collection of tags describing the resource. - // TODO: Uncomment once tagging is implemented. - //Tags tags.Map `json:"tags,omitempty"` -} diff --git a/pkg/apis/azureprovider/v1alpha1/azureclusterproviderstatus_types.go b/pkg/apis/azureprovider/v1alpha1/azureclusterproviderstatus_types.go deleted file mode 100644 index 99733618e30..00000000000 --- a/pkg/apis/azureprovider/v1alpha1/azureclusterproviderstatus_types.go +++ /dev/null @@ -1,41 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// AzureClusterProviderStatus contains the status fields -// relevant to Azure in the cluster object. -// +k8s:openapi-gen=true -type AzureClusterProviderStatus struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Network Network `json:"network,omitempty"` - Bastion VM `json:"bastion,omitempty"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -func init() { - SchemeBuilder.Register(&AzureClusterProviderStatus{}) -} diff --git a/pkg/apis/azureprovider/v1alpha1/doc.go b/pkg/apis/azureprovider/v1alpha1/doc.go deleted file mode 100644 index 53730f639ed..00000000000 --- a/pkg/apis/azureprovider/v1alpha1/doc.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package v1alpha1 contains API Schema definitions for the azureprovider v1alpha1 API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider -// +k8s:defaulter-gen=TypeMeta -// +groupName=azureprovider.k8s.io -package v1alpha1 diff --git a/pkg/apis/azureprovider/v1alpha1/register.go b/pkg/apis/azureprovider/v1alpha1/register.go deleted file mode 100644 index 8610420e1c9..00000000000 --- a/pkg/apis/azureprovider/v1alpha1/register.go +++ /dev/null @@ -1,38 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// NOTE: Boilerplate only. Ignore this file. - -// Package v1alpha1 contains API Schema definitions for the azureprovider v1alpha1 API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider -// +k8s:defaulter-gen=TypeMeta -// +groupName=azureprovider.k8s.io -package v1alpha1 - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/scheme" -) - -var ( - // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "azureprovider.k8s.io", Version: "v1alpha1"} - - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} -) diff --git a/pkg/apis/azureprovider/v1alpha1/types.go b/pkg/apis/azureprovider/v1alpha1/types.go deleted file mode 100644 index 82275991647..00000000000 --- a/pkg/apis/azureprovider/v1alpha1/types.go +++ /dev/null @@ -1,395 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha1 - -import ( - "time" - - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// TODO: Write type tests - -// AzureResourceReference is a reference to a specific Azure resource by ID -type AzureResourceReference struct { - // ID of resource - // +optional - ID *string `json:"id,omitempty"` - // TODO: Investigate if we should reference resources in other ways -} - -// TODO: Investigate resource filters - -// AzureMachineProviderConditionType is a valid value for AzureMachineProviderCondition.Type -type AzureMachineProviderConditionType string - -// Valid conditions for an Azure machine instance -const ( - // MachineCreated indicates whether the machine has been created or not. If not, - // it should include a reason and message for the failure. - MachineCreated AzureMachineProviderConditionType = "MachineCreated" -) - -// AzureMachineProviderCondition is a condition in a AzureMachineProviderStatus -type AzureMachineProviderCondition struct { - // Type is the type of the condition. - Type AzureMachineProviderConditionType `json:"type"` - // Status is the status of the condition. - Status corev1.ConditionStatus `json:"status"` - // LastProbeTime is the last time we probed the condition. - // +optional - LastProbeTime metav1.Time `json:"lastProbeTime"` - // LastTransitionTime is the last time the condition transitioned from one status to another. - // +optional - LastTransitionTime metav1.Time `json:"lastTransitionTime"` - // Reason is a unique, one-word, CamelCase reason for the condition's last transition. - // +optional - Reason string `json:"reason"` - // Message is a human-readable message indicating details about last transition. - // +optional - Message string `json:"message"` -} - -const ( - // ControlPlane machine label - ControlPlane string = "master" - // Node machine label - Node string = "worker" - // MachineRoleLabel machine label to determine the role - MachineRoleLabel = "machine.openshift.io/cluster-api-machine-role" -) - -// Network encapsulates Azure networking resources. -type Network struct { - // SecurityGroups is a map from the role/kind of the security group to its unique name, if any. - SecurityGroups map[SecurityGroupRole]*SecurityGroup `json:"securityGroups,omitempty"` - - // APIServerLB is the Kubernetes API server load balancer. - APIServerLB LoadBalancer `json:"apiServerLb,omitempty"` - - // APIServerIP is the Kubernetes API server public IP address. - APIServerIP PublicIP `json:"apiServerIp,omitempty"` -} - -// TODO: Implement tagging -/* -// Tags defines resource tags. -type Tags map[string]*string -*/ - -// Subnets is a slice of Subnet. -type Subnets []*SubnetSpec - -// TODO -// ToMap returns a map from id to subnet. -func (s Subnets) ToMap() map[string]*SubnetSpec { - res := make(map[string]*SubnetSpec) - for _, x := range s { - res[x.ID] = x - } - return res -} - -// SecurityGroupRole defines the unique role of a security group. -type SecurityGroupRole string - -var ( - // SecurityGroupBastion defines an SSH bastion role - SecurityGroupBastion = SecurityGroupRole("bastion") - - // SecurityGroupNode defines a Kubernetes workload node role - SecurityGroupNode = SecurityGroupRole(Node) - - // SecurityGroupControlPlane defines a Kubernetes control plane node role - SecurityGroupControlPlane = SecurityGroupRole(ControlPlane) -) - -// SecurityGroup defines an Azure security group. -type SecurityGroup struct { - ID string `json:"id"` - Name string `json:"name"` - IngressRules IngressRules `json:"ingressRule"` - // TODO: Uncomment once tagging is implemented. - //Tags *Tags `json:"tags"` -} - -/* -// TODO -// String returns a string representation of the security group. -func (s *SecurityGroup) String() string { - return fmt.Sprintf("id=%s/name=%s", s.ID, s.Name) -} -*/ - -// SecurityGroupProtocol defines the protocol type for a security group rule. -type SecurityGroupProtocol string - -var ( - // SecurityGroupProtocolAll is a wildcard for all IP protocols - SecurityGroupProtocolAll = SecurityGroupProtocol("*") - - // SecurityGroupProtocolTCP represents the TCP protocol in ingress rules - SecurityGroupProtocolTCP = SecurityGroupProtocol("Tcp") - - // SecurityGroupProtocolUDP represents the UDP protocol in ingress rules - SecurityGroupProtocolUDP = SecurityGroupProtocol("Udp") -) - -// TODO -// IngressRule defines an Azure ingress rule for security groups. -type IngressRule struct { - Description string `json:"description"` - Protocol SecurityGroupProtocol `json:"protocol"` - - // SourcePorts - The source port or range. Integer or range between 0 and 65535. Asterix '*' can also be used to match all ports. - SourcePorts *string `json:"sourcePorts,omitempty"` - - // DestinationPorts - The destination port or range. Integer or range between 0 and 65535. Asterix '*' can also be used to match all ports. - DestinationPorts *string `json:"destinationPorts,omitempty"` - - // Source - 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. - Source *string `json:"source,omitempty"` - - // Destination - 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. - Destination *string `json:"destination,omitempty"` -} - -// TODO -// String returns a string representation of the ingress rule. -/* -func (i *IngressRule) String() string { - return fmt.Sprintf("protocol=%s/range=[%d-%d]/description=%s", i.Protocol, i.FromPort, i.ToPort, i.Description) -} -*/ - -// TODO -// IngressRules is a slice of Azure ingress rules for security groups. -type IngressRules []*IngressRule - -// TODO -// Difference returns the difference between this slice and the other slice. -/* -func (i IngressRules) Difference(o IngressRules) (out IngressRules) { - for _, x := range i { - found := false - for _, y := range o { - sort.Strings(x.CidrBlocks) - sort.Strings(y.CidrBlocks) - sort.Strings(x.SourceSecurityGroupIDs) - sort.Strings(y.SourceSecurityGroupIDs) - if reflect.DeepEqual(x, y) { - found = true - break - } - } - - if !found { - out = append(out, x) - } - } - - return -} -*/ - -// PublicIP defines an Azure public IP address. -// TODO: Remove once load balancer is implemented. -type PublicIP struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - IPAddress string `json:"ipAddress,omitempty"` - DNSName string `json:"dnsName,omitempty"` -} - -// TODO -// LoadBalancer defines an Azure load balancer. -type LoadBalancer struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - SKU SKU `json:"sku,omitempty"` - FrontendIPConfig FrontendIPConfig `json:"frontendIpConfig,omitempty"` - BackendPool BackendPool `json:"backendPool,omitempty"` - // TODO: Uncomment once tagging is implemented. - //Tags Tags `json:"tags,omitempty"` - /* - // FrontendIPConfigurations - Object representing the frontend IPs to be used for the load balancer - FrontendIPConfigurations *[]FrontendIPConfiguration `json:"frontendIPConfigurations,omitempty"` - // BackendAddressPools - Collection of backend address pools used by a load balancer - BackendAddressPools *[]BackendAddressPool `json:"backendAddressPools,omitempty"` - // LoadBalancingRules - Object collection representing the load balancing rules Gets the provisioning - LoadBalancingRules *[]LoadBalancingRule `json:"loadBalancingRules,omitempty"` - // Probes - Collection of probe objects used in the load balancer - Probes *[]Probe `json:"probes,omitempty"` - // InboundNatRules - Collection of inbound NAT Rules used by a load balancer. Defining inbound NAT rules on your load balancer is mutually exclusive with defining an inbound NAT pool. Inbound NAT pools are referenced from virtual machine scale sets. NICs that are associated with individual virtual machines cannot reference an Inbound NAT pool. They have to reference individual inbound NAT rules. - InboundNatRules *[]InboundNatRule `json:"inboundNatRules,omitempty"` - // InboundNatPools - Defines an external port range for inbound NAT to a single backend port on NICs associated with a load balancer. Inbound NAT rules are created automatically for each NIC associated with the Load Balancer using an external port from this range. Defining an Inbound NAT pool on your Load Balancer is mutually exclusive with defining inbound Nat rules. Inbound NAT pools are referenced from virtual machine scale sets. NICs that are associated with individual virtual machines cannot reference an inbound NAT pool. They have to reference individual inbound NAT rules. - InboundNatPools *[]InboundNatPool `json:"inboundNatPools,omitempty"` - // OutboundRules - The outbound rules. - OutboundRules *[]OutboundRule `json:"outboundRules,omitempty"` - // ResourceGUID - The resource GUID property of the load balancer resource. - ResourceGUID *string `json:"resourceGuid,omitempty"` - // ProvisioningState - Gets the provisioning state of the PublicIP resource. Possible values are: 'Updating', 'Deleting', and 'Failed'. - ProvisioningState *string `json:"provisioningState,omitempty"` - */ -} - -// LoadBalancerSKU enumerates the values for load balancer sku name. -type SKU string - -var ( - SKUBasic = SKU("Basic") - SKUStandard = SKU("Standard") -) - -type FrontendIPConfig struct { - /* - // FrontendIPConfigurationPropertiesFormat - Properties of the load balancer probe. - *FrontendIPConfigurationPropertiesFormat `json:"properties,omitempty"` - // Name - The name of the resource that is unique within a resource group. This name can be used to access the resource. - Name *string `json:"name,omitempty"` - // Etag - A unique read-only string that changes whenever the resource is updated. - Etag *string `json:"etag,omitempty"` - // Zones - A list of availability zones denoting the IP allocated for the resource needs to come from. - Zones *[]string `json:"zones,omitempty"` - // ID - Resource ID. - ID *string `json:"id,omitempty"` - */ -} - -type BackendPool struct { - Name string `json:"name,omitempty"` - ID string `json:"id,omitempty"` -} - -// TODO -// LoadBalancerProtocol defines listener protocols for a load balancer. -type LoadBalancerProtocol string - -// TODO -var ( - // LoadBalancerProtocolTCP defines the LB API string representing the TCP protocol - LoadBalancerProtocolTCP = LoadBalancerProtocol("TCP") - - // LoadBalancerProtocolSSL defines the LB API string representing the TLS protocol - LoadBalancerProtocolSSL = LoadBalancerProtocol("SSL") - - // LoadBalancerProtocolHTTP defines the LB API string representing the HTTP protocol at L7 - LoadBalancerProtocolHTTP = LoadBalancerProtocol("HTTP") - - // LoadBalancerProtocolHTTPS defines the LB API string representing the HTTP protocol at L7 - LoadBalancerProtocolHTTPS = LoadBalancerProtocol("HTTPS") -) - -// TODO -// LoadBalancerListener defines an Azure load balancer listener. -type LoadBalancerListener struct { - Protocol LoadBalancerProtocol `json:"protocol"` - Port int64 `json:"port"` - InstanceProtocol LoadBalancerProtocol `json:"instanceProtocol"` - InstancePort int64 `json:"instancePort"` -} - -// TODO -// LoadBalancerHealthCheck defines an Azure load balancer health check. -type LoadBalancerHealthCheck struct { - Target string `json:"target"` - Interval time.Duration `json:"interval"` - Timeout time.Duration `json:"timeout"` - HealthyThreshold int64 `json:"healthyThreshold"` - UnhealthyThreshold int64 `json:"unhealthyThreshold"` -} - -// VMState describes the state of an Azure virtual machine. -type VMState string - -var ( - // VMStateCreating ... - VMStateCreating = VMState("Creating") - // VMStateDeleting ... - VMStateDeleting = VMState("Deleting") - // VMStateFailed ... - VMStateFailed = VMState("Failed") - // VMStateMigrating ... - VMStateMigrating = VMState("Migrating") - // VMStateSucceeded ... - VMStateSucceeded = VMState("Succeeded") - // VMStateUpdating ... - VMStateUpdating = VMState("Updating") -) - -// VM describes an Azure virtual machine. -type VM struct { - ID string `json:"id,omitempty"` - Name string `json:"name,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 VMState `json:"vmState,omitempty"` - Identity VMIdentity `json:"identity,omitempty"` - - // TODO: Uncomment once tagging is implemented. - //Tags Tags `json:"tags,omitempty"` - - // HardwareProfile - Specifies the hardware settings for the virtual machine. - //HardwareProfile *HardwareProfile `json:"hardwareProfile,omitempty"` - - // StorageProfile - Specifies the storage settings for the virtual machine disks. - //StorageProfile *StorageProfile `json:"storageProfile,omitempty"` - - // AdditionalCapabilities - Specifies additional capabilities enabled or disabled on the virtual machine. - //AdditionalCapabilities *AdditionalCapabilities `json:"additionalCapabilities,omitempty"` - - // OsProfile - Specifies the operating system settings for the virtual machine. - //OsProfile *OSProfile `json:"osProfile,omitempty"` - // NetworkProfile - Specifies the network interfaces of the virtual machine. - //NetworkProfile *NetworkProfile `json:"networkProfile,omitempty"` - - //AvailabilitySet *SubResource `json:"availabilitySet,omitempty"` -} - -// Image is a mirror of azure sdk compute.ImageReference -type Image struct { - // Fields below refer to os images in marketplace - Publisher string `json:"publisher"` - Offer string `json:"offer"` - SKU string `json:"sku"` - Version string `json:"version"` - // ResourceID represents the location of OS Image in azure subscription - ResourceID string `json:"resourceID"` -} - -// VMIdentity defines the identity of the virtual machine, if configured. -type VMIdentity string - -type OSDisk struct { - OSType string `json:"osType"` - ManagedDisk ManagedDisk `json:"managedDisk"` - DiskSizeGB int32 `json:"diskSizeGB"` -} - -type ManagedDisk struct { - StorageAccountType string `json:"storageAccountType"` -} diff --git a/pkg/apis/azureprovider/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/azureprovider/v1alpha1/zz_generated.deepcopy.go deleted file mode 100644 index 5610ddc9dc0..00000000000 --- a/pkg/apis/azureprovider/v1alpha1/zz_generated.deepcopy.go +++ /dev/null @@ -1,528 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1alpha1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AzureClusterProviderSpec) DeepCopyInto(out *AzureClusterProviderSpec) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.NetworkSpec.DeepCopyInto(&out.NetworkSpec) - in.CAKeyPair.DeepCopyInto(&out.CAKeyPair) - in.EtcdCAKeyPair.DeepCopyInto(&out.EtcdCAKeyPair) - in.FrontProxyCAKeyPair.DeepCopyInto(&out.FrontProxyCAKeyPair) - in.SAKeyPair.DeepCopyInto(&out.SAKeyPair) - if in.DiscoveryHashes != nil { - in, out := &in.DiscoveryHashes, &out.DiscoveryHashes - *out = make([]string, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AzureClusterProviderSpec. -func (in *AzureClusterProviderSpec) DeepCopy() *AzureClusterProviderSpec { - if in == nil { - return nil - } - out := new(AzureClusterProviderSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *AzureClusterProviderSpec) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AzureClusterProviderStatus) DeepCopyInto(out *AzureClusterProviderStatus) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Network.DeepCopyInto(&out.Network) - out.Bastion = in.Bastion - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AzureClusterProviderStatus. -func (in *AzureClusterProviderStatus) DeepCopy() *AzureClusterProviderStatus { - if in == nil { - return nil - } - out := new(AzureClusterProviderStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *AzureClusterProviderStatus) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AzureMachineProviderCondition) DeepCopyInto(out *AzureMachineProviderCondition) { - *out = *in - in.LastProbeTime.DeepCopyInto(&out.LastProbeTime) - in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AzureMachineProviderCondition. -func (in *AzureMachineProviderCondition) DeepCopy() *AzureMachineProviderCondition { - if in == nil { - return nil - } - out := new(AzureMachineProviderCondition) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AzureResourceReference) DeepCopyInto(out *AzureResourceReference) { - *out = *in - if in.ID != nil { - in, out := &in.ID, &out.ID - *out = new(string) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AzureResourceReference. -func (in *AzureResourceReference) DeepCopy() *AzureResourceReference { - if in == nil { - return nil - } - out := new(AzureResourceReference) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *BackendPool) DeepCopyInto(out *BackendPool) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BackendPool. -func (in *BackendPool) DeepCopy() *BackendPool { - if in == nil { - return nil - } - out := new(BackendPool) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FrontendIPConfig) DeepCopyInto(out *FrontendIPConfig) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FrontendIPConfig. -func (in *FrontendIPConfig) DeepCopy() *FrontendIPConfig { - if in == nil { - return nil - } - out := new(FrontendIPConfig) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Image) DeepCopyInto(out *Image) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Image. -func (in *Image) DeepCopy() *Image { - if in == nil { - return nil - } - out := new(Image) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *IngressRule) DeepCopyInto(out *IngressRule) { - *out = *in - if in.SourcePorts != nil { - in, out := &in.SourcePorts, &out.SourcePorts - *out = new(string) - **out = **in - } - if in.DestinationPorts != nil { - in, out := &in.DestinationPorts, &out.DestinationPorts - *out = new(string) - **out = **in - } - if in.Source != nil { - in, out := &in.Source, &out.Source - *out = new(string) - **out = **in - } - if in.Destination != nil { - in, out := &in.Destination, &out.Destination - *out = new(string) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IngressRule. -func (in *IngressRule) DeepCopy() *IngressRule { - if in == nil { - return nil - } - out := new(IngressRule) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in IngressRules) DeepCopyInto(out *IngressRules) { - { - in := &in - *out = make(IngressRules, len(*in)) - for i := range *in { - if (*in)[i] != nil { - in, out := &(*in)[i], &(*out)[i] - *out = new(IngressRule) - (*in).DeepCopyInto(*out) - } - } - return - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IngressRules. -func (in IngressRules) DeepCopy() IngressRules { - if in == nil { - return nil - } - out := new(IngressRules) - in.DeepCopyInto(out) - return *out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *KeyPair) DeepCopyInto(out *KeyPair) { - *out = *in - if in.Cert != nil { - in, out := &in.Cert, &out.Cert - *out = make([]byte, len(*in)) - copy(*out, *in) - } - if in.Key != nil { - in, out := &in.Key, &out.Key - *out = make([]byte, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KeyPair. -func (in *KeyPair) DeepCopy() *KeyPair { - if in == nil { - return nil - } - out := new(KeyPair) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LoadBalancer) DeepCopyInto(out *LoadBalancer) { - *out = *in - out.FrontendIPConfig = in.FrontendIPConfig - out.BackendPool = in.BackendPool - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoadBalancer. -func (in *LoadBalancer) DeepCopy() *LoadBalancer { - if in == nil { - return nil - } - out := new(LoadBalancer) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LoadBalancerHealthCheck) DeepCopyInto(out *LoadBalancerHealthCheck) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoadBalancerHealthCheck. -func (in *LoadBalancerHealthCheck) DeepCopy() *LoadBalancerHealthCheck { - if in == nil { - return nil - } - out := new(LoadBalancerHealthCheck) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LoadBalancerListener) DeepCopyInto(out *LoadBalancerListener) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoadBalancerListener. -func (in *LoadBalancerListener) DeepCopy() *LoadBalancerListener { - if in == nil { - return nil - } - out := new(LoadBalancerListener) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ManagedDisk) DeepCopyInto(out *ManagedDisk) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ManagedDisk. -func (in *ManagedDisk) DeepCopy() *ManagedDisk { - if in == nil { - return nil - } - out := new(ManagedDisk) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Network) DeepCopyInto(out *Network) { - *out = *in - if in.SecurityGroups != nil { - in, out := &in.SecurityGroups, &out.SecurityGroups - *out = make(map[SecurityGroupRole]*SecurityGroup, len(*in)) - for key, val := range *in { - var outVal *SecurityGroup - if val == nil { - (*out)[key] = nil - } else { - in, out := &val, &outVal - *out = new(SecurityGroup) - (*in).DeepCopyInto(*out) - } - (*out)[key] = outVal - } - } - out.APIServerLB = in.APIServerLB - out.APIServerIP = in.APIServerIP - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Network. -func (in *Network) DeepCopy() *Network { - if in == nil { - return nil - } - out := new(Network) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *NetworkSpec) DeepCopyInto(out *NetworkSpec) { - *out = *in - out.Vnet = in.Vnet - if in.Subnets != nil { - in, out := &in.Subnets, &out.Subnets - *out = make(Subnets, len(*in)) - for i := range *in { - if (*in)[i] != nil { - in, out := &(*in)[i], &(*out)[i] - *out = new(SubnetSpec) - (*in).DeepCopyInto(*out) - } - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkSpec. -func (in *NetworkSpec) DeepCopy() *NetworkSpec { - if in == nil { - return nil - } - out := new(NetworkSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *OSDisk) DeepCopyInto(out *OSDisk) { - *out = *in - out.ManagedDisk = in.ManagedDisk - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OSDisk. -func (in *OSDisk) DeepCopy() *OSDisk { - if in == nil { - return nil - } - out := new(OSDisk) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PublicIP) DeepCopyInto(out *PublicIP) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PublicIP. -func (in *PublicIP) DeepCopy() *PublicIP { - if in == nil { - return nil - } - out := new(PublicIP) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SecurityGroup) DeepCopyInto(out *SecurityGroup) { - *out = *in - if in.IngressRules != nil { - in, out := &in.IngressRules, &out.IngressRules - *out = make(IngressRules, len(*in)) - for i := range *in { - if (*in)[i] != nil { - in, out := &(*in)[i], &(*out)[i] - *out = new(IngressRule) - (*in).DeepCopyInto(*out) - } - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecurityGroup. -func (in *SecurityGroup) DeepCopy() *SecurityGroup { - if in == nil { - return nil - } - out := new(SecurityGroup) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SubnetSpec) DeepCopyInto(out *SubnetSpec) { - *out = *in - in.SecurityGroup.DeepCopyInto(&out.SecurityGroup) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubnetSpec. -func (in *SubnetSpec) DeepCopy() *SubnetSpec { - if in == nil { - return nil - } - out := new(SubnetSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in Subnets) DeepCopyInto(out *Subnets) { - { - in := &in - *out = make(Subnets, len(*in)) - for i := range *in { - if (*in)[i] != nil { - in, out := &(*in)[i], &(*out)[i] - *out = new(SubnetSpec) - (*in).DeepCopyInto(*out) - } - } - return - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Subnets. -func (in Subnets) DeepCopy() Subnets { - if in == nil { - return nil - } - out := new(Subnets) - in.DeepCopyInto(out) - 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 - out.Image = in.Image - out.OSDisk = in.OSDisk - return -} - -// 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 *VnetSpec) DeepCopyInto(out *VnetSpec) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VnetSpec. -func (in *VnetSpec) DeepCopy() *VnetSpec { - if in == nil { - return nil - } - out := new(VnetSpec) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/cloud/azure/actuators/getters.go b/pkg/cloud/azure/actuators/getters.go index 115eea30d3c..548b218045e 100644 --- a/pkg/cloud/azure/actuators/getters.go +++ b/pkg/cloud/azure/actuators/getters.go @@ -17,20 +17,9 @@ limitations under the License. package actuators var ( - DefaultScopeGetter ScopeGetter = ScopeGetterFunc(NewScope) DefaultMachineScopeGetter MachineScopeGetter = MachineScopeGetterFunc(NewMachineScope) ) -type ScopeGetter interface { - GetScope(params ScopeParams) (*Scope, error) -} - -type ScopeGetterFunc func(params ScopeParams) (*Scope, error) - -func (f ScopeGetterFunc) GetScope(params ScopeParams) (*Scope, error) { - return f(params) -} - type MachineScopeGetter interface { GetMachineScope(params MachineScopeParams) (*MachineScope, error) } diff --git a/pkg/cloud/azure/actuators/machine/actuator_test.go b/pkg/cloud/azure/actuators/machine/actuator_test.go index d9950d53c06..c0c986872ec 100644 --- a/pkg/cloud/azure/actuators/machine/actuator_test.go +++ b/pkg/cloud/azure/actuators/machine/actuator_test.go @@ -40,8 +40,6 @@ import ( "k8s.io/client-go/tools/record" "k8s.io/klog" "k8s.io/utils/pointer" - clusterproviderv1 "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1alpha1" - machineproviderv1 "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1beta1" providerspecv1 "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure" "sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure/actuators" @@ -60,14 +58,7 @@ func init() { } } -func newClusterProviderSpec() clusterproviderv1.AzureClusterProviderSpec { - return clusterproviderv1.AzureClusterProviderSpec{ - ResourceGroup: "resource-group-test", - Location: "southcentralus", - } -} - -func providerSpecFromMachine(in *machineproviderv1.AzureMachineProviderSpec) (*machinev1.ProviderSpec, error) { +func providerSpecFromMachine(in *providerspecv1.AzureMachineProviderSpec) (*machinev1.ProviderSpec, error) { bytes, err := yaml.Marshal(in) if err != nil { return nil, err @@ -77,7 +68,7 @@ func providerSpecFromMachine(in *machineproviderv1.AzureMachineProviderSpec) (*m }, nil } -func newMachine(t *testing.T, machineConfig machineproviderv1.AzureMachineProviderSpec, labels map[string]string) *machinev1.Machine { +func newMachine(t *testing.T, machineConfig providerspecv1.AzureMachineProviderSpec, labels map[string]string) *machinev1.Machine { providerSpec, err := providerSpecFromMachine(&machineConfig) if err != nil { t.Fatalf("error encoding provider config: %v", err) @@ -94,32 +85,22 @@ func newMachine(t *testing.T, machineConfig machineproviderv1.AzureMachineProvid } func newFakeScope(t *testing.T, label string) *actuators.MachineScope { - scope := &actuators.Scope{ - Context: context.Background(), - ClusterConfig: &clusterproviderv1.AzureClusterProviderSpec{ - ResourceGroup: "dummyResourceGroup", - Location: "dummyLocation", - CAKeyPair: clusterproviderv1.KeyPair{Cert: []byte("cert"), Key: []byte("key")}, - EtcdCAKeyPair: clusterproviderv1.KeyPair{Cert: []byte("cert"), Key: []byte("key")}, - FrontProxyCAKeyPair: clusterproviderv1.KeyPair{Cert: []byte("cert"), Key: []byte("key")}, - SAKeyPair: clusterproviderv1.KeyPair{Cert: []byte("cert"), Key: []byte("key")}, - DiscoveryHashes: []string{"discoveryhash0"}, - }, - } labels := make(map[string]string) - labels[machineproviderv1.MachineRoleLabel] = label + labels[providerspecv1.MachineRoleLabel] = label labels[machinev1.MachineClusterIDLabel] = "clusterID" - machineConfig := machineproviderv1.AzureMachineProviderSpec{} + machineConfig := providerspecv1.AzureMachineProviderSpec{} m := newMachine(t, machineConfig, labels) return &actuators.MachineScope{ - Scope: scope, + Context: context.Background(), Machine: m, - MachineConfig: &machineproviderv1.AzureMachineProviderSpec{ + MachineConfig: &providerspecv1.AzureMachineProviderSpec{ + ResourceGroup: "dummyResourceGroup", + Location: "dummyLocation", Subnet: "dummySubnet", Vnet: "dummyVnet", ManagedIdentity: "dummyIdentity", }, - MachineStatus: &machineproviderv1.AzureMachineProviderStatus{}, + MachineStatus: &providerspecv1.AzureMachineProviderStatus{}, } } @@ -131,7 +112,7 @@ func newFakeReconciler(t *testing.T) *Reconciler { ProvisioningState: "Succeeded", } return &Reconciler{ - scope: newFakeScope(t, machineproviderv1.ControlPlane), + scope: newFakeScope(t, providerspecv1.ControlPlane), availabilityZonesSvc: fakeSuccessSvc, networkInterfacesSvc: fakeSuccessSvc, virtualMachinesSvc: fakeVMSuccessSvc, @@ -405,7 +386,7 @@ func (s *FakeAvailabilityZonesService) Delete(ctx context.Context, spec azure.Sp } func TestAvailabilityZones(t *testing.T) { - fakeScope := newFakeScope(t, machineproviderv1.ControlPlane) + fakeScope := newFakeScope(t, providerspecv1.ControlPlane) fakeReconciler := newFakeReconcilerWithScope(t, fakeScope) fakeReconciler.scope.MachineConfig.Zone = to.StringPtr("2") @@ -449,7 +430,7 @@ func TestGetZone(t *testing.T) { } for _, tc := range testCases { - fakeScope := newFakeScope(t, machineproviderv1.ControlPlane) + fakeScope := newFakeScope(t, providerspecv1.ControlPlane) fakeReconciler := newFakeReconcilerWithScope(t, fakeScope) fakeReconciler.scope.MachineConfig.Zone = tc.inputZone @@ -470,7 +451,7 @@ func TestGetZone(t *testing.T) { } func TestCustomUserData(t *testing.T) { - fakeScope := newFakeScope(t, machineproviderv1.Node) + fakeScope := newFakeScope(t, providerspecv1.Node) userDataSecret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: "testCustomUserData", @@ -499,7 +480,7 @@ func TestCustomUserData(t *testing.T) { } func TestCustomDataFailures(t *testing.T) { - fakeScope := newFakeScope(t, machineproviderv1.Node) + fakeScope := newFakeScope(t, providerspecv1.Node) userDataSecret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: "testCustomUserData", diff --git a/pkg/cloud/azure/actuators/machine/reconciler.go b/pkg/cloud/azure/actuators/machine/reconciler.go index afd4d3d6df0..1311bf5547e 100644 --- a/pkg/cloud/azure/actuators/machine/reconciler.go +++ b/pkg/cloud/azure/actuators/machine/reconciler.go @@ -77,12 +77,12 @@ type Reconciler struct { func NewReconciler(scope *actuators.MachineScope) *Reconciler { return &Reconciler{ scope: scope, - availabilityZonesSvc: availabilityzones.NewService(scope.Scope), - networkInterfacesSvc: networkinterfaces.NewService(scope.Scope), - virtualMachinesSvc: virtualmachines.NewService(scope.Scope), - virtualMachinesExtSvc: virtualmachineextensions.NewService(scope.Scope), - publicIPSvc: publicips.NewService(scope.Scope), - disksSvc: disks.NewService(scope.Scope), + availabilityZonesSvc: availabilityzones.NewService(scope), + networkInterfacesSvc: networkinterfaces.NewService(scope), + virtualMachinesSvc: virtualmachines.NewService(scope), + virtualMachinesExtSvc: virtualmachineextensions.NewService(scope), + publicIPSvc: publicips.NewService(scope), + disksSvc: disks.NewService(scope), } } @@ -243,7 +243,7 @@ func (s *Reconciler) Update(ctx context.Context) error { if vm.OsProfile != nil && vm.OsProfile.ComputerName != nil { providerID := azure.GenerateMachineProviderID( s.scope.SubscriptionID, - s.scope.ClusterConfig.ResourceGroup, + s.scope.MachineConfig.ResourceGroup, *vm.OsProfile.ComputerName) s.scope.Machine.Spec.ProviderID = &providerID } else { @@ -422,7 +422,7 @@ func (s *Reconciler) Delete(ctx context.Context) error { } if s.scope.MachineConfig.PublicIP { - publicIPName, err := azure.GenerateMachinePublicIPName(s.scope.ClusterConfig.Name, s.scope.Machine.Name) + publicIPName, err := azure.GenerateMachinePublicIPName(s.scope.MachineConfig.Name, s.scope.Machine.Name) if err != nil { // Only when the generated name is longer than allowed by the Azure portal // That can happen only when @@ -483,7 +483,7 @@ func (s *Reconciler) createNetworkInterface(ctx context.Context, nicName string) } if s.scope.MachineConfig.PublicIP { - publicIPName, err := azure.GenerateMachinePublicIPName(s.scope.ClusterConfig.Name, s.scope.Machine.Name) + publicIPName, err := azure.GenerateMachinePublicIPName(s.scope.MachineConfig.Name, s.scope.Machine.Name) if err != nil { return machineapierrors.InvalidMachineConfiguration("unable to create Public IP: %v", err) } @@ -535,7 +535,7 @@ func (s *Reconciler) createVirtualMachine(ctx context.Context, nicName string) e } if s.scope.MachineConfig.ManagedIdentity != "" { - vmSpec.ManagedIdentity = azure.GenerateManagedIdentityName(s.scope.SubscriptionID, s.scope.ClusterConfig.ResourceGroup, s.scope.MachineConfig.ManagedIdentity) + vmSpec.ManagedIdentity = azure.GenerateManagedIdentityName(s.scope.SubscriptionID, s.scope.MachineConfig.ResourceGroup, s.scope.MachineConfig.ManagedIdentity) } if vmSpec.Tags == nil { diff --git a/pkg/cloud/azure/actuators/machine_scope.go b/pkg/cloud/azure/actuators/machine_scope.go index 519a7866b26..5eef0446132 100644 --- a/pkg/cloud/azure/actuators/machine_scope.go +++ b/pkg/cloud/azure/actuators/machine_scope.go @@ -18,7 +18,6 @@ package actuators import ( "context" - "errors" "fmt" "github.com/Azure/go-autorest/autorest" @@ -63,11 +62,6 @@ type MachineScopeParams struct { // NewMachineScope creates a new MachineScope from the supplied parameters. // This is meant to be called for each machine actuator operation. func NewMachineScope(params MachineScopeParams) (*MachineScope, error) { - scope, err := NewScope(ScopeParams{AzureClients: params.AzureClients}) - if err != nil { - return nil, err - } - machineConfig, err := MachineConfigFromProviderSpec(params.Machine.Spec.ProviderSpec) if err != nil { return nil, apierrors.InvalidMachineConfiguration(err.Error(), "failed to get machine config") @@ -78,28 +72,10 @@ func NewMachineScope(params MachineScopeParams) (*MachineScope, error) { return nil, fmt.Errorf("failed to get machine provider status: %w", err) } - if machineConfig.CredentialsSecret != nil { - if err = updateScope(params.CoreClient, machineConfig.CredentialsSecret, scope); err != nil { - return nil, fmt.Errorf("failed to update cluster: %w", err) - } - } + machineScope := &MachineScope{ + Context: context.Background(), + AzureClients: params.AzureClients, - scope.ClusterConfig.NetworkResourceGroup = scope.ClusterConfig.ResourceGroup - - if machineConfig.ResourceGroup != "" { - scope.ClusterConfig.ResourceGroup = machineConfig.ResourceGroup - } - - if machineConfig.NetworkResourceGroup != "" { - scope.ClusterConfig.NetworkResourceGroup = machineConfig.NetworkResourceGroup - } - - if machineConfig.Location != "" { - scope.ClusterConfig.Location = machineConfig.Location - } - - return &MachineScope{ - Scope: scope, // Deep copy the machine since it's change outside of the machine scope // by consumers of the machine scope (e.g. reconciler). Machine: params.Machine.DeepCopy(), @@ -111,12 +87,19 @@ func NewMachineScope(params MachineScopeParams) (*MachineScope, error) { origMachine: params.Machine.DeepCopy(), origMachineStatus: machineStatus.DeepCopy(), machineToBePatched: controllerclient.MergeFrom(params.Machine.DeepCopy()), - }, nil + } + + if err = updateFromSecret(params.CoreClient, machineScope); err != nil { + return nil, fmt.Errorf("failed to update cluster: %w", err) + } + + return machineScope, nil } // MachineScope defines a scope defined around a machine and its cluster. type MachineScope struct { - *Scope + context.Context + AzureClients Machine *machinev1.Machine CoreClient controllerclient.Client @@ -150,18 +133,7 @@ func (m *MachineScope) Role() string { // Location returns the machine location. func (m *MachineScope) Location() string { - return m.Scope.Location() -} - -func (m *MachineScope) setMachineSpec() error { - ext, err := v1beta1.EncodeMachineSpec(m.MachineConfig) - if err != nil { - return err - } - - m.Machine.Spec.ProviderSpec.Value = ext - - return nil + return m.MachineConfig.Location } func (m *MachineScope) setMachineStatus() error { @@ -254,12 +226,15 @@ func unmarshalProviderSpec(spec *runtime.RawExtension) (*v1beta1.AzureMachinePro return &config, nil } -func updateScope(coreClient controllerclient.Client, credentialsSecret *apicorev1.SecretReference, scope *Scope) error { - if credentialsSecret == nil { - return errors.New("provided empty credentials secret") +func updateFromSecret(coreClient controllerclient.Client, scope *MachineScope) error { + if scope.MachineConfig.CredentialsSecret == nil { + return nil } - secretType := types.NamespacedName{Namespace: credentialsSecret.Namespace, Name: credentialsSecret.Name} + secretType := types.NamespacedName{ + Namespace: scope.MachineConfig.CredentialsSecret.Namespace, + Name: scope.MachineConfig.CredentialsSecret.Name, + } var secret apicorev1.Secret if err := coreClient.Get( context.Background(), @@ -325,11 +300,21 @@ func updateScope(coreClient controllerclient.Client, credentialsSecret *apicorev return fmt.Errorf("failed to create azure session: %v", err) } - scope.ClusterConfig.ObjectMeta.Name = string(clusterName) + if scope.MachineConfig.ResourceGroup == "" { + scope.MachineConfig.ResourceGroup = string(resourceGroup) + } + + if scope.MachineConfig.NetworkResourceGroup == "" { + scope.MachineConfig.NetworkResourceGroup = string(resourceGroup) + } + + if scope.MachineConfig.Location == "" { + scope.MachineConfig.Location = string(region) + } + + scope.MachineConfig.ObjectMeta.Name = string(clusterName) scope.Authorizer = authorizer scope.SubscriptionID = string(subscriptionID) - scope.ClusterConfig.ResourceGroup = string(resourceGroup) - scope.ClusterConfig.Location = string(region) return nil } diff --git a/pkg/cloud/azure/actuators/machine_scope_test.go b/pkg/cloud/azure/actuators/machine_scope_test.go index 730f7e2a143..93f2b92ca7f 100644 --- a/pkg/cloud/azure/actuators/machine_scope_test.go +++ b/pkg/cloud/azure/actuators/machine_scope_test.go @@ -28,8 +28,7 @@ import ( "k8s.io/client-go/kubernetes/scheme" "k8s.io/klog" "k8s.io/utils/pointer" - clusterproviderv1 "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1alpha1" - machineproviderv1 "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1beta1" + providerspecv1 "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1beta1" controllerfake "sigs.k8s.io/controller-runtime/pkg/client/fake" ) @@ -39,7 +38,7 @@ func init() { } } -func providerSpecFromMachine(in *machineproviderv1.AzureMachineProviderSpec) (*machinev1.ProviderSpec, error) { +func providerSpecFromMachine(in *providerspecv1.AzureMachineProviderSpec) (*machinev1.ProviderSpec, error) { bytes, err := json.Marshal(in) if err != nil { return nil, err @@ -50,7 +49,7 @@ func providerSpecFromMachine(in *machineproviderv1.AzureMachineProviderSpec) (*m } func newMachine(t *testing.T) *machinev1.Machine { - machineConfig := machineproviderv1.AzureMachineProviderSpec{} + machineConfig := providerspecv1.AzureMachineProviderSpec{} providerSpec, err := providerSpecFromMachine(&machineConfig) if err != nil { t.Fatalf("error encoding provider config: %v", err) @@ -85,19 +84,22 @@ func TestCredentialsSecretSuccess(t *testing.T) { Namespace: "dummyNamespace", }, Data: map[string][]byte{ - "azure_subscription_id": []byte("dummySubID"), - "azure_client_id": []byte("dummyClientID"), - "azure_client_secret": []byte("dummyClientSecret"), - "azure_tenant_id": []byte("dummyTenantID"), - "azure_resourcegroup": []byte("dummyResourceGroup"), - "azure_region": []byte("dummyRegion"), - "azure_resource_prefix": []byte("dummyClusterName"), + AzureCredsSubscriptionIDKey: []byte("dummySubID"), + AzureCredsClientIDKey: []byte("dummyClientID"), + AzureCredsClientSecretKey: []byte("dummyClientSecret"), + AzureCredsTenantIDKey: []byte("dummyTenantID"), + AzureCredsResourceGroupKey: []byte("dummyResourceGroup"), + AzureCredsRegionKey: []byte("dummyRegion"), + AzureResourcePrefix: []byte("dummyClusterName"), + }, + } + scope := &MachineScope{ + MachineConfig: &providerspecv1.AzureMachineProviderSpec{ + CredentialsSecret: &corev1.SecretReference{Name: "testCredentials", Namespace: "dummyNamespace"}, }, } - scope := &Scope{ClusterConfig: &clusterproviderv1.AzureClusterProviderSpec{}} - err := updateScope( + err := updateFromSecret( controllerfake.NewFakeClient(credentialsSecret), - &corev1.SecretReference{Name: "testCredentials", Namespace: "dummyNamespace"}, scope) if err != nil { t.Errorf("Expected New credentials secrets to succeed: %v", err) @@ -111,20 +113,23 @@ func TestCredentialsSecretSuccess(t *testing.T) { t.Errorf("Expected location to be dummyRegion but found %s", scope.Location()) } - if scope.ClusterConfig.Name != "dummyClusterName" { - t.Errorf("Expected cluster name to be dummyClusterName but found %s", scope.ClusterConfig.Name) + if scope.MachineConfig.Name != "dummyClusterName" { + t.Errorf("Expected cluster name to be dummyClusterName but found %s", scope.MachineConfig.Name) } - if scope.ClusterConfig.ResourceGroup != "dummyResourceGroup" { - t.Errorf("Expected resourcegroup to be dummyResourceGroup but found %s", scope.ClusterConfig.ResourceGroup) + if scope.MachineConfig.ResourceGroup != "dummyResourceGroup" { + t.Errorf("Expected resourcegroup to be dummyResourceGroup but found %s", scope.MachineConfig.ResourceGroup) } } func testCredentialFields(credentialsSecret *corev1.Secret) error { - scope := &Scope{ClusterConfig: &clusterproviderv1.AzureClusterProviderSpec{}} - return updateScope( + scope := &MachineScope{ + MachineConfig: &providerspecv1.AzureMachineProviderSpec{ + CredentialsSecret: &corev1.SecretReference{Name: "testCredentials", Namespace: "dummyNamespace"}, + }, + } + return updateFromSecret( controllerfake.NewFakeClient(credentialsSecret), - &corev1.SecretReference{Name: "testCredentials", Namespace: "dummyNamespace"}, scope) } @@ -195,15 +200,15 @@ func testCredentialSecret() *corev1.Secret { } } -func testProviderSpec() *machineproviderv1.AzureMachineProviderSpec { - return &machineproviderv1.AzureMachineProviderSpec{ +func testProviderSpec() *providerspecv1.AzureMachineProviderSpec { + return &providerspecv1.AzureMachineProviderSpec{ Location: "test", ResourceGroup: "test", CredentialsSecret: &corev1.SecretReference{Name: "testCredentials", Namespace: "dummyNamespace"}, } } -func testMachineWithProviderSpec(t *testing.T, providerSpec *machineproviderv1.AzureMachineProviderSpec) *machinev1.Machine { +func testMachineWithProviderSpec(t *testing.T, providerSpec *providerspecv1.AzureMachineProviderSpec) *machinev1.Machine { providerSpecWithValues, err := providerSpecFromMachine(providerSpec) if err != nil { t.Fatalf("error encoding provider config: %v", err) @@ -265,7 +270,7 @@ func TestPersistMachineScope(t *testing.T) { t.Errorf("Expected annotation 'test' to equal 'testValue', got %q instead", scope.Machine.Annotations["test"]) } - machineStatus, err := machineproviderv1.MachineStatusFromProviderStatus(scope.Machine.Status.ProviderStatus) + machineStatus, err := providerspecv1.MachineStatusFromProviderStatus(scope.Machine.Status.ProviderStatus) if err != nil { t.Errorf("failed to get machine provider status: %v", err) } @@ -278,7 +283,7 @@ func TestPersistMachineScope(t *testing.T) { } func TestNewMachineScope(t *testing.T) { - machineConfigNoValues := &machineproviderv1.AzureMachineProviderSpec{ + machineConfigNoValues := &providerspecv1.AzureMachineProviderSpec{ CredentialsSecret: &corev1.SecretReference{Name: "testCredentials", Namespace: "dummyNamespace"}, } @@ -311,11 +316,11 @@ func TestNewMachineScope(t *testing.T) { t.Fatalf("Unexpected error %v", err) } - if scope.ClusterConfig.Location != tc.expectedLocation { - t.Errorf("Expected %v, got: %v", tc.expectedLocation, scope.ClusterConfig.Location) + if scope.MachineConfig.Location != tc.expectedLocation { + t.Errorf("Expected %v, got: %v", tc.expectedLocation, scope.MachineConfig.Location) } - if scope.ClusterConfig.ResourceGroup != tc.expectedResourceGroup { - t.Errorf("Expected %v, got: %v", tc.expectedResourceGroup, scope.ClusterConfig.ResourceGroup) + if scope.MachineConfig.ResourceGroup != tc.expectedResourceGroup { + t.Errorf("Expected %v, got: %v", tc.expectedResourceGroup, scope.MachineConfig.ResourceGroup) } } } diff --git a/pkg/cloud/azure/actuators/scope.go b/pkg/cloud/azure/actuators/scope.go deleted file mode 100644 index 4eb9201a312..00000000000 --- a/pkg/cloud/azure/actuators/scope.go +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package actuators - -import ( - "context" - - "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1alpha1" -) - -// ScopeParams defines the input parameters used to create a new Scope. -type ScopeParams struct { - AzureClients -} - -// NewScope creates a new Scope from the supplied parameters. -// This is meant to be called for each different actuator iteration. -func NewScope(params ScopeParams) (*Scope, error) { - return &Scope{ - AzureClients: params.AzureClients, - ClusterConfig: &v1alpha1.AzureClusterProviderSpec{}, - Context: context.Background(), - }, nil -} - -// Scope defines the basic context for an actuator to operate upon. -type Scope struct { - AzureClients - ClusterConfig *v1alpha1.AzureClusterProviderSpec - Context context.Context -} - -// Vnet returns the cluster Vnet. -func (s *Scope) Vnet() *v1alpha1.VnetSpec { - return &s.ClusterConfig.NetworkSpec.Vnet -} - -// Subnets returns the cluster subnets. -func (s *Scope) Subnets() v1alpha1.Subnets { - return s.ClusterConfig.NetworkSpec.Subnets -} - -// Location returns the cluster location. -func (s *Scope) Location() string { - return s.ClusterConfig.Location -} - -// Network returns the cluster network object. -func (s *Scope) Network() *v1alpha1.Network { - return nil -} diff --git a/pkg/cloud/azure/services/applicationsecuritygroups/applicationsecuritygroups.go b/pkg/cloud/azure/services/applicationsecuritygroups/applicationsecuritygroups.go index 2ed1cb9338e..2aef9609273 100644 --- a/pkg/cloud/azure/services/applicationsecuritygroups/applicationsecuritygroups.go +++ b/pkg/cloud/azure/services/applicationsecuritygroups/applicationsecuritygroups.go @@ -38,7 +38,7 @@ func (s *Service) Get(ctx context.Context, spec azure.Spec) (interface{}, error) if !ok { return network.ApplicationSecurityGroup{}, errors.New("invalid application security groups specification") } - applicationSecurityGroup, err := s.Client.Get(ctx, s.Scope.ClusterConfig.ResourceGroup, asgSpec.Name) + applicationSecurityGroup, err := s.Client.Get(ctx, s.Scope.MachineConfig.ResourceGroup, asgSpec.Name) if err != nil && azure.ResourceNotFound(err) { return nil, fmt.Errorf("application security group %s not found: %w", asgSpec.Name, err) } else if err != nil { @@ -57,14 +57,14 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { klog.V(2).Infof("creating application security group %s", asgSpec.Name) f, err := s.Client.CreateOrUpdate( ctx, - s.Scope.ClusterConfig.ResourceGroup, + s.Scope.MachineConfig.ResourceGroup, asgSpec.Name, network.ApplicationSecurityGroup{ - Location: to.StringPtr(s.Scope.ClusterConfig.Location), + Location: to.StringPtr(s.Scope.MachineConfig.Location), }, ) if err != nil { - return fmt.Errorf("failed to create application security group %s in resource group %s: %w", asgSpec.Name, s.Scope.ClusterConfig.ResourceGroup, err) + return fmt.Errorf("failed to create application security group %s in resource group %s: %w", asgSpec.Name, s.Scope.MachineConfig.ResourceGroup, err) } err = f.WaitForCompletionRef(ctx, s.Client.Client) @@ -87,13 +87,13 @@ func (s *Service) Delete(ctx context.Context, spec azure.Spec) error { return errors.New("invalid application security groups specification") } klog.V(2).Infof("deleting application security group %s", asgSpec.Name) - f, err := s.Client.Delete(ctx, s.Scope.ClusterConfig.ResourceGroup, asgSpec.Name) + f, err := s.Client.Delete(ctx, s.Scope.MachineConfig.ResourceGroup, asgSpec.Name) if err != nil && azure.ResourceNotFound(err) { // already deleted return nil } if err != nil { - return fmt.Errorf("failed to delete application security group %s in resource group %s: %w", asgSpec.Name, s.Scope.ClusterConfig.ResourceGroup, err) + return fmt.Errorf("failed to delete application security group %s in resource group %s: %w", asgSpec.Name, s.Scope.MachineConfig.ResourceGroup, err) } err = f.WaitForCompletionRef(ctx, s.Client.Client) diff --git a/pkg/cloud/azure/services/applicationsecuritygroups/service.go b/pkg/cloud/azure/services/applicationsecuritygroups/service.go index aa18909e6f7..26802c5763b 100644 --- a/pkg/cloud/azure/services/applicationsecuritygroups/service.go +++ b/pkg/cloud/azure/services/applicationsecuritygroups/service.go @@ -26,7 +26,7 @@ import ( // Service provides operations on resource groups type Service struct { Client network.ApplicationSecurityGroupsClient - Scope *actuators.Scope + Scope *actuators.MachineScope } // getGroupsClient creates a new groups client from subscriptionid. @@ -38,7 +38,7 @@ func getApplicationSecurityGroupsClient(subscriptionID string, authorizer autore } // NewService creates a new groups service. -func NewService(scope *actuators.Scope) azure.Service { +func NewService(scope *actuators.MachineScope) azure.Service { return &Service{ Client: getApplicationSecurityGroupsClient(scope.SubscriptionID, scope.Authorizer), Scope: scope, diff --git a/pkg/cloud/azure/services/availabilityzones/availabilityzones.go b/pkg/cloud/azure/services/availabilityzones/availabilityzones.go index 8fdef7b116c..9f77284fe36 100644 --- a/pkg/cloud/azure/services/availabilityzones/availabilityzones.go +++ b/pkg/cloud/azure/services/availabilityzones/availabilityzones.go @@ -44,7 +44,7 @@ func (s *Service) Get(ctx context.Context, spec azure.Spec) (interface{}, error) for _, resSku := range res.Values() { if strings.EqualFold(*resSku.Name, skusSpec.VMSize) { for _, locationInfo := range *resSku.LocationInfo { - if strings.EqualFold(*locationInfo.Location, s.Scope.ClusterConfig.Location) { + if strings.EqualFold(*locationInfo.Location, s.Scope.MachineConfig.Location) { zones = *locationInfo.Zones } } diff --git a/pkg/cloud/azure/services/availabilityzones/service.go b/pkg/cloud/azure/services/availabilityzones/service.go index 7bc3cf4b293..de5850d2085 100644 --- a/pkg/cloud/azure/services/availabilityzones/service.go +++ b/pkg/cloud/azure/services/availabilityzones/service.go @@ -26,7 +26,7 @@ import ( // Service provides operations on availability zones type Service struct { Client compute.ResourceSkusClient - Scope *actuators.Scope + Scope *actuators.MachineScope } // getResourceSkusClient creates a new availability zones client from subscriptionid. @@ -38,7 +38,7 @@ func getResourceSkusClient(subscriptionID string, authorizer autorest.Authorizer } // NewService creates a new availability zones service. -func NewService(scope *actuators.Scope) azure.Service { +func NewService(scope *actuators.MachineScope) azure.Service { return &Service{ Client: getResourceSkusClient(scope.SubscriptionID, scope.Authorizer), Scope: scope, diff --git a/pkg/cloud/azure/services/disks/disks.go b/pkg/cloud/azure/services/disks/disks.go index b51418f5693..ad2f899d31f 100644 --- a/pkg/cloud/azure/services/disks/disks.go +++ b/pkg/cloud/azure/services/disks/disks.go @@ -48,13 +48,13 @@ func (s *Service) Delete(ctx context.Context, spec azure.Spec) error { return errors.New("Invalid disk specification") } klog.V(2).Infof("deleting disk %s", diskSpec.Name) - future, err := s.Client.Delete(ctx, s.Scope.ClusterConfig.ResourceGroup, diskSpec.Name) + future, err := s.Client.Delete(ctx, s.Scope.MachineConfig.ResourceGroup, diskSpec.Name) if err != nil && azure.ResourceNotFound(err) { // already deleted return nil } if err != nil { - return fmt.Errorf("failed to delete disk %s in resource group %s: %w", diskSpec.Name, s.Scope.ClusterConfig.ResourceGroup, err) + return fmt.Errorf("failed to delete disk %s in resource group %s: %w", diskSpec.Name, s.Scope.MachineConfig.ResourceGroup, err) } // Do not wait until the operation completes. Just check the result diff --git a/pkg/cloud/azure/services/disks/service.go b/pkg/cloud/azure/services/disks/service.go index 5335fcda6b1..75b3fce8043 100644 --- a/pkg/cloud/azure/services/disks/service.go +++ b/pkg/cloud/azure/services/disks/service.go @@ -28,7 +28,7 @@ var _ azure.Service = (*Service)(nil) // Service provides operations on resource groups type Service struct { Client compute.DisksClient - Scope *actuators.Scope + Scope *actuators.MachineScope } // getGroupsClient creates a new groups client from subscriptionid. @@ -40,7 +40,7 @@ func getDisksClient(subscriptionID string, authorizer autorest.Authorizer) compu } // NewService creates a new groups service. -func NewService(scope *actuators.Scope) *Service { +func NewService(scope *actuators.MachineScope) *Service { return &Service{ Client: getDisksClient(scope.SubscriptionID, scope.Authorizer), Scope: scope, diff --git a/pkg/cloud/azure/services/groups/groups.go b/pkg/cloud/azure/services/groups/groups.go index 1bd56f3cfa5..7c620bf4eac 100644 --- a/pkg/cloud/azure/services/groups/groups.go +++ b/pkg/cloud/azure/services/groups/groups.go @@ -28,23 +28,23 @@ import ( // Get provides information about a resource group. func (s *Service) Get(ctx context.Context, spec azure.Spec) (interface{}, error) { - return s.Client.Get(ctx, s.Scope.ClusterConfig.ResourceGroup) + return s.Client.Get(ctx, s.Scope.MachineConfig.ResourceGroup) } // CreateOrUpdate creates or updates a resource group. func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { - klog.V(2).Infof("creating resource group %s", s.Scope.ClusterConfig.ResourceGroup) - _, err := s.Client.CreateOrUpdate(ctx, s.Scope.ClusterConfig.ResourceGroup, resources.Group{Location: to.StringPtr(s.Scope.ClusterConfig.Location)}) - klog.V(2).Infof("successfully created resource group %s", s.Scope.ClusterConfig.ResourceGroup) + klog.V(2).Infof("creating resource group %s", s.Scope.MachineConfig.ResourceGroup) + _, err := s.Client.CreateOrUpdate(ctx, s.Scope.MachineConfig.ResourceGroup, resources.Group{Location: to.StringPtr(s.Scope.MachineConfig.Location)}) + klog.V(2).Infof("successfully created resource group %s", s.Scope.MachineConfig.ResourceGroup) return err } // Delete deletes the resource group with the provided name. func (s *Service) Delete(ctx context.Context, spec azure.Spec) error { - klog.V(2).Infof("deleting resource group %s", s.Scope.ClusterConfig.ResourceGroup) - future, err := s.Client.Delete(ctx, s.Scope.ClusterConfig.ResourceGroup) + klog.V(2).Infof("deleting resource group %s", s.Scope.MachineConfig.ResourceGroup) + future, err := s.Client.Delete(ctx, s.Scope.MachineConfig.ResourceGroup) if err != nil { - return fmt.Errorf("failed to delete resource group %s: %w", s.Scope.ClusterConfig.ResourceGroup, err) + return fmt.Errorf("failed to delete resource group %s: %w", s.Scope.MachineConfig.ResourceGroup, err) } err = future.WaitForCompletionRef(ctx, s.Client.Client) @@ -54,6 +54,6 @@ func (s *Service) Delete(ctx context.Context, spec azure.Spec) error { _, err = future.Result(s.Client) - klog.V(2).Infof("successfully deleted resource group %s", s.Scope.ClusterConfig.ResourceGroup) + klog.V(2).Infof("successfully deleted resource group %s", s.Scope.MachineConfig.ResourceGroup) return err } diff --git a/pkg/cloud/azure/services/groups/service.go b/pkg/cloud/azure/services/groups/service.go index 3c2a929e77f..641a0726eda 100644 --- a/pkg/cloud/azure/services/groups/service.go +++ b/pkg/cloud/azure/services/groups/service.go @@ -26,7 +26,7 @@ import ( // Service provides operations on resource groups type Service struct { Client resources.GroupsClient - Scope *actuators.Scope + Scope *actuators.MachineScope } // getGroupsClient creates a new groups client from subscriptionid. @@ -38,7 +38,7 @@ func getGroupsClient(subscriptionID string, authorizer autorest.Authorizer) reso } // NewService creates a new groups service. -func NewService(scope *actuators.Scope) azure.Service { +func NewService(scope *actuators.MachineScope) azure.Service { return &Service{ Client: getGroupsClient(scope.SubscriptionID, scope.Authorizer), Scope: scope, diff --git a/pkg/cloud/azure/services/internalloadbalancers/internalloadbalancers.go b/pkg/cloud/azure/services/internalloadbalancers/internalloadbalancers.go index 6204ac91358..a8b4616cf94 100644 --- a/pkg/cloud/azure/services/internalloadbalancers/internalloadbalancers.go +++ b/pkg/cloud/azure/services/internalloadbalancers/internalloadbalancers.go @@ -43,7 +43,7 @@ func (s *Service) Get(ctx context.Context, spec azure.Spec) (interface{}, error) return network.LoadBalancer{}, errors.New("invalid internal load balancer specification") } //lbName := fmt.Sprintf("%s-api-internallb", s.Scope.Cluster.Name) - lb, err := s.Client.Get(ctx, s.Scope.ClusterConfig.ResourceGroup, internalLBSpec.Name, "") + lb, err := s.Client.Get(ctx, s.Scope.MachineConfig.ResourceGroup, internalLBSpec.Name, "") if err != nil && azure.ResourceNotFound(err) { return nil, fmt.Errorf("load balancer %s not found: %w", internalLBSpec.Name, err) } else if err != nil { @@ -62,7 +62,7 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { probeName := "tcpHTTPSProbe" frontEndIPConfigName := "controlplane-internal-lbFrontEnd" backEndAddressPoolName := "controlplane-internal-backEndPool" - idPrefix := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/loadBalancers", s.Scope.SubscriptionID, s.Scope.ClusterConfig.ResourceGroup) + idPrefix := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/loadBalancers", s.Scope.SubscriptionID, s.Scope.MachineConfig.ResourceGroup) lbName := internalLBSpec.Name klog.V(2).Infof("getting subnet %s", internalLBSpec.SubnetName) @@ -79,11 +79,11 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { // https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-standard-availability-zones#zone-redundant-by-default future, err := s.Client.CreateOrUpdate(ctx, - s.Scope.ClusterConfig.ResourceGroup, + s.Scope.MachineConfig.ResourceGroup, lbName, network.LoadBalancer{ Sku: &network.LoadBalancerSku{Name: network.LoadBalancerSkuNameStandard}, - Location: to.StringPtr(s.Scope.ClusterConfig.Location), + Location: to.StringPtr(s.Scope.MachineConfig.Location), LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{ FrontendIPConfigurations: &[]network.FrontendIPConfiguration{ { @@ -157,13 +157,13 @@ func (s *Service) Delete(ctx context.Context, spec azure.Spec) error { return errors.New("invalid internal load balancer specification") } klog.V(2).Infof("deleting internal load balancer %s", internalLBSpec.Name) - f, err := s.Client.Delete(ctx, s.Scope.ClusterConfig.ResourceGroup, internalLBSpec.Name) + f, err := s.Client.Delete(ctx, s.Scope.MachineConfig.ResourceGroup, internalLBSpec.Name) if err != nil && azure.ResourceNotFound(err) { // already deleted return nil } if err != nil { - return fmt.Errorf("failed to delete internal load balancer %s in resource group %s: %w", internalLBSpec.Name, s.Scope.ClusterConfig.ResourceGroup, err) + return fmt.Errorf("failed to delete internal load balancer %s in resource group %s: %w", internalLBSpec.Name, s.Scope.MachineConfig.ResourceGroup, err) } err = f.WaitForCompletionRef(ctx, s.Client.Client) diff --git a/pkg/cloud/azure/services/internalloadbalancers/service.go b/pkg/cloud/azure/services/internalloadbalancers/service.go index ba5c67fb3dc..cff2c7e83d4 100644 --- a/pkg/cloud/azure/services/internalloadbalancers/service.go +++ b/pkg/cloud/azure/services/internalloadbalancers/service.go @@ -26,7 +26,7 @@ import ( // Service provides operations on resource groups type Service struct { Client network.LoadBalancersClient - Scope *actuators.Scope + Scope *actuators.MachineScope } // getGroupsClient creates a new groups client from subscriptionid. @@ -38,7 +38,7 @@ func getLoadbalancersClient(subscriptionID string, authorizer autorest.Authorize } // NewService creates a new groups service. -func NewService(scope *actuators.Scope) azure.Service { +func NewService(scope *actuators.MachineScope) azure.Service { return &Service{ Client: getLoadbalancersClient(scope.SubscriptionID, scope.Authorizer), Scope: scope, diff --git a/pkg/cloud/azure/services/mock_interfaces.go b/pkg/cloud/azure/services/mock_interfaces.go deleted file mode 100644 index 8b8c6704721..00000000000 --- a/pkg/cloud/azure/services/mock_interfaces.go +++ /dev/null @@ -1,268 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package services - -import ( - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute" - "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network" - "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources" - "github.com/Azure/go-autorest/autorest" - machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1" - clusterproviderv1 "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1alpha1" - machineproviderv1 "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1beta1" -) - -// MockAzureComputeClient is a mock implementation of AzureComputeClient. -type MockAzureComputeClient struct { - MockRunCommand func(resourceGroup string, name string, cmd string) (compute.VirtualMachinesRunCommandFuture, error) - MockVMIfExists func(resourceGroup string, name string) (*compute.VirtualMachine, error) - MockDeleteVM func(resourceGroup string, name string) (compute.VirtualMachinesDeleteFuture, error) - MockWaitForVMRunCommandFuture func(future compute.VirtualMachinesRunCommandFuture) error - MockWaitForVMDeletionFuture func(future compute.VirtualMachinesDeleteFuture) error - MockDeleteManagedDisk func(resourceGroup string, name string) (compute.DisksDeleteFuture, error) - MockWaitForDisksDeleteFuture func(future compute.DisksDeleteFuture) error -} - -// MockAzureNetworkClient is a mock implementation of MockAzureNetworkClient. -type MockAzureNetworkClient struct { - MockDeleteNetworkInterface func(resourceGroup string, networkInterfaceName string) (network.InterfacesDeleteFuture, error) - MockWaitForNetworkInterfacesDeleteFuture func(future network.InterfacesDeleteFuture) error - - MockCreateOrUpdateNetworkSecurityGroup func(resourceGroupName string, networkSecurityGroupName string, location string) (*network.SecurityGroupsCreateOrUpdateFuture, error) - MockNetworkSGIfExists func(resourceGroupName string, networkSecurityGroupName string) (*network.SecurityGroup, error) - MockWaitForNetworkSGsCreateOrUpdateFuture func(future network.SecurityGroupsCreateOrUpdateFuture) error - - MockCreateOrUpdatePublicIPAddress func(resourceGroup string, IPName string) (network.PublicIPAddress, error) - MockDeletePublicIPAddress func(resourceGroup string, IPName string) (network.PublicIPAddressesDeleteFuture, error) - MockWaitForPublicIPAddressDeleteFuture func(future network.PublicIPAddressesDeleteFuture) error - - MockCreateOrUpdateVnet func(resourceGroupName string, virtualNetworkName string, location string) (*network.VirtualNetworksCreateOrUpdateFuture, error) - MockWaitForVnetCreateOrUpdateFuture func(future network.VirtualNetworksCreateOrUpdateFuture) error -} - -// MockAzureResourcesClient is a mock implementation of MockAzureResourcesClient. -type MockAzureResourcesClient struct { - MockCreateOrUpdateGroup func(resourceGroupName string, location string) (resources.Group, error) - MockDeleteGroup func(resourceGroupName string) (resources.GroupsDeleteFuture, error) - MockCheckGroupExistence func(rgName string) (autorest.Response, error) - MockWaitForGroupsDeleteFuture func(future resources.GroupsDeleteFuture) error - - MockCreateOrUpdateDeployment func(machine *machinev1.Machine, clusterConfig *clusterproviderv1.AzureClusterProviderSpec, machineConfig *machineproviderv1.AzureMachineProviderSpec) (*resources.DeploymentsCreateOrUpdateFuture, error) - MockGetDeploymentResult func(future resources.DeploymentsCreateOrUpdateFuture) (de resources.DeploymentExtended, err error) - MockValidateDeployment func(machine *machinev1.Machine, clusterConfig *clusterproviderv1.AzureClusterProviderSpec, machineConfig *machineproviderv1.AzureMachineProviderSpec) error - MockWaitForDeploymentsCreateOrUpdateFuture func(future resources.DeploymentsCreateOrUpdateFuture) error -} - -// RunCommand executes a command on the VM. -func (m *MockAzureComputeClient) RunCommand(resourceGroup string, name string, cmd string) (compute.VirtualMachinesRunCommandFuture, error) { - if m.MockRunCommand == nil { - return compute.VirtualMachinesRunCommandFuture{}, nil - } - return m.MockRunCommand(resourceGroup, name, cmd) -} - -// VMIfExists returns the reference to the VM object if it exists. -func (m *MockAzureComputeClient) VMIfExists(resourceGroup string, name string) (*compute.VirtualMachine, error) { - if m.MockVMIfExists == nil { - return nil, nil - } - return m.MockVMIfExists(resourceGroup, name) -} - -// DeleteVM deletes the virtual machine. -func (m *MockAzureComputeClient) DeleteVM(resourceGroup string, name string) (compute.VirtualMachinesDeleteFuture, error) { - if m.MockDeleteVM == nil { - return compute.VirtualMachinesDeleteFuture{}, nil - } - return m.MockDeleteVM(resourceGroup, name) -} - -// DeleteManagedDisk deletes a managed disk resource. -func (m *MockAzureComputeClient) DeleteManagedDisk(resourceGroup string, name string) (compute.DisksDeleteFuture, error) { - if m.MockDeleteManagedDisk == nil { - return compute.DisksDeleteFuture{}, nil - } - return m.MockDeleteManagedDisk(resourceGroup, name) -} - -// WaitForVMRunCommandFuture returns when the RunCommand operation completes. -func (m *MockAzureComputeClient) WaitForVMRunCommandFuture(future compute.VirtualMachinesRunCommandFuture) error { - if m.MockWaitForVMRunCommandFuture == nil { - return nil - } - return m.MockWaitForVMRunCommandFuture(future) -} - -// WaitForVMDeletionFuture returns when the DeleteVM operation completes. -func (m *MockAzureComputeClient) WaitForVMDeletionFuture(future compute.VirtualMachinesDeleteFuture) error { - if m.MockWaitForVMDeletionFuture == nil { - return nil - } - return m.MockWaitForVMDeletionFuture(future) -} - -// WaitForDisksDeleteFuture waits for the DeleteManagedDisk operation to complete. -func (m *MockAzureComputeClient) WaitForDisksDeleteFuture(future compute.DisksDeleteFuture) error { - if m.MockWaitForDisksDeleteFuture == nil { - return nil - } - return m.MockWaitForDisksDeleteFuture(future) -} - -// DeleteNetworkInterface deletes the NIC resource. -func (m *MockAzureNetworkClient) DeleteNetworkInterface(resourceGroup string, networkInterfaceName string) (network.InterfacesDeleteFuture, error) { - if m.MockDeleteNetworkInterface == nil { - return network.InterfacesDeleteFuture{}, nil - } - return m.MockDeleteNetworkInterface(resourceGroup, networkInterfaceName) -} - -// WaitForNetworkInterfacesDeleteFuture returns when the DeleteNetworkInterface operation completes. -func (m *MockAzureNetworkClient) WaitForNetworkInterfacesDeleteFuture(future network.InterfacesDeleteFuture) error { - if m.MockWaitForNetworkInterfacesDeleteFuture == nil { - return nil - } - return m.MockWaitForNetworkInterfacesDeleteFuture(future) -} - -// CreateOrUpdatePublicIPAddress retrieves the reference of the PublicIPAddress resource. -func (m *MockAzureNetworkClient) CreateOrUpdatePublicIPAddress(resourceGroup string, IPName string) (network.PublicIPAddress, error) { - if m.MockCreateOrUpdatePublicIPAddress == nil { - return network.PublicIPAddress{}, nil - } - return m.MockCreateOrUpdatePublicIPAddress(resourceGroup, IPName) -} - -// DeletePublicIPAddress deletes the PublicIPAddress resource. -func (m *MockAzureNetworkClient) DeletePublicIPAddress(resourceGroup string, IPName string) (network.PublicIPAddressesDeleteFuture, error) { - if m.MockDeletePublicIPAddress == nil { - return network.PublicIPAddressesDeleteFuture{}, nil - } - return m.MockDeletePublicIPAddress(resourceGroup, IPName) -} - -// WaitForPublicIPAddressDeleteFuture returns when the DeletePublicIPAddress completes. -func (m *MockAzureNetworkClient) WaitForPublicIPAddressDeleteFuture(future network.PublicIPAddressesDeleteFuture) error { - if m.MockWaitForPublicIPAddressDeleteFuture == nil { - return nil - } - return m.MockWaitForPublicIPAddressDeleteFuture(future) -} - -// CreateOrUpdateNetworkSecurityGroup creates or updates the NSG resource. -func (m *MockAzureNetworkClient) CreateOrUpdateNetworkSecurityGroup(resourceGroupName string, networkSecurityGroupName string, location string) (*network.SecurityGroupsCreateOrUpdateFuture, error) { - if m.MockCreateOrUpdateNetworkSecurityGroup == nil { - return nil, nil - } - return m.MockCreateOrUpdateNetworkSecurityGroup(resourceGroupName, networkSecurityGroupName, location) -} - -// NetworkSGIfExists returns the nsg resource reference if it exists. -func (m *MockAzureNetworkClient) NetworkSGIfExists(resourceGroupName string, networkSecurityGroupName string) (*network.SecurityGroup, error) { - if m.MockNetworkSGIfExists == nil { - return nil, nil - } - return m.MockNetworkSGIfExists(resourceGroupName, networkSecurityGroupName) -} - -// WaitForNetworkSGsCreateOrUpdateFuture returns when the CreateOrUpdateNetworkSecurityGroup operation completes. -func (m *MockAzureNetworkClient) WaitForNetworkSGsCreateOrUpdateFuture(future network.SecurityGroupsCreateOrUpdateFuture) error { - if m.MockWaitForNetworkSGsCreateOrUpdateFuture == nil { - return nil - } - return m.MockWaitForNetworkSGsCreateOrUpdateFuture(future) -} - -// CreateOrUpdateVnet creates or updates the vnet resource. -func (m *MockAzureNetworkClient) CreateOrUpdateVnet(resourceGroupName string, virtualNetworkName string, location string) (*network.VirtualNetworksCreateOrUpdateFuture, error) { - if m.MockCreateOrUpdateVnet == nil { - return nil, nil - } - return m.MockCreateOrUpdateVnet(resourceGroupName, virtualNetworkName, location) -} - -// WaitForVnetCreateOrUpdateFuture returns when the CreateOrUpdateVnet operation completes. -func (m *MockAzureNetworkClient) WaitForVnetCreateOrUpdateFuture(future network.VirtualNetworksCreateOrUpdateFuture) error { - if m.MockWaitForVnetCreateOrUpdateFuture == nil { - return nil - } - return m.MockWaitForVnetCreateOrUpdateFuture(future) -} - -// CreateOrUpdateGroup creates or updates an azure resource group. -func (m *MockAzureResourcesClient) CreateOrUpdateGroup(resourceGroupName string, location string) (resources.Group, error) { - if m.MockCreateOrUpdateGroup == nil { - return resources.Group{}, nil - } - return m.MockCreateOrUpdateGroup(resourceGroupName, location) -} - -// DeleteGroup deletes an azure resource group. -func (m *MockAzureResourcesClient) DeleteGroup(resourceGroupName string) (resources.GroupsDeleteFuture, error) { - if m.MockDeleteGroup == nil { - return resources.GroupsDeleteFuture{}, nil - } - return m.MockDeleteGroup(resourceGroupName) -} - -// CheckGroupExistence checks if a resource group with name 'rgName' exists. -func (m *MockAzureResourcesClient) CheckGroupExistence(rgName string) (autorest.Response, error) { - if m.MockCheckGroupExistence == nil { - return autorest.Response{}, nil - } - return m.MockCheckGroupExistence(rgName) -} - -// WaitForGroupsDeleteFuture returns when the DeleteGroup operation completes. -func (m *MockAzureResourcesClient) WaitForGroupsDeleteFuture(future resources.GroupsDeleteFuture) error { - if m.MockWaitForGroupsDeleteFuture == nil { - return nil - } - return m.MockWaitForGroupsDeleteFuture(future) -} - -// CreateOrUpdateDeployment creates or updates an ARM deployment. -func (m *MockAzureResourcesClient) CreateOrUpdateDeployment(machine *machinev1.Machine, clusterConfig *clusterproviderv1.AzureClusterProviderSpec, machineConfig *machineproviderv1.AzureMachineProviderSpec) (*resources.DeploymentsCreateOrUpdateFuture, error) { - if m.MockCreateOrUpdateDeployment == nil { - return nil, nil - } - return m.MockCreateOrUpdateDeployment(machine, clusterConfig, machineConfig) -} - -// ValidateDeployment validates an ARM deployment. -func (m *MockAzureResourcesClient) ValidateDeployment(machine *machinev1.Machine, clusterConfig *clusterproviderv1.AzureClusterProviderSpec, machineConfig *machineproviderv1.AzureMachineProviderSpec) error { - if m.MockValidateDeployment == nil { - return nil - } - return m.MockValidateDeployment(machine, clusterConfig, machineConfig) -} - -// GetDeploymentResult retrives an existing ARM deployment reference. -func (m *MockAzureResourcesClient) GetDeploymentResult(future resources.DeploymentsCreateOrUpdateFuture) (de resources.DeploymentExtended, err error) { - if m.MockGetDeploymentResult == nil { - return resources.DeploymentExtended{}, nil - } - return m.MockGetDeploymentResult(future) -} - -// WaitForDeploymentsCreateOrUpdateFuture returns when the CreateOrUpdateDeployment operation completes. -func (m *MockAzureResourcesClient) WaitForDeploymentsCreateOrUpdateFuture(future resources.DeploymentsCreateOrUpdateFuture) error { - if m.MockWaitForDeploymentsCreateOrUpdateFuture == nil { - return nil - } - return m.MockWaitForDeploymentsCreateOrUpdateFuture(future) -} diff --git a/pkg/cloud/azure/services/mock_interfaces_helper.go b/pkg/cloud/azure/services/mock_interfaces_helper.go deleted file mode 100644 index cda916cee35..00000000000 --- a/pkg/cloud/azure/services/mock_interfaces_helper.go +++ /dev/null @@ -1,359 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package services - -import ( - "errors" - "fmt" - "net/http" - - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute" - "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network" - "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources" - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" - machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1" - clusterproviderv1 "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1alpha1" - machineproviderv1 "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1beta1" -) - -// MockVMExists mocks the VMIfExists success response. -func MockVMExists() MockAzureComputeClient { - return MockAzureComputeClient{ - MockVMIfExists: func(resourceGroup string, name string) (*compute.VirtualMachine, error) { - networkProfile := compute.NetworkProfile{NetworkInterfaces: &[]compute.NetworkInterfaceReference{{ID: to.StringPtr("001")}}} - OsDiskName := fmt.Sprintf("OS_Disk_%v", name) - storageProfile := compute.StorageProfile{OsDisk: &compute.OSDisk{Name: &OsDiskName}} - vmProperties := compute.VirtualMachineProperties{StorageProfile: &storageProfile, NetworkProfile: &networkProfile} - return &compute.VirtualMachine{Name: &name, VirtualMachineProperties: &vmProperties}, nil - }, - } -} - -// MockVMExistsNICInvalid mocks the VMIfExists Invalid NIC response. -func MockVMExistsNICInvalid() MockAzureComputeClient { - return MockAzureComputeClient{ - MockVMIfExists: func(resourceGroup string, name string) (*compute.VirtualMachine, error) { - networkProfile := compute.NetworkProfile{NetworkInterfaces: &[]compute.NetworkInterfaceReference{{ID: to.StringPtr("")}}} - OsDiskName := fmt.Sprintf("OS_Disk_%v", name) - storageProfile := compute.StorageProfile{OsDisk: &compute.OSDisk{Name: &OsDiskName}} - vmProperties := compute.VirtualMachineProperties{StorageProfile: &storageProfile, NetworkProfile: &networkProfile} - return &compute.VirtualMachine{Name: &name, VirtualMachineProperties: &vmProperties}, nil - }, - } -} - -// MockVMNotExists mocks the VMExists not found response. -func MockVMNotExists() MockAzureComputeClient { - return MockAzureComputeClient{ - MockVMIfExists: func(resourceGroup string, name string) (*compute.VirtualMachine, error) { - return nil, nil - }, - } -} - -// MockVMCheckFailure mocks the VMIfExists failure response -func MockVMCheckFailure() MockAzureComputeClient { - return MockAzureComputeClient{ - MockVMIfExists: func(resourceGroup string, name string) (*compute.VirtualMachine, error) { - return &compute.VirtualMachine{}, errors.New("error while checking if vm exists") - }, - } -} - -// MockVMDeleteFailure mocks the VMDelete failure response. -func MockVMDeleteFailure() MockAzureComputeClient { - return MockAzureComputeClient{ - MockDeleteVM: func(resourceGroup string, name string) (compute.VirtualMachinesDeleteFuture, error) { - return compute.VirtualMachinesDeleteFuture{}, errors.New("error while deleting vm") - }, - } -} - -// MockVMDeleteFutureFailure mocks the VMDeleteFutureFailure response. -func MockVMDeleteFutureFailure() MockAzureComputeClient { - return MockAzureComputeClient{ - MockWaitForVMDeletionFuture: func(future compute.VirtualMachinesDeleteFuture) error { - return errors.New("failed on waiting for VirtualMachinesDeleteFuture") - }, - } -} - -// MockDisksDeleteFailure mocks the Disks Delete failure response. -func MockDisksDeleteFailure() MockAzureComputeClient { - return MockAzureComputeClient{ - MockDeleteManagedDisk: func(resourceGroup string, name string) (compute.DisksDeleteFuture, error) { - return compute.DisksDeleteFuture{}, errors.New("error while deleting managed disk") - }, - } -} - -// MockDisksDeleteFutureFailure mocks the Disks Delete Future failure response. -func MockDisksDeleteFutureFailure() MockAzureComputeClient { - return MockAzureComputeClient{ - MockWaitForDisksDeleteFuture: func(future compute.DisksDeleteFuture) error { - return errors.New("failed on waiting for VirtualMachinesDeleteFuture") - }, - } -} - -// MockRunCommandFailure mocks the RunCommand failure response. -func MockRunCommandFailure() MockAzureComputeClient { - return MockAzureComputeClient{ - MockRunCommand: func(resourceGroup string, name string, cmd string) (compute.VirtualMachinesRunCommandFuture, error) { - return compute.VirtualMachinesRunCommandFuture{}, errors.New("error while running command on vm") - }, - } -} - -// MockRunCommandFutureFailure mocks the RunCommand's future failure response. -func MockRunCommandFutureFailure() MockAzureComputeClient { - return MockAzureComputeClient{ - MockWaitForVMRunCommandFuture: func(future compute.VirtualMachinesRunCommandFuture) error { - return errors.New("failed on waiting for VirtualMachinesRunCommandFuture") - }, - } -} - -// MockNsgCreateOrUpdateSuccess mocks the SecurityGroupsCreateOrUpdateFuture response. -func MockNsgCreateOrUpdateSuccess() MockAzureNetworkClient { - return MockAzureNetworkClient{ - MockCreateOrUpdateNetworkSecurityGroup: func(resourceGroupName string, networkSecurityGroupName string, location string) (*network.SecurityGroupsCreateOrUpdateFuture, error) { - return &network.SecurityGroupsCreateOrUpdateFuture{}, nil - }, - } -} - -// MockNsgCreateOrUpdateFailure SecurityGroupsCreateOrUpdateFuture failure response. -func MockNsgCreateOrUpdateFailure() MockAzureNetworkClient { - return MockAzureNetworkClient{ - MockCreateOrUpdateNetworkSecurityGroup: func(resourceGroupName string, networkSecurityGroupName string, location string) (*network.SecurityGroupsCreateOrUpdateFuture, error) { - return nil, errors.New("failed to create or update network security group") - }, - } -} - -// MockVnetCreateOrUpdateSuccess mocks the VnetCreateOrUpdateSuccess response. -func MockVnetCreateOrUpdateSuccess() MockAzureNetworkClient { - return MockAzureNetworkClient{ - MockCreateOrUpdateVnet: func(resourceGroupName string, virtualNetworkName string, location string) (*network.VirtualNetworksCreateOrUpdateFuture, error) { - return &network.VirtualNetworksCreateOrUpdateFuture{}, nil - }, - } -} - -// MockVnetCreateOrUpdateFailure mocks the VnetCreateOrUpdateSuccess failure response. -func MockVnetCreateOrUpdateFailure() MockAzureNetworkClient { - return MockAzureNetworkClient{ - MockCreateOrUpdateVnet: func(resourceGroupName string, virtualNetworkName string, location string) (*network.VirtualNetworksCreateOrUpdateFuture, error) { - return nil, errors.New("failed to create or update vnet") - }, - } -} - -// MockNsgCreateOrUpdateFutureFailure mocks the SecurityGroupsCreateOrUpdateSuccess future failure response. -func MockNsgCreateOrUpdateFutureFailure() MockAzureNetworkClient { - return MockAzureNetworkClient{ - MockWaitForNetworkSGsCreateOrUpdateFuture: func(future network.SecurityGroupsCreateOrUpdateFuture) error { - return errors.New("failed on waiting for SecurityGroupsCreateOrUpdateFuture") - }, - } -} - -// MockVnetCreateOrUpdateFutureFailure mocks the VnetCreateOrUpdate future failure response. -func MockVnetCreateOrUpdateFutureFailure() MockAzureNetworkClient { - return MockAzureNetworkClient{ - MockWaitForVnetCreateOrUpdateFuture: func(future network.VirtualNetworksCreateOrUpdateFuture) error { - return errors.New("failed on waiting for VirtualNetworksCreateOrUpdateFuture") - }, - } -} - -// MockNicDeleteFailure mocks the InterfacesDelete failure response. -func MockNicDeleteFailure() MockAzureNetworkClient { - return MockAzureNetworkClient{ - MockDeleteNetworkInterface: func(resourceGroup string, networkInterfaceName string) (network.InterfacesDeleteFuture, error) { - return network.InterfacesDeleteFuture{}, errors.New("failed to delete network interface") - }, - } -} - -// MockNicDeleteFutureFailure mocks the InterfacesDelete future failure response. -func MockNicDeleteFutureFailure() MockAzureNetworkClient { - return MockAzureNetworkClient{ - MockWaitForNetworkInterfacesDeleteFuture: func(future network.InterfacesDeleteFuture) error { - return errors.New("failed on waiting for InterfacesDeleteFuture") - }, - } -} - -// MockPublicIPDeleteFailure mocks the PublicIPDeleteFailure response. -func MockPublicIPDeleteFailure() MockAzureNetworkClient { - return MockAzureNetworkClient{ - MockDeletePublicIPAddress: func(resourceGroup string, IPName string) (network.PublicIPAddressesDeleteFuture, error) { - return network.PublicIPAddressesDeleteFuture{}, errors.New("failed to delete public ip address") - }, - } -} - -// MockPublicIPDeleteFutureFailure mocks the PublicIPDeleteFailure future response. -func MockPublicIPDeleteFutureFailure() MockAzureNetworkClient { - return MockAzureNetworkClient{ - MockWaitForPublicIPAddressDeleteFuture: func(future network.PublicIPAddressesDeleteFuture) error { - return errors.New("failed on waiting for PublicIPAddressesDeleteFuture") - }, - } -} - -// MockCreateOrUpdatePublicIPAddress mocks the CreateOrUpdatePublicIPAddress success response. -func MockCreateOrUpdatePublicIPAddress(ip string) MockAzureNetworkClient { - return MockAzureNetworkClient{ - MockCreateOrUpdatePublicIPAddress: func(resourceGroup string, IPName string) (network.PublicIPAddress, error) { - publicIPAddress := network.PublicIPAddress{PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{}} - publicIPAddress.IPAddress = to.StringPtr(ip) - return publicIPAddress, nil - }, - } -} - -// MockCreateOrUpdatePublicIPAddressFailure mocks the CreateOrUpdatePublicIPAddress failure response. -func MockCreateOrUpdatePublicIPAddressFailure() MockAzureNetworkClient { - return MockAzureNetworkClient{ - MockCreateOrUpdatePublicIPAddress: func(resourceGroup string, IPName string) (network.PublicIPAddress, error) { - return network.PublicIPAddress{}, errors.New("failed to get public ip address") - }, - } -} - -// ResourceManagement Mocks - -// MockRgExists mocks the CheckGroupExistence response. -func MockRgExists() MockAzureResourcesClient { - return MockAzureResourcesClient{ - MockCheckGroupExistence: func(rgName string) (autorest.Response, error) { - return autorest.Response{Response: &http.Response{StatusCode: 200}}, nil - }, - } -} - -// MockRgNotExists mocks the CheckGroupExistence not found response. -func MockRgNotExists() MockAzureResourcesClient { - return MockAzureResourcesClient{ - MockCheckGroupExistence: func(rgName string) (autorest.Response, error) { - return autorest.Response{Response: &http.Response{StatusCode: 404}}, nil - }, - } -} - -// MockRgCheckFailure mocks the CheckGroupExistence failure response. -func MockRgCheckFailure() MockAzureResourcesClient { - return MockAzureResourcesClient{ - MockCheckGroupExistence: func(rgName string) (autorest.Response, error) { - return autorest.Response{Response: &http.Response{StatusCode: 200}}, errors.New("failed to check resource group existence") - }, - } -} - -// MockRgCreateOrUpdateFailure mocks the CheckGroupExistence future failure response. -func MockRgCreateOrUpdateFailure() MockAzureResourcesClient { - return MockAzureResourcesClient{ - MockCreateOrUpdateGroup: func(resourceGroupName string, location string) (resources.Group, error) { - return resources.Group{}, errors.New("failed to create resource group") - }, - } -} - -// MockRgDeleteSuccess mocks the WaitForGroupsDeleteFuture response -func MockRgDeleteSuccess() MockAzureResourcesClient { - return MockAzureResourcesClient{ - MockDeleteGroup: func(resourceGroupName string) (resources.GroupsDeleteFuture, error) { - return resources.GroupsDeleteFuture{}, nil - }, - } -} - -// MockRgDeleteFailure mocks the groups delete response. -func MockRgDeleteFailure() MockAzureResourcesClient { - return MockAzureResourcesClient{ - MockDeleteGroup: func(resourceGroupName string) (resources.GroupsDeleteFuture, error) { - return resources.GroupsDeleteFuture{}, errors.New("failed to delete resource group") - }, - } -} - -// MockRgDeleteFutureFailure mocks the WaitForGroupsDeleteFuture failure response. -func MockRgDeleteFutureFailure() MockAzureResourcesClient { - return MockAzureResourcesClient{ - MockWaitForGroupsDeleteFuture: func(future resources.GroupsDeleteFuture) error { - return errors.New("error waiting for GroupsDeleteFuture") - }, - } -} - -// MockDeploymentCreateOrUpdateSuccess mocks the DeploymentCreateOrUpdate success response. -func MockDeploymentCreateOrUpdateSuccess() MockAzureResourcesClient { - return MockAzureResourcesClient{ - MockCreateOrUpdateDeployment: func(machine *machinev1.Machine, clusterConfig *clusterproviderv1.AzureClusterProviderSpec, machineConfig *machineproviderv1.AzureMachineProviderSpec) (*resources.DeploymentsCreateOrUpdateFuture, error) { - return &resources.DeploymentsCreateOrUpdateFuture{}, nil - }, - } -} - -// MockDeploymentCreateOrUpdateFailure mocks the DeploymentCreateOrUpdate failure response. -func MockDeploymentCreateOrUpdateFailure() MockAzureResourcesClient { - return MockAzureResourcesClient{ - MockCreateOrUpdateDeployment: func(machine *machinev1.Machine, clusterConfig *clusterproviderv1.AzureClusterProviderSpec, machineConfig *machineproviderv1.AzureMachineProviderSpec) (*resources.DeploymentsCreateOrUpdateFuture, error) { - return nil, errors.New("failed to create resource") - }, - } -} - -// MockDeploymentCreateOrUpdateFutureFailure mocks the DeploymentCreateOrUpdate future failure response. -func MockDeploymentCreateOrUpdateFutureFailure() MockAzureResourcesClient { - return MockAzureResourcesClient{ - MockWaitForDeploymentsCreateOrUpdateFuture: func(future resources.DeploymentsCreateOrUpdateFuture) error { - return errors.New("failed on waiting for DeploymentsCreateOrUpdateFuture") - }, - } -} - -// MockDeloymentGetResultSuccess mocks the DeploymentGetResult success response. -func MockDeloymentGetResultSuccess() MockAzureResourcesClient { - return MockAzureResourcesClient{ - MockGetDeploymentResult: func(future resources.DeploymentsCreateOrUpdateFuture) (resources.DeploymentExtended, error) { - return resources.DeploymentExtended{Name: to.StringPtr("deployment-test")}, nil - }, - } -} - -// MockDeloymentGetResultFailure mocks the DeploymentGetResult failure response. -func MockDeloymentGetResultFailure() MockAzureResourcesClient { - return MockAzureResourcesClient{ - MockGetDeploymentResult: func(future resources.DeploymentsCreateOrUpdateFuture) (resources.DeploymentExtended, error) { - return resources.DeploymentExtended{}, errors.New("error getting deployment result") - }, - } -} - -// MockDeploymentValidate mocks the DeploymentValidate error response. -func MockDeploymentValidate() MockAzureResourcesClient { - return MockAzureResourcesClient{ - MockValidateDeployment: func(machine *machinev1.Machine, clusterConfig *clusterproviderv1.AzureClusterProviderSpec, machineConfig *machineproviderv1.AzureMachineProviderSpec) error { - return errors.New("error validating deployment") - }, - } -} diff --git a/pkg/cloud/azure/services/networkinterfaces/networkinterfaces.go b/pkg/cloud/azure/services/networkinterfaces/networkinterfaces.go index 49626e446f9..dda466b720e 100644 --- a/pkg/cloud/azure/services/networkinterfaces/networkinterfaces.go +++ b/pkg/cloud/azure/services/networkinterfaces/networkinterfaces.go @@ -54,7 +54,7 @@ func (s *Service) Get(ctx context.Context, spec azure.Spec) (interface{}, error) if !ok { return network.Interface{}, errors.New("invalid network interface specification") } - nic, err := s.Client.Get(ctx, s.Scope.ClusterConfig.ResourceGroup, nicSpec.Name, "") + nic, err := s.Client.Get(ctx, s.Scope.MachineConfig.ResourceGroup, nicSpec.Name, "") if err != nil && azure.ResourceNotFound(err) { return nil, fmt.Errorf("network interface %s not found: %w", nicSpec.Name, err) } else if err != nil { @@ -203,15 +203,15 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { } f, err := s.Client.CreateOrUpdate(ctx, - s.Scope.ClusterConfig.ResourceGroup, + s.Scope.MachineConfig.ResourceGroup, nicSpec.Name, network.Interface{ - Location: to.StringPtr(s.Scope.ClusterConfig.Location), + Location: to.StringPtr(s.Scope.MachineConfig.Location), InterfacePropertiesFormat: &nicProp, }) if err != nil { - return fmt.Errorf("failed to create network interface %s in resource group %s: %w", nicSpec.Name, s.Scope.ClusterConfig.ResourceGroup, err) + return fmt.Errorf("failed to create network interface %s in resource group %s: %w", nicSpec.Name, s.Scope.MachineConfig.ResourceGroup, err) } err = f.WaitForCompletionRef(ctx, s.Client.Client) @@ -234,13 +234,13 @@ func (s *Service) Delete(ctx context.Context, spec azure.Spec) error { return errors.New("invalid network interface Specification") } klog.V(2).Infof("deleting nic %s", nicSpec.Name) - f, err := s.Client.Delete(ctx, s.Scope.ClusterConfig.ResourceGroup, nicSpec.Name) + f, err := s.Client.Delete(ctx, s.Scope.MachineConfig.ResourceGroup, nicSpec.Name) if err != nil && azure.ResourceNotFound(err) { // already deleted return nil } if err != nil { - return fmt.Errorf("failed to delete network interface %s in resource group %s: %w", nicSpec.Name, s.Scope.ClusterConfig.ResourceGroup, err) + return fmt.Errorf("failed to delete network interface %s in resource group %s: %w", nicSpec.Name, s.Scope.MachineConfig.ResourceGroup, err) } err = f.WaitForCompletionRef(ctx, s.Client.Client) diff --git a/pkg/cloud/azure/services/networkinterfaces/service.go b/pkg/cloud/azure/services/networkinterfaces/service.go index 23a27a4f4b8..b1c3d82bcb1 100644 --- a/pkg/cloud/azure/services/networkinterfaces/service.go +++ b/pkg/cloud/azure/services/networkinterfaces/service.go @@ -26,7 +26,7 @@ import ( // Service provides operations on resource groups type Service struct { Client network.InterfacesClient - Scope *actuators.Scope + Scope *actuators.MachineScope } // getGroupsClient creates a new groups client from subscriptionid. @@ -38,7 +38,7 @@ func getNetworkInterfacesClient(subscriptionID string, authorizer autorest.Autho } // NewService creates a new groups service. -func NewService(scope *actuators.Scope) azure.Service { +func NewService(scope *actuators.MachineScope) azure.Service { return &Service{ Client: getNetworkInterfacesClient(scope.SubscriptionID, scope.Authorizer), Scope: scope, diff --git a/pkg/cloud/azure/services/publicips/publicips.go b/pkg/cloud/azure/services/publicips/publicips.go index 3c3d561d8cf..a74d15ea79a 100644 --- a/pkg/cloud/azure/services/publicips/publicips.go +++ b/pkg/cloud/azure/services/publicips/publicips.go @@ -39,7 +39,7 @@ func (s *Service) Get(ctx context.Context, spec azure.Spec) (interface{}, error) if !ok { return network.PublicIPAddress{}, errors.New("Invalid PublicIP Specification") } - publicIP, err := s.Client.Get(ctx, s.Scope.ClusterConfig.ResourceGroup, publicIPSpec.Name, "") + publicIP, err := s.Client.Get(ctx, s.Scope.MachineConfig.ResourceGroup, publicIPSpec.Name, "") if err != nil && azure.ResourceNotFound(err) { return nil, fmt.Errorf("publicip %s not found: %w", publicIPSpec.Name, err) } else if err != nil { @@ -60,12 +60,12 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { // https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-standard-availability-zones#zone-redundant-by-default f, err := s.Client.CreateOrUpdate( ctx, - s.Scope.ClusterConfig.ResourceGroup, + s.Scope.MachineConfig.ResourceGroup, ipName, network.PublicIPAddress{ Sku: &network.PublicIPAddressSku{Name: network.PublicIPAddressSkuNameStandard}, Name: to.StringPtr(ipName), - Location: to.StringPtr(s.Scope.ClusterConfig.Location), + Location: to.StringPtr(s.Scope.MachineConfig.Location), PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{ PublicIPAddressVersion: network.IPv4, PublicIPAllocationMethod: network.Static, @@ -100,13 +100,13 @@ func (s *Service) Delete(ctx context.Context, spec azure.Spec) error { return errors.New("Invalid PublicIP Specification") } klog.V(2).Infof("deleting public ip %s", publicIPSpec.Name) - f, err := s.Client.Delete(ctx, s.Scope.ClusterConfig.ResourceGroup, publicIPSpec.Name) + f, err := s.Client.Delete(ctx, s.Scope.MachineConfig.ResourceGroup, publicIPSpec.Name) if err != nil && azure.ResourceNotFound(err) { // already deleted return nil } if err != nil { - return fmt.Errorf("failed to delete public ip %s in resource group %s: %w", publicIPSpec.Name, s.Scope.ClusterConfig.ResourceGroup, err) + return fmt.Errorf("failed to delete public ip %s in resource group %s: %w", publicIPSpec.Name, s.Scope.MachineConfig.ResourceGroup, err) } err = f.WaitForCompletionRef(ctx, s.Client.Client) diff --git a/pkg/cloud/azure/services/publicips/service.go b/pkg/cloud/azure/services/publicips/service.go index bf2387f225b..8211c89d0da 100644 --- a/pkg/cloud/azure/services/publicips/service.go +++ b/pkg/cloud/azure/services/publicips/service.go @@ -26,7 +26,7 @@ import ( // Service provides operations on resource groups type Service struct { Client network.PublicIPAddressesClient - Scope *actuators.Scope + Scope *actuators.MachineScope } // getPublicIPsClient creates a new groups client from subscriptionid. @@ -38,7 +38,7 @@ func getPublicIPAddressesClient(subscriptionID string, authorizer autorest.Autho } // NewService creates a new groups service. -func NewService(scope *actuators.Scope) azure.Service { +func NewService(scope *actuators.MachineScope) azure.Service { return &Service{ Client: getPublicIPAddressesClient(scope.SubscriptionID, scope.Authorizer), Scope: scope, diff --git a/pkg/cloud/azure/services/publicloadbalancers/publicloadbalancers.go b/pkg/cloud/azure/services/publicloadbalancers/publicloadbalancers.go index e601935c230..2cb6c509cf2 100644 --- a/pkg/cloud/azure/services/publicloadbalancers/publicloadbalancers.go +++ b/pkg/cloud/azure/services/publicloadbalancers/publicloadbalancers.go @@ -40,7 +40,7 @@ func (s *Service) Get(ctx context.Context, spec azure.Spec) (interface{}, error) if !ok { return network.LoadBalancer{}, errors.New("invalid public loadbalancer specification") } - lb, err := s.Client.Get(ctx, s.Scope.ClusterConfig.ResourceGroup, publicLBSpec.Name, "") + lb, err := s.Client.Get(ctx, s.Scope.MachineConfig.ResourceGroup, publicLBSpec.Name, "") if err != nil && azure.ResourceNotFound(err) { return nil, fmt.Errorf("load balancer %s not found: %w", publicLBSpec.Name, err) } else if err != nil { @@ -58,7 +58,7 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { probeName := "tcpHTTPSProbe" frontEndIPConfigName := "controlplane-lbFrontEnd" backEndAddressPoolName := "controlplane-backEndPool" - idPrefix := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/loadBalancers", s.Scope.SubscriptionID, s.Scope.ClusterConfig.ResourceGroup) + idPrefix := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/loadBalancers", s.Scope.SubscriptionID, s.Scope.MachineConfig.ResourceGroup) lbName := publicLBSpec.Name klog.V(2).Infof("creating public load balancer %s", lbName) @@ -76,11 +76,11 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { // https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-standard-availability-zones#zone-redundant-by-default f, err := s.Client.CreateOrUpdate(ctx, - s.Scope.ClusterConfig.ResourceGroup, + s.Scope.MachineConfig.ResourceGroup, lbName, network.LoadBalancer{ Sku: &network.LoadBalancerSku{Name: network.LoadBalancerSkuNameStandard}, - Location: to.StringPtr(s.Scope.ClusterConfig.Location), + Location: to.StringPtr(s.Scope.MachineConfig.Location), LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{ FrontendIPConfigurations: &[]network.FrontendIPConfiguration{ { @@ -194,13 +194,13 @@ func (s *Service) Delete(ctx context.Context, spec azure.Spec) error { return errors.New("invalid public loadbalancer specification") } klog.V(2).Infof("deleting public load balancer %s", publicLBSpec.Name) - f, err := s.Client.Delete(ctx, s.Scope.ClusterConfig.ResourceGroup, publicLBSpec.Name) + f, err := s.Client.Delete(ctx, s.Scope.MachineConfig.ResourceGroup, publicLBSpec.Name) if err != nil && azure.ResourceNotFound(err) { // already deleted return nil } if err != nil { - return fmt.Errorf("failed to delete public load balancer %s in resource group %s: %w", publicLBSpec.Name, s.Scope.ClusterConfig.ResourceGroup, err) + return fmt.Errorf("failed to delete public load balancer %s in resource group %s: %w", publicLBSpec.Name, s.Scope.MachineConfig.ResourceGroup, err) } err = f.WaitForCompletionRef(ctx, s.Client.Client) diff --git a/pkg/cloud/azure/services/publicloadbalancers/service.go b/pkg/cloud/azure/services/publicloadbalancers/service.go index 26586ce6622..2606e25b19c 100644 --- a/pkg/cloud/azure/services/publicloadbalancers/service.go +++ b/pkg/cloud/azure/services/publicloadbalancers/service.go @@ -26,7 +26,7 @@ import ( // Service provides operations on resource groups type Service struct { Client network.LoadBalancersClient - Scope *actuators.Scope + Scope *actuators.MachineScope } // getGroupsClient creates a new groups client from subscriptionid. @@ -38,7 +38,7 @@ func getLoadbalancersClient(subscriptionID string, authorizer autorest.Authorize } // NewService creates a new groups service. -func NewService(scope *actuators.Scope) azure.Service { +func NewService(scope *actuators.MachineScope) azure.Service { return &Service{ Client: getLoadbalancersClient(scope.SubscriptionID, scope.Authorizer), Scope: scope, diff --git a/pkg/cloud/azure/services/routetables/routetables.go b/pkg/cloud/azure/services/routetables/routetables.go index 51bb65c9828..78a9ad40ff4 100644 --- a/pkg/cloud/azure/services/routetables/routetables.go +++ b/pkg/cloud/azure/services/routetables/routetables.go @@ -38,7 +38,7 @@ func (s *Service) Get(ctx context.Context, spec azure.Spec) (interface{}, error) if !ok { return network.RouteTable{}, errors.New("Invalid Route Table Specification") } - routeTable, err := s.Client.Get(ctx, s.Scope.ClusterConfig.ResourceGroup, routeTableSpec.Name, "") + routeTable, err := s.Client.Get(ctx, s.Scope.MachineConfig.ResourceGroup, routeTableSpec.Name, "") if err != nil && azure.ResourceNotFound(err) { return nil, fmt.Errorf("route table %s not found: %w", routeTableSpec.Name, err) } else if err != nil { @@ -56,15 +56,15 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { klog.V(2).Infof("creating route table %s", routeTableSpec.Name) f, err := s.Client.CreateOrUpdate( ctx, - s.Scope.ClusterConfig.ResourceGroup, + s.Scope.MachineConfig.ResourceGroup, routeTableSpec.Name, network.RouteTable{ - Location: to.StringPtr(s.Scope.ClusterConfig.Location), + Location: to.StringPtr(s.Scope.MachineConfig.Location), RouteTablePropertiesFormat: &network.RouteTablePropertiesFormat{}, }, ) if err != nil { - return fmt.Errorf("failed to create route table %s in resource group %s: %w", routeTableSpec.Name, s.Scope.ClusterConfig.ResourceGroup, err) + return fmt.Errorf("failed to create route table %s in resource group %s: %w", routeTableSpec.Name, s.Scope.MachineConfig.ResourceGroup, err) } err = f.WaitForCompletionRef(ctx, s.Client.Client) @@ -87,13 +87,13 @@ func (s *Service) Delete(ctx context.Context, spec azure.Spec) error { return errors.New("Invalid Route Table Specification") } klog.V(2).Infof("deleting route table %s", routeTableSpec.Name) - f, err := s.Client.Delete(ctx, s.Scope.ClusterConfig.ResourceGroup, routeTableSpec.Name) + f, err := s.Client.Delete(ctx, s.Scope.MachineConfig.ResourceGroup, routeTableSpec.Name) if err != nil && azure.ResourceNotFound(err) { // already deleted return nil } if err != nil { - return fmt.Errorf("failed to delete route table %s in resource group %s: %w", routeTableSpec.Name, s.Scope.ClusterConfig.ResourceGroup, err) + return fmt.Errorf("failed to delete route table %s in resource group %s: %w", routeTableSpec.Name, s.Scope.MachineConfig.ResourceGroup, err) } err = f.WaitForCompletionRef(ctx, s.Client.Client) diff --git a/pkg/cloud/azure/services/routetables/service.go b/pkg/cloud/azure/services/routetables/service.go index dc7d6b73fe7..9bf066e0f17 100644 --- a/pkg/cloud/azure/services/routetables/service.go +++ b/pkg/cloud/azure/services/routetables/service.go @@ -26,7 +26,7 @@ import ( // Service provides operations on resource groups type Service struct { Client network.RouteTablesClient - Scope *actuators.Scope + Scope *actuators.MachineScope } // getGroupsClient creates a new groups client from subscriptionid. @@ -38,7 +38,7 @@ func getRouteTablesClient(subscriptionID string, authorizer autorest.Authorizer) } // NewService creates a new groups service. -func NewService(scope *actuators.Scope) azure.Service { +func NewService(scope *actuators.MachineScope) azure.Service { return &Service{ Client: getRouteTablesClient(scope.SubscriptionID, scope.Authorizer), Scope: scope, diff --git a/pkg/cloud/azure/services/securitygroups/securitygroups.go b/pkg/cloud/azure/services/securitygroups/securitygroups.go index 239f3d8c06d..c687c186942 100644 --- a/pkg/cloud/azure/services/securitygroups/securitygroups.go +++ b/pkg/cloud/azure/services/securitygroups/securitygroups.go @@ -39,7 +39,7 @@ func (s *Service) Get(ctx context.Context, spec azure.Spec) (interface{}, error) if !ok { return network.SecurityGroup{}, errors.New("invalid security groups specification") } - securityGroup, err := s.Client.Get(ctx, s.Scope.ClusterConfig.ResourceGroup, nsgSpec.Name, "") + securityGroup, err := s.Client.Get(ctx, s.Scope.MachineConfig.ResourceGroup, nsgSpec.Name, "") if err != nil && azure.ResourceNotFound(err) { return nil, fmt.Errorf("security group %s not found: %w", nsgSpec.Name, err) } else if err != nil { @@ -92,17 +92,17 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { klog.V(2).Infof("creating security group %s", nsgSpec.Name) f, err := s.Client.CreateOrUpdate( ctx, - s.Scope.ClusterConfig.ResourceGroup, + s.Scope.MachineConfig.ResourceGroup, nsgSpec.Name, network.SecurityGroup{ - Location: to.StringPtr(s.Scope.ClusterConfig.Location), + Location: to.StringPtr(s.Scope.MachineConfig.Location), SecurityGroupPropertiesFormat: &network.SecurityGroupPropertiesFormat{ SecurityRules: securityRules, }, }, ) if err != nil { - return fmt.Errorf("failed to create security group %s in resource group %s: %w", nsgSpec.Name, s.Scope.ClusterConfig.ResourceGroup, err) + return fmt.Errorf("failed to create security group %s in resource group %s: %w", nsgSpec.Name, s.Scope.MachineConfig.ResourceGroup, err) } err = f.WaitForCompletionRef(ctx, s.Client.Client) @@ -125,13 +125,13 @@ func (s *Service) Delete(ctx context.Context, spec azure.Spec) error { return errors.New("invalid security groups specification") } klog.V(2).Infof("deleting security group %s", nsgSpec.Name) - f, err := s.Client.Delete(ctx, s.Scope.ClusterConfig.ResourceGroup, nsgSpec.Name) + f, err := s.Client.Delete(ctx, s.Scope.MachineConfig.ResourceGroup, nsgSpec.Name) if err != nil && azure.ResourceNotFound(err) { // already deleted return nil } if err != nil { - return fmt.Errorf("failed to delete security group %s in resource group %s: %w", nsgSpec.Name, s.Scope.ClusterConfig.ResourceGroup, err) + return fmt.Errorf("failed to delete security group %s in resource group %s: %w", nsgSpec.Name, s.Scope.MachineConfig.ResourceGroup, err) } err = f.WaitForCompletionRef(ctx, s.Client.Client) diff --git a/pkg/cloud/azure/services/securitygroups/service.go b/pkg/cloud/azure/services/securitygroups/service.go index a03419d4f33..78bfd8e4605 100644 --- a/pkg/cloud/azure/services/securitygroups/service.go +++ b/pkg/cloud/azure/services/securitygroups/service.go @@ -26,7 +26,7 @@ import ( // Service provides operations on resource groups type Service struct { Client network.SecurityGroupsClient - Scope *actuators.Scope + Scope *actuators.MachineScope } // getGroupsClient creates a new groups client from subscriptionid. @@ -38,7 +38,7 @@ func getSecurityGroupsClient(subscriptionID string, authorizer autorest.Authoriz } // NewService creates a new groups service. -func NewService(scope *actuators.Scope) azure.Service { +func NewService(scope *actuators.MachineScope) azure.Service { return &Service{ Client: getSecurityGroupsClient(scope.SubscriptionID, scope.Authorizer), Scope: scope, diff --git a/pkg/cloud/azure/services/subnets/service.go b/pkg/cloud/azure/services/subnets/service.go index 279784400e5..4ca3e1da494 100644 --- a/pkg/cloud/azure/services/subnets/service.go +++ b/pkg/cloud/azure/services/subnets/service.go @@ -26,7 +26,7 @@ import ( // Service provides operations on resource groups type Service struct { Client network.SubnetsClient - Scope *actuators.Scope + Scope *actuators.MachineScope } // getGroupsClient creates a new groups client from subscriptionid. @@ -38,7 +38,7 @@ func getSubnetsClient(subscriptionID string, authorizer autorest.Authorizer) net } // NewService creates a new groups service. -func NewService(scope *actuators.Scope) azure.Service { +func NewService(scope *actuators.MachineScope) azure.Service { return &Service{ Client: getSubnetsClient(scope.SubscriptionID, scope.Authorizer), Scope: scope, diff --git a/pkg/cloud/azure/services/subnets/subnets.go b/pkg/cloud/azure/services/subnets/subnets.go index 8c1a984cc95..5f71a1628e9 100644 --- a/pkg/cloud/azure/services/subnets/subnets.go +++ b/pkg/cloud/azure/services/subnets/subnets.go @@ -44,7 +44,7 @@ func (s *Service) Get(ctx context.Context, spec azure.Spec) (interface{}, error) if !ok { return network.Subnet{}, errors.New("Invalid Subnet Specification") } - subnet, err := s.Client.Get(ctx, s.Scope.ClusterConfig.NetworkResourceGroup, subnetSpec.VnetName, subnetSpec.Name, "") + subnet, err := s.Client.Get(ctx, s.Scope.MachineConfig.NetworkResourceGroup, subnetSpec.VnetName, subnetSpec.Name, "") if err != nil && azure.ResourceNotFound(err) { return nil, fmt.Errorf("subnet %s not found: %w", subnetSpec.Name, err) } else if err != nil { @@ -91,7 +91,7 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { klog.V(2).Infof("creating subnet %s in vnet %s", subnetSpec.Name, subnetSpec.VnetName) f, err := s.Client.CreateOrUpdate( ctx, - s.Scope.ClusterConfig.NetworkResourceGroup, + s.Scope.MachineConfig.NetworkResourceGroup, subnetSpec.VnetName, subnetSpec.Name, network.Subnet{ @@ -100,7 +100,7 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { }, ) if err != nil { - return fmt.Errorf("failed to create subnet %s in resource group %s: %w", subnetSpec.Name, s.Scope.ClusterConfig.NetworkResourceGroup, err) + return fmt.Errorf("failed to create subnet %s in resource group %s: %w", subnetSpec.Name, s.Scope.MachineConfig.NetworkResourceGroup, err) } err = f.WaitForCompletionRef(ctx, s.Client.Client) @@ -123,13 +123,13 @@ func (s *Service) Delete(ctx context.Context, spec azure.Spec) error { return errors.New("Invalid Subnet Specification") } klog.V(2).Infof("deleting subnet %s in vnet %s", subnetSpec.Name, subnetSpec.VnetName) - f, err := s.Client.Delete(ctx, s.Scope.ClusterConfig.NetworkResourceGroup, subnetSpec.VnetName, subnetSpec.Name) + f, err := s.Client.Delete(ctx, s.Scope.MachineConfig.NetworkResourceGroup, subnetSpec.VnetName, subnetSpec.Name) if err != nil && azure.ResourceNotFound(err) { // already deleted return nil } if err != nil { - return fmt.Errorf("failed to delete route table %s in resource group %s: %w", subnetSpec.Name, s.Scope.ClusterConfig.NetworkResourceGroup, err) + return fmt.Errorf("failed to delete route table %s in resource group %s: %w", subnetSpec.Name, s.Scope.MachineConfig.NetworkResourceGroup, err) } err = f.WaitForCompletionRef(ctx, s.Client.Client) diff --git a/pkg/cloud/azure/services/virtualmachineextensions/service.go b/pkg/cloud/azure/services/virtualmachineextensions/service.go index 9029fee7ef4..b582a1c15e5 100644 --- a/pkg/cloud/azure/services/virtualmachineextensions/service.go +++ b/pkg/cloud/azure/services/virtualmachineextensions/service.go @@ -26,7 +26,7 @@ import ( // Service provides operations on resource groups type Service struct { Client compute.VirtualMachineExtensionsClient - Scope *actuators.Scope + Scope *actuators.MachineScope } // getVirtualNetworksClient creates a new groups client from subscriptionid. @@ -38,7 +38,7 @@ func getVirtualMachineExtensionsClient(subscriptionID string, authorizer autores } // NewService creates a new groups service. -func NewService(scope *actuators.Scope) azure.Service { +func NewService(scope *actuators.MachineScope) azure.Service { return &Service{ Client: getVirtualMachineExtensionsClient(scope.SubscriptionID, scope.Authorizer), Scope: scope, diff --git a/pkg/cloud/azure/services/virtualmachineextensions/virtualmachineextensions.go b/pkg/cloud/azure/services/virtualmachineextensions/virtualmachineextensions.go index 223479e3f07..72e92b3cad3 100644 --- a/pkg/cloud/azure/services/virtualmachineextensions/virtualmachineextensions.go +++ b/pkg/cloud/azure/services/virtualmachineextensions/virtualmachineextensions.go @@ -40,7 +40,7 @@ func (s *Service) Get(ctx context.Context, spec azure.Spec) (interface{}, error) if !ok { return compute.VirtualMachineExtension{}, errors.New("invalid vm specification") } - vmExt, err := s.Client.Get(ctx, s.Scope.ClusterConfig.ResourceGroup, vmExtSpec.VMName, vmExtSpec.Name, "") + vmExt, err := s.Client.Get(ctx, s.Scope.MachineConfig.ResourceGroup, vmExtSpec.VMName, vmExtSpec.Name, "") if err != nil && azure.ResourceNotFound(err) { return nil, fmt.Errorf("vm extension %s not found: %w", vmExtSpec.Name, err) } else if err != nil { @@ -60,12 +60,12 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { future, err := s.Client.CreateOrUpdate( ctx, - s.Scope.ClusterConfig.ResourceGroup, + s.Scope.MachineConfig.ResourceGroup, vmExtSpec.VMName, vmExtSpec.Name, compute.VirtualMachineExtension{ Name: to.StringPtr(vmExtSpec.Name), - Location: to.StringPtr(s.Scope.ClusterConfig.Location), + Location: to.StringPtr(s.Scope.MachineConfig.Location), VirtualMachineExtensionProperties: &compute.VirtualMachineExtensionProperties{ Type: to.StringPtr("CustomScript"), TypeHandlerVersion: to.StringPtr("2.0"), @@ -105,13 +105,13 @@ func (s *Service) Delete(ctx context.Context, spec azure.Spec) error { return errors.New("Invalid VNET Specification") } klog.V(2).Infof("deleting vm extension %s ", vmExtSpec.Name) - future, err := s.Client.Delete(ctx, s.Scope.ClusterConfig.ResourceGroup, vmExtSpec.VMName, vmExtSpec.Name) + future, err := s.Client.Delete(ctx, s.Scope.MachineConfig.ResourceGroup, vmExtSpec.VMName, vmExtSpec.Name) if err != nil && azure.ResourceNotFound(err) { // already deleted return nil } if err != nil { - return fmt.Errorf("failed to delete vm extension %s in resource group %s: %w", vmExtSpec.Name, s.Scope.ClusterConfig.ResourceGroup, err) + return fmt.Errorf("failed to delete vm extension %s in resource group %s: %w", vmExtSpec.Name, s.Scope.MachineConfig.ResourceGroup, err) } err = future.WaitForCompletionRef(ctx, s.Client.Client) diff --git a/pkg/cloud/azure/services/virtualmachines/service.go b/pkg/cloud/azure/services/virtualmachines/service.go index 8d5fa2040a3..8dacf335b80 100644 --- a/pkg/cloud/azure/services/virtualmachines/service.go +++ b/pkg/cloud/azure/services/virtualmachines/service.go @@ -26,7 +26,7 @@ import ( // Service provides operations on resource groups type Service struct { Client compute.VirtualMachinesClient - Scope *actuators.Scope + Scope *actuators.MachineScope } // getVirtualNetworksClient creates a new groups client from subscriptionid. @@ -38,7 +38,7 @@ func getVirtualMachinesClient(subscriptionID string, authorizer autorest.Authori } // NewService creates a new groups service. -func NewService(scope *actuators.Scope) azure.Service { +func NewService(scope *actuators.MachineScope) azure.Service { return &Service{ Client: getVirtualMachinesClient(scope.SubscriptionID, scope.Authorizer), Scope: scope, diff --git a/pkg/cloud/azure/services/virtualmachines/virtualmachines.go b/pkg/cloud/azure/services/virtualmachines/virtualmachines.go index c211603c6d3..eb2acc6c2d7 100644 --- a/pkg/cloud/azure/services/virtualmachines/virtualmachines.go +++ b/pkg/cloud/azure/services/virtualmachines/virtualmachines.go @@ -54,7 +54,7 @@ func (s *Service) Get(ctx context.Context, spec azure.Spec) (interface{}, error) if !ok { return compute.VirtualMachine{}, errors.New("invalid vm specification") } - vm, err := s.Client.Get(ctx, s.Scope.ClusterConfig.ResourceGroup, vmSpec.Name, compute.InstanceView) + vm, err := s.Client.Get(ctx, s.Scope.MachineConfig.ResourceGroup, vmSpec.Name, compute.InstanceView) if err != nil && azure.ResourceNotFound(err) { return nil, fmt.Errorf("vm %s not found: %w", vmSpec.Name, err) } else if err != nil { @@ -138,7 +138,7 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { } virtualMachine := compute.VirtualMachine{ - Location: to.StringPtr(s.Scope.ClusterConfig.Location), + Location: to.StringPtr(s.Scope.MachineConfig.Location), Tags: getTagListFromSpec(vmSpec), VirtualMachineProperties: &compute.VirtualMachineProperties{ HardwareProfile: &compute.HardwareProfile{ @@ -186,7 +186,7 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { future, err := s.Client.CreateOrUpdate( ctx, - s.Scope.ClusterConfig.ResourceGroup, + s.Scope.MachineConfig.ResourceGroup, vmSpec.Name, virtualMachine) if err != nil { @@ -223,13 +223,13 @@ func (s *Service) Delete(ctx context.Context, spec azure.Spec) error { return errors.New("invalid vm Specification") } klog.V(2).Infof("deleting vm %s ", vmSpec.Name) - future, err := s.Client.Delete(ctx, s.Scope.ClusterConfig.ResourceGroup, vmSpec.Name) + future, err := s.Client.Delete(ctx, s.Scope.MachineConfig.ResourceGroup, vmSpec.Name) if err != nil && azure.ResourceNotFound(err) { // already deleted return nil } if err != nil { - return fmt.Errorf("failed to delete vm %s in resource group %s: %w", vmSpec.Name, s.Scope.ClusterConfig.ResourceGroup, err) + return fmt.Errorf("failed to delete vm %s in resource group %s: %w", vmSpec.Name, s.Scope.MachineConfig.ResourceGroup, err) } // Do not wait until the operation completes. Just check the result diff --git a/pkg/cloud/azure/services/virtualnetworks/service.go b/pkg/cloud/azure/services/virtualnetworks/service.go index 16f6237d55a..9bc511330a5 100644 --- a/pkg/cloud/azure/services/virtualnetworks/service.go +++ b/pkg/cloud/azure/services/virtualnetworks/service.go @@ -26,7 +26,7 @@ import ( // Service provides operations on resource groups type Service struct { Client network.VirtualNetworksClient - Scope *actuators.Scope + Scope *actuators.MachineScope } // getVirtualNetworksClient creates a new groups client from subscriptionid. @@ -38,7 +38,7 @@ func getVirtualNetworksClient(subscriptionID string, authorizer autorest.Authori } // NewService creates a new groups service. -func NewService(scope *actuators.Scope) azure.Service { +func NewService(scope *actuators.MachineScope) azure.Service { return &Service{ Client: getVirtualNetworksClient(scope.SubscriptionID, scope.Authorizer), Scope: scope, diff --git a/pkg/cloud/azure/services/virtualnetworks/virtualnetworks.go b/pkg/cloud/azure/services/virtualnetworks/virtualnetworks.go index c3e7ab2c49b..855a84d3452 100644 --- a/pkg/cloud/azure/services/virtualnetworks/virtualnetworks.go +++ b/pkg/cloud/azure/services/virtualnetworks/virtualnetworks.go @@ -39,7 +39,7 @@ func (s *Service) Get(ctx context.Context, spec azure.Spec) (interface{}, error) if !ok { return network.VirtualNetwork{}, errors.New("Invalid VNET Specification") } - vnet, err := s.Client.Get(ctx, s.Scope.ClusterConfig.NetworkResourceGroup, vnetSpec.Name, "") + vnet, err := s.Client.Get(ctx, s.Scope.MachineConfig.NetworkResourceGroup, vnetSpec.Name, "") if err != nil && azure.ResourceNotFound(err) { return nil, fmt.Errorf("vnet %s not found: %w", vnetSpec.Name, err) } else if err != nil { @@ -69,9 +69,9 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { } klog.V(2).Infof("creating vnet %s ", vnetSpec.Name) - f, err := s.Client.CreateOrUpdate(ctx, s.Scope.ClusterConfig.NetworkResourceGroup, vnetSpec.Name, + f, err := s.Client.CreateOrUpdate(ctx, s.Scope.MachineConfig.NetworkResourceGroup, vnetSpec.Name, network.VirtualNetwork{ - Location: to.StringPtr(s.Scope.ClusterConfig.Location), + Location: to.StringPtr(s.Scope.MachineConfig.Location), VirtualNetworkPropertiesFormat: &network.VirtualNetworkPropertiesFormat{ AddressSpace: &network.AddressSpace{ AddressPrefixes: &[]string{vnetSpec.CIDR}, @@ -102,13 +102,13 @@ func (s *Service) Delete(ctx context.Context, spec azure.Spec) error { return errors.New("Invalid VNET Specification") } klog.V(2).Infof("deleting vnet %s ", vnetSpec.Name) - future, err := s.Client.Delete(ctx, s.Scope.ClusterConfig.NetworkResourceGroup, vnetSpec.Name) + future, err := s.Client.Delete(ctx, s.Scope.MachineConfig.NetworkResourceGroup, vnetSpec.Name) if err != nil && azure.ResourceNotFound(err) { // already deleted return nil } if err != nil { - return fmt.Errorf("failed to delete vnet %s in resource group %s: %w", vnetSpec.Name, s.Scope.ClusterConfig.NetworkResourceGroup, err) + return fmt.Errorf("failed to delete vnet %s in resource group %s: %w", vnetSpec.Name, s.Scope.MachineConfig.NetworkResourceGroup, err) } err = future.WaitForCompletionRef(ctx, s.Client.Client)