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

refact(k8s-volumes): add configMap & secret based volume builder #1537

Merged
merged 7 commits into from
Dec 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions pkg/kubernetes/volume/v1alpha1/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,62 @@ func (b *Builder) WithHostDirectory(path string) *Builder {
return b
}

//WithSecret sets the VolumeSource field of Volume with provided Secret
func (b *Builder) WithSecret(secret *corev1.Secret, defaultMode int32) *Builder {
dM := defaultMode
if secret == nil {
b.errs = append(
b.errs,
errors.New("failed to build volume object: nil ConfigMap"),
)
return b
}
if defaultMode == 0 {
b.errs = append(
b.errs,
errors.New("failed to build volume object: missing defaultmode"),
)
}
volumeSource := corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
DefaultMode: &dM,
SecretName: secret.Name,
},
}
b.volume.object.VolumeSource = volumeSource
b.volume.object.Name = secret.Name
return b
}

//WithConfigMap sets the VolumeSource field of Volume with provided ConfigMap
func (b *Builder) WithConfigMap(configMap *corev1.ConfigMap, defaultMode int32) *Builder {
dM := defaultMode
if configMap == nil {
b.errs = append(
b.errs,
errors.New("failed to build volume object: nil ConfigMap"),
)
return b
}
if defaultMode == 0 {
b.errs = append(
b.errs,
errors.New("failed to build volume object: missing defaultmode"),
)
}
volumeSource := corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
DefaultMode: &dM,
LocalObjectReference: corev1.LocalObjectReference{
Name: configMap.Name,
},
},
}
b.volume.object.VolumeSource = volumeSource
b.volume.object.Name = configMap.Name
return b
}

// WithHostPathAndType sets the VolumeSource field of Volume with provided
// hostpath as directory path and type as directory type
func (b *Builder) WithHostPathAndType(
Expand Down