Skip to content
This repository was archived by the owner on Jul 28, 2026. It is now read-only.
Merged
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 pkg/operator/build_hierarchy.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func buildSecrets(ctx context.Context, cli client.Client, deploy config.Deployme
case *corev1.Secret:
rawValue, ok := o.Data[ref.Reference.Secret.Key]
if !ok {
return fmt.Errorf("no key %s in Secret %s", ref.Reference.ConfigMap.Key, o.Name)
return fmt.Errorf("no key %s in Secret %s", ref.Reference.Secret.Key, o.Name)
}
value = string(rawValue)
case *corev1.ConfigMap:
Expand Down
27 changes: 26 additions & 1 deletion pkg/operator/build_hierarchy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import (
"github.com/stretchr/testify/require"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
controller "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

// Test_buildHierarchy checks that an entire resource hierarchy can be
Expand All @@ -34,7 +36,7 @@ func Test_buildHierarchy(t *testing.T) {

l := util.TestLogger(t)
cluster := NewTestCluster(ctx, t, l)
cli := cluster.Client()
cli := newTestControllerClient(t, cluster)

resources := k8s.NewResourceSet(l, cluster)
defer resources.Stop()
Expand Down Expand Up @@ -164,3 +166,26 @@ func (w *resourceWalker) Visit(v interface{}) (next structwalk.Visitor) {
}
return w
}

// newTestControllerClient creates a Kubernetes client which uses a cache and
// index for retrieving objects. This more closely matches the behavior of the
// operator instead of using cluster.Client, which lacks a cache and always
// communicates directly with Kubernetes.
func newTestControllerClient(t *testing.T, cluster *k8s.Cluster) client.Client {
t.Helper()

ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

mgr, err := controller.NewManager(cluster.GetConfig(), manager.Options{
Scheme: cluster.Client().Scheme(),
})
require.NoError(t, err)

go func() {
require.NoError(t, mgr.Start(ctx))
}()
require.True(t, mgr.GetCache().WaitForCacheSync(ctx))

return mgr.GetClient()
}
2 changes: 0 additions & 2 deletions pkg/operator/hierarchy/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -79,7 +78,6 @@ var _ Selector = (*KeySelector)(nil)
// ApplyToList implements Selector.
func (ks *KeySelector) ApplyToList(lo *client.ListOptions) {
lo.Namespace = ks.Namespace
lo.FieldSelector = fields.OneTermEqualSelector("metadata.name", ks.Name)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(Note that Matches below already performs filtering of the objects so we don't need to do anything other than remove the selector here)

}

// Matches implements Selector.
Expand Down