Skip to content

Commit

Permalink
enable build args for specifying base image
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesesashimi committed Mar 17, 2022
1 parent 461694b commit f9e30bb
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions tests/layering/layering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path"
"strings"
"testing"
"time"

Expand All @@ -33,8 +34,9 @@ const (
ostreeUnverifiedRegistry = "ostree-unverified-registry"
imageRegistry = "image-registry.openshift-image-registry.svc:5000"
// If this moves from /run, make sure files get cleaned up
authfilePath = "/run/ostree/auth.json"
mcoNamespace = "openshift-machine-config-operator"
authfilePath = "/run/ostree/auth.json"
mcoNamespace = "openshift-machine-config-operator"
imagePullSpec = "registry.ci.openshift.org/rhcos-devel/rhel-coreos:%s"
)

type Deployments struct {
Expand All @@ -45,6 +47,15 @@ type Status struct {
deployments []Deployments
}

func getImageTag() string {
branch, found := os.LookupEnv("BRANCH")
if !found || branch == "" {
return "latest"
}

return strings.ReplaceAll(branch, "release-", "")
}

func TestBootInClusterImage(t *testing.T) {
cs := framework.NewClientSet("")

Expand All @@ -60,6 +71,10 @@ func TestBootInClusterImage(t *testing.T) {
require.Nil(t, err)
defer cs.ImageStreams(mcoNamespace).Delete(ctx, imageStreamName, metav1.DeleteOptions{})

baseImageBuildArg := fmt.Sprintf(imagePullSpec, getImageTag())

t.Logf("Imagestream %s created", imageStreamName)

// push a build to the image stream
buildConfig := &buildv1.Build{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -75,7 +90,14 @@ func TestBootInClusterImage(t *testing.T) {
},
},
Strategy: buildv1.BuildStrategy{
DockerStrategy: &buildv1.DockerBuildStrategy{},
DockerStrategy: &buildv1.DockerBuildStrategy{
BuildArgs: []corev1.EnvVar{
{
Name: "RHEL_COREOS_IMAGE",
Value: baseImageBuildArg,
},
},
},
},
Output: buildv1.BuildOutput{
To: &v1.ObjectReference{
Expand All @@ -86,16 +108,24 @@ func TestBootInClusterImage(t *testing.T) {
},
},
}

t.Logf("Using %s as the base image", baseImageBuildArg)

_, err = cs.BuildV1Interface.Builds(mcoNamespace).Create(ctx, buildConfig, metav1.CreateOptions{})
require.Nil(t, err)
defer cs.BuildV1Interface.Builds(mcoNamespace).Delete(ctx, buildName, metav1.DeleteOptions{})

t.Logf("Build %s started", buildName)
waitForBuild(t, cs, buildConfig.ObjectMeta.Name)
t.Logf("Build completed!")

// pick a random worker node
unlabelFunc := helpers.LabelRandomNodeFromPool(t, cs, "worker", "node-role.kubernetes.io/infra")
defer unlabelFunc()
infraNode := helpers.GetSingleNodeByRole(t, cs, "infra")

t.Logf("Labeled node %s with infra", infraNode.Name)

// get ImagePullSecret for the MCD service account and save to authfilePath on the node
// eventually we should use rest.InClusterConfig() instead of cs with kubeadmin
mcdServiceAccount, err := cs.ServiceAccounts(mcoNamespace).Get(ctx, "machine-config-daemon", metav1.GetOptions{})
Expand Down

0 comments on commit f9e30bb

Please sign in to comment.