Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat empty runtime namespaces as All Namespaces mode #658

Merged
merged 1 commit into from
Aug 11, 2023
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.quarkiverse.operatorsdk.runtime;

import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_NAMESPACES_SET;
import static io.quarkiverse.operatorsdk.runtime.Constants.QOSDK_USE_BUILDTIME_NAMESPACES_SET;

import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -55,9 +58,22 @@ public Supplier<QuarkusConfigurationService> configurationServiceSupplier(Versio
c.setRetryConfiguration(null);
}

// if despite all of this, we still haven't set the namespaces, use the operator-level default if it exists
// if the namespaces weren't set as an annotation, use the operator-level configuration if it exists
if (!c.isWereNamespacesSet()) {
runTimeConfiguration.namespaces.ifPresent(ns -> c.setNamespaces(new HashSet<>(ns)));
// The namespaces field has a default value so that we are able to detect if the configuration value is set to "".
// Setting the value to "" will reset the configuration and result in an empty Optional.
// Not setting the value at all will result in the default being applied, which we can test for.
if (runTimeConfiguration.namespaces.isPresent()) {
final var runtimeNamespaces = new HashSet<>(runTimeConfiguration.namespaces.get());
// If it's not the default value, use it because it was set.
// If it is the default value, ignore it and let any build time config be used.
if (!QOSDK_USE_BUILDTIME_NAMESPACES_SET.equals(runtimeNamespaces)) {
c.setNamespaces(runtimeNamespaces);
}
} else {
// Value has been explicitly reset (value was empty string), use all namespaces mode
c.setNamespaces(DEFAULT_NAMESPACES_SET);
}
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkiverse.operatorsdk.runtime;

import java.util.Collections;
import java.util.Set;

public final class Constants {
private Constants() {
}

public static final Set<String> QOSDK_USE_BUILDTIME_NAMESPACES_SET = Collections
.singleton(Constants.QOSDK_USE_BUILDTIME_NAMESPACES);

public static final String QOSDK_USE_BUILDTIME_NAMESPACES = "QOSDK_USE_BUILDTIME_NAMESPACES";
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package io.quarkiverse.operatorsdk.runtime;

import static io.quarkiverse.operatorsdk.runtime.Constants.QOSDK_USE_BUILDTIME_NAMESPACES;

import java.time.Duration;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -59,7 +61,10 @@ public class RunTimeOperatorConfiguration {
* specified by the kube config file the operator uses.
* </p>
*/
@ConfigItem
// We use a default here so that we are able to detect if the configuration value is set to "". Setting the value to "" will
// reset the configuration and result in an empty Optional, but not setting the value at all will result in the default being
// applied.
@ConfigItem(defaultValue = QOSDK_USE_BUILDTIME_NAMESPACES)
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if it might not just be enough to set the default value to io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_ALL_NAMESPACES here. Ideally, we'd need a test to cover this, actually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we set the default to WATCH_ALL_NAMESPACES we couldn't tell if there was no specific runtime setting, which means we would always override the build time property.

Maybe the build time property doesn't matter because it's only really intended to affect the manifests and not the runtime behaviour... but at the moment the code will honour the build time property if the runtime property is not set at all.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe the build time property doesn't matter because it's only really intended to affect the manifests and not the runtime behaviour... but at the moment the code will honour the build time property if the runtime property is not set at all.

I would say that this is the intended behavior but I'm open to change my mind about this depending on what people think. The previous version used the same property for both build and runtimes, which was conducive to confusing which version was used ultimately. With the new generate-with-watched-namespaces property, it is now more explicit that the build time value is used mostly for generation purposes. Its value can indeed be propagated at runtime and it's indeed how things are currently implemented, just not sure if it actually make sense since it would make it more difficult to know exactly which configuration is used at runtime. Completely separating both might make more sense with that respect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was my thinking with a property that was explicitly namespaced with manifests in the name to separate it from properties that affect the built image.

I feel like the manifests are really runtime configuration and tbh, I think using quarkus.operator-sdk.namespaces at build time should affect the manifests and not the image, and that would make conceptual sense. It breaks the duplicated properties rule though.

public Optional<List<String>> namespaces;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_OPERATOR_SDK_NAMESPACES+++`
endif::add-copy-button-to-env-var[]
--|list of string
|
|`QOSDK_USE_BUILDTIME_NAMESPACES`


a| [[quarkus-operator-sdk_quarkus.operator-sdk.concurrent-workflow-threads]]`link:#quarkus-operator-sdk_quarkus.operator-sdk.concurrent-workflow-threads[quarkus.operator-sdk.concurrent-workflow-threads]`
Expand Down