Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Set GCPMachinepoolMachine.Status.LatestModelApplied to false if some labels applied to node are not same as expected #25

Closed
wants to merge 7 commits into from
Closed

fix: Set GCPMachinepoolMachine.Status.LatestModelApplied to false if some labels applied to node are not same as expected #25

wants to merge 7 commits into from

Conversation

tasdikrahman
Copy link

instancegroupinstances: set gcpmachinepoolmachine.status.LatestModelApplied to false if additionalLabels attached to node is not the same as ones set in gcpmachinepool.spec.additionallabels Which would mark it for cleanup in graceful way if cluster.x-k8s.io/replicas-managed-by: "true" is not present on the MachinePool, and the flow of https://github.com/newrelic-forks/cluster-api-provider-gcp/blob/v1.6.0-nr5/cloud/scope/machinepool.go#L278 would be called.

What type of PR is this?

/kind bug

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests

Release note:


…odelApplied to false if additionalLabels attached to node is not the same as ones set in gcpmachinepool.spec.additionallabels
func (m *MachinePoolMachineScope) HasLatestModelApplied(_ context.Context, instance *compute.Disk) (bool, error) {
func (m *MachinePoolMachineScope) HasLatestModelApplied(ctx context.Context, instance *compute.Disk, labels map[string]string) (bool, error) {
log := log.FromContext(ctx)

image := ""

Choose a reason for hiding this comment

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

I wonder if an explicit var declaration will help with the check failure.

Copy link
Author

Choose a reason for hiding this comment

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

added a change, please check

log.Error(err, "Error checking the AdditonalLabels")
return false, err
}
if image == instanceImage && hasAdditionalLabelsDiff {
Copy link

@sachin-shankar sachin-shankar Jun 28, 2024

Choose a reason for hiding this comment

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

I think the name hasAdditionalLabelsDiff is a bit confusing here. Ideally it should mean doesNotHaveAdditionalLabelsDiff or noAdditionalLabelsDiff in the above context, correct?

Copy link
Author

Choose a reason for hiding this comment

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

just added a change here 761d5d7, please check

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
// ref: https://github.com/newrelic-forks/cluster-api-provider-gcp/blob/ef2e7f1e64ebeeb5389c446fe4cf89026fcb8a8a/cloud/services/compute/instances/reconcile_test.go#L244-L24

Choose a reason for hiding this comment

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

Could you please add a one-liner to say we need to ignore the 2 labels?

Copy link
Author

Choose a reason for hiding this comment

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

just added a change here 761d5d7, please check

@tasdikrahman
Copy link
Author

$ make test                                                                                                                                                                                                                                   (wf2a/default)
KUBEBUILDER_ASSETS="/Users/trahman/Library/Application Support/io.kubebuilder.envtest/k8s/1.28.0-darwin-arm64" go test ./...
?   	sigs.k8s.io/cluster-api-provider-gcp	[no test files]
?   	sigs.k8s.io/cluster-api-provider-gcp/cloud	[no test files]
?   	sigs.k8s.io/cluster-api-provider-gcp/cloud/gcperrors	[no test files]
ok  	sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1	(cached)
ok  	sigs.k8s.io/cluster-api-provider-gcp/cloud/providerid	(cached)
?   	sigs.k8s.io/cluster-api-provider-gcp/cloud/scope/strategies/machinepool_deployments	[no test files]
?   	sigs.k8s.io/cluster-api-provider-gcp/cloud/services/compute/firewalls	[no test files]
?   	sigs.k8s.io/cluster-api-provider-gcp/cloud/services/compute/instancegroupinstances	[no test files]
?   	sigs.k8s.io/cluster-api-provider-gcp/cloud/services/compute/instancegroups	[no test files]
?   	sigs.k8s.io/cluster-api-provider-gcp/cloud/services/compute/loadbalancers	[no test files]
?   	sigs.k8s.io/cluster-api-provider-gcp/cloud/services/compute/networks	[no test files]
?   	sigs.k8s.io/cluster-api-provider-gcp/cloud/services/container/nodepools	[no test files]
?   	sigs.k8s.io/cluster-api-provider-gcp/cloud/services/shared	[no test files]
?   	sigs.k8s.io/cluster-api-provider-gcp/exp	[no test files]
ok  	sigs.k8s.io/cluster-api-provider-gcp/cloud/scope	1.597s
ok  	sigs.k8s.io/cluster-api-provider-gcp/cloud/services/compute/instances	(cached)
ok  	sigs.k8s.io/cluster-api-provider-gcp/cloud/services/compute/subnets	(cached)
ok  	sigs.k8s.io/cluster-api-provider-gcp/cloud/services/container/clusters	(cached)
ok  	sigs.k8s.io/cluster-api-provider-gcp/controllers	(cached)
ok  	sigs.k8s.io/cluster-api-provider-gcp/exp/api/v1beta1	(cached)
?   	sigs.k8s.io/cluster-api-provider-gcp/feature	[no test files]
?   	sigs.k8s.io/cluster-api-provider-gcp/hack/boilerplate/test	[no test files]
?   	sigs.k8s.io/cluster-api-provider-gcp/util/hash	[no test files]
?   	sigs.k8s.io/cluster-api-provider-gcp/util/location	[no test files]
?   	sigs.k8s.io/cluster-api-provider-gcp/util/resourceurl	[no test files]
?   	sigs.k8s.io/cluster-api-provider-gcp/version	[no test files]
ok  	sigs.k8s.io/cluster-api-provider-gcp/exp/controllers	1.421s
ok  	sigs.k8s.io/cluster-api-provider-gcp/util/processors	(cached)
ok  	sigs.k8s.io/cluster-api-provider-gcp/util/reconciler	(cached)

lint is passing. https://github.com/newrelic-forks/cluster-api-provider-gcp/actions/runs/9715896835/job/26818326647?pr=25

@tasdikrahman tasdikrahman closed this by deleting the head repository Jul 5, 2024
@mytunguyen
Copy link

@tasdikrahman go ahead and reopen this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants