in controllers/manager/gatewayvmconfiguration_controller.go [683:737]
func (r *GatewayVMConfigurationReconciler) reconcileVMSSNetworkInterface(
ctx context.Context,
ipConfigName string,
ipPrefixID string,
lbBackendpoolID string,
wantIPConfig bool,
interfaces []*compute.VirtualMachineScaleSetNetworkConfiguration,
) (bool, error) {
log := log.FromContext(ctx)
expectedConfig := r.getExpectedIPConfig(ipConfigName, ipPrefixID, interfaces)
var primaryNic *compute.VirtualMachineScaleSetNetworkConfiguration
needUpdate := false
foundConfig := false
for _, nic := range interfaces {
if nic.Properties != nil && to.Val(nic.Properties.Primary) {
primaryNic = nic
for i, ipConfig := range nic.Properties.IPConfigurations {
if to.Val(ipConfig.Name) == ipConfigName {
if !wantIPConfig {
log.Info("Found unwanted ipConfig, dropping")
nic.Properties.IPConfigurations = append(nic.Properties.IPConfigurations[:i], nic.Properties.IPConfigurations[i+1:]...)
needUpdate = true
} else {
if different(ipConfig, expectedConfig) {
log.Info("Found target ipConfig with different configurations, dropping")
needUpdate = true
nic.Properties.IPConfigurations = append(nic.Properties.IPConfigurations[:i], nic.Properties.IPConfigurations[i+1:]...)
} else {
log.Info("Found expected ipConfig, keeping")
foundConfig = true
}
}
break
}
}
}
}
if wantIPConfig && !foundConfig {
if primaryNic == nil {
return false, fmt.Errorf("vmss(vm) primary network interface not found")
}
primaryNic.Properties.IPConfigurations = append(primaryNic.Properties.IPConfigurations, expectedConfig)
needUpdate = true
}
changed, err := r.reconcileLbBackendPool(lbBackendpoolID, primaryNic)
if err != nil {
return false, err
}
needUpdate = needUpdate || changed
return needUpdate, nil
}