Skip to content

Commit 82b558f

Browse files
proxy-bump-2 (#365)
* include exclude refactor * bumped app-proxy to 1.1112.0 Co-authored-by: Noam Gal <noam.gal@codefresh.io>
1 parent bf419e3 commit 82b558f

File tree

19 files changed

+140
-131
lines changed

19 files changed

+140
-131
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.325
1+
VERSION=v0.0.326
22

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

cmd/commands/common.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,18 @@ import (
2727
"strings"
2828
"time"
2929

30-
"github.com/argoproj-labs/argocd-autopilot/pkg/git"
3130
"github.com/codefresh-io/cli-v2/pkg/config"
3231
cfgit "github.com/codefresh-io/cli-v2/pkg/git"
3332
"github.com/codefresh-io/cli-v2/pkg/log"
3433
"github.com/codefresh-io/cli-v2/pkg/store"
3534
"github.com/codefresh-io/cli-v2/pkg/util"
3635

36+
"github.com/argoproj-labs/argocd-autopilot/pkg/git"
3737
"github.com/manifoldco/promptui"
38-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
39-
4038
"github.com/spf13/cobra"
4139
"github.com/spf13/pflag"
4240
"github.com/spf13/viper"
41+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4342
)
4443

4544
var (

cmd/commands/component.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import (
2222

2323
"github.com/codefresh-io/cli-v2/pkg/log"
2424
"github.com/codefresh-io/cli-v2/pkg/util"
25+
2526
"github.com/codefresh-io/go-sdk/pkg/codefresh/model"
2627
"github.com/juju/ansiterm"
27-
2828
"github.com/spf13/cobra"
2929
)
3030

cmd/commands/git-source.go

Lines changed: 103 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ import (
2121
"strings"
2222
"time"
2323

24+
"github.com/codefresh-io/cli-v2/pkg/log"
25+
"github.com/codefresh-io/cli-v2/pkg/runtime"
26+
"github.com/codefresh-io/cli-v2/pkg/store"
27+
"github.com/codefresh-io/cli-v2/pkg/util"
28+
apu "github.com/codefresh-io/cli-v2/pkg/util/aputil"
29+
eventsutil "github.com/codefresh-io/cli-v2/pkg/util/events"
30+
ingressutil "github.com/codefresh-io/cli-v2/pkg/util/ingress"
31+
wfutil "github.com/codefresh-io/cli-v2/pkg/util/workflow"
32+
2433
"github.com/Masterminds/semver/v3"
2534
apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands"
2635
"github.com/argoproj-labs/argocd-autopilot/pkg/application"
@@ -35,14 +44,6 @@ import (
3544
sensorsv1alpha1 "github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1"
3645
wf "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow"
3746
wfv1alpha1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
38-
"github.com/codefresh-io/cli-v2/pkg/log"
39-
"github.com/codefresh-io/cli-v2/pkg/runtime"
40-
"github.com/codefresh-io/cli-v2/pkg/store"
41-
"github.com/codefresh-io/cli-v2/pkg/util"
42-
apu "github.com/codefresh-io/cli-v2/pkg/util/aputil"
43-
eventsutil "github.com/codefresh-io/cli-v2/pkg/util/events"
44-
ingressutil "github.com/codefresh-io/cli-v2/pkg/util/ingress"
45-
wfutil "github.com/codefresh-io/cli-v2/pkg/util/workflow"
4647
appProxyModel "github.com/codefresh-io/go-sdk/pkg/codefresh/model/app-proxy"
4748
billyUtils "github.com/go-git/go-billy/v5/util"
4849
"github.com/juju/ansiterm"
@@ -81,8 +82,8 @@ type (
8182
GsName string
8283
InsCloneOpts *git.CloneOptions
8384
GsCloneOpts *git.CloneOptions
84-
Include string
85-
Exclude string
85+
Include *string
86+
Exclude *string
8687
}
8788

8889
gitSourceCronExampleOptions struct {
@@ -108,7 +109,7 @@ type (
108109
}
109110
)
110111

111-
var versionOfGitSourceByAppProxyRefactor = semver.MustParse("0.0.325")
112+
var versionOfGitSourceByAppProxyRefactor = semver.MustParse("0.0.326")
112113

113114
func NewGitSourceCommand() *cobra.Command {
114115
cmd := &cobra.Command{
@@ -232,36 +233,35 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
232233
}
233234

234235
if version.LessThan(versionOfGitSourceByAppProxyRefactor) {
235-
log.G(ctx).Infof("runtime \"%s\" is using a depracated git-source api. Versions %s and up use the app-proxy for this command", opts.RuntimeName, minAddClusterSupportedVersion)
236+
log.G(ctx).Warnf("runtime \"%s\" is using a depracated git-source api. Versions %s and up use the app-proxy for this command", opts.RuntimeName, minAddClusterSupportedVersion)
236237
return legacyGitSourceCreate(ctx, opts)
237-
} else {
238-
appProxy, err := cfConfig.NewClient().AppProxy(ctx, opts.RuntimeName, store.Get().InsecureIngressHost)
239-
if err != nil {
240-
return err
241-
}
238+
}
242239

243-
appSpecifier := opts.GsCloneOpts.Repo
244-
isInternal := util.StringIndexOf(store.Get().CFInternalGitSources, opts.GsName) > -1
245-
246-
err = appProxy.AppProxyGitSources().Create(ctx, &appProxyModel.CreateGitSourceInput{
247-
AppName: opts.GsName,
248-
AppSpecifier: appSpecifier,
249-
DestServer: store.Get().InCluster,
250-
DestNamespace: opts.RuntimeName,
251-
IsInternal: &isInternal,
252-
Include: &opts.Include,
253-
Exclude: &opts.Exclude,
254-
})
240+
appProxy, err := cfConfig.NewClient().AppProxy(ctx, opts.RuntimeName, store.Get().InsecureIngressHost)
241+
if err != nil {
242+
return err
243+
}
255244

256-
if err != nil {
257-
log.G(ctx).Errorf("failed to create git-source: %w", err)
258-
log.G(ctx).Info("attempting creation of git-source without using app-proxy")
259-
return legacyGitSourceCreate(ctx, opts)
260-
}
245+
appSpecifier := opts.GsCloneOpts.Repo
246+
isInternal := util.StringIndexOf(store.Get().CFInternalGitSources, opts.GsName) > -1
261247

262-
log.G(ctx).Infof("Successfully created git-source: \"%s\"", opts.GsName)
248+
err = appProxy.AppProxyGitSources().Create(ctx, &appProxyModel.CreateGitSourceInput{
249+
AppName: opts.GsName,
250+
AppSpecifier: appSpecifier,
251+
DestServer: store.Get().InCluster,
252+
DestNamespace: opts.RuntimeName,
253+
IsInternal: &isInternal,
254+
Include: &opts.Include,
255+
Exclude: &opts.Exclude,
256+
})
257+
258+
if err != nil {
259+
log.G(ctx).Errorf("failed to create git-source: %w", err)
260+
log.G(ctx).Info("attempting creation of git-source without using app-proxy")
261+
return legacyGitSourceCreate(ctx, opts)
263262
}
264263

264+
log.G(ctx).Infof("Successfully created git-source: \"%s\"", opts.GsName)
265265
return nil
266266
}
267267

@@ -612,7 +612,19 @@ func RunGitSourceDelete(ctx context.Context, opts *GitSourceDeleteOptions) error
612612
}
613613

614614
if version.LessThan(versionOfGitSourceByAppProxyRefactor) {
615-
log.G(ctx).Infof("runtime \"%s\" is using a depracated git-source api. Versions %s and up use the app-proxy for this command", opts.RuntimeName, minAddClusterSupportedVersion)
615+
log.G(ctx).Warnf("runtime \"%s\" is using a depracated git-source api. Versions %s and up use the app-proxy for this command", opts.RuntimeName, minAddClusterSupportedVersion)
616+
return legacyGitSourceDelete(ctx, opts)
617+
}
618+
619+
appProxy, err := cfConfig.NewClient().AppProxy(ctx, opts.RuntimeName, store.Get().InsecureIngressHost)
620+
if err != nil {
621+
return err
622+
}
623+
624+
err = appProxy.AppProxyGitSources().Delete(ctx, opts.GsName)
625+
if err != nil {
626+
log.G(ctx).Errorf("failed to delete git-source: %w", err)
627+
log.G(ctx).Info("attempting deletion of git-source without using app-proxy")
616628
err = apcmd.RunAppDelete(ctx, &apcmd.AppDeleteOptions{
617629
CloneOpts: opts.InsCloneOpts,
618630
ProjectName: opts.RuntimeName,
@@ -623,27 +635,6 @@ func RunGitSourceDelete(ctx context.Context, opts *GitSourceDeleteOptions) error
623635
if err != nil {
624636
return fmt.Errorf("failed to delete the git-source %s. Err: %w", opts.GsName, err)
625637
}
626-
} else {
627-
appProxy, err := cfConfig.NewClient().AppProxy(ctx, opts.RuntimeName, store.Get().InsecureIngressHost)
628-
if err != nil {
629-
return err
630-
}
631-
632-
err = appProxy.AppProxyGitSources().Delete(ctx, opts.GsName)
633-
if err != nil {
634-
log.G(ctx).Errorf("failed to delete git-source: %w", err)
635-
log.G(ctx).Info("attempting deletion of git-source without using app-proxy")
636-
err = apcmd.RunAppDelete(ctx, &apcmd.AppDeleteOptions{
637-
CloneOpts: opts.InsCloneOpts,
638-
ProjectName: opts.RuntimeName,
639-
AppName: opts.GsName,
640-
Global: false,
641-
})
642-
643-
if err != nil {
644-
return fmt.Errorf("failed to delete the git-source %s. Err: %w", opts.GsName, err)
645-
}
646-
}
647638
}
648639

649640
log.G(ctx).Infof("Successfully deleted the git-source: %s", opts.GsName)
@@ -692,20 +683,26 @@ func NewGitSourceEditCommand() *cobra.Command {
692683
RunE: func(cmd *cobra.Command, args []string) error {
693684
ctx := cmd.Context()
694685

695-
return RunGitSourceEdit(ctx, &GitSourceEditOptions{
686+
opts := &GitSourceEditOptions{
696687
RuntimeName: args[0],
697688
GsName: args[1],
698689
InsCloneOpts: insCloneOpts,
699690
GsCloneOpts: gsCloneOpts,
700-
Include: include,
701-
Exclude: exclude,
702-
})
691+
}
692+
if cmd.Flags().Changed("include") {
693+
opts.Include = &include
694+
}
695+
696+
if cmd.Flags().Changed("exclude") {
697+
opts.Exclude = &exclude
698+
}
699+
700+
return RunGitSourceEdit(ctx, opts)
703701
},
704702
}
705703

706-
// defaults to "nil" string in order to allows an empty value
707-
cmd.Flags().StringVar(&include, "include", "nil", "files to include. can be either filenames or a glob")
708-
cmd.Flags().StringVar(&exclude, "exclude", "nil", "files to exclude. can be either filenames or a glob")
704+
cmd.Flags().StringVar(&include, "include", "", "files to include. can be either filenames or a glob")
705+
cmd.Flags().StringVar(&exclude, "exclude", "", "files to exclude. can be either filenames or a glob")
709706

710707
insCloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{
711708
CreateIfNotExist: true,
@@ -722,41 +719,35 @@ func NewGitSourceEditCommand() *cobra.Command {
722719
}
723720

724721
func RunGitSourceEdit(ctx context.Context, opts *GitSourceEditOptions) error {
725-
repo, fs, err := opts.InsCloneOpts.GetRepo(ctx)
726-
if err != nil {
727-
return err
728-
}
729-
730722
version, err := getRuntimeVersion(ctx, opts.RuntimeName)
731723
if err != nil {
732724
return err
733725
}
734726

735727
if version.LessThan(versionOfGitSourceByAppProxyRefactor) {
736-
return legacyGitSourceEdit(ctx, opts, repo, fs, err)
737-
} else {
738-
appProxy, err := cfConfig.NewClient().AppProxy(ctx, opts.RuntimeName, store.Get().InsecureIngressHost)
739-
if err != nil {
740-
return err
741-
}
742-
743-
err = appProxy.AppProxyGitSources().Edit(ctx, &appProxyModel.EditGitSourceInput{
744-
AppName: opts.GsName,
745-
AppSpecifier: opts.GsCloneOpts.Repo,
746-
Include: &opts.Include,
747-
Exclude: &opts.Exclude,
748-
})
728+
log.G(ctx).Warnf("runtime \"%s\" is using a depracated git-source api. Versions %s and up use the app-proxy for this command", opts.RuntimeName, minAddClusterSupportedVersion)
729+
return legacyGitSourceEdit(ctx, opts)
730+
}
749731

750-
if err != nil {
751-
log.G(ctx).Errorf("failed to edit git-source: %w", err)
752-
log.G(ctx).Info("attempting edit of git-source without using app-proxy")
753-
return legacyGitSourceEdit(ctx, opts, repo, fs, err)
732+
appProxy, err := cfConfig.NewClient().AppProxy(ctx, opts.RuntimeName, store.Get().InsecureIngressHost)
733+
if err != nil {
734+
return err
735+
}
754736

755-
}
737+
err = appProxy.AppProxyGitSources().Edit(ctx, &appProxyModel.EditGitSourceInput{
738+
AppName: opts.GsName,
739+
AppSpecifier: opts.GsCloneOpts.Repo,
740+
Include: opts.Include,
741+
Exclude: opts.Exclude,
742+
})
756743

757-
log.G(ctx).Infof("Successfully edited git-source: \"%s\"", opts.GsName)
744+
if err != nil {
745+
log.G(ctx).Errorf("failed to edit git-source: %w", err)
746+
log.G(ctx).Info("attempting edit of git-source without using app-proxy")
747+
return legacyGitSourceEdit(ctx, opts)
758748
}
759749

750+
log.G(ctx).Infof("Successfully edited git-source: \"%s\"", opts.GsName)
760751
return nil
761752
}
762753

@@ -1273,12 +1264,12 @@ func legacyGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) er
12731264
return nil
12741265
}
12751266

1276-
func legacyGitSourceEdit(ctx context.Context, opts *GitSourceEditOptions, repo git.Repository, fs fs.FS, err error) error {
1277-
log.G(ctx).Infof("runtime \"%s\" is using a depracated git-source api. Versions %s and up use the app-proxy for this command", opts.RuntimeName, minAddClusterSupportedVersion)
1278-
1267+
func legacyGitSourceEdit(ctx context.Context, opts *GitSourceEditOptions) error {
1268+
repo, fs, err := opts.InsCloneOpts.GetRepo(ctx)
12791269
if err != nil {
12801270
return fmt.Errorf("failed to clone the installation repo, attempting to edit git-source %s. Err: %w", opts.GsName, err)
12811271
}
1272+
12821273
c := &dirConfig{}
12831274
fileName := fs.Join(apstore.Default.AppsDir, opts.GsName, opts.RuntimeName, "config_dir.json")
12841275
err = fs.ReadJson(fileName, c)
@@ -1290,12 +1281,12 @@ func legacyGitSourceEdit(ctx context.Context, opts *GitSourceEditOptions, repo g
12901281
c.Config.SrcRepoURL = opts.GsCloneOpts.URL()
12911282
c.Config.SrcTargetRevision = opts.GsCloneOpts.Revision()
12921283

1293-
if opts.Include != "nil" {
1294-
c.Include = opts.Include
1284+
if opts.Include != nil {
1285+
c.Include = *opts.Include
12951286
}
12961287

1297-
if opts.Exclude != "nil" {
1298-
c.Exclude = opts.Include
1288+
if opts.Exclude != nil {
1289+
c.Exclude = *opts.Exclude
12991290
}
13001291

13011292
err = fs.WriteJson(fileName, c)
@@ -1308,6 +1299,22 @@ func legacyGitSourceEdit(ctx context.Context, opts *GitSourceEditOptions, repo g
13081299
return fmt.Errorf("failed to persist the updated git-source: %s. Err: %w", opts.GsName, err)
13091300
}
13101301

1311-
log.G(ctx).Infof("Successfully created git-source: \"%s\"", opts.GsName)
1302+
log.G(ctx).Infof("Successfully edited git-source: \"%s\"", opts.GsName)
13121303
return nil
13131304
}
1305+
1306+
func legacyGitSourceDelete(ctx context.Context, opts *GitSourceDeleteOptions) error {
1307+
err := apcmd.RunAppDelete(ctx, &apcmd.AppDeleteOptions{
1308+
CloneOpts: opts.InsCloneOpts,
1309+
ProjectName: opts.RuntimeName,
1310+
AppName: opts.GsName,
1311+
Global: false,
1312+
})
1313+
1314+
if err != nil {
1315+
return fmt.Errorf("failed to delete the git-source %s. Err: %w", opts.GsName, err)
1316+
}
1317+
1318+
log.G(ctx).Infof("Successfully deleted the git-source: %s", opts.GsName)
1319+
return nil
1320+
}

cmd/commands/integrations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/codefresh-io/cli-v2/pkg/log"
2424
"github.com/codefresh-io/cli-v2/pkg/store"
2525
"github.com/codefresh-io/cli-v2/pkg/util"
26+
2627
sdk "github.com/codefresh-io/go-sdk/pkg/codefresh"
2728
model "github.com/codefresh-io/go-sdk/pkg/codefresh/model/app-proxy"
2829
"github.com/ghodss/yaml"

cmd/commands/pipeline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121

2222
"github.com/codefresh-io/cli-v2/pkg/log"
2323
"github.com/codefresh-io/cli-v2/pkg/util"
24+
2425
"github.com/codefresh-io/go-sdk/pkg/codefresh/model"
2526
"github.com/juju/ansiterm"
26-
2727
"github.com/spf13/cobra"
2828
)
2929

0 commit comments

Comments
 (0)