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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pkg/apis/flagger/v1beta1/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type CanarySpec struct {

// SkipAnalysis promotes the canary without analysing it
// +optional
SkipAnalysis bool `json:"skipAnalysis,omitempty"`
SkipAnalysis *bool `json:"skipAnalysis,omitempty"`

// revert canary mutation on deletion of canary resource
// +optional
Expand Down Expand Up @@ -615,8 +615,13 @@ func (c *Canary) GetMetricInterval() string {
// SkipAnalysis returns true if the analysis is nil
// or if spec.SkipAnalysis is true
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
Comment on lines 617 to +626

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

}
5 changes: 3 additions & 2 deletions pkg/controller/scheduler_daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ func TestScheduler_DaemonSetSkipAnalysis(t *testing.T) {
cd, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Get(context.TODO(), "podinfo", metav1.GetOptions{})
require.NoError(t, err)

cd.Spec.SkipAnalysis = true
skipAnalysis := true
cd.Spec.SkipAnalysis = &skipAnalysis
_, err = mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Update(context.TODO(), cd, metav1.UpdateOptions{})
require.NoError(t, err)

Expand All @@ -126,7 +127,7 @@ func TestScheduler_DaemonSetSkipAnalysis(t *testing.T) {

c, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Get(context.TODO(), "podinfo", metav1.GetOptions{})
require.NoError(t, err)
assert.True(t, c.Spec.SkipAnalysis)
assert.True(t, c.SkipAnalysis())
assert.Equal(t, flaggerv1.CanaryPhaseSucceeded, c.Status.Phase)
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/scheduler_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ func TestScheduler_DeploymentSkipAnalysis(t *testing.T) {
// enable skip
cd, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Get(context.TODO(), "podinfo", metav1.GetOptions{})
require.NoError(t, err)
cd.Spec.SkipAnalysis = true
skipAnalysis := true
cd.Spec.SkipAnalysis = &skipAnalysis
_, err = mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Update(context.TODO(), cd, metav1.UpdateOptions{})
require.NoError(t, err)

Expand All @@ -148,7 +149,7 @@ func TestScheduler_DeploymentSkipAnalysis(t *testing.T) {

c, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Get(context.TODO(), "podinfo", metav1.GetOptions{})
require.NoError(t, err)
assert.True(t, c.Spec.SkipAnalysis)
assert.True(t, c.SkipAnalysis())
assert.Equal(t, flaggerv1.CanaryPhaseSucceeded, c.Status.Phase)
}

Expand Down
Loading