Skip to content

Commit

Permalink
Fix failing e2e release test (#3205)
Browse files Browse the repository at this point in the history
  • Loading branch information
waodim authored Jun 3, 2024
1 parent fd482c5 commit 3fcdbcb
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
5 changes: 4 additions & 1 deletion test/features/cloudnative/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package upgrade
import (
"testing"

dynakubev1beta1 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta1/dynakube"
"github.com/Dynatrace/dynatrace-operator/test/features/cloudnative"
"github.com/Dynatrace/dynatrace-operator/test/helpers"
"github.com/Dynatrace/dynatrace-operator/test/helpers/components/dynakube"
Expand All @@ -31,7 +32,9 @@ func Feature(t *testing.T) features.Feature {
)
builder.Assess("create sample namespace", sampleApp.InstallNamespace())

dynakube.Install(builder, helpers.LevelAssess, &secretConfig, testDynakube)
previousVersionDynakube := &dynakubev1beta1.DynaKube{}
previousVersionDynakube.ConvertFrom(&testDynakube)
dynakube.InstallPreviousVersion(builder, helpers.LevelAssess, &secretConfig, *previousVersionDynakube)

// Register sample app install
builder.Assess("install sample app", sampleApp.Install())
Expand Down
53 changes: 53 additions & 0 deletions test/helpers/components/dynakube/dynakube.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"time"

"github.com/Dynatrace/dynatrace-operator/pkg/api/status"
dynatracev1beta1 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta1"
dynakubev1beta1 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta1/dynakube"
dynatracev1beta2 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta2"
dynakubev1beta2 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta2/dynakube"
"github.com/Dynatrace/dynatrace-operator/test/helpers/components/oneagent"
Expand All @@ -32,6 +34,11 @@ func Install(builder *features.FeatureBuilder, level features.Level, secretConfi
VerifyStartup(builder, level, testDynakube)
}

func InstallPreviousVersion(builder *features.FeatureBuilder, level features.Level, secretConfig *tenant.Secret, previousVersionDK dynakubev1beta1.DynaKube) {
CreatePreviousVersion(builder, level, secretConfig, previousVersionDK)
VerifyStartupPreviousVersion(builder, level, previousVersionDK)
}

func Create(builder *features.FeatureBuilder, level features.Level, secretConfig *tenant.Secret, testDynakube dynakubev1beta2.DynaKube) {
if secretConfig != nil {
builder.WithStep("created tenant secret", level, tenant.CreateTenantSecret(*secretConfig, testDynakube.Name, testDynakube.Namespace))
Expand All @@ -46,6 +53,26 @@ func Update(builder *features.FeatureBuilder, level features.Level, testDynakube
builder.WithStep("dynakube updated", level, update(testDynakube))
}

func CreatePreviousVersion(builder *features.FeatureBuilder, level features.Level, secretConfig *tenant.Secret, testDynakube dynakubev1beta1.DynaKube) {
if secretConfig != nil {
builder.WithStep("created tenant secret", level, tenant.CreateTenantSecret(*secretConfig, testDynakube.Name, testDynakube.Namespace))
}
builder.WithStep(
fmt.Sprintf("'%s' dynakube created", testDynakube.Name),
level,
createPreviousVersion(testDynakube))
}

func VerifyStartupPreviousVersion(builder *features.FeatureBuilder, level features.Level, testDynakube dynakubev1beta1.DynaKube) {
if testDynakube.NeedsOneAgent() {
builder.WithStep("oneagent started", level, oneagent.WaitForDaemonsetV1Beta1(testDynakube))
}
builder.WithStep(
fmt.Sprintf("'%s' dynakube phase changes to 'Running'", testDynakube.Name),
level,
WaitForPhasePreviousVersion(testDynakube, status.Running))
}

func Delete(builder *features.FeatureBuilder, level features.Level, testDynakube dynakubev1beta2.DynaKube) {
builder.WithStep("dynakube deleted", level, remove(testDynakube))
if testDynakube.NeedsOneAgent() {
Expand Down Expand Up @@ -83,6 +110,23 @@ func WaitForPhase(dynakube dynakubev1beta2.DynaKube, phase status.DeploymentPhas
}
}

func WaitForPhasePreviousVersion(dynakube dynakubev1beta1.DynaKube, phase status.DeploymentPhase) features.Func {
return func(ctx context.Context, t *testing.T, envConfig *envconf.Config) context.Context {
resources := envConfig.Client().Resources()

const timeout = 5 * time.Minute
err := wait.For(conditions.New(resources).ResourceMatch(&dynakube, func(object k8s.Object) bool {
dynakube, isDynakube := object.(*dynakubev1beta1.DynaKube)

return isDynakube && dynakube.Status.Phase == phase
}), wait.WithTimeout(timeout))

require.NoError(t, err)

return ctx
}
}

func create(dynakube dynakubev1beta2.DynaKube) features.Func {
return func(ctx context.Context, t *testing.T, envConfig *envconf.Config) context.Context {
require.NoError(t, dynatracev1beta2.AddToScheme(envConfig.Client().Resources().GetScheme()))
Expand All @@ -92,6 +136,15 @@ func create(dynakube dynakubev1beta2.DynaKube) features.Func {
}
}

func createPreviousVersion(dynakube dynakubev1beta1.DynaKube) features.Func {
return func(ctx context.Context, t *testing.T, envConfig *envconf.Config) context.Context {
require.NoError(t, dynatracev1beta1.AddToScheme(envConfig.Client().Resources().GetScheme()))
require.NoError(t, envConfig.Client().Resources().Create(ctx, &dynakube))

return ctx
}
}

func update(dynakube dynakubev1beta2.DynaKube) features.Func {
return func(ctx context.Context, t *testing.T, envConfig *envconf.Config) context.Context {
require.NoError(t, dynatracev1beta2.AddToScheme(envConfig.Client().Resources().GetScheme()))
Expand Down
5 changes: 5 additions & 0 deletions test/helpers/components/oneagent/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package oneagent
import (
"context"

dynatracev1beta1 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta1/dynakube"
dynatracev1beta2 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta2/dynakube"
"github.com/Dynatrace/dynatrace-operator/test/helpers"
"github.com/Dynatrace/dynatrace-operator/test/helpers/kubeobjects/daemonset"
Expand All @@ -19,6 +20,10 @@ func WaitForDaemonset(dynakube dynatracev1beta2.DynaKube) features.Func {
return helpers.ToFeatureFunc(daemonset.WaitFor(dynakube.OneAgentDaemonsetName(), dynakube.Namespace), true)
}

func WaitForDaemonsetV1Beta1(dynakube dynatracev1beta1.DynaKube) features.Func {
return helpers.ToFeatureFunc(daemonset.WaitFor(dynakube.OneAgentDaemonsetName(), dynakube.Namespace), true)
}

func WaitForDaemonSetPodsDeletion(dynakube dynatracev1beta2.DynaKube) features.Func {
return pod.WaitForPodsDeletionWithOwner(dynakube.OneAgentDaemonsetName(), dynakube.Namespace)
}
Expand Down
4 changes: 3 additions & 1 deletion test/scenarios/release/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import (

var testEnv env.Environment

const releaseTag = "1.1.0"

func TestMain(m *testing.M) {
cfg := environment.GetStandardKubeClusterEnvConfig()
testEnv = env.NewWithConfig(cfg)
testEnv.Setup(
tenant.CreateOtelSecret(operator.DefaultNamespace),
operator.InstallViaHelm("0.15.0", true, operator.DefaultNamespace), // TODO: Make the version not hard-coded, but always use the previous version. Using git is not an option because pipeline does not pull the whole git repo.
operator.InstallViaHelm(releaseTag, true, operator.DefaultNamespace), // TODO: add logic to get releaseTag in a dynamic way instead of hard coding it
)
// If we cleaned up during a fail-fast (aka.: /debug) it wouldn't be possible to investigate the error.
if !cfg.FailFast() {
Expand Down

0 comments on commit 3fcdbcb

Please sign in to comment.