Skip to content

Commit 408d6b2

Browse files
authored
CR-6135 - workflows ingress (#75)
* add resources and patches for workflows ingress
1 parent 5dddc4a commit 408d6b2

File tree

14 files changed

+329
-72
lines changed

14 files changed

+329
-72
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.78
1+
VERSION=v0.0.79
22
OUT_DIR=dist
33
YEAR?=$(shell date +"%Y")
44

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/spec/template/spec/containers/0/env",
5+
"value": [
6+
{
7+
"name": "BASE_HREF",
8+
"value": "/workflows/"
9+
}
10+
]
11+
}
12+
]

cmd/commands/common.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package commands
1616

1717
import (
18+
_ "embed"
1819
"os"
1920
"regexp"
2021

@@ -30,6 +31,9 @@ var (
3031
die = util.Die
3132
exit = os.Exit
3233

34+
//go:embed assets/ingress-patch.json
35+
ingressPatch []byte
36+
3337
cfConfig *config.Config
3438
)
3539

cmd/commands/git-source.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
165165
}
166166

167167
if len(fi) == 0 {
168-
if err = createDemoWorkflowTemplate(gsFs, opts.gsName, opts.runtimeName); err != nil {
168+
if err = createDemoWorkflowTemplate(gsFs, opts.runtimeName); err != nil {
169169
return fmt.Errorf("failed to create demo workflowTemplate: %w", err)
170170
}
171171

@@ -183,7 +183,7 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
183183
Type: application.AppTypeDirectory,
184184
URL: opts.gsCloneOpts.Repo,
185185
}
186-
if err := appDef.CreateApp(ctx, nil, opts.insCloneOpts, opts.runtimeName, store.Get().CFGitSourceType, nil); err != nil {
186+
if err := appDef.CreateApp(ctx, nil, opts.insCloneOpts, opts.runtimeName, store.Get().CFGitSourceType); err != nil {
187187
return fmt.Errorf("failed to create git-source application. Err: %w", err)
188188
}
189189

@@ -402,7 +402,7 @@ func RunGitSourceEdit(ctx context.Context, opts *GitSourceEditOptions) error {
402402
return nil
403403
}
404404

405-
func createDemoWorkflowTemplate(gsFs fs.FS, gsName, runtimeName string) error {
405+
func createDemoWorkflowTemplate(gsFs fs.FS, runtimeName string) error {
406406
wfTemplate := &wfv1alpha1.WorkflowTemplate{
407407
TypeMeta: metav1.TypeMeta{
408408
Kind: wf.WorkflowTemplateKind,

cmd/commands/runtime.go

Lines changed: 89 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5260
type (
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

98107
func 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+
642716
func 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
},

docs/commands/cli-v2_runtime_install.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ cli-v2 runtime install [runtime_name] [flags]
3333
--git-src-repo string Repository URL [GIT_SRC_GIT_REPO]
3434
-t, --git-token string Your git provider api token [GIT_TOKEN]
3535
-h, --help help for install
36+
--ingress-host string The ingress host
3637
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
3738
-n, --namespace string If present, the namespace scope for this CLI request
3839
--provider string The git provider, one of: gitea|github

docs/releases/release_notes.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* Argo CD [v2.1.0-rc2](https://github.com/codefresh-io/argo-cd/releases/tag/v2.1.0-rc2)
33
* Argo CD ApplicationSet Controller [2c62537a8e5a](https://github.com/argoproj-labs/applicationset/commit/2c62537a8e5a3d5aecad87b843870789b74bdf89)
44
* Argo Events [v1.4.0](https://github.com/argoproj/argo-events/releases/tag/v1.4.0)
5-
* Argo Rollouts [v1.0.4](https://github.com/argoproj/argo-rollouts/releases/tag/v1.0.4)
6-
* Argo Workflows [v3.1.6](https://github.com/argoproj/argo-workflows/releases/tag/v3.1.6)
5+
* Argo Rollouts [v1.0.5](https://github.com/argoproj/argo-rollouts/releases/tag/v1.0.5)
6+
* Argo Workflows [v3.1.8](https://github.com/argoproj/argo-workflows/releases/tag/v3.1.8)
77

88
### Using brew:
99
```bash
@@ -20,7 +20,7 @@ cf version
2020
### Linux
2121
```bash
2222
# download and extract the binary
23-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.78/cf-linux-amd64.tar.gz | tar zx
23+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.79/cf-linux-amd64.tar.gz | tar zx
2424

2525
# move the binary to your $PATH
2626
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -32,7 +32,7 @@ cf version
3232
### Mac
3333
```bash
3434
# download and extract the binary
35-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.78/cf-darwin-amd64.tar.gz | tar zx
35+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.79/cf-darwin-amd64.tar.gz | tar zx
3636

3737
# move the binary to your $PATH
3838
mv ./cf-darwin-amd64 /usr/local/bin/cf

manifests/argo-rollouts/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
33
resources:
4-
- https://github.com/argoproj/argo-rollouts/releases/download/v1.0.4/install.yaml
4+
- https://github.com/argoproj/argo-rollouts/releases/download/v1.0.5/install.yaml
55
patches:
66
- target:
77
group: apiextensions.k8s.io

manifests/argo-workflows/kustomization.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
33
resources:
4-
- https://github.com/argoproj/argo-workflows/releases/download/v3.1.6/install.yaml
4+
- https://github.com/argoproj/argo-workflows/releases/download/v3.1.8/install.yaml
55

66
patches:
77
# reset the crbs to `subject.namespace: default`, so that argo-workflows will later change them to the actual ns
@@ -13,3 +13,13 @@ patches:
1313
- op: replace
1414
path: /subjects/0/namespace
1515
value: default
16+
17+
- target:
18+
group: apps
19+
version: v1
20+
kind: Deployment
21+
name: argo-server
22+
patch: |-
23+
- op: add
24+
path: /spec/template/spec/containers/0/args/-
25+
value: --auth-mode=server

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.0
8-
version: 0.0.75
8+
version: 0.0.79
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

0 commit comments

Comments
 (0)