Skip to content

Commit

Permalink
fix bootstrap on different branch (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
roi-codefresh authored Mar 10, 2022
1 parent 419fdda commit 7bb7e5d
Show file tree
Hide file tree
Showing 17 changed files with 339 additions and 90 deletions.
36 changes: 25 additions & 11 deletions cmd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ type (
)

func NewAppCommand() *cobra.Command {
var cloneOpts *git.CloneOptions

cmd := &cobra.Command{
Use: "application",
Aliases: []string{"app"},
Expand All @@ -63,19 +61,17 @@ func NewAppCommand() *cobra.Command {
exit(1)
},
}
cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
FS: memfs.New(),
})

cmd.AddCommand(NewAppCreateCommand(cloneOpts))
cmd.AddCommand(NewAppListCommand(cloneOpts))
cmd.AddCommand(NewAppDeleteCommand(cloneOpts))
cmd.AddCommand(NewAppCreateCommand())
cmd.AddCommand(NewAppListCommand())
cmd.AddCommand(NewAppDeleteCommand())

return cmd
}

func NewAppCreateCommand(cloneOpts *git.CloneOptions) *cobra.Command {
func NewAppCreateCommand() *cobra.Command {
var (
cloneOpts *git.CloneOptions
appsCloneOpts *git.CloneOptions
appOpts *application.CreateOptions
projectName string
Expand Down Expand Up @@ -145,6 +141,10 @@ func NewAppCreateCommand(cloneOpts *git.CloneOptions) *cobra.Command {

cmd.Flags().StringVarP(&projectName, "project", "p", "", "Project name")
cmd.Flags().DurationVar(&timeout, "wait-timeout", time.Duration(0), "If not '0s', will try to connect to the cluster and wait until the application is in 'Synced' status for the specified timeout period")
cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
FS: memfs.New(),
CloneForWrite: true,
})
appsCloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
FS: memfs.New(),
Prefix: "apps",
Expand Down Expand Up @@ -314,7 +314,11 @@ func getCommitMsg(opts *AppCreateOptions, repofs fs.FS) string {
return commitMsg
}

func NewAppListCommand(cloneOpts *git.CloneOptions) *cobra.Command {
func NewAppListCommand() *cobra.Command {
var (
cloneOpts *git.CloneOptions
)

cmd := &cobra.Command{
Use: "list [PROJECT_NAME]",
Short: "List all applications in a project",
Expand Down Expand Up @@ -347,6 +351,10 @@ func NewAppListCommand(cloneOpts *git.CloneOptions) *cobra.Command {
},
}

cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
FS: memfs.New(),
})

return cmd
}

Expand Down Expand Up @@ -394,8 +402,9 @@ func getConfigFileFromPath(repofs fs.FS, appPath string) (*application.Config, e
return &conf, nil
}

func NewAppDeleteCommand(cloneOpts *git.CloneOptions) *cobra.Command {
func NewAppDeleteCommand() *cobra.Command {
var (
cloneOpts *git.CloneOptions
projectName string
global bool
)
Expand Down Expand Up @@ -441,6 +450,11 @@ func NewAppDeleteCommand(cloneOpts *git.CloneOptions) *cobra.Command {
cmd.Flags().StringVarP(&projectName, "project", "p", "", "Project name")
cmd.Flags().BoolVarP(&global, "global", "g", false, "global")

cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
FS: memfs.New(),
CloneForWrite: true,
})

return cmd
}

Expand Down
1 change: 1 addition & 0 deletions cmd/commands/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
log.G(ctx).WithFields(log.Fields{
"repoURL": cloneOpts.URL(),
"revision": cloneOpts.Revision(),
"forWrite": cloneOpts.CloneForWrite,
}).Debug("starting with options: ")

// clone repo
Expand Down
39 changes: 28 additions & 11 deletions cmd/commands/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ type (
)

func NewProjectCommand() *cobra.Command {
var cloneOpts *git.CloneOptions

cmd := &cobra.Command{
Use: "project",
Aliases: []string{"proj"},
Expand All @@ -72,22 +70,20 @@ func NewProjectCommand() *cobra.Command {
exit(1)
},
}
cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
FS: memfs.New(),
})

cmd.AddCommand(NewProjectCreateCommand(cloneOpts))
cmd.AddCommand(NewProjectListCommand(cloneOpts))
cmd.AddCommand(NewProjectDeleteCommand(cloneOpts))
cmd.AddCommand(NewProjectCreateCommand())
cmd.AddCommand(NewProjectListCommand())
cmd.AddCommand(NewProjectDeleteCommand())

return cmd
}

