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

refactor: use a pointer for field: skipAnalysis in Canary object #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Wenliang-CHEN
Copy link
Collaborator

This refactor tries to fulfill a special use case {ticket number}: when a custom controller uses the Flagger API to create/update a Canary object using k8s client-go:

This makes sure that the skipAnalysis field is always rendered after marshalling to json format.

Comment on lines 617 to +626
func (c *Canary) SkipAnalysis() bool {
if c.Spec.SkipAnalysis == nil {
return false
}

if c.Spec.Analysis == nil && c.Spec.CanaryAnalysis == nil {
return true
}
return c.Spec.SkipAnalysis

return *c.Spec.SkipAnalysis

Choose a reason for hiding this comment

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

we don't have to adjust the return type to *bool here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This method looks like an internal API ready for consumption: when the caller calls, it is an implementation detail how the nil pointer should be handled. Then the caller just needs to know if it is a "true" or "false", sort of a tell-dont-ask principle

This refactor tries to fulfil a special use case fluxcd#1660: when a custom
controller uses the Flagger API to render the Canary object to
json/yaml, it makes sure the skipAnalysis field is rendered when the
value is "false", so that the field is always communicated to the k8s
API server.

Comparison is as follows:

before, when skipAnalysis is "false" the canary object is rendered as such:

```
apiVersion: flagger.app/v1beta1
kind: Canary
...
spec:
  analysis:
...
```

After, it is as such:
```
apiVersion: flagger.app/v1beta1
kind: Canary
...
spec:
  skipAnalysis: false # this is the field we expected
  analysis:
...
```
@Wenliang-CHEN Wenliang-CHEN force-pushed the feat/use-pointer-for-skipAnalysis-field branch from f1ef8eb to 24b40e3 Compare June 14, 2024 07:57
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