Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove arch param where necessary #4065

Merged
merged 8 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/clients/dynatrace/activegate_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dynatrace
import (
"context"

"github.com/Dynatrace/dynatrace-operator/pkg/arch"
"github.com/pkg/errors"
)

Expand All @@ -13,7 +12,7 @@ func (dtc *dynatraceClient) GetLatestActiveGateVersion(ctx context.Context, os s
LatestGatewayVersion string `json:"latestGatewayVersion"`
}{}

url := dtc.getLatestActiveGateVersionUrl(os, arch.Arch)
url := dtc.getLatestActiveGateVersionUrl(os)
err := dtc.makeRequestAndUnmarshal(ctx, url, dynatracePaaSToken, &response)

return response.LatestGatewayVersion, errors.WithStack(err)
Expand Down
31 changes: 20 additions & 11 deletions pkg/clients/dynatrace/agent_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,32 @@ func (dtc *dynatraceClient) GetLatestAgentVersion(ctx context.Context, os, insta
return "", errors.New("os or installerType is empty")
}

var flavor string
// Default installer type has no "multidistro" flavor
// so the default flavor is always needed in that case
url := dtc.getLatestAgentVersionUrl(os, installerType, determineFlavor(installerType), determineArch(installerType))
err := dtc.makeRequestAndUnmarshal(ctx, url, dynatracePaaSToken, &response)

return response.LatestAgentVersion, errors.WithStack(err)
}

// determineArch gives you the proper arch value, because the OSAgent and ActiveGate images on the tenant-image-registry only have AMD images.
func determineArch(installerType string) string {
if installerType == InstallerTypeDefault {
flavor = arch.FlavorDefault
} else {
flavor = arch.Flavor
return ""
}

url := dtc.getLatestAgentVersionUrl(os, installerType, flavor, arch.Arch)
err := dtc.makeRequestAndUnmarshal(ctx, url, dynatracePaaSToken, &response)
return arch.Arch
}

return response.LatestAgentVersion, errors.WithStack(err)
// 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 {
if installerType == InstallerTypeDefault {
return arch.FlavorDefault
}

return arch.Flavor
}

