2019-11-15 16:41:40 +03:00
|
|
|
package client
|
|
|
|
|
|
|
|
var templates = map[string]string{
|
2020-04-27 16:13:51 +03:00
|
|
|
"deployment": deploymentTmpl,
|
|
|
|
"service": serviceTmpl,
|
|
|
|
"namespace": namespaceTmpl,
|
2020-04-27 16:37:28 +03:00
|
|
|
"secret": secretTmpl,
|
2020-04-27 16:13:51 +03:00
|
|
|
"serviceaccount": serviceAccountTmpl,
|
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 }}
|
2020-04-27 16:13:51 +03:00
|
|
|
spec:
|
|
|
|
serviceAccountName: {{ .Spec.Template.PodSpec.ServiceAccountName }}
|
2019-11-15 16:41:40 +03:00
|
|
|
containers:
|
|
|
|
{{- with .Spec.Template.PodSpec.Containers }}
|
|
|
|
{{- range . }}
|
|
|
|
- name: {{ .Name }}
|
|
|
|
env:
|
|
|
|
{{- with .Env }}
|
|
|
|
{{- range . }}
|
|
|
|
- name: "{{ .Name }}"
|
|
|
|
value: "{{ .Value }}"
|
2020-07-09 18:29:01 +03:00
|
|
|
{{- if .ValueFrom }}
|
|
|
|
{{- with .ValueFrom }}
|
|
|
|
valueFrom:
|
|
|
|
{{- if .SecretKeyRef }}
|
|
|
|
{{- with .SecretKeyRef }}
|
|
|
|
secretKeyRef:
|
|
|
|
key: {{ .Key }}
|
|
|
|
name: {{ .Name }}
|
|
|
|
optional: {{ .Optional }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2019-11-15 16:41:40 +03:00
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2020-02-06 15:31:54 +03:00
|
|
|
args:
|
|
|
|
{{- range .Args }}
|
|
|
|
- {{.}}
|
|
|
|
{{- end }}
|
2019-11-15 16:41:40 +03:00
|
|
|
command:
|
|
|
|
{{- range .Command }}
|
|
|
|
- {{.}}
|
|
|
|
{{- end }}
|
|
|
|
image: {{ .Image }}
|
2020-07-14 17:17:23 +03:00
|
|
|
imagePullPolicy: Always
|
2019-11-15 16:41:40 +03:00
|
|
|
ports:
|
|
|
|
{{- with .Ports }}
|
|
|
|
{{- range . }}
|
|
|
|
- containerPort: {{ .ContainerPort }}
|
|
|
|
name: {{ .Name }}
|
2020-08-14 13:47:28 +03:00
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2020-08-11 10:38:30 +03:00
|
|
|
{{- if .ReadinessProbe }}
|
|
|
|
{{- with .ReadinessProbe }}
|
|
|
|
readinessProbe:
|
|
|
|
{{- with .TCPSocket }}
|
|
|
|
tcpSocket:
|
|
|
|
{{- if .Host }}
|
|
|
|
host: {{ .Host }}
|
|
|
|
{{- end }}
|
|
|
|
port: {{ .Port }}
|
|
|
|
{{- end }}
|
|
|
|
initialDelaySeconds: {{ .InitialDelaySeconds }}
|
|
|
|
periodSeconds: {{ .PeriodSeconds }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2020-08-14 13:47:28 +03:00
|
|
|
{{- if .Resources }}
|
|
|
|
{{- with .Resources }}
|
|
|
|
resources:
|
|
|
|
{{- if .Limits }}
|
|
|
|
{{- with .Limits }}
|
|
|
|
limits:
|
|
|
|
{{- if .Memory }}
|
|
|
|
memory: {{ .Memory }}
|
|
|
|
{{- end }}
|
|
|
|
{{- if .CPU }}
|
|
|
|
cpu: {{ .CPU }}
|
|
|
|
{{- end }}
|
|
|
|
{{- if .EphemeralStorage }}
|
|
|
|
ephemeral-storage: {{ .EphemeralStorage }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
{{- if .Requests }}
|
|
|
|
{{- with .Requests }}
|
|
|
|
requests:
|
|
|
|
{{- if .Memory }}
|
|
|
|
memory: {{ .Memory }}
|
|
|
|
{{- end }}
|
|
|
|
{{- if .CPU }}
|
|
|
|
cpu: {{ .CPU }}
|
|
|
|
{{- end }}
|
|
|
|
{{- if .EphemeralStorage }}
|
|
|
|
ephemeral-storage: {{ .EphemeralStorage }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2020-08-11 10:38:30 +03:00
|
|
|
{{- end }}
|
2019-11-15 16:41:40 +03:00
|
|
|
{{- 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 14:03:32 +03: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 16:13:51 +03:00
|
|
|
|
2020-04-27 16:37:28 +03:00
|
|
|
var secretTmpl = `
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Secret
|
2020-05-12 16:10:39 +03:00
|
|
|
type: "{{ .Type }}"
|
2020-04-27 16:37:28 +03:00
|
|
|
metadata:
|
|
|
|
name: "{{ .Metadata.Name }}"
|
|
|
|
namespace: "{{ .Metadata.Namespace }}"
|
|
|
|
labels:
|
|
|
|
{{- with .Metadata.Labels }}
|
|
|
|
{{- range $key, $value := . }}
|
|
|
|
{{ $key }}: "{{ $value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
data:
|
2020-05-12 13:40:54 +03:00
|
|
|
{{- with .Data }}
|
|
|
|
{{- range $key, $value := . }}
|
|
|
|
{{ $key }}: "{{ $value }}"
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2020-04-27 16:37:28 +03:00
|
|
|
`
|
|
|
|
|
2020-04-27 16:13:51 +03: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 }}
|
|
|
|
`
|