use of io.kubernetes.client.openapi.models.V1ConfigMap in project heron by twitter.
the class V1ControllerTest method testLoadPodFromTemplateValidConfigMap.
@Test
public void testLoadPodFromTemplateValidConfigMap() {
final String expected = " containers: [class V1Container {\n" + " args: null\n" + " command: null\n" + " env: null\n" + " envFrom: null\n" + " image: apache/heron:latest\n" + " imagePullPolicy: null\n" + " lifecycle: null\n" + " livenessProbe: null\n" + " name: heron-tracker\n" + " ports: [class V1ContainerPort {\n" + " containerPort: 8888\n" + " hostIP: null\n" + " hostPort: null\n" + " name: api-port\n" + " protocol: null\n" + " }]\n" + " readinessProbe: null\n" + " resources: class V1ResourceRequirements {\n" + " limits: {cpu=Quantity{number=0.400, format=DECIMAL_SI}, " + "memory=Quantity{number=512000000, format=DECIMAL_SI}}\n" + " requests: {cpu=Quantity{number=0.100, format=DECIMAL_SI}, " + "memory=Quantity{number=200000000, format=DECIMAL_SI}}\n" + " }\n" + " securityContext: null\n" + " startupProbe: null\n" + " stdin: null\n" + " stdinOnce: null\n" + " terminationMessagePath: null\n" + " terminationMessagePolicy: null\n" + " tty: null\n" + " volumeDevices: null\n" + " volumeMounts: null\n" + " workingDir: null\n" + " }]";
// ConfigMap with valid Pod Template.
final V1ConfigMap configMapValidPod = new V1ConfigMapBuilder().withNewMetadata().withName(CONFIGMAP_NAME).endMetadata().addToData(POD_TEMPLATE_NAME, POD_TEMPLATE_VALID).build();
// Test case container.
// Input: ConfigMap to setup mock V1Controller, Boolean flag for executor/manager switch.
// Output: The expected Pod template as a string.
final List<TestTuple<Pair<V1ConfigMap, Boolean>, String>> testCases = new LinkedList<>();
testCases.add(new TestTuple<>("Executor valid Pod Template", new Pair<>(configMapValidPod, true), expected));
testCases.add(new TestTuple<>("Manager valid Pod Template", new Pair<>(configMapValidPod, false), expected));
// Test loop.
for (TestTuple<Pair<V1ConfigMap, Boolean>, String> testCase : testCases) {
doReturn(testCase.input.first).when(v1ControllerWithPodTemplate).getConfigMap(anyString());
V1PodTemplateSpec podTemplateSpec = v1ControllerWithPodTemplate.loadPodFromTemplate(true);
Assert.assertTrue(podTemplateSpec.toString().contains(testCase.expected));
}
}
use of io.kubernetes.client.openapi.models.V1ConfigMap in project heron by twitter.
the class V1ControllerTest method testLoadPodFromTemplateNoTargetConfigMap.
@Test
public void testLoadPodFromTemplateNoTargetConfigMap() {
final List<TestTuple<Boolean, String>> testCases = new LinkedList<>();
testCases.add(new TestTuple<>("Executor no target ConfigMap", true, "Failed to locate Pod Template"));
testCases.add(new TestTuple<>("Manager no target ConfigMap", false, "Failed to locate Pod Template"));
final V1ConfigMap configMapNoTargetData = new V1ConfigMapBuilder().withNewMetadata().withName(CONFIGMAP_NAME).endMetadata().addToData("Dummy Key", "Dummy Value").build();
for (TestTuple<Boolean, String> testCase : testCases) {
doReturn(configMapNoTargetData).when(v1ControllerWithPodTemplate).getConfigMap(anyString());
String message = "";
try {
v1ControllerWithPodTemplate.loadPodFromTemplate(testCase.input);
} catch (TopologySubmissionException e) {
message = e.getMessage();
}
Assert.assertTrue(testCase.description, message.contains(testCase.expected));
}
}
use of io.kubernetes.client.openapi.models.V1ConfigMap in project heron by twitter.
the class V1ControllerTest method testLoadPodFromTemplateInvalidConfigMap.
@Test
public void testLoadPodFromTemplateInvalidConfigMap() {
// ConfigMap with an invalid Pod Template.
final String invalidPodTemplate = "apiVersion: apps/v1\n" + "kind: InvalidTemplate\n" + "metadata:\n" + " name: heron-tracker\n" + " namespace: default\n" + "template:\n" + " metadata:\n" + " labels:\n" + " app: heron-tracker\n" + " spec:\n";
final V1ConfigMap configMap = new V1ConfigMapBuilder().withNewMetadata().withName(CONFIGMAP_NAME).endMetadata().addToData(POD_TEMPLATE_NAME, invalidPodTemplate).build();
// Test case container.
// Input: ConfigMap to setup mock V1Controller, Boolean flag for executor/manager switch.
// Output: The expected Pod template as a string.
final List<TestTuple<Pair<V1ConfigMap, Boolean>, String>> testCases = new LinkedList<>();
testCases.add(new TestTuple<>("Executor invalid Pod Template", new Pair<>(configMap, true), "Error parsing"));
testCases.add(new TestTuple<>("Manager invalid Pod Template", new Pair<>(configMap, false), "Error parsing"));
// Test loop.
for (TestTuple<Pair<V1ConfigMap, Boolean>, String> testCase : testCases) {
doReturn(testCase.input.first).when(v1ControllerWithPodTemplate).getConfigMap(anyString());
String message = "";
try {
v1ControllerWithPodTemplate.loadPodFromTemplate(testCase.input.second);
} catch (TopologySubmissionException e) {
message = e.getMessage();
}
Assert.assertTrue(message.contains(testCase.expected));
}
}
use of io.kubernetes.client.openapi.models.V1ConfigMap in project java by kubernetes-client.
the class CoreV1Api method patchNamespacedConfigMapAsync.
/**
* (asynchronously) partially update the specified ConfigMap
*
* @param name name of the ConfigMap (required)
* @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. This field is
* required for apply requests (application/apply-patch) but optional for non-apply patch
* types (JsonPatch, MergePatch, StrategicMergePatch). (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)
* @param force Force is going to \"force\" Apply requests. It means user will
* re-acquire conflicting fields owned by other people. Force flag must be unset for non-apply
* patch requests. (optional)
* @param _callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
* @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> 401 </td><td> Unauthorized </td><td> - </td></tr>
* </table>
*/
public okhttp3.Call patchNamespacedConfigMapAsync(String name, String namespace, V1Patch body, String pretty, String dryRun, String fieldManager, String fieldValidation, Boolean force, final ApiCallback<V1ConfigMap> _callback) throws ApiException {
okhttp3.Call localVarCall = patchNamespacedConfigMapValidateBeforeCall(name, namespace, body, pretty, dryRun, fieldManager, fieldValidation, force, _callback);
Type localVarReturnType = new TypeToken<V1ConfigMap>() {
}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
use of io.kubernetes.client.openapi.models.V1ConfigMap in project java by kubernetes-client.
the class ConfigMapLock method get.
@Override
public LeaderElectionRecord get() throws ApiException {
V1ConfigMap configMap = coreV1Client.readNamespacedConfigMap(name, namespace, null);
configMapRefer.set(configMap);
Map<String, String> annotations = configMap.getMetadata().getAnnotations();
if (annotations == null || annotations.isEmpty()) {
configMap.getMetadata().setAnnotations(new HashMap<>());
}
String recordRawStringContent = configMap.getMetadata().getAnnotations().get(LeaderElectionRecordAnnotationKey);
if (StringUtils.isEmpty(recordRawStringContent)) {
return new LeaderElectionRecord();
}
LeaderElectionRecord record = coreV1Client.getApiClient().getJSON().deserialize(recordRawStringContent, LeaderElectionRecord.class);
return record;
}
Aggregations