Skip to content

Commit

Permalink
Refactor KubernetesClient [HZG-225] (hazelcast#3455)
Browse files Browse the repository at this point in the history
Refactors KubernetesClient and related classes as a preparation for https://hazelcast.atlassian.net/browse/HZG-225.

KubernetesClient
1. Improve Javadoc (mainly line wrapping).
2. Decrease the number of constructors from 3 to 2: one taking KubernetesConfig and used in production, and one taking all variables and used in tests.
3. Simplify `buildKubernetesApiUrlProvider()`.
4. Make `extractStsName()` static.
5. Move `extractSts(JsonObject)` to `RuntimeContext#from(JsonObject, String)`.
6. Replace simple `String#format` usages with string concatenation.
7. Remove `StsMonitorThread#latestResourceVersion` since it is already accessible through `latestRuntimeContext.getResourceVersion()`.
8. Refactor `StsMonitorThread#onMessage(String)` and rename it to `onWatchEventReceived`.
9. Refactor and inline `parseStsList(JsonObject)`.

RuntimeContext
1. Remove UNKNOWN since it is already defined in ClusterTopologyIntentTracker.

StsMonitorTest
1. Refactor `buildSts(...)`.

GitOrigin-RevId: 0efb501bd95947faf96678403f92f437e3f2321a
  • Loading branch information
burakgok authored and actions-user committed Oct 18, 2024
1 parent 8563cd4 commit c20a0ff
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class KubernetesApiEndpointResolver
KubernetesApiEndpointResolver(ILogger logger, KubernetesConfig config, ClusterTopologyIntentTracker tracker) {
this(logger, config.getServiceName(), config.getServicePort(), config.getServiceLabelName(),
config.getServiceLabelValue(), config.getPodLabelName(), config.getPodLabelValue(),
config.isResolveNotReadyAddresses(), buildKubernetesClient(config, tracker));
config.isResolveNotReadyAddresses(), new KubernetesClient(config, tracker));
}

/**
Expand All @@ -66,13 +66,6 @@ class KubernetesApiEndpointResolver
this.client = client;
}

private static KubernetesClient buildKubernetesClient(KubernetesConfig config, ClusterTopologyIntentTracker tracker) {
return new KubernetesClient(config.getNamespace(), config.getKubernetesMasterUrl(), config.getTokenProvider(),
config.getKubernetesCaCertificate(), config.getKubernetesApiRetries(), config.getExposeExternallyMode(),
config.isUseNodeNameAsExternalAddress(), config.getServicePerPodLabelName(),
config.getServicePerPodLabelValue(), tracker);
}

@Override
List<DiscoveryNode> resolveNodes() {
if (serviceName != null && !serviceName.isEmpty()) {
Expand Down
Loading

0 comments on commit c20a0ff

Please sign in to comment.