@@ -45,7 +45,8 @@ import (
4545 sensorsv1alpha1 "github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1"
4646 wf "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow"
4747 wfv1alpha1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
48- appProxyModel "github.com/codefresh-io/go-sdk/pkg/codefresh/model/app-proxy"
48+ platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
49+ apmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model/app-proxy"
4950 billyUtils "github.com/go-git/go-billy/v5/util"
5051 "github.com/juju/ansiterm"
5152 "github.com/spf13/cobra"
6768 IngressHost string
6869 IngressClass string
6970 IngressController routingutil.RoutingController
71+ AccessMode platmodel.AccessMode
7072 GatewayName string
7173 GatewayNamespace string
72- Flow string
7374 GitProvider cfgit.Provider
7475 useGatewayAPI bool
7576 }
@@ -105,6 +106,7 @@ type (
105106 ingressHost string
106107 ingressClass string
107108 ingressController routingutil.RoutingController
109+ accessMode platmodel.AccessMode
108110 gatewayName string
109111 gatewayNamespace string
110112 useGatewayAPI bool
@@ -147,7 +149,6 @@ func NewGitSourceCreateCommand() *cobra.Command {
147149 createRepo bool
148150 include string
149151 exclude string
150- flow string
151152 )
152153
153154 cmd := & cobra.Command {
@@ -217,7 +218,6 @@ func NewGitSourceCreateCommand() *cobra.Command {
217218 CreateDemoResources : false ,
218219 Include : include ,
219220 Exclude : exclude ,
220- Flow : flow ,
221221 })
222222 },
223223 }
@@ -232,8 +232,6 @@ func NewGitSourceCreateCommand() *cobra.Command {
232232 Optional : true ,
233233 })
234234
235- flow = store .Get ().GsCreateFlow
236-
237235 return cmd
238236}
239237
@@ -243,10 +241,6 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
243241 return err
244242 }
245243
246- if opts .Flow == store .Get ().InstallationFlow {
247- return legacyGitSourceCreate (ctx , opts )
248- }
249-
250244 if version .LessThan (appProxyGitSourceSupport ) {
251245 log .G (ctx ).Warnf ("runtime \" %s\" is using a deprecated git-source api. Versions %s and up use the app-proxy for this command. You are using version: %s" , opts .RuntimeName , appProxyGitSourceSupport , version .String ())
252246 return legacyGitSourceCreate (ctx , opts )
@@ -260,7 +254,7 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
260254 appSpecifier := opts .GsCloneOpts .Repo
261255 isInternal := util .StringIndexOf (store .Get ().CFInternalGitSources , opts .GsName ) > - 1
262256
263- err = appProxy .AppProxyGitSources ().Create (ctx , & appProxyModel .CreateGitSourceInput {
257+ err = appProxy .AppProxyGitSources ().Create (ctx , & apmodel .CreateGitSourceInput {
264258 AppName : opts .GsName ,
265259 AppSpecifier : appSpecifier ,
266260 DestServer : store .Get ().InCluster ,
@@ -280,23 +274,25 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
280274 return nil
281275}
282276
283- func createPlaceholderIfNeeded (ctx context.Context , opts * GitSourceCreateOptions , gsRepo git.Repository , gsFs fs.FS ) error {
277+ func ensureGitSourceDirectory (ctx context.Context , opts * GitSourceCreateOptions , gsRepo git.Repository , gsFs fs.FS ) error {
284278 fi , err := gsFs .ReadDir ("." )
285279 if err != nil {
286280 return fmt .Errorf ("failed to read files in git-source repo. Err: %w" , err )
287281 }
288282
289- if len (fi ) == 0 {
290- if err = billyUtils .WriteFile (gsFs , "DUMMY" , []byte {}, 0666 ); err != nil {
291- return fmt .Errorf ("failed to write the git-source placeholder file. Err: %w" , err )
292- }
283+ if len (fi ) > 0 {
284+ return nil
285+ }
286+
287+ if err = billyUtils .WriteFile (gsFs , "DUMMY" , []byte {}, 0666 ); err != nil {
288+ return fmt .Errorf ("failed to write the git-source placeholder file. Err: %w" , err )
289+ }
293290
294- commitMsg := fmt .Sprintf ("Created a placeholder file in %s Directory" , opts .GsCloneOpts .Path ())
291+ commitMsg := fmt .Sprintf ("Created a placeholder file in %s Directory" , opts .GsCloneOpts .Path ())
295292
296- log .G (ctx ).Info ("Pushing placeholder file to the default-git-source repo" )
297- if err := apu .PushWithMessage (ctx , gsRepo , commitMsg ); err != nil {
298- return fmt .Errorf ("failed to push placeholder file to git-source repo: %w" , err )
299- }
293+ log .G (ctx ).Info ("Pushing placeholder file to the default-git-source repo" )
294+ if err := apu .PushWithMessage (ctx , gsRepo , commitMsg ); err != nil {
295+ return fmt .Errorf ("failed to push placeholder file to git-source repo: %w" , err )
300296 }
301297
302298 return nil
@@ -569,7 +565,7 @@ func RunGitSourceEdit(ctx context.Context, opts *GitSourceEditOptions) error {
569565 return err
570566 }
571567
572- err = appProxy .AppProxyGitSources ().Edit (ctx , & appProxyModel .EditGitSourceInput {
568+ err = appProxy .AppProxyGitSources ().Edit (ctx , & apmodel .EditGitSourceInput {
573569 AppName : opts .GsName ,
574570 AppSpecifier : opts .GsCloneOpts .Repo ,
575571 Include : opts .Include ,
@@ -591,6 +587,7 @@ func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRe
591587 if err != nil {
592588 return fmt .Errorf ("failed to read files in git-source repo. Err: %w" , err )
593589 }
590+
594591 if len (fi ) == 0 {
595592 wfTemplateFilePath := store .Get ().DemoWorkflowTemplateFileName
596593 wfTemplate := createDemoWorkflowTemplate ()
@@ -607,21 +604,24 @@ func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRe
607604 return fmt .Errorf ("failed to create calendar example pipeline. Error: %w" , err )
608605 }
609606
610- err = createDemoGitPipeline (& gitSourceGitDemoPipelineOptions {
611- runtimeName : opts .RuntimeName ,
612- gsCloneOpts : opts .GsCloneOpts ,
613- gitProvider : opts .GitProvider ,
614- gsFs : gsFs ,
615- hostName : opts .HostName ,
616- ingressHost : opts .IngressHost ,
617- ingressClass : opts .IngressClass ,
618- ingressController : opts .IngressController ,
619- gatewayName : opts .GatewayName ,
620- gatewayNamespace : opts .GatewayNamespace ,
621- useGatewayAPI : opts .useGatewayAPI ,
622- })
623- if err != nil {
624- return fmt .Errorf ("failed to create github example pipeline. Error: %w" , err )
607+ if opts .AccessMode == platmodel .AccessModeIngress {
608+ err = createDemoGitPipeline (& gitSourceGitDemoPipelineOptions {
609+ runtimeName : opts .RuntimeName ,
610+ gsCloneOpts : opts .GsCloneOpts ,
611+ gitProvider : opts .GitProvider ,
612+ gsFs : gsFs ,
613+ hostName : opts .HostName ,
614+ ingressHost : opts .IngressHost ,
615+ ingressClass : opts .IngressClass ,
616+ ingressController : opts .IngressController ,
617+ accessMode : opts .AccessMode ,
618+ gatewayName : opts .GatewayName ,
619+ gatewayNamespace : opts .GatewayNamespace ,
620+ useGatewayAPI : opts .useGatewayAPI ,
621+ })
622+ if err != nil {
623+ return fmt .Errorf ("failed to create github example pipeline. Error: %w" , err )
624+ }
625625 }
626626
627627 commitMsg := fmt .Sprintf ("Created demo pipelines in %s Directory" , opts .GsCloneOpts .Path ())
@@ -752,7 +752,7 @@ func createDemoCalendarTrigger() sensorsv1alpha1.Trigger {
752752}
753753
754754func createDemoGitPipeline (opts * gitSourceGitDemoPipelineOptions ) error {
755- if ! store . Get (). SkipIngress {
755+ if opts . accessMode == platmodel . AccessModeIngress {
756756 // Create an ingress that will manage external access to the git eventsource service
757757 routeOpts := routingutil.CreateRouteOpts {
758758 RuntimeName : opts .runtimeName ,
@@ -1532,20 +1532,22 @@ func legacyGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) er
15321532 return fmt .Errorf ("failed to create git-source demo resources: %w" , err )
15331533 }
15341534 } else {
1535- if err := createPlaceholderIfNeeded (ctx , opts , gsRepo , gsFs ); err != nil {
1536- return fmt .Errorf ("failed to create a git-source placeholder : %w" , err )
1535+ if err := ensureGitSourceDirectory (ctx , opts , gsRepo , gsFs ); err != nil {
1536+ return fmt .Errorf ("failed to ensure git-source directory : %w" , err )
15371537 }
15381538 }
15391539
15401540 appDef := & runtime.AppDef {
1541- Name : opts .GsName ,
1542- Type : application .AppTypeDirectory ,
1543- URL : opts .GsCloneOpts .Repo ,
1541+ Name : opts .GsName ,
1542+ Type : application .AppTypeDirectory ,
1543+ URL : opts .GsCloneOpts .Repo ,
1544+ Include : opts .Include ,
1545+ Exclude : opts .Exclude ,
15441546 }
15451547
15461548 appDef .IsInternal = util .StringIndexOf (store .Get ().CFInternalGitSources , appDef .Name ) > - 1
15471549
1548- if err := appDef .CreateApp (ctx , nil , opts .InsCloneOpts , opts .RuntimeName , store .Get ().CFGitSourceType , opts . Include , opts . Exclude ); err != nil {
1550+ if err := appDef .CreateApp (ctx , nil , opts .InsCloneOpts , opts .RuntimeName , store .Get ().CFGitSourceType ); err != nil {
15491551 return fmt .Errorf ("failed to create git-source application. Err: %w" , err )
15501552 }
15511553
0 commit comments