-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
groupreplication: add controller logic for volume group replication
added controller logic for volume group replication Signed-off-by: Nikhil-Ladha <[email protected]>
- Loading branch information
1 parent
af14347
commit 703125d
Showing
13 changed files
with
1,207 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
Copyright 2024 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" | ||
"time" | ||
|
||
replicationv1alpha1 "github.com/csi-addons/kubernetes-csi-addons/api/replication.storage/v1alpha1" | ||
|
||
"github.com/go-logr/logr" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func SetFailureCondition(instanceState replicationv1alpha1.ReplicationState, | ||
instanceStatus *replicationv1alpha1.VolumeReplicationStatus, instanceGeneration int64) { | ||
|
||
switch instanceState { | ||
case replicationv1alpha1.Primary: | ||
setFailedPromotionCondition(&instanceStatus.Conditions, instanceGeneration) | ||
case replicationv1alpha1.Secondary: | ||
setFailedDemotionCondition(&instanceStatus.Conditions, instanceGeneration) | ||
case replicationv1alpha1.Resync: | ||
setFailedResyncCondition(&instanceStatus.Conditions, instanceGeneration) | ||
} | ||
} | ||
|
||
func GetReplicationState(instanceState replicationv1alpha1.ReplicationState) replicationv1alpha1.State { | ||
switch instanceState { | ||
case replicationv1alpha1.Primary: | ||
return replicationv1alpha1.PrimaryState | ||
case replicationv1alpha1.Secondary: | ||
return replicationv1alpha1.SecondaryState | ||
case replicationv1alpha1.Resync: | ||
return replicationv1alpha1.SecondaryState | ||
} | ||
|
||
return replicationv1alpha1.UnknownState | ||
} | ||
|
||
func GetCurrentReplicationState(instanceStatusState replicationv1alpha1.State) replicationv1alpha1.State { | ||
if instanceStatusState == "" { | ||
return replicationv1alpha1.UnknownState | ||
} | ||
|
||
return instanceStatusState | ||
} | ||
|
||
func WaitForVolumeReplicationResource(client client.Client, logger logr.Logger, resourceName string) error { | ||
unstructuredResource := &unstructured.UnstructuredList{} | ||
unstructuredResource.SetGroupVersionKind(schema.GroupVersionKind{ | ||
Group: replicationv1alpha1.GroupVersion.Group, | ||
Kind: resourceName, | ||
Version: replicationv1alpha1.GroupVersion.Version, | ||
}) | ||
for { | ||
err := client.List(context.TODO(), unstructuredResource) | ||
if err == nil { | ||
return nil | ||
} | ||
// return errors other than NoMatch | ||
if !meta.IsNoMatchError(err) { | ||
logger.Error(err, "got an unexpected error while waiting for resource", "Resource", resourceName) | ||
return err | ||
} | ||
logger.Info("resource does not exist", "Resource", resourceName) | ||
time.Sleep(5 * time.Second) | ||
} | ||
} |
Oops, something went wrong.