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

View File

@ -4,6 +4,7 @@ var templates = map[string]string{
"deployment": deploymentTmpl, "deployment": deploymentTmpl,
"service": serviceTmpl, "service": serviceTmpl,
"namespace": namespaceTmpl, "namespace": namespaceTmpl,
"secret": secretTmpl,
"serviceaccount": serviceAccountTmpl, "serviceaccount": serviceAccountTmpl,
} }
@ -125,6 +126,26 @@ metadata:
{{- end }} {{- 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 = ` var serviceAccountTmpl = `
apiVersion: v1 apiVersion: v1
kind: ServiceAccount kind: ServiceAccount

View File

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