Compare commits
1 commit
main
...
wip/api-up
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c2a327559 |
16 changed files with 56 additions and 48 deletions
|
|
@ -11,7 +11,7 @@ plugins {
|
|||
dependencies {
|
||||
api project(':org.jdrupes.vmoperator.util')
|
||||
api 'org.jgrapes:org.jgrapes.core:[1.22.1,2)'
|
||||
api 'io.kubernetes:client-java:[19.0.0,20.0.0)'
|
||||
api 'io.kubernetes:client-java:[23.0.0,24.0.0)'
|
||||
api 'org.yaml:snakeyaml'
|
||||
api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:[2.16.1,3]'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import com.google.gson.TypeAdapterFactory;
|
|||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import io.kubernetes.client.openapi.ApiClient;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Type;
|
||||
|
|
@ -45,18 +45,15 @@ public class DynamicTypeAdapterFactory<O extends K8sDynamicModel,
|
|||
|
||||
/**
|
||||
* Make sure that this adapter is registered.
|
||||
*
|
||||
* @param client the client
|
||||
*/
|
||||
public void register(ApiClient client) {
|
||||
public void register() {
|
||||
if (!ModelCreator.class
|
||||
.equals(client.getJSON().getGson().getAdapter(objectClass)
|
||||
.getClass())
|
||||
|| !ModelsCreator.class.equals(client.getJSON().getGson()
|
||||
.equals(JSON.getGson().getAdapter(objectClass).getClass())
|
||||
|| !ModelsCreator.class.equals(JSON.getGson()
|
||||
.getAdapter(objectListClass).getClass())) {
|
||||
Gson gson = client.getJSON().getGson();
|
||||
client.getJSON().setGson(gson.newBuilder()
|
||||
.registerTypeAdapterFactory(this).create());
|
||||
Gson gson = JSON.getGson();
|
||||
JSON.setGson(
|
||||
gson.newBuilder().registerTypeAdapterFactory(this).create());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import io.kubernetes.client.common.KubernetesType;
|
|||
import io.kubernetes.client.custom.V1Patch;
|
||||
import io.kubernetes.client.openapi.ApiClient;
|
||||
import io.kubernetes.client.openapi.ApiException;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import io.kubernetes.client.openapi.apis.EventsV1Api;
|
||||
import io.kubernetes.client.openapi.models.EventsV1Event;
|
||||
import io.kubernetes.client.openapi.models.V1ObjectMeta;
|
||||
|
|
@ -118,7 +119,7 @@ public class K8s {
|
|||
= new Yaml(new SafeConstructor(new LoaderOptions())).load(yaml);
|
||||
|
||||
// There's no short-cut from Java (collections) to Gson
|
||||
var gson = client.getJSON().getGson();
|
||||
var gson = JSON.getGson();
|
||||
var jsonText = gson.toJson(yamlData);
|
||||
return gson.fromJson(jsonText, JsonObject.class);
|
||||
}
|
||||
|
|
@ -245,7 +246,7 @@ public class K8s {
|
|||
if (event.getRegarding() == null) {
|
||||
event.regarding(objectReference(object));
|
||||
}
|
||||
new EventsV1Api(client).createNamespacedEvent(
|
||||
object.getMetadata().getNamespace(), event, null, null, null, null);
|
||||
new EventsV1Api(client)
|
||||
.createNamespacedEvent(object.getMetadata().getNamespace(), event);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URI;
|
||||
import java.text.DateFormat;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Collection;
|
||||
|
|
@ -804,6 +805,7 @@ public class K8sClient extends ApiClient {
|
|||
/**
|
||||
* Builds the call.
|
||||
*
|
||||
* @param baseUrl the base url
|
||||
* @param path the path
|
||||
* @param method the method
|
||||
* @param queryParams the query params
|
||||
|
|
@ -820,12 +822,13 @@ public class K8sClient extends ApiClient {
|
|||
*/
|
||||
@SuppressWarnings({ "rawtypes", "PMD.ExcessiveParameterList" })
|
||||
@Override
|
||||
public Call buildCall(String path, String method, List<Pair> queryParams,
|
||||
List<Pair> collectionQueryParams, Object body,
|
||||
Map<String, String> headerParams, Map<String, String> cookieParams,
|
||||
Map<String, Object> formParams, String[] authNames,
|
||||
public Call buildCall(String baseUrl, String path, String method,
|
||||
List<Pair> queryParams, List<Pair> collectionQueryParams,
|
||||
Object body, Map<String, String> headerParams,
|
||||
Map<String, String> cookieParams, Map<String, Object> formParams,
|
||||
String[] authNames,
|
||||
ApiCallback callback) throws ApiException {
|
||||
return apiClient().buildCall(path, method, queryParams,
|
||||
return apiClient().buildCall(baseUrl, path, method, queryParams,
|
||||
collectionQueryParams, body, headerParams, cookieParams, formParams,
|
||||
authNames, callback);
|
||||
}
|
||||
|
|
@ -833,6 +836,7 @@ public class K8sClient extends ApiClient {
|
|||
/**
|
||||
* Builds the request.
|
||||
*
|
||||
* @param baseUrl the base url
|
||||
* @param path the path
|
||||
* @param method the method
|
||||
* @param queryParams the query params
|
||||
|
|
@ -849,12 +853,12 @@ public class K8sClient extends ApiClient {
|
|||
*/
|
||||
@SuppressWarnings({ "rawtypes", "PMD.ExcessiveParameterList" })
|
||||
@Override
|
||||
public Request buildRequest(String path, String method,
|
||||
public Request buildRequest(String baseUrl, String path, String method,
|
||||
List<Pair> queryParams, List<Pair> collectionQueryParams,
|
||||
Object body, Map<String, String> headerParams,
|
||||
Map<String, String> cookieParams, Map<String, Object> formParams,
|
||||
String[] authNames, ApiCallback callback) throws ApiException {
|
||||
return apiClient().buildRequest(path, method, queryParams,
|
||||
return apiClient().buildRequest(baseUrl, path, method, queryParams,
|
||||
collectionQueryParams, body, headerParams, cookieParams, formParams,
|
||||
authNames, callback);
|
||||
}
|
||||
|
|
@ -862,6 +866,7 @@ public class K8sClient extends ApiClient {
|
|||
/**
|
||||
* Builds the url.
|
||||
*
|
||||
* @param baseUrl the base url
|
||||
* @param path the path
|
||||
* @param queryParams the query params
|
||||
* @param collectionQueryParams the collection query params
|
||||
|
|
@ -869,9 +874,10 @@ public class K8sClient extends ApiClient {
|
|||
* @see ApiClient#buildUrl(java.lang.String, java.util.List, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
public String buildUrl(String path, List<Pair> queryParams,
|
||||
public String buildUrl(String baseUrl, String path, List<Pair> queryParams,
|
||||
List<Pair> collectionQueryParams) {
|
||||
return apiClient().buildUrl(path, queryParams, collectionQueryParams);
|
||||
return apiClient().buildUrl(baseUrl, path, queryParams,
|
||||
collectionQueryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -907,14 +913,15 @@ public class K8sClient extends ApiClient {
|
|||
* @param queryParams the query params
|
||||
* @param headerParams the header params
|
||||
* @param cookieParams the cookie params
|
||||
* @throws ApiException
|
||||
* @see ApiClient#updateParamsForAuth(java.lang.String[], java.util.List, java.util.Map, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public void updateParamsForAuth(String[] authNames, List<Pair> queryParams,
|
||||
Map<String, String> headerParams,
|
||||
Map<String, String> cookieParams) {
|
||||
Map<String, String> headerParams, Map<String, String> cookieParams,
|
||||
String payload, String method, URI uri) throws ApiException {
|
||||
apiClient().updateParamsForAuth(authNames, queryParams, headerParams,
|
||||
cookieParams);
|
||||
cookieParams, payload, method, uri);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -240,6 +240,7 @@ public class K8sClusterGenericStub<O extends KubernetesObject,
|
|||
* @param <L> the object list type
|
||||
* @param <R> the result type
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface GenericSupplier<O extends KubernetesObject,
|
||||
L extends KubernetesListObject,
|
||||
R extends K8sClusterGenericStub<O, L>> {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import io.kubernetes.client.common.KubernetesListObject;
|
||||
import io.kubernetes.client.openapi.Configuration;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import io.kubernetes.client.openapi.models.V1ListMeta;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -147,9 +147,7 @@ public class K8sDynamicModelsBase<T extends K8sDynamicModel>
|
|||
* @param objectMeta the new metadata
|
||||
*/
|
||||
public void setMetadata(V1ListMeta objectMeta) {
|
||||
data.add("metadata",
|
||||
Configuration.getDefaultApiClient().getJSON().getGson()
|
||||
.toJsonTree(objectMeta));
|
||||
data.add("metadata", JSON.getGson().toJsonTree(objectMeta));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.jdrupes.vmoperator.common;
|
|||
import io.kubernetes.client.Discovery.APIResource;
|
||||
import io.kubernetes.client.apimachinery.GroupVersionKind;
|
||||
import io.kubernetes.client.openapi.ApiException;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import io.kubernetes.client.util.generic.options.ListOptions;
|
||||
import java.io.Reader;
|
||||
import java.util.Collection;
|
||||
|
|
@ -101,8 +102,8 @@ public class K8sDynamicStub
|
|||
*/
|
||||
public static K8sDynamicStub createFromYaml(K8sClient client,
|
||||
APIResource context, Reader yaml) throws ApiException {
|
||||
var model = new K8sDynamicModel(client.getJSON().getGson(),
|
||||
K8s.yamlToJson(client, yaml));
|
||||
var model
|
||||
= new K8sDynamicModel(JSON.getGson(), K8s.yamlToJson(client, yaml));
|
||||
return K8sGenericStub.create(K8sDynamicModel.class,
|
||||
K8sDynamicModels.class, client, context, model,
|
||||
(c, ns, n) -> new K8sDynamicStub(c, context, ns, n));
|
||||
|
|
|
|||
|
|
@ -46,6 +46,6 @@ public abstract class K8sDynamicStubBase<O extends K8sDynamicModel,
|
|||
K8sClient client, APIResource context, String namespace,
|
||||
String name) {
|
||||
super(objectClass, objectListClass, client, context, namespace, name);
|
||||
taf.register(client);
|
||||
taf.register();
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@ import io.kubernetes.client.common.KubernetesListObject;
|
|||
import io.kubernetes.client.common.KubernetesObject;
|
||||
import io.kubernetes.client.custom.V1Patch;
|
||||
import io.kubernetes.client.openapi.ApiException;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import io.kubernetes.client.util.Strings;
|
||||
import io.kubernetes.client.util.generic.GenericKubernetesApi;
|
||||
import io.kubernetes.client.util.generic.KubernetesApiResponse;
|
||||
|
|
@ -325,7 +326,7 @@ public class K8sGenericStub<O extends KubernetesObject,
|
|||
opts.setForce(true);
|
||||
opts.setFieldManager("kubernetes-java-kubectl-apply");
|
||||
return patch(V1Patch.PATCH_FORMAT_APPLY_YAML,
|
||||
new V1Patch(client.getJSON().serialize(def)), opts);
|
||||
new V1Patch(JSON.serialize(def)), opts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -359,6 +360,7 @@ public class K8sGenericStub<O extends KubernetesObject,
|
|||
* @param <L> the object list type
|
||||
* @param <R> the result type
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface GenericSupplier<O extends KubernetesObject,
|
||||
L extends KubernetesListObject, R extends K8sGenericStub<O, L>> {
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class VmDefinition extends K8sDynamicModel {
|
|||
private static final Logger logger
|
||||
= Logger.getLogger(VmDefinition.class.getName());
|
||||
@SuppressWarnings("PMD.FieldNamingConventions")
|
||||
private static final Gson gson = new JSON().getGson();
|
||||
private static final Gson gson = JSON.getGson();
|
||||
@SuppressWarnings("PMD.FieldNamingConventions")
|
||||
private static final ObjectMapper objectMapper
|
||||
= new ObjectMapper().registerModule(new JavaTimeModule());
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.jdrupes.vmoperator.common;
|
|||
import io.kubernetes.client.Discovery.APIResource;
|
||||
import io.kubernetes.client.apimachinery.GroupVersionKind;
|
||||
import io.kubernetes.client.openapi.ApiException;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import io.kubernetes.client.util.generic.options.ListOptions;
|
||||
import java.io.Reader;
|
||||
import java.util.Collection;
|
||||
|
|
@ -101,8 +102,8 @@ public class VmDefinitionStub
|
|||
*/
|
||||
public static VmDefinitionStub createFromYaml(K8sClient client,
|
||||
APIResource context, Reader yaml) throws ApiException {
|
||||
var model = new VmDefinition(client.getJSON().getGson(),
|
||||
K8s.yamlToJson(client, yaml));
|
||||
var model
|
||||
= new VmDefinition(JSON.getGson(), K8s.yamlToJson(client, yaml));
|
||||
return K8sGenericStub.create(VmDefinition.class,
|
||||
VmDefinitions.class, client, context, model,
|
||||
(c, ns, n) -> new VmDefinitionStub(c, context, ns, n));
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import com.google.gson.Gson;
|
|||
import freemarker.template.Configuration;
|
||||
import freemarker.template.TemplateException;
|
||||
import io.kubernetes.client.openapi.ApiException;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import io.kubernetes.client.openapi.models.V1APIService;
|
||||
import io.kubernetes.client.openapi.models.V1ObjectMeta;
|
||||
import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesObject;
|
||||
|
|
@ -122,7 +123,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
|||
? (Map<String, Map<String, String>>) lbsDef
|
||||
: null;
|
||||
var client = channel.client();
|
||||
mergeMetadata(client.getJSON().getGson(), svcDef, defaults, vmDef);
|
||||
mergeMetadata(JSON.getGson(), svcDef, defaults, vmDef);
|
||||
|
||||
// Apply
|
||||
var svcStub = K8sV1ServiceStub
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.jdrupes.vmoperator.manager;
|
|||
import com.google.gson.JsonObject;
|
||||
import io.kubernetes.client.apimachinery.GroupVersionKind;
|
||||
import io.kubernetes.client.openapi.ApiException;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import io.kubernetes.client.util.Watch;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
|
@ -130,7 +131,7 @@ public class PoolMonitor extends
|
|||
|
||||
// Get pool and merge changes
|
||||
var vmPool = pools.computeIfAbsent(poolName, k -> new VmPool(poolName));
|
||||
vmPool.defineFrom(client().getJSON().getGson().fromJson(
|
||||
vmPool.defineFrom(JSON.getGson().fromJson(
|
||||
GsonPtr.to(poolModel.data()).to("spec").get(), VmPool.class));
|
||||
poolPipeline.fire(new VmPoolChanged(vmPool));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import freemarker.template.TemplateException;
|
|||
import freemarker.template.TemplateNotFoundException;
|
||||
import io.kubernetes.client.custom.V1Patch;
|
||||
import io.kubernetes.client.openapi.ApiException;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import io.kubernetes.client.util.generic.dynamic.Dynamics;
|
||||
import io.kubernetes.client.util.generic.options.ListOptions;
|
||||
import io.kubernetes.client.util.generic.options.PatchOptions;
|
||||
|
|
@ -160,8 +161,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
|||
opts.setForce(true);
|
||||
opts.setFieldManager("kubernetes-java-kubectl-apply");
|
||||
if (pvcStub.patch(V1Patch.PATCH_FORMAT_APPLY_YAML,
|
||||
new V1Patch(channel.client().getJSON().serialize(pvcDef)), opts)
|
||||
.isEmpty()) {
|
||||
new V1Patch(JSON.serialize(pvcDef)), opts).isEmpty()) {
|
||||
logger.warning(
|
||||
() -> "Could not patch pvc for " + pvcStub.name());
|
||||
}
|
||||
|
|
@ -203,8 +203,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
|||
opts.setForce(true);
|
||||
opts.setFieldManager("kubernetes-java-kubectl-apply");
|
||||
if (pvcStub.patch(V1Patch.PATCH_FORMAT_APPLY_YAML,
|
||||
new V1Patch(channel.client().getJSON().serialize(pvcDef)), opts)
|
||||
.isEmpty()) {
|
||||
new V1Patch(JSON.serialize(pvcDef)), opts).isEmpty()) {
|
||||
logger.warning(
|
||||
() -> "Could not patch pvc for " + pvcStub.name());
|
||||
}
|
||||
|
|
@ -218,8 +217,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
|||
PatchOptions opts = new PatchOptions();
|
||||
opts.setFieldManager("kubernetes-java-kubectl-apply");
|
||||
if (pvcStub.patch(V1Patch.PATCH_FORMAT_JSON_MERGE_PATCH,
|
||||
new V1Patch(channel.client().getJSON().serialize(pvcDef)), opts)
|
||||
.isEmpty()) {
|
||||
new V1Patch(JSON.serialize(pvcDef)), opts).isEmpty()) {
|
||||
logger.warning(
|
||||
() -> "Could not patch pvc for " + pvcStub.name());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ import org.jgrapes.core.events.Start;
|
|||
public class StatusUpdater extends VmDefUpdater {
|
||||
|
||||
@SuppressWarnings("PMD.FieldNamingConventions")
|
||||
private static final Gson gson = new JSON().getGson();
|
||||
private static final Gson gson = JSON.getGson();
|
||||
@SuppressWarnings("PMD.FieldNamingConventions")
|
||||
private static final ObjectMapper objectMapper
|
||||
= new ObjectMapper().registerModule(new JavaTimeModule());
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
package org.jdrupes.vmoperator.runner.qemu;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
|
@ -161,8 +162,7 @@ public class VmDefUpdater extends Component {
|
|||
: cond)
|
||||
.collect(Collectors.toCollection(() -> new ArrayList<>()));
|
||||
newConds.addAll(toReplace);
|
||||
status.add("conditions",
|
||||
apiClient.getJSON().getGson().toJsonTree(newConds));
|
||||
status.add("conditions", JSON.getGson().toJsonTree(newConds));
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue