-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Print messages about ports that can't change at runtime for K8s #33789
Merged
+183
−38
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,48 @@ | ||
package io.quarkus.kubernetes.spi; | ||
|
||
import java.util.Optional; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
import io.quarkus.deployment.Feature; | ||
|
||
public final class KubernetesPortBuildItem extends MultiBuildItem { | ||
|
||
private final int port; | ||
private final String name; | ||
/** | ||
* Indicates when the port is enabled vs simply configured. | ||
* For example the presence `quarkus.http.ssl-port` also is not enought to tell us if enabled. | ||
* Still, we need to communicate its value and let `quarkus-kubernetes` extension decide. | ||
**/ | ||
private final boolean enabled; | ||
private final Optional<Property<Integer>> source; | ||
|
||
public KubernetesPortBuildItem(int port, Feature feature) { | ||
this(port, feature.getName()); | ||
this(port, feature.getName(), true, Optional.empty()); | ||
} | ||
|
||
public KubernetesPortBuildItem(int port, String name) { | ||
this(port, name, true, Optional.empty()); | ||
} | ||
|
||
public KubernetesPortBuildItem(int port, String name, boolean enabled, Optional<Property<Integer>> source) { | ||
this.port = port; | ||
this.name = name; | ||
this.source = source; | ||
this.enabled = enabled; | ||
} | ||
|
||
public static KubernetesPortBuildItem fromRuntimeConfiguration(String name, String propertyName, Integer defaultValue, | ||
boolean enabled) { | ||
Property<Integer> origin = Property.fromRuntimeConfiguration(propertyName, Integer.class, defaultValue); | ||
Integer port = origin.getValue().orElse(defaultValue); | ||
return new KubernetesPortBuildItem(port, name, enabled, Optional.of(origin)); | ||
} | ||
|
||
public static KubernetesPortBuildItem fromRuntimeConfiguration(String name, String propertyName, Integer defaultValue) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to my previous comment, I think this method can be deleted. |
||
Property<Integer> origin = Property.fromRuntimeConfiguration(propertyName, Integer.class, defaultValue); | ||
Integer port = origin.getValue().orElse(defaultValue); | ||
return new KubernetesPortBuildItem(port, name, origin.getValue().isPresent(), Optional.of(origin)); | ||
} | ||
|
||
public int getPort() { | ||
|
@@ -24,4 +52,12 @@ public int getPort() { | |
public String getName() { | ||
return name; | ||
} | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
public Optional<Property<Integer>> getSource() { | ||
return source; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
extensions/kubernetes/spi/src/main/java/io/quarkus/kubernetes/spi/Property.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.quarkus.kubernetes.spi; | ||
|
||
import java.util.Optional; | ||
|
||
import org.eclipse.microprofile.config.ConfigProvider; | ||
|
||
public class Property<T> { | ||
|
||
private final String name; | ||
private final Class<T> type; | ||
private final Optional<T> value; | ||
private final T defaultValue; | ||
private final boolean runtime; | ||
|
||
public Property(String name, Class<T> type, Optional<T> value, T defaultValue, boolean runtime) { | ||
this.name = name; | ||
this.type = type; | ||
this.value = value; | ||
this.defaultValue = defaultValue; | ||
this.runtime = runtime; | ||
} | ||
|
||
public static <T> Property<T> fromRuntimeConfiguration(String name, Class<T> type, T defaultValue) { | ||
return new Property<T>(name, type, ConfigProvider.getConfig().getOptionalValue(name, type), defaultValue, true); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Class<T> getType() { | ||
return type; | ||
} | ||
|
||
public Optional<T> getValue() { | ||
return value; | ||
} | ||
|
||
public T getDefaultValue() { | ||
return defaultValue; | ||
} | ||
|
||
public boolean isRuntime() { | ||
return runtime; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...netes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/PropertyUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.quarkus.kubernetes.deployment; | ||
|
||
import java.util.HashSet; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkus.kubernetes.spi.Property; | ||
|
||
public class PropertyUtil { | ||
|
||
private static final Set<String> VISITED_EXTENSION_PROPERTIES = new HashSet<>(); | ||
private static final Logger LOG = Logger.getLogger(PropertyUtil.class); | ||
|
||
public static <T> void printMessages(String usage, String platform, Property<T> kubernetesProperty, | ||
Optional<Property<T>> extensionProperty) { | ||
extensionProperty.ifPresent(p -> { | ||
printMessages(usage, platform, kubernetesProperty, p); | ||
}); | ||
} | ||
|
||
public static <T> void printMessages(String usage, String platform, Property<T> kubernetesProperty, | ||
Property<T> extensionProperty) { | ||
if (!VISITED_EXTENSION_PROPERTIES.add(extensionProperty.getName())) { | ||
return; | ||
} | ||
|
||
String platformCapitalized = platform.substring(0, 1).toUpperCase() + platform.substring(1); | ||
T kubernetesValue = kubernetesProperty.getValue().orElse(null); | ||
if (kubernetesValue == null) { | ||
// If no kubernetes property is provided, this will be used instead. | ||
String defaultOrProvided = extensionProperty.getValue().isPresent() ? "provided" : "default"; | ||
String stringValue = String.valueOf(extensionProperty.getValue().orElse(extensionProperty.getDefaultValue())); | ||
LOG.infof("%s manifests are generated with '%s' having %s value '%s'. " | ||
+ "The app and manifests will get out of sync if the property '%s' is changed at runtime.", | ||
platformCapitalized, usage, defaultOrProvided, stringValue, extensionProperty.getName()); | ||
|
||
} else if (extensionProperty.getValue().filter(v -> !v.equals(kubernetesValue)).isPresent()) { | ||
// We have conflicting properties that need to be aligned. Maybe warn? | ||
String runtimeOrBuildTime = extensionProperty.isRuntime() ? "runtime" : "buildtime"; | ||
LOG.debugf( | ||
"%s property '%s' has been set with value '%s' while %s property '%s' is set with '%s'. %s will be set using the former.", | ||
platformCapitalized, kubernetesProperty.getName(), kubernetesProperty.getValue().get(), runtimeOrBuildTime, | ||
extensionProperty.getName(), extensionProperty.getValue().get(), usage); | ||
} else { | ||
// Both proeprties are present and aligned. | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still confuses me to generate build items that are not enabled.
I know you explained to me that this is necessary for the case when users add
quarkus.kubernetes.ports.https.tls=true
, so the container port for https is resolved from here.