Skip to content

Commit d9d250c

Browse files
authored
Merge pull request #513 from Rakshith-R/sms-tls-key-trigger
controller: replace SMS CR check with tls-key volume presence trigger
2 parents 49d330b + 30573ee commit d9d250c

16 files changed

Lines changed: 38 additions & 550 deletions

File tree

cmd/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import (
4242
csiv1 "github.com/ceph/ceph-csi-operator/api/v1"
4343
"github.com/ceph/ceph-csi-operator/internal/controller"
4444
"github.com/ceph/ceph-csi-operator/internal/utils"
45-
sm "github.com/kubernetes-csi/external-snapshot-metadata/client/apis/snapshotmetadataservice/v1beta1"
4645
//+kubebuilder:scaffold:imports
4746
)
4847

@@ -55,7 +54,6 @@ func init() {
5554
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
5655

5756
utilruntime.Must(csiv1.AddToScheme(scheme))
58-
utilruntime.Must(sm.AddToScheme(scheme))
5957
//+kubebuilder:scaffold:scheme
6058
}
6159

config/rbac/role.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ rules:
3030
- patch
3131
- update
3232
- watch
33-
- apiGroups:
34-
- cbt.storage.k8s.io
35-
resources:
36-
- snapshotmetadataservices
37-
verbs:
38-
- get
39-
- list
40-
- watch
4133
- apiGroups:
4234
- csi.ceph.io
4335
resources:

deploy/all-in-one/install-openshift.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15743,14 +15743,6 @@ rules:
1574315743
- patch
1574415744
- update
1574515745
- watch
15746-
- apiGroups:
15747-
- cbt.storage.k8s.io
15748-
resources:
15749-
- snapshotmetadataservices
15750-
verbs:
15751-
- get
15752-
- list
15753-
- watch
1575415746
- apiGroups:
1575515747
- csi.ceph.io
1575615748
resources:

deploy/all-in-one/install.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15729,14 +15729,6 @@ rules:
1572915729
- patch
1573015730
- update
1573115731
- watch
15732-
- apiGroups:
15733-
- cbt.storage.k8s.io
15734-
resources:
15735-
- snapshotmetadataservices
15736-
verbs:
15737-
- get
15738-
- list
15739-
- watch
1574015732
- apiGroups:
1574115733
- csi.ceph.io
1574215734
resources:

deploy/charts/ceph-csi-operator/templates/manager-rbac.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ rules:
3131
- patch
3232
- update
3333
- watch
34-
- apiGroups:
35-
- cbt.storage.k8s.io
36-
resources:
37-
- snapshotmetadataservices
38-
verbs:
39-
- get
40-
- list
41-
- watch
4234
- apiGroups:
4335
- csi.ceph.io
4436
resources:

deploy/multifile/operator.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,6 @@ rules:
288288
- patch
289289
- update
290290
- watch
291-
- apiGroups:
292-
- cbt.storage.k8s.io
293-
resources:
294-
- snapshotmetadataservices
295-
verbs:
296-
- get
297-
- list
298-
- watch
299291
- apiGroups:
300292
- csi.ceph.io
301293
resources:

docs/features/rbd-snapshot-metadata.md

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,11 @@ Users need to perform the following manual setup:
7373
> - Replace `<driver-namespace>` with the namespace where your RBD driver is deployed
7474
> - Ensure certificates are valid for the domain: `<service-name>.<driver-namespace>` (using the service name from step 2)
7575

76-
4. Create a SnapshotMetadataService CR for the RBD driver that will deploy the `external-snapshot-metadata` sidecar.
77-
The name of this CR must match the RBD driver CR name.
76+
4. Provide the TLS secret as a `tls-key` volume in the RBD Driver CR.
7877

79-
**Example:**
80-
81-
```yaml
82-
apiVersion: cbt.storage.k8s.io/v1beta1
83-
kind: SnapshotMetadataService
84-
metadata:
85-
name: <driver-name>
86-
spec:
87-
address: <service-name>.<driver-namespace>:<service-port>
88-
audience: <driver-name>
89-
caCert: <ca-bundle>
90-
```
91-
92-
> **Note:**
93-
> - `address`: Should point to the service created in step 2, replace `<service-name>`, `<driver-namespace>`, and `<service-port>` with your actual values from step 2
94-
> - `audience`: Recommended to use the CSI driver name for consistency
95-
> - `caCert`: Base64-encoded CA certificate bundle
96-
97-
5. Provide the TLS secret required for the `external-snapshot-metadata` sidecar as a volume mount in the RBD driver CR.
78+
This is the trigger for sidecar deployment: the operator deploys the
79+
`external-snapshot-metadata` sidecar whenever it finds a volume named `tls-key`
80+
in `spec.controllerPlugin.volumes` of an RBD Driver CR.
9881

