Skip to content

Commit

Permalink
volumegroup: add volumegroupreplicationclass controller code
Browse files Browse the repository at this point in the history
add volumegroupreplicationclass controller code

Signed-off-by: Nikhil-Ladha <[email protected]>
  • Loading branch information
Nikhil-Ladha committed Jan 16, 2025
1 parent ee41518 commit 8781201
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
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,44 @@
/*
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"

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

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

// getVolumeGroupReplicationClass fetches the volumegroupreplicationclass object in the given namespace and return the same.
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 VolumeReplicationClass", "VolumeReplicationClass", vgrClassName)
}

return nil, err
}

return vgrClassObj, nil
}

0 comments on commit 8781201

Please sign in to comment.