Skip to content

Commit

Permalink
Merge pull request kosmos-io#430 from zhouhaoA1/dev_promote
Browse files Browse the repository at this point in the history
feature: add rollback for promote feature
  • Loading branch information
kosmos-robot authored Mar 12, 2024
2 parents 0a73c7b + d6f1b6f commit d6e94ee
Show file tree
Hide file tree
Showing 26 changed files with 1,251 additions and 350 deletions.
1 change: 0 additions & 1 deletion cmd/clustertree/cluster-manager/app/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers"
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/mcs"
podcontrollers "github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/pod"
_ "github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/promote"
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/pv"
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/pvc"
nodeserver "github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/node-server"
Expand Down
6 changes: 6 additions & 0 deletions deploy/crds/kosmos.io_promotepolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,16 @@ spec:
type: string
nullable: true
type: array
rollback:
description: Rollback set true, then rollback from the backup
nullable: true
type: string
type: object
status:
description: PromotePolicyStatus defines the observed state of promotePolicy
properties:
backedupFile:
type: string
completionTimestamp:
description: CompletionTimestamp records the time a sync was completed.
Completion time is recorded even on failed sync. The server's time
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/kosmos/v1alpha1/promotepolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ type PromotePolicySpec struct {
// +optional
// +nullable
ExcludedNamespaceScopedResources []string `json:"excludedNamespaceScopedResources,omitempty"`

// Rollback set true, then rollback from the backup
// +optional
// +nullable
Rollback string `json:"rollback,omitempty"`
}

// PromotePolicyPhase is a string representation of the lifecycle phase
Expand Down Expand Up @@ -65,6 +70,12 @@ const (
// PromotePolicyPhaseFailedRestore means restore has failed
PromotePolicyPhaseFailedRestore PromotePolicyPhase = "FailedRestore"

// PromotePolicyPhaseFailedRollback means rollback has failed
PromotePolicyPhaseFailedRollback PromotePolicyPhase = "FailedRollback"

// PromotePolicyPhaseRolledback means rollback has successed
PromotePolicyPhaseRolledback PromotePolicyPhase = "RolledBack"

// PromotePolicyPhaseCompleted means the sync has run successfully
PromotePolicyPhaseCompleted PromotePolicyPhase = "Completed"
)
Expand Down Expand Up @@ -118,6 +129,8 @@ type PromotePolicyStatus struct {
// +optional
// +nullable
Progress *PromotePolicyProgress `json:"progress,omitempty"`

BackedupFile string `json:"backedupFile,omitempty"`
}

// +genclient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"time"

"github.com/google/go-cmp/cmp"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -149,12 +148,13 @@ func (r *LeafPodReconciler) SetupWithManager(mgr manager.Manager) error {
return skipFunc(createEvent.Object)
},
UpdateFunc: func(updateEvent event.UpdateEvent) bool {
pod1 := updateEvent.ObjectOld.(*corev1.Pod)
pod2 := updateEvent.ObjectNew.(*corev1.Pod)
if !skipFunc(updateEvent.ObjectNew) {
return false
}
return !cmp.Equal(pod1.Status, pod2.Status)
return skipFunc(updateEvent.ObjectNew)
//pod1 := updateEvent.ObjectOld.(*corev1.Pod)
//pod2 := updateEvent.ObjectNew.(*corev1.Pod)
//if !skipFunc(updateEvent.ObjectNew) {
// return false
//}
//return !cmp.Equal(pod1.Status, pod2.Status)
},
DeleteFunc: func(deleteEvent event.DeleteEvent) bool {
return skipFunc(deleteEvent.Object)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package backup

import (
"archive/tar"
"fmt"
"time"

"github.com/pkg/errors"
Expand All @@ -18,6 +17,7 @@ import (
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/promote/client"
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/promote/discovery"
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/promote/requests"
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/promote/types"
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/promote/utils/archive"
)

Expand Down Expand Up @@ -68,8 +68,8 @@ func (ib *itemBackupper) backupItemInternal(obj runtime.Unstructured, groupResou
namespace := metadata.GetNamespace()
name := metadata.GetName()

key := requests.ItemKey{
Resource: resourceKey(obj),
key := types.ItemKey{
Resource: groupResource.String(),
Namespace: namespace,
Name: name,
}
Expand Down Expand Up @@ -189,10 +189,3 @@ func resourceVersion(obj runtime.Unstructured) string {
gvk := obj.GetObjectKind().GroupVersionKind()
return gvk.Version
}

// resourceKey returns a string representing the object's GroupVersionKind (e.g.
// apps/v1/Deployment).
func resourceKey(obj runtime.Unstructured) string {
gvk := obj.GetObjectKind().GroupVersionKind()
return fmt.Sprintf("%s/%s", gvk.GroupVersion().String(), gvk.Kind)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"

"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/promote/requests"
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/promote/types"
)

// BackupItemAction is an actor that performs an operation on an individual item being backed up.
Expand Down Expand Up @@ -34,7 +35,7 @@ func registerBackupActions() (map[string]BackupItemAction, error) {
return actionMap, nil
}

func registerBackupItemAction(actionsMap map[string]BackupItemAction, initializer requests.HandlerInitializer) error {
func registerBackupItemAction(actionsMap map[string]BackupItemAction, initializer types.HandlerInitializer) error {
instance, err := initializer()
if err != nil {
return errors.WithMessage(err, "init backup action instance error")
Expand Down
Loading

0 comments on commit d6e94ee

Please sign in to comment.