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