Files
openstack-operator/builders/volume.go
Mohammed Naser cc5d82883c Add builder pattern
This builder pattern refactors things so that we can use the same
code to generate manifests/etc.  This means that if we make sure
that we exclusively use those, we can do testing there and keep
something common.

Change-Id: Ibc39f9b9e3e21b18fb255ba2a67d2d8ba3b5c585
2020-03-25 01:32:48 +02:00

40 lines
855 B
Go
Executable File

package builders
import (
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"
)
// VolumeBuilder provides an interface to build volumes
type VolumeBuilder struct {
obj *corev1.Volume
}
// Volume returns a new volume builder
func Volume(name string) *VolumeBuilder {
volume := &corev1.Volume{
Name: name,
}
return &VolumeBuilder{
obj: volume,
}
}
// FromConfigMap sets the source of the volume from a ConfigMap
func (v *VolumeBuilder) FromConfigMap(name string) *VolumeBuilder {
v.obj.VolumeSource = corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: v1.LocalObjectReference{Name: name},
DefaultMode: pointer.Int32Ptr(420),
},
}
return v
}
// Build returns the object after checking assertions
func (v *VolumeBuilder) Build() corev1.Volume {
return *v.obj
}