Skip to content

Commit 9e7eaf6

Browse files
authored
CR-4773 - implemented runtime delete (#17)
* implemented `runtime delete` * name each trigger differently * fix crbs subject.namespace * set events and appset kustomization to specific hash
1 parent 0448926 commit 9e7eaf6

File tree

11 files changed

+189
-47
lines changed

11 files changed

+189
-47
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.20
1+
VERSION=v0.0.21
22
OUT_DIR=dist
33
YEAR?=$(shell date +"%Y")
44

cmd/commands/runtime.go

Lines changed: 83 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,17 @@ type (
4848
RuntimeCreateOptions struct {
4949
RuntimeName string
5050
KubeContext string
51-
KubeFactory kube.Factory
52-
insCloneOpts *git.CloneOptions
5351
gsCloneOpts *git.CloneOptions
52+
insCloneOpts *git.CloneOptions
53+
KubeFactory kube.Factory
54+
}
55+
56+
RuntimeDeleteOptions struct {
57+
RuntimeName string
58+
KubeContext string
59+
Timeout time.Duration
60+
CloneOpts *git.CloneOptions
61+
KubeFactory kube.Factory
5462
}
5563
)
5664

@@ -66,6 +74,7 @@ func NewRuntimeCommand() *cobra.Command {
6674
}
6775

6876
cmd.AddCommand(NewRuntimeCreateCommand())
77+
cmd.AddCommand(NewRuntimeDeleteCommand())
6978

7079
return cmd
7180
}
@@ -92,7 +101,7 @@ func NewRuntimeCreateCommand() *cobra.Command {
92101
93102
# Adds a new runtime
94103
95-
<BIN> runtime create runtime-name --install-owner owner --install-name gitops_repo
104+
<BIN> runtime create runtime-name --install-repo gitops_repo
96105
`),
97106
PreRun: func(_ *cobra.Command, _ []string) {
98107
if gsCloneOpts.Auth.Password == "" {
@@ -108,16 +117,17 @@ func NewRuntimeCreateCommand() *cobra.Command {
108117
gsCloneOpts.Parse()
109118
},
110119
RunE: func(cmd *cobra.Command, args []string) error {
120+
ctx := cmd.Context()
111121
if len(args) < 1 {
112-
log.G().Fatal("must enter runtime name")
122+
log.G(ctx).Fatal("must enter runtime name")
113123
}
114124

115-
return RunRuntimeCreate(cmd.Context(), &RuntimeCreateOptions{
125+
return RunRuntimeCreate(ctx, &RuntimeCreateOptions{
116126
RuntimeName: args[0],
117-
KubeContext: "",
118-
KubeFactory: f,
119-
insCloneOpts: insCloneOpts,
127+
KubeContext: cmd.Flag("context").Value.String(),
120128
gsCloneOpts: gsCloneOpts,
129+
insCloneOpts: insCloneOpts,
130+
KubeFactory: f,
121131
})
122132
},
123133
}
@@ -185,6 +195,66 @@ func RunRuntimeCreate(ctx context.Context, opts *RuntimeCreateOptions) error {
185195
return nil
186196
}
187197

198+
func NewRuntimeDeleteCommand() *cobra.Command {
199+
var (
200+
f kube.Factory
201+
cloneOpts *git.CloneOptions
202+
)
203+
204+
cmd := &cobra.Command{
205+
Use: "delete [runtime_name]",
206+
Short: "Deletes a Codefresh runtime",
207+
Example: util.Doc(`
208+
# To run this command you need to create a personal access token for your git provider
209+
# and provide it using:
210+
211+
export GIT_TOKEN=<token>
212+
213+
# or with the flag:
214+
215+
--git-token <token>
216+
217+
# Adds a new runtime
218+
219+
<BIN> runtime delete runtime-name --repo gitops_repo
220+
`),
221+
PreRun: func(_ *cobra.Command, _ []string) {
222+
cloneOpts.Parse()
223+
},
224+
RunE: func(cmd *cobra.Command, args []string) error {
225+
ctx := cmd.Context()
226+
if len(args) < 1 {
227+
log.G(ctx).Fatal("must enter runtime name")
228+
}
229+
230+
return RunRuntimeDelete(ctx, &RuntimeDeleteOptions{
231+
RuntimeName: args[0],
232+
KubeContext: cmd.Flag("context").Value.String(),
233+
Timeout: aputil.MustParseDuration(cmd.Flag("request-timeout").Value.String()),
234+
CloneOpts: cloneOpts,
235+
KubeFactory: f,
236+
})
237+
},
238+
}
239+
240+
cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
241+
FS: memfs.New(),
242+
})
243+
f = kube.AddFlags(cmd.Flags())
244+
245+
return cmd
246+
}
247+
248+
func RunRuntimeDelete(ctx context.Context, opts *RuntimeDeleteOptions) error {
249+
return apcmd.RunRepoUninstall(ctx, &apcmd.RepoUninstallOptions{
250+
Namespace: opts.RuntimeName,
251+
KubeContext: opts.KubeContext,
252+
Timeout: opts.Timeout,
253+
CloneOptions: opts.CloneOpts,
254+
KubeFactory: opts.KubeFactory,
255+
})
256+
}
257+
188258
func createApp(ctx context.Context, f kube.Factory, cloneOpts *git.CloneOptions, projectName, appName, appURL, appType, namespace string, wait bool) error {
189259
timeout := time.Duration(0)
190260
if wait {
@@ -242,9 +312,10 @@ func createComponentsReporter(ctx context.Context, cloneOpts *git.CloneOptions,
242312
return err
243313
}
244314

245-
return r.Persist(ctx, &git.PushOptions{
315+
_, err = r.Persist(ctx, &git.PushOptions{
246316
CommitMsg: "Created Codefresh Resources",
247317
})
318+
return err
248319
}
249320

250321
func updateProject(repofs fs.FS, runtimeName string) error {
@@ -441,9 +512,10 @@ func createDemoWorkflowTemplate(ctx context.Context, gsCloneOpts *git.CloneOptio
441512
return err
442513
}
443514

444-
return gsRepo.Persist(ctx, &git.PushOptions{
515+
_, err = gsRepo.Persist(ctx, &git.PushOptions{
445516
CommitMsg: fmt.Sprintf("Created %s Directory", gsPath),
446517
})
518+
return err
447519
}
448520

449521
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
583655
return err
584656
}
585657

586-
err = insRepo.Persist(ctx, &git.PushOptions{
658+
_, err = insRepo.Persist(ctx, &git.PushOptions{
587659
CommitMsg: fmt.Sprintf("Created %s Resources", gsName),
588660
})
589661
if err != nil {

docs/commands/cli-v2_runtime.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ cli-v2 runtime [flags]
2525

2626
* [cli-v2](cli-v2.md) - cli-v2 is used for installing and managing codefresh installations using gitops
2727
* [cli-v2 runtime create](cli-v2_runtime_create.md) - Create a new Codefresh runtime
28+
* [cli-v2 runtime delete](cli-v2_runtime_delete.md) - Deletes a Codefresh runtime
2829

docs/commands/cli-v2_runtime_create.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cli-v2 runtime create [runtime_name] [flags]
2121
2222
# Adds a new runtime
2323
24-
cli-v2 runtime create runtime-name --install-owner owner --install-name gitops_repo
24+
cli-v2 runtime create runtime-name --install-repo gitops_repo
2525
2626
```
2727

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
## cli-v2 runtime delete
2+
3+
Deletes a Codefresh runtime
4+
5+
```
6+
cli-v2 runtime delete [runtime_name] [flags]
7+
```
8+
9+
### Examples
10+
11+
```
12+
13+
# To run this command you need to create a personal access token for your git provider
14+
# and provide it using:
15+
16+
export GIT_TOKEN=<token>
17+
18+
# or with the flag:
19+
20+
--git-token <token>
21+
22+
# Adds a new runtime
23+
24+
cli-v2 runtime delete runtime-name --repo gitops_repo
25+
26+
```
27+
28+
### Options
29+
30+
```
31+
--as string Username to impersonate for the operation
32+
--as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
33+
--cache-dir string Default cache directory (default "/home/user/.kube/cache")
34+
--certificate-authority string Path to a cert file for the certificate authority
35+
--client-certificate string Path to a client certificate file for TLS
36+
--client-key string Path to a client key file for TLS
37+
--cluster string The name of the kubeconfig cluster to use
38+
--context string The name of the kubeconfig context to use
39+
-t, --git-token string Your git provider api token [GIT_TOKEN]
40+
-h, --help help for delete
41+
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
42+
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
43+
-n, --namespace string If present, the namespace scope for this CLI request
44+
--repo string Repository URL [GIT_REPO]
45+
-s, --server string The address and port of the Kubernetes API server
46+
--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
47+
--token string Bearer token for authentication to the API server
48+
--user string The name of the kubeconfig user to use
49+
```
50+
51+
### Options inherited from parent commands
52+
53+
```
54+
--auth-context string Run the next command using a specific authentication context
55+
--cfconfig string Custom path for authentication contexts config file (default "/home/user")
56+
--insecure Disable certificate validation for TLS connections (e.g. to g.codefresh.io)
57+
--request-timeout duration Request timeout (default 30s)
58+
```
59+
60+
### SEE ALSO
61+
62+
* [cli-v2 runtime](cli-v2_runtime.md) - Manage Codefresh runtimes
63+

docs/releases/release_notes.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77

88
### Linux
99
```bash
10-
# get the latest version or change to a specific version
11-
VERSION=$(curl --silent "https://api.github.com/repos/codefresh-io/cli-v2/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
12-
1310
# download and extract the binary
14-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/$VERSION/cf-linux-amd64.tar.gz | tar zx
11+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.21/cf-linux-amd64.tar.gz | tar zx
1512

1613
# move the binary to your $PATH
1714
mv ./cf-* /usr/local/bin/cf
@@ -22,11 +19,8 @@ cf version
2219

2320
### Mac
2421
```bash
25-
# get the latest version or change to a specific version
26-
VERSION=$(curl --silent "https://api.github.com/repos/codefresh-io/cli-v2/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
27-
2822
# download and extract the binary
29-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/$VERSION/cf-darwin-amd64.tar.gz | tar zx
23+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.21/cf-darwin-amd64.tar.gz | tar zx
3024

3125
# move the binary to your $PATH
3226
mv ./cf-* /usr/local/bin/cf

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.16
44

55
require (
66
github.com/argoproj-labs/applicationset v0.1.0
7-
github.com/argoproj-labs/argocd-autopilot v0.2.8
7+
github.com/argoproj-labs/argocd-autopilot v0.2.9
88
github.com/argoproj/argo-cd/v2 v2.0.3
99
github.com/argoproj/argo-events v1.3.1
1010
github.com/argoproj/argo-workflows/v3 v3.1.0

go.sum

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ github.com/ardielle/ardielle-go v1.5.2/go.mod h1:I4hy1n795cUhaVt/ojz83SNVCYIGsAF
164164
github.com/ardielle/ardielle-tools v1.5.4/go.mod h1:oZN+JRMnqGiIhrzkRN9l26Cej9dEx4jeNG6A+AdkShk=
165165
github.com/argoproj-labs/applicationset v0.0.0-20210614145856-2c62537a8e5a h1:8Nm2KtOu/G7NtoAgucj4TkX8rghzwgFJGXNrAmuz7gc=
166166
github.com/argoproj-labs/applicationset v0.0.0-20210614145856-2c62537a8e5a/go.mod h1:5rxggh8ymYXedQDIYylNzIHe6jdshDNasIBCVJuR1iU=
167-
github.com/argoproj-labs/argocd-autopilot v0.2.8 h1:whsV51FygB5OI2qGgLui0aHTVt/V+9M0VgOfz1U+m3I=
168-
github.com/argoproj-labs/argocd-autopilot v0.2.8/go.mod h1:mFkBpj09ofv0oe4K7LcN3Ds1pAXUEOLum/Lk8KUJXH0=
167+
github.com/argoproj-labs/argocd-autopilot v0.2.9 h1:zYStiQq1cCT1EkfwEpdMEVfSkj+7ZEe1CwilmXGoldQ=
168+
github.com/argoproj-labs/argocd-autopilot v0.2.9/go.mod h1:o3HQ3wBzSFlLILnFDFWMkHetHTSjwwC30runsLvwVp8=
169169
github.com/argoproj/argo-cd v1.8.1/go.mod h1:Vfl7OGgBC83dVWgq58wU6UR3kG864h0dtHEIQ8xqw4s=
170170
github.com/argoproj/argo-cd v1.8.7 h1:CkIu8p/gcTY/fOZWM2tHuSCIAV2HggXjJftrT1IIT3k=
171171
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
177177
github.com/argoproj/argo-workflows/v3 v3.1.0/go.mod h1:Z8Wc7uDOGw8TRdhqqREHLFE5SAgS0ENqqwaLakv56MU=
178178
github.com/argoproj/gitops-engine v0.2.1/go.mod h1:OxXp8YaT73rw9gEBnGBWg55af80nkV/uIjWCbJu1Nw0=
179179
github.com/argoproj/gitops-engine v0.2.2/go.mod h1:OxXp8YaT73rw9gEBnGBWg55af80nkV/uIjWCbJu1Nw0=
180-
github.com/argoproj/gitops-engine v0.3.2 h1:m5bjOk/bWwMsFBGFpurdK31/hC5UuLMQn0hAd51TlEk=
181180
github.com/argoproj/gitops-engine v0.3.2/go.mod h1:IBHhAkqlC+3r/wBWUitWSidQhPzlLoSTWp2htq3dyQk=
181+
github.com/argoproj/gitops-engine v0.3.3 h1:zRNwKRj3h+EBpciy/+Eyo4vW2GTG3UG4HXAdWn0mQRI=
182+
github.com/argoproj/gitops-engine v0.3.3/go.mod h1:IBHhAkqlC+3r/wBWUitWSidQhPzlLoSTWp2htq3dyQk=
182183
github.com/argoproj/pkg v0.2.0/go.mod h1:F4TZgInLUEjzsWFB/BTJBsewoEy0ucnKSq6vmQiD/yc=
183184
github.com/argoproj/pkg v0.8.1/go.mod h1:ra+bQPmbVAoEL+gYSKesuigt4m49i3Qa3mE/xQcjCiA=
184185
github.com/argoproj/pkg v0.9.0 h1:PfWWYykfcEQdN0g41XLbVh/aonTjD+dPkvDp3hwpLYM=

manifests/argo-cd/kustomization.yaml

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,41 @@ apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
33
resources:
44
- https://raw.githubusercontent.com/argoproj/argo-cd/v2.0.4/manifests/install.yaml
5-
- https://raw.githubusercontent.com/argoproj-labs/applicationset/master/manifests/install.yaml # TODO: switch to the next release when available
5+
- https://raw.githubusercontent.com/argoproj-labs/applicationset/master/manifests/install.yaml?ref=2c62537a8e5a # TODO: switch to the next release when available
6+
67
# will be effective on argo-cd 2.1
78
configMapGenerator:
89
- name: argocd-cm
910
behavior: merge
1011
literals:
1112
- "timeout.reconciliation=5s"
12-
# currently in use since we are on 2.0.4
13+
1314
patches:
14-
- patch: |-
15-
apiVersion: apps/v1
16-
kind: StatefulSet
17-
metadata:
18-
name: argocd-application-controller
19-
spec:
20-
template:
21-
spec:
22-
containers:
23-
- name: argocd-application-controller
24-
command:
25-
- argocd-application-controller
26-
- --status-processors
27-
- "20"
28-
- --operation-processors
29-
- "10"
30-
- --app-resync
31-
- "5"
15+
# reset the crbs to `subject.namespace: default`, so that argo-cd will later change them to the actual ns
16+
- target:
17+
group: rbac.authorization.k8s.io
18+
version: v1
19+
kind: ClusterRoleBinding
20+
patch: |-
21+
- op: replace
22+
path: /subjects/0/namespace
23+
value: default
24+
# currently in use since we are on 2.0.4
25+
- patch: |-
26+
apiVersion: apps/v1
27+
kind: StatefulSet
28+
metadata:
29+
name: argocd-application-controller
30+
spec:
31+
template:
32+
spec:
33+
containers:
34+
- name: argocd-application-controller
35+
command:
36+
- argocd-application-controller
37+
- --status-processors
38+
- "20"
39+
- --operation-processors
40+
- "10"
41+
- --app-resync
42+
- "5"

manifests/argo-events/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
33
resources:
44
# events from master to get the secureHeaders for now, should move to next release when available
5-
- https://raw.githubusercontent.com/argoproj/argo-events/master/manifests/install.yaml
5+
- https://raw.githubusercontent.com/argoproj/argo-events/master/manifests/install.yaml?ref=d403c441bc1d
66
- eventbus.yaml

pkg/eventUtils/eventUtils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func CreateTrigger(opts *CreateTriggerOptions) *sensorsv1alpha1.Trigger {
182182
return &sensorsv1alpha1.Trigger{
183183
Template: &sensorsv1alpha1.TriggerTemplate{
184184
Conditions: opts.Conditions,
185-
Name: "http-trigger",
185+
Name: opts.DependencyName,
186186
HTTP: &sensorsv1alpha1.HTTPTrigger{
187187
URL: opts.URL,
188188
Method: "POST",

0 commit comments

Comments
 (0)