Skip to content

Commit 9ef69f8

Browse files
authored
Merge pull request #339 from authzed/nstest
Fix multi-namespace watches and add a test
2 parents 24d60c6 + 7588971 commit 9ef69f8

File tree

4 files changed

+454
-177
lines changed

4 files changed

+454
-177
lines changed

pkg/cmd/run/run.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55

66
"github.com/spf13/cobra"
7+
corev1 "k8s.io/api/core/v1"
78
"k8s.io/apimachinery/pkg/labels"
89
"k8s.io/apimachinery/pkg/util/errors"
910
genericapiserver "k8s.io/apiserver/pkg/server"
@@ -160,10 +161,16 @@ func (o *Options) Run(ctx context.Context, f cmdutil.Factory) error {
160161

161162
// register with metrics collector
162163
spiceDBClusterMetrics := ctrlmetrics.NewConditionStatusCollector[*v1alpha1.SpiceDBCluster](o.MetricNamespace, "clusters", v1alpha1.SpiceDBClusterResourceName)
163-
lister := typed.ListerFor[*v1alpha1.SpiceDBCluster](registry, typed.NewRegistryKey(controller.OwnedFactoryKey, v1alpha1ClusterGVR))
164-
spiceDBClusterMetrics.AddListerBuilder(func() ([]*v1alpha1.SpiceDBCluster, error) {
165-
return lister.List(labels.Everything())
166-
})
164+
165+
if len(o.WatchNamespaces) == 0 {
166+
o.WatchNamespaces = []string{corev1.NamespaceAll}
167+
}
168+
for _, n := range o.WatchNamespaces {
169+
lister := typed.MustListerForKey[*v1alpha1.SpiceDBCluster](registry, typed.NewRegistryKey(controller.OwnedFactoryKey(n), v1alpha1ClusterGVR))
170+
spiceDBClusterMetrics.AddListerBuilder(func() ([]*v1alpha1.SpiceDBCluster, error) {
171+
return lister.List(labels.Everything())
172+
})
173+
}
167174
legacyregistry.CustomMustRegister(spiceDBClusterMetrics)
168175

169176
if ctx.Err() != nil {

pkg/controller/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
var (
1717
QueueOps = queue.NewQueueOperationsCtx()
1818
CtxOperatorConfig = typedctx.WithDefault[*config.OperatorConfig](nil)
19+
CtxCacheNamespace = typedctx.WithDefault("")
1920
CtxClusterNN = typedctx.WithDefault(types.NamespacedName{})
2021
CtxSecretNN = typedctx.WithDefault(types.NamespacedName{})
2122
CtxSecret = typedctx.WithDefault[*corev1.Secret](nil)

0 commit comments

Comments
 (0)