Skip to content

Commit 530924c

Browse files
authored
Merge pull request #260 from florkbr/fix-malformed-caddyfile
Fix malformed caddyfile
2 parents 2d1b82d + 046f09e commit 530924c

File tree

16 files changed

+97
-6
lines changed

16 files changed

+97
-6
lines changed

api/v1alpha1/frontendenvironment_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ type FrontendEnvironmentSpec struct {
118118
// Custom HTTP Headers
119119
// These populate an ENV var that is then added into the caddy config as a header block
120120
HTTPHeaders map[string]string `json:"httpHeaders,omitempty"`
121+
// OverwriteCaddyConfig determines if the operator should overwrite
122+
// frontend container Caddyfiles with a common core Caddyfile
123+
OverwriteCaddyConfig bool `json:"overwriteCaddyConfig,omitempty"`
121124

122125
DefaultReplicas *int32 `json:"defaultReplicas,omitempty" yaml:"defaultReplicas,omitempty"`
123126
// For the ChromeUI to render navigation bundles

config/crd/bases/cloud.redhat.com_frontendenvironments.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ spec:
141141
- disabled
142142
- mode
143143
type: object
144+
overwriteCaddyConfig:
145+
description: |-
146+
OverwriteCaddyConfig determines if the operator should overwrite
147+
frontend container Caddyfiles with a common core Caddyfile
148+
type: boolean
144149
requests:
145150
additionalProperties:
146151
anyOf:

controllers/frontend_controller_suite_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ var _ = ginkgo.Describe("Frontend controller with image", func() {
148148
Monitoring: &crd.MonitoringConfig{
149149
Mode: "app-interface",
150150
},
151-
GenerateNavJSON: true,
151+
GenerateNavJSON: true,
152+
OverwriteCaddyConfig: true,
152153
},
153154
}
154155
gomega.Expect(k8sClient.Create(ctx, frontendEnvironment)).Should(gomega.Succeed())

controllers/reconcile.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func populateContainerVolumeMounts(frontendEnvironment *crd.FrontendEnvironment,
116116
MountPath: "/opt/app-root/src/build/stable/operator-generated",
117117
})
118118

119-
if frontend.Name != "chrome" {
119+
if frontendEnvironment.Spec.OverwriteCaddyConfig && frontend.Name != "chrome" {
120120
volumeMounts = append(volumeMounts, v1.VolumeMount{
121121
Name: "caddy",
122122
MountPath: "/opt/app-root/src/Caddyfile",
@@ -479,6 +479,26 @@ func (r *FrontendReconciliation) populateEnvVars(d *apps.Deployment, frontendEnv
479479
})
480480
}
481481

482+
envVars = append(envVars, v1.EnvVar{
483+
Name: "APP_NAME",
484+
Value: r.Frontend.Name,
485+
})
486+
487+
envVars = append(envVars, v1.EnvVar{
488+
Name: "ROUTE_PATH",
489+
Value: "/apps/$(APP_NAME)",
490+
})
491+
492+
envVars = append(envVars, v1.EnvVar{
493+
Name: "BETA_ROUTE_PATH",
494+
Value: "/beta$(ROUTE_PATH)",
495+
})
496+
497+
envVars = append(envVars, v1.EnvVar{
498+
Name: "PREVIEW_ROUTE_PATH",
499+
Value: "/preview$(ROUTE_PATH)",
500+
})
501+
482502
d.Spec.Template.Spec.Containers[0].Env = envVars
483503
}
484504

controllers/templates/Caddyfile

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{$CADDY_TLS_MODE}
33
auto_https disable_redirects
44
servers {
5-
metrics
5+
metrics
66
}
77
}
88

@@ -17,16 +17,48 @@
1717

1818
# Handle main app route
1919
@app_match {
20-
path ${ROUTE_PATH}*
20+
path {$ROUTE_PATH}*
2121
}
2222
handle @app_match {
23-
uri strip_prefix ${ROUTE_PATH}
23+
uri strip_prefix {$ROUTE_PATH}
2424
file_server * {
25-
root /srv/${OUTPUT_DIR}
25+
root /opt/app-root/src/dist/stable
2626
browse
2727
}
2828
}
2929

30+
# Handle beta app route
31+
@beta_match {
32+
path {$BETA_ROUTE_PATH}*
33+
}
34+
handle @beta_match {
35+
uri strip_prefix {$BETA_ROUTE_PATH}
36+
file_server * {
37+
root /opt/app-root/src/dist/preview
38+
browse
39+
}
40+
}
41+
42+
# Handle preview app route
43+
@preview_match {
44+
path {$PREVIEW_ROUTE_PATH}*
45+
}
46+
handle @preview_match {
47+
uri strip_prefix {$PREVIEW_ROUTE_PATH}
48+
file_server * {
49+
root /opt/app-root/src/dist/preview
50+
browse
51+
}
52+
}
53+
54+
handle /beta/ {
55+
redir /beta/apps/chrome/index.html permanent
56+
}
57+
58+
handle /preview/ {
59+
redir /preview/apps/chrome/index.html permanent
60+
}
61+
3062
handle / {
3163
redir /apps/chrome/index.html permanent
3264
}

