|
| 1 | +/* |
| 2 | +Copyright 2025 The Flux authors |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1 |
| 18 | + |
| 19 | +import ( |
| 20 | + "github.com/fluxcd/pkg/apis/meta" |
| 21 | + sourcev1 "github.com/fluxcd/source-controller/api/v1" |
| 22 | +) |
| 23 | + |
| 24 | +type GitSpec struct { |
| 25 | + // Checkout gives the parameters for cloning the git repository, |
| 26 | + // ready to make changes. If not present, the `spec.ref` field from the |
| 27 | + // referenced `GitRepository` or its default will be used. |
| 28 | + // +optional |
| 29 | + Checkout *GitCheckoutSpec `json:"checkout,omitempty"` |
| 30 | + |
| 31 | + // Commit specifies how to commit to the git repository. |
| 32 | + // +required |
| 33 | + Commit CommitSpec `json:"commit"` |
| 34 | + |
| 35 | + // Push specifies how and where to push commits made by the |
| 36 | + // automation. If missing, commits are pushed (back) to |
| 37 | + // `.spec.checkout.branch` or its default. |
| 38 | + // +optional |
| 39 | + Push *PushSpec `json:"push,omitempty"` |
| 40 | +} |
| 41 | + |
| 42 | +// HasRefspec returns if the GitSpec has a Refspec. |
| 43 | +func (gs GitSpec) HasRefspec() bool { |
| 44 | + if gs.Push == nil { |
| 45 | + return false |
| 46 | + } |
| 47 | + return gs.Push.Refspec != "" |
| 48 | +} |
| 49 | + |
| 50 | +type GitCheckoutSpec struct { |
| 51 | + // Reference gives a branch, tag or commit to clone from the Git |
| 52 | + // repository. |
| 53 | + // +required |
| 54 | + Reference sourcev1.GitRepositoryRef `json:"ref"` |
| 55 | +} |
| 56 | + |
| 57 | +// CommitSpec specifies how to commit changes to the git repository |
| 58 | +type CommitSpec struct { |
| 59 | + // Author gives the email and optionally the name to use as the |
| 60 | + // author of commits. |
| 61 | + // +required |
| 62 | + Author CommitUser `json:"author"` |
| 63 | + // SigningKey provides the option to sign commits with a GPG key |
| 64 | + // +optional |
| 65 | + SigningKey *SigningKey `json:"signingKey,omitempty"` |
| 66 | + // MessageTemplate provides a template for the commit message, |
| 67 | + // into which will be interpolated the details of the change made. |
| 68 | + // Note: The `Updated` template field has been removed. Use `Changed` instead. |
| 69 | + // +optional |
| 70 | + MessageTemplate string `json:"messageTemplate,omitempty"` |
| 71 | + |
| 72 | + // MessageTemplateValues provides additional values to be available to the |
| 73 | + // templating rendering. |
| 74 | + // +optional |
| 75 | + MessageTemplateValues map[string]string `json:"messageTemplateValues,omitempty"` |
| 76 | +} |
| 77 | + |
| 78 | +type CommitUser struct { |
| 79 | + // Name gives the name to provide when making a commit. |
| 80 | + // +optional |
| 81 | + Name string `json:"name,omitempty"` |
| 82 | + // Email gives the email to provide when making a commit. |
| 83 | + // +required |
| 84 | + Email string `json:"email"` |
| 85 | +} |
| 86 | + |
| 87 | +// SigningKey references a Kubernetes secret that contains a GPG keypair |
| 88 | +type SigningKey struct { |
| 89 | + // SecretRef holds the name to a secret that contains a 'git.asc' key |
| 90 | + // corresponding to the ASCII Armored file containing the GPG signing |
| 91 | + // keypair as the value. It must be in the same namespace as the |
| 92 | + // ImageUpdateAutomation. |
| 93 | + // +required |
| 94 | + SecretRef meta.LocalObjectReference `json:"secretRef,omitempty"` |
| 95 | +} |
| 96 | + |
| 97 | +// PushSpec specifies how and where to push commits. |
| 98 | +type PushSpec struct { |
| 99 | + // Branch specifies that commits should be pushed to the branch |
| 100 | + // named. The branch is created using `.spec.checkout.branch` as the |
| 101 | + // starting point, if it doesn't already exist. |
| 102 | + // +optional |
| 103 | + Branch string `json:"branch,omitempty"` |
| 104 | + |
| 105 | + // Refspec specifies the Git Refspec to use for a push operation. |
| 106 | + // If both Branch and Refspec are provided, then the commit is pushed |
| 107 | + // to the branch and also using the specified refspec. |
| 108 | + // For more details about Git Refspecs, see: |
| 109 | + // https://git-scm.com/book/en/v2/Git-Internals-The-Refspec |
| 110 | + // +optional |
| 111 | + Refspec string `json:"refspec,omitempty"` |
| 112 | + |
| 113 | + // Options specifies the push options that are sent to the Git |
| 114 | + // server when performing a push operation. For details, see: |
| 115 | + // https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt |
| 116 | + // +optional |
| 117 | + Options map[string]string `json:"options,omitempty"` |
| 118 | +} |
0 commit comments