Skip to content

Commit

Permalink
Merge pull request #339 from authzed/nstest
Browse files Browse the repository at this point in the history
Fix multi-namespace watches and add a test
  • Loading branch information
ecordell authored Nov 12, 2024
2 parents 24d60c6 + 7588971 commit 9ef69f8
Show file tree
Hide file tree
Showing 4 changed files with 454 additions and 177 deletions.
15 changes: 11 additions & 4 deletions pkg/cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

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

// register with metrics collector
spiceDBClusterMetrics := ctrlmetrics.NewConditionStatusCollector[*v1alpha1.SpiceDBCluster](o.MetricNamespace, "clusters", v1alpha1.SpiceDBClusterResourceName)
lister := typed.ListerFor[*v1alpha1.SpiceDBCluster](registry, typed.NewRegistryKey(controller.OwnedFactoryKey, v1alpha1ClusterGVR))
spiceDBClusterMetrics.AddListerBuilder(func() ([]*v1alpha1.SpiceDBCluster, error) {
return lister.List(labels.Everything())
})

if len(o.WatchNamespaces) == 0 {
o.WatchNamespaces = []string{corev1.NamespaceAll}
}
for _, n := range o.WatchNamespaces {
lister := typed.MustListerForKey[*v1alpha1.SpiceDBCluster](registry, typed.NewRegistryKey(controller.OwnedFactoryKey(n), v1alpha1ClusterGVR))
spiceDBClusterMetrics.AddListerBuilder(func() ([]*v1alpha1.SpiceDBCluster, error) {
return lister.List(labels.Everything())
})
}
legacyregistry.CustomMustRegister(spiceDBClusterMetrics)

if ctx.Err() != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
var (
QueueOps = queue.NewQueueOperationsCtx()
CtxOperatorConfig = typedctx.WithDefault[*config.OperatorConfig](nil)
CtxCacheNamespace = typedctx.WithDefault("")
CtxClusterNN = typedctx.WithDefault(types.NamespacedName{})
CtxSecretNN = typedctx.WithDefault(types.NamespacedName{})
CtxSecret = typedctx.WithDefault[*corev1.Secret](nil)
Expand Down
Loading

0 comments on commit 9ef69f8

Please sign in to comment.