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

Infer csi-usage based on csi-driver-availability #4039

Merged
merged 10 commits into from
Nov 25, 2024
3 changes: 0 additions & 3 deletions cmd/troubleshoot/dynakube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/Dynatrace/dynatrace-operator/pkg/api/shared/value"
waodim marked this conversation as resolved.
Show resolved Hide resolved
"github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta3/dynakube"
"github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta3/dynakube/activegate"
"github.com/Dynatrace/dynatrace-operator/pkg/util/address"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -378,14 +377,12 @@ func (builder *testDynaKubeBuilder) withCloudNativeCodeModulesImage(image string
func (builder *testDynaKubeBuilder) withApplicationMonitoringCodeModulesImage(image string) *testDynaKubeBuilder {
if builder.dynakube.Spec.OneAgent.ApplicationMonitoring != nil {
builder.dynakube.Spec.OneAgent.ApplicationMonitoring.CodeModulesImage = image
builder.dynakube.Spec.OneAgent.ApplicationMonitoring.UseCSIDriver = address.Of(true)
} else {
builder.dynakube.Spec.OneAgent.ApplicationMonitoring = &dynakube.ApplicationMonitoringSpec{
AppInjectionSpec: dynakube.AppInjectionSpec{
InitResources: &corev1.ResourceRequirements{},
CodeModulesImage: image,
},
UseCSIDriver: address.Of(true),
}
}
builder.dynakube.Status.CodeModules.ImageID = image
Expand Down
5 changes: 0 additions & 5 deletions config/crd/bases/dynatrace.com_dynakubes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5053,11 +5053,6 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
useCSIDriver:
description: Set if you want to use the CSIDriver. Don't enable
it if you do not have access to Kubernetes nodes or if you
lack privileges.
type: boolean
version:
description: Use a specific OneAgent CodeModule version. Defaults
to the latest version from the Dynatrace cluster.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5065,11 +5065,6 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
useCSIDriver:
description: Set if you want to use the CSIDriver. Don't enable
it if you do not have access to Kubernetes nodes or if you
lack privileges.
type: boolean
version:
description: Use a specific OneAgent CodeModule version. Defaults
to the latest version from the Dynatrace cluster.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ spec:
- name: MAX_UNMOUNTED_VOLUME_AGE
value: "{{ .Values.csidriver.maxUnmountedVolumeAge}}"
{{- end }}
envFrom:
chrismuellner marked this conversation as resolved.
Show resolved Hide resolved
- configMapRef:
name: install-config
{{- include "dynatrace-operator.startupProbe" . | nindent 8 }}
{{- if not .Values.debug }}
livenessProbe:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ metadata:
data:
modules.json: |
{
"csiDriver": {{ .Values.csidriver.enabled }},
"activeGate": {{ .Values.rbac.activeGate.create }},
"oneAgent": {{ .Values.rbac.oneAgent.create }},
"extensions": {{ .Values.rbac.extensions.create }},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ tests:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
envFrom:
- configMapRef:
name: install-config
image: image-name
imagePullPolicy: Always
startupProbe:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tests:
value:
modules.json: |
{
"csiDriver": true,
"activeGate": true,
"oneAgent": true,
"extensions": true,
Expand All @@ -27,6 +28,7 @@ tests:
}
- it: ConfigMap should respect the set values
set:
csidriver.enabled: false
rbac.oneAgent.create: false
rbac.logMonitoring.create: false
rbac.edgeConnect.create: false
Expand All @@ -48,6 +50,7 @@ tests:
value:
modules.json: |
{
"csiDriver": false,
"activeGate": false,
"oneAgent": false,
"extensions": false,
Expand Down
5 changes: 4 additions & 1 deletion pkg/api/v1beta1/dynakube/convert_from.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import (

"github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta3/dynakube"
"github.com/Dynatrace/dynatrace-operator/pkg/util/address"
"github.com/Dynatrace/dynatrace-operator/pkg/util/installconfig"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

var isEnabledModules = installconfig.GetModules()

// ConvertFrom converts v1beta3 to v1beta1.
func (dst *DynaKube) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*dynakube.DynaKube)
Expand Down Expand Up @@ -57,7 +60,7 @@ func (dst *DynaKube) fromOneAgentSpec(src *dynakube.DynaKube) {
dst.Spec.OneAgent.ApplicationMonitoring = &ApplicationMonitoringSpec{}
dst.Spec.OneAgent.ApplicationMonitoring.AppInjectionSpec = *fromAppInjectSpec(src.Spec.OneAgent.ApplicationMonitoring.AppInjectionSpec)
dst.Spec.OneAgent.ApplicationMonitoring.Version = src.Spec.OneAgent.ApplicationMonitoring.Version
dst.Spec.OneAgent.ApplicationMonitoring.UseCSIDriver = src.Spec.OneAgent.ApplicationMonitoring.UseCSIDriver
dst.Spec.OneAgent.ApplicationMonitoring.UseCSIDriver = &isEnabledModules.CSIDriver
}
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/api/v1beta1/dynakube/convert_from_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func compareCloudNativeSpec(t *testing.T, oldSpec CloudNativeFullStackSpec, newS

func compareApplicationMonitoringSpec(t *testing.T, oldSpec ApplicationMonitoringSpec, newSpec dynakube.ApplicationMonitoringSpec) {
compareAppInjectionSpec(t, oldSpec.AppInjectionSpec, newSpec.AppInjectionSpec)
assert.Equal(t, *oldSpec.UseCSIDriver, *newSpec.UseCSIDriver)
assert.Equal(t, *oldSpec.UseCSIDriver, isEnabledModules.CSIDriver)
assert.Equal(t, oldSpec.Version, newSpec.Version)
}

Expand Down Expand Up @@ -343,7 +343,6 @@ func getNewCloudNativeSpec() dynakube.CloudNativeFullStackSpec {
func getNewApplicationMonitoringSpec() dynakube.ApplicationMonitoringSpec {
return dynakube.ApplicationMonitoringSpec{
AppInjectionSpec: getNewAppInjectionSpec(),
UseCSIDriver: address.Of(true),
Version: "app-monitoring-version",
}
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/api/v1beta1/dynakube/convert_to.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ func (src *DynaKube) toOneAgentSpec(dst *dynakube.DynaKube) {
dst.Spec.OneAgent.ApplicationMonitoring = &dynakube.ApplicationMonitoringSpec{}
dst.Spec.OneAgent.ApplicationMonitoring.AppInjectionSpec = *toAppInjectSpec(src.Spec.OneAgent.ApplicationMonitoring.AppInjectionSpec)
dst.Spec.OneAgent.ApplicationMonitoring.Version = src.Spec.OneAgent.ApplicationMonitoring.Version

if src.Spec.OneAgent.ApplicationMonitoring.UseCSIDriver != nil {
dst.Spec.OneAgent.ApplicationMonitoring.UseCSIDriver = src.Spec.OneAgent.ApplicationMonitoring.UseCSIDriver
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/api/v1beta2/dynakube/convert_from.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package dynakube

import (
v1beta3 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta3/dynakube"
"github.com/Dynatrace/dynatrace-operator/pkg/util/installconfig"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

var isEnabledModules = installconfig.GetModules()

// ConvertFrom converts from the Hub version (v1beta3) to this version (v1beta3).
func (dst *DynaKube) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1beta3.DynaKube)
Expand Down Expand Up @@ -52,7 +55,7 @@ func (dst *DynaKube) fromOneAgentSpec(src *v1beta3.DynaKube) {
dst.Spec.OneAgent.ApplicationMonitoring = &ApplicationMonitoringSpec{}
dst.Spec.OneAgent.ApplicationMonitoring.AppInjectionSpec = *fromAppInjectSpec(src.Spec.OneAgent.ApplicationMonitoring.AppInjectionSpec)
dst.Spec.OneAgent.ApplicationMonitoring.Version = src.Spec.OneAgent.ApplicationMonitoring.Version
dst.Spec.OneAgent.ApplicationMonitoring.UseCSIDriver = src.IsAppMonitoringWithCSI()
dst.Spec.OneAgent.ApplicationMonitoring.UseCSIDriver = isEnabledModules.CSIDriver
}
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/api/v1beta2/dynakube/convert_from_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func compareCloudNativeSpec(t *testing.T, oldSpec CloudNativeFullStackSpec, newS

func compareApplicationMonitoringSpec(t *testing.T, oldSpec ApplicationMonitoringSpec, newSpec dynakube.ApplicationMonitoringSpec) {
compareAppInjectionSpec(t, oldSpec.AppInjectionSpec, newSpec.AppInjectionSpec)
assert.Equal(t, oldSpec.UseCSIDriver, *newSpec.UseCSIDriver)
assert.Equal(t, oldSpec.UseCSIDriver, isEnabledModules.CSIDriver)
assert.Equal(t, oldSpec.Version, newSpec.Version)
}

Expand Down Expand Up @@ -334,7 +334,6 @@ func getNewCloudNativeSpec() dynakube.CloudNativeFullStackSpec {
func getNewApplicationMonitoringSpec() dynakube.ApplicationMonitoringSpec {
return dynakube.ApplicationMonitoringSpec{
AppInjectionSpec: getNewAppInjectionSpec(),
UseCSIDriver: address.Of(true),
Version: "app-monitoring-version",
}
}
Expand Down
1 change: 0 additions & 1 deletion pkg/api/v1beta2/dynakube/convert_to.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (src *DynaKube) toOneAgentSpec(dst *dynakube.DynaKube) {
dst.Spec.OneAgent.ApplicationMonitoring = &dynakube.ApplicationMonitoringSpec{}
dst.Spec.OneAgent.ApplicationMonitoring.AppInjectionSpec = *toAppInjectSpec(src.Spec.OneAgent.ApplicationMonitoring.AppInjectionSpec)
dst.Spec.OneAgent.ApplicationMonitoring.Version = src.Spec.OneAgent.ApplicationMonitoring.Version
dst.Spec.OneAgent.ApplicationMonitoring.UseCSIDriver = &src.Spec.OneAgent.ApplicationMonitoring.UseCSIDriver
}
}

Expand Down
8 changes: 0 additions & 8 deletions pkg/api/v1beta3/dynakube/feature_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const (
AnnotationInjectionFailurePolicy = AnnotationFeaturePrefix + "injection-failure-policy"
AnnotationFeatureInitContainerSeccomp = AnnotationFeaturePrefix + "init-container-seccomp-profile"
AnnotationFeatureEnforcementMode = AnnotationFeaturePrefix + "enforcement-mode"
AnnotationFeatureReadOnlyOneAgent = AnnotationFeaturePrefix + "oneagent-readonly-host-fs"

// CSI.
AnnotationFeatureMaxFailedCsiMountAttempts = AnnotationFeaturePrefix + "max-csi-mount-attempts"
Expand Down Expand Up @@ -193,13 +192,6 @@ func (dk *DynaKube) FeatureAutomaticInjection() bool {
return dk.getFeatureFlagRaw(AnnotationFeatureAutomaticInjection) != falsePhrase
}

// FeatureReadOnlyOneAgent controls whether the host agent is run in readonly mode.
// In Host Monitoring disabling readonly mode, also disables the use of a CSI volume.
// Not compatible with Classic Fullstack.
func (dk *DynaKube) FeatureReadOnlyOneAgent() bool {
return dk.getFeatureFlagRaw(AnnotationFeatureReadOnlyOneAgent) != falsePhrase
}

// FeatureEnableMultipleOsAgentsOnNode is a feature flag to enable multiple osagents running on the same host.
func (dk *DynaKube) FeatureEnableMultipleOsAgentsOnNode() bool {
return dk.getFeatureFlagRaw(AnnotationFeatureMultipleOsAgentsOnNode) == truePhrase
Expand Down
33 changes: 8 additions & 25 deletions pkg/api/v1beta3/dynakube/oneagent_props.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/Dynatrace/dynatrace-operator/pkg/api"
"github.com/Dynatrace/dynatrace-operator/pkg/util/dtversion"
"github.com/Dynatrace/dynatrace-operator/pkg/util/installconfig"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -17,6 +18,10 @@ const (
DefaultOneAgentImageRegistrySubPath = "/linux/oneagent"
)

func (dk *DynaKube) IsCSIAvailable() bool {
return installconfig.GetModules().CSIDriver
}

// ApplicationMonitoringMode returns true when application only section is used.
func (dk *DynaKube) ApplicationMonitoringMode() bool {
return dk.Spec.OneAgent != OneAgentSpec{} && dk.Spec.OneAgent.ApplicationMonitoring != nil
Expand Down Expand Up @@ -77,30 +82,8 @@ func (dk *DynaKube) OneAgentConnectionInfoConfigMapName() string {
return dk.Name + OneAgentConnectionInfoConfigMapSuffix
}

func (dk *DynaKube) NeedsReadOnlyOneAgents() bool {
return (dk.HostMonitoringMode() || dk.CloudNativeFullstackMode()) &&
dk.FeatureReadOnlyOneAgent()
}

func (dk *DynaKube) IsAppMonitoringWithCSI() bool {
if !dk.ApplicationMonitoringMode() {
return false
}

defaultUseCSIDriver := false
if dk.Spec.OneAgent.ApplicationMonitoring.UseCSIDriver == nil {
return defaultUseCSIDriver
}

return *dk.Spec.OneAgent.ApplicationMonitoring.UseCSIDriver
}

func (dk *DynaKube) NeedsCSIDriver() bool {
isAppMonitoringWithCSI := dk.IsAppMonitoringWithCSI()

isHostMonitoringWithCSI := dk.HostMonitoringMode() && dk.FeatureReadOnlyOneAgent()

return dk.CloudNativeFullstackMode() || isAppMonitoringWithCSI || isHostMonitoringWithCSI
func (dk *DynaKube) UseReadOnlyOneAgents() bool {
chrismuellner marked this conversation as resolved.
Show resolved Hide resolved
return dk.CloudNativeFullstackMode() || (dk.HostMonitoringMode() && dk.IsCSIAvailable())
}

func (dk *DynaKube) NeedAppInjection() bool {
Expand Down Expand Up @@ -171,7 +154,7 @@ func (dk *DynaKube) CodeModulesImage() string {
func (dk *DynaKube) CustomCodeModulesImage() string {
if dk.CloudNativeFullstackMode() {
return dk.Spec.OneAgent.CloudNativeFullStack.CodeModulesImage
} else if dk.ApplicationMonitoringMode() && dk.NeedsCSIDriver() {
} else if dk.ApplicationMonitoringMode() && dk.IsCSIAvailable() {
return dk.Spec.OneAgent.ApplicationMonitoring.CodeModulesImage
}

Expand Down
Loading
Loading