Skip to content
Open
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion pkg/build/controller/build/build_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ type BuildController struct {
buildDefaults builddefaults.BuildDefaults
buildOverrides buildoverrides.BuildOverrides
internalRegistryHostname string
buildCSIVolumesEnabled bool

recorder record.EventRecorder
registryConfData string
Expand Down
5 changes: 2 additions & 3 deletions pkg/build/controller/strategy/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ func init() {

// DockerBuildStrategy creates a Docker build using a Docker builder image.
type DockerBuildStrategy struct {
Image string
BuildCSIVolumesEnabled bool
Image string
}

// CreateBuildPod creates the pod to be used for the Docker build
Expand Down Expand Up @@ -219,7 +218,7 @@ func (bs *DockerBuildStrategy) CreateBuildPod(build *buildv1.Build, additionalCA
setupBuilderDeviceFUSE(pod)
}
setupBlobCache(pod)
if err := setupBuildVolumes(pod, build.Spec.Strategy.DockerStrategy.Volumes, bs.BuildCSIVolumesEnabled); err != nil {
if err := setupBuildVolumes(pod, build.Spec.Strategy.DockerStrategy.Volumes); err != nil {
return pod, err
}
return pod, nil
Expand Down
7 changes: 3 additions & 4 deletions pkg/build/controller/strategy/sti.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import (

// SourceBuildStrategy creates STI(source to image) builds
type SourceBuildStrategy struct {
Image string
SecurityClient securityclient.SecurityV1Interface
BuildCSIVolumeseEnabled bool
Image string
SecurityClient securityclient.SecurityV1Interface
}

// DefaultDropCaps is the list of capabilities to drop if the current user cannot run as root
Expand Down Expand Up @@ -226,7 +225,7 @@ func (bs *SourceBuildStrategy) CreateBuildPod(build *buildv1.Build, additionalCA
setupBuilderDeviceFUSE(pod)
}
setupBlobCache(pod)
if err := setupBuildVolumes(pod, build.Spec.Strategy.SourceStrategy.Volumes, bs.BuildCSIVolumeseEnabled); err != nil {
if err := setupBuildVolumes(pod, build.Spec.Strategy.SourceStrategy.Volumes); err != nil {
return pod, err
}
return pod, nil
Expand Down
5 changes: 1 addition & 4 deletions pkg/build/controller/strategy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ func setupBlobCache(pod *corev1.Pod) {
}

// setupBuildVolumes sets up user defined BuildVolumes
func setupBuildVolumes(pod *corev1.Pod, buildVolumes []buildv1.BuildVolume, csiVolumesEnabled bool) error {
func setupBuildVolumes(pod *corev1.Pod, buildVolumes []buildv1.BuildVolume) error {
// if there are no BuildVolumes or the pod is nil,
// there is no processing needed, so just return quickly
if len(buildVolumes) == 0 || pod == nil {
Expand Down Expand Up @@ -791,9 +791,6 @@ func setupBuildVolumes(pod *corev1.Pod, buildVolumes []buildv1.BuildVolume, csiV
volumeSource.ConfigMap = buildVolume.Source.ConfigMap
mountConfigMapVolume(pod, &pod.Spec.Containers[0], strings.ToLower(buildVolume.Source.ConfigMap.Name), PathForBuildVolume(buildVolume.Source.ConfigMap.Name), buildVolumeSuffix, &volumeSource)
case buildv1.BuildVolumeSourceTypeCSI:
if !csiVolumesEnabled {
return fmt.Errorf("csi volumes require the BuildCSIVolumes feature gate to be enabled")
}
volumeSource.CSI = buildVolume.Source.CSI
mountCSIVolume(pod, &pod.Spec.Containers[0], strings.ToLower(buildVolume.Name), PathForBuildVolume(buildVolume.Name), buildVolumeSuffix, &volumeSource)
default:
Expand Down
63 changes: 16 additions & 47 deletions pkg/build/controller/strategy/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ func TestSetupBuildVolumes(t *testing.T) {

tests := []struct {
Name string
CSIVolumeEnabled bool
ShouldFail bool
ErrorMessage string
StartingVolumes []corev1.Volume
Expand All @@ -552,10 +551,9 @@ func TestSetupBuildVolumes(t *testing.T) {
WantVolumeMounts []corev1.VolumeMount
}{
{
Name: "Secret BuildVolume should succeed",
CSIVolumeEnabled: false,
ShouldFail: false,
ErrorMessage: "",
Name: "Secret BuildVolume should succeed",
ShouldFail: false,
ErrorMessage: "",
BuildVolumes: []buildv1.BuildVolume{
{
Name: "one",
Expand Down Expand Up @@ -606,10 +604,9 @@ func TestSetupBuildVolumes(t *testing.T) {
},
},
{
Name: "ConfigMap BuildVolume should succeed",
CSIVolumeEnabled: false,
ShouldFail: false,
ErrorMessage: "",
Name: "ConfigMap BuildVolume should succeed",
ShouldFail: false,
ErrorMessage: "",
BuildVolumes: []buildv1.BuildVolume{
{
Name: "one",
Expand Down Expand Up @@ -660,10 +657,9 @@ func TestSetupBuildVolumes(t *testing.T) {
},
},
{
Name: "CSI BuildVolume should succeed",
CSIVolumeEnabled: true,
ShouldFail: false,
ErrorMessage: "",
Name: "CSI BuildVolume should succeed",
ShouldFail: false,
ErrorMessage: "",
BuildVolumes: []buildv1.BuildVolume{
{
Name: "csi-one",
Expand Down Expand Up @@ -702,10 +698,9 @@ func TestSetupBuildVolumes(t *testing.T) {
},
},
{
Name: "Duplicate Secret BuildVolumeMount should fail",
CSIVolumeEnabled: false,
ShouldFail: true,
ErrorMessage: "user provided BuildVolumeMount path \"my-path\" collides with VolumeMount path created by the build controller",
Name: "Duplicate Secret BuildVolumeMount should fail",
ShouldFail: true,
ErrorMessage: "user provided BuildVolumeMount path \"my-path\" collides with VolumeMount path created by the build controller",
StartingVolumeMounts: []corev1.VolumeMount{
{
Name: "some-name",
Expand Down Expand Up @@ -746,10 +741,9 @@ func TestSetupBuildVolumes(t *testing.T) {
},
},
{
Name: "UnSupported BuildVolumeSourceType should fail",
CSIVolumeEnabled: false,
ShouldFail: true,
ErrorMessage: "encountered unsupported build volume source type \"UnSupportedBuildVolumeType\"",
Name: "UnSupported BuildVolumeSourceType should fail",
ShouldFail: true,
ErrorMessage: "encountered unsupported build volume source type \"UnSupportedBuildVolumeType\"",
BuildVolumes: []buildv1.BuildVolume{
{
Name: "one",
Expand All @@ -763,31 +757,6 @@ func TestSetupBuildVolumes(t *testing.T) {
WantVolumes: []corev1.Volume{},
WantVolumeMounts: []corev1.VolumeMount{},
},
{
Name: "CSI volume request without csivolumeEnabled should fail",
CSIVolumeEnabled: false,
ShouldFail: true,
ErrorMessage: "csi volumes require the BuildCSIVolumes feature gate to be enabled",
BuildVolumes: []buildv1.BuildVolume{
{
Name: "csi-one",
Source: buildv1.BuildVolumeSource{
Type: buildv1.BuildVolumeSourceTypeCSI,
CSI: &corev1.CSIVolumeSource{
Driver: "inline.storage.kubernetes.io",
VolumeAttributes: map[string]string{"foo": "bar"},
},
},
Mounts: []buildv1.BuildVolumeMount{
{
DestinationPath: "my-path",
},
},
},
},
WantVolumes: []corev1.Volume{},
WantVolumeMounts: []corev1.VolumeMount{},
},
}

for _, tt := range tests {
Expand All @@ -802,7 +771,7 @@ func TestSetupBuildVolumes(t *testing.T) {
p.Spec.Containers[0].VolumeMounts = append(p.Spec.Containers[0].VolumeMounts, tt.StartingVolumeMounts...)
}

err := setupBuildVolumes(p, tt.BuildVolumes, tt.CSIVolumeEnabled)
err := setupBuildVolumes(p, tt.BuildVolumes)

if err == nil && tt.ShouldFail {
t.Errorf("test %q should have failed with error %q, but didn't", tt.Name, tt.ErrorMessage)
Expand Down
21 changes: 3 additions & 18 deletions pkg/cmd/controller/build.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package controller

import (
"strings"

clientset "k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"

Expand Down Expand Up @@ -53,17 +51,6 @@ func RunBuildController(ctx *ControllerContext) (bool, error) {
imageDigestMirrorSetInformer := ctx.ConfigInformers.Config().V1().ImageDigestMirrorSets()
imageTagMirrorSetInformer := ctx.ConfigInformers.Config().V1().ImageTagMirrorSets()

fg := ctx.OpenshiftControllerConfig.FeatureGates
csiVolumesEnabled := false
if fg != nil {
for _, v := range fg {
v = strings.TrimSpace(v)
if v == "BuildCSIVolumes=true" {
csiVolumesEnabled = true
}
}
}

buildControllerParams := &buildcontroller.BuildControllerParams{
BuildInformer: buildInformer,
BuildConfigInformer: buildConfigInformer,
Expand All @@ -83,13 +70,11 @@ func RunBuildController(ctx *ControllerContext) (bool, error) {
KubeClient: externalKubeClient,
BuildClient: buildClient,
DockerBuildStrategy: &buildstrategy.DockerBuildStrategy{
Image: imageTemplate.ExpandOrDie("docker-builder"),
BuildCSIVolumesEnabled: csiVolumesEnabled,
Image: imageTemplate.ExpandOrDie("docker-builder"),
},
SourceBuildStrategy: &buildstrategy.SourceBuildStrategy{
Image: imageTemplate.ExpandOrDie("docker-builder"),
SecurityClient: securityClient.SecurityV1(),
BuildCSIVolumeseEnabled: csiVolumesEnabled,
Image: imageTemplate.ExpandOrDie("docker-builder"),
SecurityClient: securityClient.SecurityV1(),
},
CustomBuildStrategy: &buildstrategy.CustomBuildStrategy{},
BuildDefaults: builddefaults.BuildDefaults{Config: ctx.OpenshiftControllerConfig.Build.BuildDefaults},
Expand Down