Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbd: Allow user to disable key rotation #2817

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ rules:
- delete
- get
- list
- update
- watch
- apiGroups:
- template.openshift.io
Expand Down
5 changes: 5 additions & 0 deletions controllers/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const (
// KubeMinorTopologySpreadConstraints is the minimum minor kube version to support TSC
// used along with KubeMajorTSC for version comparison
KubeMinorTopologySpreadConstraints = "19"
// This annotation is used by both StorageCluster and StorageClass to specify whether
// the key rotation feature is enabled. Users can add this annotation to StorageCluster
// with a value of "false" to disable key rotation. When present, this annotation is then
// propagated to the associated StorageClasses.
KeyRotationEnableAnnotation = "keyrotation.csiaddons.openshift.io/enable"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion controllers/storagecluster/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ var validTopologyLabelKeys = []string{
// +kubebuilder:rbac:groups=ocs.openshift.io,resources=*,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=ceph.rook.io,resources=cephclusters;cephblockpools;cephfilesystems;cephnfses;cephobjectstores;cephobjectstoreusers;cephrbdmirrors;cephblockpoolradosnamespaces,verbs=get;list;watch;create;update;delete
// +kubebuilder:rbac:groups=noobaa.io,resources=noobaas,verbs=get;list;watch;create;update;delete
// +kubebuilder:rbac:groups=storage.k8s.io,resources=storageclasses,verbs=watch;create;delete;get;list
// +kubebuilder:rbac:groups=storage.k8s.io,resources=storageclasses,verbs=watch;create;update;delete;get;list
// +kubebuilder:rbac:groups=core,resources=pods;services;serviceaccounts;endpoints;persistentvolumes;persistentvolumeclaims;events;configmaps;secrets;nodes,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core,resources=namespaces,verbs=get
// +kubebuilder:rbac:groups=apps,resources=deployments;daemonsets;replicasets;statefulsets,verbs=get;list;watch;create;update;delete
Expand Down
25 changes: 24 additions & 1 deletion controllers/storagecluster/storageclasses.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

ocsv1 "github.com/red-hat-storage/ocs-operator/api/v4/v1"
"github.com/red-hat-storage/ocs-operator/v4/controllers/defaults"
"github.com/red-hat-storage/ocs-operator/v4/controllers/platform"
"github.com/red-hat-storage/ocs-operator/v4/controllers/util"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
Expand Down Expand Up @@ -198,6 +199,7 @@ func (r *StorageClusterReconciler) createStorageClasses(sccs []StorageClassConfi
}
}

scRecreated := false
existing := &storagev1.StorageClass{}
err := r.Client.Get(context.TODO(), types.NamespacedName{Name: sc.Name, Namespace: sc.Namespace}, existing)

Expand Down Expand Up @@ -232,6 +234,20 @@ func (r *StorageClusterReconciler) createStorageClasses(sccs []StorageClassConfi
r.Log.Info("Failed to create StorageClass.", "StorageClass", klog.KRef(sc.Namespace, sc.Name))
return err
}
scRecreated = true
}
if !scRecreated {
black-dragon74 marked this conversation as resolved.
Show resolved Hide resolved
// Delete existing key rotation annotation and set it on sc only when it is false
delete(existing.Annotations, defaults.KeyRotationEnableAnnotation)
if krState := sc.GetAnnotations()[defaults.KeyRotationEnableAnnotation]; krState == "false" {
util.AddAnnotation(existing, defaults.KeyRotationEnableAnnotation, krState)
}

err = r.Client.Update(context.TODO(), existing)
black-dragon74 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
r.Log.Error(err, "Failed to update annotations on the StorageClass.", "StorageClass", klog.KRef(sc.Namespace, existing.Name))
return err
}
}
}
}
Expand Down Expand Up @@ -314,6 +330,9 @@ func newCephBlockPoolStorageClassConfiguration(initData *ocsv1.StorageCluster) S
if initData.Spec.ManagedResources.CephBlockPools.DefaultStorageClass {
scc.storageClass.Annotations[defaultStorageClassAnnotation] = "true"
}
if initData.GetAnnotations()[defaults.KeyRotationEnableAnnotation] == "false" {
util.AddAnnotation(scc.storageClass, defaults.KeyRotationEnableAnnotation, "false")
}
return scc
black-dragon74 marked this conversation as resolved.
Show resolved Hide resolved
}

Expand All @@ -336,7 +355,7 @@ func newNonResilientCephBlockPoolStorageClassConfiguration(initData *ocsv1.Stora
persistentVolumeReclaimDelete := corev1.PersistentVolumeReclaimDelete
allowVolumeExpansion := true
volumeBindingWaitForFirstConsumer := storagev1.VolumeBindingWaitForFirstConsumer
return StorageClassConfiguration{
scc := StorageClassConfiguration{
storageClass: &storagev1.StorageClass{
ObjectMeta: metav1.ObjectMeta{
Name: util.GenerateNameForNonResilientCephBlockPoolSC(initData),
Expand Down Expand Up @@ -366,6 +385,10 @@ func newNonResilientCephBlockPoolStorageClassConfiguration(initData *ocsv1.Stora
},
isClusterExternal: initData.Spec.ExternalStorage.Enable,
}
if initData.GetAnnotations()[defaults.KeyRotationEnableAnnotation] == "false" {
util.AddAnnotation(scc.storageClass, defaults.KeyRotationEnableAnnotation, "false")
}
return scc
}

// newCephNFSStorageClassConfiguration generates configuration options for a Ceph NFS StorageClass.
Expand Down
1 change: 1 addition & 0 deletions deploy/csv-templates/ocs-operator.csv.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ spec:
- delete
- get
- list
- update
- watch
- apiGroups:
- template.openshift.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ spec:
- delete
- get
- list
- update
- watch
- apiGroups:
- template.openshift.io
Expand Down
Loading