Skip to content

Commit

Permalink
make OCL more OKD-friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesesashimi committed Apr 25, 2024
1 parent 2c5bd22 commit c0d2223
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
11 changes: 9 additions & 2 deletions pkg/controller/build/build_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1521,9 +1521,16 @@ func (ctrl *Controller) getConfigAndBuildForPool(pool *mcfgv1.MachineConfigPool)
// Determines if the build pod is in an error state by examining the individual
// container statuses. Returns true if a single container is in an error state.
func isBuildPodError(pod *corev1.Pod) bool {
errStates := map[string]struct{}{
"ErrImagePull": struct{}{},
"CreateContainerError": struct{}{},
}

for _, container := range pod.Status.ContainerStatuses {
if container.State.Waiting != nil && container.State.Waiting.Reason == "ErrImagePull" {
return true
if container.State.Waiting != nil {
if _, ok := errStates[container.State.Waiting.Reason]; ok {
return true
}
}

if container.State.Terminated != nil && container.State.Terminated.ExitCode != 0 {
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/build/image_build_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,6 @@ func (i ImageBuildRequest) toBuildahPod() *corev1.Pod {
Name: "done",
MountPath: "/tmp/done",
},
{
Name: "buildah-cache",
MountPath: "/home/build/.local/share/containers",
},
}

volumes := []corev1.Volume{
Expand Down Expand Up @@ -608,7 +604,11 @@ func (i ImageBuildRequest) toBuildahPod() *corev1.Pod {
Command: append(command, buildahBuildScript),
ImagePullPolicy: corev1.PullAlways,
SecurityContext: securityContext,
VolumeMounts: volumeMounts,
// Only attach the buildah-cache volume mount to the buildah container.
VolumeMounts: append(volumeMounts, corev1.VolumeMount{
Name: "buildah-cache",
MountPath: "/home/build/.local/share/containers",
}),
},
{
// This container waits for the aforementioned container to finish
Expand Down
3 changes: 3 additions & 0 deletions test/e2e-techpreview/Containerfile.okd-fcos
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM configs AS final
RUN rpm-ostree install cowsay && \
ostree container commit
11 changes: 11 additions & 0 deletions test/e2e-techpreview/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,17 @@ func skipOnOKD(t *testing.T) {
}
}

func skipOnOCP(t *testing.T) {
cs := framework.NewClientSet("")
isOKD, err := helpers.IsOKDCluster(cs)
require.NoError(t, err)

if !isOKD {
t.Logf("OCP detected, skipping test %s", t.Name())
t.Skip()
}
}

// Extracts the contents of a directory within a given container to a temporary
// directory. Next, it loads them into a bytes map keyed by filename. It does
// not handle nested directories, so use with caution.
Expand Down
14 changes: 14 additions & 0 deletions test/e2e-techpreview/onclusterbuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ var (
// content is mounted into the build context by the BuildController.
//go:embed Containerfile.yum-repos-d
yumReposDockerfile string

//go:embed Containerfile.okd-fcos
okdFcosDockerfile string
)

var skipCleanup bool
Expand Down Expand Up @@ -82,6 +85,17 @@ type onClusterBuildTestOpts struct {
useYumRepos bool
}

func TestOnClusterBuildsOnOKD(t *testing.T) {
skipOnOCP(t)

runOnClusterBuildTest(t, onClusterBuildTestOpts{
poolName: layeredMCPName,
customDockerfiles: map[string]string{
layeredMCPName: okdFcosDockerfile,
},
})
}

// Tests tha an on-cluster build can be performed with the Custom Pod Builder.
func TestOnClusterBuildsCustomPodBuilder(t *testing.T) {
runOnClusterBuildTest(t, onClusterBuildTestOpts{
Expand Down

0 comments on commit c0d2223

Please sign in to comment.