Skip to content

Commit 89562e3

Browse files
[Multi_K8s-Plugin] Multi Canary Rollout (#6583)
* feat: add K8s canary rollout stage and description Signed-off-by: Mohammed Firdous <mohammedfirdousaraoye@gmail.com> * feat: add DeepCopyWithName and NestedString methods, and introduce KindService constant Signed-off-by: Mohammed Firdous <124298708+mohammedfirdouss@users.noreply.github.com> * feat: implement K8s multi canary rollout stage and related configurations Signed-off-by: Mohammed Firdous <124298708+mohammedfirdouss@users.noreply.github.com> * feat: implement Kubernetes multi-cluster canary rollout stage Signed-off-by: Mohammed Firdous <124298708+mohammedfirdouss@users.noreply.github.com> * feat: add Kubernetes deployment and app configuration for canary rollout Signed-off-by: Mohammed Firdous <124298708+mohammedfirdouss@users.noreply.github.com> * feat: add test cases and configuration for Kubernetes multi-cluster canary rollout with and without service creation Signed-off-by: Mohammed Firdous <124298708+mohammedfirdouss@users.noreply.github.com> --------- Signed-off-by: Mohammed Firdous <mohammedfirdousaraoye@gmail.com> Signed-off-by: Mohammed Firdous <124298708+mohammedfirdouss@users.noreply.github.com>
1 parent 25601c8 commit 89562e3

File tree

18 files changed

+1173
-3
lines changed

18 files changed

+1173
-3
lines changed

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121

2222
"github.com/creasty/defaults"
23+
"github.com/pipe-cd/piped-plugin-sdk-go/unit"
2324

2425
config "github.com/pipe-cd/pipecd/pkg/configv1"
2526
)
@@ -48,6 +49,10 @@ type KubernetesApplicationSpec struct {
4849
// name: replication-controller-name
4950
Workloads []K8sResourceReference `json:"workloads"`
5051

52+
// Which resource should be considered as the Service of application.
53+
// Empty means the first Service resource will be used.
54+
Service K8sResourceReference `json:"service"`
55+
5156
// The label will be configured to variant manifests used to distinguish them.
5257
VariantLabel KubernetesVariantLabel `json:"variantLabel"`
5358

@@ -56,14 +61,17 @@ type KubernetesApplicationSpec struct {
5661

5762
func (s *KubernetesApplicationSpec) UnmarshalJSON(data []byte) error {
5863
type alias KubernetesApplicationSpec
64+
5965
var a alias
6066
if err := json.Unmarshal(data, &a); err != nil {
6167
return err
6268
}
69+
6370
*s = KubernetesApplicationSpec(a)
6471
if err := defaults.Set(s); err != nil {
6572
return err
6673
}
74+
6775
return nil
6876
}
6977

@@ -173,3 +181,62 @@ type KubernetesMultiTargetDeployTarget struct {
173181
Name string `json:"name"`
174182
Labels map[string]string `json:"labels"`
175183
}
184+
185+
// K8sCanaryRolloutStageOptions contains all configurable values for a K8S_CANARY_ROLLOUT stage.
186+
type K8sCanaryRolloutStageOptions struct {
187+
// How many pods for CANARY workloads.
188+
// An integer value can be specified to indicate an absolute value of pod number.
189+
// Or a string suffixed by "%" to indicate a percentage value compared to the pod number of PRIMARY.
190+
// Default is 1 pod.
191+
Replicas unit.Replicas `json:"replicas"`
192+
// Suffix that should be used when naming the CANARY variant's resources.
193+
// Default is "canary".
194+
Suffix string `json:"suffix" default:"canary"`
195+
// Whether the CANARY service should be created.
196+
CreateService bool `json:"createService"`
197+
// List of patches used to customize manifests for CANARY variant.
198+
Patches []K8sResourcePatch `json:"patches"`
199+
}
200+
201+
// K8sCanaryCleanStageOptions contains all configurable values for a K8S_CANARY_CLEAN stage.
202+
type K8sCanaryCleanStageOptions struct{}
203+
204+
// K8sResourcePatch represents a patch operation for a Kubernetes resource.
205+
type K8sResourcePatch struct {
206+
// The target of the patch operation.
207+
Target K8sResourcePatchTarget `json:"target"`
208+
// The operations to be performed on the target.
209+
Ops []K8sResourcePatchOp `json:"ops"`
210+
}
211+
212+
// K8sResourcePatchTarget represents the target of a patch operation for a Kubernetes resource.
213+
type K8sResourcePatchTarget struct {
214+
// The reference to the Kubernetes resource.
215+
K8sResourceReference
216+
// In case you want to manipulate the YAML or JSON data specified in a field
217+
// of the manifest, specify that field's path. The string value of that field
218+
// will be used as input for the patch operations.
219+
// Otherwise, the whole manifest will be the target of patch operations.
220+
DocumentRoot string `json:"documentRoot"`
221+
}
222+
223+
// K8sResourcePatchOpName represents the name of a patch operation for a Kubernetes resource.
224+
type K8sResourcePatchOpName string
225+
226+
const (
227+
// K8sResourcePatchOpYAMLReplace is the name of the patch operation that replaces the target with a new YAML document.
228+
K8sResourcePatchOpYAMLReplace K8sResourcePatchOpName = "yaml-replace"
229+
)
230+
231+
// K8sResourcePatchOp represents a patch operation for a Kubernetes resource.
232+
type K8sResourcePatchOp struct {
233+
// The operation type.
234+
// Currently, only "yaml-replace" is supported.
235+
// Default is "yaml-replace".
236+
Op K8sResourcePatchOpName `json:"op" default:"yaml-replace"`
237+
// The path string pointing to the manipulated field.
238+
// E.g. "$.spec.foos[0].bar"
239+
Path string `json:"path"`
240+
// The value string whose content will be used as new value for the field.
241+
Value string `json:"value"`
242+
}

0 commit comments

Comments
 (0)