cluster

package
v0.0.0-...-20989ac Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const KnativeServiceLabelKey = "serving.knative.dev/service"

Default values for Knative related resources

View Source
const KnativeUserContainerName = "user-container"
View Source
const (
	// ServiceAccountFileName is the name of the service account
	ServiceAccountFileName = "service-account.json"
)

Variables

View Source
var DefaultSparkDriverRoleRules = []apirbacv1.PolicyRule{
	{

		APIGroups: []string{
			"",
		},
		Resources: []string{
			"pods",
		},
		Verbs: []string{
			"*",
		},
	},
	{

		APIGroups: []string{
			"",
		},
		Resources: []string{
			"services",
		},
		Verbs: []string{
			"*",
		},
	},
}

DefaultSparkDriverRoleRules is the default spark required policies

View Source
var (
	ErrNamespaceAlreadyExists = errors.New("namespace already exists")
)

Functions

func InitClusterControllers

func InitClusterControllers(
	cfg *config.Config,
	environmentClusterMap map[string]string,
	vaultClient vault.VaultClient,
) (map[string]Controller, error)

InitClusterControllers takes in the the app config and a vault client and uses the credentials from vault to initialize one cluster controller per environment and returns a map where the key is the env name and the value is the corresponding controller.

Types

type BaseService

type BaseService struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
	Image     string `json:"image"`

	// Resources
	CPURequests    resource.Quantity `json:"cpu_requests"`
	MemoryRequests resource.Quantity `json:"memory_requests"`

	// Health Checks
	ProbePort             int32  `json:"probe_port"`
	LivenessHTTPGetPath   string `json:"liveness_path"`
	ReadinessHTTPGetPath  string `json:"readiness_path"`
	ProbeInitDelaySeconds int32  `json:"probe_delay_seconds"`

	// Env vars
	Envs []corev1.EnvVar `json:"envs"`

	// Labels
	Labels map[string]string `json:"labels"`

	ConfigMap *ConfigMap

	PersistentVolumeClaim *PersistentVolumeClaim `json:"persistent_volume_claim"`

	// Volumes
	Volumes      []corev1.Volume      `json:"volumes"`
	VolumeMounts []corev1.VolumeMount `json:"volume_mounts"`
}

BaseService defines the common properties of services that can be speficied for its deployment by the cluster controller

type ConfigMap

type ConfigMap struct {
	Name     string            `json:"name"`
	FileName string            `json:"file_name"`
	Data     string            `json:"data"`
	Labels   map[string]string `json:"labels"`
}

ConfigMap contains information to create a config map

type Container

type Container struct {
	Name         string
	Image        string
	Args         []string
	VolumeMounts []VolumeMount
	Envs         []Env
	Resources    RequestLimitResources
}

Container contains the Kubernetes Container to be deployed

func (*Container) Build

func (c *Container) Build() corev1.Container

Build converts the spec into a Kubernetes spec

type Controller

