kubernetes

package
v1.33.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 40 Imported by: 18

Documentation

Index

Constants

View Source
const (
	DefaultMinReplicas       = 1
	DefaultMaxReplicas       = 3
	DefaultCPUUtilization    = 50
	DefaultMemoryUtilization = 70
)

Default values for Horizontal Pod Autoscaler (HPA)

View Source
const (
	// DeploymentController is controller type for Deployment
	DeploymentController = "deployment"
	// DaemonSetController is controller type for DaemonSet
	DaemonSetController = "daemonset"
	// StatefulStateController is controller type for StatefulSet
	StatefulStateController = "statefulset"
)
View Source
const (
	NetworkModeService = "service:"
)
View Source
const PVCRequestSize = "100Mi"

PVCRequestSize (Persistent Volume Claim) has default size

Variables

LabelKeys are the keys for HPA related labels in the service

View Source
var ValidVolumeSet = map[string]struct{}{"emptyDir": {}, "hostPath": {}, "configMap": {}, "persistentVolumeClaim": {}}

ValidVolumeSet has the different types of valid volumes

Functions

func ConfigAffinity added in v1.24.0

func ConfigAffinity(service kobject.ServiceConfig) *api.Affinity

ConfigAffinity configures the Affinity.

func ConfigCapabilities added in v1.23.0

func ConfigCapabilities(service kobject.ServiceConfig) *api.Capabilities

ConfigCapabilities configure POSIX capabilities that can be added or removed to a container

func ConfigEnvs

func ConfigEnvs(service kobject.ServiceConfig, opt kobject.ConvertOptions) ([]api.EnvVar, error)

ConfigEnvs configures the environment variables.

func ConfigPorts

func ConfigPorts(service kobject.ServiceConfig) []api.ContainerPort

ConfigPorts configures the container ports.

func ConfigTopologySpreadConstraints added in v1.26.0

func ConfigTopologySpreadConstraints(service kobject.ServiceConfig) []api.TopologySpreadConstraint

ConfigTopologySpreadConstraints configures the TopologySpreadConstraints.

func DurationStrToSecondsInt added in v0.7.0

func DurationStrToSecondsInt(s string) (*int64, error)

DurationStrToSecondsInt converts duration string to *int64 in seconds

func FormatContainerName added in v1.19.0

func FormatContainerName(name string) string

FormatContainerName format Container name

func FormatEnvName added in v1.3.0

func FormatEnvName(name string, serviceName string) string

FormatEnvName format env name

func FormatFileName added in v1.17.0

func FormatFileName(name string) string

FormatFileName format file name

func FormatResourceName added in v1.23.0

func FormatResourceName(name string) string

FormatResourceName generate a valid k8s resource name

func GetContainerArgs added in v1.28.0

func GetContainerArgs(service kobject.ServiceConfig) []string

