Skip to content

Comments

Allow Access Operator deploy to a single Namespace or multiple Namespaces#112

Open
OwenCorrigan76 wants to merge 5 commits intostrimzi:mainfrom
OwenCorrigan76:Deploy_with_single_namespace
Open

Allow Access Operator deploy to a single Namespace or multiple Namespaces#112
OwenCorrigan76 wants to merge 5 commits intostrimzi:mainfrom
OwenCorrigan76:Deploy_with_single_namespace

Conversation

@OwenCorrigan76
Copy link
Contributor

@OwenCorrigan76 OwenCorrigan76 commented Nov 26, 2025

By default, the Kafka Access Operator watches all namespaces. This PR allows deployment of a KafkaAccess resource in a defined namespace or namespaces, by using the Optional env STRIMZI_NAMESPACE.
For example:

          env:
            - name: STRIMZI_NAMESPACE
              value: "myproject, test"

This PR fixes:
#106

@OwenCorrigan76 OwenCorrigan76 added this to the 0.3.0 milestone Nov 26, 2025
@OwenCorrigan76 OwenCorrigan76 force-pushed the Deploy_with_single_namespace branch 2 times, most recently from 2f7d88d to ba9f2cb Compare January 28, 2026 13:00
Comment on lines 36 to 43
Set<String> namespaces =
strimziNamespace == null ? Set.of() :
Arrays.stream(strimziNamespace.split(","))
.map(String::trim)
.collect(Collectors.toSet());

operator.register(new KafkaAccessReconciler(operator.getKubernetesClient()),
o -> o.settingNamespaces(namespaces));
Copy link
Member

Choose a reason for hiding this comment

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

Will this work when we configure to watch all (or any) Namespace? That means when you configure STRIMZI_NAMESPACE to *
I think you will need in that case o.watchingAllNamespaces().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comment @im-konge. That makes sense. Will implement this.

Copy link
Member

Choose a reason for hiding this comment

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

FMPOV you should not have multiple files containing RoleBinding for each Namespace - similarly to the Cluster Operator (and what we have in docs) you can just have one and if needed, it can be created in every Namespace the operator will watch.

OwenCorrigan76 and others added 2 commits February 11, 2026 14:00
Signed-off-by: OwenCorrigan76 <owencorrigan76@gmail.com>
Signed-off-by: ocorriga <ocorriga@redhat.com>
@OwenCorrigan76 OwenCorrigan76 force-pushed the Deploy_with_single_namespace branch from ba9f2cb to 471fab8 Compare February 12, 2026 10:27
Signed-off-by: ocorriga <ocorriga@redhat.com>
@OwenCorrigan76 OwenCorrigan76 force-pushed the Deploy_with_single_namespace branch 2 times, most recently from 25e2719 to b74bb48 Compare February 12, 2026 11:01
Signed-off-by: ocorriga <ocorriga@redhat.com>
@OwenCorrigan76 OwenCorrigan76 force-pushed the Deploy_with_single_namespace branch from b74bb48 to 96bb8fb Compare February 12, 2026 11:26
@OwenCorrigan76 OwenCorrigan76 marked this pull request as ready for review February 12, 2026 11:41
@OwenCorrigan76 OwenCorrigan76 self-assigned this Feb 12, 2026
Signed-off-by: ocorriga <ocorriga@redhat.com>
@OwenCorrigan76 OwenCorrigan76 changed the title Allow Access Operator deploy to a single Namespace Allow Access Operator deploy to a single Namespace or multiple Namespaces Feb 12, 2026
operator.register(new KafkaAccessReconciler(operator.getKubernetesClient()));

String strimziNamespace = System.getenv("STRIMZI_NAMESPACE");
if (strimziNamespace != null && strimziNamespace.matches("\\*")) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (strimziNamespace != null && strimziNamespace.matches("\\*")) {
if (strimziNamespace != null && strimziNamespace.equals("*")) {

I think this will be better than the regex stuff.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, as Jakub mentioned couple of times even before, this is the best thing:

Suggested change
if (strimziNamespace != null && strimziNamespace.matches("\\*")) {
if ("*".equals(strimziNamespace)) {

and you don't need the null check.

.withUseSSAToPatchPrimaryResource(false));
operator.register(new KafkaAccessReconciler(operator.getKubernetesClient()));

String strimziNamespace = System.getenv("STRIMZI_NAMESPACE");
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if having something like this:

Suggested change
String strimziNamespace = System.getenv("STRIMZI_NAMESPACE");
String strimziNamespace = System.getenv().getOrDefault("STRIMZI_NAMESPACE", "*");

would be better.
TBH it would be better to have some configuration class that would check everything and return configuration for the operator, but I don't think it's scope of this PR.
That way you would keep the current behavior of the operator -> in case that you didn't configure this env variable, the operator will watch all Namespaces. Otherwise it will watch the set of Namespaces configured inside the STRIMZI_NAMESPACE env variable.

Comment on lines +41 to +45
Set<String> namespaces =
strimziNamespace == null ? Set.of() :
Arrays.stream(strimziNamespace.split(","))
.map(String::trim)
.collect(Collectors.toSet());
Copy link
Member

Choose a reason for hiding this comment

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

So I think that this is not the correct way. What will happen when you pass the empty list of Namespaces into the settingNamespaces() method?
I would change the if-else here:

  • check if the strimziNamespace is null or empty (the null shouldn't happen here, but it's better to be safe)
  • then check if it's wildcard (you should cover also cases when you have space there - so using trim())
  • I think you should cover case when you have wildcard and Namespace there (so something like - *,namespace-0)
  • then you can split it by the ,
  • if there is something wrong, you should throw exception and not pass there empty Set

You can check how it's done in cluster-operator: https://github.com/strimzi/strimzi-kafka-operator/blob/main/operator-common/src/main/java/io/strimzi/operator/common/config/ConfigParameterParser.java#L179-L195

assertThat(currentKafkaAccess).isNotNull();
currentKafkaAccess.getSpec().setSecretName(NEW_USER_PROVIDED_SECRET_NAME);
client.resources(KafkaAccess.class).resource(currentKafkaAccess).update();
updated = true;
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't break be better than having another boolean value?
Also, if you would like to keep it, I would use different loop type - like while, which you can break and then fail inside it.

However what I saw as the cleanest solution is to use the edit:

        client.resources(KafkaAccess.class).resource(currentKafkaAccess).edit(ka -> {
            ka.getSpec().setSecretName(NEW_USER_PROVIDED_SECRET_NAME);
            return ka;
        });

or

        client.resources(KafkaAccess.class).resource(currentKafkaAccess).edit(ka -> new KafkaAccessBuilder(ka)
            .editOrNewSpec()
                .withSecretName(NEW_USER_PROVIDED_SECRET_NAME)
            .endSpec()
            .build()
        );

it should handle the conflict IIRC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants