2019-11-15 13:41:40 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
var templates = map[string]string{
|
2020-04-27 14:13:51 +01:00
|
|
|
"deployment": deploymentTmpl,
|
|
|
|
"service": serviceTmpl,
|
|
|
|
"namespace": namespaceTmpl,
|
2020-04-27 14:37:28 +01:00
|
|
|
"secret": secretTmpl,
|
2020-04-27 14:13:51 +01:00
|
|
|
"serviceaccount": serviceAccountTmpl,
|
2019-11-15 13:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var deploymentTmpl = `
|
|
|
|
apiVersion: apps/v1
|
|
|
|
kind: Deployment
|
|
|
|
metadata:
|
|
|
|
name: "{{ .Metadata.Name }}"
|
|
|
|
namespace: "{{ .Metadata.Namespace }}"
|
|
|
|
labels:
|
|
|
|
{{- with .Metadata.Labels }}
|
|
|
|
{{- range $key, $value := . }}
|
|
|
|
{{ $key }}: "{{ $value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2019-11-22 17:10:00 +00:00
|
|
|
annotations:
|
|
|
|
{{- with .Metadata.Annotations }}
|
|
|
|
{{- range $key, $value := . }}
|
|
|
|
{{ $key }}: "{{ $value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2019-11-15 13:41:40 +00:00
|
|
|
spec:
|
|
|
|
replicas: {{ .Spec.Replicas }}
|
|
|
|
selector:
|
|
|
|
matchLabels:
|
|
|
|
{{- with .Spec.Selector.MatchLabels }}
|
|
|
|
{{- range $key, $value := . }}
|
|
|
|
{{ $key }}: "{{ $value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
template:
|
|
|
|
metadata:
|
|
|
|
labels:
|
|
|
|
{{- with .Spec.Template.Metadata.Labels }}
|
|
|
|
{{- range $key, $value := . }}
|
|
|
|
{{ $key }}: "{{ $value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2019-11-26 18:14:49 +00:00
|
|
|
annotations:
|
|
|
|
{{- with .Spec.Template.Metadata.Annotations }}
|
|
|
|
{{- range $key, $value := . }}
|
|
|
|
{{ $key }}: "{{ $value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2020-04-27 14:13:51 +01:00
|
|
|
spec:
|
|
|
|
serviceAccountName: {{ .Spec.Template.PodSpec.ServiceAccountName }}
|
2019-11-15 13:41:40 +00:00
|
|
|
containers:
|
|
|
|
{{- with .Spec.Template.PodSpec.Containers }}
|
|
|
|
{{- range . }}
|
|
|
|
- name: {{ .Name }}
|
|
|
|
env:
|
|
|
|
{{- with .Env }}
|
|
|
|
{{- range . }}
|
|
|
|
- name: "{{ .Name }}"
|
|
|
|
value: "{{ .Value }}"
|
2020-07-09 16:29:01 +01:00
|
|
|
{{- if .ValueFrom }}
|
|
|
|
{{- with .ValueFrom }}
|
|
|
|
valueFrom:
|
|
|
|
{{- if .SecretKeyRef }}
|
|
|
|
{{- with .SecretKeyRef }}
|
|
|
|
secretKeyRef:
|
|
|
|
key: {{ .Key }}
|
|
|
|
name: {{ .Name }}
|
|
|
|
optional: {{ .Optional }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2019-11-15 13:41:40 +00:00
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2020-02-06 12:31:54 +00:00
|
|
|
args:
|
|
|
|
{{- range .Args }}
|
|
|
|
- {{.}}
|
|
|
|
{{- end }}
|
2019-11-15 13:41:40 +00:00
|
|
|
command:
|
|
|
|
{{- range .Command }}
|
|
|
|
- {{.}}
|
|
|
|
{{- end }}
|
|
|
|
image: {{ .Image }}
|
2020-07-14 15:17:23 +01:00
|
|
|
imagePullPolicy: Always
|
2019-11-15 13:41:40 +00:00
|
|
|
ports:
|
|
|
|
{{- with .Ports }}
|
|
|
|
{{- range . }}
|
|
|
|
- containerPort: {{ .ContainerPort }}
|
|
|
|
name: {{ .Name }}
|
|
|
|
{{- end}}
|
|
|
|
{{- end}}
|
|
|
|
{{- end }}
|
|
|
|
{{- end}}
|
|
|
|
`
|
|
|
|
|
|
|
|
var serviceTmpl = `
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Service
|
|
|
|
metadata:
|
|
|
|
name: "{{ .Metadata.Name }}"
|
|
|
|
namespace: "{{ .Metadata.Namespace }}"
|
|
|
|
labels:
|
|
|
|
{{- with .Metadata.Labels }}
|
|
|
|
{{- range $key, $value := . }}
|
|
|
|
{{ $key }}: "{{ $value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
spec:
|
|
|
|
selector:
|
|
|
|
{{- with .Spec.Selector }}
|
|
|
|
{{- range $key, $value := . }}
|
|
|
|
{{ $key }}: "{{ $value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
ports:
|
|
|
|
{{- with .Spec.Ports }}
|
|
|
|
{{- range . }}
|
|
|
|
- name: "{{ .Name }}"
|
|
|
|
port: {{ .Port }}
|
|
|
|
protocol: {{ .Protocol }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
`
|
2020-03-31 12:03:32 +01:00
|
|
|
|
|
|
|
var namespaceTmpl = `
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Namespace
|
|
|
|
metadata:
|
|
|
|
name: "{{ .Metadata.Name }}"
|
|
|
|
labels:
|
|
|
|
{{- with .Metadata.Labels }}
|
|
|
|
{{- range $key, $value := . }}
|
|
|
|
{{ $key }}: "{{ $value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
`
|
2020-04-27 14:13:51 +01:00
|
|
|
|
2020-04-27 14:37:28 +01:00
|
|
|
var secretTmpl = `
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Secret
|
2020-05-12 14:10:39 +01:00
|
|
|
type: "{{ .Type }}"
|
2020-04-27 14:37:28 +01:00
|
|
|
metadata:
|
|
|
|
name: "{{ .Metadata.Name }}"
|
|
|
|
namespace: "{{ .Metadata.Namespace }}"
|
|
|
|
labels:
|
|
|
|
{{- with .Metadata.Labels }}
|
|
|
|
{{- range $key, $value := . }}
|
|
|
|
{{ $key }}: "{{ $value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
data:
|
2020-05-12 11:40:54 +01:00
|
|
|
{{- with .Data }}
|
|
|
|
{{- range $key, $value := . }}
|
|
|
|
{{ $key }}: "{{ $value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2020-04-27 14:37:28 +01:00
|
|
|
`
|
|
|
|
|
2020-04-27 14:13:51 +01:00
|
|
|
var serviceAccountTmpl = `
|
|
|
|
apiVersion: v1
|
|
|
|
kind: ServiceAccount
|
|
|
|
metadata:
|
|
|
|
name: "{{ .Metadata.Name }}"
|
|
|
|
labels:
|
|
|
|
{{- with .Metadata.Labels }}
|
|
|
|
{{- range $key, $value := . }}
|
|
|
|
{{ $key }}: "{{ $value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
imagePullSecrets:
|
|
|
|
{{- with .ImagePullSecrets }}
|
|
|
|
{{- range . }}
|
|
|
|
- name: "{{ .Name }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
`
|