Runtime: Add Kubernetes ServiceAccounts & Remove imagePullSecrets

This commit is contained in:
Ben Toogood
2020-04-27 14:13:51 +01:00
parent 434997e676
commit 494e0b5060
9 changed files with 84 additions and 91 deletions

View File

@@ -163,7 +163,7 @@ func (r *Request) request() (*http.Request, error) {
case "namespace":
// /api/v1/namespaces/
url = fmt.Sprintf("%s/api/v1/namespaces/", r.host)
case "pod", "service", "endpoint":
case "pod", "service", "endpoint", "serviceaccount":
// /api/v1/namespaces/{namespace}/pods
url = fmt.Sprintf("%s/api/v1/namespaces/%s/%ss/", r.host, r.namespace, r.resource)
case "deployment":

View File

@@ -312,6 +312,7 @@ func NewDeployment(name, version, typ, namespace string) *Deployment {
Template: &Template{
Metadata: Metadata,
PodSpec: &PodSpec{
ServiceAccountName: namespace,
Containers: []Container{{
Name: name,
Image: DefaultImage,

View File

@@ -1,9 +1,10 @@
package client
var templates = map[string]string{
"deployment": deploymentTmpl,
"service": serviceTmpl,
"namespace": namespaceTmpl,
"deployment": deploymentTmpl,
"service": serviceTmpl,
"namespace": namespaceTmpl,
"serviceaccount": serviceAccountTmpl,
}
// stripped image pull policy always
@@ -49,13 +50,8 @@ spec:
{{ $key }}: "{{ $value }}"
{{- end }}
{{- end }}
spec:
imagePullSecrets:
{{- with .Spec.Template.PodSpec.ImagePullSecrets }}
{{- range . }}
- name: "{{ .Name }}"
{{- end }}
{{- end }}
spec:
serviceAccountName: {{ .Spec.Template.PodSpec.ServiceAccountName }}
containers:
{{- with .Spec.Template.PodSpec.Containers }}
{{- range . }}
@@ -128,3 +124,22 @@ metadata:
{{- end }}
{{- end }}
`
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 }}
`

View File

@@ -93,8 +93,8 @@ type Metadata struct {
// PodSpec is a pod
type PodSpec struct {
Containers []Container `json:"containers"`
ImagePullSecrets []ImagePullSecret `json:"imagePullSecrets"`
Containers []Container `json:"containers"`
ServiceAccountName string `json:"serviceAccountName"`
}
// PodList
@@ -194,3 +194,9 @@ type NamespaceList struct {
type ImagePullSecret struct {
Name string `json:"name"`
}
// ServiceAccount
type ServiceAccount struct {
Metadata *Metadata `json:"metadata,omitempty"`
ImagePullSecrets []ImagePullSecret `json:"imagePullSecrets,omitempty"`
}