Skip to content

Commit 0da7106

Browse files
committed
touch up manually
Signed-off-by: Ryan Zhang <[email protected]>
1 parent 185dd19 commit 0da7106

File tree

6 files changed

+24
-31
lines changed

6 files changed

+24
-31
lines changed

apis/placement/v1beta1/clusterresourceplacement_types.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ type PlacementSpec struct {
105105
RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty"`
106106
}
107107

108+
// Tolerations returns tolerations for PlacementSpec to handle nil policy case.
109+
func (p *PlacementSpec) Tolerations() []Toleration {
110+
if p.Policy != nil {
111+
return p.Policy.Tolerations
112+
}
113+
return nil
114+
}
115+
108116
// TODO: rename this to ResourceSelectorTerm
109117
// ClusterResourceSelector is used to select cluster scoped resources as the target resources to be placed.
110118
// All the fields are `ANDed`. In other words, a resource must match all the fields to be selected.
@@ -1275,14 +1283,6 @@ type ClusterResourcePlacementList struct {
12751283
Items []ClusterResourcePlacement `json:"items"`
12761284
}
12771285

1278-
// Tolerations returns tolerations for ClusterResourcePlacement.
1279-
func (m *ClusterResourcePlacement) Tolerations() []Toleration {
1280-
if m.Spec.Policy != nil {
1281-
return m.Spec.Policy.Tolerations
1282-
}
1283-
return nil
1284-
}
1285-
12861286
// SetConditions sets the conditions of the ClusterResourcePlacement.
12871287
func (m *ClusterResourcePlacement) SetConditions(conditions ...metav1.Condition) {
12881288
for _, c := range conditions {

apis/placement/v1beta1/policysnapshot_types.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ type SchedulingPolicySnapshotSpec struct {
106106
PolicyHash []byte `json:"policyHash"`
107107
}
108108

109+
// Tolerations returns tolerations for SchedulingPolicySnapshotSpec to handle nil policy case.
110+
func (s *SchedulingPolicySnapshotSpec) Tolerations() []Toleration {
111+
if s.Policy != nil {
112+
return s.Policy.Tolerations
113+
}
114+
return nil
115+
}
116+
109117
// SchedulingPolicySnapshotStatus defines the observed state of SchedulingPolicySnapshot.
110118
type SchedulingPolicySnapshotStatus struct {
111119
// +patchMergeKey=type
@@ -191,14 +199,6 @@ type ClusterSchedulingPolicySnapshotList struct {
191199
Items []ClusterSchedulingPolicySnapshot `json:"items"`
192200
}
193201

194-
// Tolerations returns tolerations for ClusterSchedulingPolicySnapshot.
195-
func (m *ClusterSchedulingPolicySnapshot) Tolerations() []Toleration {
196-
if m.Spec.Policy != nil {
197-
return m.Spec.Policy.Tolerations
198-
}
199-
return nil
200-
}
201-
202202
// SetConditions sets the given conditions on the ClusterSchedulingPolicySnapshot.
203203
func (m *ClusterSchedulingPolicySnapshot) SetConditions(conditions ...metav1.Condition) {
204204
for _, c := range conditions {
@@ -284,14 +284,6 @@ type SchedulingPolicySnapshotList struct {
284284
Items []SchedulingPolicySnapshot `json:"items"`
285285
}
286286

287-
// Tolerations returns tolerations for ClusterSchedulingPolicySnapshot.
288-
func (m *SchedulingPolicySnapshot) Tolerations() []Toleration {
289-
if m.Spec.Policy != nil {
290-
return m.Spec.Policy.Tolerations
291-
}
292-
return nil
293-
}
294-
295287
// SetConditions sets the given conditions on the ClusterSchedulingPolicySnapshot.
296288
func (m *SchedulingPolicySnapshot) SetConditions(conditions ...metav1.Condition) {
297289
for _, c := range conditions {

pkg/scheduler/framework/plugins/tainttoleration/filtering.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (p *Plugin) Filter(
2323
policy placementv1beta1.PolicySnapshotObj,
2424
cluster *clusterv1beta1.MemberCluster,
2525
) (status *framework.Status) {
26-
taint, isUntolerated := findUntoleratedTaint(cluster.Spec.Taints, policy.GetPolicySnapshotSpec().Policy.Tolerations)
26+
taint, isUntolerated := findUntoleratedTaint(cluster.Spec.Taints, policy.GetPolicySnapshotSpec().Tolerations())
2727
if !isUntolerated {
2828
return nil
2929
}

pkg/scheduler/scheduler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,12 @@ func (s *Scheduler) lookupLatestPolicySnapshot(ctx context.Context, placement fl
360360
case len(policySnapshots) == 0:
361361
// There is no latest policy snapshot associated with the placement; it could happen when
362362
// * the placement is newly created; or
363-
// * the sequence of policy snapshots is in an inconsistent state.
363+
// * the new policy snapshots is in the middle of being replaced.
364364
//
365365
// Either way, it is out of the scheduler's scope to handle such a case; the scheduler will
366366
// be triggered again if the situation is corrected.
367-
err := controller.NewExpectedBehaviorError(fmt.Errorf("no latest policy snapshot associated with placement"))
368-
klog.ErrorS(err, "Failed to find the latest policy snapshot", "placement", placementRef)
367+
err := fmt.Errorf("no latest policy snapshot associated with placement")
368+
klog.ErrorS(err, "Failed to find the latest policy snapshot, will retry", "placement", placementRef)
369369
return nil, err
370370
case len(policySnapshots) > 1:
371371
// There are multiple active policy snapshots associated with the placement; normally this

pkg/webhook/clusterresourceplacement/v1beta1_clusterresourceplacement_validating_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (v *clusterResourcePlacementValidator) Handle(_ context.Context, req admiss
6666
return admission.Denied("placement type is immutable")
6767
}
6868
// handle update case where existing tolerations were updated/deleted
69-
if validator.IsTolerationsUpdatedOrDeleted(oldCRP.Tolerations(), crp.Tolerations()) {
69+
if validator.IsTolerationsUpdatedOrDeleted(oldCRP.Spec.Tolerations(), crp.Spec.Tolerations()) {
7070
return admission.Denied("tolerations have been updated/deleted, only additions to tolerations are allowed")
7171
}
7272
}

test/scheduler/suite_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,9 @@ func beforeSuiteForProcess1() []byte {
532532
klog.InitFlags(nil)
533533
Expect(flag.Set("v", "5")).To(Succeed(), "Failed to set verbosity flag")
534534
flag.Parse()
535-
klog.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true), zap.Level(zapcore.Level(-5))))
536-
535+
logger := zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true), zap.Level(zapcore.Level(-5)))
536+
klog.SetLogger(logger)
537+
ctrl.SetLogger(logger)
537538
By("bootstrapping the test environment")
538539
// Start the hub cluster.
539540
hubTestEnv = &envtest.Environment{

0 commit comments

Comments
 (0)