Skip to content

Conversation

@pstibrany
Copy link
Contributor

Added grafana.com/rollout-mirror-replicas-from-resource-update-status-replicas annotation to optionally disable patching of reference resource when using scaling based on reference resource.

…-replicas annotation to optionally disable patching of reference resource when using scaling based on reference resource.
@pstibrany pstibrany requested review from jhalterman and pr00se August 27, 2024 15:57
Copy link
Contributor

@pr00se pr00se left a comment

Choose a reason for hiding this comment

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

Also needs a CHANGELOG entry, but otherwise LGTM. Thanks!

README.md Outdated
* `grafana.com/rollout-mirror-replicas-from-resource-name`
* `grafana.com/rollout-mirror-replicas-from-resource-kind`
* `grafana.com/rollout-mirror-replicas-from-resource-api-version`
* `grafana.com/rollout-mirror-replicas-from-resource-update-status-replicas`
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: what do you think of something like -write-back-status-replicas? might a bit clearer about which status.replicas is updated (the reference resource's).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me.

logger = log.With(logger, "name", sts.GetName(), "replicas", replicas, "referenceResource", referenceResource)

// If annotation is not present, or equals to "true", we update. If annotation equals to "false" or fails to parse, we don't update.
updateReplicas, ok := sts.Annotations[config.RolloutMirrorReplicasFromResourceUpdateStatusReplicas]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a question that has nothing to do with the actual code 😄

Sometimes we use sts.GetAnnotations() and sometimes sts.Annotations to fetch the annotations -- is there any actual difference, or just two ways to do the same thing (the function just returns sts.Annotations so I'm guessing they're the same)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tbh, I just found some random place where we did the same and used the same approach. As you found, it doesn't make a difference here.

expectedPatchedSets: nil,
expectedPatchedResources: map[string][]string{"my.group/v1/customresources/test/status": {`{"status":{"replicas":3}}`}},
},
"should patch scale subresource status.replicas if it doesn't match statefulset, but not patch the resource since it's disabled": {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "should patch...but not patch" is confusing -- maybe "shouldn't patch resource even if status.replicas doesn't match statefulset since patching is disabled"

@pstibrany
Copy link
Contributor Author

Thanks for review @pr00se, I hopefully addressed all your findings.

@pstibrany pstibrany merged commit f40e769 into main Aug 28, 2024
@pstibrany pstibrany deleted the optionally-disable-patching-of-reference-resource branch August 28, 2024 05:58
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.

2 participants