2019-11-15 16:41:40 +03:00
|
|
|
package client
|
|
|
|
|
|
|
|
var templates = map[string]string{
|
2019-11-21 20:31:13 +03:00
|
|
|
"deployment": deploymentTmpl,
|
|
|
|
"service": serviceTmpl,
|
2019-11-15 16:41:40 +03: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 20:10:00 +03:00
|
|
|
annotations:
|
|
|
|
{{- with .Metadata.Annotations }}
|
|
|
|
{{- range $key, $value := . }}
|
|
|
|
{{ $key }}: "{{ $value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2019-11-15 16:41:40 +03: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 21:14:49 +03:00
|
|
|
annotations:
|
|
|
|
{{- with .Spec.Template.Metadata.Annotations }}
|
|
|
|
{{- range $key, $value := . }}
|
|
|
|
{{ $key }}: "{{ $value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2019-11-15 16:41:40 +03:00
|
|
|
spec:
|
|
|
|
containers:
|
|
|
|
{{- with .Spec.Template.PodSpec.Containers }}
|
|
|
|
{{- range . }}
|
|
|
|
- name: {{ .Name }}
|
|
|
|
env:
|
|
|
|
{{- with .Env }}
|
|
|
|
{{- range . }}
|
|
|
|
- name: "{{ .Name }}"
|
|
|
|
value: "{{ .Value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
command:
|
|
|
|
{{- range .Command }}
|
|
|
|
- {{.}}
|
|
|
|
{{- end }}
|
|
|
|
image: {{ .Image }}
|
|
|
|
imagePullPolicy: Always
|
|
|
|
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 }}
|
|
|
|
`
|