Skip to content

Commit f36836a

Browse files
authored
[CONTP-1715] Align Operator to Helm csi daemonset and include csidrivers RBAC for DCA (#3093)
* Align with Helm Daemonset: volumes, deprecated registry, APM annotation * Add spec.apm.enabled field to condition the CSIDriver annotation and daemonset env var * Add list/watch/get for csidrivers to DCA clusterrole for admission controller
1 parent 08348c6 commit f36836a

15 files changed

Lines changed: 241 additions & 37 deletions

File tree

api/datadoghq/v1alpha1/datadogcsidriver_types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,24 @@ type DatadogCSIDriverSpec struct {
4040
// +optional
4141
DSDSocketPath *string `json:"dsdSocketPath,omitempty"`
4242

43+
// APM configures APM/Single Step Instrumentation support for the CSI driver.
44+
// +optional
45+
APM *DatadogCSIDriverAPMConfig `json:"apm,omitempty"`
46+
4347
// Override allows customization of the CSI driver DaemonSet pod template.
4448
// +optional
4549
Override *DatadogCSIDriverOverride `json:"override,omitempty"`
4650
}
4751

52+
// DatadogCSIDriverAPMConfig defines APM/Single Step Instrumentation settings for the CSI driver.
53+
// +k8s:openapi-gen=true
54+
type DatadogCSIDriverAPMConfig struct {
55+
// Enabled enables APM/Single Step Instrumentation support for the CSI driver.
56+
// Default: true
57+
// +optional
58+
Enabled *bool `json:"enabled,omitempty"`
59+
}
60+
4861
// DatadogCSIDriverOverride provides override capabilities for the CSI driver DaemonSet.
4962
// +k8s:openapi-gen=true
5063
type DatadogCSIDriverOverride struct {

api/datadoghq/v1alpha1/zz_generated.deepcopy.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/datadoghq/v1alpha1/zz_generated.openapi.go

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/v1/datadoghq.com_datadogcsidrivers.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ spec:
4848
spec:
4949
description: DatadogCSIDriverSpec defines the desired state of DatadogCSIDriver
5050
properties:
51+
apm:
52+
description: APM configures APM/Single Step Instrumentation support for the CSI driver.
53+
properties:
54+
enabled:
55+
description: |-
56+
Enabled enables APM/Single Step Instrumentation support for the CSI driver.
57+
Default: true
58+
type: boolean
59+
type: object
5160
apmSocketPath:
5261
description: |-
5362
APMSocketPath is the host path to the APM socket.

config/crd/bases/v1/datadoghq.com_datadogcsidrivers_v1alpha1.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717
"additionalProperties": false,
1818
"description": "DatadogCSIDriverSpec defines the desired state of DatadogCSIDriver",
1919
"properties": {
20+
"apm": {
21+
"additionalProperties": false,
22+
"description": "APM configures APM/Single Step Instrumentation support for the CSI driver.",
23+
"properties": {
24+
"enabled": {
25+
"description": "Enabled enables APM/Single Step Instrumentation support for the CSI driver.\nDefault: true",
26+
"type": "boolean"
27+
}
28+
},
29+
"type": "object"
30+
},
2031
"apmSocketPath": {
2132
"description": "APMSocketPath is the host path to the APM socket.\nDefault: /var/run/datadog/apm.socket",
2233
"type": "string"

internal/controller/datadogagent/feature/admissioncontroller/const.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const (
99
admissionControllerPortName = "admissioncontrollerport"
1010
admissionControllerSocketCommunicationMode = "socket"
1111
admissionControllerHostipCommunicationMode = "hostip"
12+
admissionControllerCSICommunicationMode = "csi"
13+
datadogCSIDriverName = "k8s.csi.datadoghq.com"
1214

1315
// DefaultAdmissionControllerServicePort default admission controller service port
1416
defaultAdmissionControllerServicePort = 443

internal/controller/datadogagent/feature/admissioncontroller/feature_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ import (
1414
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature"
1515
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake"
1616
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test"
17+
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/store"
1718
"github.com/DataDog/datadog-operator/pkg/images"
19+
"github.com/DataDog/datadog-operator/pkg/kubernetes"
20+
"github.com/DataDog/datadog-operator/pkg/kubernetes/rbac"
1821
"github.com/DataDog/datadog-operator/pkg/testutils"
1922

2023
"github.com/google/go-cmp/cmp"
2124
"github.com/stretchr/testify/assert"
2225
corev1 "k8s.io/api/core/v1"
26+
rbacv1 "k8s.io/api/rbac/v1"
2327
"k8s.io/utils/ptr"
2428
)
2529

@@ -40,6 +44,7 @@ func Test_admissionControllerFeature_Configure(t *testing.T) {
4044
WantConfigure: true,
4145
ClusterAgent: test.NewDefaultComponentTest().WithWantFunc(
4246
admissionControllerWantFunc(false, false, "", "", false)),
47+
WantDependenciesFunc: assertCSIDriverRBAC,
4348
},
4449
{
4550
Name: "Admission Controller enabled with validation and mutation enabled",
@@ -246,6 +251,31 @@ func Test_admissionControllerFeature_Configure(t *testing.T) {
246251
tests.Run(t, buildAdmissionControllerFeature)
247252
}
248253

254+
func assertCSIDriverRBAC(t testing.TB, sc store.StoreClient) {
255+
crObj, found := sc.Get(kubernetes.ClusterRolesKind, "", "-cluster-agent")
256+
assert.True(t, found, "Cluster Agent ClusterRole should be created")
257+
258+
cr, ok := crObj.(*rbacv1.ClusterRole)
259+
assert.True(t, ok, "Cluster Agent ClusterRole should have the expected type")
260+
261+
assert.Contains(t, cr.Rules, rbacv1.PolicyRule{
262+
APIGroups: []string{rbac.StorageAPIGroup},
263+
Resources: []string{rbac.CSIDriversResource},
264+
Verbs: []string{
265+
rbac.ListVerb,
266+
rbac.WatchVerb,
267+
},
268+
})
269+
assert.Contains(t, cr.Rules, rbacv1.PolicyRule{
270+
APIGroups: []string{rbac.StorageAPIGroup},
271+
Resources: []string{rbac.CSIDriversResource},
272+
ResourceNames: []string{datadogCSIDriverName},
273+
Verbs: []string{
274+
rbac.GetVerb,
275+
},
276+
})
277+
}
278+
249279
func testDCAResources(acm string, registry string, cwsInstrumentationEnabled bool) *test.ComponentTest {
250280
return test.NewDefaultComponentTest().WithWantFunc(
251281
func(t testing.TB, mgrInterface feature.PodTemplateManagers) {

internal/controller/datadogagent/feature/admissioncontroller/rbac.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ func (f *admissionControllerFeature) getRBACClusterPolicyRules() []rbacv1.Policy
8181
rbac.GetVerb,
8282
},
8383
},
84+
// CSIDrivers
85+
{
86+
APIGroups: []string{rbac.StorageAPIGroup},
87+
Resources: []string{rbac.CSIDriversResource},
88+
Verbs: []string{
89+
rbac.ListVerb,
90+
rbac.WatchVerb,
91+
},
92+
},
93+
{
94+
APIGroups: []string{rbac.StorageAPIGroup},
95+
Resources: []string{rbac.CSIDriversResource},
96+
ResourceNames: []string{datadogCSIDriverName},
97+
Verbs: []string{
98+
rbac.GetVerb,
99+
},
100+
},
84101
}
85102

86103
if f.cwsInstrumentationEnabled && f.cwsInstrumentationMode == "remote_copy" {

internal/controller/datadogagent_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ type DatadogAgentReconciler struct {
8181
// +kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=get;create
8282
// +kubebuilder:rbac:groups=batch,resources=cronjobs,verbs=get
8383
// +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get
84+
// +kubebuilder:rbac:groups=storage.k8s.io,resources=csidrivers,verbs=list;watch
85+
// +kubebuilder:rbac:groups=storage.k8s.io,resources=csidrivers,resourceNames=k8s.csi.datadoghq.com,verbs=get
8486

8587
// Configure External Metrics server
8688
// +kubebuilder:rbac:groups=apiregistration.k8s.io,resources=apiservices,verbs=*

internal/controller/datadogcsidriver/const.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const (
1414
defaultCSIDriverImageName = "csi-driver"
1515
// defaultRegistrarImageName is the default CSI node driver registrar image name
1616
defaultRegistrarImageName = "csi-node-driver-registrar"
17+
// defaultRegistrarImageRegistry is the default CSI node driver registrar image registry
18+
defaultRegistrarImageRegistry = "k8s.gcr.io/sig-storage"
1719
// defaultAPMSocketPath is the default host path to the APM socket
1820
defaultAPMSocketPath = "/var/run/datadog/apm.socket"
1921
// defaultDSDSocketPath is the default host path to the DogStatsD socket
@@ -34,10 +36,10 @@ const (
3436
registrationDirPath = "/var/lib/kubelet/plugins_registry"
3537
registrarMountPath = "/registration"
3638

37-
// Host path templates (used with fmt.Sprintf and the CSI driver name)
38-
kubeletPluginsDirFmt = "/var/lib/kubelet/plugins/%s"
39-
kubeletStorageDirFmt = "/var/lib/kubelet/plugins/%s/storage"
40-
csiSocketPathFmt = "/var/lib/kubelet/plugins/%s/csi.sock"
39+
// Host paths
40+
kubeletPluginsDir = "/var/lib/kubelet/plugins/datadog.csi/driver"
41+
kubeletStorageDir = "/var/lib/kubelet/plugins/datadog.csi/storage"
42+
csiSocketPath = "/var/lib/kubelet/plugins/datadog.csi/driver/csi.sock"
4143

4244
// CSI socket path inside the container
4345
csiSocketAddress = "/csi/csi.sock"
@@ -54,6 +56,9 @@ const (
5456
appLabelKey = "app"
5557
admissionControllerEnabledLabel = "admission.datadoghq.com/enabled"
5658

59+
// CSIDriver annotations
60+
apmEnabledAnnotationKey = "csi.datadoghq.com/apm-enabled"
61+
5762
// finalizerName is the finalizer for CSIDriver object cleanup
5863
finalizerName = "finalizer.datadoghq.com/csi-driver"
5964
)

0 commit comments

Comments
 (0)