Skip to content

Commit 37b31ce

Browse files
Apply defaults for Kubernetes rollout and multicluster configs (#6518)
Signed-off-by: Rawad Hossain <rawad.hossain00@gmail.com> Co-authored-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
1 parent 0a2f5f8 commit 37b31ce

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed

pkg/app/pipedv1/plugin/kubernetes/config/baseline.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414

1515
package config
1616

17-
import "github.com/pipe-cd/piped-plugin-sdk-go/unit"
17+
import (
18+
"encoding/json"
19+
20+
"github.com/creasty/defaults"
21+
"github.com/pipe-cd/piped-plugin-sdk-go/unit"
22+
)
1823

1924
// K8sBaselineRolloutStageOptions contains all configurable values for a K8S_BASELINE_ROLLOUT stage.
2025
type K8sBaselineRolloutStageOptions struct {
@@ -30,6 +35,19 @@ type K8sBaselineRolloutStageOptions struct {
3035
CreateService bool `json:"createService"`
3136
}
3237

38+
func (o *K8sBaselineRolloutStageOptions) UnmarshalJSON(data []byte) error {
39+
type alias K8sBaselineRolloutStageOptions
40+
var a alias
41+
if err := json.Unmarshal(data, &a); err != nil {
42+
return err
43+
}
44+
*o = K8sBaselineRolloutStageOptions(a)
45+
if err := defaults.Set(o); err != nil {
46+
return err
47+
}
48+
return nil
49+
}
50+
3351
// K8sBaselineCleanStageOptions contains all configurable values for a K8S_BASELINE_CLEAN stage.
3452
type K8sBaselineCleanStageOptions struct {
3553
}

pkg/app/pipedv1/plugin/kubernetes/config/canary.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414

1515
package config
1616

17-
import "github.com/pipe-cd/piped-plugin-sdk-go/unit"
17+
import (
18+
"encoding/json"
19+
20+
"github.com/creasty/defaults"
21+
"github.com/pipe-cd/piped-plugin-sdk-go/unit"
22+
)
1823

1924
// K8sCanaryRolloutStageOptions contains all configurable values for a K8S_CANARY_ROLLOUT stage.
2025
type K8sCanaryRolloutStageOptions struct {
@@ -32,6 +37,19 @@ type K8sCanaryRolloutStageOptions struct {
3237
Patches []K8sResourcePatch
3338
}
3439

40+
func (o *K8sCanaryRolloutStageOptions) UnmarshalJSON(data []byte) error {
41+
type alias K8sCanaryRolloutStageOptions
42+
var a alias
43+
if err := json.Unmarshal(data, &a); err != nil {
44+
return err
45+
}
46+
*o = K8sCanaryRolloutStageOptions(a)
47+
if err := defaults.Set(o); err != nil {
48+
return err
49+
}
50+
return nil
51+
}
52+
3553
// K8sCanaryCleanStageOptions contains all configurable values for a K8S_CANARY_CLEAN stage.
3654
type K8sCanaryCleanStageOptions struct {
3755
}

pkg/app/pipedv1/plugin/kubernetes/config/primary.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
package config
1616

17+
import (
18+
"encoding/json"
19+
20+
"github.com/creasty/defaults"
21+
)
22+
1723
// K8sPrimaryRolloutStageOptions contains all configurable values for a K8S_PRIMARY_ROLLOUT stage.
1824
type K8sPrimaryRolloutStageOptions struct {
1925
// Suffix that should be used when naming the PRIMARY variant's resources.
@@ -26,3 +32,16 @@ type K8sPrimaryRolloutStageOptions struct {
2632
// Whether the resources that are no longer defined in Git should be removed or not.
2733
Prune bool `json:"prune"`
2834
}
35+
36+
func (o *K8sPrimaryRolloutStageOptions) UnmarshalJSON(data []byte) error {
37+
type alias K8sPrimaryRolloutStageOptions
38+
var a alias
39+
if err := json.Unmarshal(data, &a); err != nil {
40+
return err
41+
}
42+
*o = K8sPrimaryRolloutStageOptions(a)
43+
if err := defaults.Set(o); err != nil {
44+
return err
45+
}
46+
return nil
47+
}

pkg/app/pipedv1/plugin/kubernetes_multicluster/config/application.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ type KubernetesApplicationSpec struct {
5454
// TODO: Define fields for KubernetesApplicationSpec.
5555
}
5656

57+
func (s *KubernetesApplicationSpec) UnmarshalJSON(data []byte) error {
58+
type alias KubernetesApplicationSpec
59+
var a alias
60+
if err := json.Unmarshal(data, &a); err != nil {
61+
return err
62+
}
63+
*s = KubernetesApplicationSpec(a)
64+
if err := defaults.Set(s); err != nil {
65+
return err
66+
}
67+
return nil
68+
}
69+
5770
func (s *KubernetesApplicationSpec) Validate() error {
5871
// TODO: Validate KubernetesApplicationSpec fields.
5972
return nil

0 commit comments

Comments
 (0)