Skip to content

Commit 24d3da2

Browse files
committed
pkg/kube: require namespace in Ctl.List
`client.Client` and `kube.Ctl` treated `namespace` (`client.InNamespace`) as an optional parameter. If not provided, it default to `"default"`. This parameter has been missed multiple times across various places in our codebase and resulted in latent errors, often because tests utilised the default namespace. This commit changes the signature of `Ctl.List` to require a `namespace string` parameter to make it impossible to forget. It additionally adds it to a few places (lifecycle client) that it was previously forgotten. (cherry picked from commit 9e08d14) # Conflicts: # charts/redpanda/chart_test.go # go.work.sum # operator/internal/controller/vectorized/cluster_controller_test.go # operator/internal/lifecycle/client.go # pkg/kube/ctl.go # pkg/kube/syncer.go # pkg/kube/syncer_test.go
1 parent 3c5ad97 commit 24d3da2

File tree

12 files changed

+67
-73
lines changed

12 files changed

+67
-73
lines changed

acceptance/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ require (
197197
github.com/redpanda-data/console/backend v0.0.0-20240303221210-05d5d9e85f20 // indirect
198198
github.com/redpanda-data/redpanda-operator/charts/connectors v0.0.0-20250407180246-dc814fb6b3b8 // indirect
199199
github.com/redpanda-data/redpanda-operator/charts/console v0.0.0-20250407180246-dc814fb6b3b8 // indirect
200-
github.com/redpanda-data/redpanda-operator/charts/redpanda/v5 v5.10.5-0.20250813202210-1c00a87f10f7 // indirect
200+
github.com/redpanda-data/redpanda-operator/charts/redpanda/v5 v5.10.5-0.20251002202632-d355ad0b3ce5 // indirect
201201
github.com/redpanda-data/redpanda-operator/gotohelm v1.1.0 // indirect
202202
github.com/redpanda-data/redpanda/src/go/rpk v0.0.0-20250716004441-6e1647296ad6 // indirect
203203
github.com/rivo/uniseg v0.4.7 // indirect

acceptance/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,8 @@ github.com/redpanda-data/redpanda-operator/charts/console v0.0.0-20250407180246-
732732
github.com/redpanda-data/redpanda-operator/charts/console v0.0.0-20250407180246-dc814fb6b3b8/go.mod h1:Sof2HY8U+RLesHJInGLoqhUMzN8iN8gUHXALbROsew8=
733733
github.com/redpanda-data/redpanda-operator/charts/console/v3 v3.1.0 h1:6jvBn+Xr1+62BEFSHoKxayRM/Xt9hp6O5nhnE368ge4=
734734
github.com/redpanda-data/redpanda-operator/charts/console/v3 v3.1.0/go.mod h1:y/8tR/cBC11uDPvjosxT8DAxnuSlPWtEzVYeCAqa4K4=
735-
github.com/redpanda-data/redpanda-operator/charts/redpanda/v5 v5.10.5-0.20250813202210-1c00a87f10f7 h1:D7ME2mDh8/e14VEAj0cIZQfVgyuluHz8Nw9yhZbcKVo=
736-
github.com/redpanda-data/redpanda-operator/charts/redpanda/v5 v5.10.5-0.20250813202210-1c00a87f10f7/go.mod h1:D8MfzGr+oPWOUNnDEezKSJyHRKvDpGb6NZS0bJdQnds=
735+
github.com/redpanda-data/redpanda-operator/charts/redpanda/v5 v5.10.5-0.20251002202632-d355ad0b3ce5 h1:ufNv+fxroH5WgVhw7346XmZg/lLj0rncnz+qbTRWHNM=
736+
github.com/redpanda-data/redpanda-operator/charts/redpanda/v5 v5.10.5-0.20251002202632-d355ad0b3ce5/go.mod h1:D8MfzGr+oPWOUNnDEezKSJyHRKvDpGb6NZS0bJdQnds=
737737
github.com/redpanda-data/redpanda-operator/gotohelm v1.1.0 h1:IV2Ic66JDKPtCnNU4Kn1naJlzZmhl0izRj17qgTCo20=
738738
github.com/redpanda-data/redpanda-operator/gotohelm v1.1.0/go.mod h1:usCpPzzzhgtPrRTiUQOzFqGmukce8U0SrzEeX2ONDFE=
739739
github.com/redpanda-data/redpanda/src/go/rpk v0.0.0-20250716004441-6e1647296ad6 h1:SbcvWTYFEbH5+NQOl1To5jppEa8RCK1HAkRNfhdUGLg=

charts/console/client_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ func NewClient(ctx context.Context, kubeCtl *kube.Ctl, dot *helmette.Dot) (*Clie
7272
}
7373

7474
func (c *Client) getConsolePod(ctx context.Context) (*corev1.Pod, error) {
75-
deploys, err := kube.List[appsv1.DeploymentList](ctx, c.Ctl,
76-
k8sclient.InNamespace(c.Release.Namespace),
77-
)
75+
deploys, err := kube.List[appsv1.DeploymentList](ctx, c.Ctl, c.Release.Namespace)
7876
if err != nil {
7977
return nil, err
8078
}
@@ -92,7 +90,7 @@ func (c *Client) getConsolePod(ctx context.Context) (*corev1.Pod, error) {
9290
}
9391

9492
pods, err := kube.List[corev1.PodList](ctx, c.Ctl,
95-
k8sclient.InNamespace(deployment.Namespace),
93+
deployment.Namespace,
9694
k8sclient.MatchingLabels(deployment.Spec.Selector.MatchLabels))
9795
if err != nil {
9896
return nil, err

charts/redpanda/chart_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func TestIntegrationChart(t *testing.T) {
165165
}),
166166
})
167167

168-
pods, err := kube.List[corev1.PodList](ctx, env.Ctl(), client.MatchingLabels{
168+
pods, err := kube.List[corev1.PodList](ctx, env.Ctl(), release.Namespace, client.MatchingLabels{
169169
"app.kubernetes.io/instance": release.Name,
170170
"app.kubernetes.io/component": release.Chart + "-statefulset",
171171
})
@@ -430,7 +430,7 @@ func TestIntegrationChart(t *testing.T) {
430430
}),
431431
})
432432

433-
pods, err := kube.List[corev1.PodList](ctx, env.Ctl(), client.MatchingLabels{
433+
pods, err := kube.List[corev1.PodList](ctx, env.Ctl(), release.Namespace, client.MatchingLabels{
434434
"app.kubernetes.io/instance": release.Name,
435435
"app.kubernetes.io/component": release.Chart + "-statefulset",
436436
})

charts/redpanda/client/client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/twmb/franz-go/pkg/sasl/scram"
2929
"github.com/twmb/franz-go/pkg/sr"
3030
corev1 "k8s.io/api/core/v1"
31-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3231
"sigs.k8s.io/controller-runtime/pkg/client"
3332

3433
"github.com/redpanda-data/redpanda-operator/charts/redpanda/v25"
@@ -496,9 +495,9 @@ func srvLookup(dot *helmette.Dot, dialer DialContextFunc, service string) ([]*ne
496495
// Querying for k8s-app=kube-dns is a generally accepted / safe
497496
// way of finding the kube DNS. We could alternatively find the
498497
// kube-dns service and use its label selector.
499-
pods, err := kube.List[corev1.PodList](ctx, ctl, client.MatchingLabels{
498+
pods, err := kube.List[corev1.PodList](ctx, ctl, kube.NamespaceSystem, client.MatchingLabels{
500499
"k8s-app": "kube-dns",
501-
}, client.InNamespace(metav1.NamespaceSystem))
500+
})
502501
if err != nil {
503502
return nil, err
504503
}

gen/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ github.com/redpanda-data/redpanda-operator/charts/connectors v0.0.0-202504071802
468468
github.com/redpanda-data/redpanda-operator/charts/connectors v0.0.0-20250407180246-dc814fb6b3b8/go.mod h1:o6FEj/SPoAxl6Rn1X9+XO1tlzSl2V64vAiBDgHntfVc=
469469
github.com/redpanda-data/redpanda-operator/charts/console v0.0.0-20250407180246-dc814fb6b3b8 h1:HIkLbEDKeCALHFytZdHfeWYo/9JMa1yh4QlsIlhlsB8=
470470
github.com/redpanda-data/redpanda-operator/charts/console v0.0.0-20250407180246-dc814fb6b3b8/go.mod h1:Sof2HY8U+RLesHJInGLoqhUMzN8iN8gUHXALbROsew8=
471-
github.com/redpanda-data/redpanda-operator/charts/redpanda/v5 v5.10.5-0.20250813202210-1c00a87f10f7 h1:D7ME2mDh8/e14VEAj0cIZQfVgyuluHz8Nw9yhZbcKVo=
472-
github.com/redpanda-data/redpanda-operator/charts/redpanda/v5 v5.10.5-0.20250813202210-1c00a87f10f7/go.mod h1:D8MfzGr+oPWOUNnDEezKSJyHRKvDpGb6NZS0bJdQnds=
471+
github.com/redpanda-data/redpanda-operator/charts/redpanda/v5 v5.10.5-0.20251002202632-d355ad0b3ce5 h1:ufNv+fxroH5WgVhw7346XmZg/lLj0rncnz+qbTRWHNM=
472+
github.com/redpanda-data/redpanda-operator/charts/redpanda/v5 v5.10.5-0.20251002202632-d355ad0b3ce5/go.mod h1:D8MfzGr+oPWOUNnDEezKSJyHRKvDpGb6NZS0bJdQnds=
473473
github.com/redpanda-data/redpanda-operator/gotohelm v1.1.0 h1:IV2Ic66JDKPtCnNU4Kn1naJlzZmhl0izRj17qgTCo20=
474474
github.com/redpanda-data/redpanda-operator/gotohelm v1.1.0/go.mod h1:usCpPzzzhgtPrRTiUQOzFqGmukce8U0SrzEeX2ONDFE=
475475
github.com/redpanda-data/redpanda/src/go/rpk v0.0.0-20250716004441-6e1647296ad6 h1:SbcvWTYFEbH5+NQOl1To5jppEa8RCK1HAkRNfhdUGLg=

0 commit comments

Comments
 (0)