Skip to content

Conversation

@nghialv
Copy link
Member

@nghialv nghialv commented Nov 15, 2021

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #2787

Does this PR introduce a user-facing change?:

Fix the bug that Piped was ignoring the specified value in Config for all Bool fields that have true as its default value

@pipecd-bot
Copy link
Collaborator

GO_LINTER

The following files are not gofmt-ed. By commenting /golinter fmt, the formatted one will be appended to this pull request automatically.

pkg/config/deployment_terraform_test.go
--- pkg/config/deployment_terraform_test.go.orig
+++ pkg/config/deployment_terraform_test.go
@@ -18,9 +18,10 @@
 	"testing"
 	"time"
 
-	"github.com/pipe-cd/pipe/pkg/model"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
+
+	"github.com/pipe-cd/pipe/pkg/model"
 )
 
 func TestTerraformDeploymentConfig(t *testing.T) {
pkg/config/deployment_kubernetes_test.go
--- pkg/config/deployment_kubernetes_test.go.orig
+++ pkg/config/deployment_kubernetes_test.go
@@ -18,9 +18,10 @@
 	"testing"
 	"time"
 
-	"github.com/pipe-cd/pipe/pkg/model"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
+
+	"github.com/pipe-cd/pipe/pkg/model"
 )
 
 func TestKubernetesDeploymentConfig(t *testing.T) {

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 31.97%. This pull request decreases coverage by -0.00%.

File Function Base Head Diff
pkg/config/bool.go NewTrueByDefaultBool -- 100.00% +100.00%
pkg/config/bool.go TrueByDefaultBool.Value -- 0.00% +0.00%
pkg/app/piped/planner/ecs/ecs.go Planner.Plan 0.00% 0.00% +0.00%
pkg/app/piped/planner/kubernetes/kubernetes.go Planner.Plan 0.00% 0.00% +0.00%

@nakabonne
Copy link
Member

Then just /golinter fmt and we're good to go.
/lgtm

"//pkg/filematcher:go_default_library",
"//pkg/git:go_default_library",
"//pkg/model:go_default_library",
"//pkg/version:go_default_library",
Copy link
Member

Choose a reason for hiding this comment

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

nits, not sure why does this related to this change

Copy link
Member Author

Choose a reason for hiding this comment

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

No. A new file was added and I ran make gazelle. It seems that the version package is no longer needed for that trigger package.

@nghialv
Copy link
Member Author

nghialv commented Nov 15, 2021

/golinter fmt

@pipecd-bot pipecd-bot removed the lgtm label Nov 15, 2021
@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 31.97%. This pull request decreases coverage by -0.00%.

File Function Base Head Diff
pkg/config/bool.go NewTrueByDefaultBool -- 100.00% +100.00%
pkg/config/bool.go TrueByDefaultBool.Value -- 0.00% +0.00%
pkg/app/piped/planner/ecs/ecs.go Planner.Plan 0.00% 0.00% +0.00%
pkg/app/piped/planner/kubernetes/kubernetes.go Planner.Plan 0.00% 0.00% +0.00%

Comment on lines 24 to 29
func (b *TrueByDefaultBool) Value() bool {
if b == nil {
return true
}
return bool(*b)
}
Copy link
Member

@khanhtc1202 khanhtc1202 Nov 15, 2021

Choose a reason for hiding this comment

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

I understand your thought about adding this new alias to explicitly mention the defaults value for this type, but since we add a new type alias, it may add unnecessary complexity to the codebase, and we have a leak in case there is no value set in the yaml file, if caller side use bool(*x) instead of this x.Value() the process will be panicked. How about using *bool type with a default value is true (using defaults package) as other places?
This is the sample test for that method: https://play.golang.org/p/5X2nruNhDZN

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch!
To be honest, I tried that way but it didn't work. And I thought it was a bug from the defaults library.
But after checking again, it seems that problem was already resolved and included in the new version.
So let me upgrade that lib to the latest version and try it again.
https://github.com/creasty/defaults/releases

Copy link
Member

Choose a reason for hiding this comment

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

Good to hear that 👍

@pipecd-bot
Copy link
Collaborator

GO_LINTER

The following files are not gofmt-ed. By commenting /golinter fmt, the formatted one will be appended to this pull request automatically.

pkg/config/deployment_terraform_test.go
--- pkg/config/deployment_terraform_test.go.orig
+++ pkg/config/deployment_terraform_test.go
@@ -18,9 +18,10 @@
 	"testing"
 	"time"
 
-	"github.com/pipe-cd/pipe/pkg/model"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
+
+	"github.com/pipe-cd/pipe/pkg/model"
 )
 
 func TestTerraformDeploymentConfig(t *testing.T) {
pkg/config/deployment_kubernetes_test.go
--- pkg/config/deployment_kubernetes_test.go.orig
+++ pkg/config/deployment_kubernetes_test.go
@@ -18,9 +18,10 @@
 	"testing"
 	"time"
 
-	"github.com/pipe-cd/pipe/pkg/model"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
+
+	"github.com/pipe-cd/pipe/pkg/model"
 )
 
 func TestKubernetesDeploymentConfig(t *testing.T) {

@nghialv
Copy link
Member Author

nghialv commented Nov 15, 2021

@khanhtc1202 Thanks for your nice catch!
I have just updated the pull request. PTAL.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 31.97%. This pull request decreases coverage by -0.00%.

File Function Base Head Diff
pkg/app/piped/planner/ecs/ecs.go Planner.Plan 0.00% 0.00% +0.00%
pkg/app/piped/planner/kubernetes/kubernetes.go Planner.Plan 0.00% 0.00% +0.00%

@khanhtc1202
Copy link
Member

Nice work! It concerned me a lot, but it's no more 👍
/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by khanhtc1202.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

@pipecd-bot pipecd-bot merged commit 9f9f856 into master Nov 15, 2021
@pipecd-bot pipecd-bot deleted the config-default branch November 15, 2021 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure that the given value will not be overridden by the default one.

5 participants