-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Fix unit tests, improve debuggability #3126
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,14 +59,21 @@ var _ = Describe("ProviderServiceAccount controller integration tests", func() { | |
helpers.CreateAndWait(ctx, intCtx.Client, intCtx.KubeconfigSecret) | ||
}) | ||
|
||
By("Verifying that the guest cluster client works") | ||
guestClient, err := tracker.GetClient(ctx, client.ObjectKeyFromObject(intCtx.Cluster)) | ||
Expect(err).ToNot(HaveOccurred()) | ||
// Note: Create a Service informer, so the test later doesn't fail if this doesn't work. | ||
Expect(guestClient.List(ctx, &corev1.ServiceList{}, client.InNamespace(metav1.NamespaceDefault))).To(Succeed()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Saw some errors in the logs. Not sure if the test failures are due to envtest not coming up (probalby not, but shouldn't hurt to have this explicit check here) |
||
|
||
pSvcAccount = getTestProviderServiceAccount(intCtx.Namespace, intCtx.VSphereCluster) | ||
createTestResource(ctx, intCtx.Client, pSvcAccount) | ||
assertEventuallyExistsInNamespace(ctx, intCtx.Client, intCtx.Namespace, pSvcAccount.GetName(), pSvcAccount) | ||
}) | ||
AfterEach(func() { | ||
// Deleting the provider service account is not strictly required as the context itself | ||
// gets teared down but keeping it for clarity. | ||
deleteTestResource(ctx, intCtx.Client, pSvcAccount) | ||
deleteTestResource(ctx, intCtx.Client, intCtx.VSphereCluster) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just some explicit cleanup. Deleting a namespace in testenv doesn't lead to all object in the namespace being deleted (there is no kube-controller-manager) |
||
deleteTestResource(ctx, intCtx.Client, intCtx.Cluster) | ||
deleteTestResource(ctx, intCtx.Client, intCtx.KubeconfigSecret) | ||
}) | ||
|
||
Context("When serviceaccount secret is created", func() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,8 @@ import ( | |
"k8s.io/apimachinery/pkg/util/wait" | ||
clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/component-base/logs" | ||
logsv1 "k8s.io/component-base/logs/api/v1" | ||
"k8s.io/klog/v2" | ||
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" | ||
"sigs.k8s.io/cluster-api/util/kubeconfig" | ||
|
@@ -60,7 +62,14 @@ import ( | |
) | ||
|
||
func init() { | ||
// Set log level 5 as default for testing (default for prod is 2). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log level 5 gives us more verbose logs of our controllers, but also a lot of useful logs from CR around Reconciles |
||
logOptions := logs.NewOptions() | ||
logOptions.Verbosity = 5 | ||
if err := logsv1.ValidateAndApply(logOptions, nil); err != nil { | ||
panic(err) | ||
} | ||
ctrl.SetLogger(klog.Background()) | ||
|
||
// add logger for ginkgo | ||
klog.SetOutput(ginkgo.GinkgoWriter) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just printing the ProviderServiceAccounts, this should make it easier to catch race conditions where there might not be any ProviderServiceAccounts