Skip to content

Commit

Permalink
updates based on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LochanRn committed Aug 23, 2022
1 parent 38acb3f commit d3b7980
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
14 changes: 10 additions & 4 deletions azure/scope/managedmachinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,22 @@ func (s *ManagedMachinePoolScope) PatchCAPIMachinePoolObject(ctx context.Context
}

// UpdateCAPIMachinePoolReplicas updates the associated MachinePool replica count.
func (s *ManagedMachinePoolScope) UpdateCAPIMachinePoolReplicas(ctx context.Context, replicas *int32) {
func (s *ManagedMachinePoolScope) UpdateCAPIMachinePoolReplicas(replicas *int32) {
s.MachinePool.Spec.Replicas = replicas
}

// UpdateCAPIMachinePoolAnnotations updates the associated MachinePool annotation.
func (s *ManagedMachinePoolScope) UpdateCAPIMachinePoolAnnotations(ctx context.Context, key, value string) {
func (s *ManagedMachinePoolScope) UpdateCAPIMachinePoolAnnotations(key, value string) {
s.MachinePool.Annotations[key] = value
}

// RemoveCAPIMachinePoolAnnotations removes the associated MachinePool annotation.
func (s *ManagedMachinePoolScope) RemoveCAPIMachinePoolAnnotations(key string) {
delete(s.MachinePool.Annotations, key)
}

// GetCAPIMachinePoolAnnotations gets the associated MachinePool annotation.
func (s *ManagedMachinePoolScope) GetCAPIMachinePoolAnnotation(ctx context.Context, key string) string {
return s.MachinePool.Annotations[key]
func (s *ManagedMachinePoolScope) GetCAPIMachinePoolAnnotation(key string) (bool, string) {
value, ok := s.MachinePool.Annotations[key]
return ok, value
}
17 changes: 9 additions & 8 deletions azure/services/agentpools/agentpools.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ type ManagedMachinePoolScope interface {
SetAgentPoolProviderIDList([]string)
SetAgentPoolReplicas(int32)
SetAgentPoolReady(bool)
UpdateCAPIMachinePoolReplicas(ctx context.Context, replicas *int32)
UpdateCAPIMachinePoolAnnotations(ctx context.Context, key, value string)
GetCAPIMachinePoolAnnotation(ctx context.Context, key string) string
UpdateCAPIMachinePoolReplicas(replicas *int32)
UpdateCAPIMachinePoolAnnotations(key, value string)
GetCAPIMachinePoolAnnotation(key string) (bool, string)
RemoveCAPIMachinePoolAnnotations(key string)
}

// Service provides operations on Azure resources.
Expand Down Expand Up @@ -135,19 +136,19 @@ func (s *Service) Reconcile(ctx context.Context) error {
// count present in MachinePool or AzureManagedMachinePool, hence we should not make an update API call based
// on difference in count.
if to.Bool(profile.EnableAutoScaling) && existingProfile.Count != nil {
if to.Bool(profile.EnableAutoScaling) && s.scope.GetCAPIMachinePoolAnnotation(ctx, azure.ReplicasManagedByAutoscalerAnnotation) != "true" {
s.scope.UpdateCAPIMachinePoolAnnotations(ctx, azure.ReplicasManagedByAutoscalerAnnotation, "true")
if ok, _ := s.scope.GetCAPIMachinePoolAnnotation(azure.ReplicasManagedByAutoscalerAnnotation); !ok {
s.scope.UpdateCAPIMachinePoolAnnotations(azure.ReplicasManagedByAutoscalerAnnotation, "true")
}

if to.Int32(existingProfile.Count) != to.Int32(normalizedProfile.Count) {
s.scope.UpdateCAPIMachinePoolReplicas(ctx, existingProfile.Count)
s.scope.UpdateCAPIMachinePoolReplicas(existingProfile.Count)
}
normalizedProfile.Count = existingProfile.Count
}

// set ReplicasManagedByAutoscalerAnnotation to false as it is disabled by the user.
if !to.Bool(profile.EnableAutoScaling) && s.scope.GetCAPIMachinePoolAnnotation(ctx, azure.ReplicasManagedByAutoscalerAnnotation) == "true" {
s.scope.UpdateCAPIMachinePoolAnnotations(ctx, azure.ReplicasManagedByAutoscalerAnnotation, "false")
if ok, _ := s.scope.GetCAPIMachinePoolAnnotation(azure.ReplicasManagedByAutoscalerAnnotation); !to.Bool(profile.EnableAutoScaling) && ok {
s.scope.RemoveCAPIMachinePoolAnnotations(azure.ReplicasManagedByAutoscalerAnnotation)
}

// Diff and check if we require an update
Expand Down

0 comments on commit d3b7980

Please sign in to comment.