Skip to content

Commit

Permalink
clean up templates to allow for preset namespace and generated namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
newgoliath committed Oct 26, 2023
1 parent 7abf88a commit 0ee0fac
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 33 deletions.
2 changes: 1 addition & 1 deletion charts/showroom/files/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<iframe id="doc" src="{{ .Values.content.url }}" width="100%" style="border:none;"></iframe>
{{- else }}
<!-- make this the content service -->
<iframe id="doc" src="{{ include "showroom-deployer.showroom.route" (list "content" .Values) }}" width="100%" style="border:none;"></iframe>
<iframe id="doc" src="{{ include "showroom-deployer.showroom.route" (list "content" .Values) }}" width="100%" style="border:none;"></iframe>
{{- end }}
</div>
<div class="split right">
Expand Down
28 changes: 22 additions & 6 deletions charts/showroom/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,36 @@
catalogItem: "{{ .Values.general.catalogItem | toString | lower }}"
guid: "{{ .Values.general.guid | toString | lower }}"
app: "showroom"
{{- end -}}

{{/*
USE ONLY WHEN WE HAVE AGV COMPONENT NAME
If there's not already a namespace, create a namespace name from namespacename-guid-catalogItem
{{ define "showroom-deployer.namespace.name" }}
{{- end }}
*/}}
{{/*
Create a namespace name from namespacename-guid-catalogItem
If there's not already a namespace, create a namespace name from namespacename-guid
*/}}
{{- define "showroom-deployer.namespace.name" }} {{ .Values.general.namespace | toString | lower }}-{{ .Values.general.guid | toString | lower }}-{{ .Values.general.catalogItem | toString | lower }}
{{- end }}
{{ define "showroom-deployer.namespace.name" -}}
{{ if .Values.namespace -}}
{{ .Values.namespace | toString | lower -}}
{{ else if not .Values.general.aVcomponentName -}}
{{ .Values.general.namespace | toString | lower }}-{{ $.Values.general.guid | toString | lower -}}
{{ else -}}
{{ .Values.general.namespace | toString | lower }}-{{ $.Values.general.guid | toString | lower }}-{{ .Values.general.agVcomponentName | toString | lower -}}
{{ end -}}
{{ end -}}

{{/*
The HTML files need a differently scoped set of the same values as above,
used in the showroom-deployer.showroom.route template below.
Add conditions for AgVcomponentName when it comes along.
*/}}
{{- define "showroom-deployer.htmlnamespace.name" }}{{ .general.namespace | toString | lower }}-{{ .general.guid | toString | lower }}-{{ .general.catalogItem | toString | lower }}
{{- end }}
{{- define "showroom-deployer.htmlnamespace.name" }}
{{- .general.namespace | toString | lower }}-{{ .general.guid | toString | lower }}
{{- end -}}

