Add k8s secrets

This commit is contained in:
Ben Toogood 2020-04-27 14:37:28 +01:00
parent 494e0b5060
commit 8d7d6ef358
3 changed files with 31 additions and 3 deletions

View File

@ -163,12 +163,12 @@ 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", "serviceaccount":
// /api/v1/namespaces/{namespace}/pods
url = fmt.Sprintf("%s/api/v1/namespaces/%s/%ss/", r.host, r.namespace, r.resource)
case "deployment":
// /apis/apps/v1/namespaces/{namespace}/deployments/{name}
url = fmt.Sprintf("%s/apis/apps/v1/namespaces/%s/%ss/", r.host, r.namespace, r.resource)
default:
// /api/v1/namespaces/{namespace}/{resource}
url = fmt.Sprintf("%s/api/v1/namespaces/%s/%ss/", r.host, r.namespace, r.resource)
}
// append resourceName if it is present

View File

@ -4,6 +4,7 @@ var templates = map[string]string{
"deployment": deploymentTmpl,
"service": serviceTmpl,
"namespace": namespaceTmpl,
"secret": secretTmpl,
"serviceaccount": serviceAccountTmpl,
}
@ -125,6 +126,26 @@ metadata:
{{- end }}
`
var secretTmpl = `
apiVersion: v1
kind: Secret
metadata:
name: "{{ .Metadata.Name }}"
namespace: "{{ .Metadata.Namespace }}"
labels:
{{- with .Metadata.Labels }}
{{- range $key, $value := . }}
{{ $key }}: "{{ $value }}"
{{- end }}
{{- end }}
data:
{{- with .Data }}
{{- range $key, $value := . }}
{{ $key }}: "{{ $value }}"
{{- end }}
{{- end }}
`
var serviceAccountTmpl = `
apiVersion: v1
kind: ServiceAccount

View File

@ -195,6 +195,13 @@ type ImagePullSecret struct {
Name string `json:"name"`
}
// Secret
type Secret struct {
Type string `json:"type,omitempty"`
Data map[string]string `json:"data"`
Metadata *Metadata `json:"metadata"`
}
// ServiceAccount
type ServiceAccount struct {
Metadata *Metadata `json:"metadata,omitempty"`