Skip to content

Commit

Permalink
refactor: hasAdditionalLabelsDiff -> doesNotHaveAdditionalLabelsDiff …
Browse files Browse the repository at this point in the history
…to make it more descriptive
  • Loading branch information
tasdikrahman committed Jun 28, 2024
1 parent c12c567 commit 761d5d7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cloud/scope/machinepoolmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (m *MachinePoolMachineScope) HasLatestModelApplied(ctx context.Context, ins
instanceImage := path.Base(diskImage.Path)

// Check if the image is the latest and additionalLabels
hasAdditionalLabelsDiff, err := m.hasAdditionalLabelsDiff(ctx, labels)
hasAdditionalLabelsDiff, err := m.doesNotHaveAdditionalLabelsDiff(ctx, labels)
if err != nil {
log.Error(err, "Error checking the AdditonalLabels")
return false, err
Expand All @@ -340,10 +340,13 @@ func (m *MachinePoolMachineScope) HasLatestModelApplied(ctx context.Context, ins
return false, nil
}

// hasAdditionalLabelsDiff Checks if the Labels applied to the instance are the latest as in the Instance Template.
// two keys of `capg-role` and `capg-cluster-<CLUSTER-NAME>` as they are added by default by CAPG
// doesNotHaveAdditionalLabelsDiff Checks if the Labels applied to the instance are the latest as in the Instance Template.
// We would need to ignore the two labels
// - `capg-role`
// - `capg-cluster-<CLUSTER-NAME>`
// as they are added by default by CAPG and when we compare it with AdditionalLabels in GCPMachinePool.Spec with the instance present.
// ref: https://github.com/newrelic-forks/cluster-api-provider-gcp/blob/ef2e7f1e64ebeeb5389c446fe4cf89026fcb8a8a/cloud/services/compute/instances/reconcile_test.go#L244-L24
func (m *MachinePoolMachineScope) hasAdditionalLabelsDiff(ctx context.Context, labels map[string]string) (bool, error) {
func (m *MachinePoolMachineScope) doesNotHaveAdditionalLabelsDiff(ctx context.Context, labels map[string]string) (bool, error) {

Check failure on line 349 in cloud/scope/machinepoolmachine.go

View workflow job for this annotation

GitHub Actions / lint

(*MachinePoolMachineScope).doesNotHaveAdditionalLabelsDiff - result 1 (error) is always nil (unparam)
diff := make(map[string]bool)
log := log.FromContext(ctx)
for _, k := range labels {
Expand Down

0 comments on commit 761d5d7

Please sign in to comment.