Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Volume Mounts #195

Merged
merged 2 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/apis/upgrade.cattle.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions pkg/apis/upgrade.cattle.io/v1/zz_generated_deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions pkg/upgrade/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/upgrade/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
),
)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
),
)
}
Expand All @@ -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),
),
}

Expand Down