deploy.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ objects:
385385
- disabled
386386
- mode
387387
type: object
388+
overwriteCaddyConfig:
389+
description: 'OverwriteCaddyConfig determines if the operator should
390+
overwrite
391+
392+
frontend container Caddyfiles with a common core Caddyfile'
393+
type: boolean
388394
requests:
389395
additionalProperties:
390396
anyOf:

tests/e2e/bundles/01-create-resources.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ spec:
88
ssl: false
99
hostname: foo.redhat.com
1010
sso: https://sso.foo.redhat.com
11+
overwriteCaddyConfig: true
1112
---
1213
apiVersion: cloud.redhat.com/v1alpha1
1314
kind: Frontend

tests/e2e/cachebust-multiple-urls/01-create-resources.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ spec:
88
ssl: false
99
hostname: foo.redhat.com
1010
sso: https://sso.foo.redhat.com
11+
overwriteCaddyConfig: true
1112
enableAkamaiCacheBust: true
1213
akamaiCacheBustImage: "quay.io/rh_ee_addrew/hi_true_bye:add_alias"
1314
akamaiCacheBustURLs:

tests/e2e/cachebust/01-create-resources.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ spec:
88
ssl: false
99
hostname: foo.redhat.com
1010
sso: https://sso.foo.redhat.com
11+
overwriteCaddyConfig: true
1112
enableAkamaiCacheBust: true
1213
akamaiCacheBustImage: "quay.io/rh_ee_addrew/hi_true_bye:add_alias"
1314
akamaiCacheBustURL: "console.doesntexist.redhat.com"

tests/e2e/generate-bundles/01-create-resources.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ spec:
88
ssl: false
99
hostname: foo.redhat.com
1010
sso: https://sso.foo.redhat.com
11+
overwriteCaddyConfig: true
1112
bundles:
1213
- id: rhel
1314
title: Red Hat Enterprise Linux

tests/e2e/generate-search-index/01-create-resources.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ spec:
88
ssl: false
99
hostname: foo.redhat.com
1010
sso: https://sso.foo.redhat.com
11+
overwriteCaddyConfig: true
1112
---
1213
apiVersion: cloud.redhat.com/v1alpha1
1314
kind: Frontend

tests/e2e/generate-service-tiles/01-create-resources.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ spec:
88
ssl: false
99
hostname: foo.redhat.com
1010
sso: https://sso.foo.redhat.com
11+
overwriteCaddyConfig: true
1112
serviceCategories:
1213
- id: automation
1314
title: Automation

tests/e2e/generate-widget-registry/01-create-resources.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ spec:
88
ssl: false
99
hostname: foo.redhat.com
1010
sso: https://sso.foo.redhat.com
11+
overwriteCaddyConfig: true
1112
---
1213
apiVersion: cloud.redhat.com/v1alpha1
1314
kind: Frontend

tests/e2e/http_headers/02-assert.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ spec:
4141
X-Frame-Options Set
4242
X-XSS-Protection 1; mode=block;
4343
}
44+
- name: APP_NAME
45+
value: chrome
46+
- name: ROUTE_PATH
47+
value: /apps/$(APP_NAME)
48+
- name: BETA_ROUTE_PATH
49+
value: /beta$(ROUTE_PATH)
50+
- name: PREVIEW_ROUTE_PATH
51+
value: /preview$(ROUTE_PATH)
4452
ports:
4553
- name: web
4654
containerPort: 80

tests/e2e/replicas/01-create-resources.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ spec:
88
ssl: false
99
hostname: foo.redhat.com
1010
sso: https://sso.foo.redhat.com
11+
overwriteCaddyConfig: true
1112
---
1213
apiVersion: cloud.redhat.com/v1alpha1
1314
kind: Frontend

tests/e2e/ssl/02-assert.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ spec:
4747
value: https_port 8000
4848
- name: CADDY_TLS_CERT
4949
value: tls /opt/certs/tls.crt /opt/certs/tls.key
50+
- name: APP_NAME
51+
value: chrome
52+
- name: ROUTE_PATH
53+
value: /apps/$(APP_NAME)
54+
- name: BETA_ROUTE_PATH
55+
value: /beta$(ROUTE_PATH)
56+
- name: PREVIEW_ROUTE_PATH
57+
value: /preview$(ROUTE_PATH)
5058
volumeMounts:
5159
- name: config
5260
mountPath: /opt/app-root/src/build/stable/operator-generated

0 commit comments

Comments
 (0)