Skip to content

Commit

Permalink
chore(deps): bump io.kubernetes:client-java from 18.0.1 to 21.0.2 (#262)
Browse files Browse the repository at this point in the history
* chore(deps): bump io.kubernetes:client-java from 18.0.1 to 21.0.2

Bumps [io.kubernetes:client-java](https://github.com/kubernetes-client/java) from 18.0.1 to 21.0.2.
- [Release notes](https://github.com/kubernetes-client/java/releases)
- [Changelog](https://github.com/kubernetes-client/java/blob/master/CHANGELOG.md)
- [Commits](kubernetes-client/java@v18.0.1...v21.0.2)

---
updated-dependencies:
- dependency-name: io.kubernetes:client-java
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* fix: update to api changes

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Piotr Wielgolaski <[email protected]>
  • Loading branch information
1 parent 893e5ac commit 160f30e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 42 deletions.
2 changes: 1 addition & 1 deletion james-controller-kubernetes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies {
implementation project(':james-agent-common')
implementation project(':james-agent-io')
implementation "com.google.guava:guava:${versions.guava}"
implementation 'io.kubernetes:client-java:18.0.1'
implementation 'io.kubernetes:client-java:21.0.2'

testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.1")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ public class KubernetesController implements JamesController {

private static final Logger LOG = Logger.getLogger(KubernetesController.class);
private final ExecutorService executor;
private final Map<String, Map<String,InformationPointDTO>> informationPointsCache;
private final Map<String, Map<String, InformationPointDTO>> informationPointsCache;
private ApiClient apiClient;


@Override
public String getId() {
return "james.controller.kubernetes";
Expand Down Expand Up @@ -98,8 +97,8 @@ public void initialize(final JamesControllerConfiguration jamesControllerConfigu
apiClient = createApiClient(configuration.getUrl(), configuration.getToken());
executor.execute(() -> {
while (!Thread.interrupted()) {
try(final Watch<V1ConfigMap> watch =
createConfigMapWatch(apiClient, configuration.getNamespace(), configuration.getLabels())) {
try (final Watch<V1ConfigMap> watch =
createConfigMapWatch(apiClient, configuration.getNamespace(), configuration.getLabels())) {
watchConfigMapChanges(watch, informationPointService);
} catch (final Exception e) {
LOG.info("Unable to setup k8s watcher", e);
Expand Down Expand Up @@ -149,25 +148,17 @@ private void watchConfigMapChanges(final Watch<V1ConfigMap> watch,
}
}

private Map<String,String> updatePairedMaps(final V1ObjectMeta metadata, final String name) {
private Map<String, String> updatePairedMaps(final V1ObjectMeta metadata, final String name) {
final String mainMapName = getSecondPartOfConfigurationName(name);

try {
final String fieldSelector = "metadata.name=" + mainMapName;
final V1ConfigMapList v1ConfigMapList =
new CoreV1Api(apiClient).listNamespacedConfigMap(metadata.getNamespace(),
null,
null,
null,
fieldSelector,
null,
null,
null,
null,
null,
false);
new CoreV1Api(apiClient).listNamespacedConfigMap(metadata.getNamespace())
.fieldSelector(fieldSelector)
.watch(false).execute();
return v1ConfigMapList.getItems().stream().findFirst().map(V1ConfigMap::getData)
.orElse(Collections.emptyMap());
.orElse(Collections.emptyMap());
} catch (ApiException e) {
LOG.warn("Problem while looking for map other map");
return Collections.emptyMap();
Expand All @@ -180,10 +171,10 @@ private String getSecondPartOfConfigurationName(final String name) {
//configuration is stored in to config maps:
// - configMap with configuration: CONFIG_NAME
// - configMap with script files: CONFIG_NAME-files
if(name.endsWith("-files")) {
if (name.endsWith("-files")) {
toReplace = "-files";
suffix = "";
}else {
} else {
suffix = "-files";
toReplace = "";
}
Expand All @@ -205,51 +196,41 @@ private Watch<V1ConfigMap> createConfigMapWatch(
.collect(Collectors.joining(","));
return Watch.createWatch(
apiClient,
api.listNamespacedConfigMapCall(namespace,
null,
null,
null,
null,
labelSelector,
null,
null,
null,
null,
true,
null),
api.listNamespacedConfigMap(namespace).labelSelector(labelSelector).watch(true).buildCall(null),
new TypeToken<Watch.Response<V1ConfigMap>>() {

}.getType());
}

private Collection<InformationPointDTO> readAllConfigurations(Map<String,String> configMaps) {
Map<ConfigParser,String> configurations = new HashMap<>();
private Collection<InformationPointDTO> readAllConfigurations(Map<String, String> configMaps) {
Map<ConfigParser, String> configurations = new HashMap<>();
InMemoryScriptStore scriptStore = new InMemoryScriptStore();
for (Map.Entry<String, String> configEntry : configMaps.entrySet()) {
final ConfigParser parser = ConfigIOFactory.getInstance().getParser(configEntry.getKey()).orElse(null);
if(parser != null){
if (parser != null) {
configurations.put(parser, configEntry.getValue());
} else if (configEntry.getKey().endsWith(".groovy")){
} else if (configEntry.getKey().endsWith(".groovy")) {
scriptStore.registerFile(configEntry.getKey(), configEntry.getValue());
} else {
LOG.warn("Unrecognized format:" + configEntry.getKey());
}
}
return configurations.entrySet().stream().flatMap(entry-> {
try (InputStream configStream = new ByteArrayInputStream(entry.getValue().getBytes());){
return entry.getKey().parseConfiguration(configStream,scriptStore).stream();
return configurations.entrySet().stream().flatMap(entry -> {
try (InputStream configStream = new ByteArrayInputStream(entry.getValue().getBytes());) {
return entry.getKey().parseConfiguration(configStream, scriptStore).stream();
} catch (IOException e) {
LOG.error("Unable to parse configurations: "+configMaps.keySet(),e);
LOG.error("Unable to parse configurations: " + configMaps.keySet(), e);
return Stream.empty();
}
}).collect(Collectors.toSet());
}

private void processUpdate(final String configName, final Collection<InformationPointDTO> informationPoints,
final InformationPointService informationPointService) {
final Map<String,InformationPointDTO> cache = informationPointsCache.computeIfAbsent(configName, name -> new LinkedHashMap<>());
final Map<String, InformationPointDTO> cache =
informationPointsCache.computeIfAbsent(configName, name -> new LinkedHashMap<>());
final Map<String, InformationPointDTO> informationPointsMap = informationPoints.stream().collect(
Collectors.toMap(informationPoint -> informationPoint.getMethodReference(),Function.identity()));
Collectors.toMap(informationPoint -> informationPoint.getMethodReference(), Function.identity()));

final MapDifference<String, InformationPointDTO> difference = Maps.difference(informationPointsMap, cache);

Expand Down

0 comments on commit 160f30e

Please sign in to comment.