GetContainerArgs update the interpolation of env variables if exists. example: [curl, $PROTOCOL://$DOMAIN] => [curl, $(PROTOCOL)://$(DOMAIN)]

func GetContainerName added in v1.26.0

func GetContainerName(service kobject.ServiceConfig) string

GetContainerName returns the name of the container, from the service config object

func GetContentFromFile added in v1.17.0

func GetContentFromFile(file string) (string, error)

GetContentFromFile gets the content from the file..

func GetEnvsFromFile added in v1.3.0

func GetEnvsFromFile(file string) (map[string]string, error)

GetEnvsFromFile get env vars from env_file

func GetFileName added in v1.33.0

func GetFileName(fileName string) string

GetFileName extracts the file name from a given file path or file name. If the input fileName contains a "/", it retrieves the substring after the last "/". The function does not format the file name further, as it may contain periods or other valid characters. Returns the extracted file name.

func GetImagePullPolicy added in v1.21.0

func GetImagePullPolicy(name, policy string) (api.PullPolicy, error)

GetImagePullPolicy get image pull settings

func GetRestartPolicy added in v1.21.0

func GetRestartPolicy(name, restart string) (api.RestartPolicy, error)

GetRestartPolicy ...

func KomposeObjectToServiceConfigGroupMapping added in v1.23.0

func KomposeObjectToServiceConfigGroupMapping(komposeObject *kobject.KomposeObject, opt kobject.ConvertOptions) map[string]kobject.ServiceConfigGroup

KomposeObjectToServiceConfigGroupMapping returns the service config group by name or by volume This group function works as following

  1. Support two mode (1): label: use a custom label, the service that contains it will be merged to one workload. (2): volume: the service that share to exactly same volume config will be merged to one workload. If use pvc, only create one for this group.
  2. If service containers restart policy and no workload argument provide and it's restart policy looks like a pod, then this service should generate a pod. If group mode specified, it should be grouped and ignore the restart policy.
  3. If group mode specified, port conflict between services in one group will be ignored, and multiple service should be created.
  4. If `volume` group mode specified, we don't have an appropriate name for this combined service, use the first one for now. A warn/info message should be printed to let the user know.

func PrintList

func PrintList(objects []runtime.Object, opt kobject.ConvertOptions) error

PrintList will take the data converted and decide on the commandline attributes given

func SetVolumeMountPaths added in v1.23.0

func SetVolumeMountPaths(volumesMount []api.VolumeMount) mapset.Set

SetVolumeMountPaths method returns a set of volumes mount path

func SetVolumeNames added in v1.23.0

func SetVolumeNames(volumes []api.Volume) mapset.Set

SetVolumeNames method return a set of volume names

func SortedKeys added in v0.7.0

func SortedKeys[V kobject.ServiceConfig | kobject.ServiceConfigGroup](serviceConfig map[string]V) []string

SortedKeys Ensure the kubernetes objects are in a consistent order

func TranslatePodResource added in v1.21.0

func TranslatePodResource(service *kobject.ServiceConfig, template *api.PodTemplateSpec)

TranslatePodResource config pod resources

Types

type DeploymentMapping added in v1.33.0

type DeploymentMapping struct {
	SourceDeploymentName string
	TargetDeploymentName string
}

type HpaValues added in v1.33.0

type HpaValues struct {
	MinReplicas       int32
	MaxReplicas       int32
	CPUtilization     int32
	MemoryUtilization int32
}

type Kubernetes

type Kubernetes struct {
	// the user provided options from the command line
	Opt kobject.ConvertOptions
}

Kubernetes implements Transformer interface and represents Kubernetes transformer

func (*Kubernetes) CheckUnsupportedKey added in v0.2.0

func (k *Kubernetes) CheckUnsupportedKey(komposeObject *kobject.KomposeObject, unsupportedKey map[string]bool) []string

CheckUnsupportedKey checks if given komposeObject contains keys that are not supported by this transformer. list of all unsupported keys are stored in unsupportedKey variable returns list of TODO: ....

func (*Kubernetes) ConfigConfigMapVolumeSource added in v1.21.0

func (k *Kubernetes) ConfigConfigMapVolumeSource(cmName string, targetPath string, cm *api.ConfigMap) *api.VolumeSource

ConfigConfigMapVolumeSource config a configmap to use as volume source

func (*Kubernetes) ConfigEmptyVolumeSource added in v0.1.2

func (k *Kubernetes) ConfigEmptyVolumeSource(key string) *api.VolumeSource

ConfigEmptyVolumeSource is helper function to create an EmptyDir api.VolumeSource either for Tmpfs or for emptyvolumes

func (*Kubernetes) ConfigHostPathVolumeSource added in v1.11.0

func (k *Kubernetes) ConfigHostPathVolumeSource(path string) (*api.VolumeSource, error)

ConfigHostPathVolumeSource is a helper function to create a HostPath api.VolumeSource

func (*Kubernetes) ConfigLBServicePorts added in v1.23.0

func (k *Kubernetes) ConfigLBServicePorts(service kobject.ServiceConfig) ([]api.ServicePort, []api.ServicePort)

ConfigLBServicePorts method configure the ports of the k8s Load Balancer Service

func (*Kubernetes) ConfigPVCVolumeSource added in v0.1.2

func (k *Kubernetes) ConfigPVCVolumeSource(name string, readonly bool) *api.VolumeSource

ConfigPVCVolumeSource is helper function to create an api.VolumeSource with a PVC

func (*Kubernetes) ConfigSecretVolumes added in v1.20.0

func (k *Kubernetes) ConfigSecretVolumes(name string, service kobject.ServiceConfig) ([]api.VolumeMount, []api.Volume)

ConfigSecretVolumes config volumes from secret. Link: https://docs.docker.com/compose/compose-file/#secrets In kubernetes' Secret resource, it has a data structure like a map[string]bytes, every key will act like the file name when mount to a container. This is the part that missing in compose. So we will create a single key secret from compose config and the key's name will be the secret's name, it's value is the file content. compose's secret can only be mounted at `/run/secrets`, so this will be hardcoded.

func (*Kubernetes) ConfigServicePorts added in v0.1.2

func (k *Kubernetes) ConfigServicePorts(service kobject.ServiceConfig) []api.ServicePort

ConfigServicePorts configure the container service ports.

func (*Kubernetes) ConfigTmpfs added in v0.4.0

func (k *Kubernetes) ConfigTmpfs(name string, service kobject.ServiceConfig) ([]api.VolumeMount, []api.Volume)

ConfigTmpfs configure the tmpfs.

func (*Kubernetes) ConfigVolumes added in v0.1.2

func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ([]api.VolumeMount, []api.Volume, []*api.PersistentVolumeClaim, []*api.ConfigMap, error)

ConfigVolumes configure the container volumes.

func (*Kubernetes) CreateHeadlessService added in v0.2.0

func (k *Kubernetes) CreateHeadlessService(name string, service kobject.ServiceConfig) *api.Service

CreateHeadlessService creates a k8s headless service. This is used for docker-compose services without ports. For such services we can't create regular Kubernetes Service. and without Service Pods can't find each other using DNS names. Instead of regular Kubernetes Service we create Headless Service. DNS of such service points directly to Pod IP address. You can find more about Headless Services in Kubernetes documentation https://kubernetes.io/docs/user-guide/services/#headless-services

func (*Kubernetes) CreateLBService added in v1.23.0

func (k *Kubernetes) CreateLBService(name string, service kobject.ServiceConfig) []*api.Service

CreateLBService creates a k8s Load Balancer Service

func (*Kubernetes) CreateNetworkPolicy added in v1.20.0

func (k *Kubernetes) CreateNetworkPolicy(networkName string) (*networkingv1.NetworkPolicy, error)

CreateNetworkPolicy initializes Network policy

func (*Kubernetes) CreatePVC added in v0.1.2

func (k *Kubernetes) CreatePVC(name string, mode string, size string, selectorValue string, storageClassName string) (*api.PersistentVolumeClaim, error)

CreatePVC initializes PersistentVolumeClaim

func (*Kubernetes) CreateSecrets added in v1.20.0

func (k *Kubernetes) CreateSecrets(komposeObject kobject.KomposeObject) ([]*api.Secret, error)

CreateSecrets create secrets

func (*Kubernetes) CreateService added in v0.1.2

func (k *Kubernetes) CreateService(name string, service kobject.ServiceConfig) *api.Service

CreateService creates a k8s service

func (*Kubernetes) CreateWorkloadAndConfigMapObjects added in v1.26.0

func (k *Kubernetes) CreateWorkloadAndConfigMapObjects(name string, service kobject.ServiceConfig, opt kobject.ConvertOptions) []runtime.Object

CreateWorkloadAndConfigMapObjects generates a Kubernetes artifact for each input type service

func (*Kubernetes) InitCJ added in v1.32.0

func (k *Kubernetes) InitCJ(name string, service kobject.ServiceConfig, schedule string, concurrencyPolicy batchv1.ConcurrencyPolicy, backoffLimit *int32) *batchv1.CronJob

InitCJ initializes Kubernetes CronJob object

func (*Kubernetes) InitConfigMapForEnv added in v1.17.0

func (k *Kubernetes) InitConfigMapForEnv(name string, opt kobject.ConvertOptions, envFile string) *api.ConfigMap

InitConfigMapForEnv initializes a ConfigMap object

func (*Kubernetes) InitConfigMapFromFile added in v1.17.0

func (k *Kubernetes) InitConfigMapFromFile(name string, service kobject.ServiceConfig, fileName string) *api.ConfigMap

InitConfigMapFromFile initializes a ConfigMap object

func (*Kubernetes) InitD added in v0.1.2

func (k *Kubernetes) InitD(name string, service kobject.ServiceConfig, replicas int) *appsv1.Deployment

InitD initializes Kubernetes Deployment object

func (*Kubernetes) InitDS added in v0.1.2

func (k *Kubernetes) InitDS(name string, service kobject.ServiceConfig) *appsv1.DaemonSet

InitDS initializes Kubernetes DaemonSet object

func (*Kubernetes) InitPod added in v0.2.0

func (k *Kubernetes) InitPod(name string, service kobject.ServiceConfig) *api.Pod

InitPod initializes Kubernetes Pod object

func (*Kubernetes) InitPodSpec added in v0.3.0

func (k *Kubernetes) InitPodSpec(name string, image string, pullSecret string) api.PodSpec

InitPodSpec creates the pod specification

func (*Kubernetes) InitPodSpecWithConfigMap added in v1.17.0

func (k *Kubernetes) InitPodSpecWithConfigMap(name string, image string, service kobject.ServiceConfig) api.PodSpec

InitPodSpecWithConfigMap creates the pod specification

func (*Kubernetes) InitSS added in v1.26.0

func (k *Kubernetes) InitSS(name string, service kobject.ServiceConfig, replicas int) *appsv1.StatefulSet

InitSS method initialize a stateful set

func (*Kubernetes) InitSvc added in v0.1.2

func (k *Kubernetes) InitSvc(name string, service kobject.ServiceConfig) *api.Service

InitSvc initializes Kubernetes Service object The created service name will = ServiceConfig.Name, but the selector may be not. If this service is grouped, the selector may be another name = name

func (*Kubernetes) IntiConfigMapFromFileOrDir added in v1.21.0

func (k *Kubernetes) IntiConfigMapFromFileOrDir(name, cmName, filePath string, service kobject.ServiceConfig) (*api.ConfigMap, error)

IntiConfigMapFromFileOrDir will create a configmap from dir or file usage:

  1. volume

func (*Kubernetes) PortsExist added in v0.1.2

func (k *Kubernetes) PortsExist(service kobject.ServiceConfig) bool

PortsExist checks if service has ports defined

func (*Kubernetes) RemoveDupObjects added in v1.21.0

func (k *Kubernetes) RemoveDupObjects(objs *[]runtime.Object)

RemoveDupObjects remove objects that are dups...eg. configmaps from env. since we know for sure that the duplication can only happen on ConfigMap, so this code will looks like this for now. + NetworkPolicy

func (*Kubernetes) SortServicesFirst added in v0.1.2

func (k *Kubernetes) SortServicesFirst(objs *[]runtime.Object)

SortServicesFirst - the objects that we get can be in any order this keeps services first according to best practice kubernetes services should be created first http://kubernetes.io/docs/user-guide/config-best-practices/

func (*Kubernetes) Transform

func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) ([]runtime.Object, error)

