Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions cns/ipampool/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ func (pm *Monitor) Start(ctx context.Context) error {
// if we have initialized and enter this case, we proceed out of the select and continue to reconcile.
}
case nnc := <-pm.nncSource: // received a new NodeNetworkConfig, extract the data from it and re-reconcile.
scaler := nnc.Status.Scaler

// Set SubnetName, SubnetAddressSpace and Pod Network ARM ID values to the global subnet, subnetCIDR and subnetARM variables.
subnet = nnc.Status.NetworkContainers[0].SubnetName
subnetCIDR = nnc.Status.NetworkContainers[0].SubnetAddressSpace
subnetARMID = GenerateARMID(&nnc.Status.NetworkContainers[0])
// check for subnet exhaustion
_, pm.metastate.exhausted = exhaustedSubnetSet[nnc.Status.NetworkContainers[0].SubnetName]
if len(nnc.Status.NetworkContainers) > 0 {
// Set SubnetName, SubnetAddressSpace and Pod Network ARM ID values to the global subnet, subnetCIDR and subnetARM variables.
subnet = nnc.Status.NetworkContainers[0].SubnetName
subnetCIDR = nnc.Status.NetworkContainers[0].SubnetAddressSpace
subnetARMID = GenerateARMID(&nnc.Status.NetworkContainers[0])
// check for subnet exhaustion
_, pm.metastate.exhausted = exhaustedSubnetSet[nnc.Status.NetworkContainers[0].SubnetName]
}

pm.metastate.primaryIPAddresses = make(map[string]struct{})
// Add Primary IP to Map, if not present.
Expand All @@ -140,6 +140,7 @@ func (pm *Monitor) Start(ctx context.Context) error {
}
}

scaler := nnc.Status.Scaler
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't have NCs we probably don't have a Status at all yet, does this matter? Will the pool monitor start respecting the real scaler when it comes in later?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, next time we get an NNC we will copy the scaler out again, and I think this zero-value scaler is safe to use

pm.metastate.batch = scaler.BatchSize
pm.metastate.max = scaler.MaxIPCount
pm.metastate.minFreeCount, pm.metastate.maxFreeCount = CalculateMinFreeIPs(scaler), CalculateMaxFreeIPs(scaler)
Expand Down Expand Up @@ -469,6 +470,7 @@ func (pm *Monitor) clampScaler(scaler *v1alpha.Scaler) {
// CalculateMinFreeIPs calculates the minimum free IP quantity based on the Scaler
// in the passed NodeNetworkConfig.
// Half of odd batches are rounded up!
//
//nolint:gocritic // ignore hugeparam
func CalculateMinFreeIPs(scaler v1alpha.Scaler) int64 {
return int64(float64(scaler.BatchSize)*(float64(scaler.RequestThresholdPercent)/100) + .5) //nolint:gomnd // it's a percent
Expand All @@ -477,6 +479,7 @@ func CalculateMinFreeIPs(scaler v1alpha.Scaler) int64 {
// CalculateMaxFreeIPs calculates the maximum free IP quantity based on the Scaler
// in the passed NodeNetworkConfig.
// Half of odd batches are rounded up!
//
//nolint:gocritic // ignore hugeparam
func CalculateMaxFreeIPs(scaler v1alpha.Scaler) int64 {
return int64(float64(scaler.BatchSize)*(float64(scaler.ReleaseThresholdPercent)/100) + .5) //nolint:gomnd // it's a percent
Expand Down
6 changes: 0 additions & 6 deletions cns/kubecontroller/nodenetworkconfig/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco

logger.Printf("[cns-rc] CRD Spec: %+v", nnc.Spec)

// if there are no network containers, don't continue to updating Listeners
if len(nnc.Status.NetworkContainers) == 0 {
logger.Errorf("[cns-rc] Empty NetworkContainers")
return reconcile.Result{}, nil
}

ipAssignments := 0
// for each NC, parse it in to a CreateNCRequest and forward it to the appropriate Listener
for i := range nnc.Status.NetworkContainers {
Expand Down