specs

package
v0.0.0-...-9ec3720 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: AGPL-3.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainerConfigToK8sEnvConfig

func ContainerConfigToK8sEnvConfig(cc specs.ContainerConfig) (envVars []core.EnvVar, envFromSources []core.EnvFromSource, err error)

ContainerConfigToK8sEnvConfig converts ContainerConfig to k8s format for container value mount.

func IntOrStringToK8s

func IntOrStringToK8s(in specs.IntOrString) *intstr.IntOrString

IntOrStringToK8s converts IntOrString to k8s version.

func ParsePodSpec

func ParsePodSpec(in string) (*specs.PodSpec, error)

ParsePodSpec parses a YAML file which defines how to configure a CAAS pod. We allow for generic container set up plus k8s select specific features.

func ParseRawK8sSpec

func ParseRawK8sSpec(in string) (string, error)

ParseRawK8sSpec parses a k8s format of YAML file which defines how to configure a CAAS pod. We allow for generic container set up plus k8s select specific features.

Types

type APIVersion

type APIVersion string

APIVersion defines the k8s API version to use.

const (
	// K8sWebhookV1Beta1 defines the v1beta1 API version for webhook resources.
	K8sWebhookV1Beta1 APIVersion = "v1beta1"

	// K8sWebhookV1 defines the v1 API version for webhook resources.
	K8sWebhookV1 APIVersion = "v1"
)
const (
	// K8sCustomResourceDefinitionV1Beta1 defines the v1beta1 API version for custom resource definition.
	K8sCustomResourceDefinitionV1Beta1 APIVersion = "v1beta1"

	// K8sCustomResourceDefinitionV1 defines the v1 API version for custom resource definition.
	K8sCustomResourceDefinitionV1 APIVersion = "v1"
)
const (
	// K8sIngressV1Beta1 defines the v1beta1 API version for ingress.
	K8sIngressV1Beta1 APIVersion = "v1beta1"

	// K8sIngressV1 defines the v1 API version for ingress.
	K8sIngressV1 APIVersion = "v1"
)

type BindingMetaGetter

type BindingMetaGetter func(sa, roleOrClusterRole NameGetter) v1.ObjectMeta

BindingMetaGetter generates ObjectMeta for role bindings, cluster role bindings.

type DeployerInterface

type DeployerInterface interface {
	Deploy(context.Context, string, bool) error
}

DeployerInterface defines method to deploy a raw k8s spec.

func New

func New(
	deploymentName string,
	namespace string,
	deploymentParams caas.DeploymentParams,
	cfg *rest.Config,
	labelGetter func(isNamespaced bool) map[string]string,
	annotations k8sannotations.Annotation,
	newRestClient NewK8sRestClientFunc,
) DeployerInterface

New constructs deployer interface.

type K8sContainerSpec

type K8sContainerSpec struct {
	LivenessProbe   *core.Probe           `json:"livenessProbe,omitempty" yaml:"livenessProbe,omitempty"`
	ReadinessProbe  *core.Probe           `json:"readinessProbe,omitempty" yaml:"readinessProbe,omitempty"`
	StartupProbe    *core.Probe           `json:"startupProbe,omitempty" yaml:"startupProbe,omitempty"`
	SecurityContext *core.SecurityContext `json:"securityContext,omitempty" yaml:"securityContext,omitempty"`
}

K8sContainerSpec is a subset of v1.Container which defines attributes we expose for charms to set.

func (*K8sContainerSpec) Validate

func (*K8sContainerSpec) Validate() error

Validate validates K8sContainerSpec.

type K8sCustomResourceDefinition

type K8sCustomResourceDefinition struct {
	Meta `json:",inline" yaml:",inline"`
	Spec K8sCustomResourceDefinitionSpec `json:"spec" yaml:"spec"`
}

K8sCustomResourceDefinition defines spec for creating or updating an CustomResourceDefinition resource.

func (K8sCustomResourceDefinition) Validate

func (crd K8sCustomResourceDefinition) Validate() error

Validate validates the spec.

type K8sCustomResourceDefinitionSpec