Transform maps komposeObject to k8s objects returns object that are already sorted in the way that Services are first

func (*Kubernetes) UpdateController added in v0.1.2

func (k *Kubernetes) UpdateController(obj runtime.Object, updateTemplate func(*api.PodTemplateSpec) error, updateMeta func(meta *metav1.ObjectMeta)) (err error)

UpdateController updates the given object with the given pod template update function and ObjectMeta update function

func (*Kubernetes) UpdateKubernetesObjects added in v0.1.2

func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.ServiceConfig, opt kobject.ConvertOptions, objects *[]runtime.Object) error

UpdateKubernetesObjects loads configurations to k8s objects

func (*Kubernetes) UpdateKubernetesObjectsMultipleContainers added in v1.23.0

func (k *Kubernetes) UpdateKubernetesObjectsMultipleContainers(name string, service kobject.ServiceConfig, objects *[]runtime.Object, podSpec PodSpec) error

UpdateKubernetesObjectsMultipleContainers method updates the kubernetes objects with the necessary data

type PodSpec added in v1.23.0

type PodSpec struct {
	api.PodSpec
}

PodSpec holds the spec of k8s pod.

func (*PodSpec) Append added in v1.23.0

func (podSpec *PodSpec) Append(ops ...PodSpecOption) *PodSpec

