diff --git a/cmd/flux/bootstrap.go b/cmd/flux/bootstrap.go index 46d7fe38ad889efc5ecb51f7d051de77c20756b1..05139ab46270f826c8c653b6e642ca0c5f49cc8f 100644 --- a/cmd/flux/bootstrap.go +++ b/cmd/flux/bootstrap.go @@ -65,6 +65,8 @@ type bootstrapFlags struct { authorName string authorEmail string + + commitMessageAppendix string } const ( @@ -113,6 +115,8 @@ func init() { bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.authorName, "author-name", "Flux", "author name for Git commits") bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.authorEmail, "author-email", "", "author email for Git commits") + bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.commitMessageAppendix, "commit-message-appendix", "", "string to add to the commit messages, e.g. '[ci skip]'") + bootstrapCmd.PersistentFlags().Var(&bootstrapArgs.arch, "arch", bootstrapArgs.arch.Description()) bootstrapCmd.PersistentFlags().MarkDeprecated("arch", "multi-arch container image is now available for AMD64, ARMv7 and ARM64") bootstrapCmd.PersistentFlags().MarkHidden("manifests") diff --git a/cmd/flux/bootstrap_git.go b/cmd/flux/bootstrap_git.go index 0774d1d9784a4a7757f4c036d2f45b2645ad12b0..fa8eb5846dbd37fd0248edca09158c964695a859 100644 --- a/cmd/flux/bootstrap_git.go +++ b/cmd/flux/bootstrap_git.go @@ -196,6 +196,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error { bootstrap.WithRepositoryURL(gitArgs.url), bootstrap.WithBranch(bootstrapArgs.branch), bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail), + bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix), bootstrap.WithKubeconfig(rootArgs.kubeconfig, rootArgs.kubecontext), bootstrap.WithPostGenerateSecretFunc(promptPublicKey), bootstrap.WithLogger(logger), diff --git a/cmd/flux/bootstrap_github.go b/cmd/flux/bootstrap_github.go index 747d9829824db769de2f6cf1fd5effc6f2f56e45..8123833109ae74d7ac6afe75105bbf37e4f48d26 100644 --- a/cmd/flux/bootstrap_github.go +++ b/cmd/flux/bootstrap_github.go @@ -219,6 +219,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error { bootstrap.WithBranch(bootstrapArgs.branch), bootstrap.WithBootstrapTransportType("https"), bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail), + bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix), bootstrap.WithProviderTeamPermissions(mapTeamSlice(githubArgs.teams, ghDefaultPermission)), bootstrap.WithReadWriteKeyPermissions(githubArgs.readWriteKey), bootstrap.WithKubeconfig(rootArgs.kubeconfig, rootArgs.kubecontext), diff --git a/cmd/flux/bootstrap_gitlab.go b/cmd/flux/bootstrap_gitlab.go index 48768c8009f2e188c888ab77b3535c0e81b171dc..6be6c6f5f76f0ac967d637b88a21858361b358c9 100644 --- a/cmd/flux/bootstrap_gitlab.go +++ b/cmd/flux/bootstrap_gitlab.go @@ -228,6 +228,7 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error { bootstrap.WithBranch(bootstrapArgs.branch), bootstrap.WithBootstrapTransportType("https"), bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail), + bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix), bootstrap.WithProviderTeamPermissions(mapTeamSlice(gitlabArgs.teams, glDefaultPermission)), bootstrap.WithReadWriteKeyPermissions(gitlabArgs.readWriteKey), bootstrap.WithKubeconfig(rootArgs.kubeconfig, rootArgs.kubecontext), diff --git a/docs/cmd/flux_bootstrap.md b/docs/cmd/flux_bootstrap.md index d6ca280a5ff2990edb0e87cb0f9b81ca3d6b8975..7d944dbdb48d4adb15042796361a573d81d4a8cf 100644 --- a/docs/cmd/flux_bootstrap.md +++ b/docs/cmd/flux_bootstrap.md @@ -17,6 +17,7 @@ The bootstrap sub-commands bootstrap the toolkit components on the targeted Git --branch string default branch (for GitHub this must match the default branch setting for the organization) (default "main") --ca-file string path to TLS CA file used for validating self-signed certificates --cluster-domain string internal cluster domain (default "cluster.local") + --commit-message-appendix string string to add to the commit messages, e.g. '[ci skip]' --components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) --components-extra strings list of components in addition to those supplied or defaulted, accepts comma-separated values -h, --help help for bootstrap diff --git a/docs/cmd/flux_bootstrap_git.md b/docs/cmd/flux_bootstrap_git.md index 638199396e3513e1c9cd9d746cb686f478fea1f4..0587e5363ba5c0d289ebf1f5117668fe67534c75 100644 --- a/docs/cmd/flux_bootstrap_git.md +++ b/docs/cmd/flux_bootstrap_git.md @@ -49,6 +49,7 @@ flux bootstrap git [flags] --branch string default branch (for GitHub this must match the default branch setting for the organization) (default "main") --ca-file string path to TLS CA file used for validating self-signed certificates --cluster-domain string internal cluster domain (default "cluster.local") + --commit-message-appendix string string to add to the commit messages, e.g. '[ci skip]' --components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) --components-extra strings list of components in addition to those supplied or defaulted, accepts comma-separated values --context string kubernetes context to use diff --git a/docs/cmd/flux_bootstrap_github.md b/docs/cmd/flux_bootstrap_github.md index cde0605dca14d4e4f180dd1316e487b85d9d898c..05dbe90eb01c0d8476235cae85b6eb6bb794cda2 100644 --- a/docs/cmd/flux_bootstrap_github.md +++ b/docs/cmd/flux_bootstrap_github.md @@ -68,6 +68,7 @@ flux bootstrap github [flags] --branch string default branch (for GitHub this must match the default branch setting for the organization) (default "main") --ca-file string path to TLS CA file used for validating self-signed certificates --cluster-domain string internal cluster domain (default "cluster.local") + --commit-message-appendix string string to add to the commit messages, e.g. '[ci skip]' --components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) --components-extra strings list of components in addition to those supplied or defaulted, accepts comma-separated values --context string kubernetes context to use diff --git a/docs/cmd/flux_bootstrap_gitlab.md b/docs/cmd/flux_bootstrap_gitlab.md index 3d0b9c43126848bd491228c10bcfbc77d30f388d..a3a6823fe33d7b2e5949dcec268954a8e9d48805 100644 --- a/docs/cmd/flux_bootstrap_gitlab.md +++ b/docs/cmd/flux_bootstrap_gitlab.md @@ -65,6 +65,7 @@ flux bootstrap gitlab [flags] --branch string default branch (for GitHub this must match the default branch setting for the organization) (default "main") --ca-file string path to TLS CA file used for validating self-signed certificates --cluster-domain string internal cluster domain (default "cluster.local") + --commit-message-appendix string string to add to the commit messages, e.g. '[ci skip]' --components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) --components-extra strings list of components in addition to those supplied or defaulted, accepts comma-separated values --context string kubernetes context to use diff --git a/internal/bootstrap/bootstrap_plain_git.go b/internal/bootstrap/bootstrap_plain_git.go index b293b78b2e94bf925bb6bb4b805b75c0d6bfa6a2..8119e79a6d6a50b69fd868499912e13aa128f3a4 100644 --- a/internal/bootstrap/bootstrap_plain_git.go +++ b/internal/bootstrap/bootstrap_plain_git.go @@ -48,7 +48,8 @@ type PlainGitBootstrapper struct { url string branch string - author git.Author + author git.Author + commitMessageAppendix string kubeconfig string kubecontext string @@ -126,9 +127,13 @@ func (b *PlainGitBootstrapper) ReconcileComponents(ctx context.Context, manifest } // Git commit generated + commitMsg := fmt.Sprintf("Add Flux %s component manifests", options.Version) + if b.commitMessageAppendix != "" { + commitMsg = commitMsg + "\n\n" + b.commitMessageAppendix + } commit, err := b.git.Commit(git.Commit{ Author: b.author, - Message: fmt.Sprintf("Add Flux %s component manifests", options.Version), + Message: commitMsg, }) if err != nil && err != git.ErrNoStagedFiles { return fmt.Errorf("failed to commit sync manifests: %w", err) @@ -245,9 +250,13 @@ func (b *PlainGitBootstrapper) ReconcileSyncConfig(ctx context.Context, options b.logger.Successf("generated sync manifests") // Git commit generated + commitMsg := fmt.Sprintf("Add Flux sync manifests") + if b.commitMessageAppendix != "" { + commitMsg = commitMsg + "\n\n" + b.commitMessageAppendix + } commit, err := b.git.Commit(git.Commit{ Author: b.author, - Message: fmt.Sprintf("Add Flux sync manifests"), + Message: commitMsg, }) if err != nil && err != git.ErrNoStagedFiles { return fmt.Errorf("failed to commit sync manifests: %w", err) diff --git a/internal/bootstrap/options.go b/internal/bootstrap/options.go index 9f737771a6346a7246bd0d6c7b53667b70f2d0a2..88972c1ebbd40cb8e732a149a8cc207672826a8a 100644 --- a/internal/bootstrap/options.go +++ b/internal/bootstrap/options.go @@ -62,6 +62,20 @@ func (o authorOption) applyGitProvider(b *GitProviderBootstrapper) { o.applyGit(b.PlainGitBootstrapper) } +func WithCommitMessageAppendix(appendix string) Option { + return commitMessageAppendixOption(appendix) +} + +type commitMessageAppendixOption string + +func (o commitMessageAppendixOption) applyGit(b *PlainGitBootstrapper) { + b.commitMessageAppendix = string(o) +} + +func (o commitMessageAppendixOption) applyGitProvider(b *GitProviderBootstrapper) { + o.applyGit(b.PlainGitBootstrapper) +} + func WithKubeconfig(kubeconfig, kubecontext string) Option { return kubeconfigOption{ kubeconfig: kubeconfig,