Skip to content
Snippets Groups Projects
Unverified Commit c0583b33 authored by Luther Monson's avatar Luther Monson Committed by GitHub
Browse files

Add Volume Mounts (#195)

* adding volume mounts
parent 27ff123e
Branches
Tags v0.10.0-dev.2
No related merge requests found
......@@ -62,6 +62,13 @@ type ContainerSpec struct {
Args []string `json:"args,omitempty"`
Env []corev1.EnvVar `json:"envs,omitempty"`
EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"`
Volumes []VolumeSpec `json:"volumes,omitempty"`
}
type VolumeSpec struct {
Name string `json:"name,omitempty"`
Source string `json:"source,omitempty"`
Destination string `json:"destination,omitempty"`
}
// DrainSpec encapsulates `kubectl drain` parameters minus node/pod selectors.
......
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*
......@@ -56,6 +57,11 @@ func (in *ContainerSpec) DeepCopyInto(out *ContainerSpec) {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.Volumes != nil {
in, out := &in.Volumes, &out.Volumes
*out = make([]VolumeSpec, len(*in))
copy(*out, *in)
}
return
}
......@@ -255,3 +261,19 @@ func (in *SecretSpec) DeepCopy() *SecretSpec {
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *VolumeSpec) DeepCopyInto(out *VolumeSpec) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VolumeSpec.
func (in *VolumeSpec) DeepCopy() *VolumeSpec {
if in == nil {
return nil
}
out := new(VolumeSpec)
in.DeepCopyInto(out)
return out
}
......@@ -76,6 +76,17 @@ func WithPlanEnvironment(planName string, planStatus upgradeapiv1.PlanStatus) Op
}
}
func WithVolumes(volumes []upgradeapiv1.VolumeSpec) Option {
return func(container *corev1.Container) {
for _, v := range volumes {
container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{
Name: v.Name,
MountPath: v.Destination,
})
}
}
}
func New(name string, spec upgradeapiv1.ContainerSpec, opt ...Option) corev1.Container {
container := corev1.Container{
Name: name,
......@@ -110,6 +121,7 @@ func New(name string, spec upgradeapiv1.ContainerSpec, opt ...Option) corev1.Con
}}, spec.Env...),
EnvFrom: spec.EnvFrom,
}
for _, fn := range opt {
fn(&container)
}
......
......@@ -212,6 +212,18 @@ func New(plan *upgradeapiv1.Plan, node *corev1.Node, controllerName string) *bat
})
}
// add volumes from upgrade plan
for _, v := range plan.Spec.Upgrade.Volumes {
podTemplate.Spec.Volumes = append(podTemplate.Spec.Volumes, corev1.Volume{
Name: v.Name,
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: v.Source,
},
},
})
}
// first, we prepare
if plan.Spec.Prepare != nil {
podTemplate.Spec.InitContainers = append(podTemplate.Spec.InitContainers,
......@@ -220,6 +232,7 @@ func New(plan *upgradeapiv1.Plan, node *corev1.Node, controllerName string) *bat
upgradectr.WithSecrets(plan.Spec.Secrets),
upgradectr.WithPlanEnvironment(plan.Name, plan.Status),
upgradectr.WithImagePullPolicy(ImagePullPolicy),
upgradectr.WithVolumes(plan.Spec.Upgrade.Volumes),
),
)
}
......@@ -260,6 +273,7 @@ func New(plan *upgradeapiv1.Plan, node *corev1.Node, controllerName string) *bat
upgradectr.WithSecrets(plan.Spec.Secrets),
upgradectr.WithPlanEnvironment(plan.Name, plan.Status),
upgradectr.WithImagePullPolicy(ImagePullPolicy),
upgradectr.WithVolumes(plan.Spec.Upgrade.Volumes),
),
)
} else if cordon {
......@@ -271,6 +285,7 @@ func New(plan *upgradeapiv1.Plan, node *corev1.Node, controllerName string) *bat
upgradectr.WithSecrets(plan.Spec.Secrets),
upgradectr.WithPlanEnvironment(plan.Name, plan.Status),
upgradectr.WithImagePullPolicy(ImagePullPolicy),
upgradectr.WithVolumes(plan.Spec.Upgrade.Volumes),
),
)
}
......@@ -290,6 +305,7 @@ func New(plan *upgradeapiv1.Plan, node *corev1.Node, controllerName string) *bat
upgradectr.WithSecrets(plan.Spec.Secrets),
upgradectr.WithPlanEnvironment(plan.Name, plan.Status),
upgradectr.WithImagePullPolicy(ImagePullPolicy),
upgradectr.WithVolumes(plan.Spec.Upgrade.Volumes),
),
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment