Skip to content

Commit 7e5ecfe

Browse files
authored
CR-18810-fix-create-gs (#695)
## What * fixed `cf git-source create` command to not crash (and handle runtime namespace correctly) * fixed `cf runtime uninstall` to get runtime namespace from platform ## Why the `cf git-source create` command was crashing, the `cf runtime uninstall` was working (even when runtimeName !== runtimeNamespace), but in a less safe way
1 parent 7ab21e9 commit 7e5ecfe

File tree

15 files changed

+121
-138
lines changed

15 files changed

+121
-138
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.1.46
1+
VERSION=v0.1.47
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/cluster.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ import (
2828
"github.com/codefresh-io/cli-v2/pkg/util"
2929
kubeutil "github.com/codefresh-io/cli-v2/pkg/util/kube"
3030
kustutil "github.com/codefresh-io/cli-v2/pkg/util/kust"
31-
platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
32-
"github.com/ghodss/yaml"
3331

3432
"github.com/Masterminds/semver/v3"
35-
"github.com/argoproj-labs/argocd-autopilot/pkg/kube"
33+
apkube "github.com/argoproj-labs/argocd-autopilot/pkg/kube"
34+
platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
35+
"github.com/ghodss/yaml"
3636
"github.com/juju/ansiterm"
3737
"github.com/spf13/cobra"
3838
kusttypes "sigs.k8s.io/kustomize/api/types"
@@ -51,7 +51,7 @@ type (
5151
tag string
5252
dryRun bool
5353
skipTLSValidation bool
54-
kubeFactory kube.Factory
54+
kubeFactory apkube.Factory
5555
}
5656

5757
ClusterRemoveOptions struct {
@@ -147,7 +147,7 @@ func newClusterAddCommand() *cobra.Command {
147147
cmd.Flags().StringVar(&opts.tag, "tag", "", "[dev only] - use a specific tag of the csdp-add-cluster image")
148148

149149
util.Die(cmd.Flags().MarkHidden("tag"))
150-
opts.kubeFactory = kube.AddFlags(cmd.Flags())
150+
opts.kubeFactory = apkube.AddFlags(cmd.Flags())
151151

152152
return cmd
153153
}

cmd/commands/common.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ import (
3838
"github.com/codefresh-io/cli-v2/pkg/util/kube"
3939
routingutil "github.com/codefresh-io/cli-v2/pkg/util/routing"
4040

41-
"github.com/argoproj-labs/argocd-autopilot/pkg/fs"
42-
"github.com/argoproj-labs/argocd-autopilot/pkg/git"
41+
apfs "github.com/argoproj-labs/argocd-autopilot/pkg/fs"
4342
apgit "github.com/argoproj-labs/argocd-autopilot/pkg/git"
4443
aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
4544
platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
@@ -487,7 +486,6 @@ func getKubeContextName(context, kubeconfig *pflag.Flag) (string, error) {
487486

488487
return contextName, context.Value.Set(contextName)
489488
}
490-
491489
type SelectItem struct {
492490
Value string
493491
Label string
@@ -744,24 +742,6 @@ func suggestIscRepo(ctx context.Context, suggestedSharedConfigRepo string) (stri
744742
return setIscRepoResponse, nil
745743
}
746744

747-
func isRuntimeManaged(ctx context.Context, runtimeName string) (bool, error) {
748-
rt, err := getRuntime(ctx, runtimeName)
749-
if err != nil {
750-
return false, err
751-
}
752-
753-
return rt.Managed, nil
754-
}
755-
756-
func getRuntimeInstallationType(ctx context.Context, runtimeName string) (*platmodel.InstallationType, error) {
757-
rt, err := getRuntime(ctx, runtimeName)
758-
if err != nil {
759-
return nil, err
760-
}
761-
762-
return &rt.InstallationType, nil
763-
}
764-
765745
func ensureRuntimeOnKubeContext(ctx context.Context, kubeconfig string, runtimeName string, kubeContextName string) error {
766746
rt, err := getRuntime(ctx, runtimeName)
767747
if err != nil {
@@ -797,7 +777,7 @@ func getRuntime(ctx context.Context, runtimeName string) (*platmodel.Runtime, er
797777
return rt, nil
798778
}
799779

800-
func patchRuntimeRepo(ctx context.Context, cloneOpts *git.CloneOptions, msg string, f func(fs fs.FS) error) error {
780+
func patchRuntimeRepo(ctx context.Context, cloneOpts *apgit.CloneOptions, msg string, f func(fs apfs.FS) error) error {
801781
r, fs, err := cloneOpts.GetRepo(ctx)
802782
if err != nil {
803783
return err

cmd/commands/config_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
cfgit "github.com/codefresh-io/cli-v2/pkg/git"
2121
"github.com/codefresh-io/cli-v2/pkg/store"
22+
2223
"github.com/stretchr/testify/assert"
2324
)
2425

cmd/commands/git-source.go

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ import (
3030
routingutil "github.com/codefresh-io/cli-v2/pkg/util/routing"
3131
wfutil "github.com/codefresh-io/cli-v2/pkg/util/workflow"
3232

33-
"github.com/argoproj-labs/argocd-autopilot/pkg/application"
34-
"github.com/argoproj-labs/argocd-autopilot/pkg/fs"
35-
"github.com/argoproj-labs/argocd-autopilot/pkg/git"
33+
apapp "github.com/argoproj-labs/argocd-autopilot/pkg/application"
34+
apfs "github.com/argoproj-labs/argocd-autopilot/pkg/fs"
35+
apgit "github.com/argoproj-labs/argocd-autopilot/pkg/git"
3636
aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
3737
apicommon "github.com/argoproj/argo-events/pkg/apis/common"
3838
eventsourcereg "github.com/argoproj/argo-events/pkg/apis/eventsource"
@@ -53,8 +53,8 @@ import (
5353

5454
type (
5555
GitSourceCreateOptions struct {
56-
InsCloneOpts *git.CloneOptions
57-
GsCloneOpts *git.CloneOptions
56+
InsCloneOpts *apgit.CloneOptions
57+
GsCloneOpts *apgit.CloneOptions
5858
GsName string
5959
RuntimeName string
6060
RuntimeNamespace string
@@ -82,22 +82,22 @@ type (
8282
GitSourceEditOptions struct {
8383
RuntimeName string
8484
GsName string
85-
GsCloneOpts *git.CloneOptions
85+
GsCloneOpts *apgit.CloneOptions
8686
Include *string
8787
Exclude *string
8888
}
8989

9090
gitSourceCalendarDemoPipelineOptions struct {
9191
runtimeName string
92-
gsCloneOpts *git.CloneOptions
93-
gsFs fs.FS
92+
gsCloneOpts *apgit.CloneOptions
93+
gsFs apfs.FS
9494
}
9595

9696
gitSourceGitDemoPipelineOptions struct {
9797
runtimeName string
98-
gsCloneOpts *git.CloneOptions
98+
gsCloneOpts *apgit.CloneOptions
9999
gitProvider cfgit.Provider
100-
gsFs fs.FS
100+
gsFs apfs.FS
101101
hostName string
102102
ingressHost string
103103
skipIngress bool
@@ -132,7 +132,7 @@ func NewGitSourceCommand() *cobra.Command {
132132

133133
func NewGitSourceCreateCommand() *cobra.Command {
134134
var (
135-
gsCloneOpts *git.CloneOptions
135+
gsCloneOpts *apgit.CloneOptions
136136
gitProvider cfgit.Provider
137137
createRepo bool
138138
include string
@@ -188,17 +188,22 @@ func NewGitSourceCreateCommand() *cobra.Command {
188188
RunE: func(cmd *cobra.Command, args []string) error {
189189
ctx := cmd.Context()
190190

191-
runtimeNamespace := args[0]
192-
namespace := cmd.Flag("namespace").Value.String()
193-
if namespace != "" {
194-
runtimeNamespace = namespace
191+
runtimeName := args[0]
192+
runtime, err := getRuntime(ctx, runtimeName)
193+
if err != nil {
194+
return err
195+
}
196+
197+
runtimeNamespace := runtimeName
198+
if runtime.Metadata.Namespace != nil {
199+
runtimeNamespace = *runtime.Metadata.Namespace
195200
}
196201

197202
return RunGitSourceCreate(ctx, &GitSourceCreateOptions{
198203
GsCloneOpts: gsCloneOpts,
199204
GitProvider: gitProvider,
200205
GsName: args[1],
201-
RuntimeName: args[0],
206+
RuntimeName: runtimeName,
202207
RuntimeNamespace: runtimeNamespace,
203208
CreateDemoResources: false,
204209
Include: include,
@@ -245,7 +250,7 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
245250
return nil
246251
}
247252

248-
func ensureGitSourceDirectory(ctx context.Context, opts *GitSourceCreateOptions, gsRepo git.Repository, gsFs fs.FS) error {
253+
func ensureGitSourceDirectory(ctx context.Context, opts *GitSourceCreateOptions, gsRepo apgit.Repository, gsFs apfs.FS) error {
249254
fi, err := gsFs.ReadDir(".")
250255
if err != nil {
251256
return fmt.Errorf("failed to read files in git-source repo. Err: %w", err)
@@ -411,7 +416,7 @@ func RunGitSourceDelete(ctx context.Context, opts *GitSourceDeleteOptions) error
411416

412417
func NewGitSourceEditCommand() *cobra.Command {
413418
var (
414-
gsCloneOpts *git.CloneOptions
419+
gsCloneOpts *apgit.CloneOptions
415420
include string
416421
exclude string
417422
)
@@ -492,7 +497,7 @@ func RunGitSourceEdit(ctx context.Context, opts *GitSourceEditOptions) error {
492497
return nil
493498
}
494499

495-
func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRepo git.Repository, gsFs fs.FS) error {
500+
func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRepo apgit.Repository, gsFs apfs.FS) error {
496501
fi, err := gsFs.ReadDir(".")
497502
if err != nil {
498503
return fmt.Errorf("failed to read files in git-source repo. Err: %w", err)
@@ -1391,7 +1396,7 @@ func deleteCommonRedundantFields(crd map[string]interface{}) {
13911396
}
13921397

13931398
func writeObjectToYaml[Object any](
1394-
gsFs fs.FS,
1399+
gsFs apfs.FS,
13951400
filePath string,
13961401
object Object,
13971402
cleanUpFunc func(Object) (map[string]interface{}, error),
@@ -1425,7 +1430,7 @@ func legacyGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) er
14251430

14261431
appDef := &runtime.AppDef{
14271432
Name: opts.GsName,
1428-
Type: application.AppTypeDirectory,
1433+
Type: apapp.AppTypeDirectory,
14291434
URL: opts.GsCloneOpts.Repo,
14301435
Include: opts.Include,
14311436
Exclude: opts.Exclude,

cmd/commands/helm_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ import (
2020
"net/http"
2121
"testing"
2222

23-
kubemocks "github.com/argoproj-labs/argocd-autopilot/pkg/kube/mocks"
2423
cfgit "github.com/codefresh-io/cli-v2/pkg/git"
2524
gitmocks "github.com/codefresh-io/cli-v2/pkg/git/mocks"
25+
26+
kubemocks "github.com/argoproj-labs/argocd-autopilot/pkg/kube/mocks"
2627
platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
2728
"github.com/golang/mock/gomock"
2829
"github.com/stretchr/testify/assert"

0 commit comments

Comments
 (0)