Skip to content

Commit

Permalink
Removing failover flag - deferring to next pr
Browse files Browse the repository at this point in the history
Signed-off-by: mszacillo <mszacillo@bloomberg.net>
  • Loading branch information
mszacillo committed Oct 27, 2024
1 parent ffbba8f commit 2aa5b1b
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 194 deletions.
28 changes: 0 additions & 28 deletions pkg/controllers/binding/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,6 @@ func mergeTargetClusters(targetClusters []workv1alpha2.TargetCluster, requiredBy
func mergeLabel(workload *unstructured.Unstructured, binding metav1.Object, scope apiextensionsv1.ResourceScope) map[string]string {
var workLabel = make(map[string]string)
if scope == apiextensionsv1.NamespaceScoped {
namespaceBindingObj := binding.(*workv1alpha2.ResourceBinding)
failoverReason := checkFailoverHistory(namespaceBindingObj)
if failoverReason != "" {
if failoverReason == workv1alpha2.EvictionReasonApplicationFailure {
util.MergeLabel(workload, workv1alpha2.ResourceBindingFailoverLabel, "application")
workLabel[workv1alpha2.ResourceBindingFailoverLabel] = "application"
} else if failoverReason == workv1alpha2.EvictionReasonTaintUntolerated {
util.MergeLabel(workload, workv1alpha2.ResourceBindingFailoverLabel, "cluster")
workLabel[workv1alpha2.ResourceBindingFailoverLabel] = "cluster"
}
}
bindingID := util.GetLabelValue(binding.GetLabels(), workv1alpha2.ResourceBindingPermanentIDLabel)
util.MergeLabel(workload, workv1alpha2.ResourceBindingPermanentIDLabel, bindingID)
workLabel[workv1alpha2.ResourceBindingPermanentIDLabel] = bindingID
Expand All @@ -194,23 +183,6 @@ func mergeLabel(workload *unstructured.Unstructured, binding metav1.Object, scop
return workLabel
}

// Check if resourcebinding contains failover history, used to determine whether we attach failover label to cloned workload
// Return failover reason
func checkFailoverHistory(resourceBinding *workv1alpha2.ResourceBinding) string {
failoverHistory := resourceBinding.Status.FailoverHistory
if len(failoverHistory) == 0 {
return ""
}
lastFailover := failoverHistory[len(failoverHistory)-1]
if lastFailover.Reason == "ClusterFailover" {
return workv1alpha2.EvictionReasonTaintUntolerated
}
if lastFailover.Reason == "ApplicationFailover" {
return workv1alpha2.EvictionReasonApplicationFailure
}
return ""
}

func mergeAnnotations(workload *unstructured.Unstructured, binding metav1.Object, scope apiextensionsv1.ResourceScope) map[string]string {
annotations := make(map[string]string)
if workload.GetGeneration() > 0 {
Expand Down
38 changes: 0 additions & 38 deletions pkg/controllers/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,10 @@ import (
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"

policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
"github.com/karmada-io/karmada/pkg/util/helper"
)

// FailoverHistoryInfoIsSupported verifies that the resource's placement supports FailoverHistory feature
func FailoverHistoryInfoIsSupported(binding *workv1alpha2.ResourceBinding) bool {
placementPtr := binding.Spec.Placement
if placementPtr == nil {
return false
}
return verifySchedulingTypeSupported(placementPtr.ReplicaScheduling, placementPtr.SpreadConstraints)
}

// FailoverHistoryInfo is currently not supported for the following scheduling types
// 1. Duplicated (as these resources do not failover)
// 2. Divided resources that can be scheduled across multiple clusters. In this case, state is harder to conserve since
// the application's replicas will not be migrating together.
func verifySchedulingTypeSupported(schedulingPtr *policyv1alpha1.ReplicaSchedulingStrategy, spreadConstraints []policyv1alpha1.SpreadConstraint) bool {
if schedulingPtr == nil {
return false
}
switch schedulingType := schedulingPtr.ReplicaSchedulingType; schedulingType {
case policyv1alpha1.ReplicaSchedulingTypeDuplicated:
return false
// Handles divided and nil case
default:
if len(spreadConstraints) == 0 {
return false
}
for _, spreadConstraint := range spreadConstraints {
if spreadConstraint.SpreadByLabel != "" {
return false
}
if spreadConstraint.SpreadByField == "cluster" && (spreadConstraint.MaxGroups > 1 || spreadConstraint.MinGroups > 1) {
return false
}
}
}
return true
}

// UpdateFailoverStatus adds a failoverHistoryItem to the failoverHistory field in the ResourceBinding.
func UpdateFailoverStatus(client client.Client, binding *workv1alpha2.ResourceBinding, failoverType workv1alpha2.FailoverReason) (err error) {
klog.V(4).Infof("Updating failover status for ResourceBinding(%s/%s)", binding.Name, binding.Namespace)
Expand Down
128 changes: 0 additions & 128 deletions pkg/controllers/utils/common_test.go

This file was deleted.

0 comments on commit 2aa5b1b

Please sign in to comment.