// GetAgentVersions gets available agent versions for the given OS and installer type.
func (dtc *dynatraceClient) GetAgentVersions(ctx context.Context, os, installerType, flavor, arch string) ([]string, error) {
func (dtc *dynatraceClient) GetAgentVersions(ctx context.Context, os, installerType, flavor string) ([]string, error) {
response := struct {
AvailableVersions []string `json:"availableVersions"`
}{}
Expand All @@ -78,7 +87,7 @@ func (dtc *dynatraceClient) GetAgentVersions(ctx context.Context, os, installerT
return nil, errors.New("os or installerType is empty")
}

url := dtc.getAgentVersionsUrl(os, installerType, flavor, arch)
url := dtc.getAgentVersionsUrl(os, installerType, flavor, determineArch(installerType))
err := dtc.makeRequestAndUnmarshal(ctx, url, dynatracePaaSToken, &response)

return response.AvailableVersions, errors.WithStack(err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/clients/dynatrace/agent_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestDynatraceClient_GetAgentVersions(t *testing.T) {
dynatraceServer, dtc := createTestDynatraceClientWithFunc(t, versionsRequestHandler)
defer dynatraceServer.Close()

availableVersions, err := dtc.GetAgentVersions(ctx, OsUnix, InstallerTypePaaS, "", "")
availableVersions, err := dtc.GetAgentVersions(ctx, OsUnix, InstallerTypePaaS, "")

require.NoError(t, err)
assert.Len(t, availableVersions, 4)
Expand All @@ -227,7 +227,7 @@ func TestDynatraceClient_GetAgentVersions(t *testing.T) {
dynatraceServer, dtc := createTestDynatraceClientWithFunc(t, errorHandler)
defer dynatraceServer.Close()

availableVersions, err := dtc.GetAgentVersions(ctx, OsUnix, InstallerTypePaaS, "", "")
availableVersions, err := dtc.GetAgentVersions(ctx, OsUnix, InstallerTypePaaS, "")

require.EqualError(t, err, "dynatrace server error 400: test-error")
assert.Empty(t, availableVersions)
Expand Down
2 changes: 1 addition & 1 deletion pkg/clients/dynatrace/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Client interface {

// GetAgentVersions on success returns an array of versions that can be used with GetAgent to
// download a specific agent version
GetAgentVersions(ctx context.Context, os, installerType, flavor, arch string) ([]string, error)
GetAgentVersions(ctx context.Context, os, installerType, flavor string) ([]string, error)

GetOneAgentConnectionInfo(ctx context.Context) (OneAgentConnectionInfo, error)

Expand Down
10 changes: 5 additions & 5 deletions pkg/clients/dynatrace/dynatrace_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ import (

var (
flavorUri = fmt.Sprintf("/v1/deployment/installer/agent/%s/%s/latest/metainfo?bitness=64&flavor=%s&arch=%s",
OsUnix, InstallerTypeDefault, arch.FlavorDefault+"a", arch.Arch)
OsUnix, InstallerTypePaaS, arch.FlavorMultidistro+"a", arch.Arch)
flavourUriResponse = `{"error":{"code":400,"message":"Constraints violated.","constraintViolations":[{"path":"flavor","message":"'defaulta' must be any of [default, multidistro, musl]","parameterLocation":"QUERY","location":null}]}}`

archUri = fmt.Sprintf("/v1/deployment/installer/agent/%s/%s/latest/metainfo?bitness=64&flavor=%s&arch=%s",
OsUnix, InstallerTypeDefault, arch.FlavorDefault, arch.Arch+"a")
OsUnix, InstallerTypePaaS, arch.FlavorMultidistro, arch.Arch+"a")
archUriResponse = `{"error":{"code":400,"message":"Constraints violated.","constraintViolations":[{"path":"arch","message":"'x86a' must be any of [all, arm, ppc, ppcle, s390, sparc, x86, zos]","parameterLocation":"QUERY","location":null}]}}`

flavorArchUri = fmt.Sprintf("/v1/deployment/installer/agent/%s/%s/latest/metainfo?bitness=64&flavor=%s&arch=%s",
OsUnix, InstallerTypeDefault, arch.FlavorDefault+"a", arch.Arch+"a")
OsUnix, InstallerTypePaaS, arch.FlavorMultidistro+"a", arch.Arch+"a")
flavourArchUriResponse = `{"error":{"code":400,"message":"Constraints violated.","constraintViolations":[{"path":"flavor","message":"'defaulta' must be any of [default, multidistro, musl]","parameterLocation":"QUERY","location":null},{"path":"arch","message":"'x86a' must be any of [all, arm, ppc, ppcle, s390, sparc, x86, zos]","parameterLocation":"QUERY","location":null}]}}`

oaLatestMetainfoUri = fmt.Sprintf("/v1/deployment/installer/agent/%s/%s/latest/metainfo?bitness=64&flavor=%s&arch=%s",
"aix", InstallerTypeDefault, arch.FlavorDefault, arch.Arch)
"aix", InstallerTypePaaS, arch.FlavorMultidistro, arch.Arch)
oaLatestMetainfoUriResponse = `{"error":{"code":404,"message":"non supported architecture <OS_ARCHITECTURE_X86> on OS <OS_TYPE_AIX>"}}`
)

Expand Down Expand Up @@ -315,7 +315,7 @@ func testServerErrors(t *testing.T) {
})

t.Run("GetLatestAgentVersion - invalid architecture", func(t *testing.T) {
_, err = dtc.GetLatestAgentVersion(context.Background(), "aix", InstallerTypeDefault)
_, 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())
})
}
Expand Down
24 changes: 17 additions & 7 deletions pkg/clients/dynatrace/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,28 @@ func (dtc *dynatraceClient) getLatestAgentUrl(os, installerType, flavor, arch st
}

func (dtc *dynatraceClient) getLatestAgentVersionUrl(os, installerType, flavor, arch string) string {
return fmt.Sprintf("%s/v1/deployment/installer/agent/%s/%s/latest/metainfo?bitness=64&flavor=%s&arch=%s",
dtc.url, os, installerType, flavor, arch)
if arch != "" {
return fmt.Sprintf("%s/v1/deployment/installer/agent/%s/%s/latest/metainfo?bitness=64&flavor=%s&arch=%s",
dtc.url, os, installerType, flavor, arch)
}

return fmt.Sprintf("%s/v1/deployment/installer/agent/%s/%s/latest/metainfo?bitness=64&flavor=%s",
dtc.url, os, installerType, flavor)
}

