github.com/annwntech/go-micro/v2@v2.9.5/util/kubernetes/client/templates.go (about)

     1  package client
     2  
     3  var templates = map[string]string{
     4  	"deployment":     deploymentTmpl,
     5  	"service":        serviceTmpl,
     6  	"namespace":      namespaceTmpl,
     7  	"secret":         secretTmpl,
     8  	"serviceaccount": serviceAccountTmpl,
     9  }
    10  
    11  // stripped image pull policy always
    12  // imagePullPolicy: Always
    13  var deploymentTmpl = `
    14  apiVersion: apps/v1
    15  kind: Deployment
    16  metadata:
    17    name: "{{ .Metadata.Name }}"
    18    namespace: "{{ .Metadata.Namespace }}"
    19    labels:
    20      {{- with .Metadata.Labels }}
    21      {{- range $key, $value := . }}
    22      {{ $key }}: "{{ $value }}"
    23      {{- end }}
    24      {{- end }}
    25    annotations:
    26      {{- with .Metadata.Annotations }}
    27      {{- range $key, $value := . }}
    28      {{ $key }}: "{{ $value }}"
    29      {{- end }}
    30      {{- end }}
    31  spec:
    32    replicas: {{ .Spec.Replicas }}
    33    selector:
    34      matchLabels:
    35        {{- with .Spec.Selector.MatchLabels }}
    36        {{- range $key, $value := . }}
    37        {{ $key }}: "{{ $value }}"
    38        {{- end }}
    39        {{- end }}
    40    template:
    41      metadata:
    42        labels:
    43          {{- with .Spec.Template.Metadata.Labels }}
    44          {{- range $key, $value := . }}
    45          {{ $key }}: "{{ $value }}"
    46          {{- end }}
    47          {{- end }}
    48        annotations:
    49          {{- with .Spec.Template.Metadata.Annotations }}
    50          {{- range $key, $value := . }}
    51          {{ $key }}: "{{ $value }}"
    52          {{- end }}
    53          {{- end }}
    54      spec: 
    55        serviceAccountName: {{ .Spec.Template.PodSpec.ServiceAccountName }}
    56        containers:
    57        {{- with .Spec.Template.PodSpec.Containers }}
    58        {{- range . }}
    59          - name: {{ .Name }}
    60            env:
    61            {{- with .Env }}
    62            {{- range . }}
    63            - name: "{{ .Name }}"
    64              value: "{{ .Value }}"
    65            {{- end }}
    66            {{- end }}
    67            args:
    68            {{- range .Args }}
    69            - {{.}}
    70            {{- end }}
    71            command:
    72            {{- range .Command }}
    73            - {{.}}
    74            {{- end }}
    75            image: {{ .Image }}
    76            ports:
    77            {{- with .Ports }}
    78            {{- range . }}
    79            - containerPort: {{ .ContainerPort }}
    80              name: {{ .Name }}
    81            {{- end}}
    82            {{- end}}
    83        {{- end }}
    84        {{- end}}
    85  `
    86  
    87  var serviceTmpl = `
    88  apiVersion: v1
    89  kind: Service
    90  metadata:
    91    name: "{{ .Metadata.Name }}"
    92    namespace: "{{ .Metadata.Namespace }}"
    93    labels:
    94      {{- with .Metadata.Labels }}
    95      {{- range $key, $value := . }}
    96      {{ $key }}: "{{ $value }}"
    97      {{- end }}
    98      {{- end }}
    99  spec:
   100    selector:
   101      {{- with .Spec.Selector }}
   102      {{- range $key, $value := . }}
   103      {{ $key }}: "{{ $value }}"
   104      {{- end }}
   105      {{- end }}
   106    ports:
   107    {{- with .Spec.Ports }}
   108    {{- range . }}
   109    - name: "{{ .Name }}"
   110      port: {{ .Port }}
   111      protocol: {{ .Protocol }}
   112    {{- end }}
   113    {{- end }}
   114  `
   115  
   116  var namespaceTmpl = `
   117  apiVersion: v1
   118  kind: Namespace
   119  metadata:
   120    name: "{{ .Metadata.Name }}"
   121    labels:
   122      {{- with .Metadata.Labels }}
   123      {{- range $key, $value := . }}
   124      {{ $key }}: "{{ $value }}"
   125      {{- end }}
   126      {{- end }}
   127  `
   128  
   129  var secretTmpl = `
   130  apiVersion: v1
   131  kind: Secret
   132  type: "{{ .Type }}"
   133  metadata:
   134    name: "{{ .Metadata.Name }}"
   135    namespace: "{{ .Metadata.Namespace }}"
   136    labels:
   137      {{- with .Metadata.Labels }}
   138      {{- range $key, $value := . }}
   139      {{ $key }}: "{{ $value }}"
   140      {{- end }}
   141      {{- end }}
   142  data:
   143    {{- with .Data }}
   144    {{- range $key, $value := . }}
   145    {{ $key }}: "{{ $value }}"
   146    {{- end }}
   147    {{- end }}
   148  `
   149  
   150  var serviceAccountTmpl = `
   151  apiVersion: v1
   152  kind: ServiceAccount
   153  metadata:
   154    name: "{{ .Metadata.Name }}"
   155    labels:
   156      {{- with .Metadata.Labels }}
   157      {{- range $key, $value := . }}
   158      {{ $key }}: "{{ $value }}"
   159      {{- end }}
   160      {{- end }}
   161  imagePullSecrets:
   162  {{- with .ImagePullSecrets }}
   163  {{- range . }}
   164  - name: "{{ .Name }}"
   165  {{- end }}
   166  {{- end }}
   167  `