Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion providers/kubeconfig/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (p *Provider) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result
// Extract and validate kubeconfig data
kubeconfigData, ok := secret.Data[p.opts.KubeconfigSecretKey]
if !ok || len(kubeconfigData) == 0 {
log.Info("Secret does not contain kubeconfig data, skipping", "key", p.opts.KubeconfigSecretKey)
log.Error(nil, "Secret does not contain kubeconfig data, skipping", "key", p.opts.KubeconfigSecretKey)
return ctrl.Result{}, nil
}

Expand Down
50 changes: 50 additions & 0 deletions providers/kubeconfig/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,56 @@ var _ = Describe("Provider Namespace", Ordered, func() {
Eventually(provider.ListClusters, "10s").Should(HaveLen(2))
})

It("skips secrets that do not contain kubeconfig data", func() {
secretWithoutKubeconfig := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "invalid-secret",
Namespace: kubeconfigSecretNamespace,
Labels: map[string]string{
kubeconfigSecretLabel: "true",
},
},
Data: map[string][]byte{
"some-other-key": []byte("some-data"),
},
}
err := localCli.Create(ctx, secretWithoutKubeconfig)
Expect(err).NotTo(HaveOccurred())

// Verify the cluster count hasn't changed (secret was skipped)
Eventually(provider.ListClusters, "2s").Should(HaveLen(2))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not happy with doing Eventually then Consistently, but I found that provider.ListClusters was coming up empty and failing Consistently if I didn't add the Eventually first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It kind of makes sense since you might be checking the list before clusters have been processed and added. But I don't think we need the Consistently once Eventually has passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added Consistently to cover this case:

  1. Before the test starts, the provider processed the existing two secrets, so provider.ListClusters is sitting at length 2
  2. We add the bad secret
  3. Before the provider has a chance to pick up the bad secret, we assert that Eventually we have length 2
  4. The Eventually passes, and the test succeeds
  5. After the test passes, a bug in the provider allows the bad secret to be treated as a cluster, and provider.ListClusters goes to length 3

Consistently(provider.ListClusters, "2s").Should(HaveLen(2))

// Clean up
err = localCli.Delete(ctx, secretWithoutKubeconfig)
Expect(err).NotTo(HaveOccurred())
})

It("skips secrets with empty kubeconfig data", func() {
secretWithEmptyKubeconfig := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "empty-secret",
Namespace: kubeconfigSecretNamespace,
Labels: map[string]string{
kubeconfigSecretLabel: "true",
},
},
Data: map[string][]byte{
kubeconfigSecretKey: []byte(""),
},
}
err := localCli.Create(ctx, secretWithEmptyKubeconfig)
Expect(err).NotTo(HaveOccurred())

// Verify the cluster count hasn't changed (secret was skipped)
Eventually(provider.ListClusters, "2s").Should(HaveLen(2))
Consistently(provider.ListClusters, "2s").Should(HaveLen(2))

// Clean up
err = localCli.Delete(ctx, secretWithEmptyKubeconfig)
Expect(err).NotTo(HaveOccurred())
})

AfterAll(func() {
By("Stopping the provider, cluster, manager, and controller", func() {
cancel()
Expand Down