-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Kubernetes API monitoring config for extensions (#4334)
- Loading branch information
1 parent
60b7a5c
commit 111fac0
Showing
4 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package validation | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta3/dynakube" | ||
) | ||
|
||
const ( | ||
errorExtensionsWithoutK8SMonitoring = "The Dynakube's specification enables extensions without an ActiveGate which has Kubernetes monitoring enabled. This is not feasible, as the cluster will not be visible in Dynatrace without the Kubernetes monitoring feature." | ||
) | ||
|
||
func extensionsWithoutK8SMonitoring(ctx context.Context, dv *Validator, dk *dynakube.DynaKube) string { | ||
if dk.IsExtensionsEnabled() && (!dk.ActiveGate().IsKubernetesMonitoringEnabled() || !dk.FeatureAutomaticKubernetesApiMonitoring()) { | ||
return errorExtensionsWithoutK8SMonitoring | ||
} | ||
|
||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package validation | ||
|
||
import ( | ||
"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" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
const testDynakubeName = "dynakube" | ||
|
||
func TestExtensionsWithoutK8SMonitoring(t *testing.T) { | ||
t.Run("no error if extensions are enabled with activegate with k8s-monitoring", func(t *testing.T) { | ||
dk := createStandaloneExtensionsDynakube(testDynakubeName, testApiUrl) | ||
dk.Spec.ActiveGate = activegate.Spec{ | ||
Capabilities: []activegate.CapabilityDisplayName{ | ||
activegate.KubeMonCapability.DisplayName, | ||
}, | ||
} | ||
assertAllowed(t, dk) | ||
}) | ||
t.Run("error if extensions are enabled without activegate with k8s-monitoring", func(t *testing.T) { | ||
assertDenied(t, | ||
[]string{errorExtensionsWithoutK8SMonitoring}, | ||
createStandaloneExtensionsDynakube(testDynakubeName, testApiUrl)) | ||
}) | ||
t.Run("error if extensions are enabled with activegate with k8s-monitoring but automatic Kuberenetes API monitoring is disabled", func(t *testing.T) { | ||
dk := createStandaloneExtensionsDynakube(testDynakubeName, testApiUrl) | ||
dk.ObjectMeta.Annotations = map[string]string{ | ||
dynakube.AnnotationFeatureAutomaticK8sApiMonitoring: "false", | ||
} | ||
dk.Spec.ActiveGate = activegate.Spec{ | ||
Capabilities: []activegate.CapabilityDisplayName{ | ||
activegate.KubeMonCapability.DisplayName, | ||
}, | ||
} | ||
assertDenied(t, []string{errorExtensionsWithoutK8SMonitoring}, dk) | ||
}) | ||
t.Run("error if extensions are enabled but automatic Kuberenetes API monitoring is disabled and without activgate k8s-monitoring", func(t *testing.T) { | ||
dk := createStandaloneExtensionsDynakube(testDynakubeName, testApiUrl) | ||
dk.ObjectMeta.Annotations = map[string]string{ | ||
dynakube.AnnotationFeatureAutomaticK8sApiMonitoring: "false", | ||
} | ||
assertDenied(t, []string{errorExtensionsWithoutK8SMonitoring}, dk) | ||
}) | ||
} | ||
|
||
func createStandaloneExtensionsDynakube(name, apiUrl string) *dynakube.DynaKube { | ||
dk := &dynakube.DynaKube{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
Namespace: testNamespace, | ||
}, | ||
Spec: dynakube.DynaKubeSpec{ | ||
APIURL: apiUrl, | ||
Extensions: &dynakube.ExtensionsSpec{}, | ||
Templates: dynakube.TemplatesSpec{ | ||
ExtensionExecutionController: dynakube.ExtensionExecutionControllerSpec{ | ||
ImageRef: image.Ref{ | ||
Repository: "repo/image", | ||
Tag: "version", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
return dk | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters