Skip to content

Commit

Permalink
support path based routing in core packages (#164)
Browse files Browse the repository at this point in the history
Signed-off-by: Manabu McCloskey <[email protected]>
  • Loading branch information
nabuskey authored Mar 4, 2024
1 parent 69443ce commit 988756c
Show file tree
Hide file tree
Showing 34 changed files with 514 additions and 179 deletions.
26 changes: 26 additions & 0 deletions hack/argo-cd/argocd-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/component: server
app.kubernetes.io/name: argocd-server
app.kubernetes.io/part-of: argocd
name: argocd-server
spec:
selector:
matchLabels:
app.kubernetes.io/name: argocd-server
template:
metadata:
labels:
app.kubernetes.io/name: argocd-server
spec:
containers:
- args:
- /usr/local/bin/argocd-server
- "{{if .UsePathRouting}}"
- --insecure
- --basehref
- /argocd
- "{{end}}"
name: argocd-server
5 changes: 5 additions & 0 deletions hack/argo-cd/generate-manifests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

INSTALL_YAML="pkg/controllers/localbuild/resources/argo/install.yaml"
INGRESS_YAML="pkg/controllers/localbuild/resources/argo/ingress.yaml"

echo "# UCP ARGO INSTALL RESOURCES" > ${INSTALL_YAML}
echo "# This file is auto-generated with 'hack/argo-cd/generate-manifests.sh'" >> ${INSTALL_YAML}
kustomize build ./hack/argo-cd/ >> ${INSTALL_YAML}

cat ./hack/argo-cd/ingress.yaml.tmpl > ${INGRESS_YAML}
49 changes: 49 additions & 0 deletions hack/argo-cd/ingress.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{{- if .UsePathRouting -}}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: argocd-server-ingress-http
namespace: argocd
annotations:
nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
ingressClassName: nginx
rules:
- host: {{ .IngressHost }}
http:
paths:
- path: /argocd(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: argocd-server
port:
name: http

{{- else -}}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: argocd-server-ingress
namespace: argocd
annotations:
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
spec:
ingressClassName: "nginx"
rules:
- host: argocd.{{ .IngressHost }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: argocd-server
port:
name: https
{{ end }}
1 change: 1 addition & 0 deletions hack/argo-cd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ patches:
- path: dex-server.yaml
- path: notifications-controller.yaml
- path: argocd-cm.yaml
- path: argocd-server.yaml
17 changes: 17 additions & 0 deletions hack/gitea/generate-manifests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

INSTALL_YAML="pkg/controllers/localbuild/resources/gitea/k8s/install.yaml"
GITEA_DIR="./hack/gitea"
CHART_VERSION="9.5.1"

echo "# GITEA INSTALL RESOURCES" > ${INSTALL_YAML}
echo "# This file is auto-generated with 'hack/gitea/generate-manifests.sh'" >> ${INSTALL_YAML}

helm repo add gitea-charts --force-update https://dl.gitea.com/charts/
helm repo update
helm template my-gitea gitea-charts/gitea -f ${GITEA_DIR}/values.yaml --version ${CHART_VERSION} >> ${INSTALL_YAML}
sed -i '3d' ${INSTALL_YAML}

cat ${GITEA_DIR}/ingress.yaml.tmpl >> ${INSTALL_YAML}
cat ${GITEA_DIR}/gitea-creds.yaml >> ${INSTALL_YAML}
9 changes: 9 additions & 0 deletions hack/gitea/gitea-creds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: v1
kind: Secret
metadata:
name: gitea-admin-secret
type: Opaque
stringData:
username: giteaAdmin
password: giteaPassword
67 changes: 67 additions & 0 deletions hack/gitea/ingress.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{{- if .UsePathRouting }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-gitea-path
namespace: gitea
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: 512m
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
ingressClassName: nginx
rules:
- host: {{ .IngressHost }}
http:
paths:
- backend:
service:
name: my-gitea-http
port:
number: 3000
path: /gitea(/|$)(.*)
pathType: ImplementationSpecific
{{ else if ( ne .Host "cnoe.localtest.me") }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-gitea-custom
namespace: gitea
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: 512m
spec:
ingressClassName: nginx
rules:
- host: gitea.{{ .IngressHost }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-gitea-http
port:
number: 3000
{{ end }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-gitea
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: 512m
spec:
ingressClassName: nginx
rules:
- host: "gitea.cnoe.localtest.me"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-gitea-http
port:
number: 3000
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ gitea:
queue:
TYPE: level
server:
DOMAIN: gitea.cnoe.localtest.me
ROOT_URL: 'https://gitea.cnoe.localtest.me:{{ .Port }}'
DOMAIN: '{{- if .UsePathRouting -}} {{ .Host }} {{- else -}} gitea.{{- .Host }} {{- end }}'
ROOT_URL: '{{- if .UsePathRouting }} {{- .Protocol }}://{{ .Host }}:{{ .Port }}/gitea {{- else }} {{- .Protocol }}://gitea.{{ .Host }}:{{ .Port }} {{- end }}'

service:
ssh:
Expand All @@ -34,11 +34,4 @@ service:
externalTrafficPolicy: Local

ingress:
enabled: true
apiVersion: 'networking.k8s.io/v1'
className: nginx
hosts:
- host: gitea.cnoe.localtest.me
paths:
- path: /
pathType: Prefix
enabled: false
2 changes: 1 addition & 1 deletion hack/ingress-nginx/deployment-ingress-nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
- --controller-class=k8s.io/ingress-nginx
- --ingress-class=nginx
- --configmap=$(POD_NAMESPACE)/ingress-nginx-controller
- --validating-webhook=:{{ .Port }}
- --validating-webhook=:8443
- --validating-webhook-certificate=/usr/local/certificates/cert
- --validating-webhook-key=/usr/local/certificates/key
- --watch-ingress-without-class=true
Expand Down
8 changes: 7 additions & 1 deletion hack/ingress-nginx/generate-manifests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash

INSTALL_YAML="pkg/controllers/localbuild/resources/nginx/k8s/ingress-nginx.yaml"
NGINX_DIR="./hack/ingress-nginx"


echo "# INGRESS-NGINX INSTALL RESOURCES" > ${INSTALL_YAML}
echo "# This file is auto-generated with 'hack/ingress-nginx/generate-manifests.sh'" >> ${INSTALL_YAML}
kustomize build ./hack/ingress-nginx/ >> ${INSTALL_YAML}
kustomize build ${NGINX_DIR} >> ${INSTALL_YAML}

cat ${NGINX_DIR}/service-ingress-nginx.yaml.tmpl >> ${INSTALL_YAML}
13 changes: 5 additions & 8 deletions hack/ingress-nginx/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ resources:

patches:
- path: deployment-ingress-nginx.yaml
- path: service-ingress-nginx.yaml
- path: cm-ingress-nginx-controller.yaml
- target:
group: ""
version: v1
kind: Service
name: ingress-nginx-controller
namespace: ingress-nginx
patch: |-
- op: remove
path: /spec/externalTrafficPolicy
- op: replace
path: /spec/type
value: NodePort
patch: |
$patch: delete
kind: Kustomization
metadata:
name: ingress-nginx-controller
15 changes: 0 additions & 15 deletions hack/ingress-nginx/service-ingress-nginx.yaml

This file was deleted.

37 changes: 37 additions & 0 deletions hack/ingress-nginx/service-ingress-nginx.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/version: 1.8.1
name: ingress-nginx-controller
namespace: ingress-nginx
spec:
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- appProtocol: {{ .Protocol }}
name: {{ .Protocol }}-{{ .Port }}
port: {{ .Port }}
protocol: TCP
targetPort: {{ .Protocol }}
- appProtocol: http
name: http
port: 80
protocol: TCP
targetPort: http
- appProtocol: https
name: https
port: 443
protocol: TCP
targetPort: https
selector:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx
type: NodePort
4 changes: 2 additions & 2 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (

type Build struct {
name string
cfg util.TemplateConfig
cfg util.CorePackageTemplateConfig
kindConfigPath string
kubeConfigPath string
kubeVersion string
Expand All @@ -37,7 +37,7 @@ type Build struct {
CancelFunc context.CancelFunc
}

func NewBuild(name, kubeVersion, kubeConfigPath, kindConfigPath, extraPortsMapping string, cfg util.TemplateConfig, customPackageDirs []string, exitOnSync bool, scheme *runtime.Scheme, ctxCancel context.CancelFunc) *Build {
func NewBuild(name, kubeVersion, kubeConfigPath, kindConfigPath, extraPortsMapping string, cfg util.CorePackageTemplateConfig, customPackageDirs []string, exitOnSync bool, scheme *runtime.Scheme, ctxCancel context.CancelFunc) *Build {
return &Build{
name: name,
kindConfigPath: kindConfigPath,
Expand Down
Loading

0 comments on commit 988756c

Please sign in to comment.