diff --git a/api/v1alpha1/applicationset_types.go b/api/v1alpha1/applicationset_types.go index 86a93a23..c17d3577 100644 --- a/api/v1alpha1/applicationset_types.go +++ b/api/v1alpha1/applicationset_types.go @@ -77,6 +77,7 @@ type ApplicationSetGenerator struct { Matrix *MatrixGenerator `json:"matrix,omitempty"` SCMProvider *SCMProviderGenerator `json:"scmProvider,omitempty"` ClusterDecisionResource *DuckTypeGenerator `json:"clusterDecisionResource,omitempty"` + PullRequest *PullRequestGenerator `json:"pullRequest,omitempty"` } // ApplicationSetBaseGenerator include list item info @@ -88,6 +89,7 @@ type ApplicationSetBaseGenerator struct { Git *GitGenerator `json:"git,omitempty"` SCMProvider *SCMProviderGenerator `json:"scmProvider,omitempty"` ClusterDecisionResource *DuckTypeGenerator `json:"clusterDecisionResource,omitempty"` + PullRequest *PullRequestGenerator `json:"pullRequest,omitempty"` } // ListGenerator include items info @@ -203,6 +205,29 @@ type SCMProviderGeneratorFilter struct { BranchMatch *string `json:"branchMatch,omitempty"` } +// PullRequestGenerator defines a generator that scrapes a PullRequest API to find candidate pull requests. +type PullRequestGenerator struct { + // Which provider to use and config for it. + Github *PullRequestGeneratorGithub `json:"github,omitempty"` + // Standard parameters. + RequeueAfterSeconds *int64 `json:"requeueAfterSeconds,omitempty"` + Template ApplicationSetTemplate `json:"template,omitempty"` +} + +// PullRequestGenerator defines a connection info specific to GitHub. +type PullRequestGeneratorGithub struct { + // GitHub org or user to scan. Required. + Owner string `json:"owner"` + // GitHub repo name to scan. Required. + Repo string `json:"repo"` + // The GitHub API URL to talk to. If blank, use https://api.github.com/. + API string `json:"api,omitempty"` + // Authentication token reference. + TokenRef *SecretRef `json:"tokenRef,omitempty"` + // Labels is used to filter the PRs that you want to target + Labels []string `json:"labels,omitempty"` +} + // ApplicationSetStatus defines the observed state of ApplicationSet type ApplicationSetStatus struct { // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 86d34843..5b2c46b5 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -80,6 +80,11 @@ func (in *ApplicationSetBaseGenerator) DeepCopyInto(out *ApplicationSetBaseGener *out = new(DuckTypeGenerator) (*in).DeepCopyInto(*out) } + if in.PullRequest != nil { + in, out := &in.PullRequest, &out.PullRequest + *out = new(PullRequestGenerator) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ApplicationSetBaseGenerator. @@ -125,6 +130,11 @@ func (in *ApplicationSetGenerator) DeepCopyInto(out *ApplicationSetGenerator) { *out = new(DuckTypeGenerator) (*in).DeepCopyInto(*out) } + if in.PullRequest != nil { + in, out := &in.PullRequest, &out.PullRequest + *out = new(PullRequestGenerator) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ApplicationSetGenerator. @@ -438,6 +448,57 @@ func (in *MatrixGenerator) DeepCopy() *MatrixGenerator { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PullRequestGenerator) DeepCopyInto(out *PullRequestGenerator) { + *out = *in + if in.Github != nil { + in, out := &in.Github, &out.Github + *out = new(PullRequestGeneratorGithub) + (*in).DeepCopyInto(*out) + } + if in.RequeueAfterSeconds != nil { + in, out := &in.RequeueAfterSeconds, &out.RequeueAfterSeconds + *out = new(int64) + **out = **in + } + in.Template.DeepCopyInto(&out.Template) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PullRequestGenerator. +func (in *PullRequestGenerator) DeepCopy() *PullRequestGenerator { + if in == nil { + return nil + } + out := new(PullRequestGenerator) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PullRequestGeneratorGithub) DeepCopyInto(out *PullRequestGeneratorGithub) { + *out = *in + if in.TokenRef != nil { + in, out := &in.TokenRef, &out.TokenRef + *out = new(SecretRef) + **out = **in + } + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PullRequestGeneratorGithub. +func (in *PullRequestGeneratorGithub) DeepCopy() *PullRequestGeneratorGithub { + if in == nil { + return nil + } + out := new(PullRequestGeneratorGithub) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SCMProviderGenerator) DeepCopyInto(out *SCMProviderGenerator) { *out = *in diff --git a/docs/Generators-Pull-Request.md b/docs/Generators-Pull-Request.md new file mode 100644 index 00000000..f9bc5268 --- /dev/null +++ b/docs/Generators-Pull-Request.md @@ -0,0 +1,88 @@ +# Pull Request Generator + +The Pull Request generator uses the API of an SCMaaS provider (eg GitHub/GitLab) to automatically discover open pull requests within an repository. This fits well with the style of building a test environment when you create a pull request. + + +```yaml +apiVersion: argoproj.io/v1alpha1 +kind: ApplicationSet +metadata: + name: myapps +spec: + generators: + - pullRequest: + # See below for provider specific options. + github: + # ... +``` + +## GitHub + +Specify the repository from which to fetch the Github Pull requests. + +```yaml +apiVersion: argoproj.io/v1alpha1 +kind: ApplicationSet +metadata: + name: myapps +spec: + generators: + - pullRequest: + github: + # The GitHub organization or user. + owner: myorg + # The Github repository + repo: myrepository + # For GitHub Enterprise (optional) + api: https://git.example.com/ + # Reference to a Secret containing an access token. (optional) + tokenRef: + secretName: github-token + key: token + # Labels is used to filter the PRs that you want to target. (optional) + labels: + - preview + template: + # ... +``` + +* `owner`: Required name of the GitHub organization or user. +* `repo`: Required name of the Github repositry. +* `api`: If using GitHub Enterprise, the URL to access it. (Optional) +* `tokenRef`: A `Secret` name and key containing the GitHub access token to use for requests. If not specified, will make anonymous requests which have a lower rate limit and can only see public repositories. (Optional) +* `labels`: Labels is used to filter the PRs that you want to target. (Optional) + +## Template + +As with all generators, several keys are available for replacement in the generated application. + +```yaml +apiVersion: argoproj.io/v1alpha1 +kind: ApplicationSet +metadata: + name: myapps +spec: + generators: + - pullRequest: + # ... + template: + metadata: + name: 'myapp-{{ branch }}-{{ number }}' + spec: + source: + repoURL: 'https://github.com/myorg/myrepo.git' + targetRevision: '{{ head_sha }}' + path: kubernetes/ + helm: + parameters: + - name: "image.tag" + value: "pull-{{ head_sha }}" + project: default + destination: + server: https://kubernetes.default.svc + namespace: default +``` + +* `number`: The ID number of the pull request. +* `branch`: The name of the branch of the pull request head. +* `head_sha`: This is the SHA of the head of the pull request. diff --git a/docs/Generators.md b/docs/Generators.md index 9f8b19fb..a6401699 100644 --- a/docs/Generators.md +++ b/docs/Generators.md @@ -12,5 +12,6 @@ As of this writing there are six generators: - [Matrix generator](Generators-Matrix.md): The Matrix generator may be used to combine the generated parameters of two separate generators. - [SCM Provider generator](Generators-SCM-Provider.md): The SCM Provider generator uses the API of an SCM provider (eg GitHub) to automatically discover repositories within an organization. - [Cluster Decision Resource generator](Generators-Cluster-Decision-Resource.md): The Cluster Decision Resource generator is used to interface with Kubernetes custom resources that use custom resource-specific logic to decide which set of Argo CD clusters to deploy to. +- [Pull Request generator](Generators-Pull-Request.md): The Pull Request generator uses the API of an SCMaaS provider (eg GitHub) to automatically discover open pull requests within an repository. -If you are new to generators, begin with the **List** and **Cluster** generators. For more advanced use cases, see the documentation for the remaining generators above. \ No newline at end of file +If you are new to generators, begin with the **List** and **Cluster** generators. For more advanced use cases, see the documentation for the remaining generators above. diff --git a/examples/pull-request-generator/pull-request-example.yaml b/examples/pull-request-generator/pull-request-example.yaml new file mode 100644 index 00000000..e5d2d5ad --- /dev/null +++ b/examples/pull-request-generator/pull-request-example.yaml @@ -0,0 +1,40 @@ +apiVersion: argoproj.io/v1alpha1 +kind: ApplicationSet +metadata: + name: myapp +spec: + generators: + - pullRequest: + github: + # The GitHub organization or user. + owner: myorg + # The Github repository + repo: myrepo + # For GitHub Enterprise. (optional) + api: https://git.example.com/ + # Reference to a Secret containing an access token. (optional) + tokenRef: + secretName: github-token + key: token + # Labels is used to filter the PRs that you want to target. (optional) + labels: + - preview + template: + metadata: + name: 'myapp-{{ branch }}-{{ number }}' + spec: + source: + repoURL: 'https://github.com/myorg/myrepo.git' + targetRevision: '{{ head_sha }}' + path: helm-guestbook + helm: + parameters: + - name: "image.tag" + value: "pull-{{ head_sha }}" + project: default + destination: + server: https://kubernetes.default.svc + namespace: "{{ branch }}-{{ number }}" + syncPolicy: + syncOptions: + - CreateNamespace=true diff --git a/main.go b/main.go index 9066576e..24e8333b 100644 --- a/main.go +++ b/main.go @@ -145,6 +145,7 @@ func main() { "Git": generators.NewGitGenerator(services.NewArgoCDService(argoCDDB, argocdRepoServer)), "SCMProvider": generators.NewSCMProviderGenerator(mgr.GetClient()), "ClusterDecisionResource": generators.NewDuckTypeGenerator(context.Background(), dynClient, k8s, namespace), + "PullRequest": generators.NewPullRequestGenerator(mgr.GetClient()), } combineGenerators := map[string]generators.Generator{ diff --git a/manifests/crds/argoproj.io_applicationsets.yaml b/manifests/crds/argoproj.io_applicationsets.yaml index c7dabf56..5be79aff 100644 --- a/manifests/crds/argoproj.io_applicationsets.yaml +++ b/manifests/crds/argoproj.io_applicationsets.yaml @@ -4284,95 +4284,31 @@ spec: required: - elements type: object - scmProvider: - description: SCMProviderGenerator defines a generator - that scrapes a SCMaaS API to find candidate repos. + pullRequest: + description: PullRequestGenerator defines a generator + that scrapes a PullRequest API to find candidate + pull requests. properties: - cloneProtocol: - description: Which protocol to use for the SCM - URL. Default is provider-specific but ssh if - possible. Not all providers necessarily support - all protocols. - type: string - filters: - description: Filters for which repos should be - considered. - items: - description: SCMProviderGeneratorFilter is a - single repository filter. If multiple filter - types are set on a single struct, they will - be AND'd together. All filters must pass for - a repo to be included. - properties: - branchMatch: - description: A regex which must match the - branch name. - type: string - labelMatch: - description: A regex which must match at - least one label. - type: string - pathsExist: - description: An array of paths, all of which - must exist. - items: - type: string - type: array - repositoryMatch: - description: A regex for repo names. - type: string - type: object - type: array github: description: Which provider to use and config for it. properties: - allBranches: - description: Scan all branches instead of - just the default branch. - type: boolean api: description: The GitHub API URL to talk to. If blank, use https://api.github.com/. type: string - organization: - description: GitHub org to scan. Required. - type: string - tokenRef: - description: Authentication token reference. - properties: - key: - type: string - secretName: - type: string - required: - - key - - secretName - type: object - required: - - organization - type: object - gitlab: - description: SCMProviderGeneratorGitlab defines - a connection info specific to Gitlab. - properties: - allBranches: - description: Scan all branches instead of - just the default branch. - type: boolean - api: - description: The Gitlab API URL to talk to. + labels: + description: Labels is used to filter the + PRs that you want to target + items: + type: string + type: array + owner: + description: GitHub org or user to scan. Required. type: string - group: - description: Gitlab group to scan. Required. You - can use either the project id (recommended) - or the full namespaced path. + repo: + description: GitHub repo name to scan. Required. type: string - includeSubgroups: - description: Recurse through subgroups (true) - or scan only the base group (false). Defaults - to "false" - type: boolean tokenRef: description: Authentication token reference. properties: @@ -4385,7 +4321,8 @@ spec: - secretName type: object required: - - group + - owner + - repo type: object requeueAfterSeconds: description: Standard parameters. @@ -4901,101 +4838,1220 @@ spec: - spec type: object type: object - type: object - type: array - template: - description: ApplicationSetTemplate represents argocd ApplicationSpec - properties: - metadata: - description: ApplicationSetTemplateMeta represents the - Argo CD application fields that may be used for Applications - generated from the ApplicationSet (based on metav1.ObjectMeta) - properties: - annotations: - additionalProperties: - type: string - type: object - finalizers: - items: - type: string - type: array - labels: - additionalProperties: + scmProvider: + description: SCMProviderGenerator defines a generator + that scrapes a SCMaaS API to find candidate repos. + properties: + cloneProtocol: + description: Which protocol to use for the SCM + URL. Default is provider-specific but ssh if + possible. Not all providers necessarily support + all protocols. type: string - type: object - name: - type: string - namespace: - type: string - type: object - spec: - description: ApplicationSpec represents desired application - state. Contains link to repository with application - definition and additional parameters link definition - revision. - properties: - destination: - description: Destination is a reference to the target - Kubernetes server and namespace - properties: - name: - description: Name is an alternate way of specifying - the target cluster by its symbolic name - type: string - namespace: - description: Namespace specifies the target - namespace for the application's resources. - The namespace will only be set for namespace-scoped - resources that have not set a value for .metadata.namespace - type: string - server: - description: Server specifies the URL of the - target cluster and must be set to the Kubernetes - control plane API - type: string - type: object - ignoreDifferences: - description: IgnoreDifferences is a list of resources - and their fields which should be ignored during - comparison - items: - description: ResourceIgnoreDifferences contains - resource filter and list of json paths which - should be ignored during comparison with live - state. - properties: - group: - type: string - jqPathExpressions: - items: + filters: + description: Filters for which repos should be + considered. + items: + description: SCMProviderGeneratorFilter is a + single repository filter. If multiple filter + types are set on a single struct, they will + be AND'd together. All filters must pass for + a repo to be included. + properties: + branchMatch: + description: A regex which must match the + branch name. type: string - type: array - jsonPointers: - items: + labelMatch: + description: A regex which must match at + least one label. type: string - type: array - kind: - type: string - name: + pathsExist: + description: An array of paths, all of which + must exist. + items: + type: string + type: array + repositoryMatch: + description: A regex for repo names. + type: string + type: object + type: array + github: + description: Which provider to use and config + for it. + properties: + allBranches: + description: Scan all branches instead of + just the default branch. + type: boolean + api: + description: The GitHub API URL to talk to. + If blank, use https://api.github.com/. type: string - namespace: + organization: + description: GitHub org to scan. Required. type: string + tokenRef: + description: Authentication token reference. + properties: + key: + type: string + secretName: + type: string + required: + - key + - secretName + type: object required: - - kind + - organization type: object - type: array - info: - description: Info contains a list of information - (URLs, email addresses, and plain text) that relates - to the application - items: + gitlab: + description: SCMProviderGeneratorGitlab defines + a connection info specific to Gitlab. properties: - name: + allBranches: + description: Scan all branches instead of + just the default branch. + type: boolean + api: + description: The Gitlab API URL to talk to. type: string - value: + group: + description: Gitlab group to scan. Required. You + can use either the project id (recommended) + or the full namespaced path. type: string + includeSubgroups: + description: Recurse through subgroups (true) + or scan only the base group (false). Defaults + to "false" + type: boolean + tokenRef: + description: Authentication token reference. + properties: + key: + type: string + secretName: + type: string + required: + - key + - secretName + type: object required: - - name + - group + type: object + requeueAfterSeconds: + description: Standard parameters. + format: int64 + type: integer + template: + description: ApplicationSetTemplate represents + argocd ApplicationSpec + properties: + metadata: + description: ApplicationSetTemplateMeta represents + the Argo CD application fields that may + be used for Applications generated from + the ApplicationSet (based on metav1.ObjectMeta) + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: ApplicationSpec represents desired + application state. Contains link to repository + with application definition and additional + parameters link definition revision. + properties: + destination: + description: Destination is a reference + to the target Kubernetes server and + namespace + properties: + name: + description: Name is an alternate + way of specifying the target cluster + by its symbolic name + type: string + namespace: + description: Namespace specifies the + target namespace for the application's + resources. The namespace will only + be set for namespace-scoped resources + that have not set a value for .metadata.namespace + type: string + server: + description: Server specifies the + URL of the target cluster and must + be set to the Kubernetes control + plane API + type: string + type: object + ignoreDifferences: + description: IgnoreDifferences is a list + of resources and their fields which + should be ignored during comparison + items: + description: ResourceIgnoreDifferences + contains resource filter and list + of json paths which should be ignored + during comparison with live state. + properties: + group: + type: string + jqPathExpressions: + items: + type: string + type: array + jsonPointers: + items: + type: string + type: array + kind: + type: string + name: + type: string + namespace: + type: string + required: + - kind + type: object + type: array + info: + description: Info contains a list of information + (URLs, email addresses, and plain text) + that relates to the application + items: + properties: + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + project: + description: Project is a reference to + the project this application belongs + to. The empty string means that application + belongs to the 'default' project. + type: string + revisionHistoryLimit: + description: RevisionHistoryLimit limits + the number of items kept in the application's + revision history, which is used for + informational purposes as well as for + rollbacks to previous versions. This + should only be changed in exceptional + circumstances. Setting to zero will + store no history. This will reduce storage + used. Increasing will increase the space + used to store the history, so we do + not recommend increasing it. Default + is 10. + format: int64 + type: integer + source: + description: Source is a reference to + the location of the application's manifests + or chart + properties: + chart: + description: Chart is a Helm chart + name, and must be specified for + applications sourced from a Helm + repo. + type: string + directory: + description: Directory holds path/directory + specific options + properties: + exclude: + description: Exclude contains + a glob pattern to match paths + against that should be explicitly + excluded from being used during + manifest generation + type: string + include: + description: Include contains + a glob pattern to match paths + against that should be explicitly + included during manifest generation + type: string + jsonnet: + description: Jsonnet holds options + specific to Jsonnet + properties: + extVars: + description: ExtVars is a + list of Jsonnet External + Variables + items: + description: JsonnetVar + represents a variable + to be passed to jsonnet + during manifest generation + properties: + code: + type: boolean + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + libs: + description: Additional library + search dirs + items: + type: string + type: array + tlas: + description: TLAS is a list + of Jsonnet Top-level Arguments + items: + description: JsonnetVar + represents a variable + to be passed to jsonnet + during manifest generation + properties: + code: + type: boolean + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + type: object + recurse: + description: Recurse specifies + whether to scan a directory + recursively for manifests + type: boolean + type: object + helm: + description: Helm holds helm specific + options + properties: + fileParameters: + description: FileParameters are + file parameters to the helm + template + items: + description: HelmFileParameter + is a file parameter that's + passed to helm template during + manifest generation + properties: + name: + description: Name is the + name of the Helm parameter + type: string + path: + description: Path is the + path to the file containing + the values for the Helm + parameter + type: string + type: object + type: array + parameters: + description: Parameters is a list + of Helm parameters which are + passed to the helm template + command upon manifest generation + items: + description: HelmParameter is + a parameter that's passed + to helm template during manifest + generation + properties: + forceString: + description: ForceString + determines whether to + tell Helm to interpret + booleans and numbers as + strings + type: boolean + name: + description: Name is the + name of the Helm parameter + type: string + value: + description: Value is the + value for the Helm parameter + type: string + type: object + type: array + releaseName: + description: ReleaseName is the + Helm release name to use. If + omitted it will use the application + name + type: string + valueFiles: + description: ValuesFiles is a + list of Helm value files to + use when generating a template + items: + type: string + type: array + values: + description: Values specifies + Helm values to be passed to + helm template, typically defined + as a block + type: string + version: + description: Version is the Helm + version to use for templating + (either "2" or "3") + type: string + type: object + ksonnet: + description: Ksonnet holds ksonnet + specific options + properties: + environment: + description: Environment is a + ksonnet application environment + name + type: string + parameters: + description: Parameters are a + list of ksonnet component parameter + override values + items: + description: KsonnetParameter + is a ksonnet component parameter + properties: + component: + type: string + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + type: object + kustomize: + description: Kustomize holds kustomize + specific options + properties: + commonAnnotations: + additionalProperties: + type: string + description: CommonAnnotations + is a list of additional annotations + to add to rendered manifests + type: object + commonLabels: + additionalProperties: + type: string + description: CommonLabels is a + list of additional labels to + add to rendered manifests + type: object + forceCommonAnnotations: + description: ForceCommonAnnotations + specifies whether to force applying + common annotations to resources + for Kustomize apps + type: boolean + forceCommonLabels: + description: ForceCommonLabels + specifies whether to force applying + common labels to resources for + Kustomize apps + type: boolean + images: + description: Images is a list + of Kustomize image override + specifications + items: + description: KustomizeImage + represents a Kustomize image + definition in the format [old_image_name=]: + type: string + type: array + namePrefix: + description: NamePrefix is a prefix + appended to resources for Kustomize + apps + type: string + nameSuffix: + description: NameSuffix is a suffix + appended to resources for Kustomize + apps + type: string + version: + description: Version controls + which version of Kustomize to + use for rendering manifests + type: string + type: object + path: + description: Path is a directory path + within the Git repository, and is + only valid for applications sourced + from Git. + type: string + plugin: + description: ConfigManagementPlugin + holds config management plugin specific + options + properties: + env: + description: Env is a list of + environment variable entries + items: + description: EnvEntry represents + an entry in the application's + environment + properties: + name: + description: Name is the + name of the variable, + usually expressed in uppercase + type: string + value: + description: Value is the + value of the variable + type: string + required: + - name + - value + type: object + type: array + name: + type: string + type: object + repoURL: + description: RepoURL is the URL to + the repository (Git or Helm) that + contains the application manifests + type: string + targetRevision: + description: TargetRevision defines + the revision of the source to sync + the application to. In case of Git, + this can be commit, tag, or branch. + If omitted, will equal to HEAD. + In case of Helm, this is a semver + tag for the Chart's version. + type: string + required: + - repoURL + type: object + syncPolicy: + description: SyncPolicy controls when + and how a sync will be performed + properties: + automated: + description: Automated will keep an + application synced to the target + revision + properties: + allowEmpty: + description: 'AllowEmpty allows + apps have zero live resources + (default: false)' + type: boolean + prune: + description: 'Prune specifies + whether to delete resources + from the cluster that are not + found in the sources anymore + as part of automated sync (default: + false)' + type: boolean + selfHeal: + description: 'SelfHeal specifes + whether to revert resources + back to their desired state + upon modification in the cluster + (default: false)' + type: boolean + type: object + retry: + description: Retry controls failed + sync retry behavior + properties: + backoff: + description: Backoff controls + how to backoff on subsequent + retries of failed syncs + properties: + duration: + description: Duration is the + amount to back off. Default + unit is seconds, but could + also be a duration (e.g. + "2m", "1h") + type: string + factor: + description: Factor is a factor + to multiply the base duration + after each failed retry + format: int64 + type: integer + maxDuration: + description: MaxDuration is + the maximum amount of time + allowed for the backoff + strategy + type: string + type: object + limit: + description: Limit is the maximum + number of attempts for retrying + a failed sync. If set to 0, + no retries will be performed. + format: int64 + type: integer + type: object + syncOptions: + description: Options allow you to + specify whole app sync-options + items: + type: string + type: array + type: object + required: + - destination + - project + - source + type: object + required: + - metadata + - spec + type: object + type: object + type: object + type: array + template: + description: ApplicationSetTemplate represents argocd ApplicationSpec + properties: + metadata: + description: ApplicationSetTemplateMeta represents the + Argo CD application fields that may be used for Applications + generated from the ApplicationSet (based on metav1.ObjectMeta) + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: ApplicationSpec represents desired application + state. Contains link to repository with application + definition and additional parameters link definition + revision. + properties: + destination: + description: Destination is a reference to the target + Kubernetes server and namespace + properties: + name: + description: Name is an alternate way of specifying + the target cluster by its symbolic name + type: string + namespace: + description: Namespace specifies the target + namespace for the application's resources. + The namespace will only be set for namespace-scoped + resources that have not set a value for .metadata.namespace + type: string + server: + description: Server specifies the URL of the + target cluster and must be set to the Kubernetes + control plane API + type: string + type: object + ignoreDifferences: + description: IgnoreDifferences is a list of resources + and their fields which should be ignored during + comparison + items: + description: ResourceIgnoreDifferences contains + resource filter and list of json paths which + should be ignored during comparison with live + state. + properties: + group: + type: string + jqPathExpressions: + items: + type: string + type: array + jsonPointers: + items: + type: string + type: array + kind: + type: string + name: + type: string + namespace: + type: string + required: + - kind + type: object + type: array + info: + description: Info contains a list of information + (URLs, email addresses, and plain text) that relates + to the application + items: + properties: + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + project: + description: Project is a reference to the project + this application belongs to. The empty string + means that application belongs to the 'default' + project. + type: string + revisionHistoryLimit: + description: RevisionHistoryLimit limits the number + of items kept in the application's revision history, + which is used for informational purposes as well + as for rollbacks to previous versions. This should + only be changed in exceptional circumstances. + Setting to zero will store no history. This will + reduce storage used. Increasing will increase + the space used to store the history, so we do + not recommend increasing it. Default is 10. + format: int64 + type: integer + source: + description: Source is a reference to the location + of the application's manifests or chart + properties: + chart: + description: Chart is a Helm chart name, and + must be specified for applications sourced + from a Helm repo. + type: string + directory: + description: Directory holds path/directory + specific options + properties: + exclude: + description: Exclude contains a glob pattern + to match paths against that should be + explicitly excluded from being used during + manifest generation + type: string + include: + description: Include contains a glob pattern + to match paths against that should be + explicitly included during manifest generation + type: string + jsonnet: + description: Jsonnet holds options specific + to Jsonnet + properties: + extVars: + description: ExtVars is a list of Jsonnet + External Variables + items: + description: JsonnetVar represents + a variable to be passed to jsonnet + during manifest generation + properties: + code: + type: boolean + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + libs: + description: Additional library search + dirs + items: + type: string + type: array + tlas: + description: TLAS is a list of Jsonnet + Top-level Arguments + items: + description: JsonnetVar represents + a variable to be passed to jsonnet + during manifest generation + properties: + code: + type: boolean + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + type: object + recurse: + description: Recurse specifies whether to + scan a directory recursively for manifests + type: boolean + type: object + helm: + description: Helm holds helm specific options + properties: + fileParameters: + description: FileParameters are file parameters + to the helm template + items: + description: HelmFileParameter is a file + parameter that's passed to helm template + during manifest generation + properties: + name: + description: Name is the name of the + Helm parameter + type: string + path: + description: Path is the path to the + file containing the values for the + Helm parameter + type: string + type: object + type: array + parameters: + description: Parameters is a list of Helm + parameters which are passed to the helm + template command upon manifest generation + items: + description: HelmParameter is a parameter + that's passed to helm template during + manifest generation + properties: + forceString: + description: ForceString determines + whether to tell Helm to interpret + booleans and numbers as strings + type: boolean + name: + description: Name is the name of the + Helm parameter + type: string + value: + description: Value is the value for + the Helm parameter + type: string + type: object + type: array + releaseName: + description: ReleaseName is the Helm release + name to use. If omitted it will use the + application name + type: string + valueFiles: + description: ValuesFiles is a list of Helm + value files to use when generating a template + items: + type: string + type: array + values: + description: Values specifies Helm values + to be passed to helm template, typically + defined as a block + type: string + version: + description: Version is the Helm version + to use for templating (either "2" or "3") + type: string + type: object + ksonnet: + description: Ksonnet holds ksonnet specific + options + properties: + environment: + description: Environment is a ksonnet application + environment name + type: string + parameters: + description: Parameters are a list of ksonnet + component parameter override values + items: + description: KsonnetParameter is a ksonnet + component parameter + properties: + component: + type: string + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + type: object + kustomize: + description: Kustomize holds kustomize specific + options + properties: + commonAnnotations: + additionalProperties: + type: string + description: CommonAnnotations is a list + of additional annotations to add to rendered + manifests + type: object + commonLabels: + additionalProperties: + type: string + description: CommonLabels is a list of additional + labels to add to rendered manifests + type: object + forceCommonAnnotations: + description: ForceCommonAnnotations specifies + whether to force applying common annotations + to resources for Kustomize apps + type: boolean + forceCommonLabels: + description: ForceCommonLabels specifies + whether to force applying common labels + to resources for Kustomize apps + type: boolean + images: + description: Images is a list of Kustomize + image override specifications + items: + description: KustomizeImage represents + a Kustomize image definition in the + format [old_image_name=]: + type: string + type: array + namePrefix: + description: NamePrefix is a prefix appended + to resources for Kustomize apps + type: string + nameSuffix: + description: NameSuffix is a suffix appended + to resources for Kustomize apps + type: string + version: + description: Version controls which version + of Kustomize to use for rendering manifests + type: string + type: object + path: + description: Path is a directory path within + the Git repository, and is only valid for + applications sourced from Git. + type: string + plugin: + description: ConfigManagementPlugin holds config + management plugin specific options + properties: + env: + description: Env is a list of environment + variable entries + items: + description: EnvEntry represents an entry + in the application's environment + properties: + name: + description: Name is the name of the + variable, usually expressed in uppercase + type: string + value: + description: Value is the value of + the variable + type: string + required: + - name + - value + type: object + type: array + name: + type: string + type: object + repoURL: + description: RepoURL is the URL to the repository + (Git or Helm) that contains the application + manifests + type: string + targetRevision: + description: TargetRevision defines the revision + of the source to sync the application to. + In case of Git, this can be commit, tag, or + branch. If omitted, will equal to HEAD. In + case of Helm, this is a semver tag for the + Chart's version. + type: string + required: + - repoURL + type: object + syncPolicy: + description: SyncPolicy controls when and how a + sync will be performed + properties: + automated: + description: Automated will keep an application + synced to the target revision + properties: + allowEmpty: + description: 'AllowEmpty allows apps have + zero live resources (default: false)' + type: boolean + prune: + description: 'Prune specifies whether to + delete resources from the cluster that + are not found in the sources anymore as + part of automated sync (default: false)' + type: boolean + selfHeal: + description: 'SelfHeal specifes whether + to revert resources back to their desired + state upon modification in the cluster + (default: false)' + type: boolean + type: object + retry: + description: Retry controls failed sync retry + behavior + properties: + backoff: + description: Backoff controls how to backoff + on subsequent retries of failed syncs + properties: + duration: + description: Duration is the amount + to back off. Default unit is seconds, + but could also be a duration (e.g. + "2m", "1h") + type: string + factor: + description: Factor is a factor to multiply + the base duration after each failed + retry + format: int64 + type: integer + maxDuration: + description: MaxDuration is the maximum + amount of time allowed for the backoff + strategy + type: string + type: object + limit: + description: Limit is the maximum number + of attempts for retrying a failed sync. + If set to 0, no retries will be performed. + format: int64 + type: integer + type: object + syncOptions: + description: Options allow you to specify whole + app sync-options + items: + type: string + type: array + type: object + required: + - destination + - project + - source + type: object + required: + - metadata + - spec + type: object + required: + - generators + type: object + pullRequest: + description: PullRequestGenerator defines a generator that scrapes + a PullRequest API to find candidate pull requests. + properties: + github: + description: Which provider to use and config for it. + properties: + api: + description: The GitHub API URL to talk to. If blank, + use https://api.github.com/. + type: string + labels: + description: Labels is used to filter the PRs that you + want to target + items: + type: string + type: array + owner: + description: GitHub org or user to scan. Required. + type: string + repo: + description: GitHub repo name to scan. Required. + type: string + tokenRef: + description: Authentication token reference. + properties: + key: + type: string + secretName: + type: string + required: + - key + - secretName + type: object + required: + - owner + - repo + type: object + requeueAfterSeconds: + description: Standard parameters. + format: int64 + type: integer + template: + description: ApplicationSetTemplate represents argocd ApplicationSpec + properties: + metadata: + description: ApplicationSetTemplateMeta represents the + Argo CD application fields that may be used for Applications + generated from the ApplicationSet (based on metav1.ObjectMeta) + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: ApplicationSpec represents desired application + state. Contains link to repository with application + definition and additional parameters link definition + revision. + properties: + destination: + description: Destination is a reference to the target + Kubernetes server and namespace + properties: + name: + description: Name is an alternate way of specifying + the target cluster by its symbolic name + type: string + namespace: + description: Namespace specifies the target + namespace for the application's resources. + The namespace will only be set for namespace-scoped + resources that have not set a value for .metadata.namespace + type: string + server: + description: Server specifies the URL of the + target cluster and must be set to the Kubernetes + control plane API + type: string + type: object + ignoreDifferences: + description: IgnoreDifferences is a list of resources + and their fields which should be ignored during + comparison + items: + description: ResourceIgnoreDifferences contains + resource filter and list of json paths which + should be ignored during comparison with live + state. + properties: + group: + type: string + jqPathExpressions: + items: + type: string + type: array + jsonPointers: + items: + type: string + type: array + kind: + type: string + name: + type: string + namespace: + type: string + required: + - kind + type: object + type: array + info: + description: Info contains a list of information + (URLs, email addresses, and plain text) that relates + to the application + items: + properties: + name: + type: string + value: + type: string + required: + - name - value type: object type: array @@ -5360,8 +6416,6 @@ spec: - metadata - spec type: object - required: - - generators type: object scmProvider: description: SCMProviderGenerator defines a generator that scrapes diff --git a/manifests/install-with-argo-cd.yaml b/manifests/install-with-argo-cd.yaml index a6901337..03bd5504 100644 --- a/manifests/install-with-argo-cd.yaml +++ b/manifests/install-with-argo-cd.yaml @@ -4795,74 +4795,26 @@ spec: required: - elements type: object - scmProvider: - description: SCMProviderGenerator defines a generator that scrapes a SCMaaS API to find candidate repos. + pullRequest: + description: PullRequestGenerator defines a generator that scrapes a PullRequest API to find candidate pull requests. properties: - cloneProtocol: - description: Which protocol to use for the SCM URL. Default is provider-specific but ssh if possible. Not all providers necessarily support all protocols. - type: string - filters: - description: Filters for which repos should be considered. - items: - description: SCMProviderGeneratorFilter is a single repository filter. If multiple filter types are set on a single struct, they will be AND'd together. All filters must pass for a repo to be included. - properties: - branchMatch: - description: A regex which must match the branch name. - type: string - labelMatch: - description: A regex which must match at least one label. - type: string - pathsExist: - description: An array of paths, all of which must exist. - items: - type: string - type: array - repositoryMatch: - description: A regex for repo names. - type: string - type: object - type: array github: description: Which provider to use and config for it. properties: - allBranches: - description: Scan all branches instead of just the default branch. - type: boolean api: description: The GitHub API URL to talk to. If blank, use https://api.github.com/. type: string - organization: - description: GitHub org to scan. Required. - type: string - tokenRef: - description: Authentication token reference. - properties: - key: - type: string - secretName: - type: string - required: - - key - - secretName - type: object - required: - - organization - type: object - gitlab: - description: SCMProviderGeneratorGitlab defines a connection info specific to Gitlab. - properties: - allBranches: - description: Scan all branches instead of just the default branch. - type: boolean - api: - description: The Gitlab API URL to talk to. + labels: + description: Labels is used to filter the PRs that you want to target + items: + type: string + type: array + owner: + description: GitHub org or user to scan. Required. type: string - group: - description: Gitlab group to scan. Required. You can use either the project id (recommended) or the full namespaced path. + repo: + description: GitHub repo name to scan. Required. type: string - includeSubgroups: - description: Recurse through subgroups (true) or scan only the base group (false). Defaults to "false" - type: boolean tokenRef: description: Authentication token reference. properties: @@ -4875,7 +4827,8 @@ spec: - secretName type: object required: - - group + - owner + - repo type: object requeueAfterSeconds: description: Standard parameters. @@ -5218,141 +5171,942 @@ spec: - spec type: object type: object - type: object - type: array - template: - description: ApplicationSetTemplate represents argocd ApplicationSpec - properties: - metadata: - description: ApplicationSetTemplateMeta represents the Argo CD application fields that may be used for Applications generated from the ApplicationSet (based on metav1.ObjectMeta) - properties: - annotations: - additionalProperties: - type: string - type: object - finalizers: - items: - type: string - type: array - labels: - additionalProperties: + scmProvider: + description: SCMProviderGenerator defines a generator that scrapes a SCMaaS API to find candidate repos. + properties: + cloneProtocol: + description: Which protocol to use for the SCM URL. Default is provider-specific but ssh if possible. Not all providers necessarily support all protocols. type: string - type: object - name: - type: string - namespace: - type: string - type: object - spec: - description: ApplicationSpec represents desired application state. Contains link to repository with application definition and additional parameters link definition revision. - properties: - destination: - description: Destination is a reference to the target Kubernetes server and namespace - properties: - name: - description: Name is an alternate way of specifying the target cluster by its symbolic name - type: string - namespace: - description: Namespace specifies the target namespace for the application's resources. The namespace will only be set for namespace-scoped resources that have not set a value for .metadata.namespace - type: string - server: - description: Server specifies the URL of the target cluster and must be set to the Kubernetes control plane API - type: string - type: object - ignoreDifferences: - description: IgnoreDifferences is a list of resources and their fields which should be ignored during comparison - items: - description: ResourceIgnoreDifferences contains resource filter and list of json paths which should be ignored during comparison with live state. - properties: - group: - type: string - jqPathExpressions: - items: + filters: + description: Filters for which repos should be considered. + items: + description: SCMProviderGeneratorFilter is a single repository filter. If multiple filter types are set on a single struct, they will be AND'd together. All filters must pass for a repo to be included. + properties: + branchMatch: + description: A regex which must match the branch name. type: string - type: array - jsonPointers: - items: + labelMatch: + description: A regex which must match at least one label. type: string - type: array - kind: - type: string - name: + pathsExist: + description: An array of paths, all of which must exist. + items: + type: string + type: array + repositoryMatch: + description: A regex for repo names. + type: string + type: object + type: array + github: + description: Which provider to use and config for it. + properties: + allBranches: + description: Scan all branches instead of just the default branch. + type: boolean + api: + description: The GitHub API URL to talk to. If blank, use https://api.github.com/. type: string - namespace: + organization: + description: GitHub org to scan. Required. type: string + tokenRef: + description: Authentication token reference. + properties: + key: + type: string + secretName: + type: string + required: + - key + - secretName + type: object required: - - kind + - organization type: object - type: array - info: - description: Info contains a list of information (URLs, email addresses, and plain text) that relates to the application - items: + gitlab: + description: SCMProviderGeneratorGitlab defines a connection info specific to Gitlab. properties: - name: + allBranches: + description: Scan all branches instead of just the default branch. + type: boolean + api: + description: The Gitlab API URL to talk to. type: string - value: + group: + description: Gitlab group to scan. Required. You can use either the project id (recommended) or the full namespaced path. type: string + includeSubgroups: + description: Recurse through subgroups (true) or scan only the base group (false). Defaults to "false" + type: boolean + tokenRef: + description: Authentication token reference. + properties: + key: + type: string + secretName: + type: string + required: + - key + - secretName + type: object required: - - name - - value + - group type: object - type: array - project: - description: Project is a reference to the project this application belongs to. The empty string means that application belongs to the 'default' project. - type: string - revisionHistoryLimit: - description: RevisionHistoryLimit limits the number of items kept in the application's revision history, which is used for informational purposes as well as for rollbacks to previous versions. This should only be changed in exceptional circumstances. Setting to zero will store no history. This will reduce storage used. Increasing will increase the space used to store the history, so we do not recommend increasing it. Default is 10. - format: int64 - type: integer - source: - description: Source is a reference to the location of the application's manifests or chart - properties: - chart: - description: Chart is a Helm chart name, and must be specified for applications sourced from a Helm repo. - type: string - directory: - description: Directory holds path/directory specific options - properties: - exclude: - description: Exclude contains a glob pattern to match paths against that should be explicitly excluded from being used during manifest generation - type: string - include: - description: Include contains a glob pattern to match paths against that should be explicitly included during manifest generation - type: string - jsonnet: - description: Jsonnet holds options specific to Jsonnet - properties: - extVars: - description: ExtVars is a list of Jsonnet External Variables - items: - description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation - properties: - code: - type: boolean - name: - type: string - value: - type: string - required: - - name - - value - type: object - type: array - libs: - description: Additional library search dirs - items: - type: string - type: array - tlas: - description: TLAS is a list of Jsonnet Top-level Arguments - items: - description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation - properties: - code: - type: boolean - name: - type: string - value: + requeueAfterSeconds: + description: Standard parameters. + format: int64 + type: integer + template: + description: ApplicationSetTemplate represents argocd ApplicationSpec + properties: + metadata: + description: ApplicationSetTemplateMeta represents the Argo CD application fields that may be used for Applications generated from the ApplicationSet (based on metav1.ObjectMeta) + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: ApplicationSpec represents desired application state. Contains link to repository with application definition and additional parameters link definition revision. + properties: + destination: + description: Destination is a reference to the target Kubernetes server and namespace + properties: + name: + description: Name is an alternate way of specifying the target cluster by its symbolic name + type: string + namespace: + description: Namespace specifies the target namespace for the application's resources. The namespace will only be set for namespace-scoped resources that have not set a value for .metadata.namespace + type: string + server: + description: Server specifies the URL of the target cluster and must be set to the Kubernetes control plane API + type: string + type: object + ignoreDifferences: + description: IgnoreDifferences is a list of resources and their fields which should be ignored during comparison + items: + description: ResourceIgnoreDifferences contains resource filter and list of json paths which should be ignored during comparison with live state. + properties: + group: + type: string + jqPathExpressions: + items: + type: string + type: array + jsonPointers: + items: + type: string + type: array + kind: + type: string + name: + type: string + namespace: + type: string + required: + - kind + type: object + type: array + info: + description: Info contains a list of information (URLs, email addresses, and plain text) that relates to the application + items: + properties: + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + project: + description: Project is a reference to the project this application belongs to. The empty string means that application belongs to the 'default' project. + type: string + revisionHistoryLimit: + description: RevisionHistoryLimit limits the number of items kept in the application's revision history, which is used for informational purposes as well as for rollbacks to previous versions. This should only be changed in exceptional circumstances. Setting to zero will store no history. This will reduce storage used. Increasing will increase the space used to store the history, so we do not recommend increasing it. Default is 10. + format: int64 + type: integer + source: + description: Source is a reference to the location of the application's manifests or chart + properties: + chart: + description: Chart is a Helm chart name, and must be specified for applications sourced from a Helm repo. + type: string + directory: + description: Directory holds path/directory specific options + properties: + exclude: + description: Exclude contains a glob pattern to match paths against that should be explicitly excluded from being used during manifest generation + type: string + include: + description: Include contains a glob pattern to match paths against that should be explicitly included during manifest generation + type: string + jsonnet: + description: Jsonnet holds options specific to Jsonnet + properties: + extVars: + description: ExtVars is a list of Jsonnet External Variables + items: + description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation + properties: + code: + type: boolean + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + libs: + description: Additional library search dirs + items: + type: string + type: array + tlas: + description: TLAS is a list of Jsonnet Top-level Arguments + items: + description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation + properties: + code: + type: boolean + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + type: object + recurse: + description: Recurse specifies whether to scan a directory recursively for manifests + type: boolean + type: object + helm: + description: Helm holds helm specific options + properties: + fileParameters: + description: FileParameters are file parameters to the helm template + items: + description: HelmFileParameter is a file parameter that's passed to helm template during manifest generation + properties: + name: + description: Name is the name of the Helm parameter + type: string + path: + description: Path is the path to the file containing the values for the Helm parameter + type: string + type: object + type: array + parameters: + description: Parameters is a list of Helm parameters which are passed to the helm template command upon manifest generation + items: + description: HelmParameter is a parameter that's passed to helm template during manifest generation + properties: + forceString: + description: ForceString determines whether to tell Helm to interpret booleans and numbers as strings + type: boolean + name: + description: Name is the name of the Helm parameter + type: string + value: + description: Value is the value for the Helm parameter + type: string + type: object + type: array + releaseName: + description: ReleaseName is the Helm release name to use. If omitted it will use the application name + type: string + valueFiles: + description: ValuesFiles is a list of Helm value files to use when generating a template + items: + type: string + type: array + values: + description: Values specifies Helm values to be passed to helm template, typically defined as a block + type: string + version: + description: Version is the Helm version to use for templating (either "2" or "3") + type: string + type: object + ksonnet: + description: Ksonnet holds ksonnet specific options + properties: + environment: + description: Environment is a ksonnet application environment name + type: string + parameters: + description: Parameters are a list of ksonnet component parameter override values + items: + description: KsonnetParameter is a ksonnet component parameter + properties: + component: + type: string + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + type: object + kustomize: + description: Kustomize holds kustomize specific options + properties: + commonAnnotations: + additionalProperties: + type: string + description: CommonAnnotations is a list of additional annotations to add to rendered manifests + type: object + commonLabels: + additionalProperties: + type: string + description: CommonLabels is a list of additional labels to add to rendered manifests + type: object + forceCommonAnnotations: + description: ForceCommonAnnotations specifies whether to force applying common annotations to resources for Kustomize apps + type: boolean + forceCommonLabels: + description: ForceCommonLabels specifies whether to force applying common labels to resources for Kustomize apps + type: boolean + images: + description: Images is a list of Kustomize image override specifications + items: + description: KustomizeImage represents a Kustomize image definition in the format [old_image_name=]: + type: string + type: array + namePrefix: + description: NamePrefix is a prefix appended to resources for Kustomize apps + type: string + nameSuffix: + description: NameSuffix is a suffix appended to resources for Kustomize apps + type: string + version: + description: Version controls which version of Kustomize to use for rendering manifests + type: string + type: object + path: + description: Path is a directory path within the Git repository, and is only valid for applications sourced from Git. + type: string + plugin: + description: ConfigManagementPlugin holds config management plugin specific options + properties: + env: + description: Env is a list of environment variable entries + items: + description: EnvEntry represents an entry in the application's environment + properties: + name: + description: Name is the name of the variable, usually expressed in uppercase + type: string + value: + description: Value is the value of the variable + type: string + required: + - name + - value + type: object + type: array + name: + type: string + type: object + repoURL: + description: RepoURL is the URL to the repository (Git or Helm) that contains the application manifests + type: string + targetRevision: + description: TargetRevision defines the revision of the source to sync the application to. In case of Git, this can be commit, tag, or branch. If omitted, will equal to HEAD. In case of Helm, this is a semver tag for the Chart's version. + type: string + required: + - repoURL + type: object + syncPolicy: + description: SyncPolicy controls when and how a sync will be performed + properties: + automated: + description: Automated will keep an application synced to the target revision + properties: + allowEmpty: + description: 'AllowEmpty allows apps have zero live resources (default: false)' + type: boolean + prune: + description: 'Prune specifies whether to delete resources from the cluster that are not found in the sources anymore as part of automated sync (default: false)' + type: boolean + selfHeal: + description: 'SelfHeal specifes whether to revert resources back to their desired state upon modification in the cluster (default: false)' + type: boolean + type: object + retry: + description: Retry controls failed sync retry behavior + properties: + backoff: + description: Backoff controls how to backoff on subsequent retries of failed syncs + properties: + duration: + description: Duration is the amount to back off. Default unit is seconds, but could also be a duration (e.g. "2m", "1h") + type: string + factor: + description: Factor is a factor to multiply the base duration after each failed retry + format: int64 + type: integer + maxDuration: + description: MaxDuration is the maximum amount of time allowed for the backoff strategy + type: string + type: object + limit: + description: Limit is the maximum number of attempts for retrying a failed sync. If set to 0, no retries will be performed. + format: int64 + type: integer + type: object + syncOptions: + description: Options allow you to specify whole app sync-options + items: + type: string + type: array + type: object + required: + - destination + - project + - source + type: object + required: + - metadata + - spec + type: object + type: object + type: object + type: array + template: + description: ApplicationSetTemplate represents argocd ApplicationSpec + properties: + metadata: + description: ApplicationSetTemplateMeta represents the Argo CD application fields that may be used for Applications generated from the ApplicationSet (based on metav1.ObjectMeta) + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: ApplicationSpec represents desired application state. Contains link to repository with application definition and additional parameters link definition revision. + properties: + destination: + description: Destination is a reference to the target Kubernetes server and namespace + properties: + name: + description: Name is an alternate way of specifying the target cluster by its symbolic name + type: string + namespace: + description: Namespace specifies the target namespace for the application's resources. The namespace will only be set for namespace-scoped resources that have not set a value for .metadata.namespace + type: string + server: + description: Server specifies the URL of the target cluster and must be set to the Kubernetes control plane API + type: string + type: object + ignoreDifferences: + description: IgnoreDifferences is a list of resources and their fields which should be ignored during comparison + items: + description: ResourceIgnoreDifferences contains resource filter and list of json paths which should be ignored during comparison with live state. + properties: + group: + type: string + jqPathExpressions: + items: + type: string + type: array + jsonPointers: + items: + type: string + type: array + kind: + type: string + name: + type: string + namespace: + type: string + required: + - kind + type: object + type: array + info: + description: Info contains a list of information (URLs, email addresses, and plain text) that relates to the application + items: + properties: + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + project: + description: Project is a reference to the project this application belongs to. The empty string means that application belongs to the 'default' project. + type: string + revisionHistoryLimit: + description: RevisionHistoryLimit limits the number of items kept in the application's revision history, which is used for informational purposes as well as for rollbacks to previous versions. This should only be changed in exceptional circumstances. Setting to zero will store no history. This will reduce storage used. Increasing will increase the space used to store the history, so we do not recommend increasing it. Default is 10. + format: int64 + type: integer + source: + description: Source is a reference to the location of the application's manifests or chart + properties: + chart: + description: Chart is a Helm chart name, and must be specified for applications sourced from a Helm repo. + type: string + directory: + description: Directory holds path/directory specific options + properties: + exclude: + description: Exclude contains a glob pattern to match paths against that should be explicitly excluded from being used during manifest generation + type: string + include: + description: Include contains a glob pattern to match paths against that should be explicitly included during manifest generation + type: string + jsonnet: + description: Jsonnet holds options specific to Jsonnet + properties: + extVars: + description: ExtVars is a list of Jsonnet External Variables + items: + description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation + properties: + code: + type: boolean + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + libs: + description: Additional library search dirs + items: + type: string + type: array + tlas: + description: TLAS is a list of Jsonnet Top-level Arguments + items: + description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation + properties: + code: + type: boolean + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + type: object + recurse: + description: Recurse specifies whether to scan a directory recursively for manifests + type: boolean + type: object + helm: + description: Helm holds helm specific options + properties: + fileParameters: + description: FileParameters are file parameters to the helm template + items: + description: HelmFileParameter is a file parameter that's passed to helm template during manifest generation + properties: + name: + description: Name is the name of the Helm parameter + type: string + path: + description: Path is the path to the file containing the values for the Helm parameter + type: string + type: object + type: array + parameters: + description: Parameters is a list of Helm parameters which are passed to the helm template command upon manifest generation + items: + description: HelmParameter is a parameter that's passed to helm template during manifest generation + properties: + forceString: + description: ForceString determines whether to tell Helm to interpret booleans and numbers as strings + type: boolean + name: + description: Name is the name of the Helm parameter + type: string + value: + description: Value is the value for the Helm parameter + type: string + type: object + type: array + releaseName: + description: ReleaseName is the Helm release name to use. If omitted it will use the application name + type: string + valueFiles: + description: ValuesFiles is a list of Helm value files to use when generating a template + items: + type: string + type: array + values: + description: Values specifies Helm values to be passed to helm template, typically defined as a block + type: string + version: + description: Version is the Helm version to use for templating (either "2" or "3") + type: string + type: object + ksonnet: + description: Ksonnet holds ksonnet specific options + properties: + environment: + description: Environment is a ksonnet application environment name + type: string + parameters: + description: Parameters are a list of ksonnet component parameter override values + items: + description: KsonnetParameter is a ksonnet component parameter + properties: + component: + type: string + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + type: object + kustomize: + description: Kustomize holds kustomize specific options + properties: + commonAnnotations: + additionalProperties: + type: string + description: CommonAnnotations is a list of additional annotations to add to rendered manifests + type: object + commonLabels: + additionalProperties: + type: string + description: CommonLabels is a list of additional labels to add to rendered manifests + type: object + forceCommonAnnotations: + description: ForceCommonAnnotations specifies whether to force applying common annotations to resources for Kustomize apps + type: boolean + forceCommonLabels: + description: ForceCommonLabels specifies whether to force applying common labels to resources for Kustomize apps + type: boolean + images: + description: Images is a list of Kustomize image override specifications + items: + description: KustomizeImage represents a Kustomize image definition in the format [old_image_name=]: + type: string + type: array + namePrefix: + description: NamePrefix is a prefix appended to resources for Kustomize apps + type: string + nameSuffix: + description: NameSuffix is a suffix appended to resources for Kustomize apps + type: string + version: + description: Version controls which version of Kustomize to use for rendering manifests + type: string + type: object + path: + description: Path is a directory path within the Git repository, and is only valid for applications sourced from Git. + type: string + plugin: + description: ConfigManagementPlugin holds config management plugin specific options + properties: + env: + description: Env is a list of environment variable entries + items: + description: EnvEntry represents an entry in the application's environment + properties: + name: + description: Name is the name of the variable, usually expressed in uppercase + type: string + value: + description: Value is the value of the variable + type: string + required: + - name + - value + type: object + type: array + name: + type: string + type: object + repoURL: + description: RepoURL is the URL to the repository (Git or Helm) that contains the application manifests + type: string + targetRevision: + description: TargetRevision defines the revision of the source to sync the application to. In case of Git, this can be commit, tag, or branch. If omitted, will equal to HEAD. In case of Helm, this is a semver tag for the Chart's version. + type: string + required: + - repoURL + type: object + syncPolicy: + description: SyncPolicy controls when and how a sync will be performed + properties: + automated: + description: Automated will keep an application synced to the target revision + properties: + allowEmpty: + description: 'AllowEmpty allows apps have zero live resources (default: false)' + type: boolean + prune: + description: 'Prune specifies whether to delete resources from the cluster that are not found in the sources anymore as part of automated sync (default: false)' + type: boolean + selfHeal: + description: 'SelfHeal specifes whether to revert resources back to their desired state upon modification in the cluster (default: false)' + type: boolean + type: object + retry: + description: Retry controls failed sync retry behavior + properties: + backoff: + description: Backoff controls how to backoff on subsequent retries of failed syncs + properties: + duration: + description: Duration is the amount to back off. Default unit is seconds, but could also be a duration (e.g. "2m", "1h") + type: string + factor: + description: Factor is a factor to multiply the base duration after each failed retry + format: int64 + type: integer + maxDuration: + description: MaxDuration is the maximum amount of time allowed for the backoff strategy + type: string + type: object + limit: + description: Limit is the maximum number of attempts for retrying a failed sync. If set to 0, no retries will be performed. + format: int64 + type: integer + type: object + syncOptions: + description: Options allow you to specify whole app sync-options + items: + type: string + type: array + type: object + required: + - destination + - project + - source + type: object + required: + - metadata + - spec + type: object + required: + - generators + type: object + pullRequest: + description: PullRequestGenerator defines a generator that scrapes a PullRequest API to find candidate pull requests. + properties: + github: + description: Which provider to use and config for it. + properties: + api: + description: The GitHub API URL to talk to. If blank, use https://api.github.com/. + type: string + labels: + description: Labels is used to filter the PRs that you want to target + items: + type: string + type: array + owner: + description: GitHub org or user to scan. Required. + type: string + repo: + description: GitHub repo name to scan. Required. + type: string + tokenRef: + description: Authentication token reference. + properties: + key: + type: string + secretName: + type: string + required: + - key + - secretName + type: object + required: + - owner + - repo + type: object + requeueAfterSeconds: + description: Standard parameters. + format: int64 + type: integer + template: + description: ApplicationSetTemplate represents argocd ApplicationSpec + properties: + metadata: + description: ApplicationSetTemplateMeta represents the Argo CD application fields that may be used for Applications generated from the ApplicationSet (based on metav1.ObjectMeta) + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: ApplicationSpec represents desired application state. Contains link to repository with application definition and additional parameters link definition revision. + properties: + destination: + description: Destination is a reference to the target Kubernetes server and namespace + properties: + name: + description: Name is an alternate way of specifying the target cluster by its symbolic name + type: string + namespace: + description: Namespace specifies the target namespace for the application's resources. The namespace will only be set for namespace-scoped resources that have not set a value for .metadata.namespace + type: string + server: + description: Server specifies the URL of the target cluster and must be set to the Kubernetes control plane API + type: string + type: object + ignoreDifferences: + description: IgnoreDifferences is a list of resources and their fields which should be ignored during comparison + items: + description: ResourceIgnoreDifferences contains resource filter and list of json paths which should be ignored during comparison with live state. + properties: + group: + type: string + jqPathExpressions: + items: + type: string + type: array + jsonPointers: + items: + type: string + type: array + kind: + type: string + name: + type: string + namespace: + type: string + required: + - kind + type: object + type: array + info: + description: Info contains a list of information (URLs, email addresses, and plain text) that relates to the application + items: + properties: + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + project: + description: Project is a reference to the project this application belongs to. The empty string means that application belongs to the 'default' project. + type: string + revisionHistoryLimit: + description: RevisionHistoryLimit limits the number of items kept in the application's revision history, which is used for informational purposes as well as for rollbacks to previous versions. This should only be changed in exceptional circumstances. Setting to zero will store no history. This will reduce storage used. Increasing will increase the space used to store the history, so we do not recommend increasing it. Default is 10. + format: int64 + type: integer + source: + description: Source is a reference to the location of the application's manifests or chart + properties: + chart: + description: Chart is a Helm chart name, and must be specified for applications sourced from a Helm repo. + type: string + directory: + description: Directory holds path/directory specific options + properties: + exclude: + description: Exclude contains a glob pattern to match paths against that should be explicitly excluded from being used during manifest generation + type: string + include: + description: Include contains a glob pattern to match paths against that should be explicitly included during manifest generation + type: string + jsonnet: + description: Jsonnet holds options specific to Jsonnet + properties: + extVars: + description: ExtVars is a list of Jsonnet External Variables + items: + description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation + properties: + code: + type: boolean + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + libs: + description: Additional library search dirs + items: + type: string + type: array + tlas: + description: TLAS is a list of Jsonnet Top-level Arguments + items: + description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation + properties: + code: + type: boolean + name: + type: string + value: type: string required: - name @@ -5556,8 +6310,6 @@ spec: - metadata - spec type: object - required: - - generators type: object scmProvider: description: SCMProviderGenerator defines a generator that scrapes a SCMaaS API to find candidate repos. diff --git a/manifests/install.yaml b/manifests/install.yaml index 278e45ab..d71b0820 100644 --- a/manifests/install.yaml +++ b/manifests/install.yaml @@ -2995,74 +2995,26 @@ spec: required: - elements type: object - scmProvider: - description: SCMProviderGenerator defines a generator that scrapes a SCMaaS API to find candidate repos. + pullRequest: + description: PullRequestGenerator defines a generator that scrapes a PullRequest API to find candidate pull requests. properties: - cloneProtocol: - description: Which protocol to use for the SCM URL. Default is provider-specific but ssh if possible. Not all providers necessarily support all protocols. - type: string - filters: - description: Filters for which repos should be considered. - items: - description: SCMProviderGeneratorFilter is a single repository filter. If multiple filter types are set on a single struct, they will be AND'd together. All filters must pass for a repo to be included. - properties: - branchMatch: - description: A regex which must match the branch name. - type: string - labelMatch: - description: A regex which must match at least one label. - type: string - pathsExist: - description: An array of paths, all of which must exist. - items: - type: string - type: array - repositoryMatch: - description: A regex for repo names. - type: string - type: object - type: array github: description: Which provider to use and config for it. properties: - allBranches: - description: Scan all branches instead of just the default branch. - type: boolean api: description: The GitHub API URL to talk to. If blank, use https://api.github.com/. type: string - organization: - description: GitHub org to scan. Required. - type: string - tokenRef: - description: Authentication token reference. - properties: - key: - type: string - secretName: - type: string - required: - - key - - secretName - type: object - required: - - organization - type: object - gitlab: - description: SCMProviderGeneratorGitlab defines a connection info specific to Gitlab. - properties: - allBranches: - description: Scan all branches instead of just the default branch. - type: boolean - api: - description: The Gitlab API URL to talk to. + labels: + description: Labels is used to filter the PRs that you want to target + items: + type: string + type: array + owner: + description: GitHub org or user to scan. Required. type: string - group: - description: Gitlab group to scan. Required. You can use either the project id (recommended) or the full namespaced path. + repo: + description: GitHub repo name to scan. Required. type: string - includeSubgroups: - description: Recurse through subgroups (true) or scan only the base group (false). Defaults to "false" - type: boolean tokenRef: description: Authentication token reference. properties: @@ -3075,7 +3027,8 @@ spec: - secretName type: object required: - - group + - owner + - repo type: object requeueAfterSeconds: description: Standard parameters. @@ -3418,141 +3371,942 @@ spec: - spec type: object type: object - type: object - type: array - template: - description: ApplicationSetTemplate represents argocd ApplicationSpec - properties: - metadata: - description: ApplicationSetTemplateMeta represents the Argo CD application fields that may be used for Applications generated from the ApplicationSet (based on metav1.ObjectMeta) - properties: - annotations: - additionalProperties: - type: string - type: object - finalizers: - items: - type: string - type: array - labels: - additionalProperties: + scmProvider: + description: SCMProviderGenerator defines a generator that scrapes a SCMaaS API to find candidate repos. + properties: + cloneProtocol: + description: Which protocol to use for the SCM URL. Default is provider-specific but ssh if possible. Not all providers necessarily support all protocols. type: string - type: object - name: - type: string - namespace: - type: string - type: object - spec: - description: ApplicationSpec represents desired application state. Contains link to repository with application definition and additional parameters link definition revision. - properties: - destination: - description: Destination is a reference to the target Kubernetes server and namespace - properties: - name: - description: Name is an alternate way of specifying the target cluster by its symbolic name - type: string - namespace: - description: Namespace specifies the target namespace for the application's resources. The namespace will only be set for namespace-scoped resources that have not set a value for .metadata.namespace - type: string - server: - description: Server specifies the URL of the target cluster and must be set to the Kubernetes control plane API - type: string - type: object - ignoreDifferences: - description: IgnoreDifferences is a list of resources and their fields which should be ignored during comparison - items: - description: ResourceIgnoreDifferences contains resource filter and list of json paths which should be ignored during comparison with live state. - properties: - group: - type: string - jqPathExpressions: - items: + filters: + description: Filters for which repos should be considered. + items: + description: SCMProviderGeneratorFilter is a single repository filter. If multiple filter types are set on a single struct, they will be AND'd together. All filters must pass for a repo to be included. + properties: + branchMatch: + description: A regex which must match the branch name. type: string - type: array - jsonPointers: - items: + labelMatch: + description: A regex which must match at least one label. type: string - type: array - kind: - type: string - name: + pathsExist: + description: An array of paths, all of which must exist. + items: + type: string + type: array + repositoryMatch: + description: A regex for repo names. + type: string + type: object + type: array + github: + description: Which provider to use and config for it. + properties: + allBranches: + description: Scan all branches instead of just the default branch. + type: boolean + api: + description: The GitHub API URL to talk to. If blank, use https://api.github.com/. type: string - namespace: + organization: + description: GitHub org to scan. Required. type: string + tokenRef: + description: Authentication token reference. + properties: + key: + type: string + secretName: + type: string + required: + - key + - secretName + type: object required: - - kind + - organization type: object - type: array - info: - description: Info contains a list of information (URLs, email addresses, and plain text) that relates to the application - items: + gitlab: + description: SCMProviderGeneratorGitlab defines a connection info specific to Gitlab. properties: - name: + allBranches: + description: Scan all branches instead of just the default branch. + type: boolean + api: + description: The Gitlab API URL to talk to. type: string - value: + group: + description: Gitlab group to scan. Required. You can use either the project id (recommended) or the full namespaced path. type: string + includeSubgroups: + description: Recurse through subgroups (true) or scan only the base group (false). Defaults to "false" + type: boolean + tokenRef: + description: Authentication token reference. + properties: + key: + type: string + secretName: + type: string + required: + - key + - secretName + type: object required: - - name - - value + - group type: object - type: array - project: - description: Project is a reference to the project this application belongs to. The empty string means that application belongs to the 'default' project. - type: string - revisionHistoryLimit: - description: RevisionHistoryLimit limits the number of items kept in the application's revision history, which is used for informational purposes as well as for rollbacks to previous versions. This should only be changed in exceptional circumstances. Setting to zero will store no history. This will reduce storage used. Increasing will increase the space used to store the history, so we do not recommend increasing it. Default is 10. - format: int64 - type: integer - source: - description: Source is a reference to the location of the application's manifests or chart - properties: - chart: - description: Chart is a Helm chart name, and must be specified for applications sourced from a Helm repo. - type: string - directory: - description: Directory holds path/directory specific options - properties: - exclude: - description: Exclude contains a glob pattern to match paths against that should be explicitly excluded from being used during manifest generation - type: string - include: - description: Include contains a glob pattern to match paths against that should be explicitly included during manifest generation - type: string - jsonnet: - description: Jsonnet holds options specific to Jsonnet - properties: - extVars: - description: ExtVars is a list of Jsonnet External Variables - items: - description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation - properties: - code: - type: boolean - name: - type: string - value: - type: string - required: - - name - - value - type: object - type: array - libs: - description: Additional library search dirs - items: - type: string - type: array - tlas: - description: TLAS is a list of Jsonnet Top-level Arguments - items: - description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation - properties: - code: - type: boolean - name: - type: string - value: + requeueAfterSeconds: + description: Standard parameters. + format: int64 + type: integer + template: + description: ApplicationSetTemplate represents argocd ApplicationSpec + properties: + metadata: + description: ApplicationSetTemplateMeta represents the Argo CD application fields that may be used for Applications generated from the ApplicationSet (based on metav1.ObjectMeta) + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: ApplicationSpec represents desired application state. Contains link to repository with application definition and additional parameters link definition revision. + properties: + destination: + description: Destination is a reference to the target Kubernetes server and namespace + properties: + name: + description: Name is an alternate way of specifying the target cluster by its symbolic name + type: string + namespace: + description: Namespace specifies the target namespace for the application's resources. The namespace will only be set for namespace-scoped resources that have not set a value for .metadata.namespace + type: string + server: + description: Server specifies the URL of the target cluster and must be set to the Kubernetes control plane API + type: string + type: object + ignoreDifferences: + description: IgnoreDifferences is a list of resources and their fields which should be ignored during comparison + items: + description: ResourceIgnoreDifferences contains resource filter and list of json paths which should be ignored during comparison with live state. + properties: + group: + type: string + jqPathExpressions: + items: + type: string + type: array + jsonPointers: + items: + type: string + type: array + kind: + type: string + name: + type: string + namespace: + type: string + required: + - kind + type: object + type: array + info: + description: Info contains a list of information (URLs, email addresses, and plain text) that relates to the application + items: + properties: + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + project: + description: Project is a reference to the project this application belongs to. The empty string means that application belongs to the 'default' project. + type: string + revisionHistoryLimit: + description: RevisionHistoryLimit limits the number of items kept in the application's revision history, which is used for informational purposes as well as for rollbacks to previous versions. This should only be changed in exceptional circumstances. Setting to zero will store no history. This will reduce storage used. Increasing will increase the space used to store the history, so we do not recommend increasing it. Default is 10. + format: int64 + type: integer + source: + description: Source is a reference to the location of the application's manifests or chart + properties: + chart: + description: Chart is a Helm chart name, and must be specified for applications sourced from a Helm repo. + type: string + directory: + description: Directory holds path/directory specific options + properties: + exclude: + description: Exclude contains a glob pattern to match paths against that should be explicitly excluded from being used during manifest generation + type: string + include: + description: Include contains a glob pattern to match paths against that should be explicitly included during manifest generation + type: string + jsonnet: + description: Jsonnet holds options specific to Jsonnet + properties: + extVars: + description: ExtVars is a list of Jsonnet External Variables + items: + description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation + properties: + code: + type: boolean + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + libs: + description: Additional library search dirs + items: + type: string + type: array + tlas: + description: TLAS is a list of Jsonnet Top-level Arguments + items: + description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation + properties: + code: + type: boolean + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + type: object + recurse: + description: Recurse specifies whether to scan a directory recursively for manifests + type: boolean + type: object + helm: + description: Helm holds helm specific options + properties: + fileParameters: + description: FileParameters are file parameters to the helm template + items: + description: HelmFileParameter is a file parameter that's passed to helm template during manifest generation + properties: + name: + description: Name is the name of the Helm parameter + type: string + path: + description: Path is the path to the file containing the values for the Helm parameter + type: string + type: object + type: array + parameters: + description: Parameters is a list of Helm parameters which are passed to the helm template command upon manifest generation + items: + description: HelmParameter is a parameter that's passed to helm template during manifest generation + properties: + forceString: + description: ForceString determines whether to tell Helm to interpret booleans and numbers as strings + type: boolean + name: + description: Name is the name of the Helm parameter + type: string + value: + description: Value is the value for the Helm parameter + type: string + type: object + type: array + releaseName: + description: ReleaseName is the Helm release name to use. If omitted it will use the application name + type: string + valueFiles: + description: ValuesFiles is a list of Helm value files to use when generating a template + items: + type: string + type: array + values: + description: Values specifies Helm values to be passed to helm template, typically defined as a block + type: string + version: + description: Version is the Helm version to use for templating (either "2" or "3") + type: string + type: object + ksonnet: + description: Ksonnet holds ksonnet specific options + properties: + environment: + description: Environment is a ksonnet application environment name + type: string + parameters: + description: Parameters are a list of ksonnet component parameter override values + items: + description: KsonnetParameter is a ksonnet component parameter + properties: + component: + type: string + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + type: object + kustomize: + description: Kustomize holds kustomize specific options + properties: + commonAnnotations: + additionalProperties: + type: string + description: CommonAnnotations is a list of additional annotations to add to rendered manifests + type: object + commonLabels: + additionalProperties: + type: string + description: CommonLabels is a list of additional labels to add to rendered manifests + type: object + forceCommonAnnotations: + description: ForceCommonAnnotations specifies whether to force applying common annotations to resources for Kustomize apps + type: boolean + forceCommonLabels: + description: ForceCommonLabels specifies whether to force applying common labels to resources for Kustomize apps + type: boolean + images: + description: Images is a list of Kustomize image override specifications + items: + description: KustomizeImage represents a Kustomize image definition in the format [old_image_name=]: + type: string + type: array + namePrefix: + description: NamePrefix is a prefix appended to resources for Kustomize apps + type: string + nameSuffix: + description: NameSuffix is a suffix appended to resources for Kustomize apps + type: string + version: + description: Version controls which version of Kustomize to use for rendering manifests + type: string + type: object + path: + description: Path is a directory path within the Git repository, and is only valid for applications sourced from Git. + type: string + plugin: + description: ConfigManagementPlugin holds config management plugin specific options + properties: + env: + description: Env is a list of environment variable entries + items: + description: EnvEntry represents an entry in the application's environment + properties: + name: + description: Name is the name of the variable, usually expressed in uppercase + type: string + value: + description: Value is the value of the variable + type: string + required: + - name + - value + type: object + type: array + name: + type: string + type: object + repoURL: + description: RepoURL is the URL to the repository (Git or Helm) that contains the application manifests + type: string + targetRevision: + description: TargetRevision defines the revision of the source to sync the application to. In case of Git, this can be commit, tag, or branch. If omitted, will equal to HEAD. In case of Helm, this is a semver tag for the Chart's version. + type: string + required: + - repoURL + type: object + syncPolicy: + description: SyncPolicy controls when and how a sync will be performed + properties: + automated: + description: Automated will keep an application synced to the target revision + properties: + allowEmpty: + description: 'AllowEmpty allows apps have zero live resources (default: false)' + type: boolean + prune: + description: 'Prune specifies whether to delete resources from the cluster that are not found in the sources anymore as part of automated sync (default: false)' + type: boolean + selfHeal: + description: 'SelfHeal specifes whether to revert resources back to their desired state upon modification in the cluster (default: false)' + type: boolean + type: object + retry: + description: Retry controls failed sync retry behavior + properties: + backoff: + description: Backoff controls how to backoff on subsequent retries of failed syncs + properties: + duration: + description: Duration is the amount to back off. Default unit is seconds, but could also be a duration (e.g. "2m", "1h") + type: string + factor: + description: Factor is a factor to multiply the base duration after each failed retry + format: int64 + type: integer + maxDuration: + description: MaxDuration is the maximum amount of time allowed for the backoff strategy + type: string + type: object + limit: + description: Limit is the maximum number of attempts for retrying a failed sync. If set to 0, no retries will be performed. + format: int64 + type: integer + type: object + syncOptions: + description: Options allow you to specify whole app sync-options + items: + type: string + type: array + type: object + required: + - destination + - project + - source + type: object + required: + - metadata + - spec + type: object + type: object + type: object + type: array + template: + description: ApplicationSetTemplate represents argocd ApplicationSpec + properties: + metadata: + description: ApplicationSetTemplateMeta represents the Argo CD application fields that may be used for Applications generated from the ApplicationSet (based on metav1.ObjectMeta) + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: ApplicationSpec represents desired application state. Contains link to repository with application definition and additional parameters link definition revision. + properties: + destination: + description: Destination is a reference to the target Kubernetes server and namespace + properties: + name: + description: Name is an alternate way of specifying the target cluster by its symbolic name + type: string + namespace: + description: Namespace specifies the target namespace for the application's resources. The namespace will only be set for namespace-scoped resources that have not set a value for .metadata.namespace + type: string + server: + description: Server specifies the URL of the target cluster and must be set to the Kubernetes control plane API + type: string + type: object + ignoreDifferences: + description: IgnoreDifferences is a list of resources and their fields which should be ignored during comparison + items: + description: ResourceIgnoreDifferences contains resource filter and list of json paths which should be ignored during comparison with live state. + properties: + group: + type: string + jqPathExpressions: + items: + type: string + type: array + jsonPointers: + items: + type: string + type: array + kind: + type: string + name: + type: string + namespace: + type: string + required: + - kind + type: object + type: array + info: + description: Info contains a list of information (URLs, email addresses, and plain text) that relates to the application + items: + properties: + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + project: + description: Project is a reference to the project this application belongs to. The empty string means that application belongs to the 'default' project. + type: string + revisionHistoryLimit: + description: RevisionHistoryLimit limits the number of items kept in the application's revision history, which is used for informational purposes as well as for rollbacks to previous versions. This should only be changed in exceptional circumstances. Setting to zero will store no history. This will reduce storage used. Increasing will increase the space used to store the history, so we do not recommend increasing it. Default is 10. + format: int64 + type: integer + source: + description: Source is a reference to the location of the application's manifests or chart + properties: + chart: + description: Chart is a Helm chart name, and must be specified for applications sourced from a Helm repo. + type: string + directory: + description: Directory holds path/directory specific options + properties: + exclude: + description: Exclude contains a glob pattern to match paths against that should be explicitly excluded from being used during manifest generation + type: string + include: + description: Include contains a glob pattern to match paths against that should be explicitly included during manifest generation + type: string + jsonnet: + description: Jsonnet holds options specific to Jsonnet + properties: + extVars: + description: ExtVars is a list of Jsonnet External Variables + items: + description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation + properties: + code: + type: boolean + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + libs: + description: Additional library search dirs + items: + type: string + type: array + tlas: + description: TLAS is a list of Jsonnet Top-level Arguments + items: + description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation + properties: + code: + type: boolean + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + type: object + recurse: + description: Recurse specifies whether to scan a directory recursively for manifests + type: boolean + type: object + helm: + description: Helm holds helm specific options + properties: + fileParameters: + description: FileParameters are file parameters to the helm template + items: + description: HelmFileParameter is a file parameter that's passed to helm template during manifest generation + properties: + name: + description: Name is the name of the Helm parameter + type: string + path: + description: Path is the path to the file containing the values for the Helm parameter + type: string + type: object + type: array + parameters: + description: Parameters is a list of Helm parameters which are passed to the helm template command upon manifest generation + items: + description: HelmParameter is a parameter that's passed to helm template during manifest generation + properties: + forceString: + description: ForceString determines whether to tell Helm to interpret booleans and numbers as strings + type: boolean + name: + description: Name is the name of the Helm parameter + type: string + value: + description: Value is the value for the Helm parameter + type: string + type: object + type: array + releaseName: + description: ReleaseName is the Helm release name to use. If omitted it will use the application name + type: string + valueFiles: + description: ValuesFiles is a list of Helm value files to use when generating a template + items: + type: string + type: array + values: + description: Values specifies Helm values to be passed to helm template, typically defined as a block + type: string + version: + description: Version is the Helm version to use for templating (either "2" or "3") + type: string + type: object + ksonnet: + description: Ksonnet holds ksonnet specific options + properties: + environment: + description: Environment is a ksonnet application environment name + type: string + parameters: + description: Parameters are a list of ksonnet component parameter override values + items: + description: KsonnetParameter is a ksonnet component parameter + properties: + component: + type: string + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + type: object + kustomize: + description: Kustomize holds kustomize specific options + properties: + commonAnnotations: + additionalProperties: + type: string + description: CommonAnnotations is a list of additional annotations to add to rendered manifests + type: object + commonLabels: + additionalProperties: + type: string + description: CommonLabels is a list of additional labels to add to rendered manifests + type: object + forceCommonAnnotations: + description: ForceCommonAnnotations specifies whether to force applying common annotations to resources for Kustomize apps + type: boolean + forceCommonLabels: + description: ForceCommonLabels specifies whether to force applying common labels to resources for Kustomize apps + type: boolean + images: + description: Images is a list of Kustomize image override specifications + items: + description: KustomizeImage represents a Kustomize image definition in the format [old_image_name=]: + type: string + type: array + namePrefix: + description: NamePrefix is a prefix appended to resources for Kustomize apps + type: string + nameSuffix: + description: NameSuffix is a suffix appended to resources for Kustomize apps + type: string + version: + description: Version controls which version of Kustomize to use for rendering manifests + type: string + type: object + path: + description: Path is a directory path within the Git repository, and is only valid for applications sourced from Git. + type: string + plugin: + description: ConfigManagementPlugin holds config management plugin specific options + properties: + env: + description: Env is a list of environment variable entries + items: + description: EnvEntry represents an entry in the application's environment + properties: + name: + description: Name is the name of the variable, usually expressed in uppercase + type: string + value: + description: Value is the value of the variable + type: string + required: + - name + - value + type: object + type: array + name: + type: string + type: object + repoURL: + description: RepoURL is the URL to the repository (Git or Helm) that contains the application manifests + type: string + targetRevision: + description: TargetRevision defines the revision of the source to sync the application to. In case of Git, this can be commit, tag, or branch. If omitted, will equal to HEAD. In case of Helm, this is a semver tag for the Chart's version. + type: string + required: + - repoURL + type: object + syncPolicy: + description: SyncPolicy controls when and how a sync will be performed + properties: + automated: + description: Automated will keep an application synced to the target revision + properties: + allowEmpty: + description: 'AllowEmpty allows apps have zero live resources (default: false)' + type: boolean + prune: + description: 'Prune specifies whether to delete resources from the cluster that are not found in the sources anymore as part of automated sync (default: false)' + type: boolean + selfHeal: + description: 'SelfHeal specifes whether to revert resources back to their desired state upon modification in the cluster (default: false)' + type: boolean + type: object + retry: + description: Retry controls failed sync retry behavior + properties: + backoff: + description: Backoff controls how to backoff on subsequent retries of failed syncs + properties: + duration: + description: Duration is the amount to back off. Default unit is seconds, but could also be a duration (e.g. "2m", "1h") + type: string + factor: + description: Factor is a factor to multiply the base duration after each failed retry + format: int64 + type: integer + maxDuration: + description: MaxDuration is the maximum amount of time allowed for the backoff strategy + type: string + type: object + limit: + description: Limit is the maximum number of attempts for retrying a failed sync. If set to 0, no retries will be performed. + format: int64 + type: integer + type: object + syncOptions: + description: Options allow you to specify whole app sync-options + items: + type: string + type: array + type: object + required: + - destination + - project + - source + type: object + required: + - metadata + - spec + type: object + required: + - generators + type: object + pullRequest: + description: PullRequestGenerator defines a generator that scrapes a PullRequest API to find candidate pull requests. + properties: + github: + description: Which provider to use and config for it. + properties: + api: + description: The GitHub API URL to talk to. If blank, use https://api.github.com/. + type: string + labels: + description: Labels is used to filter the PRs that you want to target + items: + type: string + type: array + owner: + description: GitHub org or user to scan. Required. + type: string + repo: + description: GitHub repo name to scan. Required. + type: string + tokenRef: + description: Authentication token reference. + properties: + key: + type: string + secretName: + type: string + required: + - key + - secretName + type: object + required: + - owner + - repo + type: object + requeueAfterSeconds: + description: Standard parameters. + format: int64 + type: integer + template: + description: ApplicationSetTemplate represents argocd ApplicationSpec + properties: + metadata: + description: ApplicationSetTemplateMeta represents the Argo CD application fields that may be used for Applications generated from the ApplicationSet (based on metav1.ObjectMeta) + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: ApplicationSpec represents desired application state. Contains link to repository with application definition and additional parameters link definition revision. + properties: + destination: + description: Destination is a reference to the target Kubernetes server and namespace + properties: + name: + description: Name is an alternate way of specifying the target cluster by its symbolic name + type: string + namespace: + description: Namespace specifies the target namespace for the application's resources. The namespace will only be set for namespace-scoped resources that have not set a value for .metadata.namespace + type: string + server: + description: Server specifies the URL of the target cluster and must be set to the Kubernetes control plane API + type: string + type: object + ignoreDifferences: + description: IgnoreDifferences is a list of resources and their fields which should be ignored during comparison + items: + description: ResourceIgnoreDifferences contains resource filter and list of json paths which should be ignored during comparison with live state. + properties: + group: + type: string + jqPathExpressions: + items: + type: string + type: array + jsonPointers: + items: + type: string + type: array + kind: + type: string + name: + type: string + namespace: + type: string + required: + - kind + type: object + type: array + info: + description: Info contains a list of information (URLs, email addresses, and plain text) that relates to the application + items: + properties: + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + project: + description: Project is a reference to the project this application belongs to. The empty string means that application belongs to the 'default' project. + type: string + revisionHistoryLimit: + description: RevisionHistoryLimit limits the number of items kept in the application's revision history, which is used for informational purposes as well as for rollbacks to previous versions. This should only be changed in exceptional circumstances. Setting to zero will store no history. This will reduce storage used. Increasing will increase the space used to store the history, so we do not recommend increasing it. Default is 10. + format: int64 + type: integer + source: + description: Source is a reference to the location of the application's manifests or chart + properties: + chart: + description: Chart is a Helm chart name, and must be specified for applications sourced from a Helm repo. + type: string + directory: + description: Directory holds path/directory specific options + properties: + exclude: + description: Exclude contains a glob pattern to match paths against that should be explicitly excluded from being used during manifest generation + type: string + include: + description: Include contains a glob pattern to match paths against that should be explicitly included during manifest generation + type: string + jsonnet: + description: Jsonnet holds options specific to Jsonnet + properties: + extVars: + description: ExtVars is a list of Jsonnet External Variables + items: + description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation + properties: + code: + type: boolean + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array + libs: + description: Additional library search dirs + items: + type: string + type: array + tlas: + description: TLAS is a list of Jsonnet Top-level Arguments + items: + description: JsonnetVar represents a variable to be passed to jsonnet during manifest generation + properties: + code: + type: boolean + name: + type: string + value: type: string required: - name @@ -3756,8 +4510,6 @@ spec: - metadata - spec type: object - required: - - generators type: object scmProvider: description: SCMProviderGenerator defines a generator that scrapes a SCMaaS API to find candidate repos. diff --git a/mkdocs.yml b/mkdocs.yml index 1abba819..39d0ae3a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -34,6 +34,7 @@ nav: - Generators-Matrix.md - Generators-SCM-Provider.md - Generators-Cluster-Decision-Resource.md + - Generators-Pull-Request.md - Template fields: Template.md - Controlling Resource Modification: Controlling-Resource-Modification.md - Application Pruning & Resource Deletion: Application-Deletion.md diff --git a/pkg/generators/matrix.go b/pkg/generators/matrix.go index 91eb4ef8..9796bbf5 100644 --- a/pkg/generators/matrix.go +++ b/pkg/generators/matrix.go @@ -70,6 +70,7 @@ func (m *MatrixGenerator) getParams(appSetBaseGenerator argoprojiov1alpha1.Appli Git: appSetBaseGenerator.Git, SCMProvider: appSetBaseGenerator.SCMProvider, ClusterDecisionResource: appSetBaseGenerator.ClusterDecisionResource, + PullRequest: appSetBaseGenerator.PullRequest, }, m.supportedGenerators, argoprojiov1alpha1.ApplicationSetTemplate{}, diff --git a/pkg/generators/pull_request.go b/pkg/generators/pull_request.go new file mode 100644 index 00000000..574c6256 --- /dev/null +++ b/pkg/generators/pull_request.go @@ -0,0 +1,114 @@ +package generators + +import ( + "context" + "fmt" + "strconv" + "time" + + corev1 "k8s.io/api/core/v1" + "sigs.k8s.io/controller-runtime/pkg/client" + + argoprojiov1alpha1 "github.com/argoproj-labs/applicationset/api/v1alpha1" + pullrequest "github.com/argoproj-labs/applicationset/pkg/services/pull_request" +) + +var _ Generator = (*PullRequestGenerator)(nil) + +const ( + DefaultPullRequestRequeueAfterSeconds = 30 * time.Minute +) + +type PullRequestGenerator struct { + client client.Client + selectServiceProviderFunc func(context.Context, *argoprojiov1alpha1.PullRequestGenerator, *argoprojiov1alpha1.ApplicationSet) (pullrequest.PullRequestService, error) +} + +func NewPullRequestGenerator(client client.Client) Generator { + g := &PullRequestGenerator{ + client: client, + } + g.selectServiceProviderFunc = g.selectServiceProvider + return g +} + +func (g *PullRequestGenerator) GetRequeueAfter(appSetGenerator *argoprojiov1alpha1.ApplicationSetGenerator) time.Duration { + // Return a requeue default of 30 minutes, if no default is specified. + + if appSetGenerator.PullRequest.RequeueAfterSeconds != nil { + return time.Duration(*appSetGenerator.PullRequest.RequeueAfterSeconds) * time.Second + } + + return DefaultPullRequestRequeueAfterSeconds +} + +func (g *PullRequestGenerator) GetTemplate(appSetGenerator *argoprojiov1alpha1.ApplicationSetGenerator) *argoprojiov1alpha1.ApplicationSetTemplate { + return &appSetGenerator.PullRequest.Template +} + +func (g *PullRequestGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.ApplicationSetGenerator, applicationSetInfo *argoprojiov1alpha1.ApplicationSet) ([]map[string]string, error) { + if appSetGenerator == nil { + return nil, EmptyAppSetGeneratorError + } + + if appSetGenerator.PullRequest == nil { + return nil, EmptyAppSetGeneratorError + } + + ctx := context.Background() + svc, err := g.selectServiceProviderFunc(ctx, appSetGenerator.PullRequest, applicationSetInfo) + if err != nil { + return nil, fmt.Errorf("failed to select pull request service provider: %v", err) + } + + pulls, err := svc.List(ctx) + if err != nil { + return nil, fmt.Errorf("error listing repos: %v", err) + } + params := make([]map[string]string, 0, len(pulls)) + for _, pull := range pulls { + params = append(params, map[string]string{ + "number": strconv.Itoa(pull.Number), + "branch": pull.Branch, + "head_sha": pull.HeadSHA, + }) + } + return params, nil +} + +// selectServiceProvider selects the provider to get pull requests from the configuration +func (g *PullRequestGenerator) selectServiceProvider(ctx context.Context, generatorConfig *argoprojiov1alpha1.PullRequestGenerator, applicationSetInfo *argoprojiov1alpha1.ApplicationSet) (pullrequest.PullRequestService, error) { + if generatorConfig.Github != nil { + providerConfig := generatorConfig.Github + token, err := g.getSecretRef(ctx, providerConfig.TokenRef, applicationSetInfo.Namespace) + if err != nil { + return nil, fmt.Errorf("error fetching Secret token: %v", err) + } + return pullrequest.NewGithubService(ctx, token, providerConfig.API, providerConfig.Owner, providerConfig.Repo, providerConfig.Labels) + } + return nil, fmt.Errorf("no Pull Request provider implementation configured") +} + +// getSecretRef gets the value of the key for the specified Secret resource. +func (g *PullRequestGenerator) getSecretRef(ctx context.Context, ref *argoprojiov1alpha1.SecretRef, namespace string) (string, error) { + if ref == nil { + return "", nil + } + + secret := &corev1.Secret{} + err := g.client.Get( + ctx, + client.ObjectKey{ + Name: ref.SecretName, + Namespace: namespace, + }, + secret) + if err != nil { + return "", fmt.Errorf("error fetching secret %s/%s: %v", namespace, ref.SecretName, err) + } + tokenBytes, ok := secret.Data[ref.Key] + if !ok { + return "", fmt.Errorf("key %q in secret %s/%s not found", ref.Key, namespace, ref.SecretName) + } + return string(tokenBytes), nil +} diff --git a/pkg/generators/pull_request_test.go b/pkg/generators/pull_request_test.go new file mode 100644 index 00000000..89658214 --- /dev/null +++ b/pkg/generators/pull_request_test.go @@ -0,0 +1,136 @@ +package generators + +import ( + "context" + "errors" + "testing" + + "github.com/stretchr/testify/assert" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client/fake" + + argoprojiov1alpha1 "github.com/argoproj-labs/applicationset/api/v1alpha1" + pullrequest "github.com/argoproj-labs/applicationset/pkg/services/pull_request" +) + +func TestPullRequestGithubGenerateParams(t *testing.T) { + ctx := context.Background() + cases := []struct { + selectFunc func(context.Context, *argoprojiov1alpha1.PullRequestGenerator, *argoprojiov1alpha1.ApplicationSet) (pullrequest.PullRequestService, error) + expected []map[string]string + expectedErr error + }{ + { + selectFunc: func(context.Context, *argoprojiov1alpha1.PullRequestGenerator, *argoprojiov1alpha1.ApplicationSet) (pullrequest.PullRequestService, error) { + return pullrequest.NewFakeService( + ctx, + []*pullrequest.PullRequest{ + &pullrequest.PullRequest{ + Number: 1, + Branch: "branch1", + HeadSHA: "089d92cbf9ff857a39e6feccd32798ca700fb958", + }, + }, + nil, + ) + }, + expected: []map[string]string{ + { + "number": "1", + "branch": "branch1", + "head_sha": "089d92cbf9ff857a39e6feccd32798ca700fb958", + }, + }, + expectedErr: nil, + }, + { + selectFunc: func(context.Context, *argoprojiov1alpha1.PullRequestGenerator, *argoprojiov1alpha1.ApplicationSet) (pullrequest.PullRequestService, error) { + return pullrequest.NewFakeService( + ctx, + nil, + errors.New("fake error"), + ) + }, + expected: nil, + expectedErr: errors.New("error listing repos: fake error"), + }, + } + + for _, c := range cases { + gen := PullRequestGenerator{ + selectServiceProviderFunc: c.selectFunc, + } + generatorConfig := argoprojiov1alpha1.ApplicationSetGenerator{ + PullRequest: &argoprojiov1alpha1.PullRequestGenerator{}, + } + got, gotErr := gen.GenerateParams(&generatorConfig, nil) + assert.Equal(t, c.expectedErr, gotErr) + assert.ElementsMatch(t, c.expected, got) + } +} + +func TestPullRequestGetSecretRef(t *testing.T) { + secret := &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{Name: "test-secret", Namespace: "test"}, + Data: map[string][]byte{ + "my-token": []byte("secret"), + }, + } + gen := &PullRequestGenerator{client: fake.NewClientBuilder().WithObjects(secret).Build()} + ctx := context.Background() + + cases := []struct { + name, namespace, token string + ref *argoprojiov1alpha1.SecretRef + hasError bool + }{ + { + name: "valid ref", + ref: &argoprojiov1alpha1.SecretRef{SecretName: "test-secret", Key: "my-token"}, + namespace: "test", + token: "secret", + hasError: false, + }, + { + name: "nil ref", + ref: nil, + namespace: "test", + token: "", + hasError: false, + }, + { + name: "wrong name", + ref: &argoprojiov1alpha1.SecretRef{SecretName: "other", Key: "my-token"}, + namespace: "test", + token: "", + hasError: true, + }, + { + name: "wrong key", + ref: &argoprojiov1alpha1.SecretRef{SecretName: "test-secret", Key: "other-token"}, + namespace: "test", + token: "", + hasError: true, + }, + { + name: "wrong namespace", + ref: &argoprojiov1alpha1.SecretRef{SecretName: "test-secret", Key: "my-token"}, + namespace: "other", + token: "", + hasError: true, + }, + } + + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + token, err := gen.getSecretRef(ctx, c.ref, c.namespace) + if c.hasError { + assert.NotNil(t, err) + } else { + assert.Nil(t, err) + } + assert.Equal(t, c.token, token) + }) + } +} diff --git a/pkg/services/pull_request/fake.go b/pkg/services/pull_request/fake.go new file mode 100644 index 00000000..845df70d --- /dev/null +++ b/pkg/services/pull_request/fake.go @@ -0,0 +1,23 @@ +package pull_request + +import ( + "context" +) + +type FakeService struct { + listPullReuests []*PullRequest + listError error +} + +var _ PullRequestService = (*FakeService)(nil) + +func NewFakeService(_ context.Context, listPullReuests []*PullRequest, listError error) (PullRequestService, error) { + return &FakeService{ + listPullReuests: listPullReuests, + listError: listError, + }, nil +} + +func (g *FakeService) List(ctx context.Context) ([]*PullRequest, error) { + return g.listPullReuests, g.listError +} diff --git a/pkg/services/pull_request/github.go b/pkg/services/pull_request/github.go new file mode 100644 index 00000000..70453e42 --- /dev/null +++ b/pkg/services/pull_request/github.go @@ -0,0 +1,99 @@ +package pull_request + +import ( + "context" + "fmt" + "os" + + "github.com/google/go-github/v35/github" + "golang.org/x/oauth2" +) + +type GithubService struct { + client *github.Client + owner string + repo string + labels []string +} + +var _ PullRequestService = (*GithubService)(nil) + +func NewGithubService(ctx context.Context, token, url, owner, repo string, labels []string) (PullRequestService, error) { + var ts oauth2.TokenSource + // Undocumented environment variable to set a default token, to be used in testing to dodge anonymous rate limits. + if token == "" { + token = os.Getenv("GITHUB_TOKEN") + } + if token != "" { + ts = oauth2.StaticTokenSource( + &oauth2.Token{AccessToken: token}, + ) + } + httpClient := oauth2.NewClient(ctx, ts) + var client *github.Client + if url == "" { + client = github.NewClient(httpClient) + } else { + var err error + client, err = github.NewEnterpriseClient(url, url, httpClient) + if err != nil { + return nil, err + } + } + return &GithubService{ + client: client, + owner: owner, + repo: repo, + labels: labels, + }, nil +} + +func (g *GithubService) List(ctx context.Context) ([]*PullRequest, error) { + opts := &github.PullRequestListOptions{ + ListOptions: github.ListOptions{ + PerPage: 100, + }, + } + pullRequests := []*PullRequest{} + for { + pulls, resp, err := g.client.PullRequests.List(ctx, g.owner, g.repo, opts) + if err != nil { + return nil, fmt.Errorf("error listing pull requests for %s/%s: %v", g.owner, g.repo, err) + } + for _, pull := range pulls { + if !containLabels(g.labels, pull.Labels) { + continue + } + pullRequests = append(pullRequests, &PullRequest{ + Number: *pull.Number, + Branch: *pull.Head.Ref, + HeadSHA: *pull.Head.SHA, + }) + } + if resp.NextPage == 0 { + break + } + opts.Page = resp.NextPage + } + return pullRequests, nil +} + +// containLabels returns true if gotLabels contains expectedLabels +func containLabels(expectedLabels []string, gotLabels []*github.Label) bool { + for _, expected := range expectedLabels { + found := false + for _, got := range gotLabels { + if got.Name == nil { + continue + } + if expected == *got.Name { + found = true + break + } + } + if !found { + return false + } + } + return true +} diff --git a/pkg/services/pull_request/github_test.go b/pkg/services/pull_request/github_test.go new file mode 100644 index 00000000..20bbc6b4 --- /dev/null +++ b/pkg/services/pull_request/github_test.go @@ -0,0 +1,59 @@ +package pull_request + +import ( + "testing" + + "github.com/google/go-github/v35/github" +) + +func toPtr(s string) *string { + return &s +} + +func TestContainLabels(t *testing.T) { + cases := []struct { + Name string + Labels []string + PullLabels []*github.Label + Expect bool + }{ + { + Name: "Match labels", + Labels: []string{"label1", "label2"}, + PullLabels: []*github.Label{ + &github.Label{Name: toPtr("label1")}, + &github.Label{Name: toPtr("label2")}, + &github.Label{Name: toPtr("label3")}, + }, + Expect: true, + }, + { + Name: "Not match labels", + Labels: []string{"label1", "label4"}, + PullLabels: []*github.Label{ + &github.Label{Name: toPtr("label1")}, + &github.Label{Name: toPtr("label2")}, + &github.Label{Name: toPtr("label3")}, + }, + Expect: false, + }, + { + Name: "No specify", + Labels: []string{}, + PullLabels: []*github.Label{ + &github.Label{Name: toPtr("label1")}, + &github.Label{Name: toPtr("label2")}, + &github.Label{Name: toPtr("label3")}, + }, + Expect: true, + }, + } + + for _, c := range cases { + t.Run(c.Name, func(t *testing.T) { + if got := containLabels(c.Labels, c.PullLabels); got != c.Expect { + t.Errorf("expect: %v, got: %v", c.Expect, got) + } + }) + } +} diff --git a/pkg/services/pull_request/interface.go b/pkg/services/pull_request/interface.go new file mode 100644 index 00000000..bc67681c --- /dev/null +++ b/pkg/services/pull_request/interface.go @@ -0,0 +1,17 @@ +package pull_request + +import "context" + +type PullRequest struct { + // Number is a number that will be the ID of the pull request. + Number int + // Branch is the name of the branch from which the pull request originated. + Branch string + // HeadSHA is the SHA of the HEAD from which the pull request originated. + HeadSHA string +} + +type PullRequestService interface { + // List gets a list of pull requests. + List(ctx context.Context) ([]*PullRequest, error) +} diff --git a/test/e2e/applicationset/applicationset_test.go b/test/e2e/applicationset/applicationset_test.go index 31a556df..390363b3 100644 --- a/test/e2e/applicationset/applicationset_test.go +++ b/test/e2e/applicationset/applicationset_test.go @@ -508,3 +508,72 @@ func TestCustomApplicationFinalizers(t *testing.T) { When(). Delete().Then().Expect(ApplicationsDoNotExist([]argov1alpha1.Application{expectedApp})) } + +func TestSimplePullRequestGenerator(t *testing.T) { + expectedApp := argov1alpha1.Application{ + TypeMeta: metav1.TypeMeta{ + Kind: "Application", + APIVersion: "argoproj.io/v1alpha1", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "guestbook-1", + Namespace: utils.ArgoCDNamespace, + Finalizers: []string{"resources-finalizer.argocd.argoproj.io"}, + }, + Spec: argov1alpha1.ApplicationSpec{ + Project: "default", + Source: argov1alpha1.ApplicationSource{ + RepoURL: "git@github.com:applicationset-test-org/argocd-example-apps.git", + TargetRevision: "824a5c987fdfb2b0629e9dbf5f31636c69ba4772", + Path: "kustomize-guestbook", + Kustomize: &argov1alpha1.ApplicationSourceKustomize{ + NamePrefix: "guestbook-1", + }, + }, + Destination: argov1alpha1.ApplicationDestination{ + Server: "https://kubernetes.default.svc", + Namespace: "guestbook-pull-request", + }, + }, + } + + Given(t). + // Create an PullRequestGenerator-based ApplicationSet + When().Create(v1alpha1.ApplicationSet{ObjectMeta: metav1.ObjectMeta{ + Name: "simple-pull-request-generator", + }, + Spec: v1alpha1.ApplicationSetSpec{ + Template: v1alpha1.ApplicationSetTemplate{ + ApplicationSetTemplateMeta: v1alpha1.ApplicationSetTemplateMeta{Name: "guestbook-{{ number }}"}, + Spec: argov1alpha1.ApplicationSpec{ + Project: "default", + Source: argov1alpha1.ApplicationSource{ + RepoURL: "git@github.com:applicationset-test-org/argocd-example-apps.git", + TargetRevision: "{{ head_sha }}", + Path: "kustomize-guestbook", + Kustomize: &argov1alpha1.ApplicationSourceKustomize{ + NamePrefix: "guestbook-{{ number }}", + }, + }, + Destination: argov1alpha1.ApplicationDestination{ + Server: "https://kubernetes.default.svc", + Namespace: "guestbook-{{ branch }}", + }, + }, + }, + Generators: []v1alpha1.ApplicationSetGenerator{ + { + PullRequest: &v1alpha1.PullRequestGenerator{ + Github: &v1alpha1.PullRequestGeneratorGithub{ + Owner: "applicationset-test-org", + Repo: "argocd-example-apps", + Labels: []string{ + "preview", + }, + }, + }, + }, + }, + }, + }).Then().Expect(ApplicationsExist([]argov1alpha1.Application{expectedApp})) +}