diff --git a/resourcecontexts/resource_context.go b/resourcecontexts/resource_context.go index 3feb636..3e61b55 100644 --- a/resourcecontexts/resource_context.go +++ b/resourcecontexts/resource_context.go @@ -27,6 +27,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/tools/record" + "k8s.io/utils/ptr" clientutil "kusionstack.io/kube-utils/client" "kusionstack.io/kube-utils/controller/expectations" "kusionstack.io/kube-utils/controller/mixin" @@ -160,7 +161,7 @@ func (r *RealResourceContextControl) CleanUnusedIDs(ctx context.Context, xsetObj ownedIDs[detail.ID] = detail } } - needCleanCount = len(ownedIDs) - maxInt(int(*xsetSpec.Replicas), len(objs)) + needCleanCount = len(ownedIDs) - maxInt(int(ptr.Deref(xsetSpec.Replicas, 0)), len(objs)) if needCleanCount <= 0 { return nil diff --git a/synccontrols/sync_control.go b/synccontrols/sync_control.go index 8fff200..4981669 100644 --- a/synccontrols/sync_control.go +++ b/synccontrols/sync_control.go @@ -180,7 +180,7 @@ func (r *RealSyncControl) SyncTargets(ctx context.Context, instance api.XSetObje syncContext.OwnedIds = ownedIDs return err }); err != nil { - return false, fmt.Errorf("fail to allocate %d IDs using context when sync Targets: %w", xspec.Replicas, err) + return false, fmt.Errorf("fail to allocate %d IDs using context when sync Targets: %w", ptr.Deref(xspec.Replicas, 0), err) } // stateless case