Skip to content

Commit 2702bfd

Browse files
Add app proxy (#145)
* app-proxy wip * app-proxy wip * added app-proxy * wip * bump
1 parent c811fa0 commit 2702bfd

File tree

14 files changed

+250
-38
lines changed

14 files changed

+250
-38
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.134
1+
VERSION=v0.0.135
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/common.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ var (
3838
die = util.Die
3939
exit = os.Exit
4040

41-
//go:embed assets/ingress-patch.json
42-
ingressPatch []byte
41+
//go:embed assets/workflows-ingress-patch.json
42+
workflowsIngressPatch []byte
4343

4444
cfConfig *config.Config
4545

46-
GREEN = "\033[32m"
47-
CYAN = "\033[36m"
48-
BOLD = "\033[1m"
49-
UNDERLINE = "\033[4m"
50-
COLOR_RESET = "\033[0m"
46+
GREEN = "\033[32m"
47+
CYAN = "\033[36m"
48+
BOLD = "\033[1m"
49+
UNDERLINE = "\033[4m"
50+
COLOR_RESET = "\033[0m"
5151
UNDERLINE_RESET = "\033[24m"
52-
BOLD_RESET = "\033[22m"
52+
BOLD_RESET = "\033[22m"
5353
)
5454

5555
func postInitCommands(commands []*cobra.Command) {
@@ -77,17 +77,17 @@ func IsValid(s string) (bool, error) {
7777
func askUserIfToInstallCodefreshSamples(cmd *cobra.Command, sampleInstall *bool) error {
7878
if !store.Get().Silent && !cmd.Flags().Changed("sample-install") {
7979
templates := &promptui.SelectTemplates{
80-
Selected: "{{ . | yellow }} ",
80+
Selected: "{{ . | yellow }} ",
8181
}
8282

8383
labelStr := fmt.Sprintf("%vInstall codefresh samples?%v", CYAN, COLOR_RESET)
8484

8585
prompt := promptui.Select{
86-
Label: labelStr,
87-
Items: []string {"Yes (default)", "No"},
86+
Label: labelStr,
87+
Items: []string{"Yes (default)", "No"},
8888
Templates: templates,
8989
}
90-
90+
9191
_, result, err := prompt.Run()
9292
if err != nil {
9393
return fmt.Errorf("Prompt error: %w", err)
@@ -112,8 +112,8 @@ func ensureRepo(cmd *cobra.Command, runtimeName string, cloneOpts *git.CloneOpti
112112
cloneOpts.Repo = *runtimeData.Repo
113113
die(cmd.Flags().Set("repo", *runtimeData.Repo))
114114
return nil
115-
}
116-
}
115+
}
116+
}
117117
if !store.Get().Silent {
118118
return getRepoFromUserInput(cmd, cloneOpts)
119119
}
@@ -151,7 +151,7 @@ func ensureRuntimeName(ctx context.Context, args []string, runtimeName *string)
151151

152152
func getRuntimeNameFromUserInput(runtimeName *string) error {
153153
runtimeNamePrompt := promptui.Prompt{
154-
Label: "Runtime name",
154+
Label: "Runtime name",
155155
Default: "codefresh",
156156
Pointer: promptui.PipeCursor,
157157
}
@@ -181,17 +181,17 @@ func getRuntimeNameFromUserSelect(ctx context.Context, runtimeName *string) erro
181181
}
182182

183183
templates := &promptui.SelectTemplates{
184-
Selected: "{{ . | yellow }} ",
184+
Selected: "{{ . | yellow }} ",
185185
}
186186

187187
labelStr := fmt.Sprintf("%vSelect runtime%v", CYAN, COLOR_RESET)
188188

189189
prompt := promptui.Select{
190-
Label: labelStr,
191-
Items: runtimeNames,
190+
Label: labelStr,
191+
Items: runtimeNames,
192192
Templates: templates,
193193
}
194-
194+
195195
_, result, err := prompt.Run()
196196
if err != nil {
197197
return fmt.Errorf("Prompt error: %w", err)
@@ -239,7 +239,7 @@ func getApprovalFromUser(ctx context.Context, finalParameters map[string]string,
239239

240240
func promptSummaryToUser(ctx context.Context, finalParameters map[string]string, description string) (bool, error) {
241241
templates := &promptui.SelectTemplates{
242-
Selected: "{{ . | yellow }} ",
242+
Selected: "{{ . | yellow }} ",
243243
}
244244
promptStr := fmt.Sprintf("%v%v%vSummary%v%v%v", GREEN, BOLD, UNDERLINE, COLOR_RESET, BOLD_RESET, UNDERLINE_RESET)
245245
labelStr := fmt.Sprintf("%vDo you wish to continue with %v?%v", CYAN, description, COLOR_RESET)
@@ -249,11 +249,11 @@ func promptSummaryToUser(ctx context.Context, finalParameters map[string]string,
249249
}
250250
log.G(ctx).Printf(promptStr)
251251
prompt := promptui.Select{
252-
Label: labelStr,
253-
Items: []string{"Yes", "No"},
252+
Label: labelStr,
253+
Items: []string{"Yes", "No"},
254254
Templates: templates,
255255
}
256-
256+
257257
_, result, err := prompt.Run()
258258
if err != nil {
259259
return false, fmt.Errorf("Prompt error: %w", err)
@@ -270,7 +270,7 @@ func verifyLatestVersion(ctx context.Context) error {
270270
if err != nil {
271271
return fmt.Errorf("failed getting latest cli release: %w", err)
272272
}
273-
273+
274274
latestVersionSemver := semver.MustParse(latestVersionString)
275275
currentVersion := store.Get().Version.Version
276276

cmd/commands/runtime.go

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ func NewRuntimeInstallCommand() *cobra.Command {
180180
}
181181

182182
finalParameters = map[string]string{
183-
"Runtime name": runtimeName,
184-
"Repository URL": insCloneOpts.Repo,
183+
"Runtime name": runtimeName,
184+
"Repository URL": insCloneOpts.Repo,
185185
"Installing sample resources": strconv.FormatBool(sampleInstall),
186186
}
187187

@@ -420,6 +420,10 @@ func installComponents(ctx context.Context, opts *RuntimeInstallOptions, rt *run
420420
}
421421
}
422422

423+
if err = configureAppProxy(ctx, opts, rt); err != nil {
424+
return fmt.Errorf("failed to patch App-Proxy ingress: %w", err)
425+
}
426+
423427
if err = createCodefreshArgoAgentReporter(ctx, opts.InsCloneOpts, opts, rt); err != nil {
424428
return fmt.Errorf("failed to create argocd-agent-reporter: %w", err)
425429
}
@@ -925,7 +929,7 @@ func createWorkflowsIngress(ctx context.Context, cloneOpts *git.CloneOptions, rt
925929

926930
overlaysDir := fs.Join(apstore.Default.AppsDir, "workflows", apstore.Default.OverlaysDir, rt.Name)
927931
ingress := ingressutil.CreateIngress(&ingressutil.CreateIngressOptions{
928-
Name: rt.Name + store.Get().IngressName,
932+
Name: rt.Name + store.Get().WorkflowsIngressName,
929933
Namespace: rt.Namespace,
930934
Annotations: map[string]string{
931935
"kubernetes.io/ingress.class": "nginx",
@@ -934,7 +938,7 @@ func createWorkflowsIngress(ctx context.Context, cloneOpts *git.CloneOptions, rt
934938
},
935939
Paths: []ingressutil.IngressPath{
936940
{
937-
Path: fmt.Sprintf("/%s(/|$)(.*)", store.Get().IngressPath),
941+
Path: fmt.Sprintf("/%s(/|$)(.*)", store.Get().WorkflowsIngressPath),
938942
PathType: netv1.PathTypePrefix,
939943
ServiceName: store.Get().ArgoWFServiceName,
940944
ServicePort: store.Get().ArgoWFServicePort,
@@ -945,7 +949,7 @@ func createWorkflowsIngress(ctx context.Context, cloneOpts *git.CloneOptions, rt
945949
return err
946950
}
947951

948-
if err = billyUtils.WriteFile(fs, fs.Join(overlaysDir, "ingress-patch.json"), ingressPatch, 0666); err != nil {
952+
if err = billyUtils.WriteFile(fs, fs.Join(overlaysDir, "ingress-patch.json"), workflowsIngressPatch, 0666); err != nil {
949953
return err
950954
}
951955

@@ -977,6 +981,64 @@ func createWorkflowsIngress(ctx context.Context, cloneOpts *git.CloneOptions, rt
977981
return apu.PushWithMessage(ctx, r, "Created Workflows Ingress")
978982
}
979983

984+
func configureAppProxy(ctx context.Context, opts *RuntimeInstallOptions, rt *runtime.Runtime) error {
985+
r, fs, err := opts.InsCloneOpts.GetRepo(ctx)
986+
if err != nil {
987+
return err
988+
}
989+
990+
overlaysDir := fs.Join(apstore.Default.AppsDir, "app-proxy", apstore.Default.OverlaysDir, rt.Name)
991+
992+
kust, err := kustutil.ReadKustomization(fs, overlaysDir)
993+
if err != nil {
994+
return err
995+
}
996+
997+
// configure codefresh host
998+
kust.ConfigMapGenerator = append(kust.ConfigMapGenerator, kusttypes.ConfigMapArgs{
999+
GeneratorArgs: kusttypes.GeneratorArgs{
1000+
Name: store.Get().AppProxyServiceName + "-cm",
1001+
Behavior: "merge",
1002+
KvPairSources: kusttypes.KvPairSources{
1003+
LiteralSources: []string{fmt.Sprintf("cfHost=%s", cfConfig.GetCurrentContext().URL)},
1004+
},
1005+
},
1006+
})
1007+
1008+
if opts.IngressHost != "" {
1009+
ingress := ingressutil.CreateIngress(&ingressutil.CreateIngressOptions{
1010+
Name: rt.Name + store.Get().AppProxyIngressName,
1011+
Namespace: rt.Namespace,
1012+
Annotations: map[string]string{
1013+
"kubernetes.io/ingress.class": "nginx",
1014+
"nginx.ingress.kubernetes.io/rewrite-target": "/$2",
1015+
"nginx.ingress.kubernetes.io/backend-protocol": "http",
1016+
},
1017+
Paths: []ingressutil.IngressPath{
1018+
{
1019+
Path: fmt.Sprintf("/%s(/|$)(.*)", store.Get().AppProxyIngressPath),
1020+
PathType: netv1.PathTypePrefix,
1021+
ServiceName: store.Get().AppProxyServiceName,
1022+
ServicePort: store.Get().AppProxyServicePort,
1023+
},
1024+
},
1025+
})
1026+
if err = fs.WriteYamls(fs.Join(overlaysDir, "ingress.yaml"), ingress); err != nil {
1027+
return err
1028+
}
1029+
1030+
kust.Resources = append(kust.Resources, "ingress.yaml")
1031+
}
1032+
1033+
if err = kustutil.WriteKustomization(fs, kust, overlaysDir); err != nil {
1034+
return err
1035+
}
1036+
1037+
log.G(ctx).Info("Pushing App-Proxy ingress manifests")
1038+
1039+
return apu.PushWithMessage(ctx, r, "Created App-Proxy Ingress")
1040+
}
1041+
9801042
func createEventsReporter(ctx context.Context, cloneOpts *git.CloneOptions, opts *RuntimeInstallOptions, rt *runtime.Runtime) error {
9811043
runtimeTokenSecret, err := getRuntimeTokenSecret(opts.RuntimeName, opts.RuntimeToken)
9821044
if err != nil {

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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.134/cf-linux-amd64.tar.gz | tar zx
23+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.135/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.134/cf-darwin-amd64.tar.gz | tar zx
35+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.135/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/app-proxy/app-proxy.cm.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: cap-app-proxy-cm
5+
data:
6+
apiPrefix: "/app-proxy"
7+
env: production
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
app: cap-app-proxy
6+
name: cap-app-proxy
7+
spec:
8+
selector:
9+
matchLabels:
10+
app: cap-app-proxy
11+
replicas: 1
12+
template:
13+
metadata:
14+
labels:
15+
app: cap-app-proxy
16+
spec:
17+
serviceAccountName: cap-app-proxy
18+
containers:
19+
- env:
20+
- name: API_PATH_PREFIX
21+
valueFrom:
22+
configMapKeyRef:
23+
name: cap-app-proxy-cm
24+
key: apiPrefix
25+
optional: true
26+
- name: CF_HOST
27+
valueFrom:
28+
configMapKeyRef:
29+
name: cap-app-proxy-cm
30+
key: cfHost
31+
optional: true
32+
- name: ENV
33+
valueFrom:
34+
configMapKeyRef:
35+
name: cap-app-proxy-cm
36+
key: env
37+
optional: true
38+
- name: RUNTIME_TOKEN
39+
valueFrom:
40+
secretKeyRef:
41+
name: codefresh-token
42+
key: token
43+
- name: NAMESPACE
44+
valueFrom:
45+
fieldRef:
46+
fieldPath: metadata.namespace
47+
- name: PORT
48+
value: "80"
49+
image: quay.io/codefresh/cap-app-proxy
50+
imagePullPolicy: Always
51+
name: cap-app-proxy
52+
livenessProbe:
53+
httpGet:
54+
port: http
55+
path: /api/ping
56+
readinessProbe:
57+
httpGet:
58+
port: http
59+
path: /api/ping
60+
ports:
61+
- name: http
62+
containerPort: 80
63+
resources:
64+
requests:
65+
memory: "256Mi"
66+
cpu: "0.5"
67+
limits:
68+
memory: "2048Mi"
69+
cpu: "2"

manifests/app-proxy/app-proxy.rb.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: RoleBinding
3+
metadata:
4+
labels:
5+
app: cap-app-proxy
6+
name: cap-app-proxy
7+
roleRef:
8+
apiGroup: rbac.authorization.k8s.io
9+
kind: Role
10+
name: cap-app-proxy
11+
subjects:
12+
- kind: ServiceAccount
13+
name: cap-app-proxy
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: Role
3+
metadata:
4+
labels:
5+
app: cap-app-proxy
6+
name: cap-app-proxy
7+
rules:
8+
- apiGroups:
9+
- ""
10+
resources:
11+
- secrets
12+
verbs:
13+
- get
14+
- create
15+
- delete
16+
- list
17+
- watch

manifests/app-proxy/app-proxy.sa.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
labels:
5+
app: cap-app-proxy
6+
name: cap-app-proxy

0 commit comments

Comments
 (0)