9982
**Example:**
10083

@@ -110,25 +93,43 @@ Users need to perform the following manual setup:
11093
volumes:
11194
- mount:
11295
mountPath: /tmp/certificates # Must be /tmp/certificates - required by sidecar
113-
name: tls-key
96+
name: tls-key
11497
volume:
11598
name: tls-key # Must be "tls-key"
11699
secret:
117-
secretName: snapshot-metadata-tls # The TLS secret name
100+
secretName: snapshot-metadata-tls # The TLS secret name from step 3
118101
```
119102

120103
> **Note:**
121104
> - **mountPath must be `/tmp/certificates`**: This path is required by the snapshot metadata sidecar to locate TLS certificates.
122-
> - **Volume name and mount name must be `tls-key`**: The operator specifically filters for volumes with this exact name to mount in the snapshot-metadata sidecar container.
105+
> - **Volume name and mount name must be `tls-key`**: The operator specifically looks for this name to deploy the sidecar.
123106
> - Replace `<driver-name>` with your RBD driver name (e.g., `rbd.csi.ceph.com`)
124107
> - Replace `<driver-namespace>` with the namespace where your RBD driver is deployed
125108

109+
5. Create a SnapshotMetadataService CR for the RBD driver so backup vendors can
110+
discover the sidecar endpoint. The name of this CR must match the RBD driver CR name.
111+
112+
**Example:**
113+
114+
```yaml
115+
apiVersion: cbt.storage.k8s.io/v1beta1
116+
kind: SnapshotMetadataService
117+
metadata:
118+
name: <driver-name>
119+
spec:
120+
address: <service-name>.<driver-namespace>:<service-port>
121+
audience: <driver-name>
122+
caCert: <ca-bundle>
123+
```
124+
125+
> **Note:**
126+
> - `address`: Should point to the service created in step 2, replace `<service-name>`, `<driver-namespace>`, and `<service-port>` with your actual values from step 2
127+
> - `audience`: Recommended to use the CSI driver name for consistency
128+
> - `caCert`: Base64-encoded CA certificate bundle
129+
126130
## Ceph-CSI Operator Responsibilities
127131

128132
The operator will perform the following actions for the RBD controller plugin deployment:
129133

130-
- Check for the existence of the SnapshotMetadataService CR (name must be the same as the RBD driver CR)
131-
- Check for the volume of type SecretVolumeSource (name must be the same as the RBD driver CR)
132-
133-
> ⚠️ **Note**: If the SnapshotMetadataService CR is created after adding the volume configuration
134-
> in the RBD driver CR, the ceph-csi-operator pod needs to be restarted manually.
134+
- Check for a volume named `tls-key` in `spec.controllerPlugin.volumes` of the RBD Driver CR
135+
- If present, inject the `csi-snapshot-metadata` sidecar into the controller plugin deployment and mount the TLS certificates at `/tmp/certificates`

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.25.8
55
require (
66
github.com/ceph/ceph-csi-operator/api v0.0.0-20260211052505-60308e55e5d9
77
github.com/go-logr/logr v1.4.3
8-
github.com/kubernetes-csi/external-snapshot-metadata/client v1.0.0
98
github.com/onsi/ginkgo/v2 v2.31.0
109
github.com/onsi/gomega v1.42.0
1110
github.com/stretchr/testify v1.11.1
@@ -26,6 +25,7 @@ require (
2625
github.com/cespare/xxhash/v2 v2.3.0 // indirect
2726
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2827
github.com/emicklei/go-restful/v3 v3.13.0 // indirect
28+
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
2929
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
3030
github.com/felixge/httpsnoop v1.0.4 // indirect
3131
github.com/fsnotify/fsnotify v1.9.0 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
111111
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
112112
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
113113
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
114-
github.com/kubernetes-csi/external-snapshot-metadata/client v1.0.0 h1:yRSDNeTNeZq7lSuDKXMv29ejtIRDgmJHCq36EjLQxLU=
115-
github.com/kubernetes-csi/external-snapshot-metadata/client v1.0.0/go.mod h1:Nufr1PWalLkuIyjS4Zr+ugyYEbK7MzbEUtZQUPeAJF0=
116114
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
117115
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
118116
github.com/maruel/natural v1.1.1 h1:Hja7XhhmvEFhcByqDoHz9QZbkWey+COd9xWfCfn1ioo=

internal/controller/driver_controller.go

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
corev1 "k8s.io/api/core/v1"
3535
storagev1 "k8s.io/api/storage/v1"
3636
k8serrors "k8s.io/apimachinery/pkg/api/errors"
37-
"k8s.io/apimachinery/pkg/api/meta"
3837
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3938
"k8s.io/apimachinery/pkg/runtime"
4039
"k8s.io/apimachinery/pkg/util/intstr"
@@ -51,7 +50,6 @@ import (
5150

5251
csiv1 "github.com/ceph/ceph-csi-operator/api/v1"
5352
"github.com/ceph/ceph-csi-operator/internal/utils"
54-
sm "github.com/kubernetes-csi/external-snapshot-metadata/client/apis/snapshotmetadataservice/v1beta1"
5553
)
5654

5755
//+kubebuilder:rbac:groups=csi.ceph.io,resources=drivers,verbs=get;list;watch;create;update;patch;delete
@@ -63,7 +61,6 @@ import (
6361
//+kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete
6462
//+kubebuilder:rbac:groups=apps,resources=daemonsets,verbs=get;list;watch;create;update;patch;delete
6563
//+kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch;create;update;patch;delete
66-
//+kubebuilder:rbac:groups="cbt.storage.k8s.io",resources=snapshotmetadataservices,verbs=get;list;watch;
6764

6865
type DriverType string
6966

@@ -232,16 +229,6 @@ func (r *DriverReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
232229
return ctrl.Result{}, err
233230
}
234231

235-
func (r *driverReconcile) hasSnapshotMetadataServiceCr() (bool, error) {
236-
sms := &sm.SnapshotMetadataService{}
237-
sms.Name = r.driver.Name
238-
if err := r.Get(r.ctx, client.ObjectKeyFromObject(sms), sms); !meta.IsNoMatchError(err) && client.IgnoreNotFound(err) != nil {
239-
return false, fmt.Errorf("failed to get SnapshotMetadataService resource: %w", err)
240-
}
241-
242-
return sms.UID != "", nil
243-
}
244-
245232
func (r *driverReconcile) reconcile() error {
246233
// Load the driver desired state based on driver resource, operator config resource and default values.
247234
if err := r.LoadAndValidateDesiredState(); err != nil {
@@ -969,9 +956,10 @@ func (r *driverReconcile) reconcileControllerPluginDeployment() error {
969956
}
970957
// CSI snapshot-metadata Sidecar Container
971958
if r.isRbdDriver() {
972-
if deploy, err := r.hasSnapshotMetadataServiceCr(); err != nil {
973-
r.log.Error(err, "Failed to check for SnapshotMetadataService CR")
974-
} else if deploy {
959+
tlsMountIndex := slices.IndexFunc(pluginSpec.Volumes, func(vol csiv1.VolumeSpec) bool {
960+
return vol.Volume.Name == "tls-key"
961+
})
962+
if tlsMountIndex != -1 {
975963
containers = append(containers, corev1.Container{
976964
Name: "csi-snapshot-metadata",
977965
ImagePullPolicy: imagePullPolicy,
@@ -991,14 +979,8 @@ func (r *driverReconcile) reconcileControllerPluginDeployment() error {
991979
},
992980
VolumeMounts: utils.Call(func() []corev1.VolumeMount {
993981
mounts := []corev1.VolumeMount{}
994-
tlsMountIndex := slices.IndexFunc(pluginSpec.Volumes, func(vol csiv1.VolumeSpec) bool {
995-
return vol.Volume.Name == "tls-key"
996-
})
997-
if tlsMountIndex != -1 {
998-
mounts = append(mounts, pluginSpec.Volumes[tlsMountIndex].Mount)
999-
}
982+
mounts = append(mounts, pluginSpec.Volumes[tlsMountIndex].Mount)
1000983
mounts = append(mounts, utils.SocketDirVolumeMount)
1001-
1002984
return mounts
1003985
}),
1004986
})

0 commit comments

Comments
 (0)