@@ -27,9 +27,10 @@ import (
2727 "github.com/codefresh-io/cli-v2/pkg/util"
2828 cdutil "github.com/codefresh-io/cli-v2/pkg/util/cd"
2929 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"
3032 "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
3133
32- "github.com/Masterminds/semver/v3"
3334 appset "github.com/argoproj-labs/applicationset/api/v1alpha1"
3435 apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands"
3536 "github.com/argoproj-labs/argocd-autopilot/pkg/application"
@@ -39,20 +40,28 @@ import (
3940 apstore "github.com/argoproj-labs/argocd-autopilot/pkg/store"
4041 aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
4142 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"
4246 "github.com/ghodss/yaml"
4347 "github.com/go-git/go-billy/v5/memfs"
48+ billyUtils "github.com/go-git/go-billy/v5/util"
4449 "github.com/juju/ansiterm"
4550 "github.com/spf13/cobra"
51+ appsv1 "k8s.io/api/apps/v1"
4652 v1 "k8s.io/api/core/v1"
4753 rbacv1 "k8s.io/api/rbac/v1"
4854 kerrors "k8s.io/apimachinery/pkg/api/errors"
4955 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
56+ kustid "sigs.k8s.io/kustomize/api/resid"
57+ kusttypes "sigs.k8s.io/kustomize/api/types"
5058)
5159
5260type (
5361 RuntimeInstallOptions struct {
5462 RuntimeName string
5563 RuntimeToken string
64+ IngressHost string
5665 Insecure bool
5766 Version * semver.Version
5867 gsCloneOpts * git.CloneOptions
@@ -97,6 +106,7 @@ func NewRuntimeCommand() *cobra.Command {
97106
98107func NewRuntimeInstallCommand () * cobra.Command {
99108 var (
109+ ingressHost string
100110 versionStr string
101111 f kube.Factory
102112 insCloneOpts * git.CloneOptions
@@ -161,6 +171,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
161171
162172 return RunRuntimeInstall (ctx , & RuntimeInstallOptions {
163173 RuntimeName : args [0 ],
174+ IngressHost : ingressHost ,
164175 Version : version ,
165176 Insecure : true ,
166177 gsCloneOpts : gsCloneOpts ,
@@ -173,6 +184,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
173184 },
174185 }
175186
187+ cmd .Flags ().StringVar (& ingressHost , "ingress-host" , "" , "The ingress host" )
176188 cmd .Flags ().StringVar (& versionStr , "version" , "" , "The runtime version to install, defaults to latest" )
177189 cmd .Flags ().DurationVar (& store .Get ().WaitTimeout , "wait-timeout" , store .Get ().WaitTimeout , "How long to wait for the runtime components to be ready" )
178190
@@ -207,12 +219,13 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
207219 }
208220
209221 opts .RuntimeToken = runtimeCreationResponse .NewAccessToken
210-
211222 server , err := util .CurrentServer ()
212223 if err != nil {
213224 return fmt .Errorf ("failed to get current server address: %w" , err )
214225 }
226+
215227 rt .Spec .Cluster = server
228+ rt .Spec .IngressHost = opts .IngressHost
216229
217230 log .G (ctx ).WithField ("version" , rt .Spec .Version ).Infof ("installing runtime '%s'" , opts .RuntimeName )
218231 err = apcmd .RunRepoBootstrap (ctx , & apcmd.RepoBootstrapOptions {
@@ -248,11 +261,17 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
248261
249262 for _ , component := range rt .Spec .Components {
250263 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 {
252265 return fmt .Errorf ("failed to create '%s' application: %w" , component .Name , err )
253266 }
254267 }
255268
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+
256275 if err = createEventsReporter (ctx , opts .insCloneOpts , opts , rt ); err != nil {
257276 return fmt .Errorf ("failed to create events-reporter: %w" , err )
258277 }
@@ -615,7 +634,7 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
615634
616635 for _ , component := range newComponents {
617636 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 {
619638 return fmt .Errorf ("failed to create '%s' application: %w" , component .Name , err )
620639 }
621640 }
@@ -629,7 +648,11 @@ func persistRuntime(ctx context.Context, cloneOpts *git.CloneOptions, rt *runtim
629648 return err
630649 }
631650
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 {
633656 return err
634657 }
635658
@@ -639,6 +662,57 @@ func persistRuntime(ctx context.Context, cloneOpts *git.CloneOptions, rt *runtim
639662 return err
640663}
641664
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+
642716func createEventsReporter (ctx context.Context , cloneOpts * git.CloneOptions , opts * RuntimeInstallOptions , rt * runtime.Runtime ) error {
643717 runtimeTokenSecret , err := getRuntimeTokenSecret (opts .RuntimeName , opts .RuntimeToken )
644718 if err != nil {
@@ -660,7 +734,7 @@ func createEventsReporter(ctx context.Context, cloneOpts *git.CloneOptions, opts
660734 Type : application .AppTypeDirectory ,
661735 URL : cloneOpts .URL () + "/" + resPath ,
662736 }
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 {
664738 return err
665739 }
666740
@@ -669,10 +743,6 @@ func createEventsReporter(ctx context.Context, cloneOpts *git.CloneOptions, opts
669743 return err
670744 }
671745
672- if err := updateProject (repofs , opts .RuntimeName , rt ); err != nil {
673- return err
674- }
675-
676746 if err := createEventsReporterEventSource (repofs , resPath , opts .RuntimeName , opts .Insecure ); err != nil {
677747 return err
678748 }
@@ -694,7 +764,7 @@ func createWorkflowReporter(ctx context.Context, cloneOpts *git.CloneOptions, op
694764 Type : application .AppTypeDirectory ,
695765 URL : cloneOpts .URL () + "/" + resPath ,
696766 }
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 {
698768 return err
699769 }
700770
@@ -721,8 +791,8 @@ func createWorkflowReporter(ctx context.Context, cloneOpts *git.CloneOptions, op
721791 return err
722792}
723793
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" )
726796 project , appset , err := getProjectInfoFromFile (repofs , projPath )
727797 if err != nil {
728798 return err
@@ -739,6 +809,9 @@ func updateProject(repofs fs.FS, runtimeName string, rt *runtime.Runtime) error
739809
740810 project .ObjectMeta .Labels [store .Get ().LabelKeyCFType ] = store .Get ().CFRuntimeType
741811 project .ObjectMeta .Labels [store .Get ().LabelKeyRuntimeVersion ] = runtimeVersion
812+ if rt .Spec .IngressHost != "" {
813+ project .ObjectMeta .Labels [store .Get ().LabelKeyIngressHost ] = rt .Spec .IngressHost
814+ }
742815
743816 return repofs .WriteYamls (projPath , project , appset )
744817}
@@ -875,9 +948,9 @@ func createWorkflowReporterEventSource(repofs fs.FS, path, namespace string) err
875948 EventBusName : store .Get ().EventBusName ,
876949 Resource : map [string ]eventsutil.CreateResourceEventSourceOptions {
877950 "workflows" : {
878- Group : "argoproj.io" ,
879- Version : "v1alpha1" ,
880- Resource : "workflows" ,
951+ Group : argowf . Group ,
952+ Version : argowf . Version ,
953+ Resource : argowf . WorkflowPlural ,
881954 Namespace : namespace ,
882955 },
883956 },
0 commit comments