Skip to content

Commit

Permalink
Merge branch 'release-1.4' into fixup-e2e-tests-release-1-4
Browse files Browse the repository at this point in the history
  • Loading branch information
andriisoldatenko authored Dec 2, 2024
2 parents c35370d + 83a94b6 commit 3193c31
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN --mount=type=cache,target="/root/.cache/go-build" CGO_ENABLED=1 CGO_CFLAGS="
go build -tags "${GO_BUILD_TAGS}" -trimpath -ldflags="${GO_LINKER_ARGS}" \
-o ./build/_output/bin/dynatrace-operator ./cmd/

FROM registry.access.redhat.com/ubi9-micro:9.5-1731934928@sha256:31f00ba1d79523e182624c96e05b2f5ca66ea35d64959d84acdc8b670429415f AS base
FROM registry.access.redhat.com/ubi9-micro:9.5-1733126338@sha256:a410623c2b8e9429f9606af821be0231fef2372bd0f5f853fbe9743a0ddf7b34 AS base
FROM registry.access.redhat.com/ubi9:9.5-1732804088@sha256:1057dab827c782abcfb9bda0c3900c0966b5066e671d54976a7bcb3a2d1a5e53 AS dependency
RUN mkdir -p /tmp/rootfs-dependency
COPY --from=base / /tmp/rootfs-dependency
Expand Down
29 changes: 29 additions & 0 deletions pkg/api/validation/dynakube/eec.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package validation

import (
"fmt"

"github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta3/dynakube"
"golang.org/x/net/context"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
errorExtensionExecutionControllerImageNotSpecified = `DynaKube's specification enables the Prometheus feature, make sure you correctly specify the ExtensionExecutionController image.`
errorExtensionExecutionControllerInvalidPVCConfiguration = `DynaKube specifies a PVC for the extension controller while ephemeral volume is also enabled. These settings are mutually exclusive, please choose only one.`
warningConflictingApiUrlForExtensions = `You are already using a Dynakube ('%s') that enables extensions. Having multiple Dynakubes with same '.spec.apiUrl' and '.spec.extensions' enabled can have severe side-effects on “sum” and “count” metrics and cause double-billing.`
)

func extensionControllerImage(_ context.Context, _ *Validator, dk *dynakube.DynaKube) string {
Expand All @@ -24,6 +28,31 @@ func extensionControllerImage(_ context.Context, _ *Validator, dk *dynakube.Dyna
return ""
}

func conflictingApiUrlForExtensions(ctx context.Context, dv *Validator, dk *dynakube.DynaKube) string {
if !dk.IsExtensionsEnabled() {
return ""
}

validDynakubes := &dynakube.DynaKubeList{}
if err := dv.apiReader.List(ctx, validDynakubes, &client.ListOptions{Namespace: dk.Namespace}); err != nil {
log.Info("error occurred while listing dynakubes", "err", err.Error())

return ""
}

for _, item := range validDynakubes.Items {
if item.Name == dk.Name {
continue
}

if item.IsExtensionsEnabled() && (dk.ApiUrl() == item.ApiUrl()) {
return fmt.Sprintf(warningConflictingApiUrlForExtensions, item.Name)
}
}

return ""
}

func extensionControllerPVCStorageDevice(_ context.Context, _ *Validator, dk *dynakube.DynaKube) string {
if !dk.IsExtensionsEnabled() {
return ""
Expand Down
100 changes: 100 additions & 0 deletions pkg/api/validation/dynakube/eec_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package validation

import (
"fmt"
"testing"

"github.com/Dynatrace/dynatrace-operator/pkg/api/shared/image"
"github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta3/dynakube"
"github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta3/dynakube/activegate"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestExtensionExecutionControllerImage(t *testing.T) {
Expand Down Expand Up @@ -141,3 +147,97 @@ func TestExtensionExecutionControllerPVCSettings(t *testing.T) {
})
})
}

func TestWarnIfmultiplyDKwithExtensionsEnabled(t *testing.T) {
imgRef := image.Ref{
Repository: "a",
Tag: "b",
}
// we want to exclude AG resources warning.
agSpec := activegate.Spec{
CapabilityProperties: activegate.CapabilityProperties{
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
},
},
},
}
dk1 := &dynakube.DynaKube{
ObjectMeta: defaultDynakubeObjectMeta,
Spec: dynakube.DynaKubeSpec{
APIURL: testApiUrl,
Extensions: &dynakube.ExtensionsSpec{},
Templates: dynakube.TemplatesSpec{
ExtensionExecutionController: dynakube.ExtensionExecutionControllerSpec{
ImageRef: imgRef,
},
},
ActiveGate: agSpec,
},
}

