kube

package
v0.11.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2019 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DocTemplate = template.Must(template.New("kube_doc").Funcs(templates.Funcs).Parse(`
// +k8s:deepcopy-gen=package,register

/* go:generate command for Kubernetes code-generator currently disabled, run the following manually (or uncomment and remove the minus):
	
- //go:generate $GOPATH/src/k8s.io/code-generator/generate-groups.sh all "{{ .ProjectConfig.GoPackage }}/kube/client" "{{ .ProjectConfig.GoPackage }}/kube/apis" {{ .ProjectConfig.Name }}:{{ .ProjectConfig.Version }}

*/

// Package {{ .ProjectConfig.Version }} is the {{ .ProjectConfig.Version }} version of the API.
// +groupName={{ .ProjectConfig.Name }}
package {{ .ProjectConfig.Version }}

`))
View Source
var RegisterTemplate = template.Must(template.New("kube_doc").Funcs(templates.Funcs).Parse(`package {{ .ProjectConfig.Version }}

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	runtime "k8s.io/apimachinery/pkg/runtime"
	schema "k8s.io/apimachinery/pkg/runtime/schema"
)

var (
	// Package-wide variables from generator "register".
	SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "{{ .ProjectConfig.Version }}"}
	SchemeBuilder      = runtime.NewSchemeBuilder(addKnownTypes)
	localSchemeBuilder = &SchemeBuilder
	AddToScheme        = localSchemeBuilder.AddToScheme
)

const (
	// Package-wide consts from generator "register".
	GroupName = "{{ .ProjectConfig.Name }}"
)

func Resource(resource string) schema.GroupResource {
	return SchemeGroupVersion.WithResource(resource).GroupResource()
}

{{ $project := . }}

func addKnownTypes(scheme *runtime.Scheme) error {
	scheme.AddKnownTypes(SchemeGroupVersion,
{{- range .Resources }}
{{- if resourceBelongsToProject $project . }}
		&{{ .Name }}{},
		&{{ .Name }}List{},
{{- end }}
{{- end }}
	)
	metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
	return nil
}

`))
View Source
var TypesTemplate = template.Must(template.New("kube_types").Funcs(templates.Funcs).Parse(`package {{ .ProjectConfig.Version }}


import (
	"encoding/json"
	"github.com/solo-io/solo-kit/pkg/api/v1/resources/core"
	"github.com/solo-io/solo-kit/pkg/utils/protoutils"

	api "{{ .ProjectConfig.GoPackage }}"
	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type metaOnly struct {
	v1.TypeMeta   {{ backtick }}json:",inline"{{ backtick }}
	v1.ObjectMeta {{ backtick }}json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"{{ backtick }}
}

{{- range .Resources}}
{{- if resourceBelongsToProject $ . }}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +resourceName={{ lowercase (upper_camel .PluralName) }}
{{- if .ClusterScoped }}
// +genclient:nonNamespaced
{{- else }}
// +genclient
{{- end }}
{{- if not .HasStatus }}
// +genclient:noStatus
{{- end }}
type {{ .Name }} struct {
	v1.TypeMeta {{ backtick }}json:",inline"{{ backtick }}
	// +optional
	v1.ObjectMeta {{ backtick }}json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"{{ backtick }}

	// Spec defines the implementation of this definition.
	// +optional
	Spec api.{{ .Name }} {{ backtick }}json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"{{ backtick }}

{{- if .HasStatus }}
	Status core.Status {{ backtick }}json:"status,omitempty" protobuf:"bytes,3,opt,name=status"{{ backtick }}
{{- end }}
}


func (o *{{ .Name }}) MarshalJSON() ([]byte, error) {
	spec, err := protoutils.MarshalMap(&o.Spec)
	if err != nil {
		return nil, err
	}
	delete(spec, "metadata")
{{- if .HasStatus }}
	delete(spec, "status")
{{- end }}
	asMap := map[string]interface{}{
		"metadata":   o.ObjectMeta,
		"apiVersion": o.TypeMeta.APIVersion,
		"kind":       o.TypeMeta.Kind,
{{- if .HasStatus }}
		"status":     o.Status,
{{- end }}
		"spec":       spec,
	}
	return json.Marshal(asMap)
}

func (o *{{ .Name }}) UnmarshalJSON(data []byte) error {
	var metaOnly metaOnly
	if err := json.Unmarshal(data, &metaOnly); err != nil {
		return err
	}
	var spec api.{{ .Name }}
	if err := protoutils.UnmarshalResource(data, &spec); err != nil {
		return err
	}
	*o = {{ .Name }}{
		ObjectMeta: metaOnly.ObjectMeta,
		TypeMeta:   metaOnly.TypeMeta,
		Spec:       spec,
{{- if .HasStatus }}
	    Status:     spec.Status,
{{- end }}
	}

	return nil
}


// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// {{ .Name }}List is a collection of {{ .Name }}s.
type {{ .Name }}List struct {
	v1.TypeMeta {{ backtick }}json:",inline"{{ backtick }}
	// +optional
	v1.ListMeta {{ backtick }}json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"{{ backtick }}
	Items       []{{ .Name }} {{ backtick }}json:"items" protobuf:"bytes,2,rep,name=items"{{ backtick }}
}

{{- end }}
{{- end }}
`))

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL