From 74e2856d9aa50fbc0484fbf4c09605d7c943299b Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Wed, 14 Jun 2023 14:58:16 +0900 Subject: [PATCH 01/18] add new branch flag when commit changes in eventwatcher Signed-off-by: nnnkkk7 --- .../managing-piped/configuration-reference.md | 270 ++++++++++++++++++ pkg/app/piped/eventwatcher/eventwatcher.go | 13 +- .../piped/eventwatcher/eventwatcher_test.go | 35 +++ pkg/config/piped.go | 2 + pkg/config/piped_test.go | 9 +- pkg/config/testdata/piped/piped-config.yaml | 1 + 6 files changed, 326 insertions(+), 4 deletions(-) create mode 100644 docs/content/en/docs/user-guide/managing-piped/configuration-reference.md diff --git a/docs/content/en/docs/user-guide/managing-piped/configuration-reference.md b/docs/content/en/docs/user-guide/managing-piped/configuration-reference.md new file mode 100644 index 0000000000..e3438a13c0 --- /dev/null +++ b/docs/content/en/docs/user-guide/managing-piped/configuration-reference.md @@ -0,0 +1,270 @@ +--- +title: "Configuration reference" +linkTitle: "Configuration reference" +weight: 9 +description: > + This page describes all configurable fields in the piped configuration. +--- + +``` yaml +apiVersion: pipecd.dev/v1beta1 +kind: Piped +spec: + projectID: ... + pipedID: ... + ... +``` + +## Piped Configuration + +| Field | Type | Description | Required | +|-|-|-|-| +| projectID | string | The identifier of the PipeCD project where this piped belongs to. | Yes | +| pipedID | string | The generated ID for this piped. | Yes | +| pipedKeyFile | string | The path to the file containing the generated key string for this piped. | Yes | +| pipedKeyData | string | Base64 encoded string of Piped key. Either pipedKeyFile or pipedKeyData must be set. | Yes | +| apiAddress | string | The address used to connect to the Control Plane's API in format `host:port`. | Yes | +| syncInterval | duration | How often to check whether an application should be synced. Default is `1m`. | No | +| appConfigSyncInterval | duration | How often to check whether application configuration files should be synced. Default is `1m`. | No | +| git | [Git](#git) | Git configuration needed for Git commands. | No | +| repositories | [][Repository](#gitrepository) | List of Git repositories this piped will handle. | No | +| chartRepositories | [][ChartRepository](#chartrepository) | List of Helm chart repositories that should be added while starting up. | No | +| chartRegistries | [][ChartRegistry](#chartregistry) | List of helm chart registries that should be logged in while starting up. | No | +| cloudProviders | [][CloudProvider](#cloudprovider) | List of cloud providers can be used by this piped. This field is deprecated, use `platformProviders` instead. | No | +| platformProviders | [][PlatformProvider](#platformprovider) | List of platform providers can be used by this piped. | No | +| analysisProviders | [][AnalysisProvider](#analysisprovider) | List of analysis providers can be used by this piped. | No | +| eventWatcher | [EventWatcher](#eventwatcher) | Optional Event watcher settings. | No | +| secretManagement | [SecretManagement](#secretmanagement) | The using secret management method. | No | +| notifications | [Notifications](#notifications) | Sending notifications to Slack, Webhook... | No | +| appSelector | map[string]string | List of labels to filter all applications this piped will handle. Currently, it is only be used to filter the applications suggested for adding from the control plane. | No | + +## Git + +| Field | Type | Description | Required | +|-|-|-|-| +| username | string | The username that will be configured for `git` user. Default is `piped`. | No | +| email | string | The email that will be configured for `git` user. Default is `pipecd.dev@gmail.com`. | No | +| sshConfigFilePath | string | Where to write ssh config file. Default is `$HOME/.ssh/config`. | No | +| host | string | The host name. Default is `github.com`. | No | +| hostName | string | The hostname or IP address of the remote git server. Default is the same value with Host. | No | +| sshKeyFile | string | The path to the private ssh key file. This will be used to clone the source code of the specified git repositories. | No | +| sshKeyData | string | Base64 encoded string of SSH key. | No | +| enableNewBranch | bool | Whether to create a new branch or not when commit changes in event watcher. | No | + +## GitRepository + +| Field | Type | Description | Required | +|-|-|-|-| +| repoID | string | Unique identifier to the repository. This must be unique in the piped scope. | Yes | +| remote | string | Remote address of the repository used to clone the source code. e.g. `git@github.com:org/repo.git` | Yes | +| branch | string | The branch will be handled. | Yes | + +## ChartRepository + +| Field | Type | Description | Required | +|-|-|-|-| +| type | string | The repository type. Currently, HTTP and GIT are supported. Default is HTTP. | No | +| name | string | The name of the Helm chart repository. Note that is not a Git repository but a [Helm chart repository](https://helm.sh/docs/topics/chart_repository/). | Yes if type is HTTP | +| address | string | The address to the Helm chart repository. | Yes if type is HTTP | +| username | string | Username used for the repository backed by HTTP basic authentication. | No | +| password | string | Password used for the repository backed by HTTP basic authentication. | No | +| insecure | bool | Whether to skip TLS certificate checks for the repository or not. | No | +| gitRemote | string | Remote address of the Git repository used to clone Helm charts. | Yes if type is GIT | +| sshKeyFile | string | The path to the private ssh key file used while cloning Helm charts from above Git repository. | No | + +## ChartRegistry + +| Field | Type | Description | Required | +|-|-|-|-| +| type | string | The registry type. Currently, only OCI is supported. Default is OCI. | No | +| address | string | The address to the registry. | Yes | +| username | string | Username used for the registry authentication. | No | +| password | string | Password used for the registry authentication. | No | + +## CloudProvider + +This field is deprecated, please use [PlatformProvider](#platformprovider) instead. + +## PlatformProvider + +| Field | Type | Description | Required | +|-|-|-|-| +| name | string | The name of the platform provider. | Yes | +| type | string | The platform provider type. Must be one of the following values:
`KUBERNETES`, `TERRAFORM`, `CLOUDRUN`, `LAMBDA`. | Yes | +| config | [PlatformProviderConfig](#platformproviderconfig) | Specific configuration for the specified type of platform provider. | No | + +## PlatformProviderConfig + +Must be one of the following structs: + +### PlatformProviderKubernetesConfig + +| Field | Type | Description | Required | +|-|-|-|-| +| masterURL | string | The master URL of the kubernetes cluster. Empty means in-cluster. | No | +| kubectlVersion | string | Version of kubectl which will be used to connect to your cluster. Empty means the version set on [piped config](../user-guide/managing-piped/configuration-reference/#platformproviderkubernetesconfig) or [default version](https://github.com/pipe-cd/pipecd/blob/master/tool/piped-base/install-kubectl.sh#L24) will be used. | No | +| kubeConfigPath | string | The path to the kubeconfig file. Empty means in-cluster. | No | +| appStateInformer | [KubernetesAppStateInformer](#kubernetesappstateinformer) | Configuration for application resource informer. | No | + +### PlatformProviderTerraformConfig + +| Field | Type | Description | Required | +|-|-|-|-| +| vars | []string | List of variables that will be set directly on terraform commands with `-var` flag. The variable must be formatted by `key=value`. | No | + +### PlatformProviderCloudRunConfig + +| Field | Type | Description | Required | +|-|-|-|-| +| project | string | The GCP project hosting the Cloud Run service. | Yes | +| region | string | The region of running Cloud Run service. | Yes | +| credentialsFile | string | The path to the service account file for accessing Cloud Run service. | No | + +### PlatformProviderLambdaConfig + +| Field | Type | Description | Required | +|-|-|-|-| +| region | string | The region of running Lambda service. | Yes | +| credentialsFile | string | The path to the credential file for logging into AWS cluster. If this value is not provided, piped will read credential info from environment variables. It expects the format [~/.aws/credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html). | No | +| roleARN | string | The IAM role arn to use when assuming an role. Required if you want to use the AWS SecurityTokenService. | No | +| tokenFile | string | The path to the WebIdentity token the SDK should use to assume a role with. Required if you want to use the AWS SecurityTokenService. | No | +| profile | string | The profile to use for logging into AWS cluster. The default value is `default`. | No | + +### PlatformProviderECSConfig + +| Field | Type | Description | Required | +|-|-|-|-| +| region | string | The region of running ECS cluster. | Yes | +| credentialsFile | string | The path to the credential file for logging into AWS cluster. If this value is not provided, piped will read credential info from environment variables. It expects the format [~/.aws/credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) | No | +| roleARN | string | The IAM role arn to use when assuming an role. Required if you want to use the AWS SecurityTokenService. | No | +| tokenFile | string | The path to the WebIdentity token the SDK should use to assume a role with. Required if you want to use the AWS SecurityTokenService. | No | +| profile | string | The profile to use for logging into AWS cluster. The default value is `default`. | No | + +## KubernetesAppStateInformer + +| Field | Type | Description | Required | +|-|-|-|-| +| namespace | string | Only watches the specified namespace. Empty means watching all namespaces. | No | +| includeResources | [][KubernetesResourcematcher](#kubernetesresourcematcher) | List of resources that should be added to the watching targets. | No | +| excludeResources | [][KubernetesResourcematcher](#kubernetesresourcematcher) | List of resources that should be ignored from the watching targets. | No | + +### KubernetesResourceMatcher + +| Field | Type | Description | Required | +|-|-|-|-| +| apiVersion | string | The APIVersion of the kubernetes resource. | Yes | +| kind | string | The kind name of the kubernetes resource. Empty means all kinds are matching. | No | + +## AnalysisProvider + +| Field | Type | Description | Required | +|-|-|-|-| +| name | string | The unique name of the analysis provider. | Yes | +| type | string | The provider type. Currently, only PROMETHEUS, DATADOG are available. | Yes | +| config | [AnalysisProviderConfig](#analysisproviderconfig) | Specific configuration for the specified type of analysis provider. | Yes | + +## AnalysisProviderConfig + +Must be one of the following structs: + +### AnalysisProviderPrometheusConfig +| Field | Type | Description | Required | +|-|-|-|-| +| address | string | The Prometheus server address. | Yes | +| usernameFile | string | The path to the username file. | No | +| passwordFile | string | The path to the password file. | No | + +### AnalysisProviderDatadogConfig +| Field | Type | Description | Required | +|-|-|-|-| +| address | string | The address of Datadog API server. Only "datadoghq.com", "us3.datadoghq.com", "datadoghq.eu", "ddog-gov.com" are available. Defaults to "datadoghq.com" | No | +| apiKeyFile | string | The path to the api key file. | Yes | +| applicationKeyFile | string | The path to the application key file. | Yes | + +## EventWatcher + +| Field | Type | Description | Required | +|-|-|-|-| +| checkInterval | duration | Interval to fetch the latest event and compare it with one defined in EventWatcher config files. Defaults to `1m`. | No | +| gitRepos | [][EventWatcherGitRepo](#eventwatchergitrepo) | The configuration list of git repositories to be observed. Only the repositories in this list will be observed by Piped. | No | + +### EventWatcherGitRepo + +| Field | Type | Description | Required | +|-|-|-|-| +| repoId | string | Id of the git repository. This must be unique within the repos' elements. | Yes | +| commitMessage | string | The commit message used to push after replacing values. Default message is used if not given. | No | +| includes | []string | The paths to EventWatcher files to be included. Patterns can be used like `foo/*.yaml`. | No | +| excludes | []string | The paths to EventWatcher files to be excluded. Patterns can be used like `foo/*.yaml`. This is prioritized if both includes and this are given. | No | + +## SecretManagement + +| Field | Type | Description | Required | +|-|-|-|-| +| type | string | Which management method should be used. Default is `KEY_PAIR`. | Yes | +| config | [SecretManagementConfig](#secretmanagementconfig) | Configration for using secret management method. | Yes | + +## SecretManagementConfig + +Must be one of the following structs: + +### SecretManagementKeyPair + +| Field | Type | Description | Required | +|-|-|-|-| +| privateKeyFile | string | Path to the private RSA key file. | Yes | +| privateKeyData | string | Base64 encoded string of private RSA key. Either privateKeyFile or privateKeyData must be set. | No | +| publicKeyFile | string | Path to the public RSA key file. | Yes | +| publicKeyData | string | Base64 encoded string of public RSA key. Either publicKeyFile or publicKeyData must be set. | No | + +### SecretManagementGCPKMS + +> WIP + +## Notifications + +| Field | Type | Description | Required | +|-|-|-|-| +| routes | [][NotificationRoute](#notificationroute) | List of notification routes. | No | +| receivers | [][NotificationReceiver](#notificationreceiver) | List of notification receivers. | No | + +### NotificationRoute + +| Field | Type | Description | Required | +|-|-|-|-| +| name | string | The name of the route. | Yes | +| receiver | string | The name of receiver who will receive all matched events. | Yes | +| events | []string | List of events that should be routed to the receiver. | No | +| ignoreEvents | []string | List of events that should be ignored. | No | +| groups | []string | List of event groups should be routed to the receiver. | No | +| ignoreGroups | []string | List of event groups should be ignored. | No | +| apps | []string | List of applications where their events should be routed to the receiver. | No | +| ignoreApps | []string | List of applications where their events should be ignored. | No | +| labels | map[string]string | List of labels where their events should be routed to the receiver. | No | +| ignoreLabels | map[string]string | List of labels where their events should be ignored. | No | + + +### NotificationReceiver + +| Field | Type | Description | Required | +|-|-|-|-| +| name | string | The name of the receiver. | Yes | +| slack | [NotificationReciverSlack](#notificationreceiverslack) | Configuration for slack receiver. | No | +| webhook | [NotificationReceiverWebhook](#notificationreceiverwebhook) | Configuration for webhook receiver. | No | + +#### NotificationReceiverSlack + +| Field | Type | Description | Required | +|-|-|-|-| +| hookURL | string | The hookURL of a slack channel. | Yes | +| oauthToken | string | [The token for slack api use.](https://api.slack.com/authentication/basics) | No | +| channelID | string | The channel id which slack api send to. | No | + +#### NotificationReceiverWebhook + +| Field | Type | Description | Required | +|-|-|-|-| +| url | string | The URL where notification event will be sent to. | Yes | +| signatureKey | string | The HTTP header key used to store the configured signature in each event. Default is "PipeCD-Signature". | No | +| signatureValue | string | The value of signature included in header of each event request. It can be used to verify the received events. | No | +| signatureValueFile | string | The path to the signature value file. | No | diff --git a/pkg/app/piped/eventwatcher/eventwatcher.go b/pkg/app/piped/eventwatcher/eventwatcher.go index d53838e8e3..9cac050288 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher.go +++ b/pkg/app/piped/eventwatcher/eventwatcher.go @@ -33,6 +33,7 @@ import ( "go.uber.org/zap" "google.golang.org/grpc" + "github.com/google/uuid" "github.com/pipe-cd/pipecd/pkg/app/server/service/pipedservice" "github.com/pipe-cd/pipecd/pkg/backoff" "github.com/pipe-cd/pipecd/pkg/config" @@ -639,7 +640,8 @@ func (w *watcher) commitFiles(ctx context.Context, latestData, eventName, commit EventName: eventName, } commitMsg = parseCommitMsg(commitMsg, args) - if err := repo.CommitChanges(ctx, repo.GetClonedBranch(), commitMsg, false, changes); err != nil { + branch := getBranchName(w.config.Git.EnableNewBranch, eventName, repo.GetClonedBranch()) + if err := repo.CommitChanges(ctx, branch, commitMsg, w.config.Git.EnableNewBranch, changes); err != nil { return fmt.Errorf("failed to perform git commit: %w", err) } w.logger.Info(fmt.Sprintf("event watcher will update values of Event %q", eventName)) @@ -777,3 +779,12 @@ func parseCommitMsg(msg string, args argsTemplate) string { } return buf.String() } + +// getBranchName generates a new branch name in the format {eventName}-{uuid} if newBranch is true. +// If newBranch is false, the function returns the existing branch name. +func getBranchName(newBranch bool, eventName, branch string) string { + if !newBranch { + return branch + } + return fmt.Sprintf("%s-%s", eventName, uuid.New().String()) +} diff --git a/pkg/app/piped/eventwatcher/eventwatcher_test.go b/pkg/app/piped/eventwatcher/eventwatcher_test.go index bb6c0b9f53..3983fa4a6a 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher_test.go +++ b/pkg/app/piped/eventwatcher/eventwatcher_test.go @@ -242,3 +242,38 @@ spec: }) } } + +func TestGetBranchName(t *testing.T) { + t.Parallel() + testcases := []struct { + name string + newBranch bool + eventName string + branch string + want string + }{ + { + name: "create new branch", + newBranch: true, + eventName: "event", + branch: "main", + }, + { + name: "return existing branch", + newBranch: false, + eventName: "event", + branch: "main", + want: "main", + }, + } + for _, tc := range testcases { + t.Run(tc.name, func(t *testing.T) { + got := getBranchName(tc.newBranch, tc.eventName, tc.branch) + if tc.newBranch { + assert.NotEqual(t, tc.branch, got) + } else { + assert.Equal(t, tc.want, got) + } + }) + } +} diff --git a/pkg/config/piped.go b/pkg/config/piped.go index 911dad6971..e7d504522f 100644 --- a/pkg/config/piped.go +++ b/pkg/config/piped.go @@ -326,6 +326,8 @@ type PipedGit struct { SSHKeyFile string `json:"sshKeyFile,omitempty"` // Base64 encoded string of ssh-key. SSHKeyData string `json:"sshKeyData,omitempty"` + // Whether to create a new branch or not when commit changes in event watcher. + EnableNewBranch bool `json:"enableNewBranch,omitempty"` } func (g PipedGit) ShouldConfigureSSHConfig() bool { diff --git a/pkg/config/piped_test.go b/pkg/config/piped_test.go index d9ce0f837c..0ead74edb1 100644 --- a/pkg/config/piped_test.go +++ b/pkg/config/piped_test.go @@ -45,9 +45,10 @@ func TestPipedConfig(t *testing.T) { SyncInterval: Duration(time.Minute), AppConfigSyncInterval: Duration(time.Minute), Git: PipedGit{ - Username: "username", - Email: "username@email.com", - SSHKeyFile: "/etc/piped-secret/ssh-key", + Username: "username", + Email: "username@email.com", + SSHKeyFile: "/etc/piped-secret/ssh-key", + EnableNewBranch: true, }, Repositories: []PipedRepository{ { @@ -541,6 +542,7 @@ func TestPipedConfigMask(t *testing.T) { HostName: "foo", SSHKeyFile: "foo", SSHKeyData: "foo", + EnableNewBranch: true, }, Repositories: []PipedRepository{ { @@ -704,6 +706,7 @@ func TestPipedConfigMask(t *testing.T) { HostName: "foo", SSHKeyFile: maskString, SSHKeyData: maskString, + EnableNewBranch: true, }, Repositories: []PipedRepository{ { diff --git a/pkg/config/testdata/piped/piped-config.yaml b/pkg/config/testdata/piped/piped-config.yaml index 39273652ae..35e25eea9b 100644 --- a/pkg/config/testdata/piped/piped-config.yaml +++ b/pkg/config/testdata/piped/piped-config.yaml @@ -12,6 +12,7 @@ spec: username: username email: username@email.com sshKeyFile: /etc/piped-secret/ssh-key + enableNewBranch: true repositories: - repoId: repo1 From 9d06d5c49291a4226e93c5de24cddc72115c350b Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Thu, 22 Jun 2023 16:31:45 +0900 Subject: [PATCH 02/18] add createPullRequest flag to event watcher config instead of git config Signed-off-by: nnnkkk7 --- .../user-guide/configuration-reference.md | 2 + .../user-guide/configuration-reference.md | 714 ++++++++++++++++++ .../managing-piped/configuration-reference.md | 1 - pkg/app/piped/eventwatcher/eventwatcher.go | 10 +- pkg/config/event_watcher.go | 4 + pkg/config/piped.go | 2 - pkg/config/piped_test.go | 9 +- pkg/config/testdata/piped/piped-config.yaml | 1 - 8 files changed, 728 insertions(+), 15 deletions(-) create mode 100644 docs/content/en/docs/user-guide/configuration-reference.md diff --git a/docs/content/en/docs-dev/user-guide/configuration-reference.md b/docs/content/en/docs-dev/user-guide/configuration-reference.md index d911109aee..57b0c29de7 100644 --- a/docs/content/en/docs-dev/user-guide/configuration-reference.md +++ b/docs/content/en/docs-dev/user-guide/configuration-reference.md @@ -197,6 +197,7 @@ spec: | Field | Type | Description | Required | |-|-|-|-| | name | string | The event name. | Yes | +| createPullRequest | bool | Whether to create a new branch or not when commit changes in event watcher. | No | | labels | map[string]string | Additional attributes of event. This can make an event definition unique even if the one with the same name exists. | No | | replacements | [][EventWatcherReplacement](#eventwatcherreplacement) | List of places where will be replaced when the new event matches. | Yes | @@ -699,6 +700,7 @@ Note: By default, the sum of traffic is rounded to 100. If both `primary` and `c | Field | Type | Description | Required | |-|-|-|-| | commitMessage | string | The commit message used to push after replacing values. Default message is used if not given. | No | +| createPullRequest | bool | Whether to create a new branch or not when commit changes in event watcher. | No | | replacements | [][EventWatcherReplacement](#eventwatcherreplacement) | List of places where will be replaced when the new event matches. | Yes | ## DriftDetection diff --git a/docs/content/en/docs/user-guide/configuration-reference.md b/docs/content/en/docs/user-guide/configuration-reference.md new file mode 100644 index 0000000000..a1316f6326 --- /dev/null +++ b/docs/content/en/docs/user-guide/configuration-reference.md @@ -0,0 +1,714 @@ +--- +title: "Configuration reference" +linkTitle: "Configuration reference" +weight: 9 +description: > + This page describes all configurable fields in the application configuration and analysis template. +--- + +## Kubernetes Application + +``` yaml +apiVersion: pipecd.dev/v1beta1 +kind: KubernetesApp +spec: + input: + pipeline: + ... +``` + +| Field | Type | Description | Required | +|-|-|-|-| +| name | string | The application name. | Yes (if you want to create PipeCD application through the application configuration file) | +| labels | map[string]string | Additional attributes to identify applications. | No | +| description | string | Notes on the Application. | No | +| input | [KubernetesDeploymentInput](#kubernetesdeploymentinput) | Input for Kubernetes deployment such as kubectl version, helm version, manifests filter... | No | +| trigger | [DeploymentTrigger](#deploymenttrigger) | Configuration for trigger used to determine should we trigger a new deployment or not. | No | +| planner | [DeploymentPlanner](#deploymentplanner) | Configuration for planner used while planning deployment. | No | +| commitMatcher | [CommitMatcher](#commitmatcher) | Forcibly use QuickSync or Pipeline when commit message matched the specified pattern. | No | +| quickSync | [KubernetesQuickSync](#kubernetesquicksync) | Configuration for quick sync. | No | +| pipeline | [Pipeline](#pipeline) | Pipeline for deploying progressively. | No | +| service | [KubernetesService](#kubernetesservice) | Which Kubernetes resource should be considered as the Service of application. Empty means the first Service resource will be used. | No | +| workloads | [][KubernetesWorkload](#kubernetesworkload) | Which Kubernetes resources should be considered as the Workloads of application. Empty means all Deployment resources. | No | +| trafficRouting | [KubernetesTrafficRouting](#kubernetestrafficrouting) | How to change traffic routing percentages. | No | +| encryption | [SecretEncryption](#secretencryption) | List of encrypted secrets and targets that should be decrypted before using. | No | +| attachment | [Attachment](#attachment) | List of attachment sources and targets that should be attached to manifests before using. | No | +| timeout | duration | The maximum length of time to execute deployment before giving up. Default is 6h. | No | +| notification | [DeploymentNotification](#deploymentnotification) | Additional configuration used while sending notification to external services. | No | +| postSync | [PostSync](#postsync) | Additional configuration used as extra actions once the deployment is triggered. | No | +| variantLabel | [KubernetesVariantLabel](#kubernetesvariantlabel) | The label will be configured to variant manifests used to distinguish them. | No | +| eventWatcher | [][EventWatcher](#eventwatcher) | List of configurations for event watcher. | No | +| driftDetection | [DriftDetection](#driftdetection) | Configuration for drift detection. | No | + +## Terraform application + +``` yaml +apiVersion: pipecd.dev/v1beta1 +kind: TerraformApp +spec: + input: + pipeline: + ... +``` + +| Field | Type | Description | Required | +|-|-|-|-| +| name | string | The application name. | Yes if you set the application through the application configuration file | +| labels | map[string]string | Additional attributes to identify applications. | No | +| description | string | Notes on the Application. | No | +| input | [TerraformDeploymentInput](#terraformdeploymentinput) | Input for Terraform deployment such as terraform version, workspace... | No | +| trigger | [DeploymentTrigger](#deploymenttrigger) | Configuration for trigger used to determine should we trigger a new deployment or not. | No | +| planner | [DeploymentPlanner](#deploymentplanner) | Configuration for planner used while planning deployment. | No | +| quickSync | [TerraformQuickSync](#terraformquicksync) | Configuration for quick sync. | No | +| pipeline | [Pipeline](#pipeline) | Pipeline for deploying progressively. | No | +| encryption | [SecretEncryption](#secretencryption) | List of encrypted secrets and targets that should be decrypted before using. | No | +| attachment | [Attachment](#attachment) | List of attachment sources and targets that should be attached to manifests before using. | No | +| timeout | duration | The maximum length of time to execute deployment before giving up. Default is 6h. | No | +| notification | [DeploymentNotification](#deploymentnotification) | Additional configuration used while sending notification to external services. | No | +| postSync | [PostSync](#postsync) | Additional configuration used as extra actions once the deployment is triggered. | No | +| eventWatcher | [][EventWatcher](#eventwatcher) | List of configurations for event watcher. | No | + +## Cloud Run application + +``` yaml +apiVersion: pipecd.dev/v1beta1 +kind: CloudRunApp +spec: + input: + pipeline: + ... +``` + +| Field | Type | Description | Required | +|-|-|-|-| +| name | string | The application name. | Yes if you set the application through the application configuration file | +| labels | map[string]string | Additional attributes to identify applications. | No | +| description | string | Notes on the Application. | No | +| input | [CloudRunDeploymentInput](#cloudrundeploymentinput) | Input for Cloud Run deployment such as docker image... | No | +| trigger | [DeploymentTrigger](#deploymenttrigger) | Configuration for trigger used to determine should we trigger a new deployment or not. | No | +| planner | [DeploymentPlanner](#deploymentplanner) | Configuration for planner used while planning deployment. | No | +| quickSync | [CloudRunQuickSync](#cloudrunquicksync) | Configuration for quick sync. | No | +| pipeline | [Pipeline](#pipeline) | Pipeline for deploying progressively. | No | +| encryption | [SecretEncryption](#secretencryption) | List of encrypted secrets and targets that should be decrypted before using. | No | +| attachment | [Attachment](#attachment) | List of attachment sources and targets that should be attached to manifests before using. | No | +| timeout | duration | The maximum length of time to execute deployment before giving up. Default is 6h. | No | +| notification | [DeploymentNotification](#deploymentnotification) | Additional configuration used while sending notification to external services. | No | +| postSync | [PostSync](#postsync) | Additional configuration used as extra actions once the deployment is triggered. | No | +| eventWatcher | [][EventWatcher](#eventwatcher) | List of configurations for event watcher. | No | + +## Lambda application + +``` yaml +apiVersion: pipecd.dev/v1beta1 +kind: LambdaApp +spec: + pipeline: + ... +``` + +| Field | Type | Description | Required | +|-|-|-|-| +| name | string | The application name. | Yes if you set the application through the application configuration file | +| labels | map[string]string | Additional attributes to identify applications. | No | +| description | string | Notes on the Application. | No | +| input | [LambdaDeploymentInput](#lambdadeploymentinput) | Input for Lambda deployment such as path to function manifest file... | No | +| trigger | [DeploymentTrigger](#deploymenttrigger) | Configuration for trigger used to determine should we trigger a new deployment or not. | No | +| planner | [DeploymentPlanner](#deploymentplanner) | Configuration for planner used while planning deployment. | No | +| quickSync | [LambdaQuickSync](#lambdaquicksync) | Configuration for quick sync. | No | +| pipeline | [Pipeline](#pipeline) | Pipeline for deploying progressively. | No | +| encryption | [SecretEncryption](#secretencryption) | List of encrypted secrets and targets that should be decrypted before using. | No | +| attachment | [Attachment](#attachment) | List of attachment sources and targets that should be attached to manifests before using. | No | +| timeout | duration | The maximum length of time to execute deployment before giving up. Default is 6h. | No | +| notification | [DeploymentNotification](#deploymentnotification) | Additional configuration used while sending notification to external services. | No | +| postSync | [PostSync](#postsync) | Additional configuration used as extra actions once the deployment is triggered. | No | +| eventWatcher | [][EventWatcher](#eventwatcher) | List of configurations for event watcher. | No | + +## ECS application + +``` yaml +apiVersion: pipecd.dev/v1beta1 +kind: ECSApp +spec: + input: + pipeline: + ... +``` + +| Field | Type | Description | Required | +|-|-|-|-| +| name | string | The application name. | Yes if you set the application through the application configuration file | +| labels | map[string]string | Additional attributes to identify applications. | No | +| description | string | Notes on the Application. | No | +| input | [ECSDeploymentInput](#ecsdeploymentinput) | Input for ECS deployment such as path to TaskDefinition, Service... | No | +| trigger | [DeploymentTrigger](#deploymenttrigger) | Configuration for trigger used to determine should we trigger a new deployment or not. | No | +| planner | [DeploymentPlanner](#deploymentplanner) | Configuration for planner used while planning deployment. | No | +| quickSync | [ECSQuickSync](#ecsquicksync) | Configuration for quick sync. | No | +| pipeline | [Pipeline](#pipeline) | Pipeline for deploying progressively. | No | +| encryption | [SecretEncryption](#secretencryption) | List of encrypted secrets and targets that should be decrypted before using. | No | +| attachment | [Attachment](#attachment) | List of attachment sources and targets that should be attached to manifests before using. | No | +| timeout | duration | The maximum length of time to execute deployment before giving up. Default is 6h. | No | +| notification | [DeploymentNotification](#deploymentnotification) | Additional configuration used while sending notification to external services. | No | +| postSync | [PostSync](#postsync) | Additional configuration used as extra actions once the deployment is triggered. | No | +| eventWatcher | [][EventWatcher](#eventwatcher) | List of configurations for event watcher. | No | + +## Analysis Template Configuration + +``` yaml +apiVersion: pipecd.dev/v1beta1 +kind: AnalysisTemplate +spec: + metrics: + grpc_error_rate_percentage: + interval: 1m + provider: prometheus-dev + failureLimit: 1 + expected: + max: 10 + query: awesome_query +``` + +| Field | Type | Description | Required | +|-|-|-|-| +| metrics | map[string][AnalysisMetrics](#analysismetrics) | Template for metrics. | No | + +## Event Watcher Configuration (deprecated) + +```yaml +apiVersion: pipecd.dev/v1beta1 +kind: EventWatcher +spec: + events: + - name: helloworld-image-update + replacements: + - file: helloworld/deployment.yaml + yamlField: $.spec.template.spec.containers[0].image +``` + +| Field | Type | Description | Required | +|-|-|-|-| +| name | string | The event name. | Yes | +| createPullRequest | bool | Whether to create a new branch or not when commit changes in event watcher. | No | +| labels | map[string]string | Additional attributes of event. This can make an event definition unique even if the one with the same name exists. | No | +| replacements | [][EventWatcherReplacement](#eventwatcherreplacement) | List of places where will be replaced when the new event matches. | Yes | + +### EventWatcherReplacement +One of `yamlField` or `regex` is required. + +| Field | Type | Description | Required | +|-|-|-|-| +| file | string | The relative path from the repository root to the file to be updated. | Yes | +| yamlField | string | The yaml path to the field to be updated. It requires to start with `$` which represents the root element. e.g. `$.foo.bar[0].baz`. | No | +| regex | string | The regex string that specify what should be replaced. The only first capturing group enclosed by `()` will be replaced with the new value. e.g. `host.xz/foo/bar:(v[0-9].[0-9].[0-9])` | No | + +## CommitMatcher + +| Field | Type | Description | Required | +|-|-|-|-| +| quickSync | string | Regular expression string to forcibly do QuickSync when it matches the commit message. | No | +| pipeline | string | Regular expression string to forcibly do Pipeline when it matches the commit message. | No | + +## SecretEncryption + +| Field | Type | Description | Required | +|-|-|-|-| +| encryptedSecrets | map[string]string | List of encrypted secrets. | No | +| decryptionTargets | []string | List of files to be decrypted before using. | No | + +## Attachment + +| Field | Type | Description | Required | +|-|-|-|-| +| sources | map[string]string | List of attaching files with key is its refer name. | No | +| targets | []string | List of files which should contain the attachments. | No | + +## DeploymentPlanner + +| Field | Type | Description | Required | +|-|-|-|-| +| alwaysUsePipeline | bool | Always use the defined pipeline to deploy the application in all deployments. Default is `false`. | No | + +## DeploymentTrigger + +| Field | Type | Description | Required | +|-|-|-|-| +| onCommit | [OnCommit](#oncommit) | Controls triggering new deployment when new Git commits touched the application. | No | +| onCommand | [OnCommand](#oncommand) | Controls triggering new deployment when received a new `SYNC` command. | No | +| onOutOfSync | [OnOutOfSync](#onoutofsync) | Controls triggering new deployment when application is at `OUT_OF_SYNC` state. | No | +| onChain | [OnChain](#onchain) | Controls triggering new deployment when the application is counted as a node of some chains. | No | + +### OnCommit + +| Field | Type | Description | Required | +|-|-|-|-| +| disabled | bool | Whether to exclude application from triggering target when new Git commits touched it. Default is `false`. | No | +| paths | []string | List of directories or files where any changes of them will be considered as touching the application. Regular expression can be used. Empty means watching all changes under the application directory. | No | +| ignores | []string | List of directories or files where any changes of them will NOT be considered as touching the application. Regular expression can be used. This config has a higher priority compare to `paths`. | No | + +### OnCommand + +| Field | Type | Description | Required | +|-|-|-|-| +| disabled | bool | Whether to exclude application from triggering target when received a new `SYNC` command. Default is `false`. | No | + +### OnOutOfSync + +| Field | Type | Description | Required | +|-|-|-|-| +| disabled | bool | Whether to exclude application from triggering target when application is at `OUT_OF_SYNC` state. Default is `true`. | No | +| minWindow | duration | Minimum amount of time must be elapsed since the last deployment. This can be used to avoid triggering unnecessary continuous deployments based on `OUT_OF_SYNC` status. Default is `5m`. | No | + +### OnChain + +| Field | Type | Description | Required | +|-|-|-|-| +| disabled | bool | Whether to exclude application from triggering target when application is counted as a node of some chains. Default is `true`. | No | + +## Pipeline + +| Field | Type | Description | Required | +|-|-|-|-| +| stages | [][PipelineStage](#pipelinestage) | List of deployment pipeline stages. | No | + +### PipelineStage + +| Field | Type | Description | Required | +|-|-|-|-| +| id | string | The unique ID of the stage. | No | +| name | string | One of the provided stage names. | Yes | +| desc | string | The description about the stage. | No | +| timeout | duration | The maximum time the stage can be taken to run. | No | +| with | [StageOptions](#stageoptions) | Specific configuration for the stage. This must be one of these [StageOptions](#stageoptions). | No | + +## DeploymentNotification + +| Field | Type | Description | Required | +|-|-|-|-| +| mentions | [][NotificationMention](#notificationmention) | List of users to be notified for each event. | No | + +### NotificationMention + +| Field | Type | Description | Required | +|-|-|-|-| +| event | string | The event to be notified to users. | Yes | +| slack | []string | List of user IDs for mentioning in Slack. See [here](https://api.slack.com/reference/surfaces/formatting#mentioning-users) for more information on how to check them. | No | + +## KubernetesDeploymentInput + +| Field | Type | Description | Required | +|-|-|-|-| +| manifests | []string | List of manifest files in the application directory used to deploy. Empty means all manifest files in the directory will be used. | No | +| kubectlVersion | string | Version of kubectl will be used. Empty means the version set on [piped config](../managing-piped/configuration-reference/#platformproviderkubernetesconfig) or [default version](https://github.com/pipe-cd/pipecd/blob/master/tool/piped-base/install-kubectl.sh#L24) will be used. | No | +| kustomizeVersion | string | Version of kustomize will be used. Empty means the [default version](https://github.com/pipe-cd/pipecd/blob/master/tool/piped-base/install-kustomize.sh#L24) will be used. | No | +| kustomizeOptions | map[string]string | List of options that should be used by Kustomize commands. | No | +| helmVersion | string | Version of helm will be used. Empty means the [default version](https://github.com/pipe-cd/pipecd/blob/master/tool/piped-base/install-helm.sh#L24) will be used. | No | +| helmChart | [HelmChart](#helmchart) | Where to fetch helm chart. | No | +| helmOptions | [HelmOptions](#helmoptions) | Configurable parameters for helm commands. | No | +| namespace | string | The namespace where manifests will be applied. | No | +| autoRollback | bool | Automatically reverts all deployment changes on failure. Default is `true`. | No | + +### HelmChart + +| Field | Type | Description | Required | +|-|-|-|-| +| gitRemote | string | Git remote address where the chart is placing. Empty means the same repository. | No | +| ref | string | The commit SHA or tag value. Only valid when gitRemote is not empty. | No | +| path | string | Relative path from the repository root to the chart directory. | No | +| repository | string | The name of a registered Helm Chart Repository. | No | +| name | string | The chart name. | No | +| version | string | The chart version. | No | + +### HelmOptions + +| Field | Type | Description | Required | +|-|-|-|-| +| releaseName | string | The release name of helm deployment. By default, the release name is equal to the application name. | No | +| valueFiles | []string | List of value files should be loaded. Only local files stored under the application directory or remote files served at the http(s) endpoint are allowed. | No | +| setFiles | map[string]string | List of file path for values. | No | +| apiVersions | []string | Kubernetes api versions used for Capabilities.APIVersions. | No | +| kubeVersion | string | Kubernetes version used for Capabilities.KubeVersion. | No | + +## KubernetesVariantLabel + +| Field | Type | Description | Required | +|-|-|-|-| +| key | string | The key of the label. Default is `pipecd.dev/variant`. | No | +| primaryValue | string | The label value for PRIMARY variant. Default is `primary`. | No | +| canaryValue | string | The label value for CANARY variant. Default is `canary`. | No | +| baselineValue | string | The label value for BASELINE variant. Default is `baseline`. | No | + +## KubernetesQuickSync + +| Field | Type | Description | Required | +|-|-|-|-| +| addVariantLabelToSelector | bool | Whether the PRIMARY variant label should be added to manifests if they were missing. Default is `false`. | No | +| prune | bool | Whether the resources that are no longer defined in Git should be removed or not. Default is `false` | No | + +## KubernetesService + +| Field | Type | Description | Required | +|-|-|-|-| +| name | string | The name of Service manifest. | No | + +## KubernetesWorkload + +| Field | Type | Description | Required | +|-|-|-|-| +| kind | string | The kind name of workload manifests. Currently, only `Deployment` is supported. In the future, we also want to support `ReplicationController`, `DaemonSet`, `StatefulSet`. | No | +| name | string | The name of workload manifest. | No | + +## KubernetesTrafficRouting + +| Field | Type | Description | Required | +|-|-|-|-| +| method | string | Which traffic routing method will be used. Available values are `istio`, `smi`, `podselector`. Default is `podselector`. | No | +| istio | [IstioTrafficRouting](#istiotrafficrouting)| Istio configuration when the method is `istio`. | No | + +### IstioTrafficRouting + +| Field | Type | Description | Required | +|-|-|-|-| +| editableRoutes | []string | List of routes in the VirtualService that can be changed to update traffic routing. Empty means all routes should be updated. | No | +| host | string | The service host. | No | +| virtualService | [IstioVirtualService](#istiovirtualservice) | The reference to VirtualService manifest. Empty means the first VirtualService resource will be used. | No | + +#### IstioVirtualService + +| Field | Type | Description | Required | +|-|-|-|-| +| name | string | The name of VirtualService manifest. | No | + +## TerraformDeploymentInput + +| Field | Type | Description | Required | +|-|-|-|-| +| workspace | string | The terraform workspace name. Empty means `default` workspace. | No | +| terraformVersion | string | The version of terraform should be used. Empty means the pre-installed version will be used. | No | +| vars | []string | List of variables that will be set directly on terraform commands with `-var` flag. The variable must be formatted by `key=value`. | No | +| varFiles | []string | List of variable files that will be set on terraform commands with `-var-file` flag. | No | +| commandFlags | [TerraformCommandFlags](#terraformcommandflags) | List of additional flags will be used while executing terraform commands. | No | +| commandEnvs | [TerraformCommandEnvs](#terraformcommandenvs) | List of additional environment variables will be used while executing terraform commands. | No | +| autoRollback | bool | Automatically reverts all changes from all stages when one of them failed. | No | + +### TerraformCommandFlags + +| Field | Type | Description | Required | +|-|-|-|-| +| shared | []string | List of additional flags used for all Terraform commands. | No | +| init | []string | List of additional flags used for Terraform `init` command. | No | +| plan | []string | List of additional flags used for Terraform `plan` command. | No | +| apply | []string | List of additional flags used for Terraform `apply` command. | No | + +### TerraformCommandEnvs + +| Field | Type | Description | Required | +|-|-|-|-| +| shared | []string | List of additional environment variables used for all Terraform commands. | No | +| init | []string | List of additional environment variables used for Terraform `init` command. | No | +| plan | []string | List of additional environment variables used for Terraform `plan` command. | No | +| apply | []string | List of additional environment variables used for Terraform `apply` command. | No | + +## TerraformQuickSync + +| Field | Type | Description | Required | +|-|-|-|-| +| retries | int | How many times to retry applying terraform changes. Default is `0`. | No | + +## CloudRunDeploymentInput + +| Field | Type | Description | Required | +|-|-|-|-| +| serviceManifestFile | string | The name of service manifest file placing in application directory. Default is `service.yaml`. | No | +| autoRollback | bool | Automatically reverts to the previous state when the deployment is failed. Default is `true`. | No | + +## CloudRunQuickSync + +| Field | Type | Description | Required | +|-|-|-|-| + +## LambdaDeploymentInput + +| Field | Type | Description | Required | +|-|-|-|-| +| functionManifestFile | string | The name of function manifest file placing in application directory. Default is `function.yaml`. | No | +| autoRollback | bool | Automatically reverts to the previous state when the deployment is failed. Default is `true`. | No | + +## LambdaQuickSync + +| Field | Type | Description | Required | +|-|-|-|-| + +## ECSDeploymentInput + +| Field | Type | Description | Required | +|-|-|-|-| +| serviceDefinitionFile | string | The path ECS Service configuration file. Allow file in both `yaml` and `json` format. The default value is `service.json`. See [here](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service_definition_parameters.html) for parameters.| No | +| taskDefinitionFile | string | The path to ECS TaskDefinition configuration file. Allow file in both `yaml` and `json` format. The default value is `taskdef.json`. See [here](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html) for parameters. | No | +| targetGroups | [ECSTargetGroupInput](#ecstargetgroupinput) | The target groups configuration, will be used to routing traffic to created task sets. | Yes (if you want to perform progressive delivery) | + +### ECSTargetGroupInput + +| Field | Type | Description | Required | +|-|-|-|-| +| primary | ECSTargetGroupObject | The PRIMARY target group, will be used to register the PRIMARY ECS task set. | Yes | +| canary | ECSTargetGroupObject | The CANARY target group, will be used to register the CANARY ECS task set if exist. It's required to enable PipeCD to perform the multi-stage deployment. | No | + +Note: You can get examples for those object from [here](../../examples/#ecs-applications). + +## ECSQuickSync + +| Field | Type | Description | Required | +|-|-|-|-| + +## AnalysisMetrics + +| Field | Type | Description | Required | +|-|-|-|-| +| provider | string | The unique name of provider defined in the Piped Configuration. | Yes | +| strategy | string | The strategy name. One of `THRESHOLD` or `PREVIOUS` or `CANARY_BASELINE` or `CANARY_PRIMARY` is available. Defaults to `THRESHOLD`. | No | +| query | string | A query performed against the [Analysis Provider](../../concepts/#analysis-provider). The stage will be skipped if no data points were returned. | Yes | +| expected | [AnalysisExpected](#analysisexpected) | The statically defined expected query result. This field is ignored if there was no data point as a result of the query. | Yes if the strategy is `THRESHOLD` | +| interval | duration | Run a query at specified intervals. | Yes | +| failureLimit | int | Acceptable number of failures. e.g. If 1 is set, the `ANALYSIS` stage will end with failure after two queries results failed. Defaults to 1. | No | +| skipOnNoData | bool | If true, it considers as a success when no data returned from the analysis provider. Defaults to false. | No | +| deviation | string | The stage fails on deviation in the specified direction. One of `LOW` or `HIGH` or `EITHER` is available. This can be used only for `PREVIOUS`, `CANARY_BASELINE` or `CANARY_PRIMARY`. Defaults to `EITHER`. | No | +| baselineArgs | map[string][string] | The custom arguments to be populated for the Baseline query. They can be reffered as `{{ .VariantCustomArgs.xxx }}`. | No | +| canaryArgs | map[string][string] | The custom arguments to be populated for the Canary query. They can be reffered as `{{ .VariantCustomArgs.xxx }}`. | No | +| primaryArgs | map[string][string] | The custom arguments to be populated for the Primary query. They can be reffered as `{{ .VariantCustomArgs.xxx }}`. | No | +| timeout | duration | How long after which the query times out. | No | +| template | [AnalysisTemplateRef](#analysistemplateref) | Reference to the template to be used. | No | + + +### AnalysisExpected + +| Field | Type | Description | Required | +|-|-|-|-| +| min | float64 | Failure, if the query result is less than this value. | No | +| max | float64 | Failure, if the query result is larger than this value. | No | + +### AnalysisTemplateRef + +| Field | Type | Description | Required | +|-|-|-|-| +| name | string | The template name to refer. | Yes | +| appArgs | map[string]string | The arguments for custom-args. | No | + +## AnalysisLog + +| Field | Type | Description | Required | +|-|-|-|-| + +## AnalysisHttp + +| Field | Type | Description | Required | +|-|-|-|-| + +## StageOptions + +### KubernetesPrimaryRolloutStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| +| suffix | string | Suffix that should be used when naming the PRIMARY variant's resources. Default is `primary`. | No | +| createService | bool | Whether the PRIMARY service should be created. Default is `false`. | No | +| addVariantLabelToSelector | bool | Whether the PRIMARY variant label should be added to manifests if they were missing. Default is `false`. | No | +| prune | bool | Whether the resources that are no longer defined in Git should be removed or not. Default is `false` | No | + +### KubernetesCanaryRolloutStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| +| replicas | int | How many pods for CANARY workloads. Default is `1` pod. Alternatively, can be specified a string suffixed by "%" to indicate a percentage value compared to the pod number of PRIMARY | No | +| suffix | string | Suffix that should be used when naming the CANARY variant's resources. Default is `canary`. | No | +| createService | bool | Whether the CANARY service should be created. Default is `false`. | No | +| patches | [][KubernetesResourcePatch](#kubernetesresourcepatch) | List of patches used to customize manifests for CANARY variant. | No | + +### KubernetesCanaryCleanStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| +| | | | | + +### KubernetesBaselineRolloutStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| +| replicas | int | How many pods for BASELINE workloads. Default is `1` pod. Alternatively, can be specified a string suffixed by "%" to indicate a percentage value compared to the pod number of PRIMARY | No | +| suffix | string | Suffix that should be used when naming the BASELINE variant's resources. Default is `baseline`. | No | +| createService | bool | Whether the BASELINE service should be created. Default is `false`. | No | + +### KubernetesBaselineCleanStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| +| | | | | + +### KubernetesTrafficRoutingStageOptions +This stage routes traffic with the method specified in [KubernetesTrafficRouting](#kubernetestrafficrouting). +When using `podselector` method as a traffic routing method, routing is done by updating the Service selector. +Therefore, note that all traffic will be routed to the primary if the the primary variant's service is rolled out by running the `K8S_PRIMARY_ROLLOUT` stage. + +| Field | Type | Description | Required | +|-|-|-|-| +| all | string | Which variant should receive all traffic. Available values are "primary", "canary", "baseline". Default is `primary`. | No | +| primary | [Percentage](#percentage) | The percentage of traffic should be routed to PRIMARY variant. | No | +| canary | [Percentage](#percentage) | The percentage of traffic should be routed to CANARY variant. | No | +| baseline | [Percentage](#percentage) | The percentage of traffic should be routed to BASELINE variant. | No | + +### TerraformPlanStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| +| exitOnNoChanges | bool | Whether exiting the pipeline when the result has no changes | No | + +### TerraformApplyStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| +| retries | int | How many times to retry applying terraform changes. Default is `0`. | No | + +### CloudRunPromoteStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| +| percent | [Percentage](#percentage) | Percentage of traffic should be routed to the new version. | No | + +### LambdaCanaryRolloutStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| + +### LambdaPromoteStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| +| percent | [Percentage](#percentage) | Percentage of traffic should be routed to the new version. | No | + +### ECSPrimaryRolloutStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| + +### ECSCanaryRolloutStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| +| scale | [Percentage](#percentage) | The percentage of workloads should be rolled out as CANARY variant's workload. | Yes | + +### ECSTrafficRoutingStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| +| primary | [Percentage](#percentage) | The percentage of traffic should be routed to PRIMARY variant. | No | +| canary | [Percentage](#percentage) | The percentage of traffic should be routed to CANARY variant. | No | + +Note: By default, the sum of traffic is rounded to 100. If both `primary` and `canary` numbers are not set, the PRIMARY variant will receive 100% while the CANARY variant will receive 0% of the traffic. + +### AnalysisStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| +| duration | duration | Maximum time to perform the analysis. | Yes | +| metrics | [][AnalysisMetrics](#analysismetrics) | Configuration for analysis by metrics. | No | + +### WaitStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| +| duration | duration | Time to wait. | Yes | + +### WaitApprovalStageOptions + +| Field | Type | Description | Required | +|-|-|-|-| +| timeout | duration | The maximum length of time to wait before giving up. Default is 6h. | No | +| approvers | []string | List of username who has permission to approve. | Yes | +| minApproverNum | int | Number of minimum needed approvals to make this stage complete. Default is 1. | No | + +### CustomSyncStageOptions +| Field | Type | Description | Required | +|-|-|-|-| +| timeout | duration | The maximum time the stage can be taken to run. Default is `6h`| No | +| envs | map[string]string | Environment variables used with scripts. | No | +| run | string | Script run on this stage. | Yes | + +## PostSync + +| Field | Type | Description | Required | +|-|-|-|-| +| chain | [DeploymentChain](#deploymentchain) | Deployment chain configuration, used to determine and build deployments that should be triggered once the current deployment is triggered. | No | + +### DeploymentChain + +| Field | Type | Description | Required | +|-|-|-|-| +| applications | [][DeploymentChainApplication](#deploymentchainapplication) | The list of applications which should be triggered once deployment of this application rolled out successfully. | Yes | + +#### DeploymentChainApplication + +| Field | Type | Description | Required | +|-|-|-|-| +| name | string | The name of PipeCD application, note that application name is not unique in PipeCD datastore | No | +| kind | string | The kind of the PipeCD application, which should be triggered as a node in deployment chain. The value will be one of: KUBERNETES, TERRAFORM, CLOUDRUN, LAMBDA, ECS. | No | + +## EventWatcher + +| Field | Type | Description | Required | +|-|-|-|-| +| matcher | [EventWatcherMatcher](#eventwatchermatcher) | Which event will be handled. | Yes | +| handler | [EventWatcherHandler](#eventwatcherhandler) | What to do for the event which matched by the above matcher. | Yes | + +### EventWatcherMatcher + +| Field | Type | Description | Required | +|-|-|-|-| +| name | string | The event name. | Yes | +| labels | map[string]string | Additional attributes of event. This can make an event definition unique even if the one with the same name exists. | No | + +### EventWatcherHandler + +| Field | Type | Description | Required | +|-|-|-|-| +| type | string | The handler type. Currently, only `GIT_UPDATE` is supported. | Yes | +| config | [EventWatcherHandlerConfig](#eventwatcherhandlerconfig) | Configuration for the event watcher handler. | Yes | + +### EventWatcherHandlerConfig + +| Field | Type | Description | Required | +|-|-|-|-| +| commitMessage | string | The commit message used to push after replacing values. Default message is used if not given. | No | +| createPullRequest | bool | Whether to create a new branch or not when commit changes in event watcher. | No | +| replacements | [][EventWatcherReplacement](#eventwatcherreplacement) | List of places where will be replaced when the new event matches. | Yes | + +## DriftDetection + +| Field | Type | Description | Required | +|-|-|-|-| +| ignoreFields | []string | List of fields path in manifests, which its diff should be ignored. | No | + +## PipeCD rich defined types + +### Percentage +A wrapper of type `int` to represent percentage data. Basically, you can pass `10` or `"10"` or `10%` and they will be treated as `10%` in PipeCD. + +### KubernetesResourcePatch + +| Field | Type | Description | Required | +|-|-|-|-| +| target | [KubernetesResourcePatchTarget](#kubernetesresourcepatchtarget) | Which manifest, which field will be the target of patch operations. | Yes | +| ops | [][KubernetesResourcePatchOp](#kubernetesresourcepatchop) | List of operations should be applied to the above target. | No | + +### KubernetesResourcePatchTarget + +| Field | Type | Description | Required | +|-|-|-|-| +| kind | string | The resource kind. e.g. `ConfigMap` | Yes | +| name | string | The resource name. e.g. `config-map-name` | Yes | +| documentRoot | string | In case you want to manipulate the YAML or JSON data specified in a field of the manfiest, 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. e.g. `$.data.envoy-config` | No | + +### KubernetesResourcePatchOp + +| Field | Type | Description | Required | +|-|-|-|-| +| op | string | The operation type. This must be one of `yaml-replace`, `yaml-add`, `yaml-remove`, `json-replace`, `text-regex`. Default is `yaml-replace`. | No | +| path | string | The path string pointing to the manipulated field. For yaml operations it looks like `$.foo.array[0].bar`. | No | +| value | string | The value string whose content will be used as new value for the field. | No | diff --git a/docs/content/en/docs/user-guide/managing-piped/configuration-reference.md b/docs/content/en/docs/user-guide/managing-piped/configuration-reference.md index e3438a13c0..003776225c 100644 --- a/docs/content/en/docs/user-guide/managing-piped/configuration-reference.md +++ b/docs/content/en/docs/user-guide/managing-piped/configuration-reference.md @@ -49,7 +49,6 @@ spec: | hostName | string | The hostname or IP address of the remote git server. Default is the same value with Host. | No | | sshKeyFile | string | The path to the private ssh key file. This will be used to clone the source code of the specified git repositories. | No | | sshKeyData | string | Base64 encoded string of SSH key. | No | -| enableNewBranch | bool | Whether to create a new branch or not when commit changes in event watcher. | No | ## GitRepository diff --git a/pkg/app/piped/eventwatcher/eventwatcher.go b/pkg/app/piped/eventwatcher/eventwatcher.go index 9cac050288..de3972ce13 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher.go +++ b/pkg/app/piped/eventwatcher/eventwatcher.go @@ -387,7 +387,7 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve switch handler.Type { case config.EventWatcherHandlerTypeGitUpdate: - if err := w.commitFiles(ctx, latestEvent.Data, matcher.Name, handler.Config.CommitMessage, e.GitPath, handler.Config.Replacements, tmpRepo); err != nil { + if err := w.commitFiles(ctx, latestEvent.Data, matcher.Name, handler.Config.CommitMessage, e.GitPath, handler.Config.Replacements, tmpRepo, handler.Config.CreatePullRequest); err != nil { w.logger.Error("failed to commit outdated files", zap.Error(err)) handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{ Id: latestEvent.Id, @@ -531,7 +531,7 @@ func (w *watcher) updateValues(ctx context.Context, repo git.Repo, repoID string }) continue } - if err := w.commitFiles(ctx, latestEvent.Data, e.Name, commitMsg, "", e.Replacements, tmpRepo); err != nil { + if err := w.commitFiles(ctx, latestEvent.Data, e.Name, commitMsg, "", e.Replacements, tmpRepo, e.CreatePullRequest); err != nil { w.logger.Error("failed to commit outdated files", zap.Error(err)) handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{ Id: latestEvent.Id, @@ -594,7 +594,7 @@ func (w *watcher) updateValues(ctx context.Context, repo git.Repo, repoID string } // commitFiles commits changes if the data in Git is different from the latest event. -func (w *watcher) commitFiles(ctx context.Context, latestData, eventName, commitMsg, gitPath string, replacements []config.EventWatcherReplacement, repo git.Repo) error { +func (w *watcher) commitFiles(ctx context.Context, latestData, eventName, commitMsg, gitPath string, replacements []config.EventWatcherReplacement, repo git.Repo, newBranch bool) error { // Determine files to be changed by comparing with the latest event. changes := make(map[string][]byte, len(replacements)) for _, r := range replacements { @@ -640,8 +640,8 @@ func (w *watcher) commitFiles(ctx context.Context, latestData, eventName, commit EventName: eventName, } commitMsg = parseCommitMsg(commitMsg, args) - branch := getBranchName(w.config.Git.EnableNewBranch, eventName, repo.GetClonedBranch()) - if err := repo.CommitChanges(ctx, branch, commitMsg, w.config.Git.EnableNewBranch, changes); err != nil { + branch := getBranchName(newBranch, eventName, repo.GetClonedBranch()) + if err := repo.CommitChanges(ctx, branch, commitMsg, newBranch, changes); err != nil { return fmt.Errorf("failed to perform git commit: %w", err) } w.logger.Info(fmt.Sprintf("event watcher will update values of Event %q", eventName)) diff --git a/pkg/config/event_watcher.go b/pkg/config/event_watcher.go index aac4e67e88..3d446bd460 100644 --- a/pkg/config/event_watcher.go +++ b/pkg/config/event_watcher.go @@ -31,6 +31,8 @@ type EventWatcherSpec struct { type EventWatcherEvent struct { // The event name. Name string `json:"name"` + // Whether to create a new branch or not when event watcher commits changes. + CreatePullRequest bool `json:"createPullRequest,omitempty"` // Additional attributes of event. This can make an event definition // unique even if the one with the same name exists. Labels map[string]string `json:"labels"` @@ -64,6 +66,8 @@ type EventWatcherHandlerConfig struct { // The commit message used to push after replacing values. // Default message is used if not given. CommitMessage string `json:"commitMessage,omitempty"` + // Whether to create a new branch or not when event watcher commits changes. + CreatePullRequest bool `json:"createPullRequest,omitempty"` // List of places where will be replaced when the new event matches. Replacements []EventWatcherReplacement `json:"replacements"` } diff --git a/pkg/config/piped.go b/pkg/config/piped.go index e7d504522f..911dad6971 100644 --- a/pkg/config/piped.go +++ b/pkg/config/piped.go @@ -326,8 +326,6 @@ type PipedGit struct { SSHKeyFile string `json:"sshKeyFile,omitempty"` // Base64 encoded string of ssh-key. SSHKeyData string `json:"sshKeyData,omitempty"` - // Whether to create a new branch or not when commit changes in event watcher. - EnableNewBranch bool `json:"enableNewBranch,omitempty"` } func (g PipedGit) ShouldConfigureSSHConfig() bool { diff --git a/pkg/config/piped_test.go b/pkg/config/piped_test.go index 0ead74edb1..d9ce0f837c 100644 --- a/pkg/config/piped_test.go +++ b/pkg/config/piped_test.go @@ -45,10 +45,9 @@ func TestPipedConfig(t *testing.T) { SyncInterval: Duration(time.Minute), AppConfigSyncInterval: Duration(time.Minute), Git: PipedGit{ - Username: "username", - Email: "username@email.com", - SSHKeyFile: "/etc/piped-secret/ssh-key", - EnableNewBranch: true, + Username: "username", + Email: "username@email.com", + SSHKeyFile: "/etc/piped-secret/ssh-key", }, Repositories: []PipedRepository{ { @@ -542,7 +541,6 @@ func TestPipedConfigMask(t *testing.T) { HostName: "foo", SSHKeyFile: "foo", SSHKeyData: "foo", - EnableNewBranch: true, }, Repositories: []PipedRepository{ { @@ -706,7 +704,6 @@ func TestPipedConfigMask(t *testing.T) { HostName: "foo", SSHKeyFile: maskString, SSHKeyData: maskString, - EnableNewBranch: true, }, Repositories: []PipedRepository{ { diff --git a/pkg/config/testdata/piped/piped-config.yaml b/pkg/config/testdata/piped/piped-config.yaml index 35e25eea9b..39273652ae 100644 --- a/pkg/config/testdata/piped/piped-config.yaml +++ b/pkg/config/testdata/piped/piped-config.yaml @@ -12,7 +12,6 @@ spec: username: username email: username@email.com sshKeyFile: /etc/piped-secret/ssh-key - enableNewBranch: true repositories: - repoId: repo1 From f641153c140032d429cc5a8dd1b3fcbcb37ef54c Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Thu, 22 Jun 2023 16:33:34 +0900 Subject: [PATCH 03/18] fix test Signed-off-by: nnnkkk7 --- pkg/app/piped/eventwatcher/eventwatcher_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/app/piped/eventwatcher/eventwatcher_test.go b/pkg/app/piped/eventwatcher/eventwatcher_test.go index 3983fa4a6a..e88e616cb2 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher_test.go +++ b/pkg/app/piped/eventwatcher/eventwatcher_test.go @@ -267,7 +267,9 @@ func TestGetBranchName(t *testing.T) { }, } for _, tc := range testcases { + tc := tc t.Run(tc.name, func(t *testing.T) { + t.Parallel() got := getBranchName(tc.newBranch, tc.eventName, tc.branch) if tc.newBranch { assert.NotEqual(t, tc.branch, got) From 732e620a14d85238001d9a2b7e81b2f2cb08ef93 Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Thu, 22 Jun 2023 16:40:34 +0900 Subject: [PATCH 04/18] push commit if the branch is new in event watcher Signed-off-by: nnnkkk7 --- pkg/app/piped/eventwatcher/eventwatcher.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/app/piped/eventwatcher/eventwatcher.go b/pkg/app/piped/eventwatcher/eventwatcher.go index de3972ce13..2d25df7d90 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher.go +++ b/pkg/app/piped/eventwatcher/eventwatcher.go @@ -644,6 +644,11 @@ func (w *watcher) commitFiles(ctx context.Context, latestData, eventName, commit if err := repo.CommitChanges(ctx, branch, commitMsg, newBranch, changes); err != nil { return fmt.Errorf("failed to perform git commit: %w", err) } + if newBranch { + if err := repo.Push(ctx, branch); err != nil { + return fmt.Errorf("failed to perform git push: %w", err) + } + } w.logger.Info(fmt.Sprintf("event watcher will update values of Event %q", eventName)) return nil } From b11434a94b4b31ab26308355f8943085be1a00b0 Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Fri, 23 Jun 2023 10:54:08 +0900 Subject: [PATCH 05/18] fix docs-v0.43.x Signed-off-by: nnnkkk7 --- .../en/docs-v0.43.x/user-guide/configuration-reference.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/content/en/docs-v0.43.x/user-guide/configuration-reference.md b/docs/content/en/docs-v0.43.x/user-guide/configuration-reference.md index a1838d17d1..f3881a357b 100644 --- a/docs/content/en/docs-v0.43.x/user-guide/configuration-reference.md +++ b/docs/content/en/docs-v0.43.x/user-guide/configuration-reference.md @@ -181,6 +181,7 @@ spec: | Field | Type | Description | Required | |-|-|-|-| | name | string | The event name. | Yes | +| createPullRequest | bool | Whether to create a new branch or not when commit changes in event watcher. | No | | labels | map[string]string | Additional attributes of event. This can make an event definition unique even if the one with the same name exists. | No | | replacements | [][EventWatcherReplacement](#eventwatcherreplacement) | List of places where will be replaced when the new event matches. | Yes | @@ -655,6 +656,7 @@ Note: By default, the sum of traffic is rounded to 100. If both `primary` and `c | Field | Type | Description | Required | |-|-|-|-| | commitMessage | string | The commit message used to push after replacing values. Default message is used if not given. | No | +| createPullRequest | bool | Whether to create a new branch or not when commit changes in event watcher. | No | | replacements | [][EventWatcherReplacement](#eventwatcherreplacement) | List of places where will be replaced when the new event matches. | Yes | ## DriftDetection From 5461c5ac4b7dd703cf8298da502bf13da94017f9 Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Mon, 26 Jun 2023 13:46:30 +0900 Subject: [PATCH 06/18] fix docs Signed-off-by: nnnkkk7 --- docs/content/en/docs-dev/user-guide/configuration-reference.md | 3 +-- .../en/docs-v0.43.x/user-guide/configuration-reference.md | 2 -- docs/content/en/docs/user-guide/configuration-reference.md | 2 -- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/docs/content/en/docs-dev/user-guide/configuration-reference.md b/docs/content/en/docs-dev/user-guide/configuration-reference.md index 57b0c29de7..4450461fa1 100644 --- a/docs/content/en/docs-dev/user-guide/configuration-reference.md +++ b/docs/content/en/docs-dev/user-guide/configuration-reference.md @@ -197,7 +197,6 @@ spec: | Field | Type | Description | Required | |-|-|-|-| | name | string | The event name. | Yes | -| createPullRequest | bool | Whether to create a new branch or not when commit changes in event watcher. | No | | labels | map[string]string | Additional attributes of event. This can make an event definition unique even if the one with the same name exists. | No | | replacements | [][EventWatcherReplacement](#eventwatcherreplacement) | List of places where will be replaced when the new event matches. | Yes | @@ -700,7 +699,7 @@ Note: By default, the sum of traffic is rounded to 100. If both `primary` and `c | Field | Type | Description | Required | |-|-|-|-| | commitMessage | string | The commit message used to push after replacing values. Default message is used if not given. | No | -| createPullRequest | bool | Whether to create a new branch or not when commit changes in event watcher. | No | +| makePullRequest | bool | Whether to create a new branch or not when commit changes in event watcher. Default is `false`. | No | | replacements | [][EventWatcherReplacement](#eventwatcherreplacement) | List of places where will be replaced when the new event matches. | Yes | ## DriftDetection diff --git a/docs/content/en/docs-v0.43.x/user-guide/configuration-reference.md b/docs/content/en/docs-v0.43.x/user-guide/configuration-reference.md index f3881a357b..a1838d17d1 100644 --- a/docs/content/en/docs-v0.43.x/user-guide/configuration-reference.md +++ b/docs/content/en/docs-v0.43.x/user-guide/configuration-reference.md @@ -181,7 +181,6 @@ spec: | Field | Type | Description | Required | |-|-|-|-| | name | string | The event name. | Yes | -| createPullRequest | bool | Whether to create a new branch or not when commit changes in event watcher. | No | | labels | map[string]string | Additional attributes of event. This can make an event definition unique even if the one with the same name exists. | No | | replacements | [][EventWatcherReplacement](#eventwatcherreplacement) | List of places where will be replaced when the new event matches. | Yes | @@ -656,7 +655,6 @@ Note: By default, the sum of traffic is rounded to 100. If both `primary` and `c | Field | Type | Description | Required | |-|-|-|-| | commitMessage | string | The commit message used to push after replacing values. Default message is used if not given. | No | -| createPullRequest | bool | Whether to create a new branch or not when commit changes in event watcher. | No | | replacements | [][EventWatcherReplacement](#eventwatcherreplacement) | List of places where will be replaced when the new event matches. | Yes | ## DriftDetection diff --git a/docs/content/en/docs/user-guide/configuration-reference.md b/docs/content/en/docs/user-guide/configuration-reference.md index a1316f6326..cf298d5d9d 100644 --- a/docs/content/en/docs/user-guide/configuration-reference.md +++ b/docs/content/en/docs/user-guide/configuration-reference.md @@ -187,7 +187,6 @@ spec: | Field | Type | Description | Required | |-|-|-|-| | name | string | The event name. | Yes | -| createPullRequest | bool | Whether to create a new branch or not when commit changes in event watcher. | No | | labels | map[string]string | Additional attributes of event. This can make an event definition unique even if the one with the same name exists. | No | | replacements | [][EventWatcherReplacement](#eventwatcherreplacement) | List of places where will be replaced when the new event matches. | Yes | @@ -676,7 +675,6 @@ Note: By default, the sum of traffic is rounded to 100. If both `primary` and `c | Field | Type | Description | Required | |-|-|-|-| | commitMessage | string | The commit message used to push after replacing values. Default message is used if not given. | No | -| createPullRequest | bool | Whether to create a new branch or not when commit changes in event watcher. | No | | replacements | [][EventWatcherReplacement](#eventwatcherreplacement) | List of places where will be replaced when the new event matches. | Yes | ## DriftDetection From c2662a34207134b71422a0e26c0fe766f7bcfa4f Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Mon, 26 Jun 2023 13:50:24 +0900 Subject: [PATCH 07/18] replace createPullRequest with makePullRequest Signed-off-by: nnnkkk7 --- pkg/app/piped/eventwatcher/eventwatcher.go | 4 ++-- pkg/config/event_watcher.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/app/piped/eventwatcher/eventwatcher.go b/pkg/app/piped/eventwatcher/eventwatcher.go index 2d25df7d90..40ebe408f1 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher.go +++ b/pkg/app/piped/eventwatcher/eventwatcher.go @@ -387,7 +387,7 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve switch handler.Type { case config.EventWatcherHandlerTypeGitUpdate: - if err := w.commitFiles(ctx, latestEvent.Data, matcher.Name, handler.Config.CommitMessage, e.GitPath, handler.Config.Replacements, tmpRepo, handler.Config.CreatePullRequest); err != nil { + if err := w.commitFiles(ctx, latestEvent.Data, matcher.Name, handler.Config.CommitMessage, e.GitPath, handler.Config.Replacements, tmpRepo, handler.Config.MakePullRequest); err != nil { w.logger.Error("failed to commit outdated files", zap.Error(err)) handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{ Id: latestEvent.Id, @@ -531,7 +531,7 @@ func (w *watcher) updateValues(ctx context.Context, repo git.Repo, repoID string }) continue } - if err := w.commitFiles(ctx, latestEvent.Data, e.Name, commitMsg, "", e.Replacements, tmpRepo, e.CreatePullRequest); err != nil { + if err := w.commitFiles(ctx, latestEvent.Data, e.Name, commitMsg, "", e.Replacements, tmpRepo, e.MakePullRequest); err != nil { w.logger.Error("failed to commit outdated files", zap.Error(err)) handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{ Id: latestEvent.Id, diff --git a/pkg/config/event_watcher.go b/pkg/config/event_watcher.go index 3d446bd460..5c2b566138 100644 --- a/pkg/config/event_watcher.go +++ b/pkg/config/event_watcher.go @@ -32,7 +32,7 @@ type EventWatcherEvent struct { // The event name. Name string `json:"name"` // Whether to create a new branch or not when event watcher commits changes. - CreatePullRequest bool `json:"createPullRequest,omitempty"` + MakePullRequest bool `json:"makePullRequest,omitempty"` // Additional attributes of event. This can make an event definition // unique even if the one with the same name exists. Labels map[string]string `json:"labels"` @@ -67,7 +67,7 @@ type EventWatcherHandlerConfig struct { // Default message is used if not given. CommitMessage string `json:"commitMessage,omitempty"` // Whether to create a new branch or not when event watcher commits changes. - CreatePullRequest bool `json:"createPullRequest,omitempty"` + MakePullRequest bool `json:"makePullRequest,omitempty"` // List of places where will be replaced when the new event matches. Replacements []EventWatcherReplacement `json:"replacements"` } From 8a03c1b88339ccce75913e6d05ed40fb391819cd Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Mon, 26 Jun 2023 13:51:48 +0900 Subject: [PATCH 08/18] renamed getBranchName to makeBranchName Signed-off-by: nnnkkk7 --- pkg/app/piped/eventwatcher/eventwatcher.go | 6 +++--- pkg/app/piped/eventwatcher/eventwatcher_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/app/piped/eventwatcher/eventwatcher.go b/pkg/app/piped/eventwatcher/eventwatcher.go index 40ebe408f1..a8af72096a 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher.go +++ b/pkg/app/piped/eventwatcher/eventwatcher.go @@ -640,7 +640,7 @@ func (w *watcher) commitFiles(ctx context.Context, latestData, eventName, commit EventName: eventName, } commitMsg = parseCommitMsg(commitMsg, args) - branch := getBranchName(newBranch, eventName, repo.GetClonedBranch()) + branch := makeBranchName(newBranch, eventName, repo.GetClonedBranch()) if err := repo.CommitChanges(ctx, branch, commitMsg, newBranch, changes); err != nil { return fmt.Errorf("failed to perform git commit: %w", err) } @@ -785,9 +785,9 @@ func parseCommitMsg(msg string, args argsTemplate) string { return buf.String() } -// getBranchName generates a new branch name in the format {eventName}-{uuid} if newBranch is true. +// makeBranchName generates a new branch name in the format {eventName}-{uuid} if newBranch is true. // If newBranch is false, the function returns the existing branch name. -func getBranchName(newBranch bool, eventName, branch string) string { +func makeBranchName(newBranch bool, eventName, branch string) string { if !newBranch { return branch } diff --git a/pkg/app/piped/eventwatcher/eventwatcher_test.go b/pkg/app/piped/eventwatcher/eventwatcher_test.go index e88e616cb2..aa7750ba72 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher_test.go +++ b/pkg/app/piped/eventwatcher/eventwatcher_test.go @@ -270,7 +270,7 @@ func TestGetBranchName(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() - got := getBranchName(tc.newBranch, tc.eventName, tc.branch) + got := makeBranchName(tc.newBranch, tc.eventName, tc.branch) if tc.newBranch { assert.NotEqual(t, tc.branch, got) } else { From 7ee221f808223179caa8b718cd420d6859b3a21c Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Mon, 26 Jun 2023 14:54:05 +0900 Subject: [PATCH 09/18] remove makePullRequest from EventWatcherEvent Signed-off-by: nnnkkk7 --- pkg/app/piped/eventwatcher/eventwatcher.go | 2 +- pkg/config/event_watcher.go | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/app/piped/eventwatcher/eventwatcher.go b/pkg/app/piped/eventwatcher/eventwatcher.go index a8af72096a..63367839ff 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher.go +++ b/pkg/app/piped/eventwatcher/eventwatcher.go @@ -531,7 +531,7 @@ func (w *watcher) updateValues(ctx context.Context, repo git.Repo, repoID string }) continue } - if err := w.commitFiles(ctx, latestEvent.Data, e.Name, commitMsg, "", e.Replacements, tmpRepo, e.MakePullRequest); err != nil { + if err := w.commitFiles(ctx, latestEvent.Data, e.Name, commitMsg, "", e.Replacements, tmpRepo, false); err != nil { w.logger.Error("failed to commit outdated files", zap.Error(err)) handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{ Id: latestEvent.Id, diff --git a/pkg/config/event_watcher.go b/pkg/config/event_watcher.go index 5c2b566138..45b41c7876 100644 --- a/pkg/config/event_watcher.go +++ b/pkg/config/event_watcher.go @@ -31,8 +31,6 @@ type EventWatcherSpec struct { type EventWatcherEvent struct { // The event name. Name string `json:"name"` - // Whether to create a new branch or not when event watcher commits changes. - MakePullRequest bool `json:"makePullRequest,omitempty"` // Additional attributes of event. This can make an event definition // unique even if the one with the same name exists. Labels map[string]string `json:"labels"` From 2863efeb220c571b66c2320b459993437810191c Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Mon, 26 Jun 2023 15:51:10 +0900 Subject: [PATCH 10/18] retry push commits in execute func Signed-off-by: nnnkkk7 --- pkg/app/piped/eventwatcher/eventwatcher.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pkg/app/piped/eventwatcher/eventwatcher.go b/pkg/app/piped/eventwatcher/eventwatcher.go index 63367839ff..f1fccb4914 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher.go +++ b/pkg/app/piped/eventwatcher/eventwatcher.go @@ -396,6 +396,23 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve }) continue } + if handler.Config.MakePullRequest { + retry := backoff.NewRetry(retryPushNum, backoff.NewConstant(retryPushInterval)) + _, err = retry.Do(ctx, func() (interface{}, error) { + err := tmpRepo.Push(ctx, tmpRepo.GetClonedBranch()) + return nil, err + }) + if err != nil { + w.logger.Error("failed to push commits", zap.Error(err)) + handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{ + Id: latestEvent.Id, + Status: model.EventStatus_EVENT_FAILURE, + StatusDescription: fmt.Sprintf("Failed to push commits: %v", err), + }) + continue + } + + } handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{ Id: latestEvent.Id, Status: model.EventStatus_EVENT_SUCCESS, @@ -644,11 +661,6 @@ func (w *watcher) commitFiles(ctx context.Context, latestData, eventName, commit if err := repo.CommitChanges(ctx, branch, commitMsg, newBranch, changes); err != nil { return fmt.Errorf("failed to perform git commit: %w", err) } - if newBranch { - if err := repo.Push(ctx, branch); err != nil { - return fmt.Errorf("failed to perform git push: %w", err) - } - } w.logger.Info(fmt.Sprintf("event watcher will update values of Event %q", eventName)) return nil } From ddd47e10427149fc9374d75b1a89b6bbe9b93328 Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Fri, 7 Jul 2023 15:30:05 +0900 Subject: [PATCH 11/18] fix how to push new branch Signed-off-by: nnnkkk7 --- pkg/app/piped/eventwatcher/eventwatcher.go | 67 +++++++++++----------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/pkg/app/piped/eventwatcher/eventwatcher.go b/pkg/app/piped/eventwatcher/eventwatcher.go index f1fccb4914..69d13cd060 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher.go +++ b/pkg/app/piped/eventwatcher/eventwatcher.go @@ -330,11 +330,13 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve firstRead = false } var ( - handledEvents = make([]*pipedservice.ReportEventStatusesRequest_Event, 0, len(eventCfgs)) - outDatedEvents = make([]*pipedservice.ReportEventStatusesRequest_Event, 0) - maxTimestamp int64 - outDatedDuration = time.Hour - gitUpdateEvent = false + handledEvents = make([]*pipedservice.ReportEventStatusesRequest_Event, 0, len(eventCfgs)) + outDatedEvents = make([]*pipedservice.ReportEventStatusesRequest_Event, 0) + maxTimestamp int64 + outDatedDuration = time.Hour + gitUpdateEvent = false + newBranchs = make([]string, 0, len(eventCfgs)) + isExistDefaultBranch bool ) for _, e := range eventCfgs { for _, cfg := range e.Configs { @@ -342,6 +344,9 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve matcher = cfg.Matcher handler = cfg.Handler ) + if handler.Config.MakePullRequest { + isExistDefaultBranch = true + } notHandledEvents := w.eventLister.ListNotHandled(matcher.Name, matcher.Labels, milestone+1, numToMakeOutdated) if len(notHandledEvents) == 0 { continue @@ -384,10 +389,10 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve }) continue } - switch handler.Type { case config.EventWatcherHandlerTypeGitUpdate: - if err := w.commitFiles(ctx, latestEvent.Data, matcher.Name, handler.Config.CommitMessage, e.GitPath, handler.Config.Replacements, tmpRepo, handler.Config.MakePullRequest); err != nil { + branchName, err := w.commitFiles(ctx, latestEvent.Data, matcher.Name, handler.Config.CommitMessage, e.GitPath, handler.Config.Replacements, tmpRepo, handler.Config.MakePullRequest) + if err != nil { w.logger.Error("failed to commit outdated files", zap.Error(err)) handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{ Id: latestEvent.Id, @@ -397,21 +402,7 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve continue } if handler.Config.MakePullRequest { - retry := backoff.NewRetry(retryPushNum, backoff.NewConstant(retryPushInterval)) - _, err = retry.Do(ctx, func() (interface{}, error) { - err := tmpRepo.Push(ctx, tmpRepo.GetClonedBranch()) - return nil, err - }) - if err != nil { - w.logger.Error("failed to push commits", zap.Error(err)) - handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{ - Id: latestEvent.Id, - Status: model.EventStatus_EVENT_FAILURE, - StatusDescription: fmt.Sprintf("Failed to push commits: %v", err), - }) - continue - } - + newBranchs = append(newBranchs, branchName) } handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{ Id: latestEvent.Id, @@ -446,10 +437,19 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve } retry := backoff.NewRetry(retryPushNum, backoff.NewConstant(retryPushInterval)) - _, err = retry.Do(ctx, func() (interface{}, error) { - err := tmpRepo.Push(ctx, tmpRepo.GetClonedBranch()) - return nil, err - }) + for _, branch := range newBranchs { + _, err = retry.Do(ctx, func() (interface{}, error) { + err := tmpRepo.Push(ctx, branch) + return nil, err + }) + } + if isExistDefaultBranch { + _, err = retry.Do(ctx, func() (interface{}, error) { + err := tmpRepo.Push(ctx, repo.GetClonedBranch()) + return nil, err + }) + } + if err == nil { if _, err := w.apiClient.ReportEventStatuses(ctx, &pipedservice.ReportEventStatusesRequest{Events: handledEvents}); err != nil { return fmt.Errorf("failed to report event statuses: %w", err) @@ -548,7 +548,8 @@ func (w *watcher) updateValues(ctx context.Context, repo git.Repo, repoID string }) continue } - if err := w.commitFiles(ctx, latestEvent.Data, e.Name, commitMsg, "", e.Replacements, tmpRepo, false); err != nil { + _, err := w.commitFiles(ctx, latestEvent.Data, e.Name, commitMsg, "", e.Replacements, tmpRepo, false) + if err != nil { w.logger.Error("failed to commit outdated files", zap.Error(err)) handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{ Id: latestEvent.Id, @@ -611,7 +612,7 @@ func (w *watcher) updateValues(ctx context.Context, repo git.Repo, repoID string } // commitFiles commits changes if the data in Git is different from the latest event. -func (w *watcher) commitFiles(ctx context.Context, latestData, eventName, commitMsg, gitPath string, replacements []config.EventWatcherReplacement, repo git.Repo, newBranch bool) error { +func (w *watcher) commitFiles(ctx context.Context, latestData, eventName, commitMsg, gitPath string, replacements []config.EventWatcherReplacement, repo git.Repo, newBranch bool) (string, error) { // Determine files to be changed by comparing with the latest event. changes := make(map[string][]byte, len(replacements)) for _, r := range replacements { @@ -637,19 +638,19 @@ func (w *watcher) commitFiles(ctx context.Context, latestData, eventName, commit newContent, upToDate, err = modifyText(path, r.Regex, latestData) } if err != nil { - return err + return "", err } if upToDate { continue } if err := os.WriteFile(path, newContent, os.ModePerm); err != nil { - return fmt.Errorf("failed to write file: %w", err) + return "", fmt.Errorf("failed to write file: %w", err) } changes[filePath] = newContent } if len(changes) == 0 { - return nil + return "", nil } args := argsTemplate{ @@ -659,10 +660,10 @@ func (w *watcher) commitFiles(ctx context.Context, latestData, eventName, commit commitMsg = parseCommitMsg(commitMsg, args) branch := makeBranchName(newBranch, eventName, repo.GetClonedBranch()) if err := repo.CommitChanges(ctx, branch, commitMsg, newBranch, changes); err != nil { - return fmt.Errorf("failed to perform git commit: %w", err) + return "", fmt.Errorf("failed to perform git commit: %w", err) } w.logger.Info(fmt.Sprintf("event watcher will update values of Event %q", eventName)) - return nil + return branch, nil } // modifyYAML returns a new YAML content as a first returned value if the value of given From 1ba6cc86d8abb01796b1b1c6a19c2bd19e5ec238 Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Fri, 7 Jul 2023 18:23:58 +0900 Subject: [PATCH 12/18] use map for branchname Signed-off-by: nnnkkk7 --- pkg/app/piped/eventwatcher/eventwatcher.go | 28 +++++++--------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/pkg/app/piped/eventwatcher/eventwatcher.go b/pkg/app/piped/eventwatcher/eventwatcher.go index 69d13cd060..1d34ef3302 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher.go +++ b/pkg/app/piped/eventwatcher/eventwatcher.go @@ -330,13 +330,12 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve firstRead = false } var ( - handledEvents = make([]*pipedservice.ReportEventStatusesRequest_Event, 0, len(eventCfgs)) - outDatedEvents = make([]*pipedservice.ReportEventStatusesRequest_Event, 0) - maxTimestamp int64 - outDatedDuration = time.Hour - gitUpdateEvent = false - newBranchs = make([]string, 0, len(eventCfgs)) - isExistDefaultBranch bool + handledEvents = make([]*pipedservice.ReportEventStatusesRequest_Event, 0, len(eventCfgs)) + outDatedEvents = make([]*pipedservice.ReportEventStatusesRequest_Event, 0) + maxTimestamp int64 + outDatedDuration = time.Hour + gitUpdateEvent = false + branchNames = make(map[string]bool, len(eventCfgs)) ) for _, e := range eventCfgs { for _, cfg := range e.Configs { @@ -344,9 +343,6 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve matcher = cfg.Matcher handler = cfg.Handler ) - if handler.Config.MakePullRequest { - isExistDefaultBranch = true - } notHandledEvents := w.eventLister.ListNotHandled(matcher.Name, matcher.Labels, milestone+1, numToMakeOutdated) if len(notHandledEvents) == 0 { continue @@ -401,9 +397,7 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve }) continue } - if handler.Config.MakePullRequest { - newBranchs = append(newBranchs, branchName) - } + branchNames[branchName] = true handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{ Id: latestEvent.Id, Status: model.EventStatus_EVENT_SUCCESS, @@ -437,18 +431,12 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve } retry := backoff.NewRetry(retryPushNum, backoff.NewConstant(retryPushInterval)) - for _, branch := range newBranchs { + for branch := range branchNames { _, err = retry.Do(ctx, func() (interface{}, error) { err := tmpRepo.Push(ctx, branch) return nil, err }) } - if isExistDefaultBranch { - _, err = retry.Do(ctx, func() (interface{}, error) { - err := tmpRepo.Push(ctx, repo.GetClonedBranch()) - return nil, err - }) - } if err == nil { if _, err := w.apiClient.ReportEventStatuses(ctx, &pipedservice.ReportEventStatusesRequest{Events: handledEvents}); err != nil { From 7cb265a27b02cfef1250808c911f0ab5ca9348e2 Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Sun, 9 Jul 2023 10:02:03 +0900 Subject: [PATCH 13/18] use branchHandledEvents map Signed-off-by: nnnkkk7 --- pkg/app/piped/eventwatcher/eventwatcher.go | 86 +++++++++++++--------- 1 file changed, 52 insertions(+), 34 deletions(-) diff --git a/pkg/app/piped/eventwatcher/eventwatcher.go b/pkg/app/piped/eventwatcher/eventwatcher.go index 1d34ef3302..146a662b62 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher.go +++ b/pkg/app/piped/eventwatcher/eventwatcher.go @@ -330,12 +330,12 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve firstRead = false } var ( - handledEvents = make([]*pipedservice.ReportEventStatusesRequest_Event, 0, len(eventCfgs)) - outDatedEvents = make([]*pipedservice.ReportEventStatusesRequest_Event, 0) - maxTimestamp int64 - outDatedDuration = time.Hour - gitUpdateEvent = false - branchNames = make(map[string]bool, len(eventCfgs)) + handledEvents = make([]*pipedservice.ReportEventStatusesRequest_Event, 0, len(eventCfgs)) + outDatedEvents = make([]*pipedservice.ReportEventStatusesRequest_Event, 0) + maxTimestamp int64 + outDatedDuration = time.Hour + gitUpdateEvent = false + branchHandledEvents = make(map[string][]*pipedservice.ReportEventStatusesRequest_Event, len(eventCfgs)) ) for _, e := range eventCfgs { for _, cfg := range e.Configs { @@ -390,19 +390,20 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve branchName, err := w.commitFiles(ctx, latestEvent.Data, matcher.Name, handler.Config.CommitMessage, e.GitPath, handler.Config.Replacements, tmpRepo, handler.Config.MakePullRequest) if err != nil { w.logger.Error("failed to commit outdated files", zap.Error(err)) - handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{ + handledEvent := &pipedservice.ReportEventStatusesRequest_Event{ Id: latestEvent.Id, Status: model.EventStatus_EVENT_FAILURE, StatusDescription: fmt.Sprintf("Failed to change files: %v", err), - }) + } + branchHandledEvents[branchName] = append(branchHandledEvents[branchName], handledEvent) continue } - branchNames[branchName] = true - handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{ + handledEvent := &pipedservice.ReportEventStatusesRequest_Event{ Id: latestEvent.Id, Status: model.EventStatus_EVENT_SUCCESS, StatusDescription: fmt.Sprintf("Successfully updated %d files in the %q repository", len(handler.Config.Replacements), repoID), - }) + } + branchHandledEvents[branchName] = append(branchHandledEvents[branchName], handledEvent) if latestEvent.CreatedAt > maxTimestamp { maxTimestamp = latestEvent.CreatedAt } @@ -430,41 +431,58 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve return nil } + var errors []error retry := backoff.NewRetry(retryPushNum, backoff.NewConstant(retryPushInterval)) - for branch := range branchNames { + for branch, events := range branchHandledEvents { _, err = retry.Do(ctx, func() (interface{}, error) { err := tmpRepo.Push(ctx, branch) return nil, err }) - } - if err == nil { - if _, err := w.apiClient.ReportEventStatuses(ctx, &pipedservice.ReportEventStatusesRequest{Events: handledEvents}); err != nil { - return fmt.Errorf("failed to report event statuses: %w", err) + if err == nil { + if _, err := w.apiClient.ReportEventStatuses(ctx, &pipedservice.ReportEventStatusesRequest{Events: events}); err != nil { + w.logger.Error("failed to report event statuses", zap.Error(err)) + } + w.executionMilestoneMap.Store(repoID, maxTimestamp) + continue } - w.executionMilestoneMap.Store(repoID, maxTimestamp) - return nil - } - - // If push fails because the local branch was not fresh, exit to retry again in the next interval. - if err == git.ErrBranchNotFresh { - w.logger.Warn("failed to push commits", zap.Error(err)) - return nil - } - // If push fails because of the other reason, re-set all statuses to FAILURE. - for i := range handledEvents { - if handledEvents[i].Status == model.EventStatus_EVENT_FAILURE { + // If push fails because the local branch was not fresh, exit to retry again in the next interval. + if err == git.ErrBranchNotFresh { + w.logger.Warn("failed to push commits", zap.Error(err)) continue } - handledEvents[i].Status = model.EventStatus_EVENT_FAILURE - handledEvents[i].StatusDescription = fmt.Sprintf("Failed to push changed files: %v", err) + + // If push fails because of the other reason, re-set all statuses to FAILURE. + for i := range handledEvents { + if events[i].Status == model.EventStatus_EVENT_FAILURE { + continue + } + events[i].Status = model.EventStatus_EVENT_FAILURE + events[i].StatusDescription = fmt.Sprintf("Failed to push changed files: %v", err) + } + if _, err := w.apiClient.ReportEventStatuses(ctx, &pipedservice.ReportEventStatusesRequest{Events: events}); err != nil { + w.logger.Error("failed to report event statuses", zap.Error(err)) + } + w.executionMilestoneMap.Store(repoID, maxTimestamp) + errors = append(errors, fmt.Errorf("failed to push commits: %w", err)) } - if _, err := w.apiClient.ReportEventStatuses(ctx, &pipedservice.ReportEventStatusesRequest{Events: handledEvents}); err != nil { - return fmt.Errorf("failed to report event statuses: %w", err) + if len(errors) > 0 { + return responseError(errors) } - w.executionMilestoneMap.Store(repoID, maxTimestamp) - return fmt.Errorf("failed to push commits: %w", err) + return nil +} + +// responseError is an error wrapping errors. +type responseError []error + +// Error returns a concatenation of all the error messages it wraps. +func (r responseError) Error() string { + var msgs []string + for _, err := range r { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") } // updateValues inspects all Event-definition and pushes the changes to git repo if there is. From c525c7a8fbfac66beb9798f6a17702fcd2acb6d1 Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Sun, 20 Aug 2023 20:58:27 +0900 Subject: [PATCH 14/18] use errors.Join Signed-off-by: nnnkkk7 --- pkg/app/piped/eventwatcher/eventwatcher.go | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/pkg/app/piped/eventwatcher/eventwatcher.go b/pkg/app/piped/eventwatcher/eventwatcher.go index 146a662b62..bb8328f5ba 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher.go +++ b/pkg/app/piped/eventwatcher/eventwatcher.go @@ -431,7 +431,7 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve return nil } - var errors []error + var responseError error retry := backoff.NewRetry(retryPushNum, backoff.NewConstant(retryPushInterval)) for branch, events := range branchHandledEvents { _, err = retry.Do(ctx, func() (interface{}, error) { @@ -465,26 +465,14 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve w.logger.Error("failed to report event statuses", zap.Error(err)) } w.executionMilestoneMap.Store(repoID, maxTimestamp) - errors = append(errors, fmt.Errorf("failed to push commits: %w", err)) + responseError = errors.Join(responseError, err) } - if len(errors) > 0 { - return responseError(errors) + if responseError != nil { + return responseError } return nil } -// responseError is an error wrapping errors. -type responseError []error - -// Error returns a concatenation of all the error messages it wraps. -func (r responseError) Error() string { - var msgs []string - for _, err := range r { - msgs = append(msgs, err.Error()) - } - return strings.Join(msgs, "; ") -} - // updateValues inspects all Event-definition and pushes the changes to git repo if there is. // NOTE: This will be removed. func (w *watcher) updateValues(ctx context.Context, repo git.Repo, repoID string, eventCfgs []config.EventWatcherEvent, commitMsg string) error { From 6c703492e0c664b1398360f510d5ee8bcc172c88 Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Sun, 20 Aug 2023 21:14:50 +0900 Subject: [PATCH 15/18] remove docs Signed-off-by: nnnkkk7 --- .../user-guide/configuration-reference.md | 712 ------------------ .../managing-piped/configuration-reference.md | 269 ------- 2 files changed, 981 deletions(-) delete mode 100644 docs/content/en/docs/user-guide/configuration-reference.md delete mode 100644 docs/content/en/docs/user-guide/managing-piped/configuration-reference.md diff --git a/docs/content/en/docs/user-guide/configuration-reference.md b/docs/content/en/docs/user-guide/configuration-reference.md deleted file mode 100644 index cf298d5d9d..0000000000 --- a/docs/content/en/docs/user-guide/configuration-reference.md +++ /dev/null @@ -1,712 +0,0 @@ ---- -title: "Configuration reference" -linkTitle: "Configuration reference" -weight: 9 -description: > - This page describes all configurable fields in the application configuration and analysis template. ---- - -## Kubernetes Application - -``` yaml -apiVersion: pipecd.dev/v1beta1 -kind: KubernetesApp -spec: - input: - pipeline: - ... -``` - -| Field | Type | Description | Required | -|-|-|-|-| -| name | string | The application name. | Yes (if you want to create PipeCD application through the application configuration file) | -| labels | map[string]string | Additional attributes to identify applications. | No | -| description | string | Notes on the Application. | No | -| input | [KubernetesDeploymentInput](#kubernetesdeploymentinput) | Input for Kubernetes deployment such as kubectl version, helm version, manifests filter... | No | -| trigger | [DeploymentTrigger](#deploymenttrigger) | Configuration for trigger used to determine should we trigger a new deployment or not. | No | -| planner | [DeploymentPlanner](#deploymentplanner) | Configuration for planner used while planning deployment. | No | -| commitMatcher | [CommitMatcher](#commitmatcher) | Forcibly use QuickSync or Pipeline when commit message matched the specified pattern. | No | -| quickSync | [KubernetesQuickSync](#kubernetesquicksync) | Configuration for quick sync. | No | -| pipeline | [Pipeline](#pipeline) | Pipeline for deploying progressively. | No | -| service | [KubernetesService](#kubernetesservice) | Which Kubernetes resource should be considered as the Service of application. Empty means the first Service resource will be used. | No | -| workloads | [][KubernetesWorkload](#kubernetesworkload) | Which Kubernetes resources should be considered as the Workloads of application. Empty means all Deployment resources. | No | -| trafficRouting | [KubernetesTrafficRouting](#kubernetestrafficrouting) | How to change traffic routing percentages. | No | -| encryption | [SecretEncryption](#secretencryption) | List of encrypted secrets and targets that should be decrypted before using. | No | -| attachment | [Attachment](#attachment) | List of attachment sources and targets that should be attached to manifests before using. | No | -| timeout | duration | The maximum length of time to execute deployment before giving up. Default is 6h. | No | -| notification | [DeploymentNotification](#deploymentnotification) | Additional configuration used while sending notification to external services. | No | -| postSync | [PostSync](#postsync) | Additional configuration used as extra actions once the deployment is triggered. | No | -| variantLabel | [KubernetesVariantLabel](#kubernetesvariantlabel) | The label will be configured to variant manifests used to distinguish them. | No | -| eventWatcher | [][EventWatcher](#eventwatcher) | List of configurations for event watcher. | No | -| driftDetection | [DriftDetection](#driftdetection) | Configuration for drift detection. | No | - -## Terraform application - -``` yaml -apiVersion: pipecd.dev/v1beta1 -kind: TerraformApp -spec: - input: - pipeline: - ... -``` - -| Field | Type | Description | Required | -|-|-|-|-| -| name | string | The application name. | Yes if you set the application through the application configuration file | -| labels | map[string]string | Additional attributes to identify applications. | No | -| description | string | Notes on the Application. | No | -| input | [TerraformDeploymentInput](#terraformdeploymentinput) | Input for Terraform deployment such as terraform version, workspace... | No | -| trigger | [DeploymentTrigger](#deploymenttrigger) | Configuration for trigger used to determine should we trigger a new deployment or not. | No | -| planner | [DeploymentPlanner](#deploymentplanner) | Configuration for planner used while planning deployment. | No | -| quickSync | [TerraformQuickSync](#terraformquicksync) | Configuration for quick sync. | No | -| pipeline | [Pipeline](#pipeline) | Pipeline for deploying progressively. | No | -| encryption | [SecretEncryption](#secretencryption) | List of encrypted secrets and targets that should be decrypted before using. | No | -| attachment | [Attachment](#attachment) | List of attachment sources and targets that should be attached to manifests before using. | No | -| timeout | duration | The maximum length of time to execute deployment before giving up. Default is 6h. | No | -| notification | [DeploymentNotification](#deploymentnotification) | Additional configuration used while sending notification to external services. | No | -| postSync | [PostSync](#postsync) | Additional configuration used as extra actions once the deployment is triggered. | No | -| eventWatcher | [][EventWatcher](#eventwatcher) | List of configurations for event watcher. | No | - -## Cloud Run application - -``` yaml -apiVersion: pipecd.dev/v1beta1 -kind: CloudRunApp -spec: - input: - pipeline: - ... -``` - -| Field | Type | Description | Required | -|-|-|-|-| -| name | string | The application name. | Yes if you set the application through the application configuration file | -| labels | map[string]string | Additional attributes to identify applications. | No | -| description | string | Notes on the Application. | No | -| input | [CloudRunDeploymentInput](#cloudrundeploymentinput) | Input for Cloud Run deployment such as docker image... | No | -| trigger | [DeploymentTrigger](#deploymenttrigger) | Configuration for trigger used to determine should we trigger a new deployment or not. | No | -| planner | [DeploymentPlanner](#deploymentplanner) | Configuration for planner used while planning deployment. | No | -| quickSync | [CloudRunQuickSync](#cloudrunquicksync) | Configuration for quick sync. | No | -| pipeline | [Pipeline](#pipeline) | Pipeline for deploying progressively. | No | -| encryption | [SecretEncryption](#secretencryption) | List of encrypted secrets and targets that should be decrypted before using. | No | -| attachment | [Attachment](#attachment) | List of attachment sources and targets that should be attached to manifests before using. | No | -| timeout | duration | The maximum length of time to execute deployment before giving up. Default is 6h. | No | -| notification | [DeploymentNotification](#deploymentnotification) | Additional configuration used while sending notification to external services. | No | -| postSync | [PostSync](#postsync) | Additional configuration used as extra actions once the deployment is triggered. | No | -| eventWatcher | [][EventWatcher](#eventwatcher) | List of configurations for event watcher. | No | - -## Lambda application - -``` yaml -apiVersion: pipecd.dev/v1beta1 -kind: LambdaApp -spec: - pipeline: - ... -``` - -| Field | Type | Description | Required | -|-|-|-|-| -| name | string | The application name. | Yes if you set the application through the application configuration file | -| labels | map[string]string | Additional attributes to identify applications. | No | -| description | string | Notes on the Application. | No | -| input | [LambdaDeploymentInput](#lambdadeploymentinput) | Input for Lambda deployment such as path to function manifest file... | No | -| trigger | [DeploymentTrigger](#deploymenttrigger) | Configuration for trigger used to determine should we trigger a new deployment or not. | No | -| planner | [DeploymentPlanner](#deploymentplanner) | Configuration for planner used while planning deployment. | No | -| quickSync | [LambdaQuickSync](#lambdaquicksync) | Configuration for quick sync. | No | -| pipeline | [Pipeline](#pipeline) | Pipeline for deploying progressively. | No | -| encryption | [SecretEncryption](#secretencryption) | List of encrypted secrets and targets that should be decrypted before using. | No | -| attachment | [Attachment](#attachment) | List of attachment sources and targets that should be attached to manifests before using. | No | -| timeout | duration | The maximum length of time to execute deployment before giving up. Default is 6h. | No | -| notification | [DeploymentNotification](#deploymentnotification) | Additional configuration used while sending notification to external services. | No | -| postSync | [PostSync](#postsync) | Additional configuration used as extra actions once the deployment is triggered. | No | -| eventWatcher | [][EventWatcher](#eventwatcher) | List of configurations for event watcher. | No | - -## ECS application - -``` yaml -apiVersion: pipecd.dev/v1beta1 -kind: ECSApp -spec: - input: - pipeline: - ... -``` - -| Field | Type | Description | Required | -|-|-|-|-| -| name | string | The application name. | Yes if you set the application through the application configuration file | -| labels | map[string]string | Additional attributes to identify applications. | No | -| description | string | Notes on the Application. | No | -| input | [ECSDeploymentInput](#ecsdeploymentinput) | Input for ECS deployment such as path to TaskDefinition, Service... | No | -| trigger | [DeploymentTrigger](#deploymenttrigger) | Configuration for trigger used to determine should we trigger a new deployment or not. | No | -| planner | [DeploymentPlanner](#deploymentplanner) | Configuration for planner used while planning deployment. | No | -| quickSync | [ECSQuickSync](#ecsquicksync) | Configuration for quick sync. | No | -| pipeline | [Pipeline](#pipeline) | Pipeline for deploying progressively. | No | -| encryption | [SecretEncryption](#secretencryption) | List of encrypted secrets and targets that should be decrypted before using. | No | -| attachment | [Attachment](#attachment) | List of attachment sources and targets that should be attached to manifests before using. | No | -| timeout | duration | The maximum length of time to execute deployment before giving up. Default is 6h. | No | -| notification | [DeploymentNotification](#deploymentnotification) | Additional configuration used while sending notification to external services. | No | -| postSync | [PostSync](#postsync) | Additional configuration used as extra actions once the deployment is triggered. | No | -| eventWatcher | [][EventWatcher](#eventwatcher) | List of configurations for event watcher. | No | - -## Analysis Template Configuration - -``` yaml -apiVersion: pipecd.dev/v1beta1 -kind: AnalysisTemplate -spec: - metrics: - grpc_error_rate_percentage: - interval: 1m - provider: prometheus-dev - failureLimit: 1 - expected: - max: 10 - query: awesome_query -``` - -| Field | Type | Description | Required | -|-|-|-|-| -| metrics | map[string][AnalysisMetrics](#analysismetrics) | Template for metrics. | No | - -## Event Watcher Configuration (deprecated) - -```yaml -apiVersion: pipecd.dev/v1beta1 -kind: EventWatcher -spec: - events: - - name: helloworld-image-update - replacements: - - file: helloworld/deployment.yaml - yamlField: $.spec.template.spec.containers[0].image -``` - -| Field | Type | Description | Required | -|-|-|-|-| -| name | string | The event name. | Yes | -| labels | map[string]string | Additional attributes of event. This can make an event definition unique even if the one with the same name exists. | No | -| replacements | [][EventWatcherReplacement](#eventwatcherreplacement) | List of places where will be replaced when the new event matches. | Yes | - -### EventWatcherReplacement -One of `yamlField` or `regex` is required. - -| Field | Type | Description | Required | -|-|-|-|-| -| file | string | The relative path from the repository root to the file to be updated. | Yes | -| yamlField | string | The yaml path to the field to be updated. It requires to start with `$` which represents the root element. e.g. `$.foo.bar[0].baz`. | No | -| regex | string | The regex string that specify what should be replaced. The only first capturing group enclosed by `()` will be replaced with the new value. e.g. `host.xz/foo/bar:(v[0-9].[0-9].[0-9])` | No | - -## CommitMatcher - -| Field | Type | Description | Required | -|-|-|-|-| -| quickSync | string | Regular expression string to forcibly do QuickSync when it matches the commit message. | No | -| pipeline | string | Regular expression string to forcibly do Pipeline when it matches the commit message. | No | - -## SecretEncryption - -| Field | Type | Description | Required | -|-|-|-|-| -| encryptedSecrets | map[string]string | List of encrypted secrets. | No | -| decryptionTargets | []string | List of files to be decrypted before using. | No | - -## Attachment - -| Field | Type | Description | Required | -|-|-|-|-| -| sources | map[string]string | List of attaching files with key is its refer name. | No | -| targets | []string | List of files which should contain the attachments. | No | - -## DeploymentPlanner - -| Field | Type | Description | Required | -|-|-|-|-| -| alwaysUsePipeline | bool | Always use the defined pipeline to deploy the application in all deployments. Default is `false`. | No | - -## DeploymentTrigger - -| Field | Type | Description | Required | -|-|-|-|-| -| onCommit | [OnCommit](#oncommit) | Controls triggering new deployment when new Git commits touched the application. | No | -| onCommand | [OnCommand](#oncommand) | Controls triggering new deployment when received a new `SYNC` command. | No | -| onOutOfSync | [OnOutOfSync](#onoutofsync) | Controls triggering new deployment when application is at `OUT_OF_SYNC` state. | No | -| onChain | [OnChain](#onchain) | Controls triggering new deployment when the application is counted as a node of some chains. | No | - -### OnCommit - -| Field | Type | Description | Required | -|-|-|-|-| -| disabled | bool | Whether to exclude application from triggering target when new Git commits touched it. Default is `false`. | No | -| paths | []string | List of directories or files where any changes of them will be considered as touching the application. Regular expression can be used. Empty means watching all changes under the application directory. | No | -| ignores | []string | List of directories or files where any changes of them will NOT be considered as touching the application. Regular expression can be used. This config has a higher priority compare to `paths`. | No | - -### OnCommand - -| Field | Type | Description | Required | -|-|-|-|-| -| disabled | bool | Whether to exclude application from triggering target when received a new `SYNC` command. Default is `false`. | No | - -### OnOutOfSync - -| Field | Type | Description | Required | -|-|-|-|-| -| disabled | bool | Whether to exclude application from triggering target when application is at `OUT_OF_SYNC` state. Default is `true`. | No | -| minWindow | duration | Minimum amount of time must be elapsed since the last deployment. This can be used to avoid triggering unnecessary continuous deployments based on `OUT_OF_SYNC` status. Default is `5m`. | No | - -### OnChain - -| Field | Type | Description | Required | -|-|-|-|-| -| disabled | bool | Whether to exclude application from triggering target when application is counted as a node of some chains. Default is `true`. | No | - -## Pipeline - -| Field | Type | Description | Required | -|-|-|-|-| -| stages | [][PipelineStage](#pipelinestage) | List of deployment pipeline stages. | No | - -### PipelineStage - -| Field | Type | Description | Required | -|-|-|-|-| -| id | string | The unique ID of the stage. | No | -| name | string | One of the provided stage names. | Yes | -| desc | string | The description about the stage. | No | -| timeout | duration | The maximum time the stage can be taken to run. | No | -| with | [StageOptions](#stageoptions) | Specific configuration for the stage. This must be one of these [StageOptions](#stageoptions). | No | - -## DeploymentNotification - -| Field | Type | Description | Required | -|-|-|-|-| -| mentions | [][NotificationMention](#notificationmention) | List of users to be notified for each event. | No | - -### NotificationMention - -| Field | Type | Description | Required | -|-|-|-|-| -| event | string | The event to be notified to users. | Yes | -| slack | []string | List of user IDs for mentioning in Slack. See [here](https://api.slack.com/reference/surfaces/formatting#mentioning-users) for more information on how to check them. | No | - -## KubernetesDeploymentInput - -| Field | Type | Description | Required | -|-|-|-|-| -| manifests | []string | List of manifest files in the application directory used to deploy. Empty means all manifest files in the directory will be used. | No | -| kubectlVersion | string | Version of kubectl will be used. Empty means the version set on [piped config](../managing-piped/configuration-reference/#platformproviderkubernetesconfig) or [default version](https://github.com/pipe-cd/pipecd/blob/master/tool/piped-base/install-kubectl.sh#L24) will be used. | No | -| kustomizeVersion | string | Version of kustomize will be used. Empty means the [default version](https://github.com/pipe-cd/pipecd/blob/master/tool/piped-base/install-kustomize.sh#L24) will be used. | No | -| kustomizeOptions | map[string]string | List of options that should be used by Kustomize commands. | No | -| helmVersion | string | Version of helm will be used. Empty means the [default version](https://github.com/pipe-cd/pipecd/blob/master/tool/piped-base/install-helm.sh#L24) will be used. | No | -| helmChart | [HelmChart](#helmchart) | Where to fetch helm chart. | No | -| helmOptions | [HelmOptions](#helmoptions) | Configurable parameters for helm commands. | No | -| namespace | string | The namespace where manifests will be applied. | No | -| autoRollback | bool | Automatically reverts all deployment changes on failure. Default is `true`. | No | - -### HelmChart - -| Field | Type | Description | Required | -|-|-|-|-| -| gitRemote | string | Git remote address where the chart is placing. Empty means the same repository. | No | -| ref | string | The commit SHA or tag value. Only valid when gitRemote is not empty. | No | -| path | string | Relative path from the repository root to the chart directory. | No | -| repository | string | The name of a registered Helm Chart Repository. | No | -| name | string | The chart name. | No | -| version | string | The chart version. | No | - -### HelmOptions - -| Field | Type | Description | Required | -|-|-|-|-| -| releaseName | string | The release name of helm deployment. By default, the release name is equal to the application name. | No | -| valueFiles | []string | List of value files should be loaded. Only local files stored under the application directory or remote files served at the http(s) endpoint are allowed. | No | -| setFiles | map[string]string | List of file path for values. | No | -| apiVersions | []string | Kubernetes api versions used for Capabilities.APIVersions. | No | -| kubeVersion | string | Kubernetes version used for Capabilities.KubeVersion. | No | - -## KubernetesVariantLabel - -| Field | Type | Description | Required | -|-|-|-|-| -| key | string | The key of the label. Default is `pipecd.dev/variant`. | No | -| primaryValue | string | The label value for PRIMARY variant. Default is `primary`. | No | -| canaryValue | string | The label value for CANARY variant. Default is `canary`. | No | -| baselineValue | string | The label value for BASELINE variant. Default is `baseline`. | No | - -## KubernetesQuickSync - -| Field | Type | Description | Required | -|-|-|-|-| -| addVariantLabelToSelector | bool | Whether the PRIMARY variant label should be added to manifests if they were missing. Default is `false`. | No | -| prune | bool | Whether the resources that are no longer defined in Git should be removed or not. Default is `false` | No | - -## KubernetesService - -| Field | Type | Description | Required | -|-|-|-|-| -| name | string | The name of Service manifest. | No | - -## KubernetesWorkload - -| Field | Type | Description | Required | -|-|-|-|-| -| kind | string | The kind name of workload manifests. Currently, only `Deployment` is supported. In the future, we also want to support `ReplicationController`, `DaemonSet`, `StatefulSet`. | No | -| name | string | The name of workload manifest. | No | - -## KubernetesTrafficRouting - -| Field | Type | Description | Required | -|-|-|-|-| -| method | string | Which traffic routing method will be used. Available values are `istio`, `smi`, `podselector`. Default is `podselector`. | No | -| istio | [IstioTrafficRouting](#istiotrafficrouting)| Istio configuration when the method is `istio`. | No | - -### IstioTrafficRouting - -| Field | Type | Description | Required | -|-|-|-|-| -| editableRoutes | []string | List of routes in the VirtualService that can be changed to update traffic routing. Empty means all routes should be updated. | No | -| host | string | The service host. | No | -| virtualService | [IstioVirtualService](#istiovirtualservice) | The reference to VirtualService manifest. Empty means the first VirtualService resource will be used. | No | - -#### IstioVirtualService - -| Field | Type | Description | Required | -|-|-|-|-| -| name | string | The name of VirtualService manifest. | No | - -## TerraformDeploymentInput - -| Field | Type | Description | Required | -|-|-|-|-| -| workspace | string | The terraform workspace name. Empty means `default` workspace. | No | -| terraformVersion | string | The version of terraform should be used. Empty means the pre-installed version will be used. | No | -| vars | []string | List of variables that will be set directly on terraform commands with `-var` flag. The variable must be formatted by `key=value`. | No | -| varFiles | []string | List of variable files that will be set on terraform commands with `-var-file` flag. | No | -| commandFlags | [TerraformCommandFlags](#terraformcommandflags) | List of additional flags will be used while executing terraform commands. | No | -| commandEnvs | [TerraformCommandEnvs](#terraformcommandenvs) | List of additional environment variables will be used while executing terraform commands. | No | -| autoRollback | bool | Automatically reverts all changes from all stages when one of them failed. | No | - -### TerraformCommandFlags - -| Field | Type | Description | Required | -|-|-|-|-| -| shared | []string | List of additional flags used for all Terraform commands. | No | -| init | []string | List of additional flags used for Terraform `init` command. | No | -| plan | []string | List of additional flags used for Terraform `plan` command. | No | -| apply | []string | List of additional flags used for Terraform `apply` command. | No | - -### TerraformCommandEnvs - -| Field | Type | Description | Required | -|-|-|-|-| -| shared | []string | List of additional environment variables used for all Terraform commands. | No | -| init | []string | List of additional environment variables used for Terraform `init` command. | No | -| plan | []string | List of additional environment variables used for Terraform `plan` command. | No | -| apply | []string | List of additional environment variables used for Terraform `apply` command. | No | - -## TerraformQuickSync - -| Field | Type | Description | Required | -|-|-|-|-| -| retries | int | How many times to retry applying terraform changes. Default is `0`. | No | - -## CloudRunDeploymentInput - -| Field | Type | Description | Required | -|-|-|-|-| -| serviceManifestFile | string | The name of service manifest file placing in application directory. Default is `service.yaml`. | No | -| autoRollback | bool | Automatically reverts to the previous state when the deployment is failed. Default is `true`. | No | - -## CloudRunQuickSync - -| Field | Type | Description | Required | -|-|-|-|-| - -## LambdaDeploymentInput - -| Field | Type | Description | Required | -|-|-|-|-| -| functionManifestFile | string | The name of function manifest file placing in application directory. Default is `function.yaml`. | No | -| autoRollback | bool | Automatically reverts to the previous state when the deployment is failed. Default is `true`. | No | - -## LambdaQuickSync - -| Field | Type | Description | Required | -|-|-|-|-| - -## ECSDeploymentInput - -| Field | Type | Description | Required | -|-|-|-|-| -| serviceDefinitionFile | string | The path ECS Service configuration file. Allow file in both `yaml` and `json` format. The default value is `service.json`. See [here](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service_definition_parameters.html) for parameters.| No | -| taskDefinitionFile | string | The path to ECS TaskDefinition configuration file. Allow file in both `yaml` and `json` format. The default value is `taskdef.json`. See [here](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html) for parameters. | No | -| targetGroups | [ECSTargetGroupInput](#ecstargetgroupinput) | The target groups configuration, will be used to routing traffic to created task sets. | Yes (if you want to perform progressive delivery) | - -### ECSTargetGroupInput - -| Field | Type | Description | Required | -|-|-|-|-| -| primary | ECSTargetGroupObject | The PRIMARY target group, will be used to register the PRIMARY ECS task set. | Yes | -| canary | ECSTargetGroupObject | The CANARY target group, will be used to register the CANARY ECS task set if exist. It's required to enable PipeCD to perform the multi-stage deployment. | No | - -Note: You can get examples for those object from [here](../../examples/#ecs-applications). - -## ECSQuickSync - -| Field | Type | Description | Required | -|-|-|-|-| - -## AnalysisMetrics - -| Field | Type | Description | Required | -|-|-|-|-| -| provider | string | The unique name of provider defined in the Piped Configuration. | Yes | -| strategy | string | The strategy name. One of `THRESHOLD` or `PREVIOUS` or `CANARY_BASELINE` or `CANARY_PRIMARY` is available. Defaults to `THRESHOLD`. | No | -| query | string | A query performed against the [Analysis Provider](../../concepts/#analysis-provider). The stage will be skipped if no data points were returned. | Yes | -| expected | [AnalysisExpected](#analysisexpected) | The statically defined expected query result. This field is ignored if there was no data point as a result of the query. | Yes if the strategy is `THRESHOLD` | -| interval | duration | Run a query at specified intervals. | Yes | -| failureLimit | int | Acceptable number of failures. e.g. If 1 is set, the `ANALYSIS` stage will end with failure after two queries results failed. Defaults to 1. | No | -| skipOnNoData | bool | If true, it considers as a success when no data returned from the analysis provider. Defaults to false. | No | -| deviation | string | The stage fails on deviation in the specified direction. One of `LOW` or `HIGH` or `EITHER` is available. This can be used only for `PREVIOUS`, `CANARY_BASELINE` or `CANARY_PRIMARY`. Defaults to `EITHER`. | No | -| baselineArgs | map[string][string] | The custom arguments to be populated for the Baseline query. They can be reffered as `{{ .VariantCustomArgs.xxx }}`. | No | -| canaryArgs | map[string][string] | The custom arguments to be populated for the Canary query. They can be reffered as `{{ .VariantCustomArgs.xxx }}`. | No | -| primaryArgs | map[string][string] | The custom arguments to be populated for the Primary query. They can be reffered as `{{ .VariantCustomArgs.xxx }}`. | No | -| timeout | duration | How long after which the query times out. | No | -| template | [AnalysisTemplateRef](#analysistemplateref) | Reference to the template to be used. | No | - - -### AnalysisExpected - -| Field | Type | Description | Required | -|-|-|-|-| -| min | float64 | Failure, if the query result is less than this value. | No | -| max | float64 | Failure, if the query result is larger than this value. | No | - -### AnalysisTemplateRef - -| Field | Type | Description | Required | -|-|-|-|-| -| name | string | The template name to refer. | Yes | -| appArgs | map[string]string | The arguments for custom-args. | No | - -## AnalysisLog - -| Field | Type | Description | Required | -|-|-|-|-| - -## AnalysisHttp - -| Field | Type | Description | Required | -|-|-|-|-| - -## StageOptions - -### KubernetesPrimaryRolloutStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| -| suffix | string | Suffix that should be used when naming the PRIMARY variant's resources. Default is `primary`. | No | -| createService | bool | Whether the PRIMARY service should be created. Default is `false`. | No | -| addVariantLabelToSelector | bool | Whether the PRIMARY variant label should be added to manifests if they were missing. Default is `false`. | No | -| prune | bool | Whether the resources that are no longer defined in Git should be removed or not. Default is `false` | No | - -### KubernetesCanaryRolloutStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| -| replicas | int | How many pods for CANARY workloads. Default is `1` pod. Alternatively, can be specified a string suffixed by "%" to indicate a percentage value compared to the pod number of PRIMARY | No | -| suffix | string | Suffix that should be used when naming the CANARY variant's resources. Default is `canary`. | No | -| createService | bool | Whether the CANARY service should be created. Default is `false`. | No | -| patches | [][KubernetesResourcePatch](#kubernetesresourcepatch) | List of patches used to customize manifests for CANARY variant. | No | - -### KubernetesCanaryCleanStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| -| | | | | - -### KubernetesBaselineRolloutStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| -| replicas | int | How many pods for BASELINE workloads. Default is `1` pod. Alternatively, can be specified a string suffixed by "%" to indicate a percentage value compared to the pod number of PRIMARY | No | -| suffix | string | Suffix that should be used when naming the BASELINE variant's resources. Default is `baseline`. | No | -| createService | bool | Whether the BASELINE service should be created. Default is `false`. | No | - -### KubernetesBaselineCleanStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| -| | | | | - -### KubernetesTrafficRoutingStageOptions -This stage routes traffic with the method specified in [KubernetesTrafficRouting](#kubernetestrafficrouting). -When using `podselector` method as a traffic routing method, routing is done by updating the Service selector. -Therefore, note that all traffic will be routed to the primary if the the primary variant's service is rolled out by running the `K8S_PRIMARY_ROLLOUT` stage. - -| Field | Type | Description | Required | -|-|-|-|-| -| all | string | Which variant should receive all traffic. Available values are "primary", "canary", "baseline". Default is `primary`. | No | -| primary | [Percentage](#percentage) | The percentage of traffic should be routed to PRIMARY variant. | No | -| canary | [Percentage](#percentage) | The percentage of traffic should be routed to CANARY variant. | No | -| baseline | [Percentage](#percentage) | The percentage of traffic should be routed to BASELINE variant. | No | - -### TerraformPlanStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| -| exitOnNoChanges | bool | Whether exiting the pipeline when the result has no changes | No | - -### TerraformApplyStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| -| retries | int | How many times to retry applying terraform changes. Default is `0`. | No | - -### CloudRunPromoteStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| -| percent | [Percentage](#percentage) | Percentage of traffic should be routed to the new version. | No | - -### LambdaCanaryRolloutStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| - -### LambdaPromoteStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| -| percent | [Percentage](#percentage) | Percentage of traffic should be routed to the new version. | No | - -### ECSPrimaryRolloutStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| - -### ECSCanaryRolloutStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| -| scale | [Percentage](#percentage) | The percentage of workloads should be rolled out as CANARY variant's workload. | Yes | - -### ECSTrafficRoutingStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| -| primary | [Percentage](#percentage) | The percentage of traffic should be routed to PRIMARY variant. | No | -| canary | [Percentage](#percentage) | The percentage of traffic should be routed to CANARY variant. | No | - -Note: By default, the sum of traffic is rounded to 100. If both `primary` and `canary` numbers are not set, the PRIMARY variant will receive 100% while the CANARY variant will receive 0% of the traffic. - -### AnalysisStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| -| duration | duration | Maximum time to perform the analysis. | Yes | -| metrics | [][AnalysisMetrics](#analysismetrics) | Configuration for analysis by metrics. | No | - -### WaitStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| -| duration | duration | Time to wait. | Yes | - -### WaitApprovalStageOptions - -| Field | Type | Description | Required | -|-|-|-|-| -| timeout | duration | The maximum length of time to wait before giving up. Default is 6h. | No | -| approvers | []string | List of username who has permission to approve. | Yes | -| minApproverNum | int | Number of minimum needed approvals to make this stage complete. Default is 1. | No | - -### CustomSyncStageOptions -| Field | Type | Description | Required | -|-|-|-|-| -| timeout | duration | The maximum time the stage can be taken to run. Default is `6h`| No | -| envs | map[string]string | Environment variables used with scripts. | No | -| run | string | Script run on this stage. | Yes | - -## PostSync - -| Field | Type | Description | Required | -|-|-|-|-| -| chain | [DeploymentChain](#deploymentchain) | Deployment chain configuration, used to determine and build deployments that should be triggered once the current deployment is triggered. | No | - -### DeploymentChain - -| Field | Type | Description | Required | -|-|-|-|-| -| applications | [][DeploymentChainApplication](#deploymentchainapplication) | The list of applications which should be triggered once deployment of this application rolled out successfully. | Yes | - -#### DeploymentChainApplication - -| Field | Type | Description | Required | -|-|-|-|-| -| name | string | The name of PipeCD application, note that application name is not unique in PipeCD datastore | No | -| kind | string | The kind of the PipeCD application, which should be triggered as a node in deployment chain. The value will be one of: KUBERNETES, TERRAFORM, CLOUDRUN, LAMBDA, ECS. | No | - -## EventWatcher - -| Field | Type | Description | Required | -|-|-|-|-| -| matcher | [EventWatcherMatcher](#eventwatchermatcher) | Which event will be handled. | Yes | -| handler | [EventWatcherHandler](#eventwatcherhandler) | What to do for the event which matched by the above matcher. | Yes | - -### EventWatcherMatcher - -| Field | Type | Description | Required | -|-|-|-|-| -| name | string | The event name. | Yes | -| labels | map[string]string | Additional attributes of event. This can make an event definition unique even if the one with the same name exists. | No | - -### EventWatcherHandler - -| Field | Type | Description | Required | -|-|-|-|-| -| type | string | The handler type. Currently, only `GIT_UPDATE` is supported. | Yes | -| config | [EventWatcherHandlerConfig](#eventwatcherhandlerconfig) | Configuration for the event watcher handler. | Yes | - -### EventWatcherHandlerConfig - -| Field | Type | Description | Required | -|-|-|-|-| -| commitMessage | string | The commit message used to push after replacing values. Default message is used if not given. | No | -| replacements | [][EventWatcherReplacement](#eventwatcherreplacement) | List of places where will be replaced when the new event matches. | Yes | - -## DriftDetection - -| Field | Type | Description | Required | -|-|-|-|-| -| ignoreFields | []string | List of fields path in manifests, which its diff should be ignored. | No | - -## PipeCD rich defined types - -### Percentage -A wrapper of type `int` to represent percentage data. Basically, you can pass `10` or `"10"` or `10%` and they will be treated as `10%` in PipeCD. - -### KubernetesResourcePatch - -| Field | Type | Description | Required | -|-|-|-|-| -| target | [KubernetesResourcePatchTarget](#kubernetesresourcepatchtarget) | Which manifest, which field will be the target of patch operations. | Yes | -| ops | [][KubernetesResourcePatchOp](#kubernetesresourcepatchop) | List of operations should be applied to the above target. | No | - -### KubernetesResourcePatchTarget - -| Field | Type | Description | Required | -|-|-|-|-| -| kind | string | The resource kind. e.g. `ConfigMap` | Yes | -| name | string | The resource name. e.g. `config-map-name` | Yes | -| documentRoot | string | In case you want to manipulate the YAML or JSON data specified in a field of the manfiest, 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. e.g. `$.data.envoy-config` | No | - -### KubernetesResourcePatchOp - -| Field | Type | Description | Required | -|-|-|-|-| -| op | string | The operation type. This must be one of `yaml-replace`, `yaml-add`, `yaml-remove`, `json-replace`, `text-regex`. Default is `yaml-replace`. | No | -| path | string | The path string pointing to the manipulated field. For yaml operations it looks like `$.foo.array[0].bar`. | No | -| value | string | The value string whose content will be used as new value for the field. | No | diff --git a/docs/content/en/docs/user-guide/managing-piped/configuration-reference.md b/docs/content/en/docs/user-guide/managing-piped/configuration-reference.md deleted file mode 100644 index 003776225c..0000000000 --- a/docs/content/en/docs/user-guide/managing-piped/configuration-reference.md +++ /dev/null @@ -1,269 +0,0 @@ ---- -title: "Configuration reference" -linkTitle: "Configuration reference" -weight: 9 -description: > - This page describes all configurable fields in the piped configuration. ---- - -``` yaml -apiVersion: pipecd.dev/v1beta1 -kind: Piped -spec: - projectID: ... - pipedID: ... - ... -``` - -## Piped Configuration - -| Field | Type | Description | Required | -|-|-|-|-| -| projectID | string | The identifier of the PipeCD project where this piped belongs to. | Yes | -| pipedID | string | The generated ID for this piped. | Yes | -| pipedKeyFile | string | The path to the file containing the generated key string for this piped. | Yes | -| pipedKeyData | string | Base64 encoded string of Piped key. Either pipedKeyFile or pipedKeyData must be set. | Yes | -| apiAddress | string | The address used to connect to the Control Plane's API in format `host:port`. | Yes | -| syncInterval | duration | How often to check whether an application should be synced. Default is `1m`. | No | -| appConfigSyncInterval | duration | How often to check whether application configuration files should be synced. Default is `1m`. | No | -| git | [Git](#git) | Git configuration needed for Git commands. | No | -| repositories | [][Repository](#gitrepository) | List of Git repositories this piped will handle. | No | -| chartRepositories | [][ChartRepository](#chartrepository) | List of Helm chart repositories that should be added while starting up. | No | -| chartRegistries | [][ChartRegistry](#chartregistry) | List of helm chart registries that should be logged in while starting up. | No | -| cloudProviders | [][CloudProvider](#cloudprovider) | List of cloud providers can be used by this piped. This field is deprecated, use `platformProviders` instead. | No | -| platformProviders | [][PlatformProvider](#platformprovider) | List of platform providers can be used by this piped. | No | -| analysisProviders | [][AnalysisProvider](#analysisprovider) | List of analysis providers can be used by this piped. | No | -| eventWatcher | [EventWatcher](#eventwatcher) | Optional Event watcher settings. | No | -| secretManagement | [SecretManagement](#secretmanagement) | The using secret management method. | No | -| notifications | [Notifications](#notifications) | Sending notifications to Slack, Webhook... | No | -| appSelector | map[string]string | List of labels to filter all applications this piped will handle. Currently, it is only be used to filter the applications suggested for adding from the control plane. | No | - -## Git - -| Field | Type | Description | Required | -|-|-|-|-| -| username | string | The username that will be configured for `git` user. Default is `piped`. | No | -| email | string | The email that will be configured for `git` user. Default is `pipecd.dev@gmail.com`. | No | -| sshConfigFilePath | string | Where to write ssh config file. Default is `$HOME/.ssh/config`. | No | -| host | string | The host name. Default is `github.com`. | No | -| hostName | string | The hostname or IP address of the remote git server. Default is the same value with Host. | No | -| sshKeyFile | string | The path to the private ssh key file. This will be used to clone the source code of the specified git repositories. | No | -| sshKeyData | string | Base64 encoded string of SSH key. | No | - -## GitRepository - -| Field | Type | Description | Required | -|-|-|-|-| -| repoID | string | Unique identifier to the repository. This must be unique in the piped scope. | Yes | -| remote | string | Remote address of the repository used to clone the source code. e.g. `git@github.com:org/repo.git` | Yes | -| branch | string | The branch will be handled. | Yes | - -## ChartRepository - -| Field | Type | Description | Required | -|-|-|-|-| -| type | string | The repository type. Currently, HTTP and GIT are supported. Default is HTTP. | No | -| name | string | The name of the Helm chart repository. Note that is not a Git repository but a [Helm chart repository](https://helm.sh/docs/topics/chart_repository/). | Yes if type is HTTP | -| address | string | The address to the Helm chart repository. | Yes if type is HTTP | -| username | string | Username used for the repository backed by HTTP basic authentication. | No | -| password | string | Password used for the repository backed by HTTP basic authentication. | No | -| insecure | bool | Whether to skip TLS certificate checks for the repository or not. | No | -| gitRemote | string | Remote address of the Git repository used to clone Helm charts. | Yes if type is GIT | -| sshKeyFile | string | The path to the private ssh key file used while cloning Helm charts from above Git repository. | No | - -## ChartRegistry - -| Field | Type | Description | Required | -|-|-|-|-| -| type | string | The registry type. Currently, only OCI is supported. Default is OCI. | No | -| address | string | The address to the registry. | Yes | -| username | string | Username used for the registry authentication. | No | -| password | string | Password used for the registry authentication. | No | - -## CloudProvider - -This field is deprecated, please use [PlatformProvider](#platformprovider) instead. - -## PlatformProvider - -| Field | Type | Description | Required | -|-|-|-|-| -| name | string | The name of the platform provider. | Yes | -| type | string | The platform provider type. Must be one of the following values:
`KUBERNETES`, `TERRAFORM`, `CLOUDRUN`, `LAMBDA`. | Yes | -| config | [PlatformProviderConfig](#platformproviderconfig) | Specific configuration for the specified type of platform provider. | No | - -## PlatformProviderConfig - -Must be one of the following structs: - -### PlatformProviderKubernetesConfig - -| Field | Type | Description | Required | -|-|-|-|-| -| masterURL | string | The master URL of the kubernetes cluster. Empty means in-cluster. | No | -| kubectlVersion | string | Version of kubectl which will be used to connect to your cluster. Empty means the version set on [piped config](../user-guide/managing-piped/configuration-reference/#platformproviderkubernetesconfig) or [default version](https://github.com/pipe-cd/pipecd/blob/master/tool/piped-base/install-kubectl.sh#L24) will be used. | No | -| kubeConfigPath | string | The path to the kubeconfig file. Empty means in-cluster. | No | -| appStateInformer | [KubernetesAppStateInformer](#kubernetesappstateinformer) | Configuration for application resource informer. | No | - -### PlatformProviderTerraformConfig - -| Field | Type | Description | Required | -|-|-|-|-| -| vars | []string | List of variables that will be set directly on terraform commands with `-var` flag. The variable must be formatted by `key=value`. | No | - -### PlatformProviderCloudRunConfig - -| Field | Type | Description | Required | -|-|-|-|-| -| project | string | The GCP project hosting the Cloud Run service. | Yes | -| region | string | The region of running Cloud Run service. | Yes | -| credentialsFile | string | The path to the service account file for accessing Cloud Run service. | No | - -### PlatformProviderLambdaConfig - -| Field | Type | Description | Required | -|-|-|-|-| -| region | string | The region of running Lambda service. | Yes | -| credentialsFile | string | The path to the credential file for logging into AWS cluster. If this value is not provided, piped will read credential info from environment variables. It expects the format [~/.aws/credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html). | No | -| roleARN | string | The IAM role arn to use when assuming an role. Required if you want to use the AWS SecurityTokenService. | No | -| tokenFile | string | The path to the WebIdentity token the SDK should use to assume a role with. Required if you want to use the AWS SecurityTokenService. | No | -| profile | string | The profile to use for logging into AWS cluster. The default value is `default`. | No | - -### PlatformProviderECSConfig - -| Field | Type | Description | Required | -|-|-|-|-| -| region | string | The region of running ECS cluster. | Yes | -| credentialsFile | string | The path to the credential file for logging into AWS cluster. If this value is not provided, piped will read credential info from environment variables. It expects the format [~/.aws/credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) | No | -| roleARN | string | The IAM role arn to use when assuming an role. Required if you want to use the AWS SecurityTokenService. | No | -| tokenFile | string | The path to the WebIdentity token the SDK should use to assume a role with. Required if you want to use the AWS SecurityTokenService. | No | -| profile | string | The profile to use for logging into AWS cluster. The default value is `default`. | No | - -## KubernetesAppStateInformer - -| Field | Type | Description | Required | -|-|-|-|-| -| namespace | string | Only watches the specified namespace. Empty means watching all namespaces. | No | -| includeResources | [][KubernetesResourcematcher](#kubernetesresourcematcher) | List of resources that should be added to the watching targets. | No | -| excludeResources | [][KubernetesResourcematcher](#kubernetesresourcematcher) | List of resources that should be ignored from the watching targets. | No | - -### KubernetesResourceMatcher - -| Field | Type | Description | Required | -|-|-|-|-| -| apiVersion | string | The APIVersion of the kubernetes resource. | Yes | -| kind | string | The kind name of the kubernetes resource. Empty means all kinds are matching. | No | - -## AnalysisProvider - -| Field | Type | Description | Required | -|-|-|-|-| -| name | string | The unique name of the analysis provider. | Yes | -| type | string | The provider type. Currently, only PROMETHEUS, DATADOG are available. | Yes | -| config | [AnalysisProviderConfig](#analysisproviderconfig) | Specific configuration for the specified type of analysis provider. | Yes | - -## AnalysisProviderConfig - -Must be one of the following structs: - -### AnalysisProviderPrometheusConfig -| Field | Type | Description | Required | -|-|-|-|-| -| address | string | The Prometheus server address. | Yes | -| usernameFile | string | The path to the username file. | No | -| passwordFile | string | The path to the password file. | No | - -### AnalysisProviderDatadogConfig -| Field | Type | Description | Required | -|-|-|-|-| -| address | string | The address of Datadog API server. Only "datadoghq.com", "us3.datadoghq.com", "datadoghq.eu", "ddog-gov.com" are available. Defaults to "datadoghq.com" | No | -| apiKeyFile | string | The path to the api key file. | Yes | -| applicationKeyFile | string | The path to the application key file. | Yes | - -## EventWatcher - -| Field | Type | Description | Required | -|-|-|-|-| -| checkInterval | duration | Interval to fetch the latest event and compare it with one defined in EventWatcher config files. Defaults to `1m`. | No | -| gitRepos | [][EventWatcherGitRepo](#eventwatchergitrepo) | The configuration list of git repositories to be observed. Only the repositories in this list will be observed by Piped. | No | - -### EventWatcherGitRepo - -| Field | Type | Description | Required | -|-|-|-|-| -| repoId | string | Id of the git repository. This must be unique within the repos' elements. | Yes | -| commitMessage | string | The commit message used to push after replacing values. Default message is used if not given. | No | -| includes | []string | The paths to EventWatcher files to be included. Patterns can be used like `foo/*.yaml`. | No | -| excludes | []string | The paths to EventWatcher files to be excluded. Patterns can be used like `foo/*.yaml`. This is prioritized if both includes and this are given. | No | - -## SecretManagement - -| Field | Type | Description | Required | -|-|-|-|-| -| type | string | Which management method should be used. Default is `KEY_PAIR`. | Yes | -| config | [SecretManagementConfig](#secretmanagementconfig) | Configration for using secret management method. | Yes | - -## SecretManagementConfig - -Must be one of the following structs: - -### SecretManagementKeyPair - -| Field | Type | Description | Required | -|-|-|-|-| -| privateKeyFile | string | Path to the private RSA key file. | Yes | -| privateKeyData | string | Base64 encoded string of private RSA key. Either privateKeyFile or privateKeyData must be set. | No | -| publicKeyFile | string | Path to the public RSA key file. | Yes | -| publicKeyData | string | Base64 encoded string of public RSA key. Either publicKeyFile or publicKeyData must be set. | No | - -### SecretManagementGCPKMS - -> WIP - -## Notifications - -| Field | Type | Description | Required | -|-|-|-|-| -| routes | [][NotificationRoute](#notificationroute) | List of notification routes. | No | -| receivers | [][NotificationReceiver](#notificationreceiver) | List of notification receivers. | No | - -### NotificationRoute - -| Field | Type | Description | Required | -|-|-|-|-| -| name | string | The name of the route. | Yes | -| receiver | string | The name of receiver who will receive all matched events. | Yes | -| events | []string | List of events that should be routed to the receiver. | No | -| ignoreEvents | []string | List of events that should be ignored. | No | -| groups | []string | List of event groups should be routed to the receiver. | No | -| ignoreGroups | []string | List of event groups should be ignored. | No | -| apps | []string | List of applications where their events should be routed to the receiver. | No | -| ignoreApps | []string | List of applications where their events should be ignored. | No | -| labels | map[string]string | List of labels where their events should be routed to the receiver. | No | -| ignoreLabels | map[string]string | List of labels where their events should be ignored. | No | - - -### NotificationReceiver - -| Field | Type | Description | Required | -|-|-|-|-| -| name | string | The name of the receiver. | Yes | -| slack | [NotificationReciverSlack](#notificationreceiverslack) | Configuration for slack receiver. | No | -| webhook | [NotificationReceiverWebhook](#notificationreceiverwebhook) | Configuration for webhook receiver. | No | - -#### NotificationReceiverSlack - -| Field | Type | Description | Required | -|-|-|-|-| -| hookURL | string | The hookURL of a slack channel. | Yes | -| oauthToken | string | [The token for slack api use.](https://api.slack.com/authentication/basics) | No | -| channelID | string | The channel id which slack api send to. | No | - -#### NotificationReceiverWebhook - -| Field | Type | Description | Required | -|-|-|-|-| -| url | string | The URL where notification event will be sent to. | Yes | -| signatureKey | string | The HTTP header key used to store the configured signature in each event. Default is "PipeCD-Signature". | No | -| signatureValue | string | The value of signature included in header of each event request. It can be used to verify the received events. | No | -| signatureValueFile | string | The path to the signature value file. | No | From b20d50df5f445db50431298cd2e4a70e4d0136cd Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Wed, 23 Aug 2023 08:11:33 +0900 Subject: [PATCH 16/18] remove handledEvents Signed-off-by: nnnkkk7 --- pkg/app/piped/eventwatcher/eventwatcher.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pkg/app/piped/eventwatcher/eventwatcher.go b/pkg/app/piped/eventwatcher/eventwatcher.go index bb8328f5ba..1cfb13d233 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher.go +++ b/pkg/app/piped/eventwatcher/eventwatcher.go @@ -330,7 +330,6 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve firstRead = false } var ( - handledEvents = make([]*pipedservice.ReportEventStatusesRequest_Event, 0, len(eventCfgs)) outDatedEvents = make([]*pipedservice.ReportEventStatusesRequest_Event, 0) maxTimestamp int64 outDatedDuration = time.Hour @@ -423,9 +422,6 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve } w.logger.Info(fmt.Sprintf("successfully made %d events OUTDATED", len(outDatedEvents))) } - if len(handledEvents) == 0 { - return nil - } if !gitUpdateEvent { return nil @@ -454,7 +450,7 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve } // If push fails because of the other reason, re-set all statuses to FAILURE. - for i := range handledEvents { + for i := range events { if events[i].Status == model.EventStatus_EVENT_FAILURE { continue } From 154a943d96cb17d836f06b4920da2f06cf6ad704 Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Fri, 2 Feb 2024 07:24:57 +0900 Subject: [PATCH 17/18] avoid using '!' Signed-off-by: nnnkkk7 --- pkg/app/piped/eventwatcher/eventwatcher.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/app/piped/eventwatcher/eventwatcher.go b/pkg/app/piped/eventwatcher/eventwatcher.go index 1cfb13d233..56de16239e 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher.go +++ b/pkg/app/piped/eventwatcher/eventwatcher.go @@ -791,8 +791,8 @@ func parseCommitMsg(msg string, args argsTemplate) string { // makeBranchName generates a new branch name in the format {eventName}-{uuid} if newBranch is true. // If newBranch is false, the function returns the existing branch name. func makeBranchName(newBranch bool, eventName, branch string) string { - if !newBranch { - return branch + if newBranch { + return fmt.Sprintf("%s-%s", eventName, uuid.New().String()) } - return fmt.Sprintf("%s-%s", eventName, uuid.New().String()) + return branch } From e1a4e414be6de63db6cb7fe5759d871cc1ef0e07 Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Fri, 2 Feb 2024 07:25:29 +0900 Subject: [PATCH 18/18] rearrange package Signed-off-by: nnnkkk7 --- pkg/app/piped/eventwatcher/eventwatcher.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/app/piped/eventwatcher/eventwatcher.go b/pkg/app/piped/eventwatcher/eventwatcher.go index 56de16239e..de9162cc04 100644 --- a/pkg/app/piped/eventwatcher/eventwatcher.go +++ b/pkg/app/piped/eventwatcher/eventwatcher.go @@ -30,10 +30,10 @@ import ( "text/template" "time" + "github.com/google/uuid" "go.uber.org/zap" "google.golang.org/grpc" - "github.com/google/uuid" "github.com/pipe-cd/pipecd/pkg/app/server/service/pipedservice" "github.com/pipe-cd/pipecd/pkg/backoff" "github.com/pipe-cd/pipecd/pkg/config"