type Controller interface {
	DeployKnativeService(ctx context.Context, svc *KnativeService) error
	DeleteKnativeService(ctx context.Context, svcName string, namespace string, ignoreNotFound bool) error
	GetKnativeServiceURL(ctx context.Context, svcName string, namespace string) string
	ApplyIstioVirtualService(ctx context.Context, routerEndpoint *VirtualService) error
	DeleteIstioVirtualService(ctx context.Context, svcName string, namespace string) error
	DeployKubernetesService(ctx context.Context, svc *KubernetesService) error
	DeleteKubernetesDeployment(ctx context.Context, name string, namespace string, ignoreNotFound bool) error
	DeleteKubernetesService(ctx context.Context, svcName string, namespace string, ignoreNotFound bool) error
	CreateNamespace(ctx context.Context, name string) error
	ApplyConfigMap(ctx context.Context, namespace string, configMap *ConfigMap) error
	DeleteConfigMap(ctx context.Context, name string, namespace string, ignoreNotFound bool) error
	CreateSecret(ctx context.Context, secret *Secret) error
	DeleteSecret(ctx context.Context, secretName string, namespace string, ignoreNotFound bool) error
	ApplyPersistentVolumeClaim(ctx context.Context, namespace string, pvc *PersistentVolumeClaim) error
	DeletePersistentVolumeClaim(ctx context.Context, pvcName string, namespace string, ignoreNotFound bool) error
	ListPods(ctx context.Context, namespace string, labelSelector string) (*apicorev1.PodList, error)
	ListPodLogs(ctx context.Context, namespace string,
		podName string, opts *apicorev1.PodLogOptions) (io.ReadCloser, error)
	CreateJob(ctx context.Context, namespace string, job Job) (*apibatchv1.Job, error)
	GetJob(ctx context.Context, namespace string, jobName string) (*apibatchv1.Job, error)
	DeleteJob(ctx context.Context, namespace string, jobName string) error
	CreateServiceAccount(ctx context.Context, namespace string,
		serviceAccount *ServiceAccount) (*apicorev1.ServiceAccount, error)
	CreateRole(ctx context.Context, namespace string, role *Role) (*apirbacv1.Role, error)
	CreateRoleBinding(ctx context.Context, namespace string, roleBinding *RoleBinding) (*apirbacv1.RoleBinding, error)
	CreateSparkApplication(ctx context.Context, namespace string,
		request *CreateSparkRequest) (*apisparkv1beta2.SparkApplication, error)
	GetSparkApplication(ctx context.Context, namespace, appName string) (*apisparkv1beta2.SparkApplication, error)
	DeleteSparkApplication(ctx context.Context, namespace, appName string) error
}

Controller defines the operations supported by the cluster controller

type CreateSparkRequest

type CreateSparkRequest struct {
	JobName               string
	JobLabels             map[string]string
	JobImageRef           string
	JobApplicationPath    string
	JobArguments          []string
	JobConfigMount        string
	DriverCPURequest      string
	DriverMemoryRequest   string
	ExecutorCPURequest    string
	ExecutorMemoryRequest string
	ExecutorReplica       int32
	ServiceAccountName    string
	SparkInfraConfig      *config.SparkAppConfig
	EnvVars               *[]openapi.EnvVar
}

CreateSparkRequest is the request for creating a spark driver

type Env

type Env struct {
	Name  string
	Value string
}

Env is a Kubernetes environment variable

func (*Env) Build

func (e *Env) Build() corev1.EnvVar

Build converts the spec into a Kubernetes spec

type Job

type Job struct {
	Name                    string
	Namespace               string
	Labels                  map[string]string
	Completions             *int32
	BackOffLimit            *int32
	TTLSecondsAfterFinished *int32
	RestartPolicy           corev1.RestartPolicy
	Containers              []Container
	SecretVolumes           []SecretVolume
}

Job contains the information to build a Kubernetes Job object

func (*Job) Build

func (j *Job) Build() *batchv1.Job

Build converts the spec into a Kubernetes spec

type KnativeService

type KnativeService struct {
	*BaseService

	IsClusterLocal bool  `json:"is_cluster_local"`
	ContainerPort  int32 `json:"containerPort"`

	// Autoscaling properties
	MinReplicas       int `json:"minReplicas"`
	MaxReplicas       int `json:"maxReplicas"`
	TargetConcurrency int `json:"targetConcurrency"`

	// Resource properties
	QueueProxyResourcePercentage    int     `json:"queueProxyResourcePercentage"`
	UserContainerLimitRequestFactor float64 `json:"userContainerLimitRequestFactor"`
}

KnativeService defines the properties for Knative services

func (*KnativeService) BuildKnativeServiceConfig

func (cfg *KnativeService) BuildKnativeServiceConfig() *knservingv1.Service

Creates a new config object compatible with the knative serving API, from the given config

type KubernetesService

type KubernetesService struct {
	*BaseService

	InitContainers  []Container                `json:"init_containers"`
	Command         []string                   `json:"command"`
	Args            []string                   `json:"args"`
	Replicas        int                        `json:"replicas"`
	Ports           []Port                     `json:"ports"`
	SecurityContext *corev1.PodSecurityContext `json:"security_context"`
}

KubernetesService defines the properties for Kubernetes services

func (*KubernetesService) BuildKubernetesServiceConfig

