Skip to content

Commit

Permalink
feat: re-add support for older property, now marked as deprecated
Browse files Browse the repository at this point in the history
If the older property check-crd-and-validate-local-model is used, a
warning is issued about its deprecation. If both new and older
properties are used, the new one takes precedence and another warning
is also issued.
  • Loading branch information
metacosm committed Apr 29, 2021
1 parent 7d939c2 commit 73d17fb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ ConfigurationServiceBuildItem createConfigurationServiceAndOperator(

final var version = Utils.loadFromProperties();
final CRDConfiguration crdConfig = buildTimeConfiguration.crd;
final var validateCustomResources = Utils.isValidateCustomResourcesEnvVarSet()
? Utils.shouldCheckCRDAndValidateLocalModel()
: crdConfig.validate;
final boolean validateCustomResources = shouldValidateCustomResources();

final var index = combinedIndexBuildItem.getIndex();
final var resourceControllers = index.getAllKnownImplementors(RESOURCE_CONTROLLER);
Expand All @@ -144,6 +142,27 @@ ConfigurationServiceBuildItem createConfigurationServiceAndOperator(
validateCustomResources);
}

private boolean shouldValidateCustomResources() {
if (Utils.isValidateCustomResourcesEnvVarSet()) {
return Utils.shouldCheckCRDAndValidateLocalModel();
}
var validateCustomResources = true;
var useDeprecated = false;
if (buildTimeConfiguration.checkCRDAndValidateLocalModel.isPresent()) {
validateCustomResources = buildTimeConfiguration.checkCRDAndValidateLocalModel.get();
useDeprecated = true;
log.warn("Use of deprecated check-crd-and-validate-local-model property. Use crd.validate instead.");
}
final var validate = buildTimeConfiguration.crd.validate;
if (useDeprecated && validate != validateCustomResources) {
log.warnv(
"Deprecated property check-crd-and-validate-local-model with value ''{0}'' is overridden by crd.validate property value ''{1}''",
validateCustomResources, validate);
validateCustomResources = validate;
}
return validateCustomResources;
}

private boolean asBoolean(String value) {
return Boolean.parseBoolean(value);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
quarkus.operator-sdk.controllers.annotation.finalizer=from-property/finalizer
quarkus.operator-sdk.controllers.annotation.namespaces=bar
quarkus.operator-sdk.concurrent-reconciliation-threads=10
quarkus.operator-sdk.check-crd-and-validate-local-model=true
quarkus.operator-sdk.crd.validate=false
quarkus.operator-sdk.crd.versions=v1beta1
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
package io.quarkiverse.operatorsdk.runtime;

import java.util.Map;
import java.util.Optional;

import io.fabric8.kubernetes.client.CustomResource;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;

@ConfigRoot(name = "operator-sdk", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public class BuildTimeOperatorConfiguration {

/**
* Whether the operator should check that the CRD is properly deployed and that the associated
* {@link CustomResource} implementation matches its information before registering the associated
* controller.
*
* @deprecated Use {@link CRDConfiguration#validate} instead
*/
@ConfigItem(defaultValue = "true")
@Deprecated
public Optional<Boolean> checkCRDAndValidateLocalModel;

/**
* Maps a controller name to its configuration.
*/
Expand Down

0 comments on commit 73d17fb

Please sign in to comment.