Skip to content

Commit

Permalink
Update test to run on OpenShift (#350)
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Earls <[email protected]>
  • Loading branch information
kevinearls authored and jpkrohling committed Apr 4, 2019
1 parent 9d5f173 commit aa7de57
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
47 changes: 42 additions & 5 deletions test/e2e/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os/exec"
"strings"
"testing"
"time"

osv1sec "github.com/openshift/api/security/v1"
framework "github.com/operator-framework/operator-sdk/pkg/test"
"github.com/operator-framework/operator-sdk/pkg/test/e2eutil"
log "github.com/sirupsen/logrus"
Expand All @@ -32,18 +35,28 @@ func DaemonSet(t *testing.T) {
}

func daemonsetTest(t *testing.T, f *framework.Framework, ctx *framework.TestCtx) error {
// TODO restore this after fix of https://github.com/jaegertracing/jaeger-operator/issues/322
if isOpenShift(t) {
t.Skipf("Test %s is not currently supported on OpenShift because of issue 322\n", t.Name())
}
cleanupOptions := &framework.CleanupOptions{TestContext: ctx, Timeout: timeout, RetryInterval: retryInterval}
namespace, err := ctx.GetNamespace()
if err != nil {
return fmt.Errorf("could not get namespace: %v", err)
}

j := jaegerAgentAsDaemonsetDefinition(namespace, "agent-as-daemonset")
if isOpenShift(t) {
err = f.Client.Create(goctx.TODO(), hostPortSccDaemonset(), cleanupOptions)
if err != nil && !strings.Contains(err.Error(), "already exists") {
return err
}

// ideally, we would use the REST API, but for a single-usage within the project, this is the simplest solution that works
cmd := exec.Command("oc", "adm", "--namespace", namespace, "policy", "add-scc-to-user", "daemonset-with-hostport", "-z", "default")
output, err := cmd.CombinedOutput()
if err != nil {
fmt.Printf("Failed creating hostport scc with error [%v] OUTPUT: [%v]\n", err, string(output))
return err;
}
}

j := jaegerAgentAsDaemonsetDefinition(namespace, "agent-as-daemonset")
log.Infof("passing %v", j)
err = f.Client.Create(goctx.TODO(), j, cleanupOptions)
if err != nil {
Expand Down Expand Up @@ -198,3 +211,27 @@ func jaegerAgentAsDaemonsetDefinition(namespace string, name string) *v1.Jaeger
}
return j
}

func hostPortSccDaemonset() (*osv1sec.SecurityContextConstraints) {
annotations := make(map[string]string)
annotations["kubernetes.io/description"] = "Allows DaemonSets to bind to a well-known host port"

scc := &osv1sec.SecurityContextConstraints{
TypeMeta: metav1.TypeMeta {
Kind: "SecurityContextConstraints",
APIVersion:"security.openshift.io/v1",
},
ObjectMeta: metav1.ObjectMeta {
Name: "daemonset-with-hostport",
Annotations:annotations,
},
RunAsUser: osv1sec.RunAsUserStrategyOptions{
Type: osv1sec.RunAsUserStrategyRunAsAny,
},
SELinuxContext: osv1sec.SELinuxContextStrategyOptions{
Type:"RunAsAny",
},
AllowHostPorts: true,
}
return scc
}
2 changes: 2 additions & 0 deletions test/e2e/suite_smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
osv1 "github.com/openshift/api/route/v1"
osv1sec "github.com/openshift/api/security/v1"

"github.com/jaegertracing/jaeger-operator/pkg/apis"
"github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
Expand All @@ -24,6 +25,7 @@ func TestSmoke(t *testing.T) {

if isOpenShift(t) {
assert.NoError(t, framework.AddToFrameworkScheme(osv1.AddToScheme, &osv1.Route{}))
assert.NoError(t, framework.AddToFrameworkScheme(osv1sec.AddToScheme, &osv1sec.SecurityContextConstraints{}))
}

t.Run("smoke", func(t *testing.T) {
Expand Down

0 comments on commit aa7de57

Please sign in to comment.