Skip to content

Commit 4c9a736

Browse files
committed
fix the e2e test and add cadata
Signed-off-by: Ryan Zhang <[email protected]>
1 parent 1985d16 commit 4c9a736

File tree

7 files changed

+92
-57
lines changed

7 files changed

+92
-57
lines changed

pkg/propertyprovider/azure/provider.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package azure
1919

2020
import (
2121
"context"
22+
"encoding/base64"
2223
"fmt"
2324
"sync"
2425
"time"
@@ -112,6 +113,10 @@ type PropertyProvider struct {
112113
// Cached cluster entry point.
113114
clusterEntryPoint string
114115
clusterEntryPointObservedTime time.Time
116+
117+
// Cached cluster certificate authority data (base64 encoded).
118+
clusterCertificateAuthority string
119+
clusterCertificateAuthorityObservedTime time.Time
115120
}
116121

117122
// Verify that the Azure property provider implements the MetricProvider interface at compile time.
@@ -253,6 +258,15 @@ func (p *PropertyProvider) Start(ctx context.Context, config *rest.Config) error
253258
p.clusterEntryPoint = config.Host
254259
p.clusterEntryPointObservedTime = time.Now()
255260

261+
// Cache the cluster certificate authority data (base64 encoded).
262+
if len(config.CAData) > 0 {
263+
p.clusterCertificateAuthority = base64.StdEncoding.EncodeToString(config.CAData)
264+
p.clusterCertificateAuthorityObservedTime = time.Now()
265+
klog.V(2).Info("Cached cluster certificate authority data")
266+
} else {
267+
klog.V(2).Info("No certificate authority data available in rest.Config")
268+
}
269+
256270
// Set up the node reconciler.
257271
klog.V(2).Info("Setting up the node reconciler")
258272
nodeReconciler := &controllers.NodeReconciler{
@@ -345,10 +359,20 @@ func (p *PropertyProvider) Collect(ctx context.Context) propertyprovider.Propert
345359
p.collectAvailableResource(ctx, &resources)
346360
}
347361

348-
// insert the cluster entry point property
349-
properties[propertyprovider.ClusterEntryPointProperty] = clusterv1beta1.PropertyValue{
350-
Value: p.clusterEntryPoint,
351-
ObservationTime: metav1.NewTime(p.clusterEntryPointObservedTime),
362+
// insert the cluster entry point property (if available)
363+
if p.clusterEntryPoint != "" {
364+
properties[propertyprovider.ClusterEntryPointProperty] = clusterv1beta1.PropertyValue{
365+
Value: p.clusterEntryPoint,
366+
ObservationTime: metav1.NewTime(p.clusterEntryPointObservedTime),
367+
}
368+
}
369+
370+
// insert the cluster certificate authority property (if available)
371+
if p.clusterCertificateAuthority != "" {
372+
properties[propertyprovider.ClusterCertificateAuthorityProperty] = clusterv1beta1.PropertyValue{
373+
Value: p.clusterCertificateAuthority,
374+
ObservationTime: metav1.NewTime(p.clusterCertificateAuthorityObservedTime),
375+
}
352376
}
353377

354378
// Return the collection response.

pkg/propertyprovider/azure/provider_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
var (
4141
ignoreObservationTimeFieldInPropertyValue = cmpopts.IgnoreFields(clusterv1beta1.PropertyValue{}, "ObservationTime")
4242
ignoreNonDeterministicProperty = cmpopts.IgnoreMapEntries(func(k clusterv1beta1.PropertyName, v clusterv1beta1.PropertyValue) bool {
43-
return k == propertyprovider.K8sVersionProperty || k == propertyprovider.ClusterEntryPointProperty
43+
return k == propertyprovider.K8sVersionProperty || k == propertyprovider.ClusterEntryPointProperty || k == propertyprovider.ClusterCertificateAuthorityProperty
4444
})
4545
)
4646

pkg/propertyprovider/commons.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ const (
3030
// ClusterEntryPointProperty is a property that describes the cluster entry point (API server endpoint).
3131
ClusterEntryPointProperty = "k8s.io/cluster-entrypoint"
3232

33+
// ClusterCertificateAuthorityProperty is a property that describes the cluster's certificate authority data (base64 encoded).
34+
ClusterCertificateAuthorityProperty = "k8s.io/cluster-certificate-authority-data"
35+
3336
// The resource properties.
3437
// Total and allocatable CPU resource properties.
3538
TotalCPUCapacityProperty = "resources.kubernetes-fleet.io/total-cpu"

pkg/scheduler/scheduler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ func (s *Scheduler) scheduleOnce(ctx context.Context, worker int) {
228228
}
229229

230230
// Requeue if the scheduling cycle suggests so.
231-
if res.Requeue { //nolint:golint //no lint SA1019 we need more time to fully migrate to RequeueAfter as we used these two fields separately.
231+
//nolint:staticcheck
232+
//lint:ignore SA1019 we need more time to fully migrate to RequeueAfter as we used these two fields separately.
233+
if res.Requeue {
232234
if res.RequeueAfter > 0 {
233235
s.queue.AddAfter(placementKey, res.RequeueAfter)
234236
observeSchedulingCycleMetrics(cycleStartTime, false, true)

pkg/utils/controller/controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ func (w *controller) reconcileHandler(ctx context.Context, key interface{}) {
284284
w.queue.Forget(key)
285285
w.queue.AddAfter(key, result.RequeueAfter)
286286
metrics.FleetReconcileTotal.WithLabelValues(w.name, labelRequeueAfter).Inc()
287-
case result.Requeue: //nolint:golint // SA1019 we need more time to fully migrate to RequeueAfter as we used these two fields separately.
287+
//nolint:staticcheck
288+
//lint:ignore SA1019 we need more time to fully migrate to RequeueAfter as we used these two fields separately.
289+
case result.Requeue:
288290
w.queue.AddRateLimited(key)
289291
metrics.FleetReconcileTotal.WithLabelValues(w.name, labelRequeue).Inc()
290292
default:

test/e2e/join_and_leave_test.go

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -479,61 +479,65 @@ var _ = Describe("Test member cluster join and leave without placement", Label("
479479

480480
var _ = Describe("Test member cluster join and leave with clusterProfile", Label("joinleave"), Ordered, Serial, func() {
481481
clusterProfileList := &clusterinventory.ClusterProfileList{}
482-
483-
It("Make sure we have all the cluster profiles", func() {
484-
Eventually(func() error {
485-
if err := hubClient.List(ctx, clusterProfileList, &client.ListOptions{Namespace: utils.FleetSystemNamespace}); err != nil {
486-
return fmt.Errorf("failed to get cluster profiles: %w", err)
487-
}
488-
489-
// create a map for easy lookup
490-
cpMap := make(map[string]clusterinventory.ClusterProfile)
491-
for idx := range clusterProfileList.Items {
492-
cp := clusterProfileList.Items[idx]
493-
cpMap[cp.Name] = cp
494-
}
495-
// make sure all the member clusters have a cluster profile
496-
for idx := range allMemberClusterNames {
497-
cp, ok := cpMap[allMemberClusterNames[idx]]
498-
if !ok {
499-
return fmt.Errorf("cluster profile for member cluster %s not found", allMemberClusterNames[idx])
482+
Context("Test cluster profile and ", Label("joinleave"), Ordered, Serial, func() {
483+
It("Make sure we have all the cluster profiles", func() {
484+
Eventually(func() error {
485+
if err := hubClient.List(ctx, clusterProfileList, &client.ListOptions{Namespace: utils.FleetSystemNamespace}); err != nil {
486+
return fmt.Errorf("failed to get cluster profiles: %w", err)
500487
}
501-
if cp.Status.Version.Kubernetes == "" {
502-
return fmt.Errorf("cluster profile %s Kubernetes version should not be empty", cp.Name)
503-
}
504-
if len(cp.Status.AccessProviders) != 1 {
505-
return fmt.Errorf("cluster profile %s has no access providers %+v", cp.Name, cp.Status.AccessProviders)
506-
}
507-
if cp.Status.AccessProviders[0].Name != controller.ClusterManagerName {
508-
return fmt.Errorf("cluster profile %s access provider name %s doesn't match expected %s", cp.Name, cp.Status.AccessProviders[0].Name, controller.ClusterManagerName)
488+
489+
// create a map for easy lookup
490+
cpMap := make(map[string]clusterinventory.ClusterProfile)
491+
for idx := range clusterProfileList.Items {
492+
cp := clusterProfileList.Items[idx]
493+
cpMap[cp.Name] = cp
509494
}
510-
if cp.Status.AccessProviders[0].Cluster.Server == "" {
511-
return fmt.Errorf("cluster profile %s access provider server should not be empty", allMemberClusterNames[idx])
495+
// make sure all the member clusters have a cluster profile
496+
for idx := range allMemberClusterNames {
497+
cp, ok := cpMap[allMemberClusterNames[idx]]
498+
if !ok {
499+
return fmt.Errorf("cluster profile for member cluster %s not found", allMemberClusterNames[idx])
500+
}
501+
if cp.Status.Version.Kubernetes == "" {
502+
return fmt.Errorf("cluster profile %s Kubernetes version should not be empty", cp.Name)
503+
}
504+
if len(cp.Status.AccessProviders) != 1 {
505+
return fmt.Errorf("cluster profile %s has no access providers %+v", cp.Name, cp.Status.AccessProviders)
506+
}
507+
if cp.Status.AccessProviders[0].Name != controller.ClusterManagerName {
508+
return fmt.Errorf("cluster profile %s access provider name %s doesn't match expected %s", cp.Name, cp.Status.AccessProviders[0].Name, controller.ClusterManagerName)
509+
}
510+
if cp.Status.AccessProviders[0].Cluster.Server == "" {
511+
return fmt.Errorf("cluster profile %s access provider server should not be empty", allMemberClusterNames[idx])
512+
}
513+
if len(cp.Status.AccessProviders[0].Cluster.CertificateAuthorityData) == 0 {
514+
return fmt.Errorf("cluster profile %s access provider certificate authority data should not be empty", allMemberClusterNames[idx])
515+
}
512516
}
513-
}
514-
return nil
515-
}, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to verify cluster profiles")
516-
})
517+
return nil
518+
}, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to verify cluster profiles")
519+
})
517520

518-
It("Delete member cluster CR associated to the member cluster to simulate member left", func() {
519-
var mc clusterv1beta1.MemberCluster
520-
Expect(hubClient.Get(ctx, types.NamespacedName{Name: memberCluster3WestProdName}, &mc)).To(Succeed(), "Failed to get member cluster")
521-
Expect(hubClient.Delete(ctx, &mc)).Should(Succeed())
522-
})
521+
It("Delete member cluster CR associated to the member cluster to simulate member left", func() {
522+
var mc clusterv1beta1.MemberCluster
523+
Expect(hubClient.Get(ctx, types.NamespacedName{Name: memberCluster3WestProdName}, &mc)).To(Succeed(), "Failed to get member cluster")
524+
Expect(hubClient.Delete(ctx, &mc)).Should(Succeed())
525+
})
523526

524-
It("Make sure we delete the corresponding cluster profiles", func() {
525-
Eventually(func() error {
526-
if err := hubClient.List(ctx, clusterProfileList, &client.ListOptions{Namespace: utils.FleetSystemNamespace}); err != nil {
527-
return fmt.Errorf("failed to get cluster profiles: %w", err)
528-
}
529-
for idx := range clusterProfileList.Items {
530-
cp := clusterProfileList.Items[idx]
531-
if cp.Name == memberCluster3WestProdName {
532-
return fmt.Errorf("cluster profile for member cluster %s should be deleted", memberCluster3WestProdName)
527+
It("Make sure we delete the corresponding cluster profiles", func() {
528+
Eventually(func() error {
529+
if err := hubClient.List(ctx, clusterProfileList, &client.ListOptions{Namespace: utils.FleetSystemNamespace}); err != nil {
530+
return fmt.Errorf("failed to get cluster profiles: %w", err)
533531
}
534-
}
535-
return nil
536-
}, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to verify cluster profiles")
532+
for idx := range clusterProfileList.Items {
533+
cp := clusterProfileList.Items[idx]
534+
if cp.Name == memberCluster3WestProdName {
535+
return fmt.Errorf("cluster profile for member cluster %s should be deleted", memberCluster3WestProdName)
536+
}
537+
}
538+
return nil
539+
}, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to verify cluster profiles")
540+
})
537541
})
538542

539543
AfterAll(func() {

test/e2e/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func checkIfAzurePropertyProviderIsWorking() {
314314
})
315315
// we don't know the exact value of k8s version and cluster entry point
316316
ignoreClusterProperties := cmpopts.IgnoreMapEntries(func(k clusterv1beta1.PropertyName, v clusterv1beta1.PropertyValue) bool {
317-
return k == propertyprovider.K8sVersionProperty || k == propertyprovider.ClusterEntryPointProperty
317+
return k == propertyprovider.K8sVersionProperty || k == propertyprovider.ClusterEntryPointProperty || k == propertyprovider.ClusterCertificateAuthorityProperty
318318
})
319319
if diff := cmp.Diff(
320320
mcObj.Status.Properties, wantStatus.Properties,

0 commit comments

Comments
 (0)