Skip to content

Commit

Permalink
Transfers EC.Labels and EC.Annotations to the POD spec
Browse files Browse the repository at this point in the history
  • Loading branch information
aorcholski committed Dec 3, 2024
1 parent 2904e52 commit c2f26e5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
5 changes: 4 additions & 1 deletion pkg/controllers/edgeconnect/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,10 @@ func (controller *Controller) createOrUpdateEdgeConnectDeploymentAndSettings(ctx

desiredDeployment := deployment.New(ec)

desiredDeployment.Spec.Template.Annotations = map[string]string{consts.EdgeConnectAnnotationSecretHash: secretHash}
if desiredDeployment.Spec.Template.Annotations == nil {
desiredDeployment.Spec.Template.Annotations = map[string]string{}
}
desiredDeployment.Spec.Template.Annotations[consts.EdgeConnectAnnotationSecretHash] = secretHash

Check failure on line 680 in pkg/controllers/edgeconnect/controller.go

View workflow job for this annotation

GitHub Actions / Run linting

assignments should only be cuddled with other assignments (wsl)
_log = _log.WithValues("deploymentName", desiredDeployment.Name)

if err := controllerutil.SetControllerReference(ec, desiredDeployment, scheme.Scheme); err != nil {
Expand Down
18 changes: 9 additions & 9 deletions pkg/controllers/edgeconnect/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/Dynatrace/dynatrace-operator/pkg/util/kubeobjects/labels"
"github.com/Dynatrace/dynatrace-operator/pkg/util/kubeobjects/resources"
maputils "github.com/Dynatrace/dynatrace-operator/pkg/util/map"
"github.com/Dynatrace/dynatrace-operator/pkg/util/prioritymap"
"github.com/Dynatrace/dynatrace-operator/pkg/webhook"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -15,10 +14,8 @@ import (
)

const (
customEnvPriority = prioritymap.HighPriority
defaultEnvPriority = prioritymap.DefaultPriority
unprivilegedUser = int64(1000)
unprivilegedGroup = int64(1000)
unprivilegedUser = int64(1000)
unprivilegedGroup = int64(1000)
)

func New(ec *edgeconnect.EdgeConnect) *appsv1.Deployment {
Expand All @@ -27,9 +24,11 @@ func New(ec *edgeconnect.EdgeConnect) *appsv1.Deployment {

func create(ec *edgeconnect.EdgeConnect) *appsv1.Deployment {
appLabels := buildAppLabels(ec)
labels := maputils.MergeMap(
ec.Labels,
appLabels.BuildLabels(),
labels := appLabels.BuildLabels()

podLabels := maputils.MergeMap(
labels,
ec.Spec.Labels,
)

log.Debug("EdgeConnect deployment app labels", "labels", labels)
Expand All @@ -48,7 +47,8 @@ func create(ec *edgeconnect.EdgeConnect) *appsv1.Deployment {
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Annotations: ec.Spec.Annotations,
Labels: podLabels,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{edgeConnectContainer(ec)},
Expand Down
36 changes: 36 additions & 0 deletions pkg/controllers/edgeconnect/deployment/deployment_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package deployment

import (
maputils "github.com/Dynatrace/dynatrace-operator/pkg/util/map"
"testing"
"time"

Expand Down Expand Up @@ -66,6 +67,41 @@ func Test_buildAppLabels(t *testing.T) {
})
}

func Test_buildLabels(t *testing.T) {
ec := &edgeconnect.EdgeConnect{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testNamespace,
},
Spec: edgeconnect.EdgeConnectSpec{
ApiServer: "abc12345.dynatrace.com",
Labels: map[string]string{
"app": "test-app",
},
OAuth: edgeconnect.OAuthSpec{
ClientSecret: "secret-name",
Endpoint: "https://test.com/sso/oauth2/token",
Resource: "urn:dtenvironment:test12345",
},
},
Status: edgeconnect.EdgeConnectStatus{
Version: status.VersionStatus{
Version: "",
},
UpdatedTimestamp: metav1.NewTime(time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC)),
},
}

t.Run("Check custom label set correctly", func(t *testing.T) {
appLabels := buildAppLabels(ec)
labels := maputils.MergeMap(
ec.Labels,
appLabels.BuildLabels(),
)
assert.Contains(t, labels, "app")
})
}

func Test_prepareResourceRequirements(t *testing.T) {
ec := &edgeconnect.EdgeConnect{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit c2f26e5

Please sign in to comment.