func (dtc *dynatraceClient) getLatestActiveGateVersionUrl(os, arch string) string {
return fmt.Sprintf("%s/v1/deployment/installer/gateway/%s/latest/metainfo?arch=%s",
dtc.url, os, arch)
func (dtc *dynatraceClient) getLatestActiveGateVersionUrl(os string) string {
return fmt.Sprintf("%s/v1/deployment/installer/gateway/%s/latest/metainfo",
dtc.url, os)
}

func (dtc *dynatraceClient) getAgentVersionsUrl(os, installerType, flavor, arch string) string {
return fmt.Sprintf("%s/v1/deployment/installer/agent/versions/%s/%s?flavor=%s&arch=%s",
dtc.url, os, installerType, flavor, arch)
if arch != "" {
return fmt.Sprintf("%s/v1/deployment/installer/agent/versions/%s/%s?flavor=%s&arch=%s",
dtc.url, os, installerType, flavor, arch)
}

return fmt.Sprintf("%s/v1/deployment/installer/agent/versions/%s/%s?flavor=%s",
dtc.url, os, installerType, flavor)
}
0sewa0 marked this conversation as resolved.
Show resolved Hide resolved

func (dtc *dynatraceClient) getOneAgentConnectionInfoUrl() string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package statefulset
import (
"strconv"

"github.com/Dynatrace/dynatrace-operator/pkg/api/status"
"github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta3/dynakube"
"github.com/Dynatrace/dynatrace-operator/pkg/controllers/dynakube/activegate/capability"
"github.com/Dynatrace/dynatrace-operator/pkg/controllers/dynakube/activegate/consts"
Expand Down Expand Up @@ -116,7 +117,7 @@ func (statefulSetBuilder Builder) addTemplateSpec(sts *appsv1.StatefulSet) {
Containers: statefulSetBuilder.buildBaseContainer(),
NodeSelector: statefulSetBuilder.capability.Properties().NodeSelector,
ServiceAccountName: statefulSetBuilder.dynakube.ActiveGate().GetServiceAccountName(),
Affinity: nodeAffinity(),
Affinity: statefulSetBuilder.nodeAffinity(),
Tolerations: statefulSetBuilder.capability.Properties().Tolerations,
SecurityContext: &corev1.PodSecurityContext{
SeccompProfile: &corev1.SeccompProfile{
Expand Down Expand Up @@ -222,16 +223,13 @@ func (statefulSetBuilder Builder) buildCommonEnvs() []corev1.EnvVar {
return statefulSetBuilder.envMap.AsEnvVars()
}

func nodeAffinity() *corev1.Affinity {
return &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
NodeSelectorTerms: []corev1.NodeSelectorTerm{
{
MatchExpressions: node.AffinityNodeRequirementForSupportedArches(),
},
},
},
},
func (statefulSetBuilder Builder) nodeAffinity() *corev1.Affinity {
var affinity corev1.Affinity
if statefulSetBuilder.dynakube.Status.ActiveGate.Source == status.TenantRegistryVersionSource || statefulSetBuilder.dynakube.Status.ActiveGate.Source == status.CustomVersionVersionSource {
affinity = node.AMDOnlyAffinity()
} else {
affinity = node.Affinity()
}

return &affinity
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,34 @@ func TestGetBaseObjectMeta(t *testing.T) {
require.NotEmpty(t, sts.Spec.Template.Labels)
assert.Equal(t, expectedTemplateAnnotations, sts.Spec.Template.Annotations)
})
t.Run("has default node affinity", func(t *testing.T) {
t.Run("has default(tenant-registry) node affinity", func(t *testing.T) {
dk := getTestDynakube()
dk.Status.ActiveGate.VersionStatus.Source = status.TenantRegistryVersionSource
multiCapability := capability.NewMultiCapability(&dk)
builder := NewStatefulSetBuilder(testKubeUID, testConfigHash, dk, multiCapability)
sts, _ := builder.CreateStatefulSet(nil)
expectedNodeSelectorTerms := []corev1.NodeSelectorTerm{
{
MatchExpressions: []corev1.NodeSelectorRequirement{
{
Key: "kubernetes.io/arch",
Operator: corev1.NodeSelectorOpIn,
Values: []string{"amd64"},
},
{
Key: "kubernetes.io/os",
Operator: corev1.NodeSelectorOpIn,
Values: []string{"linux"},
},
},
}}

require.NotEmpty(t, sts.Spec.Template.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms)
assert.Contains(t, sts.Spec.Template.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms, expectedNodeSelectorTerms[0])
})
t.Run("has none tenant-registry node affinity", func(t *testing.T) {
dk := getTestDynakube()
dk.Status.ActiveGate.VersionStatus.Source = status.CustomImageVersionSource
multiCapability := capability.NewMultiCapability(&dk)
builder := NewStatefulSetBuilder(testKubeUID, testConfigHash, dk, multiCapability)
sts, _ := builder.CreateStatefulSet(nil)
Expand Down
15 changes: 2 additions & 13 deletions pkg/controllers/dynakube/extension/eec/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,19 +462,8 @@ func TestAffinity(t *testing.T) {

statefulSet := getStatefulset(t, dk)

expectedAffinity := &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
NodeSelectorTerms: []corev1.NodeSelectorTerm{
{
MatchExpressions: node.AffinityNodeRequirementForSupportedArches(),
},
},
},
},
}

assert.Equal(t, expectedAffinity, statefulSet.Spec.Template.Spec.Affinity)
expectedAffinity := node.Affinity()
assert.Equal(t, expectedAffinity, *statefulSet.Spec.Template.Spec.Affinity)
})
}

Expand Down
12 changes: 1 addition & 11 deletions pkg/controllers/dynakube/extension/eec/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,7 @@ func buildAppLabels(dynakubeName string) *labels.AppLabels {
}

func buildAffinity() corev1.Affinity {
return corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
NodeSelectorTerms: []corev1.NodeSelectorTerm{
{
MatchExpressions: node.AffinityNodeRequirementForSupportedArches(),
},
},
},
},
}
return node.Affinity()
}