func (cfg *KubernetesService) BuildKubernetesServiceConfig() (*appsv1.Deployment, *corev1.Service)

type NameValuePair

type NameValuePair struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

NameValuePair captures a pair of name and value TODO: DATA-2094: This may no longer be necessary

type PersistentVolumeClaim

type PersistentVolumeClaim struct {
	Name        string            `json:"name"`
	Namespace   string            `json:"namespace"`
	AccessModes []string          `json:"access_modes"`
	Size        resource.Quantity `json:"size"`
	Labels      map[string]string `json:"labels"`
}

PersistentVolumeClaim contains the information to build a persistent volume claim

func (*PersistentVolumeClaim) BuildPersistentVolumeClaim

func (pvc *PersistentVolumeClaim) BuildPersistentVolumeClaim() *corev1.PersistentVolumeClaim

type Port

type Port struct {
	Name     string `json:"name"`
	Port     int    `json:"port"`
	Protocol string `json:"protocol"`
}

type RequestLimitResources

type RequestLimitResources struct {
	Request Resource
	Limit   Resource
}

RequestLimitResources is a Kubernetes resource request and limits

func (*RequestLimitResources) Build

Build converts the spec into a Kubernetes spec

type Resource

type Resource struct {
	CPU    resource.Quantity
	Memory resource.Quantity
}

Resource is a Kubernetes resource

func (*Resource) Build

func (r *Resource) Build() corev1.ResourceList

Build converts the spec into a Kubernetes spec

type Role

type Role struct {
	Name        string                 `json:"name"`
	Namespace   string                 `json:"namespace"`
	Labels      map[string]string      `json:"labels"`
	PolicyRules []apirbacv1.PolicyRule `json:"rules"`
}

Role contains the information to build a role

func (*Role) BuildRole

func (r *Role) BuildRole() *apirbacv1.Role

type RoleBinding

type RoleBinding struct {
	Name               string            `json:"name"`
	Namespace          string            `json:"namespace"`
	Labels             map[string]string `json:"labels"`
	RoleName           string            `json:"role_name"`
	ServiceAccountName string            `json:"service_account_name"`
}

RoleBinding contains the information to build a role binding

func (*RoleBinding) BuildRoleBinding

func (r *RoleBinding) BuildRoleBinding() *apirbacv1.RoleBinding

type Secret

type Secret struct {
	Name      string
	Namespace string
	Data      map[string]string
	Labels    map[string]string
}

Secret defines a kubernetes secret.

func (*Secret) BuildSecret

func (cfg *Secret) BuildSecret() *corev1.Secret

BuildSecret builds a kubernetes secret from the given config.

type SecretVolume

type SecretVolume struct {
	Name       string
	SecretName string
}

SecretVolume is a Kubernetes volume that mounted by a secret

func (*SecretVolume) Build

func (v *SecretVolume) Build() corev1.Volume

Build converts the spec into a Kubernetes spec

type ServiceAccount

type ServiceAccount struct {
	Name      string            `json:"name"`
	Namespace string            `json:"namespace"`
	Labels    map[string]string `json:"labels"`
}

ServiceAccount contains the information to build a service account

func (*ServiceAccount) BuildServiceAccount

func (sa *ServiceAccount) BuildServiceAccount() *corev1.ServiceAccount

type VirtualService

type VirtualService struct {
	Name             string            `json:"name"`
	Namespace        string            `json:"namespace"`
	Labels           map[string]string `json:"labels"`
	Gateway          string            `json:"gateway"`
	Endpoint         string            `json:"endpoint"`
	DestinationHost  string            `json:"destination_host"`
	HostRewrite      string            `json:"host_rewrite"`
	MatchURIPrefixes []string          `json:"match_uri_prefix"`
}

func (VirtualService) BuildVirtualService

func (cfg VirtualService) BuildVirtualService() *v1beta1.VirtualService

type VolumeMount

type VolumeMount struct {
	Name      string
	MountPath string
}

VolumeMount is a Kubernetes VolumeMount

func (*VolumeMount) Build

func (vm *VolumeMount) Build() corev1.VolumeMount

Build converts the spec into a Kubernetes spec

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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