func NewProjectCreateCommand(cloneOpts *git.CloneOptions) *cobra.Command {
func NewProjectCreateCommand() *cobra.Command {
var (
kubeContext string
dryRun bool
addCmd argocd.AddClusterCmd
cloneOpts *git.CloneOptions
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -128,6 +124,10 @@ func NewProjectCreateCommand(cloneOpts *git.CloneOptions) *cobra.Command {
cmd.Flags().StringVar(&kubeContext, "dest-kube-context", "", "The default destination kubernetes context for applications in this project")
cmd.Flags().BoolVar(&dryRun, "dry-run", false, "If true, print manifests instead of applying them to the cluster (nothing will be commited to git)")

cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
FS: memfs.New(),
CloneForWrite: true,
})
addCmd, err := argocd.AddClusterAddFlags(cmd)
die(err)

Expand Down Expand Up @@ -350,7 +350,11 @@ func getDefaultAppLabels(labels map[string]string) map[string]string {
return res
}

func NewProjectListCommand(cloneOpts *git.CloneOptions) *cobra.Command {
func NewProjectListCommand() *cobra.Command {
var (
cloneOpts *git.CloneOptions
)

cmd := &cobra.Command{
Use: "list ",
Short: "Lists all the projects on a git repository",
Expand Down Expand Up @@ -378,6 +382,10 @@ func NewProjectListCommand(cloneOpts *git.CloneOptions) *cobra.Command {
},
}

cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
FS: memfs.New(),
})

return cmd
}

Expand Down Expand Up @@ -418,7 +426,11 @@ var getProjectInfoFromFile = func(repofs fs.FS, name string) (*argocdv1alpha1.Ap
return proj, appSet, nil
}

func NewProjectDeleteCommand(cloneOpts *git.CloneOptions) *cobra.Command {
func NewProjectDeleteCommand() *cobra.Command {
var (
cloneOpts *git.CloneOptions
)

cmd := &cobra.Command{
Use: "delete [PROJECT_NAME]",
Short: "Delete a project and all of its applications",
Expand Down Expand Up @@ -451,6 +463,11 @@ func NewProjectDeleteCommand(cloneOpts *git.CloneOptions) *cobra.Command {
},
}

cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
FS: memfs.New(),
CloneForWrite: true,
})

return cmd
}

Expand Down
14 changes: 13 additions & 1 deletion cmd/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func NewRepoBootstrapCommand() *cobra.Command {
cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
FS: memfs.New(),
CreateIfNotExist: true,
CloneForWrite: true,
})