type K8sCustomResourceDefinitionSpec struct {
	Version     APIVersion
	SpecV1Beta1 apiextensionsv1beta1.CustomResourceDefinitionSpec
	SpecV1      apiextensionsv1.CustomResourceDefinitionSpec
}

K8sCustomResourceDefinitionSpec defines the spec details of CustomResourceDefinition with the API version.

func (K8sCustomResourceDefinitionSpec) MarshalJSON

func (crdSpecs K8sCustomResourceDefinitionSpec) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface.

func (*K8sCustomResourceDefinitionSpec) UnmarshalJSON

func (crdSpecs *K8sCustomResourceDefinitionSpec) UnmarshalJSON(value []byte) (err error)

UnmarshalJSON implements the json.Unmarshaller interface.

func (K8sCustomResourceDefinitionSpec) Validate

func (crdSpecs K8sCustomResourceDefinitionSpec) Validate(name string) error

Validate validates the spec.

type K8sIngress

type K8sIngress struct {
	Meta `json:",inline" yaml:",inline"`
	Spec K8sIngressSpec `json:"spec" yaml:"spec"`
}

K8sIngress defines spec for creating or updating an ingress resource.

func (K8sIngress) Validate

func (ing K8sIngress) Validate() error

Validate returns an error if the spec is not valid.

type K8sIngressSpec

type K8sIngressSpec struct {
	Version     APIVersion
	SpecV1Beta1 networkingv1beta1.IngressSpec
	SpecV1      networkingv1.IngressSpec
}

K8sIngressSpec defines the spec details of the Ingress with the API version.

func (K8sIngressSpec) MarshalJSON

func (ing K8sIngressSpec) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface.

func (*K8sIngressSpec) UnmarshalJSON

func (ing *K8sIngressSpec) UnmarshalJSON(value []byte) (err error)

UnmarshalJSON implements the json.Unmarshaller interface.

type K8sMutatingWebhook

type K8sMutatingWebhook struct {
	Meta     `json:",inline" yaml:",inline"`
	Webhooks []K8sMutatingWebhookSpec `json:"webhooks" yaml:"webhooks"`
}

K8sMutatingWebhook defines spec for creating or updating an MutatingWebhook resource.

func (*K8sMutatingWebhook) APIVersion

func (w *K8sMutatingWebhook) APIVersion() APIVersion

APIVersion returns the API version.

func (K8sMutatingWebhook) Validate

func (w K8sMutatingWebhook) Validate() error

Validate validates the spec.

type K8sMutatingWebhookSpec

type K8sMutatingWebhookSpec struct {
	Version     APIVersion
	SpecV1Beta1 admissionregistrationv1beta1.MutatingWebhook
	SpecV1      admissionregistrationv1.MutatingWebhook
}

K8sMutatingWebhookSpec defines the spec details of MutatingWebhook with the API version.

func (K8sMutatingWebhookSpec) MarshalJSON

func (wh K8sMutatingWebhookSpec) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface.

func (*K8sMutatingWebhookSpec) UnmarshalJSON

func (wh *K8sMutatingWebhookSpec) UnmarshalJSON(value []byte) (err error)

UnmarshalJSON implements the json.Unmarshaller interface. NOTE: try v1beta1 first then v1 because admissionregistrationv1 and admissionregistrationv1beta1 have the same struct but some fields might have different required values. To avoid breaking existing workloads, we will consider to switch v1 as higher priority in 2.9 instead.

type K8sPodSpec

type K8sPodSpec = K8sPodSpecV3

K8sPodSpec is the current k8s pod spec.

type K8sPodSpecV2

type K8sPodSpecV2 struct {
	// k8s resources.
	KubernetesResources *KubernetesResourcesV2 `json:"kubernetesResources,omitempty" yaml:"kubernetesResources,omitempty"`
}

K8sPodSpecV2 is a subset of v1.PodSpec which defines attributes we expose for charms to set.

func (*K8sPodSpecV2) Validate

func (p *K8sPodSpecV2) Validate() error

Validate is defined on ProviderPod.

type K8sPodSpecV3