Append is responsible for adding the pod spec options to the particular pod

func (*PodSpec) Get added in v1.23.0

func (podSpec *PodSpec) Get() api.PodSpec

Get is responsible for returning the pod spec of a particular pod

type PodSpecOption added in v1.23.0

type PodSpecOption func(*PodSpec)

PodSpecOption holds the function to apply on a PodSpec

func AddContainer added in v1.23.0

func AddContainer(service kobject.ServiceConfig, opt kobject.ConvertOptions) PodSpecOption

AddContainer method is responsible for adding a new container to a k8s Pod.

func DomainName added in v1.23.0

func DomainName(service kobject.ServiceConfig) PodSpecOption

DomainName configure the domain name of a pod

func HostName added in v1.23.0

func HostName(service kobject.ServiceConfig) PodSpecOption

HostName configure the host name of a pod

func ImagePullPolicy added in v1.23.0

func ImagePullPolicy(name string, service kobject.ServiceConfig) PodSpecOption

ImagePullPolicy Configure the image pull policy

func ResourcesLimits added in v1.23.0

func ResourcesLimits(service kobject.ServiceConfig) PodSpecOption

ResourcesLimits Configure the resource limits

func ResourcesRequests added in v1.23.0

func ResourcesRequests(service kobject.ServiceConfig) PodSpecOption

