diff --git a/examples/cloudrun/bluegreen/.pipe.yaml b/examples/cloudrun/bluegreen/.pipe.yaml index c0ce74c6ef..00e1725f3b 100644 --- a/examples/cloudrun/bluegreen/.pipe.yaml +++ b/examples/cloudrun/bluegreen/.pipe.yaml @@ -8,13 +8,13 @@ spec: stages: # Deploy workloads of the new version. # But this is still receiving no traffic. - - name: CLOUDRUN_NEW_VERSION_ROLLOUT + - name: CLOUDRUN_CANARY_ROLLOUT # Change the traffic routing state where # the new version will receive 100% of the traffic as soon as possible. # This is known as blue-green strategy. - name: CLOUDRUN_TRAFFIC_ROUTING with: - newVersion: 100 + canary: 100 # Optional: We can also add an ANALYSIS stage to verify the new version. # If this stage finds any not good metrics of the new version, # a rollback process to the previous version will be executed. diff --git a/examples/cloudrun/canary/.pipe.yaml b/examples/cloudrun/canary/.pipe.yaml index 2e839309ce..5f6a37b9a7 100644 --- a/examples/cloudrun/canary/.pipe.yaml +++ b/examples/cloudrun/canary/.pipe.yaml @@ -8,13 +8,13 @@ spec: stages: # Deploy workloads of the new version. # But this is still receiving no traffic. - - name: CLOUDRUN_NEW_VERSION_ROLLOUT + - name: CLOUDRUN_CANARY_ROLLOUT # Change the traffic routing state where # the new version will receive the specified percentage of traffic. # This is known as multi-phase canary strategy. - name: CLOUDRUN_TRAFFIC_ROUTING with: - newVersion: 10 + canary: 10 # Optional: We can also add an ANALYSIS stage to verify the new version. # If this stage finds any not good metrics of the new version, # a rollback process to the previous version will be executed. @@ -23,4 +23,4 @@ spec: # thre new version will receive 100% of the traffic. - name: CLOUDRUN_TRAFFIC_ROUTING with: - newVersion: 100 + canary: 100 diff --git a/examples/lambda/bluegreen/.pipe.yaml b/examples/lambda/bluegreen/.pipe.yaml index 9a11823016..e2ea137566 100644 --- a/examples/lambda/bluegreen/.pipe.yaml +++ b/examples/lambda/bluegreen/.pipe.yaml @@ -12,13 +12,13 @@ spec: stages: # Deploy workloads of the new version. # But this is still receiving no traffic. - - name: LAMBDA_NEW_VERSION_ROLLOUT + - name: LAMBDA_CANARY_ROLLOUT # Change the traffic routing state where # the new version will receive 100% of the traffic as soon as possible. # This is known as blue-green strategy. - name: LAMBDA_TRAFFIC_ROUTING with: - newVersion: 100 + canary: 100 # Optional: We can also add an ANALYSIS stage to verify the new version. # If this stage finds any not good metrics of the new version, # a rollback process to the previous version will be executed. diff --git a/examples/lambda/canary/.pipe.yaml b/examples/lambda/canary/.pipe.yaml index adc861f1f4..ed707a35e6 100644 --- a/examples/lambda/canary/.pipe.yaml +++ b/examples/lambda/canary/.pipe.yaml @@ -12,13 +12,13 @@ spec: stages: # Deploy workloads of the new version. # But this is still receiving no traffic. - - name: LAMBDA_NEW_VERSION_ROLLOUT + - name: LAMBDA_CANARY_ROLLOUT # Change the traffic routing state where # the new version will receive the specified percentage of traffic. # This is known as multi-phase canary strategy. - name: LAMBDA_TRAFFIC_ROUTING with: - newVersion: 10 + canary: 10 # Optional: We can also add an ANALYSIS stage to verify the new version. # If this stage finds any not good metrics of the new version, # a rollback process to the previous version will be executed. @@ -27,4 +27,4 @@ spec: # thre new version will receive 100% of the traffic. - name: LAMBDA_TRAFFIC_ROUTING with: - newVersion: 100 + canary: 100 diff --git a/examples/lambda/simple/.pipe.yaml b/examples/lambda/simple/.pipe.yaml index e14a3d92a1..e9a7972159 100644 --- a/examples/lambda/simple/.pipe.yaml +++ b/examples/lambda/simple/.pipe.yaml @@ -4,6 +4,7 @@ kind: LambdaApp spec: input: # Where to fetch the source code to create lambda package. + # If the source code is inside the same repository "git" and "ref" can be omitted. git: git@github.com:org/source-repo.git path: lambdas/demoapp ref: v1.0.0 diff --git a/pkg/config/deployment.go b/pkg/config/deployment.go index 453199abc2..7f453defae 100644 --- a/pkg/config/deployment.go +++ b/pkg/config/deployment.go @@ -49,17 +49,28 @@ type PipelineStage struct { Desc string Timeout Duration - WaitStageOptions *WaitStageOptions - WaitApprovalStageOptions *WaitApprovalStageOptions - AnalysisStageOptions *AnalysisStageOptions + WaitStageOptions *WaitStageOptions + WaitApprovalStageOptions *WaitApprovalStageOptions + AnalysisStageOptions *AnalysisStageOptions + K8sPrimaryRolloutStageOptions *K8sPrimaryRolloutStageOptions K8sCanaryRolloutStageOptions *K8sCanaryRolloutStageOptions K8sCanaryCleanStageOptions *K8sCanaryCleanStageOptions K8sBaselineRolloutStageOptions *K8sBaselineRolloutStageOptions K8sBaselineCleanStageOptions *K8sBaselineCleanStageOptions K8sTrafficRoutingStageOptions *K8sTrafficRoutingStageOptions - TerraformPlanStageOptions *TerraformPlanStageOptions - TerraformApplyStageOptions *TerraformApplyStageOptions + + TerraformSyncStageOptions *TerraformSyncStageOptions + TerraformPlanStageOptions *TerraformPlanStageOptions + TerraformApplyStageOptions *TerraformApplyStageOptions + + CloudRunSyncStageOptions *CloudRunSyncStageOptions + CloudRunCanaryRolloutStageOptions *CloudRunCanaryRolloutStageOptions + CloudRunTrafficRoutingStageOptions *CloudRunTrafficRoutingStageOptions + + LambdaSyncStageOptions *LambdaSyncStageOptions + LambdaCanaryRolloutStageOptions *LambdaCanaryRolloutStageOptions + LambdaTrafficRoutingStageOptions *LambdaTrafficRoutingStageOptions } type genericPipelineStage struct { @@ -127,6 +138,12 @@ func (s *PipelineStage) UnmarshalJSON(data []byte) error { if len(gs.With) > 0 { err = json.Unmarshal(gs.With, s.K8sTrafficRoutingStageOptions) } + + case model.StageTerraformSync: + s.TerraformSyncStageOptions = &TerraformSyncStageOptions{} + if len(gs.With) > 0 { + err = json.Unmarshal(gs.With, s.TerraformSyncStageOptions) + } case model.StageTerraformPlan: s.TerraformPlanStageOptions = &TerraformPlanStageOptions{} if len(gs.With) > 0 { @@ -137,6 +154,39 @@ func (s *PipelineStage) UnmarshalJSON(data []byte) error { if len(gs.With) > 0 { err = json.Unmarshal(gs.With, s.TerraformApplyStageOptions) } + + case model.StageCloudRunSync: + s.CloudRunSyncStageOptions = &CloudRunSyncStageOptions{} + if len(gs.With) > 0 { + err = json.Unmarshal(gs.With, s.CloudRunSyncStageOptions) + } + case model.StageCloudRunCanaryRollout: + s.CloudRunCanaryRolloutStageOptions = &CloudRunCanaryRolloutStageOptions{} + if len(gs.With) > 0 { + err = json.Unmarshal(gs.With, s.CloudRunCanaryRolloutStageOptions) + } + case model.StageCloudRunTrafficRouting: + s.CloudRunTrafficRoutingStageOptions = &CloudRunTrafficRoutingStageOptions{} + if len(gs.With) > 0 { + err = json.Unmarshal(gs.With, s.CloudRunTrafficRoutingStageOptions) + } + + case model.StageLambdaSync: + s.LambdaSyncStageOptions = &LambdaSyncStageOptions{} + if len(gs.With) > 0 { + err = json.Unmarshal(gs.With, s.LambdaSyncStageOptions) + } + case model.StageLambdaCanaryRollout: + s.LambdaCanaryRolloutStageOptions = &LambdaCanaryRolloutStageOptions{} + if len(gs.With) > 0 { + err = json.Unmarshal(gs.With, s.LambdaCanaryRolloutStageOptions) + } + case model.StageLambdaTrafficRouting: + s.LambdaTrafficRoutingStageOptions = &LambdaTrafficRoutingStageOptions{} + if len(gs.With) > 0 { + err = json.Unmarshal(gs.With, s.LambdaTrafficRoutingStageOptions) + } + default: err = fmt.Errorf("unsupported stage name: %s", s.Name) } diff --git a/pkg/config/deployment_cloudrun.go b/pkg/config/deployment_cloudrun.go index 9414f13eb3..65a69d3c61 100644 --- a/pkg/config/deployment_cloudrun.go +++ b/pkg/config/deployment_cloudrun.go @@ -13,3 +13,63 @@ // limitations under the License. package config + +// CloudRunDeploymentSpec represents a deployment configuration for CloudRun application. +type CloudRunDeploymentSpec struct { + Input CloudRunDeploymentInput `json:"input"` + QuickSync CloudRunSyncStageOptions `json:"quickSync"` + Pipeline *DeploymentPipeline `json:"pipeline"` +} + +func (s *CloudRunDeploymentSpec) GetStage(index int32) (PipelineStage, bool) { + if s.Pipeline == nil { + return PipelineStage{}, false + } + if int(index) >= len(s.Pipeline.Stages) { + return PipelineStage{}, false + } + return s.Pipeline.Stages[index], true +} + +// Validate returns an error if any wrong configuration value was found. +func (s *CloudRunDeploymentSpec) Validate() error { + return nil +} + +type CloudRunDeploymentInput struct { + image string `json:"image"` + // Automatically reverts all changes from all stages when one of them failed. + // Default is true. + AutoRollback bool `json:"autoRollback"` +} + +// CloudRunSyncStageOptions contains all configurable values for a CLOUDRUN_SYNC stage. +type CloudRunSyncStageOptions struct { +} + +// CloudRunCanaryRolloutStageOptions contains all configurable values for a CLOUDRUN_CANARY_ROLLOUT stage. +type CloudRunCanaryRolloutStageOptions struct { +} + +// CloudRunTrafficRoutingStageOptions contains all configurable values for a CLOUDRUN_TRAFFIC_ROUTING stage. +type CloudRunTrafficRoutingStageOptions struct { + // Which variant should receive all traffic. + // This can be either "primary" or "canary". + All string `json:"all"` + // The percentage of traffic should be routed to PRIMARY variant. + Primary int `json:"primary"` + // The percentage of traffic should be routed to CANARY variant. + Canary int `json:"canary"` +} + +func (opts CloudRunTrafficRoutingStageOptions) Percentages() (primary, canary int) { + switch opts.All { + case "primary": + primary = 100 + return + case "canary": + canary = 100 + return + } + return opts.Primary, opts.Canary +} diff --git a/pkg/config/deployment_lambda.go b/pkg/config/deployment_lambda.go index 9414f13eb3..67a498f75d 100644 --- a/pkg/config/deployment_lambda.go +++ b/pkg/config/deployment_lambda.go @@ -13,3 +13,65 @@ // limitations under the License. package config + +// LambdaDeploymentSpec represents a deployment configuration for Lambda application. +type LambdaDeploymentSpec struct { + Input LambdaDeploymentInput `json:"input"` + QuickSync LambdaSyncStageOptions `json:"quickSync"` + Pipeline *DeploymentPipeline `json:"pipeline"` +} + +func (s *LambdaDeploymentSpec) GetStage(index int32) (PipelineStage, bool) { + if s.Pipeline == nil { + return PipelineStage{}, false + } + if int(index) >= len(s.Pipeline.Stages) { + return PipelineStage{}, false + } + return s.Pipeline.Stages[index], true +} + +// Validate returns an error if any wrong configuration value was found. +func (s *LambdaDeploymentSpec) Validate() error { + return nil +} + +type LambdaDeploymentInput struct { + Git string `json:"git"` + Path string `json:"path"` + Ref string `json:"ref"` + // Automatically reverts all changes from all stages when one of them failed. + // Default is true. + AutoRollback bool `json:"autoRollback"` +} + +// LambdaSyncStageOptions contains all configurable values for a CLOUDRUN_SYNC stage. +type LambdaSyncStageOptions struct { +} + +// LambdaCanaryRolloutStageOptions contains all configurable values for a CLOUDRUN_CANARY_ROLLOUT stage. +type LambdaCanaryRolloutStageOptions struct { +} + +// LambdaTrafficRoutingStageOptions contains all configurable values for a CLOUDRUN_TRAFFIC_ROUTING stage. +type LambdaTrafficRoutingStageOptions struct { + // Which variant should receive all traffic. + // This can be either "primary" or "canary". + All string `json:"all"` + // The percentage of traffic should be routed to PRIMARY variant. + Primary int `json:"primary"` + // The percentage of traffic should be routed to CANARY variant. + Canary int `json:"canary"` +} + +func (opts LambdaTrafficRoutingStageOptions) Percentages() (primary, canary int) { + switch opts.All { + case "primary": + primary = 100 + return + case "canary": + canary = 100 + return + } + return opts.Primary, opts.Canary +} diff --git a/pkg/config/deployment_terraform.go b/pkg/config/deployment_terraform.go index c5a2a27118..6dd19acfa1 100644 --- a/pkg/config/deployment_terraform.go +++ b/pkg/config/deployment_terraform.go @@ -16,8 +16,9 @@ package config // TerraformDeploymentSpec represents a deployment configuration for Terraform application. type TerraformDeploymentSpec struct { - Input TerraformDeploymentInput `json:"input"` - Pipeline *DeploymentPipeline `json:"pipeline"` + Input TerraformDeploymentInput `json:"input"` + QuickSync TerraformApplyStageOptions `json:"quickSync"` + Pipeline *DeploymentPipeline `json:"pipeline"` } func (s *TerraformDeploymentSpec) GetStage(index int32) (PipelineStage, bool) { @@ -44,11 +45,17 @@ type TerraformDeploymentInput struct { Dependencies []string `json:"dependencies,omitempty"` } -// TerraformPlanStageOptions contains all configurable values for a K8S_TERRAFORM_PLAN stage. +// TerraformSyncStageOptions contains all configurable values for a TERRAFORM_SYNC stage. +type TerraformSyncStageOptions struct { + // How many times to retry applying terraform changes. + Retries int `json:"retries"` +} + +// TerraformPlanStageOptions contains all configurable values for a TERRAFORM_PLAN stage. type TerraformPlanStageOptions struct { } -// TerraformApplyStageOptions contains all configurable values for a K8S_TERRAFORM_APPLY stage. +// TerraformApplyStageOptions contains all configurable values for a TERRAFORM_APPLY stage. type TerraformApplyStageOptions struct { // How many times to retry applying terraform changes. Retries int `json:"retries"` diff --git a/pkg/config/testdata/application/cloudrun-app-bluegreen.yaml b/pkg/config/testdata/application/cloudrun-app-bluegreen.yaml index c0ce74c6ef..00e1725f3b 100644 --- a/pkg/config/testdata/application/cloudrun-app-bluegreen.yaml +++ b/pkg/config/testdata/application/cloudrun-app-bluegreen.yaml @@ -8,13 +8,13 @@ spec: stages: # Deploy workloads of the new version. # But this is still receiving no traffic. - - name: CLOUDRUN_NEW_VERSION_ROLLOUT + - name: CLOUDRUN_CANARY_ROLLOUT # Change the traffic routing state where # the new version will receive 100% of the traffic as soon as possible. # This is known as blue-green strategy. - name: CLOUDRUN_TRAFFIC_ROUTING with: - newVersion: 100 + canary: 100 # Optional: We can also add an ANALYSIS stage to verify the new version. # If this stage finds any not good metrics of the new version, # a rollback process to the previous version will be executed. diff --git a/pkg/config/testdata/application/cloudrun-app-canary.yaml b/pkg/config/testdata/application/cloudrun-app-canary.yaml index 2e839309ce..5f6a37b9a7 100644 --- a/pkg/config/testdata/application/cloudrun-app-canary.yaml +++ b/pkg/config/testdata/application/cloudrun-app-canary.yaml @@ -8,13 +8,13 @@ spec: stages: # Deploy workloads of the new version. # But this is still receiving no traffic. - - name: CLOUDRUN_NEW_VERSION_ROLLOUT + - name: CLOUDRUN_CANARY_ROLLOUT # Change the traffic routing state where # the new version will receive the specified percentage of traffic. # This is known as multi-phase canary strategy. - name: CLOUDRUN_TRAFFIC_ROUTING with: - newVersion: 10 + canary: 10 # Optional: We can also add an ANALYSIS stage to verify the new version. # If this stage finds any not good metrics of the new version, # a rollback process to the previous version will be executed. @@ -23,4 +23,4 @@ spec: # thre new version will receive 100% of the traffic. - name: CLOUDRUN_TRAFFIC_ROUTING with: - newVersion: 100 + canary: 100 diff --git a/pkg/config/testdata/application/lambda-app-bluegreen.yaml b/pkg/config/testdata/application/lambda-app-bluegreen.yaml index 9a11823016..e2ea137566 100644 --- a/pkg/config/testdata/application/lambda-app-bluegreen.yaml +++ b/pkg/config/testdata/application/lambda-app-bluegreen.yaml @@ -12,13 +12,13 @@ spec: stages: # Deploy workloads of the new version. # But this is still receiving no traffic. - - name: LAMBDA_NEW_VERSION_ROLLOUT + - name: LAMBDA_CANARY_ROLLOUT # Change the traffic routing state where # the new version will receive 100% of the traffic as soon as possible. # This is known as blue-green strategy. - name: LAMBDA_TRAFFIC_ROUTING with: - newVersion: 100 + canary: 100 # Optional: We can also add an ANALYSIS stage to verify the new version. # If this stage finds any not good metrics of the new version, # a rollback process to the previous version will be executed. diff --git a/pkg/config/testdata/application/lambda-app-canary.yaml b/pkg/config/testdata/application/lambda-app-canary.yaml index adc861f1f4..ed707a35e6 100644 --- a/pkg/config/testdata/application/lambda-app-canary.yaml +++ b/pkg/config/testdata/application/lambda-app-canary.yaml @@ -12,13 +12,13 @@ spec: stages: # Deploy workloads of the new version. # But this is still receiving no traffic. - - name: LAMBDA_NEW_VERSION_ROLLOUT + - name: LAMBDA_CANARY_ROLLOUT # Change the traffic routing state where # the new version will receive the specified percentage of traffic. # This is known as multi-phase canary strategy. - name: LAMBDA_TRAFFIC_ROUTING with: - newVersion: 10 + canary: 10 # Optional: We can also add an ANALYSIS stage to verify the new version. # If this stage finds any not good metrics of the new version, # a rollback process to the previous version will be executed. @@ -27,4 +27,4 @@ spec: # thre new version will receive 100% of the traffic. - name: LAMBDA_TRAFFIC_ROUTING with: - newVersion: 100 + canary: 100 diff --git a/pkg/model/stage.go b/pkg/model/stage.go index e52c1494e8..63ebadc409 100644 --- a/pkg/model/stage.go +++ b/pkg/model/stage.go @@ -50,22 +50,31 @@ const ( // should be splitted as the specified percentage to PRIMARY, CANARY, BASELINE variants. StageK8sTrafficRouting Stage = "K8S_TRAFFIC_ROUTING" + // StageTerraformSync synced infrastructure with all the tf defined in Git. + // Firstly, it does plan and if there are any changes detected it applies those changes automatically. + StageTerraformSync Stage = "TERRAFORM_SYNC" // StageTerraformPlan shows terraform plan result. StageTerraformPlan Stage = "TERRAFORM_PLAN" // StageTerraformApply represents the state where // the new configuration has been applied. StageTerraformApply Stage = "TERRAFORM_APPLY" - // StageCloudRunNewVersionRollout represents the state where + // StageCloudRunSync does quick sync by rolling out the new version + // and switch all trafic to them. + StageCloudRunSync Stage = "CLOUDRUN_SYNC" + // StageCloudRunCanaryRollout represents the state where // the workloads of the new version has been rolled out. - StageCloudRunNewVersionRollout Stage = "CLOUDRUN_NEW_VERSION_ROLLOUT" + StageCloudRunCanaryRollout Stage = "CLOUDRUN_CANARY_ROLLOUT" // StageCloudRunTrafficRouting represents the state where the traffic to application // should be splitted as the specified percentage to previous version and new version. StageCloudRunTrafficRouting Stage = "CLOUDRUN_TRAFFIC_ROUTING" - // StageLambdaNewVersionRollout represents the state where + // StageLambdaSync does quick sync by rolling out the new version + // and switch all trafic to them. + StageLambdaSync Stage = "LAMBDA_SYNC" + // StageLambdaCanaryRollout represents the state where // the workloads of the new version has been rolled out. - StageLambdaNewVersionRollout Stage = "LAMBDA_NEW_VERSION_ROLLOUT" + StageLambdaCanaryRollout Stage = "LAMBDA_CANARY_ROLLOUT" // StageLambdaTrafficRouting represents the state where the traffic to application // should be splitted as the specified percentage to previous version and new version. StageLambdaTrafficRouting Stage = "LAMBDA_TRAFFIC_ROUTING"