Skip to content
container.go 1.73 KiB
Newer Older
Timothee Gosselin's avatar
WIP
Timothee Gosselin committed
package container

import (
	"github.com/pkg/errors"
	corev1 "k8s.io/api/core/v1"
)

func Generate(c Mutate) (obj corev1.Container, err error) {
Timothee Gosselin's avatar
WIP
Timothee Gosselin committed
	var container corev1.Container
	var ports []corev1.ContainerPort
	var cmd []string
	var args []string
	var resources corev1.ResourceRequirements
	var volumeMounts []corev1.VolumeMount
	var readiness *corev1.Probe
	var liveness *corev1.Probe
	var envList []corev1.EnvVar

	ports, err = c.ContainerPorts()
	if err != nil {
Timothee Gosselin's avatar
Timothee Gosselin committed
		return container, errors.Wrap(err, "failed to generate container ports")
Timothee Gosselin's avatar
WIP
Timothee Gosselin committed
	}
	args, err = c.ContainerArgs()
	if err != nil {
Timothee Gosselin's avatar
Timothee Gosselin committed
		return container, errors.Wrap(err, "failed to generate container ports")
Timothee Gosselin's avatar
WIP
Timothee Gosselin committed
	}
	resources, err = c.ContainerResources()
	if err != nil {
Timothee Gosselin's avatar
Timothee Gosselin committed
		return container, errors.Wrap(err, "failed to generate container ports")
Timothee Gosselin's avatar
WIP
Timothee Gosselin committed
	}
	volumeMounts, err = c.ContainerVolumeMounts()
	if err != nil {
Timothee Gosselin's avatar
Timothee Gosselin committed
		return container, errors.Wrap(err, "failed to generate container ports")
Timothee Gosselin's avatar
WIP
Timothee Gosselin committed
	}
	readiness, err = c.ContainerReadinessProbe()
	if err != nil {
Timothee Gosselin's avatar
Timothee Gosselin committed
		return container, errors.Wrap(err, "failed to generate container ports")
Timothee Gosselin's avatar
WIP
Timothee Gosselin committed
	}
	liveness, err = c.ContainerLivennessProbe()
	if err != nil {
Timothee Gosselin's avatar
Timothee Gosselin committed
		return container, errors.Wrap(err, "failed to generate container ports")
Timothee Gosselin's avatar
WIP
Timothee Gosselin committed
	}
	envList, err = c.ContainerEnvVar()
	if err != nil {
Timothee Gosselin's avatar
Timothee Gosselin committed
		return container, errors.Wrap(err, "failed to generate container ports")
Timothee Gosselin's avatar
WIP
Timothee Gosselin committed
	}
	container = corev1.Container{
		Name:            c.ContainerName(),
		Image:           c.ContainerImage(),
		ImagePullPolicy: c.ContainerImagePullPolicy(),
		Args:            args,
		Command:         cmd,
		Env:             envList,
		Ports:           ports,
		VolumeMounts:    volumeMounts,
		LivenessProbe:   liveness,
		ReadinessProbe:  readiness,
		Resources:       resources,
	}

Timothee Gosselin's avatar
Timothee Gosselin committed
	return container, err
Timothee Gosselin's avatar
WIP
Timothee Gosselin committed
}