ResourcesRequests Configure the resource requests

func RestartPolicy added in v1.23.0

func RestartPolicy(name string, service kobject.ServiceConfig) PodSpecOption

RestartPolicy Configure the container restart policy.

func SecurityContext added in v1.23.0

func SecurityContext(name string, service kobject.ServiceConfig) PodSpecOption

SecurityContext Configure SecurityContext

func ServiceAccountName added in v1.24.0

func ServiceAccountName(serviceAccountName string) PodSpecOption

ServiceAccountName is responsible for setting the service account name to the pod spec

func SetPorts added in v1.23.0

func SetPorts(service kobject.ServiceConfig) PodSpecOption

SetPorts Configure ports

func SetVolumeMounts added in v1.23.0

func SetVolumeMounts(volumesMount []api.VolumeMount) PodSpecOption

SetVolumeMounts returns a function which adds the volume mounts option to the pod spec

func SetVolumes added in v1.23.0

func SetVolumes(volumes []api.Volume) PodSpecOption

SetVolumes method returns a method that adds the volumes to the pod spec

func TerminationGracePeriodSeconds added in v1.23.0

func TerminationGracePeriodSeconds(name string, service kobject.ServiceConfig) PodSpecOption

TerminationGracePeriodSeconds method is responsible for attributing the grace period seconds option to a pod

func TopologySpreadConstraints added in v1.26.0

func TopologySpreadConstraints(service kobject.ServiceConfig) PodSpecOption

TopologySpreadConstraints is responsible for setting the topology spread constraints to the pod spec

Jump to

Keyboard shortcuts

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