type K8sPodSpecV3 struct {
	// k8s resources.
	KubernetesResources *KubernetesResources `json:"kubernetesResources,omitempty" yaml:"kubernetesResources,omitempty"`
}

K8sPodSpecV3 is a subset of v1.PodSpec which defines attributes we expose for charms to set.

func (*K8sPodSpecV3) Validate

func (p *K8sPodSpecV3) Validate() error

Validate is defined on ProviderPod.

type K8sRBACResources

type K8sRBACResources struct {
	K8sRBACSpecConverter
	ServiceAccounts []K8sServiceAccountSpec `json:"serviceAccounts,omitempty" yaml:"serviceAccounts,omitempty"`
}

K8sRBACResources defines a spec for creating RBAC resources.

func PrimeServiceAccountToK8sRBACResources

func PrimeServiceAccountToK8sRBACResources(spec specs.PrimeServiceAccountSpecV3) (*K8sRBACResources, error)

PrimeServiceAccountToK8sRBACResources converts PrimeServiceAccount to K8sRBACResources.

func (K8sRBACResources) ToK8s

func (ks K8sRBACResources) ToK8s(
	getSaMeta ServiceAccountMetaGetter,
	getRoleMeta, getClusterRoleMeta RoleMetaGetter,
	getBindingMeta, getClusterBindingMeta BindingMetaGetter,
) (
	serviceAccounts []core.ServiceAccount,
	roles []rbacv1.Role,
	clusterroles []rbacv1.ClusterRole,
	roleBindings []rbacv1.RoleBinding,
	clusterRoleBindings []rbacv1.ClusterRoleBinding,
)

ToK8s converts modelled RBAC specs to k8s specs.

func (K8sRBACResources) Validate

func (ks K8sRBACResources) Validate() error

Validate validates the spec.

type K8sRBACSpecConverter

type K8sRBACSpecConverter interface {
	ToK8s(
		getSaMeta ServiceAccountMetaGetter,
		getRoleMeta, getClusterRoleMeta RoleMetaGetter,
		getBindingMeta, getClusterBindingMeta BindingMetaGetter,
	) (
		[]core.ServiceAccount,
		[]rbacv1.Role,
		[]rbacv1.ClusterRole,
		[]rbacv1.RoleBinding,
		[]rbacv1.ClusterRoleBinding,
	)
}

K8sRBACSpecConverter has a method to convert modelled RBAC spec to k8s spec.

type K8sSecret

type K8sSecret struct {
	Name        string            `json:"name" yaml:"name"`
	Type        core.SecretType   `json:"type" yaml:"type"`
	Annotations map[string]string `json:"annotations,omitempty"`
	Data        map[string]string `json:"data,omitempty" yaml:"data,omitempty"`
	StringData  map[string]string `json:"stringData,omitempty" yaml:"stringData,omitempty"`
}

K8sSecret is a subset of v1.Secret which defines attributes we expose for charms to set.

type K8sService

type K8sService struct {
	Meta `json:",inline" yaml:",inline"`
	Spec core.ServiceSpec `json:"spec" yaml:"spec"`
}

K8sService is a subset of v1.Service which defines attributes we expose for charms to set.

func (K8sService) Validate

func (s K8sService) Validate() error

Validate validates the spec.

type K8sServiceAccountSpec

type K8sServiceAccountSpec struct {
	Name                       string `json:"name" yaml:"name"`
	specs.ServiceAccountSpecV3 `json:",inline" yaml:",inline"`
}

K8sServiceAccountSpec defines spec for referencing or creating additional RBAC resources.

func (K8sServiceAccountSpec) Validate

func (sa K8sServiceAccountSpec) Validate() error

Validate returns an error if the spec is not valid.

type K8sServiceAccountSpecV2

type K8sServiceAccountSpecV2 struct {
	Name                       string `json:"name" yaml:"name"`
	specs.ServiceAccountSpecV2 `json:",inline" yaml:",inline"`
}

K8sServiceAccountSpecV2 defines spec for referencing or creating a service account for version 2.

func (K8sServiceAccountSpecV2) Validate

