Skip to content

Commit 882ec8a

Browse files
authored
sample abn extension (#131)
Signed-off-by: Michael Kalantar <[email protected]>
1 parent adfe968 commit 882ec8a

File tree

5 files changed

+116
-0
lines changed

5 files changed

+116
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{- define "env.knative-istio.none.routemap" }}
2+
3+
{{- $versions := include "normalize.versions.ksvc" . | mustFromJson }}
4+
5+
apiVersion: v1
6+
kind: ConfigMap
7+
{{- template "routemap.metadata" . }}
8+
data:
9+
strSpec: |
10+
versions:
11+
{{- range $i, $v := $versions }}
12+
- resources:
13+
- gvrShort: ksvc
14+
name: {{ template "ksvc.name" $v }}
15+
namespace: {{ template "ksvc.namespace" $v }}
16+
weight: {{ $v.weight }}
17+
{{- end }} {{- /* range $i, $v := $versions */}}
18+
{{- end }} {{- /* define "env.knative-istio.none.routemap" */}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{- define "env.knative-istio.none" }}
2+
3+
{{- /* prepare versions for simpler processing */}}
4+
{{- $versions := include "normalize.versions.ksvc" . | mustFromJson }}
5+
6+
{{- /* routemap */}}
7+
{{ include "env.knative-istio.none.routemap" . }}
8+
9+
{{- end }} {{- /* define "env.knative-istio.none" */}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{- define "env.knative-istio" }}
2+
3+
{{- /* Prepare versions for simpler processing */}}
4+
{{- $versions := include "normalize.versions.ksvc" . | mustFromJson }}
5+
6+
{{- range $i, $v := $versions }}
7+
{{- /* KNative Service */}}
8+
{{ include "env.knative.version.ksvc" $v }}
9+
---
10+
{{- end }} {{- /* range $i, $v := $versions */}}
11+
12+
{{- /* routemap (and other strategy specific objects) */}}
13+
{{- if not .Values.application.strategy }}
14+
{{ include "env.knative-istio.none" . }}
15+
{{- else if eq "none" .Values.application.strategy }}
16+
{{ include "env.knative-istio.none" . }}
17+
{{- end }} {{- /* if eq ... .Values.application.strategy */}}
18+
19+
{{- end }} {{- /* define "env.knative-istio" */}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{- /* deployment specific wrapping for normalize.versions */}}
2+
{{- define "normalize.versions.ksvc" }}
3+
{{- $versions := include "normalize.versions" . | mustFromJson }}
4+
{{- $normalizedVersions := list }}
5+
{{- range $i, $v := $versions -}}
6+
{{- $version := merge $v }}
7+
8+
{{- $version = set $version "port" (pluck "port" (dict "port" 80) $.Values.application $v | last) }}
9+
{{- if (and $v.ksvcSpecification $v.ksvcSpecification.ports) }}
10+
{{- $version = set $version "port" (pluck "port" $v (index $v.ksvcSpecification.ports 0) | last) }}
11+
{{- end }}
12+
13+
{{- $normalizedVersions = append $normalizedVersions $version }}
14+
{{- end }} {{- /* range $i, $v := $versions */}}
15+
{{- mustToJson $normalizedVersions }}
16+
{{- end }} {{- /* define "normalize.versions.ksvc" */}}
17+
18+
{{- /* Identify the name of a Knative Service object */ -}}
19+
{{- define "ksvc.name" -}}
20+
{{- if (and .ksvcSpecification .ksvcSpecification.metadata .ksvcSpecification.metadata.name) -}}
21+
{{ .ksvcSpecification.metadata.name }}
22+
{{- else -}}
23+
{{ .VERSION_NAME }}
24+
{{- end -}}
25+
{{- end }} {{- /* define "ksvc.name" */ -}}
26+
27+
{{- /* Identify the namespace of a Knative Service object */ -}}
28+
{{- define "ksvc.namespace" -}}
29+
{{- if (and .ksvcSpecification .ksvcSpecification.metadata .ksvcSpecification.metadata.namespace) -}}
30+
{{ .ksvcSpecification.metadata.namespace }}
31+
{{- else -}}
32+
{{ .VERSION_NAMESPACE }}
33+
{{- end -}}
34+
{{- end }} {{- /* define "ksvc.namespace" */ -}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{{- define "env.knative.version.ksvc" }}
2+
3+
{{- /* compute basic metadata */}}
4+
{{- $metadata := include "application.version.metadata" . | mustFromJson }}
5+
6+
{{- /* define Service */}}
7+
apiVersion: serving.knative.dev/v1
8+
kind: Service
9+
{{- if .ksvcSpecification }}
10+
metadata:
11+
{{- if .ksvcSpecification.metadata }}
12+
{{ toYaml (merge .ksvcSpecification.metadata $metadata) | nindent 2 | trim }}
13+
{{- else }}
14+
{{ toYaml $metadata | nindent 2 | trim }}
15+
{{- end }} {{- /* if .ksvcSpecification.metadata */}}
16+
spec:
17+
{{ toYaml .ksvcSpecification.spec | nindent 2 | trim }}
18+
{{- else }} {{- /* if .ksvcSpecification */}}
19+
{{- if not .image }} {{- /* require .image */}}
20+
{{- print "missing field: image required when deploymentSpecification absent" | fail }}
21+
{{- end }} {{- /* if not .image */}}
22+
{{- if not .port }} {{- /* require .port */}}
23+
{{- print "missing field: port required when deploymentSpecification absent" | fail }}
24+
{{- end }} {{- /* if not .port */}}
25+
metadata:
26+
{{ toYaml $metadata | nindent 2 | trim }}
27+
spec:
28+
template:
29+
spec:
30+
containers:
31+
- image: {{ .image }}
32+
ports:
33+
- containerPort: {{ .port }}
34+
{{- end }} {{- /* if .ksvcSpecification */}}
35+
36+
{{- end }} {{- /* define "env.knative.version.ksvc" */}}

0 commit comments

Comments
 (0)