@@ -27,9 +27,10 @@ import (
27
27
"github.com/codefresh-io/cli-v2/pkg/util"
28
28
cdutil "github.com/codefresh-io/cli-v2/pkg/util/cd"
29
29
eventsutil "github.com/codefresh-io/cli-v2/pkg/util/events"
30
+ ingressutil "github.com/codefresh-io/cli-v2/pkg/util/ingress"
31
+ kustutil "github.com/codefresh-io/cli-v2/pkg/util/kust"
30
32
"github.com/codefresh-io/go-sdk/pkg/codefresh/model"
31
33
32
- "github.com/Masterminds/semver/v3"
33
34
appset "github.com/argoproj-labs/applicationset/api/v1alpha1"
34
35
apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands"
35
36
"github.com/argoproj-labs/argocd-autopilot/pkg/application"
@@ -39,20 +40,28 @@ import (
39
40
apstore "github.com/argoproj-labs/argocd-autopilot/pkg/store"
40
41
aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
41
42
argocdv1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
43
+ argowf "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow"
44
+
45
+ "github.com/Masterminds/semver/v3"
42
46
"github.com/ghodss/yaml"
43
47
"github.com/go-git/go-billy/v5/memfs"
48
+ billyUtils "github.com/go-git/go-billy/v5/util"
44
49
"github.com/juju/ansiterm"
45
50
"github.com/spf13/cobra"
51
+ appsv1 "k8s.io/api/apps/v1"
46
52
v1 "k8s.io/api/core/v1"
47
53
rbacv1 "k8s.io/api/rbac/v1"
48
54
kerrors "k8s.io/apimachinery/pkg/api/errors"
49
55
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
56
+ kustid "sigs.k8s.io/kustomize/api/resid"
57
+ kusttypes "sigs.k8s.io/kustomize/api/types"
50
58
)
51
59
52
60
type (
53
61
RuntimeInstallOptions struct {
54
62
RuntimeName string
55
63
RuntimeToken string
64
+ IngressHost string
56
65
Insecure bool
57
66
Version * semver.Version
58
67
gsCloneOpts * git.CloneOptions
@@ -97,6 +106,7 @@ func NewRuntimeCommand() *cobra.Command {
97
106
98
107
func NewRuntimeInstallCommand () * cobra.Command {
99
108
var (
109
+ ingressHost string
100
110
versionStr string
101
111
f kube.Factory
102
112
insCloneOpts * git.CloneOptions
@@ -161,6 +171,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
161
171
162
172
return RunRuntimeInstall (ctx , & RuntimeInstallOptions {
163
173
RuntimeName : args [0 ],
174
+ IngressHost : ingressHost ,
164
175
Version : version ,
165
176
Insecure : true ,
166
177
gsCloneOpts : gsCloneOpts ,
@@ -173,6 +184,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
173
184
},
174
185
}
175
186
187
+ cmd .Flags ().StringVar (& ingressHost , "ingress-host" , "" , "The ingress host" )
176
188
cmd .Flags ().StringVar (& versionStr , "version" , "" , "The runtime version to install, defaults to latest" )
177
189
cmd .Flags ().DurationVar (& store .Get ().WaitTimeout , "wait-timeout" , store .Get ().WaitTimeout , "How long to wait for the runtime components to be ready" )
178
190
@@ -207,12 +219,13 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
207
219
}
208
220
209
221
opts .RuntimeToken = runtimeCreationResponse .NewAccessToken
210
-
211
222
server , err := util .CurrentServer ()
212
223
if err != nil {
213
224
return fmt .Errorf ("failed to get current server address: %w" , err )
214
225
}
226
+
215
227
rt .Spec .Cluster = server
228
+ rt .Spec .IngressHost = opts .IngressHost
216
229
217
230
log .G (ctx ).WithField ("version" , rt .Spec .Version ).Infof ("installing runtime '%s'" , opts .RuntimeName )
218
231
err = apcmd .RunRepoBootstrap (ctx , & apcmd.RepoBootstrapOptions {
@@ -248,11 +261,17 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
248
261
249
262
for _ , component := range rt .Spec .Components {
250
263
log .G (ctx ).Infof ("creating component '%s'" , component .Name )
251
- if err = component .CreateApp (ctx , opts .KubeFactory , opts .insCloneOpts , opts .RuntimeName , store .Get ().CFComponentType , rt . Spec . Version ); err != nil {
264
+ if err = component .CreateApp (ctx , opts .KubeFactory , opts .insCloneOpts , opts .RuntimeName , store .Get ().CFComponentType ); err != nil {
252
265
return fmt .Errorf ("failed to create '%s' application: %w" , component .Name , err )
253
266
}
254
267
}
255
268
269
+ if opts .IngressHost != "" {
270
+ if err = createWorkflowsIngress (ctx , opts .insCloneOpts , rt ); err != nil {
271
+ return fmt .Errorf ("failed to patch Argo-Workflows ingress: %w" , err )
272
+ }
273
+ }
274
+
256
275
if err = createEventsReporter (ctx , opts .insCloneOpts , opts , rt ); err != nil {
257
276
return fmt .Errorf ("failed to create events-reporter: %w" , err )
258
277
}
@@ -615,7 +634,7 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
615
634
616
635
for _ , component := range newComponents {
617
636
log .G (ctx ).Infof ("Creating app '%s'" , component .Name )
618
- if err = component .CreateApp (ctx , nil , opts .CloneOpts , opts .RuntimeName , store .Get ().CFComponentType , newRt . Spec . Version ); err != nil {
637
+ if err = component .CreateApp (ctx , nil , opts .CloneOpts , opts .RuntimeName , store .Get ().CFComponentType ); err != nil {
619
638
return fmt .Errorf ("failed to create '%s' application: %w" , component .Name , err )
620
639
}
621
640
}
@@ -629,7 +648,11 @@ func persistRuntime(ctx context.Context, cloneOpts *git.CloneOptions, rt *runtim
629
648
return err
630
649
}
631
650
632
- if err = rt .Save (fs , fs .Join (apstore .Default .BootsrtrapDir , store .Get ().RuntimeFilename ), rtConf ); err != nil {
651
+ if err = rt .Save (fs , fs .Join (apstore .Default .BootsrtrapDir , rt .Name + ".yaml" ), rtConf ); err != nil {
652
+ return err
653
+ }
654
+
655
+ if err := updateProject (fs , rt ); err != nil {
633
656
return err
634
657
}
635
658
@@ -639,6 +662,57 @@ func persistRuntime(ctx context.Context, cloneOpts *git.CloneOptions, rt *runtim
639
662
return err
640
663
}
641
664
665
+ func createWorkflowsIngress (ctx context.Context , cloneOpts * git.CloneOptions , rt * runtime.Runtime ) error {
666
+ r , fs , err := cloneOpts .GetRepo (ctx )
667
+ if err != nil {
668
+ return err
669
+ }
670
+
671
+ overlaysDir := fs .Join (apstore .Default .AppsDir , "workflows" , apstore .Default .OverlaysDir , rt .Name )
672
+ ingress := ingressutil .CreateIngress (& ingressutil.CreateIngressOptions {
673
+ Name : rt .Name + store .Get ().IngressName ,
674
+ Namespace : rt .Namespace ,
675
+ Path : store .Get ().IngressPath ,
676
+ ServiceName : store .Get ().ArgoWFServiceName ,
677
+ ServicePort : store .Get ().ArgoWFServicePort ,
678
+ })
679
+ if err = fs .WriteYamls (fs .Join (overlaysDir , "ingress.yaml" ), ingress ); err != nil {
680
+ return err
681
+ }
682
+
683
+ if err = billyUtils .WriteFile (fs , fs .Join (overlaysDir , "ingress-patch.json" ), ingressPatch , 0666 ); err != nil {
684
+ return err
685
+ }
686
+
687
+ kust , err := kustutil .ReadKustomization (fs , overlaysDir )
688
+ if err != nil {
689
+ return err
690
+ }
691
+
692
+ kust .Resources = append (kust .Resources , "ingress.yaml" )
693
+ kust .Patches = append (kust .Patches , kusttypes.Patch {
694
+ Target : & kusttypes.Selector {
695
+ KrmId : kusttypes.KrmId {
696
+ Gvk : kustid.Gvk {
697
+ Group : appsv1 .SchemeGroupVersion .Group ,
698
+ Version : appsv1 .SchemeGroupVersion .Version ,
699
+ Kind : "Deployment" ,
700
+ },
701
+ Name : store .Get ().ArgoWFServiceName ,
702
+ },
703
+ },
704
+ Path : "ingress-patch.json" ,
705
+ })
706
+ if err = kustutil .WriteKustomization (fs , kust , overlaysDir ); err != nil {
707
+ return err
708
+ }
709
+
710
+ _ , err = r .Persist (ctx , & git.PushOptions {
711
+ CommitMsg : "Created Workflows Ingress" ,
712
+ })
713
+ return err
714
+ }
715
+
642
716
func createEventsReporter (ctx context.Context , cloneOpts * git.CloneOptions , opts * RuntimeInstallOptions , rt * runtime.Runtime ) error {
643
717
runtimeTokenSecret , err := getRuntimeTokenSecret (opts .RuntimeName , opts .RuntimeToken )
644
718
if err != nil {
@@ -660,7 +734,7 @@ func createEventsReporter(ctx context.Context, cloneOpts *git.CloneOptions, opts
660
734
Type : application .AppTypeDirectory ,
661
735
URL : cloneOpts .URL () + "/" + resPath ,
662
736
}
663
- if err := appDef .CreateApp (ctx , opts .KubeFactory , cloneOpts , opts .RuntimeName , store .Get ().CFComponentType , nil ); err != nil {
737
+ if err := appDef .CreateApp (ctx , opts .KubeFactory , cloneOpts , opts .RuntimeName , store .Get ().CFComponentType ); err != nil {
664
738
return err
665
739
}
666
740
@@ -669,10 +743,6 @@ func createEventsReporter(ctx context.Context, cloneOpts *git.CloneOptions, opts
669
743
return err
670
744
}
671
745
672
- if err := updateProject (repofs , opts .RuntimeName , rt ); err != nil {
673
- return err
674
- }
675
-
676
746
if err := createEventsReporterEventSource (repofs , resPath , opts .RuntimeName , opts .Insecure ); err != nil {
677
747
return err
678
748
}
@@ -694,7 +764,7 @@ func createWorkflowReporter(ctx context.Context, cloneOpts *git.CloneOptions, op
694
764
Type : application .AppTypeDirectory ,
695
765
URL : cloneOpts .URL () + "/" + resPath ,
696
766
}
697
- if err := appDef .CreateApp (ctx , opts .KubeFactory , cloneOpts , opts .RuntimeName , store .Get ().CFComponentType , opts . Version ); err != nil {
767
+ if err := appDef .CreateApp (ctx , opts .KubeFactory , cloneOpts , opts .RuntimeName , store .Get ().CFComponentType ); err != nil {
698
768
return err
699
769
}
700
770
@@ -721,8 +791,8 @@ func createWorkflowReporter(ctx context.Context, cloneOpts *git.CloneOptions, op
721
791
return err
722
792
}
723
793
724
- func updateProject (repofs fs.FS , runtimeName string , rt * runtime.Runtime ) error {
725
- projPath := repofs .Join (apstore .Default .ProjectsDir , runtimeName + ".yaml" )
794
+ func updateProject (repofs fs.FS , rt * runtime.Runtime ) error {
795
+ projPath := repofs .Join (apstore .Default .ProjectsDir , rt . Name + ".yaml" )
726
796
project , appset , err := getProjectInfoFromFile (repofs , projPath )
727
797
if err != nil {
728
798
return err
@@ -739,6 +809,9 @@ func updateProject(repofs fs.FS, runtimeName string, rt *runtime.Runtime) error
739
809
740
810
project .ObjectMeta .Labels [store .Get ().LabelKeyCFType ] = store .Get ().CFRuntimeType
741
811
project .ObjectMeta .Labels [store .Get ().LabelKeyRuntimeVersion ] = runtimeVersion
812
+ if rt .Spec .IngressHost != "" {
813
+ project .ObjectMeta .Labels [store .Get ().LabelKeyIngressHost ] = rt .Spec .IngressHost
814
+ }
742
815
743
816
return repofs .WriteYamls (projPath , project , appset )
744
817
}
@@ -875,9 +948,9 @@ func createWorkflowReporterEventSource(repofs fs.FS, path, namespace string) err
875
948
EventBusName : store .Get ().EventBusName ,
876
949
Resource : map [string ]eventsutil.CreateResourceEventSourceOptions {
877
950
"workflows" : {
878
- Group : "argoproj.io" ,
879
- Version : "v1alpha1" ,
880
- Resource : "workflows" ,
951
+ Group : argowf . Group ,
952
+ Version : argowf . Version ,
953
+ Resource : argowf . WorkflowPlural ,
881
954
Namespace : namespace ,
882
955
},
883
956
},
0 commit comments