Skip to content

Commit

Permalink
fix(platform): cluster status is Terminating, update will delete it (#…
Browse files Browse the repository at this point in the history
…2304)

Co-authored-by: xdonggao <[email protected]>
  • Loading branch information
GaoXiaodong and xdonggao authored Aug 3, 2023
1 parent e13aefd commit 4cd32bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/platform/registry/cluster/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func NewStorage(optsGetter genericregistry.RESTOptionsGetter, platformClient pla
UpdateStrategy: strategy,
DeleteStrategy: strategy,

ShouldDeleteDuringUpdate: clusterstrategy.ShouldDeleteDuringUpdate,

TableConvertor: printerstorage.TableConvertor{TableGenerator: printers.NewTableGenerator().With(AddHandlers)},
}
options := &genericregistry.StoreOptions{
Expand Down
10 changes: 10 additions & 0 deletions pkg/platform/registry/cluster/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericregistry "k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage/names"
Expand Down Expand Up @@ -251,6 +252,15 @@ func MatchCluster(label labels.Selector, field fields.Selector) storage.Selectio
}
}

func ShouldDeleteDuringUpdate(ctx context.Context, key string, obj, existing runtime.Object) bool {
app, ok := obj.(*platform.Cluster)
if !ok {
log.Errorf("unexpected object, key:%s", key)
return false
}
return len(app.Spec.Finalizers) == 0 && registry.ShouldDeleteDuringUpdate(ctx, key, obj, existing)
}

// ToSelectableFields returns a field set that represents the object
func ToSelectableFields(cluster *platform.Cluster) fields.Set {
objectMetaFieldsSet := genericregistry.ObjectMetaFieldsSet(&cluster.ObjectMeta, false)
Expand Down

0 comments on commit 4cd32bb

Please sign in to comment.