Skip to content

Commit e43ce71

Browse files
authored
Fix bug preventing resource reconciliation due to "Secret not cached" (#4966)
This was caused by PR #4857 setting ReaderFailOnMissingInformer. It happens only if the CRDs installed via crdPattern do not include a resource which requires a Secret informer. This issue was missed in our testing because we generally run with a full (or close to full) set of CRDs installed, but the problem only appears with a minimal subset installed. Fixes #4926.
1 parent 53b024e commit e43ce71

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

v2/cmd/controller/app/setup.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ func initializeClients(cfg config.Values, mgr ctrl.Manager) (*clients, error) {
416416

417417
armClientCache := armreconciler.NewARMClientCache(
418418
credentialProvider,
419-
kubeClient,
420419
cfg.Cloud(),
421420
nil,
422421
armMetrics)

v2/internal/reconcilers/arm/arm_client_cache.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
1616
"github.com/Azure/azure-service-operator/v2/internal/identity"
1717
"github.com/Azure/azure-service-operator/v2/internal/metrics"
18-
"github.com/Azure/azure-service-operator/v2/internal/util/kubeclient"
1918
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
2019
)
2120

@@ -26,14 +25,12 @@ type ARMClientCache struct {
2625
clients map[string]*armClient
2726
cloudConfig cloud.Configuration
2827
credentialProvider identity.CredentialProvider
29-
kubeClient kubeclient.Client
3028
httpClient *http.Client
3129
armMetrics *metrics.ARMClientMetrics
3230
}
3331

3432
func NewARMClientCache(
3533
credentialProvider identity.CredentialProvider,
36-
kubeClient kubeclient.Client,
3734
configuration cloud.Configuration,
3835
httpClient *http.Client,
3936
armMetrics *metrics.ARMClientMetrics,
@@ -42,7 +39,6 @@ func NewARMClientCache(
4239
lock: sync.Mutex{},
4340
clients: make(map[string]*armClient),
4441
cloudConfig: configuration,
45-
kubeClient: kubeClient,
4642
credentialProvider: credentialProvider,
4743
httpClient: httpClient,
4844
armMetrics: armMetrics,

v2/internal/reconcilers/arm/arm_client_cache_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func NewTestARMClientCache(client kubeclient.Client) (*ARMClientCache, error) {
6969
return nil, err
7070
}
7171

72-
return NewARMClientCache(credentialProvider, client, cfg.Cloud(), nil, metrics.NewARMClientMetrics()), nil
72+
return NewARMClientCache(credentialProvider, cfg.Cloud(), nil, metrics.NewARMClientMetrics()), nil
7373
}
7474

7575
type testResources struct {
@@ -113,7 +113,7 @@ func Test_DefaultCredential_NotSet_ReturnsErrorWhenTryToUseGlobalCredential(t *t
113113
g.Expect(err).To(BeNil())
114114

115115
providerWithNoDefaultCred := identity.NewCredentialProvider(nil, kubeClient, nil)
116-
clientWithNoDefaultCred := NewARMClientCache(providerWithNoDefaultCred, kubeClient, cfg.Cloud(), nil, metrics.NewARMClientMetrics())
116+
clientWithNoDefaultCred := NewARMClientCache(providerWithNoDefaultCred, cfg.Cloud(), nil, metrics.NewARMClientMetrics())
117117

118118
rg := newResourceGroup("")
119119

v2/internal/reconcilers/generic/register.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
kerrors "k8s.io/apimachinery/pkg/util/errors"
2323
ctrl "sigs.k8s.io/controller-runtime"
2424
ctrlbuilder "sigs.k8s.io/controller-runtime/pkg/builder"
25+
"sigs.k8s.io/controller-runtime/pkg/cache"
2526
"sigs.k8s.io/controller-runtime/pkg/client"
2627
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
2728
"sigs.k8s.io/controller-runtime/pkg/controller"
@@ -100,6 +101,21 @@ func RegisterAll(
100101
}
101102
}
102103

104+
// Start informer for secrets. Not all ASO resources have registered for events from secrets, but we always need the ability
105+
// to read secrets as at the very least we need to check for the aso-credential secret at the root of the resource namespace.
106+
// This ensures the cache is populated since ReaderFailOnMissingInformer is true.
107+
secretGVK := schema.GroupVersionKind{
108+
Group: "",
109+
Version: "v1",
110+
Kind: "Secret",
111+
}
112+
mgr.GetLogger().V(Info).Info("Registering informer for type", "type", secretGVK.String())
113+
// We don't need to block until synced, we just want to make sure the informer is going to start
114+
_, err := mgr.GetCache().GetInformerForKind(context.Background(), secretGVK, cache.BlockUntilSynced(false))
115+
if err != nil {
116+
return eris.Wrapf(err, "failed to start informer for secrets")
117+
}
118+
103119
var errs []error
104120
for _, obj := range objs {
105121
// TODO: Consider pulling some of the construction of things out of register (gvk, etc), so that we can pass in just

v2/internal/testcommon/kube_test_context_envtest.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@ func createEnvtestContext() (BaseTestContextFactory, context.CancelFunc) {
543543
// register resources needed by controller for namespace
544544
armClientCache := arm.NewARMClientCache(
545545
credentialProvider,
546-
envtest.KubeClient,
547546
cfg.Cloud(),
548547
perTestContext.HTTPClient,
549548
metrics.NewARMClientMetrics())

0 commit comments

Comments
 (0)