diff --git a/Makefile b/Makefile index 3f59bbbbf..5dbe020d7 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=v0.0.20 +VERSION=v0.0.21 OUT_DIR=dist YEAR?=$(shell date +"%Y") diff --git a/cmd/commands/runtime.go b/cmd/commands/runtime.go index cabd70931..a28a784ec 100644 --- a/cmd/commands/runtime.go +++ b/cmd/commands/runtime.go @@ -48,9 +48,17 @@ type ( RuntimeCreateOptions struct { RuntimeName string KubeContext string - KubeFactory kube.Factory - insCloneOpts *git.CloneOptions gsCloneOpts *git.CloneOptions + insCloneOpts *git.CloneOptions + KubeFactory kube.Factory + } + + RuntimeDeleteOptions struct { + RuntimeName string + KubeContext string + Timeout time.Duration + CloneOpts *git.CloneOptions + KubeFactory kube.Factory } ) @@ -66,6 +74,7 @@ func NewRuntimeCommand() *cobra.Command { } cmd.AddCommand(NewRuntimeCreateCommand()) + cmd.AddCommand(NewRuntimeDeleteCommand()) return cmd } @@ -92,7 +101,7 @@ func NewRuntimeCreateCommand() *cobra.Command { # Adds a new runtime - runtime create runtime-name --install-owner owner --install-name gitops_repo + runtime create runtime-name --install-repo gitops_repo `), PreRun: func(_ *cobra.Command, _ []string) { if gsCloneOpts.Auth.Password == "" { @@ -108,16 +117,17 @@ func NewRuntimeCreateCommand() *cobra.Command { gsCloneOpts.Parse() }, RunE: func(cmd *cobra.Command, args []string) error { + ctx := cmd.Context() if len(args) < 1 { - log.G().Fatal("must enter runtime name") + log.G(ctx).Fatal("must enter runtime name") } - return RunRuntimeCreate(cmd.Context(), &RuntimeCreateOptions{ + return RunRuntimeCreate(ctx, &RuntimeCreateOptions{ RuntimeName: args[0], - KubeContext: "", - KubeFactory: f, - insCloneOpts: insCloneOpts, + KubeContext: cmd.Flag("context").Value.String(), gsCloneOpts: gsCloneOpts, + insCloneOpts: insCloneOpts, + KubeFactory: f, }) }, } @@ -185,6 +195,66 @@ func RunRuntimeCreate(ctx context.Context, opts *RuntimeCreateOptions) error { return nil } +func NewRuntimeDeleteCommand() *cobra.Command { + var ( + f kube.Factory + cloneOpts *git.CloneOptions + ) + + cmd := &cobra.Command{ + Use: "delete [runtime_name]", + Short: "Deletes a Codefresh runtime", + Example: util.Doc(` +# To run this command you need to create a personal access token for your git provider +# and provide it using: + + export GIT_TOKEN= + +# or with the flag: + + --git-token + +# Adds a new runtime + + runtime delete runtime-name --repo gitops_repo +`), + PreRun: func(_ *cobra.Command, _ []string) { + cloneOpts.Parse() + }, + RunE: func(cmd *cobra.Command, args []string) error { + ctx := cmd.Context() + if len(args) < 1 { + log.G(ctx).Fatal("must enter runtime name") + } + + return RunRuntimeDelete(ctx, &RuntimeDeleteOptions{ + RuntimeName: args[0], + KubeContext: cmd.Flag("context").Value.String(), + Timeout: aputil.MustParseDuration(cmd.Flag("request-timeout").Value.String()), + CloneOpts: cloneOpts, + KubeFactory: f, + }) + }, + } + + cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{ + FS: memfs.New(), + }) + f = kube.AddFlags(cmd.Flags()) + + return cmd +} + +func RunRuntimeDelete(ctx context.Context, opts *RuntimeDeleteOptions) error { + return apcmd.RunRepoUninstall(ctx, &apcmd.RepoUninstallOptions{ + Namespace: opts.RuntimeName, + KubeContext: opts.KubeContext, + Timeout: opts.Timeout, + CloneOptions: opts.CloneOpts, + KubeFactory: opts.KubeFactory, + }) +} + func createApp(ctx context.Context, f kube.Factory, cloneOpts *git.CloneOptions, projectName, appName, appURL, appType, namespace string, wait bool) error { timeout := time.Duration(0) if wait { @@ -242,9 +312,10 @@ func createComponentsReporter(ctx context.Context, cloneOpts *git.CloneOptions, return err } - return r.Persist(ctx, &git.PushOptions{ + _, err = r.Persist(ctx, &git.PushOptions{ CommitMsg: "Created Codefresh Resources", }) + return err } func updateProject(repofs fs.FS, runtimeName string) error { @@ -441,9 +512,10 @@ func createDemoWorkflowTemplate(ctx context.Context, gsCloneOpts *git.CloneOptio return err } - return gsRepo.Persist(ctx, &git.PushOptions{ + _, err = gsRepo.Persist(ctx, &git.PushOptions{ CommitMsg: fmt.Sprintf("Created %s Directory", gsPath), }) + return err } func createGitSource(ctx context.Context, insCloneOpts *git.CloneOptions, gsCloneOpts *git.CloneOptions, gsName, runtimeName string) error { @@ -583,7 +655,7 @@ func createGitSource(ctx context.Context, insCloneOpts *git.CloneOptions, gsClon return err } - err = insRepo.Persist(ctx, &git.PushOptions{ + _, err = insRepo.Persist(ctx, &git.PushOptions{ CommitMsg: fmt.Sprintf("Created %s Resources", gsName), }) if err != nil { diff --git a/docs/commands/cli-v2_runtime.md b/docs/commands/cli-v2_runtime.md index a2bbc3a62..edd892bc0 100644 --- a/docs/commands/cli-v2_runtime.md +++ b/docs/commands/cli-v2_runtime.md @@ -25,4 +25,5 @@ cli-v2 runtime [flags] * [cli-v2](cli-v2.md) - cli-v2 is used for installing and managing codefresh installations using gitops * [cli-v2 runtime create](cli-v2_runtime_create.md) - Create a new Codefresh runtime +* [cli-v2 runtime delete](cli-v2_runtime_delete.md) - Deletes a Codefresh runtime diff --git a/docs/commands/cli-v2_runtime_create.md b/docs/commands/cli-v2_runtime_create.md index 9055ad2ef..11eba45c5 100644 --- a/docs/commands/cli-v2_runtime_create.md +++ b/docs/commands/cli-v2_runtime_create.md @@ -21,7 +21,7 @@ cli-v2 runtime create [runtime_name] [flags] # Adds a new runtime - cli-v2 runtime create runtime-name --install-owner owner --install-name gitops_repo + cli-v2 runtime create runtime-name --install-repo gitops_repo ``` diff --git a/docs/commands/cli-v2_runtime_delete.md b/docs/commands/cli-v2_runtime_delete.md new file mode 100644 index 000000000..d395801c2 --- /dev/null +++ b/docs/commands/cli-v2_runtime_delete.md @@ -0,0 +1,63 @@ +## cli-v2 runtime delete + +Deletes a Codefresh runtime + +``` +cli-v2 runtime delete [runtime_name] [flags] +``` + +### Examples + +``` + +# To run this command you need to create a personal access token for your git provider +# and provide it using: + + export GIT_TOKEN= + +# or with the flag: + + --git-token + +# Adds a new runtime + + cli-v2 runtime delete runtime-name --repo gitops_repo + +``` + +### Options + +``` + --as string Username to impersonate for the operation + --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. + --cache-dir string Default cache directory (default "/home/user/.kube/cache") + --certificate-authority string Path to a cert file for the certificate authority + --client-certificate string Path to a client certificate file for TLS + --client-key string Path to a client key file for TLS + --cluster string The name of the kubeconfig cluster to use + --context string The name of the kubeconfig context to use + -t, --git-token string Your git provider api token [GIT_TOKEN] + -h, --help help for delete + --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure + --kubeconfig string Path to the kubeconfig file to use for CLI requests. + -n, --namespace string If present, the namespace scope for this CLI request + --repo string Repository URL [GIT_REPO] + -s, --server string The address and port of the Kubernetes API server + --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used + --token string Bearer token for authentication to the API server + --user string The name of the kubeconfig user to use +``` + +### Options inherited from parent commands + +``` + --auth-context string Run the next command using a specific authentication context + --cfconfig string Custom path for authentication contexts config file (default "/home/user") + --insecure Disable certificate validation for TLS connections (e.g. to g.codefresh.io) + --request-timeout duration Request timeout (default 30s) +``` + +### SEE ALSO + +* [cli-v2 runtime](cli-v2_runtime.md) - Manage Codefresh runtimes + diff --git a/docs/releases/release_notes.md b/docs/releases/release_notes.md index bc18583e2..072ddd65b 100644 --- a/docs/releases/release_notes.md +++ b/docs/releases/release_notes.md @@ -7,11 +7,8 @@ ### Linux ```bash -# get the latest version or change to a specific version -VERSION=$(curl --silent "https://api.github.com/repos/codefresh-io/cli-v2/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/') - # download and extract the binary -curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/$VERSION/cf-linux-amd64.tar.gz | tar zx +curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.21/cf-linux-amd64.tar.gz | tar zx # move the binary to your $PATH mv ./cf-* /usr/local/bin/cf @@ -22,11 +19,8 @@ cf version ### Mac ```bash -# get the latest version or change to a specific version -VERSION=$(curl --silent "https://api.github.com/repos/codefresh-io/cli-v2/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/') - # download and extract the binary -curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/$VERSION/cf-darwin-amd64.tar.gz | tar zx +curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.21/cf-darwin-amd64.tar.gz | tar zx # move the binary to your $PATH mv ./cf-* /usr/local/bin/cf diff --git a/go.mod b/go.mod index c59f56d42..d292dadf2 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.16 require ( github.com/argoproj-labs/applicationset v0.1.0 - github.com/argoproj-labs/argocd-autopilot v0.2.8 + github.com/argoproj-labs/argocd-autopilot v0.2.9 github.com/argoproj/argo-cd/v2 v2.0.3 github.com/argoproj/argo-events v1.3.1 github.com/argoproj/argo-workflows/v3 v3.1.0 diff --git a/go.sum b/go.sum index 17584daf1..155bbacbc 100644 --- a/go.sum +++ b/go.sum @@ -164,8 +164,8 @@ github.com/ardielle/ardielle-go v1.5.2/go.mod h1:I4hy1n795cUhaVt/ojz83SNVCYIGsAF github.com/ardielle/ardielle-tools v1.5.4/go.mod h1:oZN+JRMnqGiIhrzkRN9l26Cej9dEx4jeNG6A+AdkShk= github.com/argoproj-labs/applicationset v0.0.0-20210614145856-2c62537a8e5a h1:8Nm2KtOu/G7NtoAgucj4TkX8rghzwgFJGXNrAmuz7gc= github.com/argoproj-labs/applicationset v0.0.0-20210614145856-2c62537a8e5a/go.mod h1:5rxggh8ymYXedQDIYylNzIHe6jdshDNasIBCVJuR1iU= -github.com/argoproj-labs/argocd-autopilot v0.2.8 h1:whsV51FygB5OI2qGgLui0aHTVt/V+9M0VgOfz1U+m3I= -github.com/argoproj-labs/argocd-autopilot v0.2.8/go.mod h1:mFkBpj09ofv0oe4K7LcN3Ds1pAXUEOLum/Lk8KUJXH0= +github.com/argoproj-labs/argocd-autopilot v0.2.9 h1:zYStiQq1cCT1EkfwEpdMEVfSkj+7ZEe1CwilmXGoldQ= +github.com/argoproj-labs/argocd-autopilot v0.2.9/go.mod h1:o3HQ3wBzSFlLILnFDFWMkHetHTSjwwC30runsLvwVp8= github.com/argoproj/argo-cd v1.8.1/go.mod h1:Vfl7OGgBC83dVWgq58wU6UR3kG864h0dtHEIQ8xqw4s= github.com/argoproj/argo-cd v1.8.7 h1:CkIu8p/gcTY/fOZWM2tHuSCIAV2HggXjJftrT1IIT3k= github.com/argoproj/argo-cd v1.8.7/go.mod h1:tqFZW5Lr9KBCDsvOaE5Fh8M1eJ1ThvR58pyyLv8Zqvs= @@ -177,8 +177,9 @@ github.com/argoproj/argo-workflows/v3 v3.1.0 h1:YrTppFW7VYZsFnDB7/9A0nI3V+VVqozv github.com/argoproj/argo-workflows/v3 v3.1.0/go.mod h1:Z8Wc7uDOGw8TRdhqqREHLFE5SAgS0ENqqwaLakv56MU= github.com/argoproj/gitops-engine v0.2.1/go.mod h1:OxXp8YaT73rw9gEBnGBWg55af80nkV/uIjWCbJu1Nw0= github.com/argoproj/gitops-engine v0.2.2/go.mod h1:OxXp8YaT73rw9gEBnGBWg55af80nkV/uIjWCbJu1Nw0= -github.com/argoproj/gitops-engine v0.3.2 h1:m5bjOk/bWwMsFBGFpurdK31/hC5UuLMQn0hAd51TlEk= github.com/argoproj/gitops-engine v0.3.2/go.mod h1:IBHhAkqlC+3r/wBWUitWSidQhPzlLoSTWp2htq3dyQk= +github.com/argoproj/gitops-engine v0.3.3 h1:zRNwKRj3h+EBpciy/+Eyo4vW2GTG3UG4HXAdWn0mQRI= +github.com/argoproj/gitops-engine v0.3.3/go.mod h1:IBHhAkqlC+3r/wBWUitWSidQhPzlLoSTWp2htq3dyQk= github.com/argoproj/pkg v0.2.0/go.mod h1:F4TZgInLUEjzsWFB/BTJBsewoEy0ucnKSq6vmQiD/yc= github.com/argoproj/pkg v0.8.1/go.mod h1:ra+bQPmbVAoEL+gYSKesuigt4m49i3Qa3mE/xQcjCiA= github.com/argoproj/pkg v0.9.0 h1:PfWWYykfcEQdN0g41XLbVh/aonTjD+dPkvDp3hwpLYM= diff --git a/manifests/argo-cd/kustomization.yaml b/manifests/argo-cd/kustomization.yaml index 31af453b3..62fca2000 100644 --- a/manifests/argo-cd/kustomization.yaml +++ b/manifests/argo-cd/kustomization.yaml @@ -2,30 +2,41 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - https://raw.githubusercontent.com/argoproj/argo-cd/v2.0.4/manifests/install.yaml - - https://raw.githubusercontent.com/argoproj-labs/applicationset/master/manifests/install.yaml # TODO: switch to the next release when available + - https://raw.githubusercontent.com/argoproj-labs/applicationset/master/manifests/install.yaml?ref=2c62537a8e5a # TODO: switch to the next release when available + # will be effective on argo-cd 2.1 configMapGenerator: - name: argocd-cm behavior: merge literals: - "timeout.reconciliation=5s" -# currently in use since we are on 2.0.4 + patches: -- patch: |- - apiVersion: apps/v1 - kind: StatefulSet - metadata: - name: argocd-application-controller - spec: - template: - spec: - containers: - - name: argocd-application-controller - command: - - argocd-application-controller - - --status-processors - - "20" - - --operation-processors - - "10" - - --app-resync - - "5" + # reset the crbs to `subject.namespace: default`, so that argo-cd will later change them to the actual ns + - target: + group: rbac.authorization.k8s.io + version: v1 + kind: ClusterRoleBinding + patch: |- + - op: replace + path: /subjects/0/namespace + value: default + # currently in use since we are on 2.0.4 + - patch: |- + apiVersion: apps/v1 + kind: StatefulSet + metadata: + name: argocd-application-controller + spec: + template: + spec: + containers: + - name: argocd-application-controller + command: + - argocd-application-controller + - --status-processors + - "20" + - --operation-processors + - "10" + - --app-resync + - "5" diff --git a/manifests/argo-events/kustomization.yaml b/manifests/argo-events/kustomization.yaml index 95469428e..98d895ae3 100644 --- a/manifests/argo-events/kustomization.yaml +++ b/manifests/argo-events/kustomization.yaml @@ -2,5 +2,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: # events from master to get the secureHeaders for now, should move to next release when available - - https://raw.githubusercontent.com/argoproj/argo-events/master/manifests/install.yaml + - https://raw.githubusercontent.com/argoproj/argo-events/master/manifests/install.yaml?ref=d403c441bc1d - eventbus.yaml diff --git a/pkg/eventUtils/eventUtils.go b/pkg/eventUtils/eventUtils.go index 4368200b9..d5913253a 100644 --- a/pkg/eventUtils/eventUtils.go +++ b/pkg/eventUtils/eventUtils.go @@ -182,7 +182,7 @@ func CreateTrigger(opts *CreateTriggerOptions) *sensorsv1alpha1.Trigger { return &sensorsv1alpha1.Trigger{ Template: &sensorsv1alpha1.TriggerTemplate{ Conditions: opts.Conditions, - Name: "http-trigger", + Name: opts.DependencyName, HTTP: &sensorsv1alpha1.HTTPTrigger{ URL: opts.URL, Method: "POST",