gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/runtime/kubernetes/client/templates.go (about) 1 package client 2 3 var templates = map[string]string{ 4 "deployment": deploymentTmpl, 5 "service": serviceTmpl, 6 } 7 8 var deploymentTmpl = ` 9 apiVersion: apps/v1 10 kind: Deployment 11 metadata: 12 name: "{{ .Metadata.Name }}" 13 namespace: "{{ .Metadata.Namespace }}" 14 labels: 15 {{- with .Metadata.Labels }} 16 {{- range $key, $value := . }} 17 {{ $key }}: "{{ $value }}" 18 {{- end }} 19 {{- end }} 20 annotations: 21 {{- with .Metadata.Annotations }} 22 {{- range $key, $value := . }} 23 {{ $key }}: "{{ $value }}" 24 {{- end }} 25 {{- end }} 26 spec: 27 replicas: {{ .Spec.Replicas }} 28 selector: 29 matchLabels: 30 {{- with .Spec.Selector.MatchLabels }} 31 {{- range $key, $value := . }} 32 {{ $key }}: "{{ $value }}" 33 {{- end }} 34 {{- end }} 35 template: 36 metadata: 37 labels: 38 {{- with .Spec.Template.Metadata.Labels }} 39 {{- range $key, $value := . }} 40 {{ $key }}: "{{ $value }}" 41 {{- end }} 42 {{- end }} 43 annotations: 44 {{- with .Spec.Template.Metadata.Annotations }} 45 {{- range $key, $value := . }} 46 {{ $key }}: "{{ $value }}" 47 {{- end }} 48 {{- end }} 49 spec: 50 containers: 51 {{- with .Spec.Template.PodSpec.Containers }} 52 {{- range . }} 53 - name: {{ .Name }} 54 env: 55 {{- with .Env }} 56 {{- range . }} 57 - name: "{{ .Name }}" 58 value: "{{ .Value }}" 59 {{- end }} 60 {{- end }} 61 command: 62 {{- range .Command }} 63 - {{.}} 64 {{- end }} 65 image: {{ .Image }} 66 imagePullPolicy: Always 67 ports: 68 {{- with .Ports }} 69 {{- range . }} 70 - containerPort: {{ .ContainerPort }} 71 name: {{ .Name }} 72 {{- end}} 73 {{- end}} 74 {{- end }} 75 {{- end}} 76 ` 77 78 var serviceTmpl = ` 79 apiVersion: v1 80 kind: Service 81 metadata: 82 name: "{{ .Metadata.Name }}" 83 namespace: "{{ .Metadata.Namespace }}" 84 labels: 85 {{- with .Metadata.Labels }} 86 {{- range $key, $value := . }} 87 {{ $key }}: "{{ $value }}" 88 {{- end }} 89 {{- end }} 90 spec: 91 selector: 92 {{- with .Spec.Selector }} 93 {{- range $key, $value := . }} 94 {{ $key }}: "{{ $value }}" 95 {{- end }} 96 {{- end }} 97 ports: 98 {{- with .Spec.Ports }} 99 {{- range . }} 100 - name: "{{ .Name }}" 101 port: {{ .Port }} 102 protocol: {{ .Protocol }} 103 {{- end }} 104 {{- end }} 105 `