Skip to content

Commit

Permalink
move most common constants to v2alpha1 (#1560)
Browse files Browse the repository at this point in the history
  • Loading branch information
celenechang authored Dec 12, 2024
1 parent 5d3e3d1 commit 2fcfea2
Show file tree
Hide file tree
Showing 65 changed files with 705 additions and 708 deletions.
138 changes: 2 additions & 136 deletions api/datadoghq/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,146 +5,12 @@

package common

// TODO move most of these constants out of common

// This file tracks constants related to setting up the Datadog Agents
// This file tracks common constants used across API versions

// // Labels
const (
// AgentDeploymentNameLabelKey label key use to link a Resource to a DatadogAgent
AgentDeploymentNameLabelKey = "agent.datadoghq.com/name"
// AgentDeploymentComponentLabelKey label key use to know with component is it
AgentDeploymentComponentLabelKey = "agent.datadoghq.com/component"
// MD5AgentDeploymentProviderLabelKey label key is used to identify which provider is being used
MD5AgentDeploymentProviderLabelKey = "agent.datadoghq.com/provider"
// MD5AgentDeploymentAnnotationKey annotation key used on a Resource in order to identify which AgentDeployment have been used to generate it.
MD5AgentDeploymentAnnotationKey = "agent.datadoghq.com/agentspechash"
// MD5ChecksumAnnotationKey annotation key is used to identify customConfig configurations
MD5ChecksumAnnotationKey = "checksum/%s-custom-config"
)

// Annotations
const (
SystemProbeAppArmorAnnotationKey = "container.apparmor.security.beta.kubernetes.io/system-probe"
SystemProbeAppArmorAnnotationValue = "unconfined"

AgentAppArmorAnnotationKey = "container.apparmor.security.beta.kubernetes.io/agent"
AgentAppArmorAnnotationValue = "unconfined"
)

// Datadog volume names and mount paths
const (
ConfdVolumeName = "confd"
ConfdVolumePath = "/conf.d"
ConfigVolumeName = "config"
ConfigVolumePath = "/etc/datadog-agent"
ChecksdVolumeName = "checksd"
ChecksdVolumePath = "/checks.d"

HostRootVolumeName = "hostroot"
HostRootHostPath = "/"
HostRootMountPath = "/host/root"

GroupVolumeName = "group"
GroupHostPath = "/etc/group"
GroupMountPath = "/etc/group"

PasswdVolumeName = "passwd"
PasswdHostPath = "/etc/passwd"
PasswdMountPath = "/etc/passwd"

ProcdirVolumeName = "procdir"
ProcdirHostPath = "/proc"
ProcdirMountPath = "/host/proc"

CgroupsVolumeName = "cgroups"
CgroupsHostPath = "/sys/fs/cgroup"
CgroupsMountPath = "/host/sys/fs/cgroup"

SystemProbeOSReleaseDirVolumeName = "host-osrelease"
SystemProbeOSReleaseDirVolumePath = "/etc/os-release"
SystemProbeOSReleaseDirMountPath = "/host/etc/os-release"

SystemProbeSocketVolumeName = "sysprobe-socket-dir"
SystemProbeSocketVolumePath = "/var/run/sysprobe"

DebugfsVolumeName = "debugfs"
// same path on host and container
DebugfsPath = "/sys/kernel/debug"

ModulesVolumeName = "modules"
// same path on host and container
ModulesVolumePath = "/lib/modules"

SrcVolumeName = "src"
// same path on host and container
SrcVolumePath = "/usr/src"

AgentCustomConfigVolumePath = "/etc/datadog-agent/datadog.yaml"
SystemProbeConfigVolumePath = "/etc/datadog-agent/system-probe.yaml"
OtelCustomConfigVolumePath = "/etc/datadog-agent/otel-config.yaml"

LogDatadogVolumeName = "logdatadog"
LogDatadogVolumePath = "/var/log/datadog"
DefaultLogTempStoragePath = "/var/lib/datadog-agent/logs"
TmpVolumeName = "tmp"
TmpVolumePath = "/tmp"
CertificatesVolumeName = "certificates"
CertificatesVolumePath = "/etc/datadog-agent/certificates"
AuthVolumeName = "datadog-agent-auth"
AuthVolumePath = "/etc/datadog-agent/auth"
InstallInfoVolumeName = "installinfo"
InstallInfoVolumeSubPath = "install_info"
InstallInfoVolumePath = "/etc/datadog-agent/install_info"
InstallInfoVolumeReadOnly = true

DogstatsdHostPortName = "dogstatsdport"
DogstatsdHostPortHostPort = 8125
DogstatsdSocketVolumeName = "dsdsocket"
DogstatsdAPMSocketHostPath = "/var/run/datadog"
DogstatsdSocketLocalPath = "/var/run/datadog"
DogstatsdSocketName = "dsd.socket"

HostCriSocketPathPrefix = "/host"
CriSocketVolumeName = "runtimesocketdir"
RuntimeDirVolumePath = "/var/run"

KubeletAgentCAPath = "/var/run/host-kubelet-ca.crt"
KubeletCAVolumeName = "kubelet-ca"

APMSocketName = "apm.socket"

ExternalMetricsAPIServiceName = "v1beta1.external.metrics.k8s.io"

SeccompSecurityVolumeName = "datadog-agent-security"
SeccompSecurityVolumePath = "/etc/config"
SeccompRootVolumeName = "seccomp-root"
SeccompRootVolumePath = "/host/var/lib/kubelet/seccomp"
SeccompRootPath = "/var/lib/kubelet/seccomp"
SystemProbeSeccompKey = "system-probe-seccomp.json"
SystemProbeAgentSecurityConfigMapSuffixName = "system-probe-seccomp"
SystemProbeSeccompProfileName = "system-probe"

AppArmorAnnotationKey = "container.apparmor.security.beta.kubernetes.io"

AgentCustomConfigVolumeName = "custom-datadog-yaml"
ClusterAgentCustomConfigVolumeName = "custom-cluster-agent-yaml"

FIPSProxyCustomConfigVolumeName = "fips-proxy-cfg"
FIPSProxyCustomConfigFileName = "datadog-fips-proxy.cfg"
FIPSProxyCustomConfigMapName = "%s-fips-config"
FIPSProxyCustomConfigMountPath = "/etc/datadog-fips-proxy/datadog-fips-proxy.cfg"
)

const (
// FieldPathSpecNodeName used as FieldPath for selecting the NodeName
FieldPathSpecNodeName = "spec.nodeName"

// FieldPathStatusHostIP used as FieldPath to retrieve the host ip
FieldPathStatusHostIP = "status.hostIP"

// FieldPathStatusPodIP used as FieldPath to retrieve the pod ip
FieldPathStatusPodIP = "status.podIP"

// FieldPathMetaName used as FieldPath to retrieve the pod name
FieldPathMetaName = "metadata.name"
)
8 changes: 3 additions & 5 deletions api/datadoghq/v2alpha1/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package v2alpha1
import (
"fmt"

apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -124,7 +122,7 @@ func UpdateDeploymentStatus(dep *appsv1.Deployment, depStatus *DeploymentStatus,
return depStatus
}

if hash, ok := dep.Annotations[apicommon.MD5AgentDeploymentAnnotationKey]; ok {
if hash, ok := dep.Annotations[MD5AgentDeploymentAnnotationKey]; ok {
depStatus.CurrentHash = hash
}
if updateTime != nil {
Expand Down Expand Up @@ -186,7 +184,7 @@ func UpdateDaemonSetStatus(ds *appsv1.DaemonSet, dsStatus []*DaemonSetStatus, up
if updateTime != nil {
newStatus.LastUpdate = updateTime
}
if hash, ok := ds.Annotations[apicommon.MD5AgentDeploymentAnnotationKey]; ok {
if hash, ok := ds.Annotations[MD5AgentDeploymentAnnotationKey]; ok {
newStatus.CurrentHash = hash
}

Expand Down Expand Up @@ -236,7 +234,7 @@ func UpdateExtendedDaemonSetStatus(eds *edsdatadoghqv1alpha1.ExtendedDaemonSet,
if updateTime != nil {
newStatus.LastUpdate = updateTime
}
if hash, ok := eds.Annotations[apicommon.MD5AgentDeploymentAnnotationKey]; ok {
if hash, ok := eds.Annotations[MD5AgentDeploymentAnnotationKey]; ok {
newStatus.CurrentHash = hash
}

Expand Down
142 changes: 139 additions & 3 deletions api/datadoghq/v2alpha1/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package v2alpha1

// This file tracks constants closely related to the DatadogAgent CRD
// This file tracks constants related to the DatadogAgent CRD

const (

Expand Down Expand Up @@ -98,8 +98,6 @@ const (
DefaultAdmissionControllerTargetPort = 8000
// DefaultAdmissionControllerWebhookName default admission controller webhook name
DefaultAdmissionControllerWebhookName string = "datadog-webhook"
// DefaultDogstatsdOriginDetection default Origin Detection
// DefaultDogstatsdOriginDetection = "false" // CELENE NOT USED!
// DefaultDogstatsdPort default dogstatsd port
DefaultDogstatsdPort = 8125
// DefaultDogstatsdPortName default dogstatsd port name
Expand Down Expand Up @@ -133,3 +131,141 @@ const (
EndpointsChecksConfigProvider = "endpointschecks"
ClusterAndEndpointsConfigProviders = "clusterchecks endpointschecks"
)

// Labels
const (
// MD5AgentDeploymentProviderLabelKey label key is used to identify which provider is being used
MD5AgentDeploymentProviderLabelKey = "agent.datadoghq.com/provider"
// MD5AgentDeploymentAnnotationKey annotation key used on a Resource in order to identify which AgentDeployment have been used to generate it.
MD5AgentDeploymentAnnotationKey = "agent.datadoghq.com/agentspechash"
// MD5ChecksumAnnotationKey annotation key is used to identify customConfig configurations
MD5ChecksumAnnotationKey = "checksum/%s-custom-config"
)

// Annotations
const (
AppArmorAnnotationKey = "container.apparmor.security.beta.kubernetes.io"

SystemProbeAppArmorAnnotationKey = "container.apparmor.security.beta.kubernetes.io/system-probe"
SystemProbeAppArmorAnnotationValue = "unconfined"

AgentAppArmorAnnotationKey = "container.apparmor.security.beta.kubernetes.io/agent"
AgentAppArmorAnnotationValue = "unconfined"
)

// Volumes and paths
const (
ConfdVolumeName = "confd"
ConfdVolumePath = "/conf.d"
ConfigVolumeName = "config"
ConfigVolumePath = "/etc/datadog-agent"
ChecksdVolumeName = "checksd"
ChecksdVolumePath = "/checks.d"

HostRootVolumeName = "hostroot"
HostRootHostPath = "/"
HostRootMountPath = "/host/root"

GroupVolumeName = "group"
GroupHostPath = "/etc/group"
GroupMountPath = "/etc/group"

PasswdVolumeName = "passwd"
PasswdHostPath = "/etc/passwd"
PasswdMountPath = "/etc/passwd"

ProcdirVolumeName = "procdir"
ProcdirHostPath = "/proc"
ProcdirMountPath = "/host/proc"

CgroupsVolumeName = "cgroups"
CgroupsHostPath = "/sys/fs/cgroup"
CgroupsMountPath = "/host/sys/fs/cgroup"

SystemProbeOSReleaseDirVolumeName = "host-osrelease"
SystemProbeOSReleaseDirVolumePath = "/etc/os-release"
SystemProbeOSReleaseDirMountPath = "/host/etc/os-release"

SystemProbeSocketVolumeName = "sysprobe-socket-dir"
SystemProbeSocketVolumePath = "/var/run/sysprobe"

DebugfsVolumeName = "debugfs"
// same path on host and container
DebugfsPath = "/sys/kernel/debug"

ModulesVolumeName = "modules"
// same path on host and container
ModulesVolumePath = "/lib/modules"

SrcVolumeName = "src"
// same path on host and container
SrcVolumePath = "/usr/src"

AgentCustomConfigVolumePath = "/etc/datadog-agent/datadog.yaml"
SystemProbeConfigVolumePath = "/etc/datadog-agent/system-probe.yaml"
OtelCustomConfigVolumePath = "/etc/datadog-agent/otel-config.yaml"

LogDatadogVolumeName = "logdatadog"
LogDatadogVolumePath = "/var/log/datadog"
DefaultLogTempStoragePath = "/var/lib/datadog-agent/logs"
TmpVolumeName = "tmp"
TmpVolumePath = "/tmp"
CertificatesVolumeName = "certificates"
CertificatesVolumePath = "/etc/datadog-agent/certificates"
AuthVolumeName = "datadog-agent-auth"
AuthVolumePath = "/etc/datadog-agent/auth"
InstallInfoVolumeName = "installinfo"
InstallInfoVolumeSubPath = "install_info"
InstallInfoVolumePath = "/etc/datadog-agent/install_info"
InstallInfoVolumeReadOnly = true

DogstatsdHostPortName = "dogstatsdport"
DogstatsdHostPortHostPort = 8125
DogstatsdSocketVolumeName = "dsdsocket"
DogstatsdAPMSocketHostPath = "/var/run/datadog"
DogstatsdSocketLocalPath = "/var/run/datadog"
DogstatsdSocketName = "dsd.socket"

HostCriSocketPathPrefix = "/host"
CriSocketVolumeName = "runtimesocketdir"
RuntimeDirVolumePath = "/var/run"

KubeletAgentCAPath = "/var/run/host-kubelet-ca.crt"
KubeletCAVolumeName = "kubelet-ca"

APMSocketName = "apm.socket"

ExternalMetricsAPIServiceName = "v1beta1.external.metrics.k8s.io"

SeccompSecurityVolumeName = "datadog-agent-security"
SeccompSecurityVolumePath = "/etc/config"
SeccompRootVolumeName = "seccomp-root"
SeccompRootVolumePath = "/host/var/lib/kubelet/seccomp"
SeccompRootPath = "/var/lib/kubelet/seccomp"
SystemProbeSeccompKey = "system-probe-seccomp.json"
SystemProbeAgentSecurityConfigMapSuffixName = "system-probe-seccomp"
SystemProbeSeccompProfileName = "system-probe"

AgentCustomConfigVolumeName = "custom-datadog-yaml"
ClusterAgentCustomConfigVolumeName = "custom-cluster-agent-yaml"

FIPSProxyCustomConfigVolumeName = "fips-proxy-cfg"
FIPSProxyCustomConfigFileName = "datadog-fips-proxy.cfg"
FIPSProxyCustomConfigMapName = "%s-fips-config"
FIPSProxyCustomConfigMountPath = "/etc/datadog-fips-proxy/datadog-fips-proxy.cfg"
)

// Field paths
const (
// FieldPathSpecNodeName used as FieldPath for selecting the NodeName
FieldPathSpecNodeName = "spec.nodeName"

// FieldPathStatusHostIP used as FieldPath to retrieve the host ip
FieldPathStatusHostIP = "status.hostIP"

// FieldPathStatusPodIP used as FieldPath to retrieve the pod ip
FieldPathStatusPodIP = "status.podIP"

// FieldPathMetaName used as FieldPath to retrieve the pod name
FieldPathMetaName = "metadata.name"
)
7 changes: 3 additions & 4 deletions api/datadoghq/v2alpha1/datadogagent_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package v2alpha1

import (
apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common"
apiutils "github.com/DataDog/datadog-operator/api/utils"
"github.com/DataDog/datadog-operator/pkg/defaulting"
)
Expand Down Expand Up @@ -42,7 +41,7 @@ const (
defaultAPMHostPortEnabled bool = false
defaultAPMHostPort int32 = 8126
defaultAPMSocketEnabled bool = true
defaultAPMSocketHostPath string = apicommon.DogstatsdAPMSocketHostPath + "/" + apicommon.APMSocketName
defaultAPMSocketHostPath string = DogstatsdAPMSocketHostPath + "/" + APMSocketName
defaultAPMSingleStepInstrEnabled bool = false
defaultLanguageDetectionEnabled bool = true
defaultCSPMEnabled bool = false
Expand All @@ -61,7 +60,7 @@ const (
defaultDogstatsdOriginDetectionEnabled bool = false
defaultDogstatsdHostPortEnabled bool = false
defaultDogstatsdSocketEnabled bool = true
defaultDogstatsdHostSocketPath string = apicommon.DogstatsdAPMSocketHostPath + "/" + apicommon.DogstatsdSocketName
defaultDogstatsdHostSocketPath string = DogstatsdAPMSocketHostPath + "/" + DogstatsdSocketName

defaultOTLPGRPCEnabled bool = false
defaultOTLPGRPCHostPortEnabled bool = true
Expand Down Expand Up @@ -211,7 +210,7 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) {

apiutils.DefaultStringIfUnset(&ddaSpec.Features.LogCollection.ContainerSymlinksPath, defaultLogContainerSymlinksPath)

apiutils.DefaultStringIfUnset(&ddaSpec.Features.LogCollection.TempStoragePath, apicommon.DefaultLogTempStoragePath)
apiutils.DefaultStringIfUnset(&ddaSpec.Features.LogCollection.TempStoragePath, DefaultLogTempStoragePath)
}

// LiveContainerCollection Feature
Expand Down
3 changes: 1 addition & 2 deletions api/datadoghq/v2alpha1/datadogagent_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package v2alpha1
import (
"testing"

apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common"
apiutils "github.com/DataDog/datadog-operator/api/utils"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -652,7 +651,7 @@ func Test_defaultFeatures(t *testing.T) {
ContainerLogsPath: apiutils.NewStringPointer(defaultLogContainerLogsPath),
PodLogsPath: apiutils.NewStringPointer(defaultLogPodLogsPath),
ContainerSymlinksPath: apiutils.NewStringPointer(defaultLogContainerSymlinksPath),
TempStoragePath: apiutils.NewStringPointer(apicommon.DefaultLogTempStoragePath),
TempStoragePath: apiutils.NewStringPointer(DefaultLogTempStoragePath),
},
LiveProcessCollection: &LiveProcessCollectionFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultLiveProcessCollectionEnabled),
Expand Down
Loading

0 comments on commit 2fcfea2

Please sign in to comment.