// add kubernetes flags
Expand Down Expand Up @@ -299,6 +300,7 @@ func NewRepoUninstallCommand() *cobra.Command {
var (
cloneOpts *git.CloneOptions
f kube.Factory
force bool
)

cmd := &cobra.Command{
Expand All @@ -323,6 +325,12 @@ func NewRepoUninstallCommand() *cobra.Command {
# and delete all manifests from a specific folder in the gitops repository
<BIN> repo uninstall --repo https://github.com/example/repo/path/to/installation_root
# Uninstall using the --force flag will try to uninstall even if some steps
# failed. For example, if it cannot clone the bootstrap repo for some reason
# it will still attempt to delete argo-cd from the cluster. Use with caution!
<BIN> repo uninstall --repo https://github.com/example/repo --force
`),
PreRun: func(_ *cobra.Command, _ []string) { cloneOpts.Parse() },
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -335,13 +343,17 @@ func NewRepoUninstallCommand() *cobra.Command {
KubeContextName: kubeContextName,
Timeout: util.MustParseDuration(cmd.Flag("request-timeout").Value.String()),
CloneOptions: cloneOpts,
Force: force,
KubeFactory: f,
})
},
}

cmd.Flags().BoolVar(&force, "force", false, "If true, will try to complete the uninstallation even if one or more of the uninstallation steps failed")

cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
FS: memfs.New(),
FS: memfs.New(),
CloneForWrite: true,
})
f = kube.AddFlags(cmd.Flags())

Expand Down
12 changes: 11 additions & 1 deletion docs/Getting-Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,22 @@ If you want the autopilot-managed folder structure to reside under some sub-fold
export GIT_REPO=https://github.com/owner/name/some/relative/path
```

#### Using a Specific Revision
#### Using a Specific Branch
If you want to use a specific branch for your GitOps repository operations, you can use the `ref` query parameter:
```
export GIT_REPO=https://github.com/owner/name?ref=gitops_branch
```

!!! note
When running commands that commit or write to the repository, the value of `ref` can only be a branch.


!!! tip
When running commands that commit or write to the repository you may also specify the `-b`, this would create the branch specified in `ref` if it doesn't exist.

Note that when doing so the new branch would be create from the default branch.


#### Using a Specific git Provider
You can add the `--provider` flag to the `repo bootstrap` command, to enforce using a specific provider when creating a new repository. If the value is not supplied, the code will attempt to infer it from the clone URL.
Autopilot currently support github, gitlab, azure devops, and gitea as SCM providers.
Expand Down
5 changes: 1 addition & 4 deletions docs/commands/argocd-autopilot_application.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ argocd-autopilot application [flags]
### Options

```
-t, --git-token string Your git provider api token [GIT_TOKEN]
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
-h, --help help for application
--repo string Repository URL [GIT_REPO]
-h, --help help for application
```

### SEE ALSO
Expand Down
12 changes: 4 additions & 8 deletions docs/commands/argocd-autopilot_application_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,20 @@ argocd-autopilot application create [APP_NAME] [flags]
--context string The name of the kubeconfig context to use
--dest-namespace string K8s target namespace (overrides the namespace specified in the kustomization.yaml)
--dest-server string K8s cluster URL (e.g. https://kubernetes.default.svc) (default "https://kubernetes.default.svc")
-t, --git-token string Your git provider api token [GIT_TOKEN]
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
-h, --help help for create
--installation-mode string One of: normal|flat. If flat, will commit the application manifests (after running kustomize build), otherwise will commit the kustomization.yaml (default "normal")
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
-n, --namespace string If present, the namespace scope for this CLI request
-p, --project string Project name
--repo string Repository URL [GIT_REPO]
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
--type string The application type (kustomize|dir)
-b, --upsert-branch If true will try to checkout the specified branch and create it if it doesn't exist
--wait-timeout duration If not '0s', will try to connect to the cluster and wait until the application is in 'Synced' status for the specified timeout period
```

### Options inherited from parent commands

```
-t, --git-token string Your git provider api token [GIT_TOKEN]
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
--repo string Repository URL [GIT_REPO]
```

### SEE ALSO

* [argocd-autopilot application](argocd-autopilot_application.md) - Manage applications
Expand Down
12 changes: 4 additions & 8 deletions docs/commands/argocd-autopilot_application_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,14 @@ argocd-autopilot application delete [APP_NAME] [flags]

### Options

```
-g, --global global
-h, --help help for delete
-p, --project string Project name
```

### Options inherited from parent commands

```
-t, --git-token string Your git provider api token [GIT_TOKEN]
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
-g, --global global
-h, --help help for delete
-p, --project string Project name
--repo string Repository URL [GIT_REPO]
-b, --upsert-branch If true will try to checkout the specified branch and create it if it doesn't exist
```

### SEE ALSO
Expand Down
7 changes: 1 addition & 6 deletions docs/commands/argocd-autopilot_application_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,10 @@ argocd-autopilot application list [PROJECT_NAME] [flags]

### Options

```
-h, --help help for list
```

### Options inherited from parent commands

```
-t, --git-token string Your git provider api token [GIT_TOKEN]
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
-h, --help help for list
--repo string Repository URL [GIT_REPO]
```

Expand Down
5 changes: 1 addition & 4 deletions docs/commands/argocd-autopilot_project.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ argocd-autopilot project [flags]
### Options

```
-t, --git-token string Your git provider api token [GIT_TOKEN]
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
-h, --help help for project
--repo string Repository URL [GIT_REPO]
-h, --help help for project
```

### SEE ALSO
Expand Down
12 changes: 4 additions & 8 deletions docs/commands/argocd-autopilot_project_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ argocd-autopilot project create [PROJECT] [flags]
--exec-command-args stringArray Arguments to supply to the --exec-command executable
--exec-command-env stringToString Environment vars to set when running the --exec-command executable (default [])
--exec-command-install-hint string Text shown to the user when the --exec-command executable doesn't seem to be present
-t, --git-token string Your git provider api token [GIT_TOKEN]
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
--grpc-web Enables gRPC-web protocol. Useful if Argo CD server is behind proxy which does not support HTTP2.
--grpc-web-root-path string Enables gRPC-web protocol. Useful if Argo CD server is behind proxy which does not support HTTP2. Set web root.
-H, --header strings Sets additional header to all requests made by Argo CD CLI. (Can be repeated multiple times to add multiple headers, also supports comma separated headers)
Expand All @@ -55,23 +57,17 @@ argocd-autopilot project create [PROJECT] [flags]
--plaintext Disable TLS
--port-forward Connect to a random argocd-server port using port forwarding
--port-forward-namespace string Namespace name which should be used for port forwarding
--repo string Repository URL [GIT_REPO]
--server string Argo CD server address
--server-crt string Server certificate file
--service-account string System namespace service account to use for kubernetes resource management. If not set then default "argocd-manager" SA will be created
--shard int Cluster shard number; inferred from hostname if not set (default -1)
--system-namespace string Use different system namespace (default "kube-system")
--upsert Override an existing cluster with the same name even if the spec differs
-b, --upsert-branch If true will try to checkout the specified branch and create it if it doesn't exist
-y, --yes Skip explicit confirmation
```

### Options inherited from parent commands

```
-t, --git-token string Your git provider api token [GIT_TOKEN]
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
--repo string Repository URL [GIT_REPO]
```

### SEE ALSO

* [argocd-autopilot project](argocd-autopilot_project.md) - Manage projects
Expand Down
Loading

0 comments on commit 7bb7e5d

Please sign in to comment.