Skip to content

Commit 5bdb13f

Browse files
committed
chore: fix ingress
1 parent e02efea commit 5bdb13f

8 files changed

Lines changed: 41 additions & 23 deletions

File tree

.github/workflows/deploy-production-ru.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ on:
2222
ru_test_host:
2323
description: "Temporary RU host for local testing without public DNS"
2424
required: true
25-
default: ru-test.werf.io
25+
default: ru.werf.io
2626
type: string
2727

2828
env:
@@ -32,7 +32,7 @@ env:
3232
WERF_STAGES_STORAGE: "ghcr.io/werf/werfio-guides-stages"
3333
WERF_SET_ACTIVE_RELEASE: "global.active_release=2"
3434
WERFIO_GITHUB_TOKEN: "${{ secrets.API_TOKEN }}"
35-
RU_TEST_HOST: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.ru_test_host || 'ru-test.werf.io' }}
35+
RU_TEST_HOST: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.ru_test_host || 'ru.werf.io' }}
3636

3737
jobs:
3838
converge-ru:
@@ -167,5 +167,6 @@ jobs:
167167
168168
169169
170+
170171
171172

.helm/templates/20-ingress-tuf-router.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ metadata:
1515
name: tuf-router
1616
annotations: {}
1717
spec:
18-
ingressClassName: {{ pluck .Values.werf.env .Values.ingressClassName | first | default .Values.ingressClassName._default }}
18+
ingressClassName: {{ include "ingressClassName" . }}
1919
{{- if or (ne .Values.werf.env "production") (ne $targetCluster "ru") $ruConfig.tlsEnabled }}
2020
tls:
2121
- hosts:

.helm/templates/20-ingress.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ metadata:
2323
{{- include "rewrites" . | indent 6 }}
2424
nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
2525
spec:
26-
ingressClassName: {{ pluck .Values.werf.env .Values.ingressClassName | first | default .Values.ingressClassName._default }}
26+
ingressClassName: {{ include "ingressClassName" . }}
2727
{{- if or (eq $targetCluster "eu") $ruConfig.tlsEnabled }}
2828
tls:
2929
- hosts:
@@ -75,7 +75,7 @@ metadata:
7575
nginx.ingress.kubernetes.io/auth-signin: https://$host/dex-authenticator/sign_in
7676
nginx.ingress.kubernetes.io/auth-url: https://werfio-dex-authenticator.{{ $.Values.werf.namespace }}.svc.cluster.local/dex-authenticator/auth
7777
spec:
78-
ingressClassName: {{ pluck .Values.werf.env .Values.ingressClassName | first | default .Values.ingressClassName._default }}
78+
ingressClassName: {{ include "ingressClassName" . }}
7979
tls:
8080
- hosts:
8181
- {{ $host }}
@@ -106,7 +106,7 @@ metadata:
106106
nginx.ingress.kubernetes.io/auth-signin: https://$host/dex-authenticator/sign_in
107107
nginx.ingress.kubernetes.io/auth-url: https://werfio-ru-dex-authenticator.{{ $.Values.werf.namespace }}.svc.cluster.local/dex-authenticator/auth
108108
spec:
109-
ingressClassName: {{ pluck .Values.werf.env .Values.ingressClassName | first | default .Values.ingressClassName._default }}
109+
ingressClassName: {{ include "ingressClassName" . }}
110110
tls:
111111
- hosts:
112112
- {{ $host }}
@@ -134,7 +134,7 @@ spec:
134134
secretName: tls-{{ $host }}
135135
issuerRef:
136136
kind: ClusterIssuer
137-
name: letsencrypt-standalone-geo
137+
name: {{ include "certificateIssuerName" . }}
138138
commonName: {{ $ruHost }}
139139
dnsNames:
140140
- {{ $ruHost }}
@@ -150,7 +150,7 @@ spec:
150150
secretName: tls-{{ $host }}
151151
issuerRef:
152152
kind: ClusterIssuer
153-
name: letsencrypt-standalone-geo
153+
name: {{ include "certificateIssuerName" . }}
154154
commonName: {{ $host }}
155155
dnsNames:
156156
- {{ $host }}

.helm/templates/_helpers.tpl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ eu
2828
{{- end }}
2929
{{- end }}
3030

