From 58c922bf293615ba11b1b4388ff7bc26150745f0 Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Thu, 31 Oct 2024 10:47:46 +0900 Subject: [PATCH] Delete platform-specific specs from configv1 Signed-off-by: Shinnosuke Sawada-Dazai --- pkg/configv1/application.go | 41 --- pkg/configv1/application_cloudrun.go | 53 --- pkg/configv1/application_cloudrun_test.go | 77 ----- pkg/configv1/application_ecs.go | 162 --------- pkg/configv1/application_ecs_test.go | 165 --------- pkg/configv1/application_kubernetes.go | 313 ------------------ pkg/configv1/application_lambda.go | 57 ---- pkg/configv1/application_terraform.go | 92 ----- pkg/configv1/application_test.go | 222 ++++--------- pkg/configv1/config.go | 76 +---- pkg/configv1/config_test.go | 112 ------- .../application/cloudrun-app-bluegreen.yaml | 21 -- .../application/cloudrun-app-canary.yaml | 26 -- .../testdata/application/cloudrun-app.yaml | 2 - .../application/custom-sync-without-run.yaml | 11 - .../testdata/application/custom-sync.yaml | 14 - .../ecs-app-invalid-access-type.yaml | 7 - .../ecs-app-service-discovery.yaml | 7 - .../testdata/application/ecs-app.yaml | 11 - .../k8s-app-bluegreen-with-analysis.yaml | 28 -- .../application/k8s-app-bluegreen.yaml | 28 -- .../testdata/application/k8s-app-canary.yaml | 298 ----------------- .../application/k8s-app-envoy-bluegreen.yaml | 16 - .../application/k8s-app-envoy-canary.yaml | 16 - .../testdata/application/k8s-app-helm.yaml | 38 --- .../application/k8s-app-istio-bluegreen.yaml | 41 --- .../application/k8s-app-istio-canary.yaml | 56 ---- .../application/k8s-app-kustomization.yaml | 5 - .../application/k8s-app-resource-route.yaml | 16 - .../k8s-app-use-pipeline-template.yaml | 5 - .../testdata/application/k8s-plain-yaml.yaml | 9 - .../application/lambda-app-bluegreen.yaml | 16 - .../application/lambda-app-canary.yaml | 21 -- .../testdata/application/lambda-app.yaml | 2 - .../application/terraform-app-empty.yaml | 2 - .../terraform-app-secret-management.yaml | 14 - .../terraform-app-with-approval.yaml | 37 --- .../application/terraform-app-with-exit.yaml | 39 --- .../testdata/application/terraform-app.yaml | 6 - .../truebydefaultbool-false-explicitly.yaml | 2 - .../truebydefaultbool-true-explicitly.yaml | 2 - 41 files changed, 82 insertions(+), 2084 deletions(-) delete mode 100644 pkg/configv1/application_cloudrun.go delete mode 100644 pkg/configv1/application_cloudrun_test.go delete mode 100644 pkg/configv1/application_ecs.go delete mode 100644 pkg/configv1/application_ecs_test.go delete mode 100644 pkg/configv1/application_kubernetes.go delete mode 100644 pkg/configv1/application_lambda.go delete mode 100644 pkg/configv1/application_terraform.go delete mode 100644 pkg/configv1/config_test.go delete mode 100644 pkg/configv1/testdata/application/cloudrun-app-bluegreen.yaml delete mode 100644 pkg/configv1/testdata/application/cloudrun-app-canary.yaml delete mode 100644 pkg/configv1/testdata/application/cloudrun-app.yaml delete mode 100644 pkg/configv1/testdata/application/custom-sync-without-run.yaml delete mode 100644 pkg/configv1/testdata/application/custom-sync.yaml delete mode 100644 pkg/configv1/testdata/application/ecs-app-invalid-access-type.yaml delete mode 100644 pkg/configv1/testdata/application/ecs-app-service-discovery.yaml delete mode 100644 pkg/configv1/testdata/application/ecs-app.yaml delete mode 100644 pkg/configv1/testdata/application/k8s-app-bluegreen-with-analysis.yaml delete mode 100644 pkg/configv1/testdata/application/k8s-app-bluegreen.yaml delete mode 100644 pkg/configv1/testdata/application/k8s-app-canary.yaml delete mode 100644 pkg/configv1/testdata/application/k8s-app-envoy-bluegreen.yaml delete mode 100644 pkg/configv1/testdata/application/k8s-app-envoy-canary.yaml delete mode 100644 pkg/configv1/testdata/application/k8s-app-helm.yaml delete mode 100644 pkg/configv1/testdata/application/k8s-app-istio-bluegreen.yaml delete mode 100644 pkg/configv1/testdata/application/k8s-app-istio-canary.yaml delete mode 100644 pkg/configv1/testdata/application/k8s-app-kustomization.yaml delete mode 100644 pkg/configv1/testdata/application/k8s-app-resource-route.yaml delete mode 100644 pkg/configv1/testdata/application/k8s-app-use-pipeline-template.yaml delete mode 100644 pkg/configv1/testdata/application/k8s-plain-yaml.yaml delete mode 100644 pkg/configv1/testdata/application/lambda-app-bluegreen.yaml delete mode 100644 pkg/configv1/testdata/application/lambda-app-canary.yaml delete mode 100644 pkg/configv1/testdata/application/lambda-app.yaml delete mode 100644 pkg/configv1/testdata/application/terraform-app-empty.yaml delete mode 100644 pkg/configv1/testdata/application/terraform-app-secret-management.yaml delete mode 100644 pkg/configv1/testdata/application/terraform-app-with-approval.yaml delete mode 100644 pkg/configv1/testdata/application/terraform-app-with-exit.yaml delete mode 100644 pkg/configv1/testdata/application/terraform-app.yaml diff --git a/pkg/configv1/application.go b/pkg/configv1/application.go index a2c49495b1..703673a7d6 100644 --- a/pkg/configv1/application.go +++ b/pkg/configv1/application.go @@ -17,8 +17,6 @@ package config import ( "encoding/json" "fmt" - "os" - "path/filepath" "strings" "github.com/pipe-cd/pipecd/pkg/model" @@ -303,23 +301,6 @@ func (a *AnalysisStageOptions) Validate() error { return nil } -// ScriptRunStageOptions contains all configurable values for a SCRIPT_RUN stage. -type ScriptRunStageOptions struct { - Env map[string]string `json:"env"` - Run string `json:"run"` - Timeout Duration `json:"timeout" default:"6h"` - OnRollback string `json:"onRollback"` - SkipOn SkipOptions `json:"skipOn,omitempty"` -} - -// Validate checks the required fields of ScriptRunStageOptions. -func (s *ScriptRunStageOptions) Validate() error { - if s.Run == "" { - return fmt.Errorf("SCRIPT_RUN stage requires run field") - } - return nil -} - type AnalysisTemplateRef struct { Name string `json:"name"` AppArgs map[string]string `json:"appArgs"` @@ -571,25 +552,3 @@ func (dd *DriftDetection) Validate() error { } return nil } - -func LoadApplication(repoPath, configRelPath string, appKind model.ApplicationKind) (*GenericApplicationSpec, error) { - absPath := filepath.Join(repoPath, configRelPath) - - cfg, err := LoadFromYAML(absPath) - if err != nil { - if os.IsNotExist(err) { - return nil, fmt.Errorf("application config file %s was not found in Git", configRelPath) - } - return nil, err - } - if kind, ok := cfg.Kind.ToApplicationKind(); !ok || kind != appKind { - return nil, fmt.Errorf("invalid application kind in the application config file, got: %s, expected: %s", kind, appKind) - } - - spec, ok := cfg.GetGenericApplication() - if !ok { - return nil, fmt.Errorf("unsupported application kind: %s", appKind) - } - - return &spec, nil -} diff --git a/pkg/configv1/application_cloudrun.go b/pkg/configv1/application_cloudrun.go deleted file mode 100644 index 2f061f5ac6..0000000000 --- a/pkg/configv1/application_cloudrun.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2024 The PipeCD Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package config - -// CloudRunApplicationSpec represents an application configuration for CloudRun application. -type CloudRunApplicationSpec struct { - GenericApplicationSpec - // Input for CloudRun deployment such as docker image... - Input CloudRunDeploymentInput `json:"input"` - // Configuration for quick sync. - QuickSync CloudRunSyncStageOptions `json:"quickSync"` -} - -// Validate returns an error if any wrong configuration value was found. -func (s *CloudRunApplicationSpec) Validate() error { - if err := s.GenericApplicationSpec.Validate(); err != nil { - return err - } - return nil -} - -type CloudRunDeploymentInput struct { - // The name of service manifest file placing in application directory. - // Default is service.yaml - ServiceManifestFile string `json:"serviceManifestFile"` - // Automatically reverts to the previous state when the deployment is failed. - // Default is true. - // - // Deprecated: Use Planner.AutoRollback instead. - AutoRollback *bool `json:"autoRollback,omitempty" default:"true"` -} - -// CloudRunSyncStageOptions contains all configurable values for a CLOUDRUN_SYNC stage. -type CloudRunSyncStageOptions struct { -} - -// CloudRunPromoteStageOptions contains all configurable values for a CLOUDRUN_PROMOTE stage. -type CloudRunPromoteStageOptions struct { - // Percentage of traffic should be routed to the new version. - Percent Percentage `json:"percent"` -} diff --git a/pkg/configv1/application_cloudrun_test.go b/pkg/configv1/application_cloudrun_test.go deleted file mode 100644 index 2d419a78f7..0000000000 --- a/pkg/configv1/application_cloudrun_test.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2024 The PipeCD Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package config - -import ( - "testing" - "time" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestCloudRunApplicationConfig(t *testing.T) { - testcases := []struct { - fileName string - expectedKind Kind - expectedAPIVersion string - expectedSpec interface{} - expectedError error - }{ - { - fileName: "testdata/application/cloudrun-app.yaml", - expectedKind: KindCloudRunApp, - expectedAPIVersion: "pipecd.dev/v1beta1", - expectedSpec: &CloudRunApplicationSpec{ - GenericApplicationSpec: GenericApplicationSpec{ - Timeout: Duration(6 * time.Hour), - Trigger: Trigger{ - OnCommit: OnCommit{ - Disabled: false, - }, - OnCommand: OnCommand{ - Disabled: false, - }, - OnOutOfSync: OnOutOfSync{ - Disabled: newBoolPointer(true), - MinWindow: Duration(5 * time.Minute), - }, - OnChain: OnChain{ - Disabled: newBoolPointer(true), - }, - }, - Planner: DeploymentPlanner{ - AutoRollback: newBoolPointer(true), - }, - }, - Input: CloudRunDeploymentInput{ - AutoRollback: newBoolPointer(true), - }, - }, - expectedError: nil, - }, - } - for _, tc := range testcases { - t.Run(tc.fileName, func(t *testing.T) { - cfg, err := LoadFromYAML(tc.fileName) - require.Equal(t, tc.expectedError, err) - if err == nil { - assert.Equal(t, tc.expectedKind, cfg.Kind) - assert.Equal(t, tc.expectedAPIVersion, cfg.APIVersion) - assert.Equal(t, tc.expectedSpec, cfg.spec) - } - }) - } -} diff --git a/pkg/configv1/application_ecs.go b/pkg/configv1/application_ecs.go deleted file mode 100644 index 469183913b..0000000000 --- a/pkg/configv1/application_ecs.go +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright 2024 The PipeCD Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package config - -import ( - "fmt" -) - -const ( - AccessTypeELB string = "ELB" - AccessTypeServiceDiscovery string = "SERVICE_DISCOVERY" -) - -// ECSApplicationSpec represents an application configuration for ECS application. -type ECSApplicationSpec struct { - GenericApplicationSpec - // Input for ECS deployment such as where to fetch source code... - Input ECSDeploymentInput `json:"input"` - // Configuration for quick sync. - QuickSync ECSSyncStageOptions `json:"quickSync"` -} - -// Validate returns an error if any wrong configuration value was found. -func (s *ECSApplicationSpec) Validate() error { - if err := s.GenericApplicationSpec.Validate(); err != nil { - return err - } - - if err := s.Input.validate(); err != nil { - return err - } - - return nil -} - -type ECSDeploymentInput struct { - // The Amazon Resource Name (ARN) that identifies the cluster. - ClusterArn string `json:"clusterArn,omitempty"` - // The launch type on which to run your task. - // https://docs.aws.amazon.com/AmazonECS/latest/developerguide/launch_types.html - // Default is FARGATE - LaunchType string `json:"launchType,omitempty" default:"FARGATE"` - // VpcConfiguration ECSVpcConfiguration `json:"awsvpcConfiguration"` - AwsVpcConfiguration ECSVpcConfiguration `json:"awsvpcConfiguration,omitempty" default:""` - // The name of service definition file placing in application directory. - ServiceDefinitionFile string `json:"serviceDefinitionFile"` - // The name of task definition file placing in application directory. - // Default is taskdef.json - TaskDefinitionFile string `json:"taskDefinitionFile" default:"taskdef.json"` - // ECSTargetGroups - TargetGroups ECSTargetGroups `json:"targetGroups,omitempty"` - // Automatically reverts all changes from all stages when one of them failed. - // Default is true. - // - // Deprecated: Use Planner.AutoRollback instead. - AutoRollback *bool `json:"autoRollback,omitempty" default:"true"` - // Run standalone task during deployment. - // Default is true. - RunStandaloneTask *bool `json:"runStandaloneTask,omitempty" default:"true"` - // How the ECS service is accessed. - // Possible values are: - // - ELB - The service is accessed via ELB and target groups. - // - SERVICE_DISCOVERY - The service is accessed via ECS Service Discovery. - // Default is ELB. - AccessType string `json:"accessType,omitempty" default:"ELB"` -} - -func (in *ECSDeploymentInput) IsStandaloneTask() bool { - return in.ServiceDefinitionFile == "" -} - -func (in *ECSDeploymentInput) IsAccessedViaELB() bool { - return in.AccessType == AccessTypeELB -} - -type ECSVpcConfiguration struct { - Subnets []string `json:"subnets,omitempty"` - AssignPublicIP string `json:"assignPublicIp,omitempty"` - SecurityGroups []string `json:"securityGroups,omitempty"` -} - -type ECSTargetGroups struct { - Primary *ECSTargetGroup `json:"primary,omitempty"` - Canary *ECSTargetGroup `json:"canary,omitempty"` -} - -type ECSTargetGroup struct { - TargetGroupArn string `json:"targetGroupArn,omitempty"` - ContainerName string `json:"containerName,omitempty"` - ContainerPort int `json:"containerPort,omitempty"` - LoadBalancerName string `json:"loadBalancerName,omitempty"` -} - -// ECSSyncStageOptions contains all configurable values for a ECS_SYNC stage. -type ECSSyncStageOptions struct { - // Whether to delete old tasksets before creating new ones or not. - // If this is set, the application may be unavailable for a short of time during the deployment. - // Default is false. - Recreate bool `json:"recreate"` -} - -// ECSCanaryRolloutStageOptions contains all configurable values for a ECS_CANARY_ROLLOUT stage. -type ECSCanaryRolloutStageOptions struct { - // Scale represents the amount of desired task that should be rolled out as CANARY variant workload. - Scale Percentage `json:"scale"` -} - -// ECSPrimaryRolloutStageOptions contains all configurable values for a ECS_PRIMARY_ROLLOUT stage. -type ECSPrimaryRolloutStageOptions struct { -} - -// ECSCanaryCleanStageOptions contains all configurable values for a ECS_CANARY_CLEAN stage. -type ECSCanaryCleanStageOptions struct { -} - -// ECSTrafficRoutingStageOptions contains all configurable values for ECS_TRAFFIC_ROUTING stage. -type ECSTrafficRoutingStageOptions struct { - // Canary represents the amount of traffic that the rolled out CANARY variant will serve. - Canary Percentage `json:"canary,omitempty"` - // Primary represents the amount of traffic that the rolled out CANARY variant will serve. - Primary Percentage `json:"primary,omitempty"` -} - -func (opts ECSTrafficRoutingStageOptions) Percentage() (primary, canary int) { - primary = opts.Primary.Int() - if primary > 0 && primary <= 100 { - canary = 100 - primary - return - } - - canary = opts.Canary.Int() - if canary > 0 && canary <= 100 { - primary = 100 - canary - return - } - // As default, Primary variant will receive 100% of traffic. - primary = 100 - canary = 0 - return -} - -func (in *ECSDeploymentInput) validate() error { - switch in.AccessType { - case AccessTypeELB, AccessTypeServiceDiscovery: - break - default: - return fmt.Errorf("invalid accessType: %s", in.AccessType) - } - return nil -} diff --git a/pkg/configv1/application_ecs_test.go b/pkg/configv1/application_ecs_test.go deleted file mode 100644 index ed6a5054ca..0000000000 --- a/pkg/configv1/application_ecs_test.go +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2024 The PipeCD Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package config - -import ( - "fmt" - "testing" - "time" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestECSApplicationConfig(t *testing.T) { - testcases := []struct { - fileName string - expectedKind Kind - expectedAPIVersion string - expectedLaunchType string - expectedSpec interface{} - expectedError error - }{ - { - fileName: "testdata/application/ecs-app.yaml", - expectedKind: KindECSApp, - expectedAPIVersion: "pipecd.dev/v1beta1", - expectedSpec: &ECSApplicationSpec{ - GenericApplicationSpec: GenericApplicationSpec{ - Timeout: Duration(6 * time.Hour), - Trigger: Trigger{ - OnCommit: OnCommit{ - Disabled: false, - }, - OnCommand: OnCommand{ - Disabled: false, - }, - OnOutOfSync: OnOutOfSync{ - Disabled: newBoolPointer(true), - MinWindow: Duration(5 * time.Minute), - }, - OnChain: OnChain{ - Disabled: newBoolPointer(true), - }, - }, - Planner: DeploymentPlanner{ - AutoRollback: newBoolPointer(true), - }, - }, - Input: ECSDeploymentInput{ - ServiceDefinitionFile: "/path/to/servicedef.yaml", - TaskDefinitionFile: "/path/to/taskdef.yaml", - TargetGroups: ECSTargetGroups{ - Primary: &ECSTargetGroup{ - TargetGroupArn: "arn:aws:elasticloadbalancing:xyz", - ContainerName: "web", - ContainerPort: 80, - }, - }, - LaunchType: "FARGATE", - AutoRollback: newBoolPointer(true), - RunStandaloneTask: newBoolPointer(true), - AccessType: "ELB", - }, - }, - expectedError: nil, - }, - { - fileName: "testdata/application/ecs-app-service-discovery.yaml", - expectedKind: KindECSApp, - expectedAPIVersion: "pipecd.dev/v1beta1", - expectedSpec: &ECSApplicationSpec{ - GenericApplicationSpec: GenericApplicationSpec{ - Timeout: Duration(6 * time.Hour), - Trigger: Trigger{ - OnCommit: OnCommit{ - Disabled: false, - }, - OnCommand: OnCommand{ - Disabled: false, - }, - OnOutOfSync: OnOutOfSync{ - Disabled: newBoolPointer(true), - MinWindow: Duration(5 * time.Minute), - }, - OnChain: OnChain{ - Disabled: newBoolPointer(true), - }, - }, - Planner: DeploymentPlanner{ - AutoRollback: newBoolPointer(true), - }, - }, - Input: ECSDeploymentInput{ - ServiceDefinitionFile: "/path/to/servicedef.yaml", - TaskDefinitionFile: "/path/to/taskdef.yaml", - LaunchType: "FARGATE", - AutoRollback: newBoolPointer(true), - RunStandaloneTask: newBoolPointer(true), - AccessType: "SERVICE_DISCOVERY", - }, - }, - expectedError: nil, - }, - { - fileName: "testdata/application/ecs-app-invalid-access-type.yaml", - expectedKind: KindECSApp, - expectedAPIVersion: "pipecd.dev/v1beta1", - expectedSpec: &ECSApplicationSpec{ - GenericApplicationSpec: GenericApplicationSpec{ - Timeout: Duration(6 * time.Hour), - Trigger: Trigger{ - OnCommit: OnCommit{ - Disabled: false, - }, - OnCommand: OnCommand{ - Disabled: false, - }, - OnOutOfSync: OnOutOfSync{ - Disabled: newBoolPointer(true), - MinWindow: Duration(5 * time.Minute), - }, - OnChain: OnChain{ - Disabled: newBoolPointer(true), - }, - }, - Planner: DeploymentPlanner{ - AutoRollback: newBoolPointer(true), - }, - }, - Input: ECSDeploymentInput{ - ServiceDefinitionFile: "/path/to/servicedef.yaml", - TaskDefinitionFile: "/path/to/taskdef.yaml", - LaunchType: "FARGATE", - AutoRollback: newBoolPointer(true), - RunStandaloneTask: newBoolPointer(true), - AccessType: "XXX", - }, - }, - expectedError: fmt.Errorf("invalid accessType: XXX"), - }, - } - for _, tc := range testcases { - t.Run(tc.fileName, func(t *testing.T) { - cfg, err := LoadFromYAML(tc.fileName) - require.Equal(t, tc.expectedError, err) - if err == nil { - assert.Equal(t, tc.expectedKind, cfg.Kind) - assert.Equal(t, tc.expectedAPIVersion, cfg.APIVersion) - assert.Equal(t, tc.expectedSpec, cfg.spec) - } - }) - } -} diff --git a/pkg/configv1/application_kubernetes.go b/pkg/configv1/application_kubernetes.go deleted file mode 100644 index b8ad067a9d..0000000000 --- a/pkg/configv1/application_kubernetes.go +++ /dev/null @@ -1,313 +0,0 @@ -// Copyright 2024 The PipeCD Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package config - -// KubernetesApplicationSpec represents an application configuration for Kubernetes application. -type KubernetesApplicationSpec struct { - GenericApplicationSpec - // Input for Kubernetes deployment such as kubectl version, helm version, manifests filter... - Input KubernetesDeploymentInput `json:"input"` - // Configuration for quick sync. - QuickSync K8sSyncStageOptions `json:"quickSync"` - // Which resource should be considered as the Service of application. - // Empty means the first Service resource will be used. - Service K8sResourceReference `json:"service"` - // Which resources should be considered as the Workload of application. - // Empty means all Deployments. - // e.g. - // - kind: Deployment - // name: deployment-name - // - kind: ReplicationController - // name: replication-controller-name - Workloads []K8sResourceReference `json:"workloads"` - // Which method should be used for traffic routing. - TrafficRouting *KubernetesTrafficRouting `json:"trafficRouting"` - // The label will be configured to variant manifests used to distinguish them. - VariantLabel KubernetesVariantLabel `json:"variantLabel"` - // List of route configurations to resolve the platform provider for application resources. - // Each resource will be checked over the match conditions of each route. - // If matches, it will be applied to the route's provider, - // otherwise, it will be fallen through the next route to check. - // Any resource which does not match any specified route will be applied - // to the default platform provider which had been specified while registering the application. - ResourceRoutes []KubernetesResourceRoute `json:"resourceRoutes"` -} - -// Validate returns an error if any wrong configuration value was found. -func (s *KubernetesApplicationSpec) Validate() error { - if err := s.GenericApplicationSpec.Validate(); err != nil { - return err - } - return nil -} - -type KubernetesVariantLabel struct { - // The key of the label. - // Default is pipecd.dev/variant. - Key string `json:"key" default:"pipecd.dev/variant"` - // The label value for PRIMARY variant. - // Default is primary. - PrimaryValue string `json:"primaryValue" default:"primary"` - // The label value for CANARY variant. - // Default is canary. - CanaryValue string `json:"canaryValue" default:"canary"` - // The label value for BASELINE variant. - // Default is baseline. - BaselineValue string `json:"baselineValue" default:"baseline"` -} - -// KubernetesDeploymentInput represents needed input for triggering a Kubernetes deployment. -type KubernetesDeploymentInput struct { - // List of manifest files in the application directory used to deploy. - // Empty means all manifest files in the directory will be used. - Manifests []string `json:"manifests,omitempty"` - // Version of kubectl will be used. - KubectlVersion string `json:"kubectlVersion,omitempty"` - - // Version of kustomize will be used. - KustomizeVersion string `json:"kustomizeVersion,omitempty"` - // List of options that should be used by Kustomize commands. - KustomizeOptions map[string]string `json:"kustomizeOptions,omitempty"` - - // Version of helm will be used. - HelmVersion string `json:"helmVersion,omitempty"` - // Where to fetch helm chart. - HelmChart *InputHelmChart `json:"helmChart,omitempty"` - // Configurable parameters for helm commands. - HelmOptions *InputHelmOptions `json:"helmOptions,omitempty"` - - // The namespace where manifests will be applied. - Namespace string `json:"namespace,omitempty"` - - // Automatically reverts all deployment changes on failure. - // Default is true. - // - // Deprecated: Use Planner.AutoRollback instead. - AutoRollback *bool `json:"autoRollback,omitempty" default:"true"` - - // Automatically create a new namespace if it does not exist. - // Default is false. - AutoCreateNamespace bool `json:"autoCreateNamespace,omitempty"` -} - -type InputHelmChart struct { - // Git remote address where the chart is placing. - // Empty means the same repository. - GitRemote string `json:"gitRemote,omitempty"` - // The commit SHA or tag for remote git. - Ref string `json:"ref,omitempty"` - // Relative path from the repository root directory to the chart directory. - Path string `json:"path,omitempty"` - - // The name of an added Helm Chart Repository. - Repository string `json:"repository,omitempty"` - Name string `json:"name,omitempty"` - Version string `json:"version,omitempty"` - // Whether to skip TLS certificate checks for the repository or not. - // This option will automatically set the value of HelmChartRepository.Insecure. - Insecure bool `json:"-"` -} - -type InputHelmOptions struct { - // The release name of helm deployment. - // By default the release name is equal to the application name. - ReleaseName string `json:"releaseName,omitempty"` - // List of values. - SetValues map[string]string `json:"setValues,omitempty"` - // List of value files should be loaded. - ValueFiles []string `json:"valueFiles,omitempty"` - // List of file path for values. - SetFiles map[string]string `json:"setFiles,omitempty"` - // Set of supported Kubernetes API versions. - APIVersions []string `json:"apiVersions,omitempty"` - // Kubernetes version used for Capabilities.KubeVersion - KubeVersion string `json:"kubeVersion,omitempty"` -} - -type KubernetesTrafficRoutingMethod string - -const ( - KubernetesTrafficRoutingMethodPodSelector KubernetesTrafficRoutingMethod = "podselector" - KubernetesTrafficRoutingMethodIstio KubernetesTrafficRoutingMethod = "istio" - KubernetesTrafficRoutingMethodSMI KubernetesTrafficRoutingMethod = "smi" -) - -type KubernetesTrafficRouting struct { - Method KubernetesTrafficRoutingMethod `json:"method"` - Istio *IstioTrafficRouting `json:"istio"` -} - -// DetermineKubernetesTrafficRoutingMethod determines the routing method should be used based on the TrafficRouting config. -// The default is PodSelector: the way by updating the selector in Service to switching all of traffic. -func DetermineKubernetesTrafficRoutingMethod(cfg *KubernetesTrafficRouting) KubernetesTrafficRoutingMethod { - if cfg == nil { - return KubernetesTrafficRoutingMethodPodSelector - } - if cfg.Method == "" { - return KubernetesTrafficRoutingMethodPodSelector - } - return cfg.Method -} - -type IstioTrafficRouting struct { - // List of routes in the VirtualService that can be changed to update traffic routing. - // Empty means all routes should be updated. - EditableRoutes []string `json:"editableRoutes"` - // TODO: Add a validate to ensure this was configured or using the default value by service name. - // The service host. - Host string `json:"host"` - // The reference to VirtualService manifest. - // Empty means the first VirtualService resource will be used. - VirtualService K8sResourceReference `json:"virtualService"` -} - -type K8sResourceReference struct { - Kind string `json:"kind"` - Name string `json:"name"` -} - -// K8sSyncStageOptions contains all configurable values for a K8S_SYNC stage. -type K8sSyncStageOptions struct { - // Whether the PRIMARY variant label should be added to manifests if they were missing. - AddVariantLabelToSelector bool `json:"addVariantLabelToSelector"` - // Whether the resources that are no longer defined in Git should be removed or not. - Prune bool `json:"prune"` -} - -// K8sPrimaryRolloutStageOptions contains all configurable values for a K8S_PRIMARY_ROLLOUT stage. -type K8sPrimaryRolloutStageOptions struct { - // Suffix that should be used when naming the PRIMARY variant's resources. - // Default is "primary". - Suffix string `json:"suffix"` - // Whether the PRIMARY service should be created. - CreateService bool `json:"createService"` - // Whether the PRIMARY variant label should be added to manifests if they were missing. - AddVariantLabelToSelector bool `json:"addVariantLabelToSelector"` - // Whether the resources that are no longer defined in Git should be removed or not. - Prune bool `json:"prune"` -} - -// K8sCanaryRolloutStageOptions contains all configurable values for a K8S_CANARY_ROLLOUT stage. -type K8sCanaryRolloutStageOptions struct { - // How many pods for CANARY workloads. - // An integer value can be specified to indicate an absolute value of pod number. - // Or a string suffixed by "%" to indicate an percentage value compared to the pod number of PRIMARY. - // Default is 1 pod. - Replicas Replicas `json:"replicas"` - // Suffix that should be used when naming the CANARY variant's resources. - // Default is "canary". - Suffix string `json:"suffix"` - // Whether the CANARY service should be created. - CreateService bool `json:"createService"` - // List of patches used to customize manifests for CANARY variant. - Patches []K8sResourcePatch -} - -type K8sResourcePatch struct { - Target K8sResourcePatchTarget `json:"target"` - Ops []K8sResourcePatchOp `json:"ops"` -} - -type K8sResourcePatchTarget struct { - K8sResourceReference - // In case you want to manipulate the YAML or JSON data specified in a field - // of the manifest, specify that field's path. The string value of that field - // will be used as input for the patch operations. - // Otherwise, the whole manifest will be the target of patch operations. - DocumentRoot string `json:"documentRoot"` -} - -type K8sResourcePatchOpName string - -const ( - K8sResourcePatchOpYAMLReplace = "yaml-replace" -) - -type K8sResourcePatchOp struct { - // The operation type. - // This must be one of "yaml-replace", "yaml-add", "yaml-remove", "json-replace" or "text-regex". - // Default is "yaml-replace". - Op K8sResourcePatchOpName `json:"op" default:"yaml-replace"` - // The path string pointing to the manipulated field. - // E.g. "$.spec.foos[0].bar" - Path string `json:"path"` - // The value string whose content will be used as new value for the field. - Value string `json:"value"` -} - -// K8sCanaryCleanStageOptions contains all configurable values for a K8S_CANARY_CLEAN stage. -type K8sCanaryCleanStageOptions struct { -} - -// K8sBaselineRolloutStageOptions contains all configurable values for a K8S_BASELINE_ROLLOUT stage. -type K8sBaselineRolloutStageOptions struct { - // How many pods for BASELINE workloads. - // An integer value can be specified to indicate an absolute value of pod number. - // Or a string suffixed by "%" to indicate an percentage value compared to the pod number of PRIMARY. - // Default is 1 pod. - Replicas Replicas `json:"replicas"` - // Suffix that should be used when naming the BASELINE variant's resources. - // Default is "baseline". - Suffix string `json:"suffix"` - // Whether the BASELINE service should be created. - CreateService bool `json:"createService"` -} - -// K8sBaselineCleanStageOptions contains all configurable values for a K8S_BASELINE_CLEAN stage. -type K8sBaselineCleanStageOptions struct { -} - -// K8sTrafficRoutingStageOptions contains all configurable values for a K8S_TRAFFIC_ROUTING stage. -type K8sTrafficRoutingStageOptions struct { - // Which variant should receive all traffic. - // "primary" or "canary" or "baseline" can be populated. - All string `json:"all"` - // The percentage of traffic should be routed to PRIMARY variant. - Primary Percentage `json:"primary"` - // The percentage of traffic should be routed to CANARY variant. - Canary Percentage `json:"canary"` - // The percentage of traffic should be routed to BASELINE variant. - Baseline Percentage `json:"baseline"` -} - -func (opts K8sTrafficRoutingStageOptions) Percentages() (primary, canary, baseline int) { - switch opts.All { - case "primary": - primary = 100 - return - case "canary": - canary = 100 - return - case "baseline": - baseline = 100 - return - } - return opts.Primary.Int(), opts.Canary.Int(), opts.Baseline.Int() -} - -type KubernetesResourceRoute struct { - Provider KubernetesProviderMatcher `json:"provider"` - Match *KubernetesResourceRouteMatcher `json:"match"` -} - -type KubernetesResourceRouteMatcher struct { - Kind string `json:"kind"` - Name string `json:"name"` -} - -type KubernetesProviderMatcher struct { - Name string `json:"name"` - Labels map[string]string `json:"labels"` -} diff --git a/pkg/configv1/application_lambda.go b/pkg/configv1/application_lambda.go deleted file mode 100644 index 5106e9df51..0000000000 --- a/pkg/configv1/application_lambda.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2024 The PipeCD Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package config - -// LambdaApplicationSpec represents an application configuration for Lambda application. -type LambdaApplicationSpec struct { - GenericApplicationSpec - // Input for Lambda deployment such as where to fetch source code... - Input LambdaDeploymentInput `json:"input"` - // Configuration for quick sync. - QuickSync LambdaSyncStageOptions `json:"quickSync"` -} - -// Validate returns an error if any wrong configuration value was found. -func (s *LambdaApplicationSpec) Validate() error { - if err := s.GenericApplicationSpec.Validate(); err != nil { - return err - } - return nil -} - -type LambdaDeploymentInput struct { - // The name of service manifest file placing in application directory. - // Default is function.yaml - FunctionManifestFile string `json:"functionManifestFile" default:"function.yaml"` - // Automatically reverts all changes from all stages when one of them failed. - // Default is true. - // - // Deprecated: Use Planner.AutoRollback instead. - AutoRollback *bool `json:"autoRollback,omitempty" default:"true"` -} - -// LambdaSyncStageOptions contains all configurable values for a LAMBDA_SYNC stage. -type LambdaSyncStageOptions struct { -} - -// LambdaCanaryRolloutStageOptions contains all configurable values for a LAMBDA_CANARY_ROLLOUT stage. -type LambdaCanaryRolloutStageOptions struct { -} - -// LambdaPromoteStageOptions contains all configurable values for a LAMBDA_PROMOTE stage. -type LambdaPromoteStageOptions struct { - // Percentage of traffic should be routed to the new version. - Percent Percentage `json:"percent"` -} diff --git a/pkg/configv1/application_terraform.go b/pkg/configv1/application_terraform.go deleted file mode 100644 index f94d3f092b..0000000000 --- a/pkg/configv1/application_terraform.go +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2024 The PipeCD Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package config - -// TerraformApplicationSpec represents an application configuration for Terraform application. -type TerraformApplicationSpec struct { - GenericApplicationSpec - // Input for Terraform deployment such as terraform version, workspace... - Input TerraformDeploymentInput `json:"input"` - // Configuration for quick sync. - QuickSync TerraformApplyStageOptions `json:"quickSync"` -} - -// Validate returns an error if any wrong configuration value was found. -func (s *TerraformApplicationSpec) Validate() error { - if err := s.GenericApplicationSpec.Validate(); err != nil { - return err - } - return nil -} - -type TerraformDeploymentInput struct { - // The terraform workspace name. - // Empty means "default" workpsace. - Workspace string `json:"workspace,omitempty"` - // The version of terraform should be used. - // Empty means the pre-installed version will be used. - TerraformVersion string `json:"terraformVersion,omitempty"` - // List of variables that will be set directly on terraform commands with "-var" flag. - // The variable must be formatted by "key=value" as below: - // "image_id=ami-abc123" - // 'image_id_list=["ami-abc123","ami-def456"]' - // 'image_id_map={"us-east-1":"ami-abc123","us-east-2":"ami-def456"}' - Vars []string `json:"vars,omitempty"` - // List of variable files that will be set on terraform commands with "-var-file" flag. - VarFiles []string `json:"varFiles,omitempty"` - // Automatically reverts all changes from all stages when one of them failed. - // Default is false. - // - // Deprecated: Use Planner.AutoRollback instead. - AutoRollback bool `json:"autoRollback"` - // List of additional flags will be used while executing terraform commands. - CommandFlags TerraformCommandFlags `json:"commandFlags"` - // List of additional environment variables will be used while executing terraform commands. - CommandEnvs TerraformCommandEnvs `json:"commandEnvs"` -} - -// 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 { - // Exit the pipeline if the result is "No Changes" with success status. - ExitOnNoChanges bool `json:"exitOnNoChanges"` -} - -// 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"` -} - -// TerraformCommandFlags contains all additional flags will be used while executing terraform commands. -type TerraformCommandFlags struct { - Shared []string `json:"shared"` - Init []string `json:"init"` - Plan []string `json:"plan"` - Apply []string `json:"apply"` -} - -// TerraformCommandEnvs contains all additional environment variables will be used while executing terraform commands. -type TerraformCommandEnvs struct { - Shared []string `json:"shared"` - Init []string `json:"init"` - Plan []string `json:"plan"` - Apply []string `json:"apply"` -} diff --git a/pkg/configv1/application_test.go b/pkg/configv1/application_test.go index 1ab3e1afaa..440aa6b11a 100644 --- a/pkg/configv1/application_test.go +++ b/pkg/configv1/application_test.go @@ -24,6 +24,10 @@ import ( "github.com/pipe-cd/pipecd/pkg/model" ) +func newBoolPointer(b bool) *bool { + return &b +} + func TestHasStage(t *testing.T) { testcases := []struct { name string @@ -379,37 +383,26 @@ func TestGenericTriggerConfiguration(t *testing.T) { fileName: "testdata/application/generic-trigger.yaml", expectedKind: KindKubernetesApp, expectedAPIVersion: "pipecd.dev/v1beta1", - expectedSpec: &KubernetesApplicationSpec{ - GenericApplicationSpec: GenericApplicationSpec{ - Timeout: Duration(6 * time.Hour), - Trigger: Trigger{ - OnCommit: OnCommit{ - Disabled: false, - Paths: []string{ - "deployment.yaml", - }, - }, - OnOutOfSync: OnOutOfSync{ - Disabled: newBoolPointer(true), - MinWindow: Duration(5 * time.Minute), - }, - OnChain: OnChain{ - Disabled: newBoolPointer(true), + expectedSpec: &GenericApplicationSpec{ + Timeout: Duration(6 * time.Hour), + Trigger: Trigger{ + OnCommit: OnCommit{ + Disabled: false, + Paths: []string{ + "deployment.yaml", }, }, - Planner: DeploymentPlanner{ - AutoRollback: newBoolPointer(true), + OnOutOfSync: OnOutOfSync{ + Disabled: newBoolPointer(true), + MinWindow: Duration(5 * time.Minute), + }, + OnChain: OnChain{ + Disabled: newBoolPointer(true), }, }, - Input: KubernetesDeploymentInput{ + Planner: DeploymentPlanner{ AutoRollback: newBoolPointer(true), }, - VariantLabel: KubernetesVariantLabel{ - Key: "pipecd.dev/variant", - PrimaryValue: "primary", - BaselineValue: "baseline", - CanaryValue: "canary", - }, }, expectedError: nil, }, @@ -439,31 +432,20 @@ func TestTrueByDefaultBoolConfiguration(t *testing.T) { fileName: "testdata/application/truebydefaultbool-not-specified.yaml", expectedKind: KindKubernetesApp, expectedAPIVersion: "pipecd.dev/v1beta1", - expectedSpec: &KubernetesApplicationSpec{ - GenericApplicationSpec: GenericApplicationSpec{ - Timeout: Duration(6 * time.Hour), - Trigger: Trigger{ - OnOutOfSync: OnOutOfSync{ - Disabled: newBoolPointer(true), - MinWindow: Duration(5 * time.Minute), - }, - OnChain: OnChain{ - Disabled: newBoolPointer(true), - }, + expectedSpec: &GenericApplicationSpec{ + Timeout: Duration(6 * time.Hour), + Trigger: Trigger{ + OnOutOfSync: OnOutOfSync{ + Disabled: newBoolPointer(true), + MinWindow: Duration(5 * time.Minute), }, - Planner: DeploymentPlanner{ - AutoRollback: newBoolPointer(true), + OnChain: OnChain{ + Disabled: newBoolPointer(true), }, }, - Input: KubernetesDeploymentInput{ + Planner: DeploymentPlanner{ AutoRollback: newBoolPointer(true), }, - VariantLabel: KubernetesVariantLabel{ - Key: "pipecd.dev/variant", - PrimaryValue: "primary", - BaselineValue: "baseline", - CanaryValue: "canary", - }, }, expectedError: nil, }, @@ -471,30 +453,19 @@ func TestTrueByDefaultBoolConfiguration(t *testing.T) { fileName: "testdata/application/truebydefaultbool-false-explicitly.yaml", expectedKind: KindKubernetesApp, expectedAPIVersion: "pipecd.dev/v1beta1", - expectedSpec: &KubernetesApplicationSpec{ - GenericApplicationSpec: GenericApplicationSpec{ - Timeout: Duration(6 * time.Hour), - Trigger: Trigger{ - OnOutOfSync: OnOutOfSync{ - Disabled: newBoolPointer(false), - MinWindow: Duration(5 * time.Minute), - }, - OnChain: OnChain{ - Disabled: newBoolPointer(true), - }, + expectedSpec: &GenericApplicationSpec{ + Timeout: Duration(6 * time.Hour), + Trigger: Trigger{ + OnOutOfSync: OnOutOfSync{ + Disabled: newBoolPointer(false), + MinWindow: Duration(5 * time.Minute), }, - Planner: DeploymentPlanner{ - AutoRollback: newBoolPointer(true), + OnChain: OnChain{ + Disabled: newBoolPointer(true), }, }, - Input: KubernetesDeploymentInput{ - AutoRollback: newBoolPointer(false), - }, - VariantLabel: KubernetesVariantLabel{ - Key: "pipecd.dev/variant", - PrimaryValue: "primary", - BaselineValue: "baseline", - CanaryValue: "canary", + Planner: DeploymentPlanner{ + AutoRollback: newBoolPointer(true), }, }, expectedError: nil, @@ -503,31 +474,20 @@ func TestTrueByDefaultBoolConfiguration(t *testing.T) { fileName: "testdata/application/truebydefaultbool-true-explicitly.yaml", expectedKind: KindKubernetesApp, expectedAPIVersion: "pipecd.dev/v1beta1", - expectedSpec: &KubernetesApplicationSpec{ - GenericApplicationSpec: GenericApplicationSpec{ - Timeout: Duration(6 * time.Hour), - Trigger: Trigger{ - OnOutOfSync: OnOutOfSync{ - Disabled: newBoolPointer(true), - MinWindow: Duration(5 * time.Minute), - }, - OnChain: OnChain{ - Disabled: newBoolPointer(true), - }, + expectedSpec: &GenericApplicationSpec{ + Timeout: Duration(6 * time.Hour), + Trigger: Trigger{ + OnOutOfSync: OnOutOfSync{ + Disabled: newBoolPointer(true), + MinWindow: Duration(5 * time.Minute), }, - Planner: DeploymentPlanner{ - AutoRollback: newBoolPointer(true), + OnChain: OnChain{ + Disabled: newBoolPointer(true), }, }, - Input: KubernetesDeploymentInput{ + Planner: DeploymentPlanner{ AutoRollback: newBoolPointer(true), }, - VariantLabel: KubernetesVariantLabel{ - Key: "pipecd.dev/variant", - PrimaryValue: "primary", - BaselineValue: "baseline", - CanaryValue: "canary", - }, }, expectedError: nil, }, @@ -557,49 +517,38 @@ func TestGenericPostSyncConfiguration(t *testing.T) { fileName: "testdata/application/generic-postsync.yaml", expectedKind: KindKubernetesApp, expectedAPIVersion: "pipecd.dev/v1beta1", - expectedSpec: &KubernetesApplicationSpec{ - GenericApplicationSpec: GenericApplicationSpec{ - Timeout: Duration(6 * time.Hour), - Trigger: Trigger{ - OnOutOfSync: OnOutOfSync{ - Disabled: newBoolPointer(true), - MinWindow: Duration(5 * time.Minute), - }, - OnChain: OnChain{ - Disabled: newBoolPointer(true), - }, + expectedSpec: &GenericApplicationSpec{ + Timeout: Duration(6 * time.Hour), + Trigger: Trigger{ + OnOutOfSync: OnOutOfSync{ + Disabled: newBoolPointer(true), + MinWindow: Duration(5 * time.Minute), }, - Planner: DeploymentPlanner{ - AutoRollback: newBoolPointer(true), + OnChain: OnChain{ + Disabled: newBoolPointer(true), }, - PostSync: &PostSync{ - DeploymentChain: &DeploymentChain{ - ApplicationMatchers: []ChainApplicationMatcher{ - { - Name: "app-1", - }, - { - Labels: map[string]string{ - "env": "staging", - "foo": "bar", - }, - }, - { - Kind: "ECSApp", + }, + Planner: DeploymentPlanner{ + AutoRollback: newBoolPointer(true), + }, + PostSync: &PostSync{ + DeploymentChain: &DeploymentChain{ + ApplicationMatchers: []ChainApplicationMatcher{ + { + Name: "app-1", + }, + { + Labels: map[string]string{ + "env": "staging", + "foo": "bar", }, }, + { + Kind: "ECSApp", + }, }, }, }, - Input: KubernetesDeploymentInput{ - AutoRollback: newBoolPointer(true), - }, - VariantLabel: KubernetesVariantLabel{ - Key: "pipecd.dev/variant", - PrimaryValue: "primary", - BaselineValue: "baseline", - CanaryValue: "canary", - }, }, expectedError: nil, }, @@ -616,32 +565,3 @@ func TestGenericPostSyncConfiguration(t *testing.T) { }) } } - -func TestScriptSycConfiguration(t *testing.T) { - testcases := []struct { - name string - opts ScriptRunStageOptions - wantErr bool - }{ - { - name: "valid", - opts: ScriptRunStageOptions{ - Run: "echo 'hello world'", - }, - wantErr: false, - }, - { - name: "invalid", - opts: ScriptRunStageOptions{ - Run: "", - }, - wantErr: true, - }, - } - for _, tc := range testcases { - t.Run(tc.name, func(t *testing.T) { - err := tc.opts.Validate() - assert.Equal(t, tc.wantErr, err != nil) - }) - } -} diff --git a/pkg/configv1/config.go b/pkg/configv1/config.go index 5fe663744a..f455fbd1e6 100644 --- a/pkg/configv1/config.go +++ b/pkg/configv1/config.go @@ -23,8 +23,6 @@ import ( "github.com/creasty/defaults" "sigs.k8s.io/yaml" - - "github.com/pipe-cd/pipecd/pkg/model" ) const ( @@ -39,15 +37,25 @@ const ( // KindKubernetesApp represents application configuration for a Kubernetes application. // This application can be a group of plain-YAML Kubernetes manifests, // or kustomization manifests or helm manifests. + // + // Deprecated: use KindApplication instead. KindKubernetesApp Kind = "KubernetesApp" // KindTerraformApp represents application configuration for a Terraform application. // This application contains a single workspace of a terraform root module. + // + // Deprecated: use KindApplication instead. KindTerraformApp Kind = "TerraformApp" // KindLambdaApp represents application configuration for an AWS Lambda application. + // + // Deprecated: use KindApplication instead. KindLambdaApp Kind = "LambdaApp" // KindCloudRunApp represents application configuration for a CloudRun application. + // + // Deprecated: use KindApplication instead. KindCloudRunApp Kind = "CloudRunApp" // KindECSApp represents application configuration for an AWS ECS. + // + // Deprecated: use KindApplication instead. KindECSApp Kind = "ECSApp" // KindApplication represents a generic application configuration. KindApplication Kind = "Application" @@ -80,13 +88,6 @@ type Config struct { ApplicationSpec *GenericApplicationSpec - // TODO: remove these fields - KubernetesApplicationSpec *KubernetesApplicationSpec - TerraformApplicationSpec *TerraformApplicationSpec - CloudRunApplicationSpec *CloudRunApplicationSpec - LambdaApplicationSpec *LambdaApplicationSpec - ECSApplicationSpec *ECSApplicationSpec - PipedSpec *PipedSpec ControlPlaneSpec *ControlPlaneSpec AnalysisTemplateSpec *AnalysisTemplateSpec @@ -104,30 +105,10 @@ func (c *Config) init(kind Kind, apiVersion string) error { c.APIVersion = apiVersion switch kind { - case KindApplication: + case KindApplication, KindKubernetesApp, KindTerraformApp, KindCloudRunApp, KindLambdaApp, KindECSApp: c.ApplicationSpec = &GenericApplicationSpec{} c.spec = c.ApplicationSpec - case KindKubernetesApp: - c.KubernetesApplicationSpec = &KubernetesApplicationSpec{} - c.spec = c.KubernetesApplicationSpec - - case KindTerraformApp: - c.TerraformApplicationSpec = &TerraformApplicationSpec{} - c.spec = c.TerraformApplicationSpec - - case KindCloudRunApp: - c.CloudRunApplicationSpec = &CloudRunApplicationSpec{} - c.spec = c.CloudRunApplicationSpec - - case KindLambdaApp: - c.LambdaApplicationSpec = &LambdaApplicationSpec{} - c.spec = c.LambdaApplicationSpec - - case KindECSApp: - c.ECSApplicationSpec = &ECSApplicationSpec{} - c.spec = c.ECSApplicationSpec - case KindPiped: c.PipedSpec = &PipedSpec{} c.spec = c.PipedSpec @@ -229,38 +210,3 @@ func DecodeYAML(data []byte) (*Config, error) { } return c, nil } - -// ToApplicationKind converts configuration kind to application kind. -func (k Kind) ToApplicationKind() (model.ApplicationKind, bool) { - switch k { - case KindKubernetesApp: - return model.ApplicationKind_KUBERNETES, true - case KindTerraformApp: - return model.ApplicationKind_TERRAFORM, true - case KindLambdaApp: - return model.ApplicationKind_LAMBDA, true - case KindCloudRunApp: - return model.ApplicationKind_CLOUDRUN, true - case KindECSApp: - return model.ApplicationKind_ECS, true - } - return model.ApplicationKind_KUBERNETES, false -} - -func (c *Config) GetGenericApplication() (GenericApplicationSpec, bool) { - switch c.Kind { - case KindApplication: - return *c.ApplicationSpec, true - case KindKubernetesApp: - return c.KubernetesApplicationSpec.GenericApplicationSpec, true - case KindTerraformApp: - return c.TerraformApplicationSpec.GenericApplicationSpec, true - case KindCloudRunApp: - return c.CloudRunApplicationSpec.GenericApplicationSpec, true - case KindLambdaApp: - return c.LambdaApplicationSpec.GenericApplicationSpec, true - case KindECSApp: - return c.ECSApplicationSpec.GenericApplicationSpec, true - } - return GenericApplicationSpec{}, false -} diff --git a/pkg/configv1/config_test.go b/pkg/configv1/config_test.go deleted file mode 100644 index 0cfc80b5ae..0000000000 --- a/pkg/configv1/config_test.go +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2024 The PipeCD Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package config - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/pipe-cd/pipecd/pkg/model" -) - -func TestUnmarshalConfig(t *testing.T) { - testcases := []struct { - name string - data string - wantSpec interface{} - wantErr bool - }{ - { - name: "correct config for KubernetesApp", - data: `{ - "apiVersion": "pipecd.dev/v1beta1", - "kind": "KubernetesApp", - "spec": { - "input": { - "namespace": "default" - } - } -}`, - wantSpec: &KubernetesApplicationSpec{ - Input: KubernetesDeploymentInput{ - Namespace: "default", - }, - }, - wantErr: false, - }, - { - name: "config for KubernetesApp with unknown field", - data: `{ - "apiVersion": "pipecd.dev/v1beta1", - "kind": "KubernetesApp", - "spec": { - "input": { - "namespace": "default" - }, - "unknown": {} - } -}`, - wantSpec: &KubernetesApplicationSpec{ - Input: KubernetesDeploymentInput{ - Namespace: "default", - }, - }, - wantErr: true, - }, - } - for _, tc := range testcases { - t.Run(tc.name, func(t *testing.T) { - var got Config - err := json.Unmarshal([]byte(tc.data), &got) - assert.Equal(t, tc.wantErr, err != nil) - assert.Equal(t, tc.wantSpec, got.spec) - }) - } -} - -func newBoolPointer(v bool) *bool { - return &v -} - -func TestKind_ToApplicationKind(t *testing.T) { - testcases := []struct { - name string - k Kind - want model.ApplicationKind - wantOk bool - }{ - { - name: "App config", - k: KindKubernetesApp, - want: model.ApplicationKind_KUBERNETES, - wantOk: true, - }, - { - name: "Not an app config", - k: KindPiped, - want: model.ApplicationKind_KUBERNETES, - wantOk: false, - }, - } - for _, tc := range testcases { - t.Run(tc.name, func(t *testing.T) { - got, gotOk := tc.k.ToApplicationKind() - assert.Equal(t, tc.want, got) - assert.Equal(t, tc.wantOk, gotOk) - }) - } -} diff --git a/pkg/configv1/testdata/application/cloudrun-app-bluegreen.yaml b/pkg/configv1/testdata/application/cloudrun-app-bluegreen.yaml deleted file mode 100644 index d5faee008f..0000000000 --- a/pkg/configv1/testdata/application/cloudrun-app-bluegreen.yaml +++ /dev/null @@ -1,21 +0,0 @@ -# https://cloud.google.com/run/docs/rollouts-rollbacks-traffic-migration -apiVersion: pipecd.dev/v1beta1 -kind: CloudRunApp -spec: - input: - image: gcr.io/demo-project/demoapp:v1.0.0 - pipeline: - stages: - # Deploy workloads of the new version. - # But this is still receiving no traffic. - - name: CLOUDRUN_PROMOTE - # 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_PROMOTE - with: - 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. - - name: ANALYSIS diff --git a/pkg/configv1/testdata/application/cloudrun-app-canary.yaml b/pkg/configv1/testdata/application/cloudrun-app-canary.yaml deleted file mode 100644 index 0e2d8ff50a..0000000000 --- a/pkg/configv1/testdata/application/cloudrun-app-canary.yaml +++ /dev/null @@ -1,26 +0,0 @@ -# https://cloud.google.com/run/docs/rollouts-rollbacks-traffic-migration -apiVersion: pipecd.dev/v1beta1 -kind: CloudRunApp -spec: - input: - image: gcr.io/demo-project/demoapp:v1.0.0 - pipeline: - stages: - # Deploy workloads of the new version. - # But this is still receiving no traffic. - - name: CLOUDRUN_PROMOTE - # 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_PROMOTE - with: - 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. - - name: ANALYSIS - # Change the traffic routing state where - # thre new version will receive 100% of the traffic. - - name: CLOUDRUN_PROMOTE - with: - canary: 100 diff --git a/pkg/configv1/testdata/application/cloudrun-app.yaml b/pkg/configv1/testdata/application/cloudrun-app.yaml deleted file mode 100644 index ce274c98fc..0000000000 --- a/pkg/configv1/testdata/application/cloudrun-app.yaml +++ /dev/null @@ -1,2 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: CloudRunApp diff --git a/pkg/configv1/testdata/application/custom-sync-without-run.yaml b/pkg/configv1/testdata/application/custom-sync-without-run.yaml deleted file mode 100644 index 3f9fcdc61d..0000000000 --- a/pkg/configv1/testdata/application/custom-sync-without-run.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: LambdaApp -spec: - pipeline: - stages: - - name: CUSTOM_SYNC - desc: "deploy by sam" - with: - timeout: 6h - envs: - AWS_PROFILE: default diff --git a/pkg/configv1/testdata/application/custom-sync.yaml b/pkg/configv1/testdata/application/custom-sync.yaml deleted file mode 100644 index 8d65a8e1fa..0000000000 --- a/pkg/configv1/testdata/application/custom-sync.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: LambdaApp -spec: - pipeline: - stages: - - name: CUSTOM_SYNC - desc: "deploy by sam" - with: - timeout: 6h - envs: - AWS_PROFILE: default - run: | - sam build - sam deploy -g --profile $AWS_PROFILE diff --git a/pkg/configv1/testdata/application/ecs-app-invalid-access-type.yaml b/pkg/configv1/testdata/application/ecs-app-invalid-access-type.yaml deleted file mode 100644 index 4f41eb974e..0000000000 --- a/pkg/configv1/testdata/application/ecs-app-invalid-access-type.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: ECSApp -spec: - input: - serviceDefinitionFile: /path/to/servicedef.yaml - taskDefinitionFile: /path/to/taskdef.yaml - accessType: XXX \ No newline at end of file diff --git a/pkg/configv1/testdata/application/ecs-app-service-discovery.yaml b/pkg/configv1/testdata/application/ecs-app-service-discovery.yaml deleted file mode 100644 index cc9da20611..0000000000 --- a/pkg/configv1/testdata/application/ecs-app-service-discovery.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: ECSApp -spec: - input: - serviceDefinitionFile: /path/to/servicedef.yaml - taskDefinitionFile: /path/to/taskdef.yaml - accessType: SERVICE_DISCOVERY \ No newline at end of file diff --git a/pkg/configv1/testdata/application/ecs-app.yaml b/pkg/configv1/testdata/application/ecs-app.yaml deleted file mode 100644 index 95f8b3f1ce..0000000000 --- a/pkg/configv1/testdata/application/ecs-app.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: ECSApp -spec: - input: - serviceDefinitionFile: /path/to/servicedef.yaml - taskDefinitionFile: /path/to/taskdef.yaml - targetGroups: - primary: - targetGroupArn: arn:aws:elasticloadbalancing:xyz - containerName: web - containerPort: 80 diff --git a/pkg/configv1/testdata/application/k8s-app-bluegreen-with-analysis.yaml b/pkg/configv1/testdata/application/k8s-app-bluegreen-with-analysis.yaml deleted file mode 100644 index 006b3a353d..0000000000 --- a/pkg/configv1/testdata/application/k8s-app-bluegreen-with-analysis.yaml +++ /dev/null @@ -1,28 +0,0 @@ -# Pipeline for a Kubernetes application. -# This makes a progressive delivery with BlueGreen strategy. -# This also has a ANALYSIS stage for running smoke test againts the stage. -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - stages: - - name: K8S_CANARY_ROLLOUT - with: - replicas: 100% - - name: ANALYSIS - with: - duration: 10m - failureLimit: 2 - https: - - template: - name: http_stage_check - - name: K8S_TRAFFIC_ROUTING - with: - all: canary - - name: K8S_PRIMARY_ROLLOUT - - name: K8S_TRAFFIC_ROUTING - with: - all: primary - - name: K8S_CANARY_CLEAN - trafficRouting: - method: pod diff --git a/pkg/configv1/testdata/application/k8s-app-bluegreen.yaml b/pkg/configv1/testdata/application/k8s-app-bluegreen.yaml deleted file mode 100644 index 8f6d2b1c3b..0000000000 --- a/pkg/configv1/testdata/application/k8s-app-bluegreen.yaml +++ /dev/null @@ -1,28 +0,0 @@ -# Pipeline for a Kubernetes application. -# This makes a progressive delivery with BlueGreen strategy. -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - description: | - application description first string - application description second string - planner: - alwaysUsePipeline: true - trigger: - onOutOfSync: - disabled: true - pipeline: - stages: - - name: K8S_CANARY_ROLLOUT - with: - replicas: 100% - - name: K8S_TRAFFIC_ROUTING - with: - canary: 100 - - name: K8S_PRIMARY_ROLLOUT - - name: K8S_TRAFFIC_ROUTING - with: - primary: 100 - - name: K8S_CANARY_CLEAN - trafficRouting: - method: podselector diff --git a/pkg/configv1/testdata/application/k8s-app-canary.yaml b/pkg/configv1/testdata/application/k8s-app-canary.yaml deleted file mode 100644 index a244944114..0000000000 --- a/pkg/configv1/testdata/application/k8s-app-canary.yaml +++ /dev/null @@ -1,298 +0,0 @@ -# Progressive delivery with canary strategy. -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - stages: - # Deploy the workloads of CANARY variant. In this case, the number of - # workload replicas of CANARY variant is 10% of the replicas number of PRIMARY variant. - - name: K8S_CANARY_ROLLOUT - with: - replicas: 10% - # Update the workload of PRIMARY variant to the new version. - - name: K8S_PRIMARY_ROLLOUT - # Destroy all workloads of CANARY variant. - - name: K8S_CANARY_CLEAN - ---- -# Progressive delivery with canary strategy. -# This also adds an Approval stage to wait until got -# an approval from one of the specified approvers. -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - stages: - - name: K8S_CANARY_ROLLOUT - with: - replicas: 2 - - name: WAIT_APPROVAL - with: - approvers: - - user-foo - - user-bar - - name: K8S_PRIMARY_ROLLOUT - - name: K8S_CANARY_CLEAN - ---- -# Progressive delivery with canary strategy. -# This has an Analysis stage for verifying the deployment process. -# The analysis is just based on the metrics, log, http response from canary version. -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - stages: - - name: K8S_CANARY_ROLLOUT - with: - replicas: 10% - - name: ANALYSIS - with: - duration: 10m - metrics: - - query: grpc_error_percentage - expected: - max: 0.1 - interval: 1m - failureLimit: 1 - provider: prometheus-dev - logs: - - query: | - resource.type="k8s_container" - resource.labels.cluster_name="cluster-1" - resource.labels.namespace_name="stg" - resource.labels.pod_id="pod1" - interval: 1m - failureLimit: 3 - provider: stackdriver-dev - https: - - url: https://canary-endpoint.dev - method: GET - expectedCode: 200 - failureLimit: 1 - interval: 1m - - name: K8S_PRIMARY_ROLLOUT - - name: K8S_CANARY_CLEAN - ---- -# Progressive delivery with canary strategy. -# The canary process has multiple phases: from 10% then analysis -# then up to 20% then analysis then 100%. -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - stages: - - name: K8S_CANARY_ROLLOUT - with: - replicas: 10% - - name: ANALYSIS - with: - duration: 10m - - name: K8S_CANARY_ROLLOUT - with: - replicas: 20% - - name: ANALYSIS - with: - duration: 10m - - name: K8S_PRIMARY_ROLLOUT - - name: K8S_CANARY_CLEAN - ---- -# Progressive delivery with canary strategy. -# This has an Analysis stage for verifying the deployment process. -# The analysis stage is configured to use metrics templates at .pipe directory. -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - stages: - - name: K8S_CANARY_ROLLOUT - with: - replicas: 10% - - name: ANALYSIS - with: - duration: 10m - metrics: - - template: - name: prometheus_grpc_error_percentage - - template: - name: prometheus_grpc_error_percentage - logs: - - template: - name: stackdriver_log_error - https: - - template: - name: http_canary_check - - name: K8S_PRIMARY_ROLLOUT - - name: K8S_CANARY_CLEAN - ---- -# Progressive delivery with canary strategy. -# This has an Analysis stage for verifying the deployment process. -# The analysis stage is configured to use metrics with custom args. -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - stages: - - name: K8S_CANARY_ROLLOUT - with: - replicas: 10% - - name: ANALYSIS - with: - duration: 10m - metrics: - - template: - name: grpc_error_rate_percentage - args: - namespace: default - - name: K8S_PRIMARY_ROLLOUT - - name: K8S_CANARY_CLEAN - ---- -# Canary deployment that has an analysis stage to verify canary. -# This deploys both canary and baseline version. -# The baseline pod is a pod that is based on our currently running production version. -# We want to collect metrics against a “new” copy of our old container so -# we don’t muddy the waters testing against a pod that might have been running for a long time. -# The analysis stage is based on the comparision between baseline and stage workloads. -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - stages: - - name: K8S_BASELINE_ROLLOUT - with: - replicas: 10% - - name: K8S_CANARY_ROLLOUT - with: - replicas: 10% - - name: ANALYSIS - with: - duration: 10m - - name: K8S_PRIMARY_ROLLOUT - - name: K8S_BASELINE_CLEAN - - name: K8S_CANARY_CLEAN - -# Progressive delivery with canary strategy. -# This has an Analysis stage for verifying the deployment process. -# This is run the analysis with dynamic data as well as one with static data. -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - stages: - - name: K8S_CANARY_ROLLOUT - with: - replicas: 10% - - name: ANALYSIS - with: - duration: 10m - metrics: - - template: - name: prometheus_grpc_error_percentage - logs: - - template: - name: stackdriver_log_error - https: - - template: - name: http_canary_check - dynamic: - metrics: - - query: grpc_error_percentage - provider: prometheus-dev - #sensitivity: SENSITIVE - logs: - - query: | - resource.type="k8s_container" - resource.labels.cluster_name="cluster-1" - resource.labels.namespace_name="stg" - provider: stackdriver-dev - https: - - url: https://canary-endpoint.dev - method: GET - expectedCode: 200 - interval: 1m - - name: K8S_PRIMARY_ROLLOUT - - name: K8S_CANARY_CLEAN - -# Stage represents a temporary desired state for the application. -# Users can declarative a list of stages to archive the final desired state. -# This is a pod that is based on our currently running production version. -# We want to collect metrics against a “new” copy of our old container so -# we don’t muddy the waters testing against a pod that might have been running for a long time. -# https://www.spinnaker.io/guides/user/canary/best-practices/#compare-canary-against-baseline-not-against-production -# K8S_BASELINE_ROLLOUT - -# Requirements: -# Multiple canary stages -# Automated analysis -# - between baseline and canary -# - based on metrics, logs of only canary -# Various targets: deployment, daemonset, statefulset - -# # List of deployments for the same commit -# # that must be succeeded before running the deployment for this application. -# requireDeployments: -# - app: demoapp -# env: dev -# - app: anotherapp -# # Make a pull request to promote other applicationzwww -# # (or promote changes through environments of the same application) -# # after the success of this deployment. -# promote: -# - app: demoapp -# env: prod -# transforms: -# - source: pipe.yaml -# destination: pipe.yaml -# regex: git@github.com:org/config-repo.git:charts/demoapp?ref=(.*) -# replacement: git@github.com:org/config-repo.git:charts/demoapp?ref={{ $1 }} -# pullRequest: -# title: Update demoapp service in prod -# commit: Update demo app service in prod -# desc: | -# Update demoapp service to {{ .App.Input.Version }} - ---- -# Progressive delivery with canary strategy. -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - stages: - - name: K8S_CANARY_ROLLOUT - with: - replicas: 10% - patches: - - target: - kind: ConfigMap - name: envoy-config - documentRoot: $.data.envoy-config - yamlOps: - - op: replace - path: $.resources[0].virtual_hosts[0].routes[0].route.weighted_clusters.clusters[0].weight - value: 50 - - op: replace - path: $.resources[0].virtual_hosts[0].routes[0].route.weighted_clusters.clusters[1].weight - value: 50 - - - name: K8S_CANARY_ROLLOUT - with: - replicas: 10% - patches: - - target: - kind: ConfigMap - name: envoy-config - documentRoot: $.data.envoy-config - yamlOps: - - op: replace - path: $.resources[0].virtual_hosts[0].routes[0].route.weighted_clusters.clusters[0].weight - value: 10 - - op: replace - path: $.resources[0].virtual_hosts[0].routes[0].route.weighted_clusters.clusters[1].weight - value: 90 - - - name: K8S_PRIMARY_ROLLOUT - - name: K8S_CANARY_CLEAN diff --git a/pkg/configv1/testdata/application/k8s-app-envoy-bluegreen.yaml b/pkg/configv1/testdata/application/k8s-app-envoy-bluegreen.yaml deleted file mode 100644 index e90a8c8041..0000000000 --- a/pkg/configv1/testdata/application/k8s-app-envoy-bluegreen.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - stages: - - name: K8S_CANARY_ROLLOUT - with: - replicas: 100% - - name: K8S_TRAFFIC_ROUTING - with: - all: canary - - name: K8S_PRIMARY_ROLLOUT - - name: K8S_TRAFFIC_ROUTING - with: - all: primary - - name: K8S_CANARY_CLEAN diff --git a/pkg/configv1/testdata/application/k8s-app-envoy-canary.yaml b/pkg/configv1/testdata/application/k8s-app-envoy-canary.yaml deleted file mode 100644 index 6d0dc734ed..0000000000 --- a/pkg/configv1/testdata/application/k8s-app-envoy-canary.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - stages: - - name: K8S_CANARY_ROLLOUT - with: - replicas: 10% - - name: K8S_TRAFFIC_ROUTING - with: - canary: 10 - - name: K8S_PRIMARY_ROLLOUT - - name: K8S_TRAFFIC_ROUTING - with: - primary: 100 - - name: K8S_CANARY_CLEAN diff --git a/pkg/configv1/testdata/application/k8s-app-helm.yaml b/pkg/configv1/testdata/application/k8s-app-helm.yaml deleted file mode 100644 index 92569a6fe7..0000000000 --- a/pkg/configv1/testdata/application/k8s-app-helm.yaml +++ /dev/null @@ -1,38 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - input: - # Helm chart sourced from current Git repo. - helmChart: - path: charts/demoapp - helmValueFiles: - - values.yaml - helmVersion: 3.1.1 - ---- -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - input: - # Helm chart sourced from another Git repo. - helmChart: - git: git@github.com:org/chart-repo.git - path: charts/demoapp - ref: v1.0.0 - helmValueFiles: - - values.yaml - helmVersion: 3.1.1 - ---- -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - input: - # Helm chart sourced from a Helm repository. - helmChart: - repository: https://helm.com/stable - name: demoapp - version: 1.0.0 - helmValueFiles: - - values.yaml - helmVersion: 3.1.1 diff --git a/pkg/configv1/testdata/application/k8s-app-istio-bluegreen.yaml b/pkg/configv1/testdata/application/k8s-app-istio-bluegreen.yaml deleted file mode 100644 index 0655b3a509..0000000000 --- a/pkg/configv1/testdata/application/k8s-app-istio-bluegreen.yaml +++ /dev/null @@ -1,41 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - stages: - # Deploy the workloads of CANARY variant. In this case, the number of - # workload replicas of CANARY variant is the same with PRIMARY variant. - - name: K8S_CANARY_ROLLOUT - with: - replicas: 100% - # The percentage of traffic each variant should receive. - # In this case, CANARY variant will receive all of the traffic. - - name: K8S_TRAFFIC_ROUTING - with: - all: canary - # Update the workload of PRIMARY variant to the new version. - - name: K8S_PRIMARY_ROLLOUT - # The percentage of traffic each variant should receive. - # In this case, PRIMARY variant will receive all of the traffic. - - name: K8S_TRAFFIC_ROUTING - with: - all: primary - # Destroy all workloads of CANARY variant. - - name: K8S_CANARY_CLEAN - # Specify application service. - service: - name: demoapp - # Specify application workloads. - workloads: - - name: demoapp - # Configuration for CANARY variant. - canaryVariant: - suffix: canary - createService: true - # Configuration for BASELINE variant. - baselineVariant: - suffix: baseline - createService: true - # Configuration for traffic splitting. - trafficRouting: - method: istio # pod (change label in service to switch traffic), smi, envoy diff --git a/pkg/configv1/testdata/application/k8s-app-istio-canary.yaml b/pkg/configv1/testdata/application/k8s-app-istio-canary.yaml deleted file mode 100644 index 109ad87927..0000000000 --- a/pkg/configv1/testdata/application/k8s-app-istio-canary.yaml +++ /dev/null @@ -1,56 +0,0 @@ -# Progressive delivery with canary strategy. -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - stages: - # Deploy the workloads of CANARY variant. In this case, the number of - # workload replicas of CANARY variant is 10% of the replicas number of PRIMARY variant. - - name: K8S_CANARY_ROLLOUT - with: - replicas: 10% - # The percentage of traffic each variant should receive. - # In this case, CANARY variant will receive 10% of traffic, - # while PRIMARY will receive 90% of traffic. - - name: K8S_TRAFFIC_ROUTING - with: - canary: 10 - # Update the workload of PRIMARY variant to the new version. - - name: K8S_PRIMARY_ROLLOUT - # The percentage of traffic each variant should receive. - # In this case, PRIMARY variant will receive all of the traffic. - - name: K8S_TRAFFIC_ROUTING - with: - primary: 100 - # Destroy all workloads of CANARY variant. - - name: K8S_CANARY_CLEAN - ---- -# Progressive delivery with canary strategy. -# The canary process has multiple phases: from 10% then analysis -# then up to 20% then analysis then 100%. -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - stages: - - name: K8S_CANARY_ROLLOUT - with: - replicas: 20% - - name: K8S_TRAFFIC_ROUTING - with: - canary: 10 - - name: ANALYSIS - with: - duration: 10m - - name: K8S_TRAFFIC_ROUTING - with: - canary: 20 - - name: ANALYSIS - with: - duration: 10m - - name: K8S_PRIMARY_ROLLOUT - - name: K8S_TRAFFIC_ROUTING - with: - primary: 100 - - name: K8S_CANARY_CLEAN diff --git a/pkg/configv1/testdata/application/k8s-app-kustomization.yaml b/pkg/configv1/testdata/application/k8s-app-kustomization.yaml deleted file mode 100644 index 7632fa0a91..0000000000 --- a/pkg/configv1/testdata/application/k8s-app-kustomization.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - input: - kubectlVersion: 3.1.1 diff --git a/pkg/configv1/testdata/application/k8s-app-resource-route.yaml b/pkg/configv1/testdata/application/k8s-app-resource-route.yaml deleted file mode 100644 index 38479dafd7..0000000000 --- a/pkg/configv1/testdata/application/k8s-app-resource-route.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - resourceRoutes: - - match: - kind: Ingress - provider: - name: ConfigCluster - - match: - kind: Service - name: Foo - provider: - name: ConfigCluster - - provider: - labels: - group: workload diff --git a/pkg/configv1/testdata/application/k8s-app-use-pipeline-template.yaml b/pkg/configv1/testdata/application/k8s-app-use-pipeline-template.yaml deleted file mode 100644 index ad409367e4..0000000000 --- a/pkg/configv1/testdata/application/k8s-app-use-pipeline-template.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - pipeline: - useTemplate: k8s-canary-with-analysis diff --git a/pkg/configv1/testdata/application/k8s-plain-yaml.yaml b/pkg/configv1/testdata/application/k8s-plain-yaml.yaml deleted file mode 100644 index f7b99f70b4..0000000000 --- a/pkg/configv1/testdata/application/k8s-plain-yaml.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - input: - manifests: - - demoapp-deployment.yaml - kubectlVersion: 2.1.1 - sealedSecrets: - - path: sealed-secret.yaml diff --git a/pkg/configv1/testdata/application/lambda-app-bluegreen.yaml b/pkg/configv1/testdata/application/lambda-app-bluegreen.yaml deleted file mode 100644 index faed917016..0000000000 --- a/pkg/configv1/testdata/application/lambda-app-bluegreen.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# Using version, alias, additional version to do canary, bluegreen. -# https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html -apiVersion: pipecd.dev/v1beta1 -kind: LambdaApp -spec: - pipeline: - stages: - # Deploy workloads of the new version. - # But this is still receiving no traffic. - - 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_PROMOTE - with: - percent: 100 diff --git a/pkg/configv1/testdata/application/lambda-app-canary.yaml b/pkg/configv1/testdata/application/lambda-app-canary.yaml deleted file mode 100644 index 4f581ad867..0000000000 --- a/pkg/configv1/testdata/application/lambda-app-canary.yaml +++ /dev/null @@ -1,21 +0,0 @@ -# Using version, alias, additional version to do canary, bluegreen. -# https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html -apiVersion: pipecd.dev/v1beta1 -kind: LambdaApp -spec: - pipeline: - stages: - # Deploy workloads of the new version. - # But this is still receiving no traffic. - - 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_PROMOTE - with: - percent: 10 - # Change the traffic routing state where - # thre new version will receive 100% of the traffic. - - name: LAMBDA_PROMOTE - with: - percent: 100 diff --git a/pkg/configv1/testdata/application/lambda-app.yaml b/pkg/configv1/testdata/application/lambda-app.yaml deleted file mode 100644 index 34c9394f08..0000000000 --- a/pkg/configv1/testdata/application/lambda-app.yaml +++ /dev/null @@ -1,2 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: LambdaApp diff --git a/pkg/configv1/testdata/application/terraform-app-empty.yaml b/pkg/configv1/testdata/application/terraform-app-empty.yaml deleted file mode 100644 index 105b69b066..0000000000 --- a/pkg/configv1/testdata/application/terraform-app-empty.yaml +++ /dev/null @@ -1,2 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: TerraformApp diff --git a/pkg/configv1/testdata/application/terraform-app-secret-management.yaml b/pkg/configv1/testdata/application/terraform-app-secret-management.yaml deleted file mode 100644 index d14876e383..0000000000 --- a/pkg/configv1/testdata/application/terraform-app-secret-management.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: TerraformApp -spec: - input: - workspace: dev - terraformVersion: 0.12.23 - trigger: - onOutOfSync: - disabled: false - encryption: - encryptedSecrets: - serviceAccount: ENCRYPTED_DATA_GENERATED_FROM_WEB - decryptionTargets: - - service-account.yaml diff --git a/pkg/configv1/testdata/application/terraform-app-with-approval.yaml b/pkg/configv1/testdata/application/terraform-app-with-approval.yaml deleted file mode 100644 index 23c638ce99..0000000000 --- a/pkg/configv1/testdata/application/terraform-app-with-approval.yaml +++ /dev/null @@ -1,37 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: TerraformApp -spec: - input: - workspace: dev - terraformVersion: 0.12.23 - pipeline: - stages: - - name: TERRAFORM_PLAN - - name: WAIT_APPROVAL - with: - approvers: - - foo - - bar - - name: TERRAFORM_APPLY - -#--- -# apiVersion: pipecd.dev/v1beta1 -# kind: TerraformApp -# spec: -# input: -# terraformVersion: 0.12.23 -# pipeline: -# stages: -# - name: TERRAFORM_PLAN -# with: -# workspace: dev -# - name: TERRAFORM_APPLY -# with: -# workspace: dev -# - name: WAIT_APPROVAL -# - name: TERRAFORM_PLAN -# with: -# workspace: prod -# - name: TERRAFORM_APPLY -# with: -# workspace: prod diff --git a/pkg/configv1/testdata/application/terraform-app-with-exit.yaml b/pkg/configv1/testdata/application/terraform-app-with-exit.yaml deleted file mode 100644 index 194643c12f..0000000000 --- a/pkg/configv1/testdata/application/terraform-app-with-exit.yaml +++ /dev/null @@ -1,39 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: TerraformApp -spec: - input: - workspace: dev - terraformVersion: 0.12.23 - pipeline: - stages: - - name: TERRAFORM_PLAN - with: - exitOnNoChanges: true - - name: WAIT_APPROVAL - with: - approvers: - - foo - - bar - - name: TERRAFORM_APPLY - -#--- -# apiVersion: pipecd.dev/v1beta1 -# kind: TerraformApp -# spec: -# input: -# terraformVersion: 0.12.23 -# pipeline: -# stages: -# - name: TERRAFORM_PLAN -# with: -# workspace: dev -# - name: TERRAFORM_APPLY -# with: -# workspace: dev -# - name: WAIT_APPROVAL -# - name: TERRAFORM_PLAN -# with: -# workspace: prod -# - name: TERRAFORM_APPLY -# with: -# workspace: prod diff --git a/pkg/configv1/testdata/application/terraform-app.yaml b/pkg/configv1/testdata/application/terraform-app.yaml deleted file mode 100644 index 26719e2582..0000000000 --- a/pkg/configv1/testdata/application/terraform-app.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: pipecd.dev/v1beta1 -kind: TerraformApp -spec: - input: - workspace: dev - terraformVersion: 0.12.23 diff --git a/pkg/configv1/testdata/application/truebydefaultbool-false-explicitly.yaml b/pkg/configv1/testdata/application/truebydefaultbool-false-explicitly.yaml index d54005e372..0aefa1d812 100644 --- a/pkg/configv1/testdata/application/truebydefaultbool-false-explicitly.yaml +++ b/pkg/configv1/testdata/application/truebydefaultbool-false-explicitly.yaml @@ -4,5 +4,3 @@ spec: trigger: onOutOfSync: disabled: false - input: - autoRollback: false diff --git a/pkg/configv1/testdata/application/truebydefaultbool-true-explicitly.yaml b/pkg/configv1/testdata/application/truebydefaultbool-true-explicitly.yaml index 5862ab5e1f..608db641cf 100644 --- a/pkg/configv1/testdata/application/truebydefaultbool-true-explicitly.yaml +++ b/pkg/configv1/testdata/application/truebydefaultbool-true-explicitly.yaml @@ -4,5 +4,3 @@ spec: trigger: onOutOfSync: disabled: true - input: - autoRollback: true