func()

in pkg/provider/ip/provider.go [202:266]


func (p *ipv4Provider) UpdateResourceCapacity(instance ec2.EC2Instance) error {
	resourceProviderAndPool, isPresent := p.getInstanceProviderAndPool(instance.Name())
	if !isPresent {
		p.log.Error(utils.ErrNotFound, utils.ErrMsgProviderAndPoolNotFound, "node name", instance.Name())
		return nil
	}

	resourceProviderAndPool.lock.Lock()
	defer resourceProviderAndPool.lock.Unlock()

	// Check if PD is enabled
	isCurrPDEnabled := p.conditions.IsWindowsPrefixDelegationEnabled()

	// Only toggle to PD mode if instance is nitro; otherwise, continue with secondary IP mode
	isNitroInstance, err := utils.IsNitroInstance(instance.Type())
	if err == nil && isNitroInstance {
		// Previous state and current state are both PD enabled, which means prefix provider has been active without toggling, hence
		// no need to update the warm pool config or node capacity as secondary IP provider
		if resourceProviderAndPool.isPrevPDEnabled && isCurrPDEnabled {
			p.log.V(1).Info("prefix provider has been active without toggling, no update from secondary IP provider",
				"isPrevPDEnabled", resourceProviderAndPool.isPrevPDEnabled, "isCurrPDEnabled", isCurrPDEnabled)
			return nil
		}

		// If toggling from secondary IP to PD mode, then set the secondary IP pool state to draining and
		// do not update the capacity as that would be done by prefix provider
		if !resourceProviderAndPool.isPrevPDEnabled && isCurrPDEnabled {
			resourceProviderAndPool.isPrevPDEnabled = true
			p.log.Info("Prefix IP provider should be active")
			job := resourceProviderAndPool.resourcePool.SetToDraining()
			if job.Operations != worker.OperationReconcileNotRequired {
				p.SubmitAsyncJob(job)
			}
			return nil
		}
	} else {
		p.log.V(1).Info("Non-nitro instances continue using secondary IP mode", "instance name", instance.Name(),
			"instance type", instance.Type())
	}

	resourceProviderAndPool.isPrevPDEnabled = false

	p.config = pool.GetWinWarmPoolConfig(p.log, p.apiWrapper, isCurrPDEnabled && isNitroInstance)

	// Set the secondary IP provider pool state to active
	job := resourceProviderAndPool.resourcePool.SetToActive(p.config)
	if job.Operations != worker.OperationReconcileNotRequired {
		p.SubmitAsyncJob(job)
	}

	instanceType := instance.Type()
	instanceName := instance.Name()
	os := instance.Os()

	capacity := resourceProviderAndPool.capacity

	err = p.apiWrapper.K8sAPI.AdvertiseCapacityIfNotSet(instance.Name(), config.ResourceNameIPAddress, capacity)
	if err != nil {
		return err
	}
	p.log.V(1).Info("advertised capacity",
		"instance", instanceName, "instance type", instanceType, "os", os, "capacity", capacity)

	return nil
}