Skip to content

Commit

Permalink
write own deployment
Browse files Browse the repository at this point in the history
renamed container to testcontainer and log versions
  • Loading branch information
miampf committed Oct 22, 2024
1 parent ca5ad16 commit 8733d30
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
38 changes: 32 additions & 6 deletions e2e/aks-runtime/aks_runtime_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 Edgeless Systems GmbH
// SPDX-License-Identifier: AGPL-3.0-only

///go:build e2e
//go:build e2e

package aksruntime

Expand All @@ -13,15 +13,15 @@ import (
"testing"
"time"

"github.com/edgelesssys/contrast/e2e/internal/confcom"
"github.com/edgelesssys/contrast/e2e/internal/az"
"github.com/edgelesssys/contrast/e2e/internal/contrasttest"
"github.com/edgelesssys/contrast/e2e/internal/kubeclient"
"github.com/edgelesssys/contrast/internal/kubeapi"
"github.com/edgelesssys/contrast/internal/kuberesource"
"github.com/stretchr/testify/require"
)

const getdentsTester = "getdents-tester"
const testContainer = "testcontainer"

var (
imageReplacementsFile, namespaceFile, platformStr string
Expand All @@ -39,6 +39,14 @@ func TestAKSRuntime(t *testing.T) {
require.NoError(err)
namespace := contrasttest.MakeNamespace(t)

// Log versions
kataPolicyGenV, err := az.KataPolicyGenVersion()
require.NoError(err)
nodeImageV, err := az.NodeImageVersion("rgMiampf", "rgMiampf")
require.NoError(err)
t.Log("katapolicygen version: ", kataPolicyGenV)
t.Log("node image version: ", nodeImageV)

c := kubeclient.NewForTest(t)

// create the namespace
Expand All @@ -52,9 +60,27 @@ func TestAKSRuntime(t *testing.T) {
require.NoError(os.WriteFile(namespaceFile, []byte(namespace), 0o644))
}

deployment := kuberesource.Deployment(testContainer, "").
WithSpec(kuberesource.DeploymentSpec().
WithReplicas(1).
WithSelector(kuberesource.LabelSelector().WithMatchLabels(
map[string]string{"app.kubernetes.io/name": testContainer},
)).
WithTemplate(kuberesource.PodTemplateSpec().
WithLabels(map[string]string{"app.kubernetes.io/name": testContainer}).
WithSpec(kuberesource.PodSpec().
WithContainers(kuberesource.Container().
WithName(testContainer).
WithImage("docker.io/bash@sha256:ce062497c248eb1cf4d32927f8c1780cce158d3ed0658c586a5be7308d583cbb").
WithCommand("/usr/local/bin/bash", "-c", "while true; do sleep 10; done"),
),
),
),
)

// define resources
// TODO: Log kata-agent, guest kernel, node image version with custom container deployment
resources := kuberesource.GetDEnts()
resources := []any{deployment}
resources = kuberesource.PatchRuntimeHandlers(resources, "kata-cc-isolation")
resources = kuberesource.PatchNamespaces(resources, namespace)
resources = kuberesource.PatchImages(resources, imageReplacements)
Expand All @@ -66,7 +92,7 @@ func TestAKSRuntime(t *testing.T) {
resourceBytes, err := kuberesource.EncodeUnstructured(toWrite)
require.NoError(err)
require.NoError(os.WriteFile(path.Join(workdir, "resources.yaml"), resourceBytes, 0o644))
require.NoError(confcom.KataPolicyGen(t, path.Join(workdir, "resources.yaml")))
require.NoError(az.KataPolicyGen(t, path.Join(workdir, "resources.yaml")))

// load in generated resources and patch the runtime handler again
resourceBytes, err = os.ReadFile(path.Join(workdir, "resources.yaml"))
Expand All @@ -78,7 +104,7 @@ func TestAKSRuntime(t *testing.T) {
defer cancel()
err = c.Apply(ctx, toApply...)
require.NoError(err)
require.NoError(c.WaitFor(ctx, kubeclient.Ready, kubeclient.Deployment{}, namespace, getdentsTester))
require.NoError(c.WaitFor(ctx, kubeclient.Ready, kubeclient.Deployment{}, namespace, testContainer))
}

func TestMain(m *testing.M) {
Expand Down
3 changes: 2 additions & 1 deletion e2e/internal/az/aks.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"fmt"
"os/exec"
"strings"
)

// NodeImageVersion gets the node image version from the specified cluster
Expand All @@ -25,5 +26,5 @@ func NodeImageVersion(clusterName string, rg string) (string, error) {
return "", err
}

return fmt.Sprintf("%s", outMap[0]["nodeImageVersion"]), nil
return strings.TrimSpace(fmt.Sprintf("%s", outMap[0]["nodeImageVersion"])), nil
}
13 changes: 8 additions & 5 deletions e2e/internal/az/confcom.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ package az

import (
"os/exec"
"strings"
"testing"
)

// KataPolicyGen executes `az confcom katapolicygen --yaml <resourcePath>`.
func KataPolicyGen(t *testing.T, resourcePath string) error {
// log versions and extensions that are used
// KataPolicyGenVersion gets the version string of `az confcom katapolicygen`.
func KataPolicyGenVersion() (string, error) {
out, err := exec.Command("az", "confcom", "katapolicygen", "--print-version").Output()
if err != nil {
return err
return "", err
}
t.Log(string(out))
return strings.TrimSpace(string(out)), nil
}

// KataPolicyGen executes `az confcom katapolicygen --yaml <resourcePath>`.
func KataPolicyGen(t *testing.T, resourcePath string) error {
return exec.Command("az", "confcom", "katapolicygen", "--yaml", resourcePath).Run()
}

0 comments on commit 8733d30

Please sign in to comment.