Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

✨ [Add] Coverage dir for unpack pod #884

Merged
merged 1 commit into from
May 10, 2024
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
40 changes: 32 additions & 8 deletions pkg/source/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"io/fs"
"os"
"strings"

"github.com/nlepage/go-tarfs"
Expand Down Expand Up @@ -112,6 +113,12 @@ func (i *Image) getDesiredPodApplyConfig(bundle *rukpakv1alpha2.BundleDeployment
// this PSA definition either configurable or workable in a restricted namespace.
//
// See https://github.com/operator-framework/rukpak/pull/539 for more detail.

// This should ideally be a persistent volume that remains even after the
// pod is re-created. Since unpack image process is about to change to use
// a registry client, and the test coverage procedure is to revisited, creating
// a temp solution that uses an empty dir.
gocoverdirEnv := os.Getenv("GOCOVERDIR")
containerSecurityContext := applyconfigurationcorev1.SecurityContext().
WithAllowPrivilegeEscalation(false).
WithCapabilities(applyconfigurationcorev1.Capabilities().
Expand Down Expand Up @@ -150,17 +157,34 @@ func (i *Image) getDesiredPodApplyConfig(bundle *rukpakv1alpha2.BundleDeployment
WithName(imageBundleUnpackContainerName).
WithImage(bundle.Spec.Source.Image.Ref).
WithCommand("/bin/unpack", "--bundle-dir", "/").
WithVolumeMounts(applyconfigurationcorev1.VolumeMount().
WithName("util").
WithMountPath("/bin"),
).
WithVolumeMounts(func() []*applyconfigurationcorev1.VolumeMountApplyConfiguration {
var volumeMounts []*applyconfigurationcorev1.VolumeMountApplyConfiguration
if gocoverdirEnv != "" {
volumeMounts = append(volumeMounts, applyconfigurationcorev1.VolumeMount().
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A temporary fix to get e2e's running in operator controller!

WithName("test-coverage").
WithMountPath(gocoverdirEnv))
}
volumeMounts = append(volumeMounts, applyconfigurationcorev1.VolumeMount().
WithName("util").
WithMountPath("/bin"))
return volumeMounts
}()...).
WithEnv(applyconfigurationcorev1.EnvVar().WithName("GOCOVERDIR").WithValue(gocoverdirEnv)).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we only set this if gocoverdirEnv != ""?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing an empty configuration is causing errors. Tried various options, but looks like the only one is to create the entire container spec separately based on whether env var is present or not.

Leaving it to be as is for now, if the env is not set it results in an empty string which doesn't cause a problem for now. Also this is just a band aid, and will replaced by direct registry client anyways.

WithSecurityContext(containerSecurityContext.WithRunAsUser(1001)).
WithTerminationMessagePolicy(corev1.TerminationMessageFallbackToLogsOnError),
).
WithVolumes(applyconfigurationcorev1.Volume().
WithName("util").
WithEmptyDir(applyconfigurationcorev1.EmptyDirVolumeSource()),
).
WithVolumes(func() []*applyconfigurationcorev1.VolumeApplyConfiguration {
var volumes []*applyconfigurationcorev1.VolumeApplyConfiguration
if gocoverdirEnv != "" {
volumes = append(volumes, applyconfigurationcorev1.Volume().
WithName("test-coverage").
WithEmptyDir(applyconfigurationcorev1.EmptyDirVolumeSource()))
}
volumes = append(volumes, applyconfigurationcorev1.Volume().
WithName("util").
WithEmptyDir(applyconfigurationcorev1.EmptyDirVolumeSource()))
return volumes
}()...).
WithSecurityContext(applyconfigurationcorev1.PodSecurityContext().
WithRunAsNonRoot(true).
WithSeccompProfile(applyconfigurationcorev1.SeccompProfile().
Expand Down
Loading