Skip to content

Commit

Permalink
Use pod name as cluster check runner ID (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-mez committed Jun 24, 2021
1 parent 022a88e commit 0a9f32b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
1 change: 1 addition & 0 deletions api/v1alpha1/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const (
DDKubeStateMetricsCoreConfigMap = "DD_KUBE_STATE_METRICS_CORE_CONFIGMAP_NAME"
DDClcRunnerEnabled = "DD_CLC_RUNNER_ENABLED"
DDClcRunnerHost = "DD_CLC_RUNNER_HOST"
DDClcRunnerID = "DD_CLC_RUNNER_ID"
DDExtraConfigProviders = "DD_EXTRA_CONFIG_PROVIDERS"
DDExtraListeners = "DD_EXTRA_LISTENERS"
DDHostname = "DD_HOSTNAME"
Expand Down
24 changes: 18 additions & 6 deletions controllers/datadogagent/clusterchecksrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,14 @@ func getEnvVarsForClusterChecksRunner(dda *datadoghqv1alpha1.DatadogAgent) []cor
},
},
},
{
Name: datadoghqv1alpha1.DDClcRunnerID,
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: FieldPathMetaName,
},
},
},
}

if spec.ClusterName != "" {
Expand Down Expand Up @@ -491,22 +499,26 @@ func getClusterChecksRunnerCustomConfigConfigMapName(dda *datadoghqv1alpha1.Data
}

// getPodAffinity returns the pod anti affinity of the cluster check runner pods
// the default anti affinity ensures we don't schedule multiple cluster check runners on the same node
// the default anti affinity prefers scheduling the runners on different nodes if possible
// for better checks stability in case of node failure.
func getPodAffinity(affinity *corev1.Affinity) *corev1.Affinity {
if affinity != nil {
return affinity
}

return &corev1.Affinity{
PodAntiAffinity: &corev1.PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
datadoghqv1alpha1.AgentDeploymentComponentLabelKey: datadoghqv1alpha1.DefaultClusterChecksRunnerResourceSuffix,
Weight: 50,
PodAffinityTerm: corev1.PodAffinityTerm{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
datadoghqv1alpha1.AgentDeploymentComponentLabelKey: datadoghqv1alpha1.DefaultClusterChecksRunnerResourceSuffix,
},
},
TopologyKey: "kubernetes.io/hostname",
},
TopologyKey: "kubernetes.io/hostname",
},
},
},
Expand Down
21 changes: 16 additions & 5 deletions controllers/datadogagent/clusterchecksrunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ func clusterChecksRunnerDefaultEnvVars() []corev1.EnvVar {
},
},
},
{
Name: "DD_CLC_RUNNER_ID",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.name",
},
},
},
}
}

Expand Down Expand Up @@ -380,14 +388,17 @@ func Test_getPodAffinity(t *testing.T) {
affinity: nil,
want: &corev1.Affinity{
PodAntiAffinity: &corev1.PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"agent.datadoghq.com/component": "cluster-checks-runner",
Weight: 50,
PodAffinityTerm: corev1.PodAffinityTerm{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"agent.datadoghq.com/component": "cluster-checks-runner",
},
},
TopologyKey: "kubernetes.io/hostname",
},
TopologyKey: "kubernetes.io/hostname",
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions controllers/datadogagent/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const (
// FieldPathStatusPodIP used as FieldPath to retrieve the pod ip
FieldPathStatusPodIP = "status.podIP"

// FieldPathMetaName used as FieldPath to retrieve the pod name
FieldPathMetaName = "metadata.name"

// kind names definition
extendedDaemonSetKind = "ExtendedDaemonSet"
daemonSetKind = "DaemonSet"
Expand Down

0 comments on commit 0a9f32b

Please sign in to comment.