Skip to content

Commit

Permalink
Fix PatchServiceTest assertion to pick first non blank body
Browse files Browse the repository at this point in the history
Remove hardcoded get() from collector.getBodies() which was causing
IndexOutOfBoundsException since number of GET requests made in edit() method
have now reduced by one
  • Loading branch information
rohanKanojia authored and manusa committed Jun 28, 2021
1 parent 1ec8528 commit 4358c25
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ protected void applyJob(Job job, String sourceName) {
doCreateJob(job, currentNamespace, sourceName);
} catch (KubernetesClientException exception) {
if(exception.getStatus().getCode().equals(HttpURLConnection.HTTP_CONFLICT)) {
Job old = kubernetesClient.batch().jobs().inNamespace(currentNamespace).withName(id).get();
Job old = kubernetesClient.batch().v1().jobs().inNamespace(currentNamespace).withName(id).get();
Job updatedJob = patchService.compareAndPatchEntity(currentNamespace, job, old);
log.info("Updated Job: " + updatedJob.getMetadata().getName());
return;
Expand All @@ -1217,7 +1217,7 @@ protected void applyJob(Job job, String sourceName) {
}

public void doCreateJob(Job job, String namespace, String sourceName) {
kubernetesClient.batch().jobs().inNamespace(namespace).create(job);
kubernetesClient.batch().v1().jobs().inNamespace(namespace).create(job);
log.info("Creating a Job from " + sourceName + " namespace " + namespace + " name " + getName(job));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private static EntityPatcher<Job> jobPatcher() {
return oldObj;
}

JobBuilder entity = new JobBuilder(client.batch().jobs().withName(oldObj.getMetadata().getName()).fromServer().get());
JobBuilder entity = new JobBuilder(client.batch().v1().jobs().withName(oldObj.getMetadata().getName()).fromServer().get());

if (!UserConfigurationCompare.configEqual(newObj.getMetadata(), oldObj.getMetadata())) {
entity.withMetadata(newObj.getMetadata());
Expand All @@ -271,7 +271,7 @@ private static EntityPatcher<Job> jobPatcher() {
entity.editSpec().withTemplate(newObj.getSpec().getTemplate());
}

return client.batch().jobs().withName(oldObj.getMetadata().getName()).edit(p -> entity.build());
return client.batch().v1().jobs().withName(oldObj.getMetadata().getName()).edit(p -> entity.build());
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void testResourcePatching() {
}

@Test
public void testSecretPatching() {
public void testSecretPatching() throws InterruptedException {
Secret oldSecret = new SecretBuilder()
.withNewMetadata().withName("secret").endMetadata()
.addToData("test", "dGVzdA==")
Expand All @@ -97,7 +97,9 @@ public void testSecretPatching() {

patchService.compareAndPatchEntity("test", newSecret, oldSecret);
collector.assertEventsRecordedInOrder("get-secret", "get-secret", "patch-secret");
assertEquals("[{\"op\":\"remove\",\"path\":\"/data\"},{\"op\":\"add\",\"path\":\"/stringData\",\"value\":{\"test\":\"test\"}}]", collector.getBodies().get(3));
// Due to recent patch related improvements in KubernetesClient now edit call requires 2 GET requests
// for resource from server instead of 3 GET requests.
assertEquals("[{\"op\":\"remove\",\"path\":\"/data\"},{\"op\":\"add\",\"path\":\"/stringData\",\"value\":{\"test\":\"test\"}}]", collector.getBodies().get(2));

}

Expand Down

0 comments on commit 4358c25

Please sign in to comment.