func (ksa K8sServiceAccountSpecV2) Validate() error

Validate returns an error if the spec is not valid.

type K8sValidatingWebhook

type K8sValidatingWebhook struct {
	Meta     `json:",inline" yaml:",inline"`
	Webhooks []K8sValidatingWebhookSpec `json:"webhooks" yaml:"webhooks"`
}

K8sValidatingWebhook defines spec for creating or updating an ValidatingWebhook resource.

func (*K8sValidatingWebhook) APIVersion

func (w *K8sValidatingWebhook) APIVersion() APIVersion

APIVersion returns the API version.

func (*K8sValidatingWebhook) Validate

func (w *K8sValidatingWebhook) Validate() error

Validate validates the spec.

type K8sValidatingWebhookSpec

type K8sValidatingWebhookSpec struct {
	Version     APIVersion
	SpecV1Beta1 admissionregistrationv1beta1.ValidatingWebhook
	SpecV1      admissionregistrationv1.ValidatingWebhook
}

K8sValidatingWebhookSpec defines the spec details of ValidatingWebhook with the API version.

func (K8sValidatingWebhookSpec) MarshalJSON

func (wh K8sValidatingWebhookSpec) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface.

func (*K8sValidatingWebhookSpec) UnmarshalJSON

func (wh *K8sValidatingWebhookSpec) UnmarshalJSON(value []byte) (err error)

UnmarshalJSON implements the json.Unmarshaller interface. NOTE: try v1beta1 first then v1 because admissionregistrationv1 and admissionregistrationv1beta1 have the same struct but some fields might have different required values. To avoid breaking existing workloads, we will consider to switch v1 as higher priority in 2.9 instead.

type KubernetesResources

type KubernetesResources struct {
	Pod *PodSpec `json:"pod,omitempty" yaml:"pod,omitempty"`

	Secrets                   []K8sSecret                            `json:"secrets" yaml:"secrets"`
	Services                  []K8sService                           `json:"services" yaml:"services"`
	CustomResourceDefinitions []K8sCustomResourceDefinition          `json:"customResourceDefinitions" yaml:"customResourceDefinitions"`
	CustomResources           map[string][]unstructured.Unstructured `json:"customResources,omitempty" yaml:"customResources,omitempty"`

	MutatingWebhookConfigurations   []K8sMutatingWebhook   `json:"mutatingWebhookConfigurations,omitempty" yaml:"mutatingWebhookConfigurations,omitempty"`
	ValidatingWebhookConfigurations []K8sValidatingWebhook `json:"validatingWebhookConfigurations,omitempty" yaml:"validatingWebhookConfigurations,omitempty"`

	K8sRBACResources `json:",inline" yaml:",inline"`

	IngressResources []K8sIngress `json:"ingressResources,omitempty" yaml:"ingressResources,omitempty"`
}

KubernetesResources is the k8s related resources.

func (*KubernetesResources) Validate

func (krs *KubernetesResources) Validate() error

Validate is defined on ProviderPod.

type KubernetesResourcesV2

type KubernetesResourcesV2 struct {
	Pod *PodSpec `json:"pod,omitempty" yaml:"pod,omitempty"`

	Secrets                   []K8sSecret                                                  `json:"secrets" yaml:"secrets"`
	CustomResourceDefinitions map[string]apiextensionsv1beta1.CustomResourceDefinitionSpec `json:"customResourceDefinitions,omitempty" yaml:"customResourceDefinitions,omitempty"`
	CustomResources           map[string][]unstructured.Unstructured                       `json:"customResources,omitempty" yaml:"customResources,omitempty"`

	MutatingWebhookConfigurations   map[string][]admissionregistration.MutatingWebhook   `json:"mutatingWebhookConfigurations,omitempty" yaml:"mutatingWebhookConfigurations,omitempty"`
	ValidatingWebhookConfigurations map[string][]admissionregistration.ValidatingWebhook `json:"validatingWebhookConfigurations,omitempty" yaml:"validatingWebhookConfigurations,omitempty"`

	ServiceAccounts  []K8sServiceAccountSpecV2 `json:"serviceAccounts,omitempty" yaml:"serviceAccounts,omitempty"`
	IngressResources []K8sIngress              `json:"ingressResources,omitempty" yaml:"ingressResources,omitempty"`
}

