-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
test : Add unit test for old deprecated Config constructor #6157
Conversation
35dbbce
to
d2b916a
Compare
class KubeConfigSource { | ||
@BeforeEach | ||
void setUp() { | ||
System.setProperty("kubeconfig", Utils.filePath(ConfigSourcePrecedenceTest.class.getResource("/test-kubeconfig"))); |
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.
I assume this is reusing a .kube/config shared with other tests.
It's better if you create one specific for this test and store it as /config-source-precedence/kube-config
or something similar.
@Nested | ||
@DisplayName("user configuration overrides KubeConfig attributes") | ||
class UserConfigurationOverKubeConfig extends UserConfigurationViaConfigBuilder { | ||
} |
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.
Not sure what's going on here
System.setProperty("KUBERNETES_SERVICE_HOST", "10.96.0.1"); | ||
System.setProperty("KUBERNETES_SERVICE_PORT", "443"); | ||
System.setProperty("kubernetes.auth.serviceAccount.token", | ||
Utils.filePath(ConfigSourcePrecedenceTest.class.getResource("/test-serviceaccount/token"))); |
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.
} | ||
|
||
@Test | ||
@DisplayName("Service Account files provided, then do NOT use it") |
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.
What's it
in this context?
System.setProperty("KUBERNETES_SERVICE_HOST", "10.96.0.1"); | ||
System.setProperty("KUBERNETES_SERVICE_PORT", "443"); | ||
System.setProperty("kubernetes.auth.serviceAccount.token", | ||
Utils.filePath(ConfigSourcePrecedenceTest.class.getResource("/test-serviceaccount/token"))); |
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.
System.setProperty("KUBERNETES_SERVICE_HOST", "10.96.0.1"); | ||
System.setProperty("KUBERNETES_SERVICE_PORT", "443"); |
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.
Why do this look like environment variables?
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.
Yes, Config class uses Utils.getSystemPropertyOrEnvVar
to resolve kubernetes apiserver host and port
kubernetes-client/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Config.java
Lines 531 to 532 in 520894a
String masterHost = Utils.getSystemPropertyOrEnvVar(KUBERNETES_SERVICE_HOST_PROPERTY, (String) null); | |
String masterPort = Utils.getSystemPropertyOrEnvVar(KUBERNETES_SERVICE_PORT_PROPERTY, (String) null); |
This method can handle converting property name kubernetes.service.host
to environment variable KUBERNETES_SERVICE_HOST
; but I think we're passing it incorrectly. At the moment, it only seems to work as both property and env names as KUBERNETES_SERVICE_HOST
kubernetes-client/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Config.java
Lines 121 to 122 in 520894a
public static final String KUBERNETES_SERVICE_HOST_PROPERTY = "KUBERNETES_SERVICE_HOST"; | |
public static final String KUBERNETES_SERVICE_PORT_PROPERTY = "KUBERNETES_SERVICE_PORT"; |
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.
So maybe report this as a bug?
Also, given your context, not sure if this is the valid test name then?
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.
Umm, I'm not sure if it's a bug as KubernetesClient doesn't document anywhere usage of kubernetes.service.host
and kubernetes.service.port
properties in https://github.com/fabric8io/kubernetes-client#configuring-the-client
KUBERNETES_SERVICE_HOST/PORT
environment variables are something that's exposed via Kubernetes. KubernetesClient is just trying to detect it in auto configuration phase.
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.
I have removed adding KUBERNETES_SERVICE_HOST
and KUBERNETES_SERVICE_PORT
to System Properties as they're not System Properties.
@Nested | ||
@DisplayName("user configuration overrides ServiceAccount's Config attributes") | ||
class UserConfigurationOverServiceAccount extends UserConfigurationViaConfigBuilder { | ||
} |
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.
.hasFieldOrPropertyWithValue("masterUrl", "https://user-configuration-override:8443/") | ||
.hasFieldOrPropertyWithValue("namespace", "namespace-overridden") | ||
.hasFieldOrPropertyWithValue("autoOAuthToken", "token-overridden"); |
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.
Can you also add an assertion for one of the configurations that's read from the initial source? -> precedence values preserved <-
@Nested | ||
@DisplayName("User configuration overrides Config attributes configured via System Properties") | ||
class UserConfigurationOverSystemProperties extends UserConfigurationViaConfigBuilder { | ||
} |
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.
private abstract static class UserConfigurationViaConfigBuilder { | ||
@SuppressWarnings("unused") | ||
@Test | ||
@DisplayName("User configuration via builder given most precedence") | ||
void whenUserConfigurationOverridesSomeFields_thenUserConfigurationGivenPrecedence() { | ||
// Given | ||
Config config = new ConfigBuilder() | ||
.withMasterUrl("https://user-configuration-override:8443") | ||
.withNamespace("namespace-overridden") | ||
.withAutoOAuthToken("token-overridden") | ||
.build(); | ||
|
||
// When + Then | ||
assertThat(config) | ||
.hasFieldOrPropertyWithValue("masterUrl", "https://user-configuration-override:8443/") | ||
.hasFieldOrPropertyWithValue("namespace", "namespace-overridden") | ||
.hasFieldOrPropertyWithValue("autoOAuthToken", "token-overridden"); | ||
} | ||
} |
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's not worth reusing this test.
It obfuscates things and makes it hard to understand what's going on, especially in case of failure.
In addition, there's no check for precedence (as suggested in one of the other comments). You'd specifically want one assertion to ensure that 1. some values are overridden, and 2. some values are preserved from the precedent config
kubernetes-itests/src/test/java/io/fabric8/kubernetes/DisableAutoConfigurationIT.java
Show resolved
Hide resolved
ddae5ab
to
66c4e8d
Compare
- Add unit test for `@Deprecated` Config constructor. We don't know whether this public constructor is being used by any user. Adding a test just in case to verify that it behaves as expected. - Organize tests in `ConfigTest` to be grouped under various load sources - Add new test `ConfigSourcePrecedenceTest` for verifying Config source load precedence Signed-off-by: Rohan Kumar <[email protected]>
66c4e8d
to
7a94b68
Compare
Quality Gate passedIssues Measures |
@Test | ||
@DisplayName("override via system property should get more precedence over kubeconfig") | ||
void testOverrideViaSystemProperties() { |
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.
This is redundant, please remove any of these redundant tests in a follow-up PR
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.
…asses in ConfigTest - Remove `@Nested` class BuildConfigured as it doesn’t have any common setup, teardown blocks - Remove these tests as they were already covered by ConfigSourcePrecedenceTest: - `testOverrideViaSystemProperties` - `testSystemPropertiesAndBuilderGetMorePrecedenceOverKubeconfig` - Rename tests with legacy names starting with `testXXXX` - Add `@DisplayName` annotation for tests wherever applicable - Remove `assertConfig` method and inline assertions in tests wherever it’s getting used - Remove abstract test class introduced in fabric8io#6157 `AutoConfiguredDisabledScenarios`, duplicate tests so that it’s more clear in case of failure Signed-off-by: Rohan Kumar <[email protected]>
…asses in ConfigTest - Remove `@Nested` class BuildConfigured as it doesn’t have any common setup, teardown blocks - Remove these tests as they were already covered by ConfigSourcePrecedenceTest: - `testOverrideViaSystemProperties` - `testSystemPropertiesAndBuilderGetMorePrecedenceOverKubeconfig` - Rename tests with legacy names starting with `testXXXX` - Add `@DisplayName` annotation for tests wherever applicable - Remove `assertConfig` method and inline assertions in tests wherever it’s getting used - Remove abstract test class introduced in fabric8io#6157 `AutoConfiguredDisabledScenarios`, duplicate tests so that it’s more clear in case of failure - Move this test outside of ConfigTest as a separate test class `ConfigDisableAutoConfigurationTest` Signed-off-by: Rohan Kumar <[email protected]>
…asses in ConfigTest - Remove `@Nested` class BuildConfigured as it doesn’t have any common setup, teardown blocks - Remove these tests as they were already covered by ConfigSourcePrecedenceTest: - `testOverrideViaSystemProperties` - `testSystemPropertiesAndBuilderGetMorePrecedenceOverKubeconfig` - Rename tests with legacy names starting with `testXXXX` - Add `@DisplayName` annotation for tests wherever applicable - Remove `assertConfig` method and inline assertions in tests wherever it’s getting used - Remove abstract test class introduced in fabric8io#6157 `AutoConfiguredDisabledScenarios`, duplicate tests so that it’s more clear in case of failure - Move this test outside of ConfigTest as a separate test class `ConfigDisableAutoConfigurationTest` Signed-off-by: Rohan Kumar <[email protected]>
…sses in ConfigTest - Remove `@Nested` class BuildConfigured as it doesn’t have any common setup, teardown blocks - Remove these tests as they were already covered by ConfigSourcePrecedenceTest: - `testOverrideViaSystemProperties` - `testSystemPropertiesAndBuilderGetMorePrecedenceOverKubeconfig` - Rename tests with legacy names starting with `testXXXX` - Add `@DisplayName` annotation for tests wherever applicable - Remove `assertConfig` method and inline assertions in tests wherever it’s getting used - Remove abstract test class introduced in #6157 `AutoConfiguredDisabledScenarios`, duplicate tests so that it’s more clear in case of failure - Move this test outside of ConfigTest as a separate test class `ConfigDisableAutoConfigurationTest` Signed-off-by: Rohan Kumar <[email protected]>
Description
Prerequisite to #6153
@Deprecated
Config constructor. We don't know whether this public constructor is being used by any user. Adding a test just in case to verify that it behaves as expected.ConfigTest
to be grouped under various load sources@Nested
classesConfigSourcePrecedenceTest
for verifying Config source load precedenceType of change
test, version modification, documentation, etc.)
Checklist