Skip to content

Commit ebc35bc

Browse files
committed
fix the lint error after bumping the version
Signed-off-by: Ryan Zhang <yangzhangrice@hotmail.com>
1 parent d924671 commit ebc35bc

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
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)

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)