KubernetesResourcesV2 is the k8s related resources for version 2.

func (*KubernetesResourcesV2) Validate

func (krs *KubernetesResourcesV2) Validate() error

Validate is defined on ProviderPod.

type Meta

type Meta struct {
	Name        string            `json:"name" yaml:"name"`
	Labels      map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
	Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
}

Meta defines fields for constructing k8s spec ObjectMeta field.

func (Meta) Validate

func (m Meta) Validate() error

Validate validates the spec.

type NameGetter

type NameGetter interface {
	GetName() string
}

NameGetter defines method to get the name from the resource.

type NewK8sRestClientFunc

type NewK8sRestClientFunc func(c *rest.Config) (rest.Interface, error)

NewK8sRestClientFunc defines a function which returns a k8s rest client based on the supplied config.

type PodSpec

type PodSpec struct {
	Labels                        map[string]string        `json:"labels,omitempty" yaml:"labels,omitempty"`
	Annotations                   annotations.Annotation   `json:"annotations,omitempty" yaml:"annotations,omitempty"`
	RestartPolicy                 core.RestartPolicy       `json:"restartPolicy,omitempty" yaml:"restartPolicy,omitempty"`
	ActiveDeadlineSeconds         *int64                   `json:"activeDeadlineSeconds,omitempty" yaml:"activeDeadlineSeconds,omitempty"`
	TerminationGracePeriodSeconds *int64                   `json:"terminationGracePeriodSeconds,omitempty" yaml:"terminationGracePeriodSeconds,omitempty"`
	SecurityContext               *core.PodSecurityContext `json:"securityContext,omitempty" yaml:"securityContext,omitempty"`
	ReadinessGates                []core.PodReadinessGate  `json:"readinessGates,omitempty" yaml:"readinessGates,omitempty"`
	DNSPolicy                     core.DNSPolicy           `json:"dnsPolicy,omitempty" yaml:"dnsPolicy,omitempty"`
	HostNetwork                   bool                     `json:"hostNetwork,omitempty" yaml:"hostNetwork,omitempty"`
	HostPID                       bool                     `json:"hostPID,omitempty" yaml:"hostPID,omitempty"`
	PriorityClassName             string                   `json:"priorityClassName,omitempty"`
	Priority                      *int32                   `json:"priority,omitempty"`
}

PodSpec is a subset of v1.PodSpec which defines attributes we expose for charms to set.

func (PodSpec) IsEmpty

func (ps PodSpec) IsEmpty() bool

IsEmpty checks if PodSpec is empty or not.

type PodSpecConverter

type PodSpecConverter interface {
	Validate() error
	ToLatest() *specs.PodSpec
}

PodSpecConverter defines methods to validate and convert a specific version of podspec to latest version.

type PodSpecWithAnnotations

type PodSpecWithAnnotations struct {
	Labels      map[string]string
	Annotations annotations.Annotation
	core.PodSpec
}

PodSpecWithAnnotations wraps a k8s podspec to add annotations and labels.

type RoleMetaGetter

type RoleMetaGetter func(roleName, serviceAccountName string, index int) v1.ObjectMeta

RoleMetaGetter generates ObjectMeta for roles, cluster roles.

type ServiceAccountMetaGetter

type ServiceAccountMetaGetter func(rawName string) v1.ObjectMeta

ServiceAccountMetaGetter generates ObjectMeta for service accounts.

type YAMLOrJSONDecoder

type YAMLOrJSONDecoder struct {
	// contains filtered or unexported fields
}

YAMLOrJSONDecoder attempts to decode a stream of JSON documents or YAML documents by sniffing for a leading { character.

func (*YAMLOrJSONDecoder) Decode

func (d *YAMLOrJSONDecoder) Decode(into interface{}) error

Decode unmarshals the next object from the underlying stream into the provide object, or returns an error.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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