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

Commit

Permalink
[Add] Coverage dir for unpack pod
Browse files Browse the repository at this point in the history
This PR adds the go test coverage variable to the
unpack pod. It also creates necessary volumes
if the GOCOVERDIR env var is set.

Signed-off-by: Varsha Prasad Narsing <[email protected]>
  • Loading branch information
varshaprasad96 committed May 10, 2024
1 parent d747ca9 commit 599807a
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 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,39 @@ 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().
WithName("test-coverage").
WithMountPath(gocoverdirEnv))
}
volumeMounts = append(volumeMounts, applyconfigurationcorev1.VolumeMount().
WithName("util").
WithMountPath("/bin"))
return volumeMounts
}()...).
WithEnv(func() *applyconfigurationcorev1.EnvVarApplyConfiguration {
if gocoverdirEnv != "" {
return applyconfigurationcorev1.EnvVar().WithName("GOCOVERDIR").WithValue(gocoverdirEnv)
}
return nil
}()).
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

0 comments on commit 599807a

Please sign in to comment.