t.Run("no warning different ApiUrls", func(t *testing.T) {
dk2 := &dynakube.DynaKube{
ObjectMeta: metav1.ObjectMeta{
Name: testName + "second",
Namespace: testNamespace,
},
Spec: dynakube.DynaKubeSpec{
APIURL: "https://f.q.d.n/123",
Extensions: &dynakube.ExtensionsSpec{},
Templates: dynakube.TemplatesSpec{
ExtensionExecutionController: dynakube.ExtensionExecutionControllerSpec{
ImageRef: imgRef,
},
},
ActiveGate: agSpec,
},
}
assertAllowedWithoutWarnings(t, dk1, dk2)
})
t.Run("warning same ApiUrls", func(t *testing.T) {
dk2 := &dynakube.DynaKube{
ObjectMeta: metav1.ObjectMeta{
Name: testName + "second",
Namespace: testNamespace,
},
Spec: dynakube.DynaKubeSpec{
APIURL: testApiUrl,
Extensions: &dynakube.ExtensionsSpec{},
Templates: dynakube.TemplatesSpec{
ExtensionExecutionController: dynakube.ExtensionExecutionControllerSpec{
ImageRef: imgRef,
},
},
ActiveGate: agSpec,
},
}
warnings, err := assertAllowed(t, dk1, dk2)
require.NoError(t, err)
require.Len(t, warnings, 1)

expected := fmt.Sprintf(warningConflictingApiUrlForExtensions, dk2.Name)
assert.Equal(t, expected, warnings[0])
})

t.Run("no warning same ApiUrls and for second dk: extensions feature is disabled", func(t *testing.T) {
dk2 := &dynakube.DynaKube{
ObjectMeta: metav1.ObjectMeta{
Name: testName + "second",
Namespace: testNamespace,
},
Spec: dynakube.DynaKubeSpec{
APIURL: testApiUrl,
Extensions: nil,
Templates: dynakube.TemplatesSpec{
ExtensionExecutionController: dynakube.ExtensionExecutionControllerSpec{
ImageRef: imgRef,
},
},
ActiveGate: agSpec,
},
}
assertAllowedWithoutWarnings(t, dk1, dk2)
})
}
1 change: 1 addition & 0 deletions pkg/api/validation/dynakube/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var (
conflictingHostGroupSettings,
deprecatedFeatureFlag,
ignoredLogMonitoringTemplate,
conflictingApiUrlForExtensions,
}
updateValidatorErrorFuncs = []updateValidatorFunc{
IsMutatedApiUrl,
Expand Down
2 changes: 1 addition & 1 deletion pkg/clients/dynatrace/agent_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func determineArch(installerType string) string {
}

// determineFlavor gives you the proper flavor value, because the default installer type has no "multidistro" flavor so the default flavor is always needed in that case.
func determineFlavor(installerType string) string {
func determineFlavor(installerType string) string { //nolint:nolintlint,unparam
if installerType == InstallerTypeDefault {
return arch.FlavorDefault
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/clients/dynatrace/dynatrace_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,6 @@ func testServerErrors(t *testing.T) {
err = dtc.makeRequestAndUnmarshal(context.Background(), dtc.url+flavorArchUri, dynatracePaaSToken, &response)
assert.Equal(t, "dynatrace server error 400: Constraints violated.\n\t- flavor: 'defaulta' must be any of [default, multidistro, musl]\n\t- arch: 'x86a' must be any of [all, arm, ppc, ppcle, s390, sparc, x86, zos]", err.Error())
})

t.Run("GetLatestAgentVersion - invalid architecture", func(t *testing.T) {
_, err = dtc.GetLatestAgentVersion(context.Background(), "aix", InstallerTypePaaS)
assert.Equal(t, "dynatrace server error 404: non supported architecture <OS_ARCHITECTURE_X86> on OS <OS_TYPE_AIX>", err.Error())
})
}

func dynatraceServerErrorsHandler() http.HandlerFunc {
Expand Down

0 comments on commit 3193c31

Please sign in to comment.