mirror of
https://github.com/fluxcd/flux2.git
synced 2025-11-01 18:26:25 +08:00
Add branch flag to bootstrap cmd
This commit is contained in:
@ -50,10 +50,11 @@ var (
|
|||||||
bootstrapRegistry string
|
bootstrapRegistry string
|
||||||
bootstrapImagePullSecret string
|
bootstrapImagePullSecret string
|
||||||
bootstrapArch string
|
bootstrapArch string
|
||||||
|
bootstrapBranch string
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
bootstrapBranch = "master"
|
bootstrapDefaultBranch = "master"
|
||||||
bootstrapInstallManifest = "toolkit-components.yaml"
|
bootstrapInstallManifest = "toolkit-components.yaml"
|
||||||
bootstrapSourceManifest = "toolkit-source.yaml"
|
bootstrapSourceManifest = "toolkit-source.yaml"
|
||||||
bootstrapKustomizationManifest = "toolkit-kustomization.yaml"
|
bootstrapKustomizationManifest = "toolkit-kustomization.yaml"
|
||||||
@ -70,6 +71,8 @@ func init() {
|
|||||||
"Kubernetes secret name used for pulling the toolkit images from a private registry")
|
"Kubernetes secret name used for pulling the toolkit images from a private registry")
|
||||||
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArch, "arch", "amd64",
|
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArch, "arch", "amd64",
|
||||||
"arch can be amd64 or arm64")
|
"arch can be amd64 or arm64")
|
||||||
|
bootstrapCmd.PersistentFlags().StringVar(&bootstrapBranch, "branch", bootstrapDefaultBranch,
|
||||||
|
"default branch (for GitHub this must match the organization default branch setting)")
|
||||||
rootCmd.AddCommand(bootstrapCmd)
|
rootCmd.AddCommand(bootstrapCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +117,8 @@ func applyInstallManifests(ctx context.Context, manifestPath string, components
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateSyncManifests(url, name, namespace, targetPath, tmpDir string, interval time.Duration) error {
|
func generateSyncManifests(url, branch, name, namespace, targetPath, tmpDir string, interval time.Duration) error {
|
||||||
gvk := sourcev1.GroupVersion.WithKind("GitRepository")
|
gvk := sourcev1.GroupVersion.WithKind(sourcev1.GitRepositoryKind)
|
||||||
gitRepository := sourcev1.GitRepository{
|
gitRepository := sourcev1.GitRepository{
|
||||||
TypeMeta: metav1.TypeMeta{
|
TypeMeta: metav1.TypeMeta{
|
||||||
Kind: gvk.Kind,
|
Kind: gvk.Kind,
|
||||||
@ -131,7 +134,7 @@ func generateSyncManifests(url, name, namespace, targetPath, tmpDir string, inte
|
|||||||
Duration: interval,
|
Duration: interval,
|
||||||
},
|
},
|
||||||
Reference: &sourcev1.GitRepositoryRef{
|
Reference: &sourcev1.GitRepositoryRef{
|
||||||
Branch: "master",
|
Branch: branch,
|
||||||
},
|
},
|
||||||
SecretRef: &corev1.LocalObjectReference{
|
SecretRef: &corev1.LocalObjectReference{
|
||||||
Name: name,
|
Name: name,
|
||||||
@ -148,7 +151,7 @@ func generateSyncManifests(url, name, namespace, targetPath, tmpDir string, inte
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gvk = kustomizev1.GroupVersion.WithKind("Kustomization")
|
gvk = kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)
|
||||||
kustomization := kustomizev1.Kustomization{
|
kustomization := kustomizev1.Kustomization{
|
||||||
TypeMeta: metav1.TypeMeta{
|
TypeMeta: metav1.TypeMeta{
|
||||||
Kind: gvk.Kind,
|
Kind: gvk.Kind,
|
||||||
|
|||||||
@ -55,6 +55,9 @@ the bootstrap command will perform an upgrade if needed.`,
|
|||||||
|
|
||||||
# Run bootstrap for a private repo hosted on GitHub Enterprise
|
# Run bootstrap for a private repo hosted on GitHub Enterprise
|
||||||
gotk bootstrap github --owner=<organization> --repository=<repo name> --hostname=<domain>
|
gotk bootstrap github --owner=<organization> --repository=<repo name> --hostname=<domain>
|
||||||
|
|
||||||
|
# Run bootstrap for a an existing repository with a branch named main
|
||||||
|
gotk bootstrap github --owner=<organization> --repository=<repo name> --branch=main
|
||||||
`,
|
`,
|
||||||
RunE: bootstrapGitHubCmdRun,
|
RunE: bootstrapGitHubCmdRun,
|
||||||
}
|
}
|
||||||
@ -223,22 +226,19 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// configure repo synchronization
|
// configure repo synchronization
|
||||||
if isInstall {
|
logger.Actionf("generating sync manifests")
|
||||||
// generate source and kustomization manifests
|
if err := generateSyncManifests(repository.GetSSH(), bootstrapBranch, namespace, namespace, ghPath, tmpDir, ghInterval); err != nil {
|
||||||
logger.Actionf("generating sync manifests")
|
return err
|
||||||
if err := generateSyncManifests(repository.GetSSH(), namespace, namespace, ghPath, tmpDir, ghInterval); err != nil {
|
}
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// commit and push manifests
|
// commit and push manifests
|
||||||
if changed, err = repository.Commit(ctx, path.Join(ghPath, namespace), "Add manifests"); err != nil {
|
if changed, err = repository.Commit(ctx, path.Join(ghPath, namespace), "Add manifests"); err != nil {
|
||||||
|
return err
|
||||||
|
} else if changed {
|
||||||
|
if err := repository.Push(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if changed {
|
|
||||||
if err := repository.Push(ctx); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
logger.Successf("sync manifests pushed")
|
|
||||||
}
|
}
|
||||||
|
logger.Successf("sync manifests pushed")
|
||||||
|
|
||||||
// apply manifests and waiting for sync
|
// apply manifests and waiting for sync
|
||||||
logger.Actionf("applying sync manifests")
|
logger.Actionf("applying sync manifests")
|
||||||
|
|||||||
@ -52,6 +52,9 @@ the bootstrap command will perform an upgrade if needed.`,
|
|||||||
|
|
||||||
# Run bootstrap for a private repo hosted on a GitLab server
|
# Run bootstrap for a private repo hosted on a GitLab server
|
||||||
gotk bootstrap gitlab --owner=<group> --repository=<repo name> --hostname=<domain>
|
gotk bootstrap gitlab --owner=<group> --repository=<repo name> --hostname=<domain>
|
||||||
|
|
||||||
|
# Run bootstrap for a an existing repository with a branch named main
|
||||||
|
gotk bootstrap gitlab --owner=<organization> --repository=<repo name> --branch=main
|
||||||
`,
|
`,
|
||||||
RunE: bootstrapGitLabCmdRun,
|
RunE: bootstrapGitLabCmdRun,
|
||||||
}
|
}
|
||||||
@ -195,22 +198,19 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// configure repo synchronization
|
// configure repo synchronization
|
||||||
if isInstall {
|
logger.Actionf("generating sync manifests")
|
||||||
// generate source and kustomization manifests
|
if err := generateSyncManifests(repository.GetSSH(), bootstrapBranch, namespace, namespace, glPath, tmpDir, glInterval); err != nil {
|
||||||
logger.Actionf("generating sync manifests")
|
return err
|
||||||
if err := generateSyncManifests(repository.GetSSH(), namespace, namespace, glPath, tmpDir, glInterval); err != nil {
|
}
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// commit and push manifests
|
// commit and push manifests
|
||||||
if changed, err = repository.Commit(ctx, path.Join(glPath, namespace), "Add manifests"); err != nil {
|
if changed, err = repository.Commit(ctx, path.Join(glPath, namespace), "Add manifests"); err != nil {
|
||||||
|
return err
|
||||||
|
} else if changed {
|
||||||
|
if err := repository.Push(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if changed {
|
|
||||||
if err := repository.Push(ctx); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
logger.Successf("sync manifests pushed")
|
|
||||||
}
|
}
|
||||||
|
logger.Successf("sync manifests pushed")
|
||||||
|
|
||||||
// apply manifests and waiting for sync
|
// apply manifests and waiting for sync
|
||||||
logger.Actionf("applying sync manifests")
|
logger.Actionf("applying sync manifests")
|
||||||
|
|||||||
@ -10,6 +10,7 @@ The bootstrap sub-commands bootstrap the toolkit components on the targeted Git
|
|||||||
|
|
||||||
```
|
```
|
||||||
--arch string arch can be amd64 or arm64 (default "amd64")
|
--arch string arch can be amd64 or arm64 (default "amd64")
|
||||||
|
--branch string default branch (for GitHub this must match the organization default branch setting) (default "master")
|
||||||
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
||||||
-h, --help help for bootstrap
|
-h, --help help for bootstrap
|
||||||
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
||||||
|
|||||||
@ -35,6 +35,9 @@ gotk bootstrap github [flags]
|
|||||||
# Run bootstrap for a private repo hosted on GitHub Enterprise
|
# Run bootstrap for a private repo hosted on GitHub Enterprise
|
||||||
gotk bootstrap github --owner=<organization> --repository=<repo name> --hostname=<domain>
|
gotk bootstrap github --owner=<organization> --repository=<repo name> --hostname=<domain>
|
||||||
|
|
||||||
|
# Run bootstrap for a an existing repository with a branch named main
|
||||||
|
gotk bootstrap github --owner=<organization> --repository=<repo name> --branch=main
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
@ -55,6 +58,7 @@ gotk bootstrap github [flags]
|
|||||||
|
|
||||||
```
|
```
|
||||||
--arch string arch can be amd64 or arm64 (default "amd64")
|
--arch string arch can be amd64 or arm64 (default "amd64")
|
||||||
|
--branch string default branch (for GitHub this must match the organization default branch setting) (default "master")
|
||||||
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
||||||
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
||||||
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||||
|
|||||||
@ -32,6 +32,9 @@ gotk bootstrap gitlab [flags]
|
|||||||
# Run bootstrap for a private repo hosted on a GitLab server
|
# Run bootstrap for a private repo hosted on a GitLab server
|
||||||
gotk bootstrap gitlab --owner=<group> --repository=<repo name> --hostname=<domain>
|
gotk bootstrap gitlab --owner=<group> --repository=<repo name> --hostname=<domain>
|
||||||
|
|
||||||
|
# Run bootstrap for a an existing repository with a branch named main
|
||||||
|
gotk bootstrap gitlab --owner=<organization> --repository=<repo name> --branch=main
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
@ -52,6 +55,7 @@ gotk bootstrap gitlab [flags]
|
|||||||
|
|
||||||
```
|
```
|
||||||
--arch string arch can be amd64 or arm64 (default "amd64")
|
--arch string arch can be amd64 or arm64 (default "amd64")
|
||||||
|
--branch string default branch (for GitHub this must match the organization default branch setting) (default "master")
|
||||||
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
||||||
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
||||||
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||||
|
|||||||
@ -79,6 +79,10 @@ cluster e.g. `staging-cluster` and `production-cluster`:
|
|||||||
└── gitops-system
|
└── gitops-system
|
||||||
```
|
```
|
||||||
|
|
||||||
|
!!! hint "Change the default branch"
|
||||||
|
If you wish to change the branch to something else than master, create the repository manually,
|
||||||
|
push a branch to origin and then use `gotk bootstrap <GIT-PROVIDER> --branch=your-branch`.
|
||||||
|
|
||||||
### GitHub and GitHub Enterprise
|
### GitHub and GitHub Enterprise
|
||||||
|
|
||||||
Generate a [personal access token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line)
|
Generate a [personal access token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line)
|
||||||
|
|||||||
Reference in New Issue
Block a user