@@ -21,6 +21,7 @@ import (
21
21
"strings"
22
22
"time"
23
23
24
+ "github.com/Masterminds/semver/v3"
24
25
apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands"
25
26
"github.com/argoproj-labs/argocd-autopilot/pkg/application"
26
27
"github.com/argoproj-labs/argocd-autopilot/pkg/fs"
@@ -39,8 +40,8 @@ import (
39
40
"github.com/codefresh-io/cli-v2/pkg/store"
40
41
"github.com/codefresh-io/cli-v2/pkg/util"
41
42
apu "github.com/codefresh-io/cli-v2/pkg/util/aputil"
42
- ingressutil "github.com/codefresh-io/cli-v2/pkg/util/ingress"
43
43
eventsutil "github.com/codefresh-io/cli-v2/pkg/util/events"
44
+ ingressutil "github.com/codefresh-io/cli-v2/pkg/util/ingress"
44
45
wfutil "github.com/codefresh-io/cli-v2/pkg/util/workflow"
45
46
billyUtils "github.com/go-git/go-billy/v5/util"
46
47
"github.com/juju/ansiterm"
@@ -103,6 +104,8 @@ type (
103
104
}
104
105
)
105
106
107
+ var versionOfGitSourceByAppProxyRefactor = semver .MustParse ("0.0.319" )
108
+
106
109
func NewGitSourceCommand () * cobra.Command {
107
110
cmd := & cobra.Command {
108
111
Use : "git-source" ,
@@ -205,37 +208,57 @@ func NewGitSourceCreateCommand() *cobra.Command {
205
208
}
206
209
207
210
func RunGitSourceCreate (ctx context.Context , opts * GitSourceCreateOptions ) error {
208
- // upsert git-source repo
209
-
210
- gsRepo , gsFs , err := opts .GsCloneOpts .GetRepo (ctx )
211
+ version , err := getRuntimeVersion (ctx , opts .RuntimeName )
211
212
if err != nil {
212
- return fmt . Errorf ( "failed to clone git-source repo: %w" , err )
213
+ return err
213
214
}
214
215
215
- if opts .CreateDemoResources {
216
- if err := createDemoResources (ctx , opts , gsRepo , gsFs ); err != nil {
217
- return fmt .Errorf ("failed to create git-source demo resources: %w" , err )
216
+ if version .LessThan (versionOfGitSourceByAppProxyRefactor ) {
217
+
218
+ 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 )
219
+ // upsert git-source repo
220
+ gsRepo , gsFs , err := opts .GsCloneOpts .GetRepo (ctx )
221
+ if err != nil {
222
+ return fmt .Errorf ("failed to clone git-source repo: %w" , err )
218
223
}
219
- } else {
220
- if err := createPlaceholderIfNeeded (ctx , opts , gsRepo , gsFs ); err != nil {
221
- return fmt .Errorf ("failed to create a git-source placeholder: %w" , err )
224
+
225
+ if opts .CreateDemoResources {
226
+ if err := createDemoResources (ctx , opts , gsRepo , gsFs ); err != nil {
227
+ return fmt .Errorf ("failed to create git-source demo resources: %w" , err )
228
+ }
229
+ } else {
230
+ if err := createPlaceholderIfNeeded (ctx , opts , gsRepo , gsFs ); err != nil {
231
+ return fmt .Errorf ("failed to create a git-source placeholder: %w" , err )
232
+ }
222
233
}
223
- }
224
234
225
- appDef := & runtime.AppDef {
226
- Name : opts .GsName ,
227
- Type : application .AppTypeDirectory ,
228
- URL : opts .GsCloneOpts .Repo ,
229
- }
235
+ appDef := & runtime.AppDef {
236
+ Name : opts .GsName ,
237
+ Type : application .AppTypeDirectory ,
238
+ URL : opts .GsCloneOpts .Repo ,
239
+ }
240
+
241
+ appDef .IsInternal = util .StringIndexOf (store .Get ().CFInternalGitSources , appDef .Name ) > - 1
242
+
243
+ if err := appDef .CreateApp (ctx , nil , opts .InsCloneOpts , opts .RuntimeName , store .Get ().CFGitSourceType , opts .Include , "" ); err != nil {
244
+ return fmt .Errorf ("failed to create git-source application. Err: %w" , err )
245
+ }
246
+ } else {
247
+ appProxy , err := cfConfig .NewClient ().AppProxy (ctx , opts .RuntimeName , store .Get ().InsecureIngressHost )
248
+ if err != nil {
249
+ return err
250
+ }
230
251
231
- appDef .IsInternal = util .StringIndexOf (store .Get ().CFInternalGitSources , appDef .Name ) > - 1
252
+ appSpecifier := opts .GsCloneOpts .Repo
253
+ isInternal := util .StringIndexOf (store .Get ().CFInternalGitSources , opts .GsName ) > - 1
232
254
233
- if err := appDef .CreateApp (ctx , nil , opts .InsCloneOpts , opts .RuntimeName , store .Get ().CFGitSourceType , opts .Include , "" ); err != nil {
234
- return fmt .Errorf ("failed to create git-source application. Err: %w" , err )
255
+ err = appProxy .AppProxyGitSources ().Create (ctx , opts .GsName , appSpecifier , opts .RuntimeName , opts .RuntimeName , isInternal )
256
+ if err != nil {
257
+ return fmt .Errorf ("failed to create git-source: %w" , err )
258
+ }
235
259
}
236
260
237
261
log .G (ctx ).Infof ("Successfully created git-source: \" %s\" " , opts .GsName )
238
-
239
262
return nil
240
263
}
241
264
@@ -368,7 +391,7 @@ func createCronExampleEventSource() *eventsourcev1alpha1.EventSource {
368
391
Name : store .Get ().CronExampleEventSourceName ,
369
392
},
370
393
Spec : eventsourcev1alpha1.EventSourceSpec {
371
- Template : tpl ,
394
+ Template : tpl ,
372
395
EventBusName : store .Get ().EventBusName ,
373
396
Calendar : map [string ]eventsourcev1alpha1.CalendarEventSource {
374
397
store .Get ().CronExampleEventName : {
@@ -390,7 +413,7 @@ func createCronExampleSensor(triggers []sensorsv1alpha1.Trigger) (*sensorsv1alph
390
413
391
414
tpl := & sensorsv1alpha1.Template {
392
415
ServiceAccountName : "argo-server" ,
393
- Container : & corev1.Container {},
416
+ Container : & corev1.Container {},
394
417
}
395
418
396
419
if store .Get ().SetDefaultResources {
@@ -407,7 +430,7 @@ func createCronExampleSensor(triggers []sensorsv1alpha1.Trigger) (*sensorsv1alph
407
430
},
408
431
Spec : sensorsv1alpha1.SensorSpec {
409
432
EventBusName : "codefresh-eventbus" ,
410
- Template : tpl ,
433
+ Template : tpl ,
411
434
Dependencies : dependencies ,
412
435
Triggers : triggers ,
413
436
},
@@ -580,19 +603,36 @@ func NewGitSourceDeleteCommand() *cobra.Command {
580
603
}
581
604
582
605
func RunGitSourceDelete (ctx context.Context , opts * GitSourceDeleteOptions ) error {
583
- err := apcmd .RunAppDelete (ctx , & apcmd.AppDeleteOptions {
584
- CloneOpts : opts .InsCloneOpts ,
585
- ProjectName : opts .RuntimeName ,
586
- AppName : opts .GsName ,
587
- Global : false ,
588
- })
589
-
606
+ version , err := getRuntimeVersion (ctx , opts .RuntimeName )
590
607
if err != nil {
591
- return fmt . Errorf ( "failed to delete the git-source %s. Err: %w" , opts . GsName , err )
608
+ return err
592
609
}
593
610
594
- log .G (ctx ).Infof ("Successfully deleted the git-source: %s" , opts .GsName )
611
+ if version .LessThan (versionOfGitSourceByAppProxyRefactor ) {
612
+ 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 )
613
+ err = apcmd .RunAppDelete (ctx , & apcmd.AppDeleteOptions {
614
+ CloneOpts : opts .InsCloneOpts ,
615
+ ProjectName : opts .RuntimeName ,
616
+ AppName : opts .GsName ,
617
+ Global : false ,
618
+ })
619
+
620
+ if err != nil {
621
+ return fmt .Errorf ("failed to delete the git-source %s. Err: %w" , opts .GsName , err )
622
+ }
623
+ } else {
624
+ appProxy , err := cfConfig .NewClient ().AppProxy (ctx , opts .RuntimeName , store .Get ().InsecureIngressHost )
625
+ if err != nil {
626
+ return err
627
+ }
628
+
629
+ err = appProxy .AppProxyGitSources ().Delete (ctx , opts .GsName )
630
+ if err != nil {
631
+ return fmt .Errorf ("failed to delete git-source: %w" , err )
632
+ }
633
+ }
595
634
635
+ log .G (ctx ).Infof ("Successfully deleted the git-source: %s" , opts .GsName )
596
636
return nil
597
637
}
598
638
@@ -662,29 +702,53 @@ func NewGitSourceEditCommand() *cobra.Command {
662
702
func RunGitSourceEdit (ctx context.Context , opts * GitSourceEditOptions ) error {
663
703
repo , fs , err := opts .InsCloneOpts .GetRepo (ctx )
664
704
if err != nil {
665
- return fmt . Errorf ( "failed to clone the installation repo, attemptint to edit git-source %s. Err: %w" , opts . GsName , err )
705
+ return err
666
706
}
667
- c := & dirConfig {}
668
- fileName := fs .Join (apstore .Default .AppsDir , opts .GsName , opts .RuntimeName , "config_dir.json" )
669
- err = fs .ReadJson (fileName , c )
707
+
708
+ version , err := getRuntimeVersion (ctx , opts .RuntimeName )
670
709
if err != nil {
671
- return fmt . Errorf ( "failed to read the %s of git-source: %s. Err: %w" , fileName , opts . GsName , err )
710
+ return err
672
711
}
673
712
674
- c .Config .SrcPath = opts .GsCloneOpts .Path ()
675
- c .Config .SrcRepoURL = opts .GsCloneOpts .URL ()
676
- c .Config .SrcTargetRevision = opts .GsCloneOpts .Revision ()
713
+ if version .LessThan (versionOfGitSourceByAppProxyRefactor ) {
714
+ 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 )
677
715
678
- err = fs .WriteJson (fileName , c )
679
- if err != nil {
680
- return fmt .Errorf ("failed to write the updated %s of git-source: %s. Err: %w" , fileName , opts .GsName , err )
681
- }
716
+ if err != nil {
717
+ return fmt .Errorf ("failed to clone the installation repo, attemptint to edit git-source %s. Err: %w" , opts .GsName , err )
718
+ }
719
+ c := & dirConfig {}
720
+ fileName := fs .Join (apstore .Default .AppsDir , opts .GsName , opts .RuntimeName , "config_dir.json" )
721
+ err = fs .ReadJson (fileName , c )
722
+ if err != nil {
723
+ return fmt .Errorf ("failed to read the %s of git-source: %s. Err: %w" , fileName , opts .GsName , err )
724
+ }
725
+
726
+ c .Config .SrcPath = opts .GsCloneOpts .Path ()
727
+ c .Config .SrcRepoURL = opts .GsCloneOpts .URL ()
728
+ c .Config .SrcTargetRevision = opts .GsCloneOpts .Revision ()
729
+
730
+ err = fs .WriteJson (fileName , c )
731
+ if err != nil {
732
+ return fmt .Errorf ("failed to write the updated %s of git-source: %s. Err: %w" , fileName , opts .GsName , err )
733
+ }
682
734
683
- log .G (ctx ).Info ("Pushing updated GitSource to the installation repo" )
684
- if err := apu .PushWithMessage (ctx , repo , fmt .Sprintf ("Persisted an updated git-source \" %s\" " , opts .GsName )); err != nil {
685
- return fmt .Errorf ("failed to persist the updated git-source: %s. Err: %w" , opts .GsName , err )
735
+ log .G (ctx ).Info ("Pushing updated GitSource to the installation repo" )
736
+ if err := apu .PushWithMessage (ctx , repo , fmt .Sprintf ("Persisted an updated git-source \" %s\" " , opts .GsName )); err != nil {
737
+ return fmt .Errorf ("failed to persist the updated git-source: %s. Err: %w" , opts .GsName , err )
738
+ }
739
+ } else {
740
+ appProxy , err := cfConfig .NewClient ().AppProxy (ctx , opts .RuntimeName , store .Get ().InsecureIngressHost )
741
+ if err != nil {
742
+ return err
743
+ }
744
+
745
+ err = appProxy .AppProxyGitSources ().Edit (ctx , opts .GsName , opts .GsCloneOpts .Repo )
746
+ if err != nil {
747
+ return fmt .Errorf ("failed to edit git-source: %w" , err )
748
+ }
686
749
}
687
750
751
+ log .G (ctx ).Infof ("Successfully created git-source: \" %s\" " , opts .GsName )
688
752
return nil
689
753
}
690
754
@@ -845,7 +909,7 @@ func createGithubExampleEventSource(repoURL string, ingressHost string, runtimeN
845
909
},
846
910
Spec : eventsourcev1alpha1.EventSourceSpec {
847
911
EventBusName : store .Get ().EventBusName ,
848
- Template : tpl ,
912
+ Template : tpl ,
849
913
Service : & eventsourcev1alpha1.Service {
850
914
Ports : []corev1.ServicePort {
851
915
{
@@ -959,7 +1023,7 @@ func createGithubExampleSensor() *sensorsv1alpha1.Sensor {
959
1023
}
960
1024
961
1025
tpl := & sensorsv1alpha1.Template {
962
- Container : & corev1.Container {},
1026
+ Container : & corev1.Container {},
963
1027
ServiceAccountName : store .Get ().WorkflowTriggerServiceAccount ,
964
1028
}
965
1029
@@ -977,7 +1041,7 @@ func createGithubExampleSensor() *sensorsv1alpha1.Sensor {
977
1041
},
978
1042
Spec : sensorsv1alpha1.SensorSpec {
979
1043
EventBusName : store .Get ().EventBusName ,
980
- Template : tpl ,
1044
+ Template : tpl ,
981
1045
Dependencies : dependencies ,
982
1046
Triggers : triggers ,
983
1047
},
@@ -1157,3 +1221,16 @@ func unMarshalCustomObject(obj interface{}) (map[string]interface{}, error) {
1157
1221
}
1158
1222
return crd , nil
1159
1223
}
1224
+
1225
+ func getRuntimeVersion (ctx context.Context , runtimeName string ) (* semver.Version , error ) {
1226
+ rt , err := cfConfig .NewClient ().V2 ().Runtime ().Get (ctx , runtimeName )
1227
+ if err != nil {
1228
+ return nil , err
1229
+ }
1230
+
1231
+ if rt .RuntimeVersion == nil {
1232
+ return nil , fmt .Errorf ("runtime \" %s\" has no version" , runtimeName )
1233
+ }
1234
+
1235
+ return semver .MustParse (* rt .RuntimeVersion ), nil
1236
+ }
0 commit comments