{{/*
Create a showroom route for the HTML page
Expand All @@ -28,4 +44,4 @@ Create a showroom route for the HTML page
{{- $values := index . 1 -}}
{{- $tmpnamespace := include "showroom-deployer.htmlnamespace.name" $values -}}
{{- printf "https://showroom-proxy-%s.%s/%s" $tmpnamespace $values.deployer.domain $service }}
{{- end }}
{{- end -}}
2 changes: 1 addition & 1 deletion charts/showroom/templates/content/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.content.userdataName }}
namespace: {{- template "showroom-deployer.namespace.name" . }}
namespace: {{ template "showroom-deployer.namespace.name" . }}
data:
user_data.yml: |
{{ .Values.content.user_data | indent 4 }}
Expand Down
2 changes: 1 addition & 1 deletion charts/showroom/templates/content/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: showroom-content
namespace: {{- template "showroom-deployer.namespace.name" . }}
namespace: {{ template "showroom-deployer.namespace.name" . }}
spec:
replicas: 1
selector:
Expand Down
2 changes: 1 addition & 1 deletion charts/showroom/templates/content/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: v1
kind: Service
metadata:
name: showroom-content
namespace: {{- template "showroom-deployer.namespace.name" . }}
namespace: {{ template "showroom-deployer.namespace.name" . }}
spec:
type: ClusterIP
ports:
Expand Down
2 changes: 1 addition & 1 deletion charts/showroom/templates/home/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: showroom-html
namespace: {{- template "showroom-deployer.namespace.name" . }}
namespace: {{ template "showroom-deployer.namespace.name" . }}
data:
{{ tpl ((.Files.Glob "files/*").AsConfig) . | indent 2 }}
2 changes: 1 addition & 1 deletion charts/showroom/templates/home/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: showroom
namespace: {{- template "showroom-deployer.namespace.name" . }}
namespace: {{ template "showroom-deployer.namespace.name" . }}
spec:
replicas: 1
selector:
Expand Down
2 changes: 1 addition & 1 deletion charts/showroom/templates/home/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Service
metadata:
name: showroom
namespace: {{- template "showroom-deployer.namespace.name" . }}
namespace: {{ template "showroom-deployer.namespace.name" . }}
spec:
type: ClusterIP
ports:
Expand Down
2 changes: 1 addition & 1 deletion charts/showroom/templates/namespace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: v1
kind: Namespace
metadata:
name: {{- template "showroom-deployer.namespace.name" . }}
name: {{ template "showroom-deployer.namespace.name" . }}
annotations:
openshift.io/display-name: "Showroom Deployer"
openshift.io/description: "Showroom namespace description."
11 changes: 5 additions & 6 deletions charts/showroom/templates/proxy/nginx/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
kind: ConfigMap
metadata:
creationTimestamp: null
name: showroom-proxy
namespace: {{ template "showroom-deployer.namespace.name" . }}
apiVersion: v1
data:
nginx.conf: |
Expand Down Expand Up @@ -84,9 +89,3 @@ data:
}
}
kind: ConfigMap
metadata:
creationTimestamp: null
name: showroom-proxy
# namespace: {{- template "showroom-deployer.namespace.name" . }}
namespace: {{- template "showroom-deployer.namespace.name" . }}
2 changes: 1 addition & 1 deletion charts/showroom/templates/proxy/nginx/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: showroom-proxy
namespace: {{- template "showroom-deployer.namespace.name" . }}
namespace: {{ template "showroom-deployer.namespace.name" . }}
labels:
app.kubernetes.io/name: showroom-proxy
spec:
Expand Down
4 changes: 1 addition & 3 deletions charts/showroom/templates/proxy/nginx/route.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
apiVersion: route.openshift.io/v1
kind: Route
metadata:
#name: showroom-proxy
name: showroom-proxy
namespace: {{- template "showroom-deployer.namespace.name" . }}
#namespace: {{- template "showroom-deployer.namespace.name" . }}
namespace: {{ template "showroom-deployer.namespace.name" . }}
labels:
app.kubernetes.io/name: showroom-proxy
spec:
Expand Down
2 changes: 1 addition & 1 deletion charts/showroom/templates/proxy/nginx/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Service
metadata:
name: showroom-proxy
namespace: {{- template "showroom-deployer.namespace.name" . }}
namespace: {{ template "showroom-deployer.namespace.name" . }}
spec:
type: ClusterIP
ports:
Expand Down
4 changes: 2 additions & 2 deletions charts/showroom/templates/terminal/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: terminal
namespace: {{- template "showroom-deployer.namespace.name" . }}
name: showroom-terminal
namespace: {{ template "showroom-deployer.namespace.name" . }}
spec:
replicas: 1
selector:
Expand Down
6 changes: 3 additions & 3 deletions charts/showroom/templates/terminal/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: edit-{{ .Values.terminal.serviceAccount }}
namespace: {{- template "showroom-deployer.namespace.name" . }}
namespace: {{ template "showroom-deployer.namespace.name" . }}
labels:
app.kubernetes.io/instance: {{- template "showroom-deployer.namespace.name" . }}
app.kubernetes.io/instance: {{ template "showroom-deployer.namespace.name" . }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: edit
subjects:
- kind: ServiceAccount
name: {{ .Values.terminal.serviceAccount }}
namespace: {{- template "showroom-deployer.namespace.name" . }}
namespace: {{ template "showroom-deployer.namespace.name" . }}
2 changes: 1 addition & 1 deletion charts/showroom/templates/terminal/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Service
metadata:
name: terminal
namespace: {{- template "showroom-deployer.namespace.name" . }}
namespace: {{ template "showroom-deployer.namespace.name" . }}
spec:
type: ClusterIP
ports:
Expand Down
2 changes: 1 addition & 1 deletion charts/showroom/templates/terminal/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Values.terminal.serviceAccount }}
namespace: {{- template "showroom-deployer.namespace.name" . }}
namespace: {{ template "showroom-deployer.namespace.name" . }}
2 changes: 1 addition & 1 deletion charts/showroom/values.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
# Default values for showroom.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.


general:
guid: nnnn
namespace: showroom
Expand Down

0 comments on commit 0ee0fac

Please sign in to comment.