Skip to content

Commit d0853a5

Browse files
committed
fix the lint eror
Signed-off-by: Ryan Zhang <yangzhangrice@hotmail.com>
1 parent 1532d24 commit d0853a5

File tree

7 files changed

+22
-16
lines changed

7 files changed

+22
-16
lines changed

pkg/propertyprovider/azure/controllers/node.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ import (
2626
"k8s.io/apimachinery/pkg/api/errors"
2727
"k8s.io/klog/v2"
2828
ctrl "sigs.k8s.io/controller-runtime"
29-
"sigs.k8s.io/controller-runtime/pkg/builder"
3029
"sigs.k8s.io/controller-runtime/pkg/client"
31-
"sigs.k8s.io/controller-runtime/pkg/predicate"
3230

3331
"github.com/kubefleet-dev/kubefleet/pkg/propertyprovider/azure/trackers"
3432
)
@@ -95,6 +93,6 @@ func (r *NodeReconciler) SetupWithManager(mgr ctrl.Manager, controllerName strin
9593
// Reconcile any node changes (create, update, delete).
9694
return ctrl.NewControllerManagedBy(mgr).
9795
Named(controllerName).
98-
For(&corev1.Node{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
96+
For(&corev1.Node{}).
9997
Complete(r)
10098
}

pkg/propertyprovider/azure/provider.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,16 +473,13 @@ func (p *PropertyProvider) collectK8sVersion(_ context.Context, properties map[c
473473
// Check if we have a cached version that is still valid.
474474
p.k8sVersionMutex.RLock()
475475
if p.cachedK8sVersion != "" && now.Sub(p.cachedK8sVersionObservedTime) < k8sVersionCacheTTL {
476+
defer p.k8sVersionMutex.RUnlock()
476477
// Cache is still valid, use the cached version.
477-
cachedVersion := p.cachedK8sVersion
478-
cacheTime := p.cachedK8sVersionObservedTime
479-
p.k8sVersionMutex.RUnlock()
480-
481478
properties[propertyprovider.K8sVersionProperty] = clusterv1beta1.PropertyValue{
482-
Value: cachedVersion,
483-
ObservationTime: metav1.NewTime(cacheTime),
479+
Value: p.cachedK8sVersion,
480+
ObservationTime: metav1.NewTime(p.cachedK8sVersionObservedTime),
484481
}
485-
klog.V(2).InfoS("Using cached Kubernetes version", "version", cachedVersion, "cacheAge", now.Sub(cacheTime))
482+
klog.V(2).InfoS("Using cached Kubernetes version", "version", p.cachedK8sVersion, "cacheAge", now.Sub(p.cachedK8sVersionObservedTime))
486483
return
487484
}
488485
p.k8sVersionMutex.RUnlock()

pkg/propertyprovider/azure/provider_integration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import (
3939

4040
var (
4141
ignoreObservationTimeFieldInPropertyValue = cmpopts.IgnoreFields(clusterv1beta1.PropertyValue{}, "ObservationTime")
42-
ignoreK8sVersionProperty = cmpopts.IgnoreMapEntries(func(k clusterv1beta1.PropertyName, v clusterv1beta1.PropertyValue) bool {
43-
return k == propertyprovider.K8sVersionProperty
42+
ignoreNonDeterministicProperty = cmpopts.IgnoreMapEntries(func(k clusterv1beta1.PropertyName, v clusterv1beta1.PropertyValue) bool {
43+
return k == propertyprovider.K8sVersionProperty || k == propertyprovider.ClusterEntryPointProperty
4444
})
4545
)
4646

@@ -314,7 +314,7 @@ var (
314314
}
315315

316316
res := p.Collect(ctx)
317-
if diff := cmp.Diff(res, expectedRes, ignoreObservationTimeFieldInPropertyValue, ignoreK8sVersionProperty, cmpopts.EquateEmpty()); diff != "" {
317+
if diff := cmp.Diff(res, expectedRes, ignoreObservationTimeFieldInPropertyValue, ignoreNonDeterministicProperty, cmpopts.EquateEmpty()); diff != "" {
318318
return fmt.Errorf("property collection response (-got, +want):\n%s", diff)
319319
}
320320
return nil

pkg/propertyprovider/azure/provider_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,10 +949,14 @@ func TestCollectWithDisabledFeatures(t *testing.T) {
949949
isAvailableResourcesCollectionEnabled: tc.isAvailableResourcesCollectionEnabled,
950950
cachedK8sVersion: k8sversion,
951951
cachedK8sVersionObservedTime: time.Now(),
952+
clusterEntryPoint: "test-cluster",
952953
}
953954
tc.wantPropertyCollectionResponse.Properties[propertyprovider.K8sVersionProperty] = clusterv1beta1.PropertyValue{
954955
Value: k8sversion,
955956
}
957+
tc.wantPropertyCollectionResponse.Properties[propertyprovider.ClusterEntryPointProperty] = clusterv1beta1.PropertyValue{
958+
Value: "test-cluster",
959+
}
956960
res := p.Collect(ctx)
957961
if diff := cmp.Diff(res, tc.wantPropertyCollectionResponse, ignoreObservationTimeFieldInPropertyValue); diff != "" {
958962
t.Fatalf("Collect() property collection response diff (-got, +want):\n%s", diff)

pkg/scheduler/scheduler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ func NewScheduler(
100100

101101
// ScheduleOnce performs scheduling for one single item pulled from the work queue.
102102
// it returns true if the context is not canceled, false otherwise.
103+
//
104+
//lint:ignore SA1019 we need more time to fully migrate to RequeueAfter as we used these two fields separately.
103105
func (s *Scheduler) scheduleOnce(ctx context.Context, worker int) {
104106
// Retrieve the next item (name of a placement) from the work queue.
105107
//
@@ -228,7 +230,6 @@ func (s *Scheduler) scheduleOnce(ctx context.Context, worker int) {
228230
}
229231

230232
// Requeue if the scheduling cycle suggests so.
231-
//lint:ignore SA1019 we need more time to fully migrate to RequeueAfter as we used these two fields separately.
232233
if res.Requeue {
233234
if res.RequeueAfter > 0 {
234235
s.queue.AddAfter(placementKey, res.RequeueAfter)

pkg/utils/controller/controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ func (w *controller) processNextWorkItem(ctx context.Context) bool {
260260
return true
261261
}
262262

263+
//lint:ignore SA1019 we need more time to fully migrate to RequeueAfter as we used these two fields separately.
263264
func (w *controller) reconcileHandler(ctx context.Context, key interface{}) {
264265
// Update metrics after processing each item
265266
reconcileStartTS := time.Now()
@@ -284,7 +285,7 @@ func (w *controller) reconcileHandler(ctx context.Context, key interface{}) {
284285
w.queue.Forget(key)
285286
w.queue.AddAfter(key, result.RequeueAfter)
286287
metrics.FleetReconcileTotal.WithLabelValues(w.name, labelRequeueAfter).Inc()
287-
case result.RequeueAfter > 0:
288+
case result.Requeue:
288289
w.queue.AddRateLimited(key)
289290
metrics.FleetReconcileTotal.WithLabelValues(w.name, labelRequeue).Inc()
290291
default:

test/e2e/utils_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,15 @@ func checkIfAzurePropertyProviderIsWorking() {
312312
ignoreCostProperties := cmpopts.IgnoreMapEntries(func(k clusterv1beta1.PropertyName, v clusterv1beta1.PropertyValue) bool {
313313
return k == azure.PerCPUCoreCostProperty || k == azure.PerGBMemoryCostProperty
314314
})
315+
// we don't know the exact value of k8s version and cluster entry point
316+
ignoreClusterProperties := cmpopts.IgnoreMapEntries(func(k clusterv1beta1.PropertyName, v clusterv1beta1.PropertyValue) bool {
317+
return k == propertyprovider.K8sVersionProperty || k == propertyprovider.ClusterEntryPointProperty
318+
})
315319
if diff := cmp.Diff(
316320
mcObj.Status.Properties, wantStatus.Properties,
317321
ignoreTimeTypeFields,
318322
ignoreCostProperties,
323+
ignoreClusterProperties,
319324
); diff != "" {
320325
return fmt.Errorf("member cluster status properties diff (-got, +want):\n%s", diff)
321326
}
@@ -576,7 +581,7 @@ func cleanupInvalidClusters() {
576581
}
577582
Eventually(func() error {
578583
err := hubClient.Get(ctx, types.NamespacedName{Name: name}, mcObj)
579-
if err != nil {
584+
if err != nil && !k8serrors.IsNotFound(err) {
580585
return err
581586
}
582587
mcObj.Finalizers = []string{}

0 commit comments

Comments
 (0)