func (b *Builder) WithLivenessProbe(liveness *corev1.Probe) *Builder {
	if liveness == nil {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: nil liveness probe"),
		)
		return b
	}
	b.con.LivenessProbe = liveness
	return b
}
WithLivenessProbe sets the liveness probe of the container
package container
import (
	errors "github.com/pkg/errors"
	corev1 "k8s.io/api/core/v1"
)
type container struct {
	corev1.Container  
}
type OptionFunc func(*container)
type Predicate func(*container) (nameOrMsg string, ok bool)
func predicateFailedError(message string) error {
	return errors.Errorf("predicatefailed: %s", message)
}
func (c *container) asContainer() corev1.Container {
	return corev1.Container{
		Name:                     c.Name,
		Image:                    c.Image,
		Command:                  c.Command,
		Args:                     c.Args,
		WorkingDir:               c.WorkingDir,
		Ports:                    c.Ports,
		EnvFrom:                  c.EnvFrom,
		Env:                      c.Env,
		Resources:                c.Resources,
		VolumeMounts:             c.VolumeMounts,
		VolumeDevices:            c.VolumeDevices,
		LivenessProbe:            c.LivenessProbe,
		ReadinessProbe:           c.ReadinessProbe,
		Lifecycle:                c.Lifecycle,
		TerminationMessagePath:   c.TerminationMessagePath,
		TerminationMessagePolicy: c.TerminationMessagePolicy,
		ImagePullPolicy:          c.ImagePullPolicy,
		SecurityContext:          c.SecurityContext,
		Stdin:                    c.Stdin,
		StdinOnce:                c.StdinOnce,
		TTY:                      c.TTY,
	}
}
func New(opts ...OptionFunc) corev1.Container {
	c := &container{}
	for _, o := range opts {
		o(c)
	}
	return c.asContainer()
}
type Builder struct {
	con    *container   
	checks []Predicate  
	errors []error      
}
func NewBuilder() *Builder {
	return &Builder{
		con: &container{},
	}
}
func (b *Builder) validate() error {
	for _, c := range b.checks {
		if m, ok := c(b.con); !ok {
			b.errors = append(b.errors, predicateFailedError(m))
		}
	}
	if len(b.errors) == 0 {
		return nil
	}
	return errors.Errorf("validation errors: %v", b.errors)
}
func (b *Builder) Build() (corev1.Container, error) {
	err := b.validate()
	if err != nil {
		return corev1.Container{}, err
	}
	return b.con.asContainer(), nil
}
func (b *Builder) AddCheck(p Predicate) *Builder {
	b.checks = append(b.checks, p)
	return b
}
func (b *Builder) AddChecks(p []Predicate) *Builder {
	for _, check := range p {
		b.AddCheck(check)
	}
	return b
}
func (b *Builder) WithName(name string) *Builder {
	if len(name) == 0 {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: missing name"),
		)
		return b
	}
	WithName(name)(b.con)
	return b
}
func WithName(name string) OptionFunc {
	return func(c *container) {
		c.Name = name
	}
}
func (b *Builder) WithImage(img string) *Builder {
	if len(img) == 0 {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: missing image"),
		)
		return b
	}
	WithImage(img)(b.con)
	return b
}
func WithImage(img string) OptionFunc {
	return func(c *container) {
		c.Image = img
	}
}
func (b *Builder) WithCommandNew(cmd []string) *Builder {
	if cmd == nil {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: nil command"),
		)
		return b
	}
	if len(cmd) == 0 {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: missing command"),
		)
		return b
	}
	newcmd := []string{}
	newcmd = append(newcmd, cmd...)
	b.con.Command = newcmd
	return b
}
func (b *Builder) WithArgumentsNew(args []string) *Builder {
	if args == nil {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: nil arguments"),
		)
		return b
	}
	if len(args) == 0 {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: missing arguments"),
		)
		return b
	}
	newargs := []string{}
	newargs = append(newargs, args...)
	b.con.Args = newargs
	return b
}
func (b *Builder) WithVolumeMountsNew(volumeMounts []corev1.VolumeMount) *Builder {
	if volumeMounts == nil {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: nil volumemounts"),
		)
		return b
	}
	if len(volumeMounts) == 0 {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: missing volumemounts"),
		)
		return b
	}
	newvolumeMounts := []corev1.VolumeMount{}
	newvolumeMounts = append(newvolumeMounts, volumeMounts...)
	b.con.VolumeMounts = newvolumeMounts
	return b
}
func (b *Builder) WithVolumeDevices(volumeDevices []corev1.VolumeDevice) *Builder {
	if volumeDevices == nil {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: nil volumedevices"),
		)
		return b
	}
	if len(volumeDevices) == 0 {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: missing volumedevices"),
		)
		return b
	}
	newVolumeDevices := []corev1.VolumeDevice{}
	newVolumeDevices = append(newVolumeDevices, volumeDevices...)
	b.con.VolumeDevices = newVolumeDevices
	return b
}
func (b *Builder) WithImagePullPolicy(policy corev1.PullPolicy) *Builder {
	if len(policy) == 0 {
		b.errors = append(
			b.errors,
			errors.New(
				"failed to build container object: missing imagepullpolicy",
			),
		)
		return b
	}
	b.con.ImagePullPolicy = policy
	return b
}
func (b *Builder) WithPrivilegedSecurityContext(privileged *bool) *Builder {
	if privileged == nil {
		b.errors = append(
			b.errors,
			errors.New(
				"failed to build container object: missing securitycontext",
			),
		)
		return b
	}
	newprivileged := *privileged
	newsecuritycontext := &corev1.SecurityContext{
		Privileged: &newprivileged,
	}
	b.con.SecurityContext = newsecuritycontext
	return b
}
func (b *Builder) WithResources(
	resources *corev1.ResourceRequirements,
) *Builder {
	if resources == nil {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: missing resources"),
		)
		return b
	}
	newresources := *resources
	b.con.Resources = newresources
	return b
}
func (b *Builder) WithResourcesByValue(resources corev1.ResourceRequirements) *Builder {
	b.con.Resources = resources
	return b
}
func (b *Builder) WithPortsNew(ports []corev1.ContainerPort) *Builder {
	if ports == nil {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: nil ports"),
		)
		return b
	}
	if len(ports) == 0 {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: missing ports"),
		)
		return b
	}
	newports := []corev1.ContainerPort{}
	newports = append(newports, ports...)
	b.con.Ports = newports
	return b
}
func (b *Builder) WithEnvsNew(envs []corev1.EnvVar) *Builder {
	if envs == nil {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: nil envs"),
		)
		return b
	}
	if len(envs) == 0 {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: missing envs"),
		)
		return b
	}
	newenvs := []corev1.EnvVar{}
	newenvs = append(newenvs, envs...)
	b.con.Env = newenvs
	return b
}
func (b *Builder) WithEnvs(envs []corev1.EnvVar) *Builder {
	if envs == nil {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: nil envs"),
		)
		return b
	}
	if len(envs) == 0 {
		b.errors = append(
			b.errors,
			errors.New("failed to build container object: missing envs"),
		)
		return b
	}
	if b.con.Env == nil {
		b.WithEnvsNew(envs)
		return b
	}
	b.con.Env = append(b.con.Env, envs...)
	return b
}