generated from telekom/reuse-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refac: removed k8s informer code and streamlined k8s client creation
- Loading branch information
Showing
21 changed files
with
129 additions
and
530 deletions.
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
91 changes: 0 additions & 91 deletions
91
...ore/src/main/java/de/telekom/eni/pandora/horizon/kubernetes/InformerStoreInitHandler.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
...ore/src/main/java/de/telekom/eni/pandora/horizon/kubernetes/InformerStoreInitSupport.java
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
...core/src/main/java/de/telekom/eni/pandora/horizon/kubernetes/KubernetesClientBuilder.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,74 @@ | ||
package de.telekom.eni.pandora.horizon.kubernetes; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; | ||
import de.telekom.eni.pandora.horizon.exception.CouldNotConstructKubernetesClientException; | ||
import de.telekom.eni.pandora.horizon.kubernetes.config.KubernetesProperties; | ||
import de.telekom.eni.pandora.horizon.util.RoverToken; | ||
import io.fabric8.kubernetes.client.Config; | ||
import io.fabric8.kubernetes.client.ConfigBuilder; | ||
import io.fabric8.kubernetes.client.DefaultKubernetesClient; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.util.Base64; | ||
|
||
public class KubernetesClientBuilder { | ||
|
||
private final KubernetesProperties kubernetesProperties; | ||
|
||
public KubernetesClientBuilder(KubernetesProperties kubernetesProperties) { | ||
this.kubernetesProperties = kubernetesProperties; | ||
} | ||
|
||
private Config parseRoverToken(String roverToken) throws JsonProcessingException { | ||
byte[] decodedBytes = Base64.getDecoder().decode(roverToken); | ||
|
||
RoverToken tokenObject = new YAMLMapper().readValue(new String(decodedBytes), RoverToken.class); | ||
|
||
return new ConfigBuilder() | ||
.withMasterUrl(tokenObject.getMasterUrl()) | ||
.withOauthToken(tokenObject.getToken()) | ||
.withCaCertData(tokenObject.getCaCertificate()) | ||
.withDisableHostnameVerification(true) | ||
.build(); | ||
} | ||
private Config withCustomSettings(Config config) { | ||
config.setRequestTimeout(kubernetesProperties.getRequestTimeoutInMs()); | ||
config.setConnectionTimeout(kubernetesProperties.getConnectionTimeoutMs()); | ||
|
||
return config; | ||
} | ||
|
||
public KubernetesClient createClientFromRoverToken(String roverToken) throws CouldNotConstructKubernetesClientException { | ||
try { | ||
var config = parseRoverToken(roverToken); | ||
|
||
return new DefaultKubernetesClient(withCustomSettings(config)); | ||
} catch (Exception e) { | ||
throw new CouldNotConstructKubernetesClientException("Error: Rover token could not be parsed.", e); | ||
} | ||
} | ||
|
||
public KubernetesClient createClientFromeKubeconfigFile(String path) throws CouldNotConstructKubernetesClientException { | ||
try { | ||
var configFile = new File(path); | ||
var configYAML = String.join("\n", Files.readAllLines(configFile.toPath(), StandardCharsets.UTF_8)); | ||
|
||
var config = Config.fromKubeconfig(configYAML); | ||
|
||
return new DefaultKubernetesClient(withCustomSettings(config)); | ||
} catch (IOException e) { | ||
throw new CouldNotConstructKubernetesClientException(String.format("Error: Kubernetes config %1s could not be processed.", path), e); | ||
} | ||
} | ||
|
||
public KubernetesClient createDefaultClient() { | ||
var config = new ConfigBuilder().build(); | ||
|
||
return new DefaultKubernetesClient(withCustomSettings(config)); | ||
} | ||
} |
88 changes: 0 additions & 88 deletions
88
...core/src/main/java/de/telekom/eni/pandora/horizon/kubernetes/KubernetesClientWrapper.java
This file was deleted.
Oops, something went wrong.
106 changes: 0 additions & 106 deletions
106
...zon-core/src/main/java/de/telekom/eni/pandora/horizon/kubernetes/PodResourceListener.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.