Skip to content

Commit 2f35dad

Browse files
CR-5821-gs-delete (#57)
* successfully deletes git-source * removed comment * removed redundant * removed redundant * underscore * returning err * bump * resolved conflicts * added files * returning nil * added file
1 parent 1839ef3 commit 2f35dad

File tree

8 files changed

+120
-9
lines changed

8 files changed

+120
-9
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.60
1+
VERSION=v0.0.62
22
OUT_DIR=dist
33
YEAR?=$(shell date +"%Y")
44

cmd/commands/git-source.go

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@ package commands
1717
import (
1818
"context"
1919
"fmt"
20+
"time"
2021

2122
"github.com/codefresh-io/cli-v2/pkg/log"
2223
"github.com/codefresh-io/cli-v2/pkg/runtime"
2324
"github.com/codefresh-io/cli-v2/pkg/store"
2425
"github.com/codefresh-io/cli-v2/pkg/util"
2526

27+
apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands"
2628
"github.com/argoproj-labs/argocd-autopilot/pkg/application"
2729
"github.com/argoproj-labs/argocd-autopilot/pkg/fs"
2830
"github.com/argoproj-labs/argocd-autopilot/pkg/git"
31+
aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
2932
wf "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow"
3033
wfv1alpha1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
3134
"github.com/go-git/go-billy/v5/memfs"
@@ -42,19 +45,28 @@ type (
4245
runtimeName string
4346
fullGsPath string
4447
}
48+
49+
GitSourceDeleteOptions struct {
50+
RuntimeName string
51+
GsName string
52+
CloneOpts *git.CloneOptions
53+
Timeout time.Duration
54+
}
4555
)
4656

4757
func NewGitSourceCommand() *cobra.Command {
4858
cmd := &cobra.Command{
49-
Use: "git-source",
50-
Short: "Manage git-sources of Codefresh runtimes",
59+
Use: "git-source",
60+
Short: "Manage git-sources of Codefresh runtimes",
61+
PersistentPreRunE: cfConfig.RequireAuthentication,
5162
Run: func(cmd *cobra.Command, args []string) {
5263
cmd.HelpFunc()(cmd, args)
5364
exit(1)
5465
},
5566
}
5667

5768
cmd.AddCommand(NewGitSourceCreateCommand())
69+
cmd.AddCommand(NewGitSourceDeleteCommand())
5870

5971
return cmd
6072
}
@@ -69,7 +81,7 @@ func NewGitSourceCreateCommand() *cobra.Command {
6981
Use: "create runtime_name git-source_name",
7082
Short: "add a new git-source to an existing runtime",
7183
Example: util.Doc(`
72-
<BIN> git-source create runtime_name git-source-name https://github.com/owner/repo-name/my-workflow
84+
<BIN> git-source create runtime_name git-source-name --git-src-repo https://github.com/owner/repo-name/my-workflow
7385
`),
7486
PreRun: func(cmd *cobra.Command, args []string) {
7587
ctx := cmd.Context()
@@ -120,6 +132,49 @@ func NewGitSourceCreateCommand() *cobra.Command {
120132
return cmd
121133
}
122134

135+
func NewGitSourceDeleteCommand() *cobra.Command {
136+
var (
137+
cloneOpts *git.CloneOptions
138+
)
139+
140+
cmd := &cobra.Command{
141+
Use: "delete runtime_name git-source_name",
142+
Short: "delete a git-source from a runtime",
143+
Example: util.Doc(`
144+
<BIN> git-source delete runtime_name git-source_name
145+
`),
146+
PreRun: func(cmd *cobra.Command, args []string) {
147+
ctx := cmd.Context()
148+
149+
if len(args) < 1 {
150+
log.G(ctx).Fatal("must enter runtime name")
151+
}
152+
153+
if len(args) < 2 {
154+
log.G(ctx).Fatal("must enter git-source name")
155+
}
156+
157+
cloneOpts.Parse()
158+
},
159+
RunE: func(cmd *cobra.Command, args []string) error {
160+
ctx := cmd.Context()
161+
162+
return RunDeleteGitSource(ctx, &GitSourceDeleteOptions{
163+
RuntimeName: args[0],
164+
GsName: args[1],
165+
Timeout: aputil.MustParseDuration(cmd.Flag("request-timeout").Value.String()),
166+
CloneOpts: cloneOpts,
167+
})
168+
},
169+
}
170+
171+
cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
172+
FS: memfs.New(),
173+
})
174+
175+
return cmd
176+
}
177+
123178
func RunCreateGitSource(ctx context.Context, opts *GitSourceCreateOptions) error {
124179
gsRepo, gsFs, err := opts.gsCloneOpts.GetRepo(ctx)
125180
if err != nil {
@@ -160,6 +215,23 @@ func RunCreateGitSource(ctx context.Context, opts *GitSourceCreateOptions) error
160215
return nil
161216
}
162217

218+
func RunDeleteGitSource(ctx context.Context, opts *GitSourceDeleteOptions) error {
219+
err := apcmd.RunAppDelete(ctx, &apcmd.AppDeleteOptions{
220+
CloneOpts: opts.CloneOpts,
221+
ProjectName: opts.RuntimeName,
222+
AppName: opts.GsName,
223+
Global: false,
224+
})
225+
226+
if err != nil {
227+
return fmt.Errorf("failed to delete git-source %s. Err: %w", opts.GsName, err)
228+
}
229+
230+
log.G(ctx).Debug("successfully deleted git-source: %s", opts.GsName)
231+
232+
return nil
233+
}
234+
163235
func createDemoWorkflowTemplate(gsFs fs.FS, gsName, runtimeName string) error {
164236
wfTemplate := &wfv1alpha1.WorkflowTemplate{
165237
TypeMeta: metav1.TypeMeta{
@@ -186,6 +258,6 @@ func createDemoWorkflowTemplate(gsFs fs.FS, gsName, runtimeName string) error {
186258
},
187259
},
188260
}
189-
261+
190262
return gsFs.WriteYamls("demo-wf-template.yaml", wfTemplate)
191263
}

docs/commands/cli-v2_git-source.md

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

2626
* [cli-v2](cli-v2.md) - cli-v2 is used for installing and managing codefresh installations using gitops
2727
* [cli-v2 git-source create](cli-v2_git-source_create.md) - add a new git-source to an existing runtime
28+
* [cli-v2 git-source delete](cli-v2_git-source_delete.md) - delete a git-source from a runtime
2829

docs/commands/cli-v2_git-source_create.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cli-v2 git-source create runtime_name git-source_name [flags]
1010

1111
```
1212
13-
cli-v2 git-source create runtime_name git-source-name https://github.com/owner/repo-name/my-workflow
13+
cli-v2 git-source create runtime_name git-source-name --git-src-repo https://github.com/owner/repo-name/my-workflow
1414
1515
```
1616

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## cli-v2 git-source delete
2+
3+
delete a git-source from a runtime
4+
5+
```
6+
cli-v2 git-source delete runtime_name git-source_name [flags]
7+
```
8+
9+
### Examples
10+
11+
```
12+
13+
cli-v2 git-source delete runtime_name git-source_name
14+
15+
```
16+
17+
### Options
18+
19+
```
20+
-t, --git-token string Your git provider api token [GIT_TOKEN]
21+
-h, --help help for delete
22+
--repo string Repository URL [GIT_REPO]
23+
```
24+
25+
### Options inherited from parent commands
26+
27+
```
28+
--auth-context string Run the next command using a specific authentication context
29+
--cfconfig string Custom path for authentication contexts config file (default "/home/user")
30+
--insecure Disable certificate validation for TLS connections (e.g. to g.codefresh.io)
31+
--request-timeout duration Request timeout (default 30s)
32+
```
33+
34+
### SEE ALSO
35+
36+
* [cli-v2 git-source](cli-v2_git-source.md) - Manage git-sources of Codefresh runtimes
37+

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ cf version
2020
### Linux
2121
```bash
2222
# download and extract the binary
23-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.60/cf-linux-amd64.tar.gz | tar zx
23+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.62/cf-linux-amd64.tar.gz | tar zx
2424

2525
# move the binary to your $PATH
2626
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -32,7 +32,7 @@ cf version
3232
### Mac
3333
```bash
3434
# download and extract the binary
35-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.60/cf-darwin-amd64.tar.gz | tar zx
35+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.62/cf-darwin-amd64.tar.gz | tar zx
3636

3737
# move the binary to your $PATH
3838
mv ./cf-darwin-amd64 /usr/local/bin/cf

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ replace (
5858
k8s.io/mount-utils => k8s.io/mount-utils v0.21.1
5959
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.21.1
6060
sigs.k8s.io/kustomize => sigs.k8s.io/kustomize/v4 v4.1.3
61+
6162
)

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.0
8-
version: 0.0.60
8+
version: 0.0.62
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

0 commit comments

Comments
 (0)