Skip to content

Commit

Permalink
Updating clustersBeforeFailover spec
Browse files Browse the repository at this point in the history
Signed-off-by: mszacillo <mszacillo@bloomberg.net>
  • Loading branch information
mszacillo committed Oct 29, 2024
1 parent 2aa5b1b commit 1d8fe66
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 74 deletions.
8 changes: 4 additions & 4 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -20036,16 +20036,16 @@
"description": "ClustersAfterFailover records the clusters where the application is running after failover.",
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.work.v1alpha2.TargetCluster"
"type": "string",
"default": ""
}
},
"clustersBeforeFailover": {
"description": "ClustersBeforeFailover records the clusters where the application was running prior to failover.",
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.work.v1alpha2.TargetCluster"
"type": "string",
"default": ""
}
},
"preservedLabelState": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1350,37 +1350,13 @@ spec:
description: ClustersAfterFailover records the clusters where
the application is running after failover.
items:
description: TargetCluster represents the identifier of a
member cluster.
properties:
name:
description: Name of target cluster.
type: string
replicas:
description: Replicas in target cluster
format: int32
type: integer
required:
- name
type: object
type: string
type: array
clustersBeforeFailover:
description: ClustersBeforeFailover records the clusters where
the application was running prior to failover.
items:
description: TargetCluster represents the identifier of a
member cluster.
properties:
name:
description: Name of target cluster.
type: string
replicas:
description: Replicas in target cluster
format: int32
type: integer
required:
- name
type: object
type: string
type: array
preservedLabelState:
additionalProperties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1350,37 +1350,13 @@ spec:
description: ClustersAfterFailover records the clusters where
the application is running after failover.
items:
description: TargetCluster represents the identifier of a
member cluster.
properties:
name:
description: Name of target cluster.
type: string
replicas:
description: Replicas in target cluster
format: int32
type: integer
required:
- name
type: object
type: string
type: array
clustersBeforeFailover:
description: ClustersBeforeFailover records the clusters where
the application was running prior to failover.
items:
description: TargetCluster represents the identifier of a
member cluster.
properties:
name:
description: Name of target cluster.
type: string
replicas:
description: Replicas in target cluster
format: int32
type: integer
required:
- name
type: object
type: string
type: array
preservedLabelState:
additionalProperties:
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/work/v1alpha2/binding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,11 @@ type FailoverHistoryItem struct {

// ClustersBeforeFailover records the clusters where the application was running prior to failover.
// +required
ClustersBeforeFailover []TargetCluster `json:"clustersBeforeFailover"`
ClustersBeforeFailover []string `json:"clustersBeforeFailover"`

// ClustersAfterFailover records the clusters where the application is running after failover.
// +required
ClustersAfterFailover []TargetCluster `json:"clustersAfterFailover"`
ClustersAfterFailover []string `json:"clustersAfterFailover"`

// PreservedLabelState represents the application state information collected from the original cluster,
// and it will be injected into the new cluster in the form of application labels.
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/work/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (c *RBApplicationFailoverController) syncBinding(ctx context.Context, bindi
}

func (c *RBApplicationFailoverController) evictBinding(binding *workv1alpha2.ResourceBinding, clusters []string) error {
if err := controllerUtils.UpdateFailoverStatus(c.Client, binding, workv1alpha2.EvictionReasonApplicationFailure); err != nil {
if err := controllerUtils.UpdateFailoverStatus(c.Client, binding, clusters, workv1alpha2.EvictionReasonApplicationFailure); err != nil {
klog.Errorf("Failed to update status with failover information. Error: %v", err)
}
for _, cluster := range clusters {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/cluster/taint_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (tc *NoExecuteTaintManager) syncBindingEviction(key util.QueueKey) error {
// Case 2: Need eviction after toleration time. If time is up, do eviction right now.
// Case 3: Tolerate forever, we do nothing.
if needEviction || tolerationTime == 0 {
err := controllerUtils.UpdateFailoverStatus(tc.Client, binding, workv1alpha2.EvictionReasonTaintUntolerated)
err := controllerUtils.UpdateFailoverStatus(tc.Client, binding, []string{cluster}, workv1alpha2.ClusterFailover)
if err != nil {
klog.Errorf("Failed to update status with failover information. Error: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/controllers/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ import (
)

// UpdateFailoverStatus adds a failoverHistoryItem to the failoverHistory field in the ResourceBinding.
func UpdateFailoverStatus(client client.Client, binding *workv1alpha2.ResourceBinding, failoverType workv1alpha2.FailoverReason) (err error) {
func UpdateFailoverStatus(client client.Client, binding *workv1alpha2.ResourceBinding, clusters []string, failoverType workv1alpha2.FailoverReason) (err error) {
klog.V(4).Infof("Updating failover status for ResourceBinding(%s/%s)", binding.Name, binding.Namespace)
err = retry.RetryOnConflict(retry.DefaultRetry, func() (err error) {
_, err = helper.UpdateStatus(context.Background(), client, binding, func() error {
failoverHistoryItem := workv1alpha2.FailoverHistoryItem{
StartTime: metav1.Time{Time: time.Now()},
Reason: failoverType,
ClustersBeforeFailover: binding.Spec.Clusters,
ClustersAfterFailover: []workv1alpha2.TargetCluster{},
ClustersBeforeFailover: clusters,
ClustersAfterFailover: []string{},
}
binding.Status.FailoverHistory = append(binding.Status.FailoverHistory, failoverHistoryItem)
// ToDo: Consider parametrizing failover history length
Expand Down
12 changes: 7 additions & 5 deletions pkg/generated/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func (p *ClusterEviction) Filter(_ context.Context, bindingSpec *workv1alpha2.Re
}

// containsCluster checks if selected cluster has been previously failed over from
func containsCluster(clusters []workv1alpha2.TargetCluster, findCluster string) bool {
func containsCluster(clusters []string, findCluster string) bool {
for _, cluster := range clusters {
if cluster.Name == findCluster {
if cluster == findCluster {
return true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestClusterEviction_Filter(t *testing.T) {
bindingStatus: &workv1alpha2.ResourceBindingStatus{
FailoverHistory: []workv1alpha2.FailoverHistoryItem{
{
ClustersBeforeFailover: []workv1alpha2.TargetCluster{{Name: "cluster1", Replicas: 2}},
ClustersBeforeFailover: []string{"cluster1"},
Reason: workv1alpha2.ApplicationFailover,
StartTime: metav1.Time{Time: time.Now()},
},
Expand Down
6 changes: 5 additions & 1 deletion pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,10 +845,14 @@ func patchBindingStatusWithUpdatedFailoverHistory(karmadaClient karmadaclientset
if rb.Status.FailoverHistory == nil || scheduleResult == nil {
return nil
}
var clusters []string
for _, cluster := range scheduleResult {
clusters = append(clusters, cluster.Name)
}
klog.V(4).Infof("Begin to patch failoverHistory with scheduling result(%v) to ResourceBinding(%s/%s).", scheduleResult, rb.Namespace, rb.Name)
updateRB := rb.DeepCopy()
historyLength := len(updateRB.Status.FailoverHistory)
updateRB.Status.FailoverHistory[historyLength-1].ClustersAfterFailover = scheduleResult
updateRB.Status.FailoverHistory[historyLength-1].ClustersAfterFailover = clusters
return patchBindingStatus(karmadaClient, rb, updateRB)
}

Expand Down

0 comments on commit 1d8fe66

Please sign in to comment.