Skip to content

Commit

Permalink
difftracker initial integration (left TODOs)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeedward2000 committed Feb 27, 2025
1 parent 9fcaf84 commit 9727188
Show file tree
Hide file tree
Showing 13 changed files with 2,501 additions and 5 deletions.
7 changes: 4 additions & 3 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ const (
LoadBalancerSKUBasic = "basic"
// LoadBalancerSKUStandard is the load balancer standard SKU
LoadBalancerSKUStandard = "standard"
// LoadBalancerSKUStandardV2 is the load balancer standardV2 SKU
LoadBalancerSKUStandardV2 = "standardV2"

// ServiceAnnotationLoadBalancerInternal is the annotation used on the service
ServiceAnnotationLoadBalancerInternal = "service.beta.kubernetes.io/azure-load-balancer-internal"
Expand Down Expand Up @@ -381,9 +383,8 @@ const (
LoadBalancerBackendPoolConfigurationTypeNodeIPConfiguration = "nodeIPConfiguration"
// LoadBalancerBackendPoolConfigurationTypeNodeIP is the lb backend pool config type node ip
LoadBalancerBackendPoolConfigurationTypeNodeIP = "nodeIP"
// LoadBalancerBackendPoolConfigurationTypePODIP is the lb backend pool config type pod ip
// TODO (nilo19): support pod IP in the future
LoadBalancerBackendPoolConfigurationTypePODIP = "podIP"
// LoadBalancerBackendPoolConfigurationTypePodIP is the lb backend pool config type pod ip
LoadBalancerBackendPoolConfigurationTypePodIP = "podIP"
)

// error messages
Expand Down
39 changes: 37 additions & 2 deletions pkg/provider/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"sigs.k8s.io/cloud-provider-azure/pkg/consts"
"sigs.k8s.io/cloud-provider-azure/pkg/provider/config"
azureconfig "sigs.k8s.io/cloud-provider-azure/pkg/provider/config"
"sigs.k8s.io/cloud-provider-azure/pkg/provider/difftracker"
"sigs.k8s.io/cloud-provider-azure/pkg/provider/privatelinkservice"
"sigs.k8s.io/cloud-provider-azure/pkg/provider/routetable"
"sigs.k8s.io/cloud-provider-azure/pkg/provider/securitygroup"
Expand Down Expand Up @@ -158,6 +159,8 @@ type Cloud struct {
endpointSlicesCache sync.Map

azureResourceLocker *AzureResourceLocker

diffTracker *difftracker.DiffTrackerState
}

// NewCloud returns a Cloud with initialized clients
Expand Down Expand Up @@ -294,13 +297,13 @@ func (az *Cloud) InitializeCloudFromConfig(ctx context.Context, config *config.C

if config.LoadBalancerBackendPoolConfigurationType == "" ||
// TODO(nilo19): support pod IP mode in the future
strings.EqualFold(config.LoadBalancerBackendPoolConfigurationType, consts.LoadBalancerBackendPoolConfigurationTypePODIP) {
strings.EqualFold(config.LoadBalancerBackendPoolConfigurationType, consts.LoadBalancerBackendPoolConfigurationTypePodIP) {
config.LoadBalancerBackendPoolConfigurationType = consts.LoadBalancerBackendPoolConfigurationTypeNodeIPConfiguration
} else {
supportedLoadBalancerBackendPoolConfigurationTypes := utilsets.NewString(
strings.ToLower(consts.LoadBalancerBackendPoolConfigurationTypeNodeIPConfiguration),
strings.ToLower(consts.LoadBalancerBackendPoolConfigurationTypeNodeIP),
strings.ToLower(consts.LoadBalancerBackendPoolConfigurationTypePODIP))
strings.ToLower(consts.LoadBalancerBackendPoolConfigurationTypePodIP))
if !supportedLoadBalancerBackendPoolConfigurationTypes.Has(strings.ToLower(config.LoadBalancerBackendPoolConfigurationType)) {
return fmt.Errorf("loadBalancerBackendPoolConfigurationType %s is not supported, supported values are %v", config.LoadBalancerBackendPoolConfigurationType, supportedLoadBalancerBackendPoolConfigurationTypes.UnsortedList())
}
Expand Down Expand Up @@ -495,9 +498,41 @@ func (az *Cloud) InitializeCloudFromConfig(ctx context.Context, config *config.C
}
}

if az.IsLBBackendPoolTypePodIP() {
az.initializeDiffTracker()
}

return nil
}

func (az *Cloud) initializeDiffTracker() {
// TODO (enechitoaia): CONSTRUCT K8sState and NRPState from the current state of the cluster
K8sState := difftracker.K8sState{
Services: utilsets.NewString(),
Egresses: utilsets.NewString(),
Nodes: make(map[string]difftracker.Node),
}
NRPState := difftracker.NRPState{
LoadBalancers: utilsets.NewString(),
NATGateways: utilsets.NewString(),
NRPLocations: make(map[string]difftracker.NRPLocation),
}

// Initialize the diff tracker state and get the necessary operations to sync the cluster with NRP
diffTrackerState, syncOperations := difftracker.InitializeDiffTrackerState(K8sState, NRPState)
az.diffTracker = diffTrackerState
// Print syncOps to surpress unused variable error
klog.V(2).Infof("Sync operations: %v", syncOperations)
// TODO (enechitoaia): call NRP APIs (including ServiceGateway) to update the state of the NRP

// if Load Balancers have been correctly updated:
az.diffTracker.UpdateNRPLoadBalancers()
// if NAT Gateways have been correctly updated:
az.diffTracker.UpdateNRPNATGateways()
// if Locations have been correctly updated:
az.diffTracker.UpdateNRPLocationsAddresses()
}

// Multiple standard load balancer mode only supports IP-based load balancers.
func (az *Cloud) checkEnableMultipleStandardLoadBalancers() error {
if az.IsLBBackendPoolTypeNodeIPConfig() {
Expand Down
8 changes: 8 additions & 0 deletions pkg/provider/config/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ func (az *Config) IsLBBackendPoolTypeNodeIP() bool {
return strings.EqualFold(az.LoadBalancerBackendPoolConfigurationType, consts.LoadBalancerBackendPoolConfigurationTypeNodeIP)
}

func (az *Config) IsLBBackendPoolTypePodIP() bool {
return strings.EqualFold(az.LoadBalancerBackendPoolConfigurationType, consts.LoadBalancerBackendPoolConfigurationTypeNodeIP) && az.UseStandardV2LoadBalancer()
}

func (az *Config) GetPutVMSSVMBatchSize() int {
return az.PutVMSSVMBatchSize
}
Expand All @@ -191,6 +195,10 @@ func (az *Config) UseStandardLoadBalancer() bool {
return strings.EqualFold(az.LoadBalancerSKU, consts.LoadBalancerSKUStandard)
}

func (az *Config) UseStandardV2LoadBalancer() bool {
return strings.EqualFold(az.LoadBalancerSKU, consts.LoadBalancerSKUStandardV2)
}

func (az *Config) ExcludeMasterNodesFromStandardLB() bool {
return az.ExcludeMasterFromStandardLB != nil && *az.ExcludeMasterFromStandardLB
}
Expand Down
34 changes: 34 additions & 0 deletions pkg/provider/difftracker/difftracker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package difftracker

import (
utilsets "sigs.k8s.io/cloud-provider-azure/pkg/util/sets"
)

func InitializeDiffTrackerState(k8sState K8sState, nrpState NRPState) (*DiffTrackerState, *SyncDiffTrackerStateReturnType) {
// If any field is nil, initialize it
if k8sState.Services == nil {
k8sState.Services = utilsets.NewString()
}
if k8sState.Egresses == nil {
k8sState.Egresses = utilsets.NewString()
}
if k8sState.Nodes == nil {
k8sState.Nodes = make(map[string]Node)
}
if nrpState.LoadBalancers == nil {
nrpState.LoadBalancers = utilsets.NewString()
}
if nrpState.NATGateways == nil {
nrpState.NATGateways = utilsets.NewString()
}
if nrpState.NRPLocations == nil {
nrpState.NRPLocations = make(map[string]NRPLocation)
}

diffTrackerState := &DiffTrackerState{
K8s: k8sState,
NRP: nrpState,
}
syncOperations := diffTrackerState.GetSyncDiffTrackerState()
return diffTrackerState, syncOperations
}
Loading

0 comments on commit 9727188

Please sign in to comment.