Skip to content

Commit

Permalink
Fix CLC config (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-mez committed Apr 6, 2020
1 parent e84c57a commit d5889a1
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 67 deletions.
8 changes: 5 additions & 3 deletions deploy/crds/datadoghq.com_datadogagents_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3171,9 +3171,11 @@ spec:
config:
description: Cluster Agent configuration
properties:
clusterChecksRunnerEnabled:
description: 'Enable the Cluster Checks Runner feature on both
the cluster-agents and the daemonset ref: https://docs.datadoghq.com/agent/autodiscovery/ClusterChecksRunner/
clusterChecksEnabled:
description: 'Enable the Cluster Checks and Endpoint Checks
feature on both the cluster-agents and the daemonset ref:
https://docs.datadoghq.com/agent/cluster_agent/clusterchecks/
https://docs.datadoghq.com/agent/cluster_agent/endpointschecks/
Autodiscovery via Kube Service annotations is automatically
enabled'
type: boolean
Expand Down
18 changes: 11 additions & 7 deletions pkg/apis/datadoghq/v1alpha1/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const (
DDMetricsProviderEnabled = "DD_EXTERNAL_METRICS_PROVIDER_ENABLED"
DDMetricsProviderPort = "DD_EXTERNAL_METRICS_PROVIDER_PORT"
DDAppKey = "DD_APP_KEY"
DDClusterChecksRunnerEnabled = "DD_CLUSTER_CHECKS_ENABLED"
DDClusterChecksEnabled = "DD_CLUSTER_CHECKS_ENABLED"
DDClcRunnerEnabled = "DD_CLC_RUNNER_ENABLED"
DDClcRunnerHost = "DD_CLC_RUNNER_HOST"
DDExtraConfigProviders = "DD_EXTRA_CONFIG_PROVIDERS"
Expand Down Expand Up @@ -125,17 +125,21 @@ const (
DefaultSeccompProfileName = "localhost/system-probe"
SysteProbeAppArmorAnnotationKey = "container.apparmor.security.beta.kubernetes.io/system-probe"
SysteProbeSeccompAnnotationKey = "container.seccomp.security.alpha.kubernetes.io/system-probe"

// Extra config provider names

KubeServicesConfigProvider = "kube_services"
KubeEndpointsConfigProvider = "kube_endpoints"
ClusterChecksConfigProvider = "clusterchecks"
EndpointsChecksConfigProvider = "endpointschecks"
KubeServicesConfigProvider = "kube_services"
KubeEndpointsConfigProvider = "kube_endpoints"
KubeServicesAndEndpointsConfigProviders = "kube_services kube_endpoints"
ClusterChecksConfigProvider = "clusterchecks"
EndpointsChecksConfigProvider = "endpointschecks"
ClusterAndEndpointsConfigPoviders = "clusterchecks endpointschecks"

// Extra listeners

KubeServicesListener = "kube_services"
KubeEndpointsListener = "kube_endpoints"
KubeServicesListener = "kube_services"
KubeEndpointsListener = "kube_endpoints"
KubeServicesAndEndpointsListeners = "kube_services kube_endpoints"

// Liveness probe default config

Expand Down
12 changes: 4 additions & 8 deletions pkg/apis/datadoghq/v1alpha1/datadogagent_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
defaultProcessEnabled bool = false
defaultMetricsProviderEnabled bool = false
defaultMetricsProviderPort int32 = 443
defaultClusterChecksRunnerEnabled bool = false
defaultClusterChecksEnabled bool = false
defaultClusterAgentReplicas int32 = 1
defaultAgentCanaryReplicas int32 = 1
defaultClusterChecksRunnerReplicas int32 = 2
Expand Down Expand Up @@ -106,10 +106,6 @@ func IsDefaultedDatadogAgent(ad *DatadogAgent) bool {
if ad.Spec.ClusterAgent.Replicas == nil {
return false
}

if BoolValue(ad.Spec.ClusterAgent.Config.ClusterChecksRunnerEnabled) && ad.Spec.ClusterChecksRunner == nil {
return false
}
}

if ad.Spec.ClusterChecksRunner != nil {
Expand Down Expand Up @@ -348,7 +344,7 @@ func DefaultDatadogAgent(ad *DatadogAgent) *DatadogAgent {

if defaultedAD.Spec.ClusterAgent != nil {
defaultedAD.Spec.ClusterAgent = DefaultDatadogAgentSpecClusterAgent(defaultedAD.Spec.ClusterAgent)
if BoolValue(defaultedAD.Spec.ClusterAgent.Config.ClusterChecksRunnerEnabled) && ad.Spec.ClusterChecksRunner == nil {
if BoolValue(defaultedAD.Spec.ClusterAgent.Config.ClusterChecksEnabled) && ad.Spec.ClusterChecksRunner == nil {
defaultedAD.Spec.ClusterChecksRunner = &DatadogAgentSpecClusterChecksRunnerSpec{}
}
}
Expand Down Expand Up @@ -621,8 +617,8 @@ func DefaultDatadogAgentSpecClusterAgentConfig(config *ClusterAgentConfig) *Clus
config.MetricsProviderPort = NewInt32Pointer(defaultMetricsProviderPort)
}

if config.ClusterChecksRunnerEnabled == nil {
config.ClusterChecksRunnerEnabled = NewBoolPointer(defaultClusterChecksRunnerEnabled)
if config.ClusterChecksEnabled == nil {
config.ClusterChecksEnabled = NewBoolPointer(defaultClusterChecksEnabled)
}

return config
Expand Down
8 changes: 5 additions & 3 deletions pkg/apis/datadoghq/v1alpha1/datadogagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,12 @@ type ClusterAgentConfig struct {
// +optional
MetricsProviderPort *int32 `json:"metricsProviderPort,omitempty"`

// Enable the Cluster Checks Runner feature on both the cluster-agents and the daemonset
// ref: https://docs.datadoghq.com/agent/autodiscovery/ClusterChecksRunner/
// Enable the Cluster Checks and Endpoint Checks feature on both the cluster-agents and the daemonset
// ref:
// https://docs.datadoghq.com/agent/cluster_agent/clusterchecks/
// https://docs.datadoghq.com/agent/cluster_agent/endpointschecks/
// Autodiscovery via Kube Service annotations is automatically enabled
ClusterChecksRunnerEnabled *bool `json:"clusterChecksRunnerEnabled,omitempty"`
ClusterChecksEnabled *bool `json:"clusterChecksEnabled,omitempty"`

// Set logging verbosity, valid log levels are:
// trace, debug, info, warn, error, critical, and off
Expand Down
7 changes: 4 additions & 3 deletions pkg/apis/datadoghq/v1alpha1/test/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type NewDatadogAgentOptions struct {
ClusterAgentEnabled bool
MetricsServerEnabled bool
MetricsServerPort int32
ClusterChecksRunnerEnabled bool
ClusterChecksEnabled bool
NodeAgentConfig *datadoghqv1alpha1.NodeAgentConfig
APMEnabled bool
ProcessEnabled bool
Expand All @@ -52,6 +52,7 @@ type NewDatadogAgentOptions struct {
CustomConfig string
AgentDaemonsetName string
ClusterAgentDeploymentName string
ClusterChecksRunnerEnabled bool
ClusterChecksRunnerVolumes []corev1.Volume
ClusterChecksRunnerVolumeMounts []corev1.VolumeMount
ClusterChecksRunnerEnvVars []corev1.EnvVar
Expand Down Expand Up @@ -128,8 +129,8 @@ func NewDefaultedDatadogAgent(ns, name string, options *NewDatadogAgentOptions)
ad.Spec.ClusterAgent.Config.MetricsProviderPort = datadoghqv1alpha1.NewInt32Pointer(options.MetricsServerPort)
}
}
if options.ClusterChecksRunnerEnabled {
ad.Spec.ClusterAgent.Config.ClusterChecksRunnerEnabled = datadoghqv1alpha1.NewBoolPointer(true)
if options.ClusterChecksEnabled {
ad.Spec.ClusterAgent.Config.ClusterChecksEnabled = datadoghqv1alpha1.NewBoolPointer(true)
}

if len(options.ClusterAgentVolumes) != 0 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/datadoghq/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/apis/datadoghq/v1alpha1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

135 changes: 127 additions & 8 deletions pkg/controller/datadogagent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ func defaultEnvVars() []corev1.EnvVar {
Name: "DD_API_KEY",
Value: "",
},
{
Name: "DD_CRI_SOCKET_PATH",
Value: "/host/var/run/docker.sock",
},
{
Name: "DOCKER_HOST",
Value: "unix:///host/var/run/docker.sock",
},
{
Name: "DD_CLUSTER_AGENT_ENABLED",
Value: "true",
Expand All @@ -222,14 +230,6 @@ func defaultEnvVars() []corev1.EnvVar {
Name: "DD_CLUSTER_AGENT_AUTH_TOKEN",
ValueFrom: authTokenValue(),
},
{
Name: "DD_CRI_SOCKET_PATH",
Value: "/host/var/run/docker.sock",
},
{
Name: "DOCKER_HOST",
Value: "unix:///host/var/run/docker.sock",
},
}
}

Expand Down Expand Up @@ -920,6 +920,125 @@ func Test_newExtendedDaemonSetFromInstance_LogsEnabled(t *testing.T) {
test.Run(t)
}

func Test_newExtendedDaemonSetFromInstance_clusterChecksConfig(t *testing.T) {
clusterChecksPodSpec := defaultPodSpec()
clusterChecksPodSpec.Containers[0].Env = addEnvVar(clusterChecksPodSpec.Containers[0].Env, "DD_EXTRA_CONFIG_PROVIDERS", "clusterchecks endpointschecks")
clusterChecksPodSpec.InitContainers[1].Env = addEnvVar(clusterChecksPodSpec.InitContainers[1].Env, "DD_EXTRA_CONFIG_PROVIDERS", "clusterchecks endpointschecks")

dda := test.NewDefaultedDatadogAgent("bar", "foo", &test.NewDatadogAgentOptions{
UseEDS: true,
ClusterAgentEnabled: true,
ClusterChecksEnabled: true,
})

dda.Spec.ClusterChecksRunner = nil

ddaHash, _ := comparison.GenerateMD5ForSpec(dda.Spec)

test := extendedDaemonSetFromInstanceTest{
name: "with cluster checks / clc runners",
agentdeployment: dda,
wantErr: false,
want: &edsdatadoghqv1alpha1.ExtendedDaemonSet{
ObjectMeta: metav1.ObjectMeta{
Namespace: "bar",
Name: "foo",
Labels: map[string]string{
"agent.datadoghq.com/name": "foo",
"agent.datadoghq.com/component": "agent",
"app.kubernetes.io/instance": "agent",
"app.kubernetes.io/managed-by": "datadog-operator",
"app.kubernetes.io/name": "datadog-agent-deployment",
"app.kubernetes.io/part-of": "foo",
"app.kubernetes.io/version": "",
},
Annotations: map[string]string{"agent.datadoghq.com/agentspechash": ddaHash},
},
Spec: edsdatadoghqv1alpha1.ExtendedDaemonSetSpec{
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "foo",
Namespace: "bar",
Labels: map[string]string{
"agent.datadoghq.com/name": "foo",
"agent.datadoghq.com/component": "agent",
"app.kubernetes.io/instance": "agent",
"app.kubernetes.io/managed-by": "datadog-operator",
"app.kubernetes.io/name": "datadog-agent-deployment",
"app.kubernetes.io/part-of": "foo",
"app.kubernetes.io/version": "",
},
Annotations: make(map[string]string),
},
Spec: clusterChecksPodSpec,
},
Strategy: getDefaultEDSStrategy(),
},
},
}

test.Run(t)
}

func Test_newExtendedDaemonSetFromInstance_endpointsChecksConfig(t *testing.T) {
endpointChecksChecksPodSpec := defaultPodSpec()
endpointChecksChecksPodSpec.Containers[0].Env = addEnvVar(endpointChecksChecksPodSpec.Containers[0].Env, "DD_EXTRA_CONFIG_PROVIDERS", "endpointschecks")
endpointChecksChecksPodSpec.InitContainers[1].Env = addEnvVar(endpointChecksChecksPodSpec.InitContainers[1].Env, "DD_EXTRA_CONFIG_PROVIDERS", "endpointschecks")

dda := test.NewDefaultedDatadogAgent("bar", "foo", &test.NewDatadogAgentOptions{
UseEDS: true,
ClusterAgentEnabled: true,
ClusterChecksEnabled: true,
ClusterChecksRunnerEnabled: true,
})

ddaHash, _ := comparison.GenerateMD5ForSpec(dda.Spec)

test := extendedDaemonSetFromInstanceTest{
name: "with cluster checks / with clc runners",
agentdeployment: dda,
wantErr: false,
want: &edsdatadoghqv1alpha1.ExtendedDaemonSet{
ObjectMeta: metav1.ObjectMeta{
Namespace: "bar",
Name: "foo",
Labels: map[string]string{
"agent.datadoghq.com/name": "foo",
"agent.datadoghq.com/component": "agent",
"app.kubernetes.io/instance": "agent",
"app.kubernetes.io/managed-by": "datadog-operator",
"app.kubernetes.io/name": "datadog-agent-deployment",
"app.kubernetes.io/part-of": "foo",
"app.kubernetes.io/version": "",
},
Annotations: map[string]string{"agent.datadoghq.com/agentspechash": ddaHash},
},
Spec: edsdatadoghqv1alpha1.ExtendedDaemonSetSpec{
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "foo",
Namespace: "bar",
Labels: map[string]string{
"agent.datadoghq.com/name": "foo",
"agent.datadoghq.com/component": "agent",
"app.kubernetes.io/instance": "agent",
"app.kubernetes.io/managed-by": "datadog-operator",
"app.kubernetes.io/name": "datadog-agent-deployment",
"app.kubernetes.io/part-of": "foo",
"app.kubernetes.io/version": "",
},
Annotations: make(map[string]string),
},
Spec: endpointChecksChecksPodSpec,
},
Strategy: getDefaultEDSStrategy(),
},
},
}

test.Run(t)
}

func getDefaultEDSStrategy() edsdatadoghqv1alpha1.ExtendedDaemonSetSpecStrategy {
var defaultMaxParallelPodCreation int32 = 250
return edsdatadoghqv1alpha1.ExtendedDaemonSetSpecStrategy{
Expand Down
13 changes: 6 additions & 7 deletions pkg/controller/datadogagent/clusteragent.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"context"
"fmt"
"strconv"
"strings"
"time"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -424,8 +423,8 @@ func getEnvVarsForClusterAgent(dda *datadoghqv1alpha1.DatadogAgent) []corev1.Env
Value: *spec.Agent.Config.DDUrl,
},
{
Name: datadoghqv1alpha1.DDClusterChecksRunnerEnabled,
Value: strconv.FormatBool(*spec.ClusterAgent.Config.ClusterChecksRunnerEnabled),
Name: datadoghqv1alpha1.DDClusterChecksEnabled,
Value: strconv.FormatBool(*spec.ClusterAgent.Config.ClusterChecksEnabled),
},
{
Name: datadoghqv1alpha1.DDClusterAgentKubeServiceName,
Expand Down Expand Up @@ -484,16 +483,16 @@ func getEnvVarsForClusterAgent(dda *datadoghqv1alpha1.DatadogAgent) []corev1.Env
}
}

// Cluster Checks Runner config
if *spec.ClusterAgent.Config.ClusterChecksRunnerEnabled {
// Cluster Checks config
if *spec.ClusterAgent.Config.ClusterChecksEnabled {
envVars = append(envVars, []corev1.EnvVar{
{
Name: datadoghqv1alpha1.DDExtraConfigProviders,
Value: datadoghqv1alpha1.KubeServicesConfigProvider,
Value: datadoghqv1alpha1.KubeServicesAndEndpointsConfigProviders,
},
{
Name: datadoghqv1alpha1.DDExtraListeners,
Value: strings.Join([]string{datadoghqv1alpha1.KubeServicesListener, datadoghqv1alpha1.KubeEndpointsListener}, " "),
Value: datadoghqv1alpha1.KubeServicesAndEndpointsListeners,
},
}...)
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/controller/datadogagent/clusterchecksrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (r *ReconcileDatadogAgent) reconcileClusterChecksRunner(logger logr.Logger,
}

func needClusterChecksRunner(dda *datadoghqv1alpha1.DatadogAgent) bool {
if dda.Spec.ClusterAgent != nil && datadoghqv1alpha1.BoolValue(dda.Spec.ClusterAgent.Config.ClusterChecksRunnerEnabled) {
if dda.Spec.ClusterAgent != nil && dda.Spec.ClusterChecksRunner != nil && datadoghqv1alpha1.BoolValue(dda.Spec.ClusterAgent.Config.ClusterChecksEnabled) {
return true
}

Expand Down Expand Up @@ -306,8 +306,12 @@ func getEnvVarsForClusterChecksRunner(dda *datadoghqv1alpha1.DatadogAgent) []cor
Value: *spec.Agent.Config.DDUrl,
},
{
Name: datadoghqv1alpha1.DDClusterChecksRunnerEnabled,
Value: strconv.FormatBool(*spec.ClusterAgent.Config.ClusterChecksRunnerEnabled),
Name: datadoghqv1alpha1.DDClusterChecksEnabled,
Value: "true",
},
{
Name: datadoghqv1alpha1.DDClusterAgentEnabled,
Value: "true",
},
{
Name: datadoghqv1alpha1.DDClusterAgentKubeServiceName,
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/datadogagent/clusterchecksrunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func clusterChecksRunnerDefaultEnvVars() []corev1.EnvVar {
Name: "DD_CLUSTER_CHECKS_ENABLED",
Value: "true",
},
{
Name: "DD_CLUSTER_AGENT_ENABLED",
Value: "true",
},
{
Name: "DD_CLUSTER_AGENT_KUBERNETES_SERVICE_NAME",
Value: fmt.Sprintf("%s-%s", testDadName, datadoghqv1alpha1.DefaultClusterAgentResourceSuffix),
Expand Down

0 comments on commit d5889a1

Please sign in to comment.