31+
{{- define "ingressClassName" }}
32+
{{- $defaultClassName := pluck .Values.werf.env .Values.ingressClassName | first | default .Values.ingressClassName._default -}}
33+
{{- if eq .Values.werf.env "production" }}
34+
{{- $targetCluster := include "targetCluster" . -}}
35+
{{- $clusterConfig := get (.Values.productionDeploy | default dict) $targetCluster | default dict -}}
36+
{{- get $clusterConfig "ingressClassName" | default $defaultClassName -}}
37+
{{- else -}}
38+
{{- $defaultClassName -}}
39+
{{- end }}
40+
{{- end }}
41+
42+
{{- define "certificateIssuerName" }}
43+
{{- if eq .Values.werf.env "production" }}
44+
{{- $targetCluster := include "targetCluster" . -}}
45+
{{- $clusterConfig := get (.Values.productionDeploy | default dict) $targetCluster | default dict -}}
46+
{{- get $clusterConfig "certificateIssuerName" | default "letsencrypt-standalone-geo" -}}
47+
{{- else -}}
48+
letsencrypt
49+
{{- end }}
50+
{{- end }}
51+
3152
{{- define "clusterPlacement" }}
3253
{{- $targetCluster := include "targetCluster" . -}}
3354
{{- $clusterConfig := get (.Values.clusters | default dict) $targetCluster | default dict -}}

.helm/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ imagePullSecrets:
55
- github-werfio
66

77
productionDeploy:
8+
eu:
9+
ingressClassName: standalone-geo
10+
certificateIssuerName: letsencrypt-standalone-geo
811
ru:
912
hostOverride: ""
1013
tlsEnabled: true
1114
certificateEnabled: true
15+
ingressClassName: nginx
16+
certificateIssuerName: letsencrypt
1217

1318
clusters:
1419
eu:

backend/common.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,6 @@ func URLToVersion(version string) (result string) {
525525
return
526526
}
527527

528-
func normalizedRequestHost(r *http.Request) string {
529-
host := r.Host
530-
if parsedHost, _, err := net.SplitHostPort(r.Host); err == nil {
531-
host = parsedHost
532-
}
533-
return host
534-
}
535-
536528
func validateURL(url string) error {
537529
if strings.ToLower(os.Getenv("URL_VALIDATION")) == "false" {
538530
return nil
@@ -603,8 +595,7 @@ func getGroups() (groups []string) {
603595

604596
func getRootFilesPath(r *http.Request) (result string) {
605597
result = "./root/"
606-
host := normalizedRequestHost(r)
607-
if strings.HasPrefix(host, "ru.") || strings.HasPrefix(host, "ru-") {
598+
if strings.HasPrefix(r.Host, "ru.") || strings.HasPrefix(r.Host, "ru-") {
608599
result += "ru"
609600
} else {
610601
result += "en"

backend/handlers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ func unknownVersionHandler(w http.ResponseWriter, r *http.Request) {
9797
}
9898

9999
URLToRedirect = fmt.Sprintf("/docs/%v%v", group, pageURLRelative)
100-
err = validateURL(fmt.Sprintf("https://%s%s", normalizedRequestHost(r), URLToRedirect))
100+
err = validateURL(fmt.Sprintf("https://%s%s", r.Host, URLToRedirect))
101101

102102
if err != nil {
103-
log.Errorf("Error validating URL: %v, (original was https://%s/%v)", err.Error(), normalizedRequestHost(r), r.URL.RequestURI())
103+
log.Errorf("Error validating URL: %v, (original was https://%s/%v)", err.Error(), r.Host, r.URL.RequestURI())
104104
notFoundHandler(w, r)
105105
} else {
106106
http.Redirect(w, r, fmt.Sprintf("%s", URLToRedirect), 302)
@@ -126,11 +126,11 @@ func groupChannelHandler(w http.ResponseWriter, r *http.Request) {
126126
err, version = getVersionFromChannelAndGroup(&ReleasesStatus, vars["channel"], vars["group"])
127127
if err == nil {
128128
URLToRedirect = fmt.Sprintf("/docs/%v%v", VersionToURL(version), pageURLRelative)
129-
err = validateURL(fmt.Sprintf("https://%s%s", normalizedRequestHost(r), URLToRedirect))
129+
err = validateURL(fmt.Sprintf("https://%s%s", r.Host, URLToRedirect))
130130
}
131131

132132
if err != nil {
133-
log.Errorf("Error validating URL: %v, (original was https://%s/%v)", err.Error(), normalizedRequestHost(r), r.URL.RequestURI())
133+
log.Errorf("Error validating URL: %v, (original was https://%s/%v)", err.Error(), r.Host, r.URL.RequestURI())
134134
// URLToRedirect = fmt.Sprintf("/404.html")
135135
notFoundHandler(w, r)
136136
} else {

backend/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func newRouter() *mux.Router {
2424

2525
var ruHostMatch mux.MatcherFunc = func(r *http.Request, rm *mux.RouteMatch) bool {
2626
result := false
27-
result, _ = regexp.MatchString(`^ru[\.\-](localhost|.*(\.flant\.dev|werf\.io))$`, normalizedRequestHost(r))
27+
result, _ = regexp.MatchString(`^ru[\.\-](localhost|.*(\.flant\.dev|werf\.io))$`, r.Host)
2828
return result
2929
}
3030

0 commit comments

Comments
 (0)