From 42cc91364b85231ef4de1b8f423d170054cffaa4 Mon Sep 17 00:00:00 2001 From: Konstantinos Angelopoulos Date: Wed, 3 Sep 2025 01:20:56 +0200 Subject: [PATCH] add vm to backendpool --- Makefile | 2 +- pkg/azure/access/helpers/nic.go | 3 ++- pkg/azure/api/providerspec.go | 7 +++++++ pkg/azure/provider/helpers/driver.go | 11 ++++++++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index a6e5210fc..a8cf4bf0b 100644 --- a/Makefile +++ b/Makefile @@ -106,7 +106,7 @@ build: PLATFORM ?= linux/amd64 .PHONY: docker-image docker-image: - @docker buildx build --platform $(PLATFORM) -t $(IMAGE_REPOSITORY):$(IMAGE_TAG) . + @docker buildx build --load --platform $(PLATFORM) -t $(IMAGE_REPOSITORY):$(IMAGE_TAG) . .PHONY: docker-login docker-login: diff --git a/pkg/azure/access/helpers/nic.go b/pkg/azure/access/helpers/nic.go index 503eb02c0..2cd26c840 100644 --- a/pkg/azure/access/helpers/nic.go +++ b/pkg/azure/access/helpers/nic.go @@ -6,11 +6,12 @@ package helpers import ( "context" - "k8s.io/klog/v2" "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4" + "k8s.io/klog/v2" + "github.com/gardener/machine-controller-manager-provider-azure/pkg/azure/access/errors" "github.com/gardener/machine-controller-manager-provider-azure/pkg/azure/instrument" ) diff --git a/pkg/azure/api/providerspec.go b/pkg/azure/api/providerspec.go index c5df3e30d..4f7a49355 100644 --- a/pkg/azure/api/providerspec.go +++ b/pkg/azure/api/providerspec.go @@ -74,6 +74,8 @@ type AzureProviderSpec struct { SubnetInfo AzureSubnetInfo `json:"subnetInfo,omitempty"` // CloudConfiguration contains config that controls which cloud to connect to CloudConfiguration *CloudConfiguration `json:"cloudConfiguration,omitempty"` + // BackendAddressPoolConfig contains the configuration for the Azure Load Balancer. + BackendAddressPoolConfig *AzureBackendAddressPoolConfig `json:"backendAddressPoolConfig,omitempty"` } // AzureVirtualMachineProperties describes the properties of a Virtual Machine. @@ -330,3 +332,8 @@ type CloudConfiguration struct { // Name is the name of the cloud to connect to, e.g. "AzurePublic" or "AzureChina". Name string `json:"name"` } + +// AzureBackendAddressPoolConfig is the configuration for a backend pool address in an Azure Load Balancer. +type AzureBackendAddressPoolConfig struct { + ID string `json:"id"` +} diff --git a/pkg/azure/provider/helpers/driver.go b/pkg/azure/provider/helpers/driver.go index 771662fb0..873e77c78 100644 --- a/pkg/azure/provider/helpers/driver.go +++ b/pkg/azure/provider/helpers/driver.go @@ -27,6 +27,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/klog/v2" "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "github.com/gardener/machine-controller-manager-provider-azure/pkg/azure/access" accesserrors "github.com/gardener/machine-controller-manager-provider-azure/pkg/azure/access/errors" @@ -393,12 +394,13 @@ func CreateNICIfNotExists(ctx context.Context, factory access.Factory, connectCo if err != nil { return "", status.WrapError(codes.Internal, fmt.Sprintf("failed to create NIC: [ResourceGroup: %s, Name: %s], Err: %v", providerSpec.ResourceGroup, nicName, err), err) } + klog.Infof("Successfully created NIC: [ResourceGroup: %s, NIC: [Name: %s, ID: %s]]", resourceGroup, nicName, *nic.ID) return *nic.ID, nil } func createNICParams(providerSpec api.AzureProviderSpec, subnet *armnetwork.Subnet, nicName string) armnetwork.Interface { - return armnetwork.Interface{ + ifc := armnetwork.Interface{ Location: to.Ptr(providerSpec.Location), Properties: &armnetwork.InterfacePropertiesFormat{ EnableAcceleratedNetworking: providerSpec.Properties.NetworkProfile.AcceleratedNetworking, @@ -407,6 +409,7 @@ func createNICParams(providerSpec api.AzureProviderSpec, subnet *armnetwork.Subn { Name: &nicName, Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{ + Primary: ptr.To(true), PrivateIPAllocationMethod: to.Ptr(armnetwork.IPAllocationMethodDynamic), Subnet: subnet, }, @@ -417,6 +420,12 @@ func createNICParams(providerSpec api.AzureProviderSpec, subnet *armnetwork.Subn Tags: createNICTags(providerSpec.Tags), Name: &nicName, } + if providerSpec.BackendAddressPoolConfig != nil { + ifc.Properties.IPConfigurations[0].Properties.LoadBalancerBackendAddressPools = []*armnetwork.BackendAddressPool{ + {ID: ptr.To(providerSpec.BackendAddressPoolConfig.ID)}, + } + } + return ifc } func createNICTags(tags map[string]string) map[string]*string {