Skip to content

Commit b69b7b3

Browse files
committed
fix panic of xsetspec.replicas nil pointer
1 parent 56069d5 commit b69b7b3

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

resourcecontexts/resource_context.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"k8s.io/apimachinery/pkg/types"
2828
"k8s.io/apimachinery/pkg/util/sets"
2929
"k8s.io/client-go/tools/record"
30+
"k8s.io/utils/ptr"
3031
clientutil "kusionstack.io/kube-utils/client"
3132
"kusionstack.io/kube-utils/controller/expectations"
3233
"kusionstack.io/kube-utils/controller/mixin"
@@ -160,7 +161,7 @@ func (r *RealResourceContextControl) CleanUnusedIDs(ctx context.Context, xsetObj
160161
ownedIDs[detail.ID] = detail
161162
}
162163
}
163-
needCleanCount = len(ownedIDs) - maxInt(int(*xsetSpec.Replicas), len(objs))
164+
needCleanCount = len(ownedIDs) - maxInt(int(ptr.Deref(xsetSpec.Replicas, 0)), len(objs))
164165

165166
if needCleanCount <= 0 {
166167
return nil

synccontrols/sync_control.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (r *RealSyncControl) SyncTargets(ctx context.Context, instance api.XSetObje
180180
syncContext.OwnedIds = ownedIDs
181181
return err
182182
}); err != nil {
183-
return false, fmt.Errorf("fail to allocate %d IDs using context when sync Targets: %w", xspec.Replicas, err)
183+
return false, fmt.Errorf("fail to allocate %d IDs using context when sync Targets: %w", ptr.Deref(xspec.Replicas, 0), err)
184184
}
185185

186186
// stateless case

0 commit comments

Comments
 (0)