/* Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package container import ( corev1 "k8s.io/api/core/v1" parameters "k8s.libre.sh/application/settings" ) // Container is the specification of the desired behavior of the Container. // It is a stripped down version of https://godoc.org/k8s.io/api/core/v1#Container // with only user definied specs // // Parameters are used to define how settings are passed on to the container. // // +kubebuilder:object:generate=true type Container struct { *ContainerSpec `json:",inline"` *parameters.ConfigSpec `json:"parameters,omitempty"` } // +kubebuilder:object:generate=true type ContainerSpec struct { // Name of the container specified as a DNS_LABEL. // Each container in a pod must have a unique name (DNS_LABEL). // Cannot be updated. Name string `json:"name,omitempty"` // Docker image name. // More info: https://kubernetes.io/docs/concepts/containers/images // This field is optional to allow higher level config management to default or override // container images in workload controllers like Deployments and StatefulSets. // +optional Image string `json:"image,omitempty"` // Entrypoint array. Not executed within a shell. // The docker image's ENTRYPOINT is used if this is not provided. // Variable references $(VAR_NAME) are expanded using the container's environment. If a variable // cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax // can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, // regardless of whether the variable exists or not. // Cannot be updated. // More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell // +optional Command []string `json:"command,omitempty" protobuf:"bytes,3,rep,name=command"` // Arguments to the entrypoint. // The docker image's CMD is used if this is not provided. // Variable references $(VAR_NAME) are expanded using the container's environment. If a variable // cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax // can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, // regardless of whether the variable exists or not. // Cannot be updated. // More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell // +optional Args []string `json:"args,omitempty"` // List of ports to expose from the container. Exposing a port here gives // the system additional information about the network connections a // container uses, but is primarily informational. Not specifying a port here // DOES NOT prevent that port from being exposed. Any port which is // listening on the default "0.0.0.0" address inside a container will be // accessible from the network. // Cannot be updated. // +optional // +patchMergeKey=containerPort // +patchStrategy=merge // +listType=map // +listMapKey=containerPort // +listMapKey=protocol Ports []corev1.ContainerPort `json:"ports,omitempty"` // Image pull policy. // One of Always, Never, IfNotPresent. // Defaults to Always if :latest tag is specified, or IfNotPresent otherwise. // Cannot be updated. // More info: https://kubernetes.io/docs/concepts/containers/images#updating-images // +optional ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"` Probes `json:"inline,omitempty"` } // Periodic probe for container health // // +kubebuilder:object:generate=true type Probes struct { // Periodic probe of container liveness. // Container will be restarted if the probe fails. // Cannot be updated. // More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes // +optional ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"` // Periodic probe of container liveness. // Container will be restarted if the probe fails. // Cannot be updated. // More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes // +optional LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty" protobuf:"bytes,10,opt,name=livenessProbe"` } func (c *ContainerSpec) GetContainerImage() string { return c.Image } func (c *ContainerSpec) GetContainerName() string { return c.Name } func (c *ContainerSpec) GetContainerImagePullPolicy() corev1.PullPolicy { return c.ImagePullPolicy } func (c *ContainerSpec) GetContainerPorts() []corev1.ContainerPort { return c.Ports } func (c *ContainerSpec) GetContainerLivenessProbe() *corev1.Probe { return c.LivenessProbe } func (c *ContainerSpec) GetContainerReadinessProbe() *corev1.Probe { return c.ReadinessProbe } func (c *ContainerSpec) GetContainerArgs() []string { return c.Args } func (c *ContainerSpec) GetContainerCommand() []string { return c.Command } func (o *Container) TemplateValues() map[string]interface{} { values := make(map[string]interface{}) values["Name"] = o.Name values["Image"] = o.Image values["Command"] = o.Command values["Args"] = o.Args values["Ports"] = o.Ports values["ImagePullPolicy"] = o.ImagePullPolicy values["Probes"] = o.Probes return values }