use of io.kubernetes.client.openapi.models.V1ConfigMap in project java by kubernetes-client.
the class ConfigMapLock method create.
@Override
public boolean create(LeaderElectionRecord record) {
try {
V1ConfigMap configMap = new V1ConfigMap();
V1ObjectMeta objectMeta = new V1ObjectMeta();
objectMeta.setName(name);
objectMeta.setNamespace(namespace);
Map<String, String> annotations = new HashMap<>();
annotations.put(LeaderElectionRecordAnnotationKey, coreV1Client.getApiClient().getJSON().serialize(record));
objectMeta.setAnnotations(annotations);
if (record.getOwnerReference() != null) {
objectMeta.setOwnerReferences(Collections.singletonList(record.getOwnerReference()));
}
configMap.setMetadata(objectMeta);
V1ConfigMap createdConfigMap = coreV1Client.createNamespacedConfigMap(namespace, configMap, null, null, null, null);
configMapRefer.set(createdConfigMap);
return true;
} catch (ApiException e) {
if (e.getCode() == HttpURLConnection.HTTP_CONFLICT) {
log.debug("received {} when creating configmap lock", e.getCode(), e);
} else {
log.error("received {} when creating configmap lock", e.getCode(), e);
}
return false;
}
}
use of io.kubernetes.client.openapi.models.V1ConfigMap in project java by kubernetes-client.
the class ConfigMapLock method update.
@Override
public boolean update(LeaderElectionRecord record) {
try {
V1ConfigMap configMap = configMapRefer.get();
configMap.getMetadata().putAnnotationsItem(LeaderElectionRecordAnnotationKey, coreV1Client.getApiClient().getJSON().serialize(record));
// TODO consider to retry if receiving a 409 code
V1ConfigMap replacedConfigMap = coreV1Client.replaceNamespacedConfigMap(name, namespace, configMap, null, null, null, null);
configMapRefer.set(replacedConfigMap);
return true;
} catch (ApiException e) {
if (e.getCode() == HttpURLConnection.HTTP_CONFLICT) {
log.debug("received {} when updating configmap lock", e.getCode(), e);
} else {
log.error("received {} when updating configmap lock", e.getCode(), e);
}
return false;
}
}
use of io.kubernetes.client.openapi.models.V1ConfigMap in project java by kubernetes-client.
the class KubernetesInformerCreatorTest method testInformerInjection.
@Test
public void testInformerInjection() throws InterruptedException {
assertNotNull(podInformer);
assertNotNull(configMapInformer);
Semaphore getCount = new Semaphore(2);
Semaphore watchCount = new Semaphore(2);
Parameters getParams = new Parameters();
Parameters watchParams = new Parameters();
getParams.put("semaphore", getCount);
watchParams.put("semaphore", watchCount);
V1Pod foo1 = new V1Pod().kind("Pod").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
V1ConfigMap bar1 = new V1ConfigMap().kind("ConfigMap").metadata(new V1ObjectMeta().namespace("default").name("bar1"));
wireMockRule.stubFor(get(urlMatching("^/api/v1/pods.*")).withPostServeAction("semaphore", getParams).withQueryParam("watch", equalTo("false")).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1PodList().metadata(new V1ListMeta().resourceVersion("0")).items(Arrays.asList(foo1))))));
wireMockRule.stubFor(get(urlMatching("^/api/v1/pods.*")).withPostServeAction("semaphore", watchParams).withQueryParam("watch", equalTo("true")).willReturn(aResponse().withStatus(200).withBody("{}")));
wireMockRule.stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).withPostServeAction("semaphore", getParams).withQueryParam("watch", equalTo("false")).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1ConfigMapList().metadata(new V1ListMeta().resourceVersion("0")).items(Arrays.asList(bar1))))));
wireMockRule.stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).withPostServeAction("semaphore", watchParams).withQueryParam("watch", equalTo("true")).willReturn(aResponse().withStatus(200).withBody("{}")));
// These will be released for each web call above.
getCount.acquire(2);
watchCount.acquire(2);
informerFactory.startAllRegisteredInformers();
// Wait for the GETs to complete and the watches to start.
getCount.acquire(2);
watchCount.acquire(2);
verify(1, getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("false")));
verify(getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("true")));
verify(1, getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/configmaps")).withQueryParam("watch", equalTo("false")));
verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/configmaps")).withQueryParam("watch", equalTo("true")));
assertEquals(1, new Lister<>(podInformer.getIndexer()).list().size());
assertEquals(1, new Lister<>(configMapInformer.getIndexer()).list().size());
}
use of io.kubernetes.client.openapi.models.V1ConfigMap in project java by kubernetes-client.
the class WatchTest method testWatchEnd.
@Test
public void testWatchEnd() throws IOException {
JSON json = new JSON();
Watch<V1ConfigMap> watch = new Watch<V1ConfigMap>(json, null, new TypeToken<Watch.Response<V1ConfigMap>>() {
}.getType(), null);
JsonObject metadata = new JsonObject();
metadata.addProperty("name", "foo");
metadata.addProperty("namespace", "bar");
JsonObject status = new JsonObject();
status.add("metadata", metadata);
status.addProperty("kind", "Status");
status.addProperty("apiVersion", "v1");
status.addProperty("status", "failure");
status.addProperty("message", "too old resource version");
status.addProperty("reason", "Gone");
status.addProperty("code", 410);
JsonObject obj = new JsonObject();
obj.addProperty("type", "ERROR");
obj.add("object", status);
String data = json.getGson().toJson(obj);
Watch.Response<V1ConfigMap> response = watch.parseLine(data);
assertEquals(null, response.object);
}
use of io.kubernetes.client.openapi.models.V1ConfigMap in project java by kubernetes-client.
the class CoreV1Api method createNamespacedConfigMapWithHttpInfo.
/**
* create a ConfigMap
*
* @param namespace object name and auth scope, such as for teams and projects (required)
* @param body (required)
* @param pretty If 'true', then the output is pretty printed. (optional)
* @param dryRun When present, indicates that modifications should not be persisted. An invalid or
* unrecognized dryRun directive will result in an error response and no further processing of
* the request. Valid values are: - All: all dry run stages will be processed (optional)
* @param fieldManager fieldManager is a name associated with the actor or entity that is making
* these changes. The value must be less than or 128 characters long, and only contain
* printable characters, as defined by https://golang.org/pkg/unicode/#IsPrint. (optional)
* @param fieldValidation fieldValidation determines how the server should respond to
* unknown/duplicate fields in the object in the request. Introduced as alpha in 1.23, older
* servers or servers with the `ServerSideFieldValidation` feature disabled will
* discard valid values specified in this param and not perform any server side field
* validation. Valid values are: - Ignore: ignores unknown/duplicate fields. - Warn: responds
* with a warning for each unknown/duplicate field, but successfully serves the request. -
* Strict: fails the request on unknown/duplicate fields. (optional)
* @return ApiResponse<V1ConfigMap>
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the
* response body
* @http.response.details
* <table summary="Response Details" border="1">
* <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
* <tr><td> 200 </td><td> OK </td><td> - </td></tr>
* <tr><td> 201 </td><td> Created </td><td> - </td></tr>
* <tr><td> 202 </td><td> Accepted </td><td> - </td></tr>
* <tr><td> 401 </td><td> Unauthorized </td><td> - </td></tr>
* </table>
*/
public ApiResponse<V1ConfigMap> createNamespacedConfigMapWithHttpInfo(String namespace, V1ConfigMap body, String pretty, String dryRun, String fieldManager, String fieldValidation) throws ApiException {
okhttp3.Call localVarCall = createNamespacedConfigMapValidateBeforeCall(namespace, body, pretty, dryRun, fieldManager, fieldValidation, null);
Type localVarReturnType = new TypeToken<V1ConfigMap>() {
}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}
Aggregations