Skip to content

Commit

Permalink
test(integration): use different namespaces for instrumentation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm committed May 31, 2024
1 parent 3e263ce commit 4715156
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 39 deletions.
8 changes: 4 additions & 4 deletions tests/integration/helm_opentelemetry_operator_enabled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func Test_Helm_OpenTelemetry_Operator_Enabled(t *testing.T) {
)
return ctx
}).
Assess("instrumentation-cr in ot-operator1 namespace is created", func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
res := envConf.Client().Resources("ot-operator1")
Assess("instrumentation-cr in ot-operator-enabled-1 namespace is created", func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
res := envConf.Client().Resources("ot-operator-enabled-1")
releaseName := ctxopts.HelmRelease(ctx)
labelSelector := fmt.Sprintf("app=%s-sumologic-ot-operator-instr", releaseName)
instrs := otoperatorappsv1.InstrumentationList{}
Expand All @@ -90,8 +90,8 @@ func Test_Helm_OpenTelemetry_Operator_Enabled(t *testing.T) {
)
return ctx
}).
Assess("instrumentation-cr in ot-operator2 namespace is created", func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
res := envConf.Client().Resources("ot-operator2")
Assess("instrumentation-cr in ot-operator-enabled-2 namespace is created", func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
res := envConf.Client().Resources("ot-operator-enabled-2")
releaseName := ctxopts.HelmRelease(ctx)
labelSelector := fmt.Sprintf("app=%s-sumologic-ot-operator-instr", releaseName)
instrs := otoperatorappsv1.InstrumentationList{}
Expand Down
31 changes: 5 additions & 26 deletions tests/integration/helm_opentelemetry_operator_instr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ func Test_OpenTelemetry_Operator_Instrumentation(t *testing.T) {
waitDuration = time.Minute * 2
)

var originalNamespaceKey internalCtxKey = "originalNamespace"

installChecks := []featureCheck{
CheckSumologicSecret(3),
CheckTracesWithoutGatewayInstall,
Expand Down Expand Up @@ -75,8 +73,8 @@ func Test_OpenTelemetry_Operator_Instrumentation(t *testing.T) {
)
return ctx
}).
Assess("instrumentation-cr in ot-operator1 namespace is created", func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
res := envConf.Client().Resources("ot-operator1")
Assess("instrumentation-cr in ot-operator-instr-1 namespace is created", func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
res := envConf.Client().Resources("ot-operator-instr-1")
releaseName := ctxopts.HelmRelease(ctx)
labelSelector := fmt.Sprintf("app=%s-sumologic-ot-operator-instr", releaseName)
instrs := otoperatorappsv1.InstrumentationList{}
Expand All @@ -93,8 +91,8 @@ func Test_OpenTelemetry_Operator_Instrumentation(t *testing.T) {
)
return ctx
}).
Assess("instrumentation-cr in ot-operator2 namespace is created", func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
res := envConf.Client().Resources("ot-operator2")
Assess("instrumentation-cr in ot-operator-instr-2 namespace is created", func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
res := envConf.Client().Resources("ot-operator-instr-2")
releaseName := ctxopts.HelmRelease(ctx)
labelSelector := fmt.Sprintf("app=%s-sumologic-ot-operator-instr", releaseName)
instrs := otoperatorappsv1.InstrumentationList{}
Expand All @@ -121,24 +119,5 @@ func Test_OpenTelemetry_Operator_Instrumentation(t *testing.T) {

curlApp := GetCurlAppFeature()

useDefaultNs := func(ctx context.Context, envConf *envconf.Config, t *testing.T, _ features.Feature) (context.Context, error) {
originalNamespace := ctxopts.Namespace(ctx)
ctx = context.WithValue(ctx, originalNamespaceKey, originalNamespace)
kubectlOptions := ctxopts.KubectlOptions(ctx)
kubectlOptions.Namespace = originalNamespace
ctx = ctxopts.WithKubectlOptions(ctx, kubectlOptions)
ctx = ctxopts.WithNamespace(ctx, originalNamespace)
return ctx, nil
}

restoreOriginalNamespace := func(ctx context.Context, envConf *envconf.Config, t *testing.T, _ features.Feature) (context.Context, error) {
originalNamespace := ctx.Value(originalNamespaceKey).(string)
kubectlOptions := ctxopts.KubectlOptions(ctx)
kubectlOptions.Namespace = originalNamespace
ctx = ctxopts.WithKubectlOptions(ctx, kubectlOptions)
ctx = ctxopts.WithNamespace(ctx, originalNamespace)
return ctx, nil
}

testenv.BeforeEachFeature(useDefaultNs).AfterEachFeature(restoreOriginalNamespace).Test(t, featInstall, featOpenTelemetryOperator, featDotnetApp, featJavaApp, featNodeJSApp, featPythonApp, curlApp)
testenv.Test(t, featInstall, featOpenTelemetryOperator, featDotnetApp, featJavaApp, featNodeJSApp, featPythonApp, curlApp)
}
3 changes: 2 additions & 1 deletion tests/integration/internal/k8s/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ func WaitUntilSumologicMockAvailable(
waitDuration time.Duration,
tickDuration time.Duration,
) {
k8s.WaitUntilServiceAvailable(t, ctxopts.KubectlOptions(ctx), serviceName, int(waitDuration), tickDuration)
retries := waitDuration / tickDuration
k8s.WaitUntilServiceAvailable(t, ctxopts.KubectlOptions(ctx), serviceName, int(retries), tickDuration)
}

func formatSelectors(listOptions v1.ListOptions) string {
Expand Down
11 changes: 5 additions & 6 deletions tests/integration/internal/stepfuncs/assess_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
log "k8s.io/klog/v2"
"sigs.k8s.io/e2e-framework/klient/k8s"
"sigs.k8s.io/e2e-framework/klient/k8s/resources"
Expand Down Expand Up @@ -49,10 +48,10 @@ func WaitUntilPodsAvailable(listOptions metav1.ListOptions, count int, wait time
// `wait` and `tick` times as well as the provided list options and the desired count.
func WaitUntilPodsAvailableCustomNS(listOptions metav1.ListOptions, count int, wait time.Duration, tick time.Duration, namespace string) features.Func {
return func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
opts := ctxopts.KubectlOptions(ctx)
opts := *ctxopts.KubectlOptions(ctx)
opts.Namespace = namespace

k8s_internal.WaitUntilPodsAvailable(t, opts,
k8s_internal.WaitUntilPodsAvailable(t, &opts,
listOptions, count, wait, tick,
)
return ctx
Expand Down Expand Up @@ -506,7 +505,7 @@ func WaitUntilStatefulSetIsReady(
) features.Func {
return func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
sts := appsv1.StatefulSet{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: ctxopts.Namespace(ctx),
},
}
Expand Down Expand Up @@ -557,7 +556,7 @@ func WaitUntilDaemonSetIsReady(
) features.Func {
return func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
ds := appsv1.DaemonSet{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: ctxopts.Namespace(ctx),
},
}
Expand Down Expand Up @@ -608,7 +607,7 @@ func WaitUntilDeploymentIsReady(
) features.Func {
return func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
deps := appsv1.Deployment{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: ctxopts.Namespace(ctx),
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sumologic:
opentelemetry-operator:
enabled: true
createDefaultInstrumentation: true
instrumentationNamespaces: "ot-operator1,ot-operator2"
instrumentationNamespaces: "ot-operator-enabled-1,ot-operator-enabled-2"
manager:
resources:
requests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sumologic:
opentelemetry-operator:
enabled: true
createDefaultInstrumentation: true
instrumentationNamespaces: "ot-operator1,ot-operator2,test-apps"
instrumentationNamespaces: "ot-operator-instr-1,ot-operator-instr-2,test-apps"
manager:
resources:
requests:
Expand Down

0 comments on commit 4715156

Please sign in to comment.