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

add volumegroupreplicationclass controller code #749

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions docs/volumegroupreplicationclass.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# VolumeGroupReplicationClass

VolumeGroupReplicationClass is a cluster scoped resource that contains driver related configuration parameters for volume group replication.

`provisioner` is name of the storage provisioner.

`parameters` contains key-value pairs that are passed down to the driver. Users can add their own key-value pairs. Keys with `replication.storage.openshift.io/` prefix are reserved by operator and not passed down to the driver.

## Reserved parameter keys

- `replication.storage.openshift.io/group-replication-secret-name`
- `replication.storage.openshift.io/group-replication-secret-namespace`

```yaml
apiVersion: replication.storage.openshift.io/v1alpha1
kind: VolumeGroupReplicationClass
metadata:
name: volumegroupreplicationclass-sample
spec:
provisioner: example.provisioner.io
parameters:
replication.storage.openshift.io/group-replication-secret-name: secret-name
replication.storage.openshift.io/group-replication-secret-namespace: secret-namespace
```
10 changes: 8 additions & 2 deletions internal/controller/replication.storage/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ const (
// Driver.
replicationParameterPrefix = "replication.storage.openshift.io/"

prefixedReplicationSecretNameKey = replicationParameterPrefix + "replication-secret-name" // name key for secret
prefixedReplicationSecretNamespaceKey = replicationParameterPrefix + "replication-secret-namespace" // namespace key secret
prefixedReplicationSecretNameKey = replicationParameterPrefix + "replication-secret-name" // name key for secret
prefixedReplicationSecretNamespaceKey = replicationParameterPrefix + "replication-secret-namespace" // namespace key secret
prefixedGroupReplicationSecretNameKey = replicationParameterPrefix + "group-replication-secret-name" // name key for secret
prefixedGroupReplicationSecretNamespaceKey = replicationParameterPrefix + "group-replication-secret-namespace" // namespace key secret
)

// filterPrefixedParameters removes all the reserved keys from the
Expand All @@ -53,10 +55,14 @@ func validatePrefixedParameters(param map[string]string) error {
if strings.HasPrefix(k, replicationParameterPrefix) {
switch k {
case prefixedReplicationSecretNameKey:
fallthrough
case prefixedGroupReplicationSecretNameKey:
if v == "" {
return errors.New("secret name cannot be empty")
}
case prefixedReplicationSecretNamespaceKey:
fallthrough
case prefixedGroupReplicationSecretNamespaceKey:
if v == "" {
return errors.New("secret namespace cannot be empty")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright 2025 The Kubernetes-CSI-Addons Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controller

import (
"context"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"

replicationv1alpha1 "github.com/csi-addons/kubernetes-csi-addons/api/replication.storage/v1alpha1"
)

// getVolumeGroupReplicationClass fetches the volumegroupreplicationclass object in the given namespace and return the same.
// nolint:unused // Ignore unused function, will be updated later
func (r VolumeGroupReplicationReconciler) getVolumeGroupReplicationClass(logger logr.Logger, vgrClassName string) (*replicationv1alpha1.VolumeGroupReplicationClass, error) {
vgrClassObj := &replicationv1alpha1.VolumeGroupReplicationClass{}
err := r.Client.Get(context.TODO(), types.NamespacedName{Name: vgrClassName}, vgrClassObj)
if err != nil {
if errors.IsNotFound(err) {
logger.Error(err, "VolumeGroupReplicationClass not found", "VolumeGroupReplicationClass", vgrClassName)
} else {
logger.Error(err, "Got an unexpected error while fetching VolumeGroupReplicationClass", "VolumeGroupReplicationClass", vgrClassName)
}

return nil, err
}

return vgrClassObj, nil
}
Loading