func setImagePullSecrets(imagePullSecrets []corev1.LocalObjectReference) func(o *appsv1.StatefulSet) {
Expand Down
12 changes: 1 addition & 11 deletions pkg/controllers/dynakube/extension/otel/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,7 @@ func buildAppLabels(dkName string) *labels.AppLabels {
func buildAffinity() corev1.Affinity {
// TODO: implement new attributes in CR dk.Spec.Templates.OpenTelemetryCollector.Affinity
// otherwise to use defaults ones
return corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
NodeSelectorTerms: []corev1.NodeSelectorTerm{
{
MatchExpressions: node.AffinityNodeRequirementForSupportedArches(),
},
},
},
},
}
return node.Affinity()
}

func setImagePullSecrets(imagePullSecrets []corev1.LocalObjectReference) func(o *appsv1.StatefulSet) {
Expand Down
14 changes: 2 additions & 12 deletions pkg/controllers/dynakube/extension/otel/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,9 @@ func TestAffinity(t *testing.T) {
dk := getTestDynakube()
statefulSet := getStatefulset(t, dk)

expectedAffinity := &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
NodeSelectorTerms: []corev1.NodeSelectorTerm{
{
MatchExpressions: node.AffinityNodeRequirementForSupportedArches(),
},
},
},
},
}
expectedAffinity := node.Affinity()

assert.Equal(t, expectedAffinity, statefulSet.Spec.Template.Spec.Affinity)
assert.Equal(t, expectedAffinity, *statefulSet.Spec.Template.Spec.Affinity)
})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/dynakube/kspm/daemonset/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (r *Reconciler) generateDaemonSet() (*appsv1.DaemonSet, error) {
daemonset.SetAllLabels(labels.BuildLabels(), labels.BuildMatchLabels(), labels.BuildLabels(), r.dk.KSPM().Labels),
daemonset.SetAllAnnotations(r.dk.KSPM().Annotations, templateAnnotations),
daemonset.SetServiceAccount(serviceAccountName),
daemonset.SetAffinity(node.Affinity()),
daemonset.SetAffinity(node.AMDOnlyAffinity()),
daemonset.SetPriorityClass(r.dk.KSPM().PriorityClassName),
daemonset.SetTolerations(r.dk.KSPM().Tolerations),
daemonset.SetPullSecret(r.dk.ImagePullSecretReferences()...),
Expand Down
26 changes: 7 additions & 19 deletions pkg/controllers/dynakube/oneagent/daemonset/affinity.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
package daemonset

import (
"github.com/Dynatrace/dynatrace-operator/pkg/api/status"
"github.com/Dynatrace/dynatrace-operator/pkg/util/kubeobjects/node"
corev1 "k8s.io/api/core/v1"
)

func (b *builder) affinity() *corev1.Affinity {
return &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
NodeSelectorTerms: b.affinityNodeSelectorTerms(),
},
},
}
}

func (b *builder) affinityNodeSelectorTerms() []corev1.NodeSelectorTerm {
nodeSelectorTerms := []corev1.NodeSelectorTerm{
kubernetesArchOsSelectorTerm(),
var affinity corev1.Affinity
if b.dk.Status.OneAgent.VersionStatus.Source == status.TenantRegistryVersionSource || b.dk.Status.OneAgent.VersionStatus.Source == status.CustomVersionVersionSource {
affinity = node.AMDOnlyAffinity()
} else {
affinity = node.Affinity()
}

return nodeSelectorTerms
}

func kubernetesArchOsSelectorTerm() corev1.NodeSelectorTerm {
return corev1.NodeSelectorTerm{
MatchExpressions: node.AffinityNodeRequirementForSupportedArches(),
}
return &affinity
}
Loading
Loading