Skip to content

Commit

Permalink
Fix eclipse-jkube#267: openshift-maven-plugin does not update Routes
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Trejo <[email protected]>
Signed-off-by: Tue Dissing <[email protected]>
  • Loading branch information
mtrejo authored and manusa committed Jul 16, 2020
1 parent 00c7623 commit a0ecb56
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ protected <T extends HasMetadata,L,D> void doCreateResource(T resource, String n

private <T extends HasMetadata> void doPatchEntity(T oldEntity, T newEntity, String namespace, String sourceName) {
String kind = newEntity.getKind();
log.info("Updating {} from {}", kind, sourceName);
log.info("Updating %s from %s", kind, sourceName);
try {
Object answer = patchService.compareAndPatchEntity(namespace, newEntity, oldEntity);
logGeneratedEntity("Updated " + kind + ": ", namespace, newEntity, answer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/**
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

package org.eclipse.jkube.kit.config.service;

import io.fabric8.openshift.api.model.Route;
Expand All @@ -9,6 +23,7 @@
import org.junit.Before;
import org.junit.Test;

import static java.net.HttpURLConnection.*;
import static org.junit.Assert.assertEquals;

public class ApplyServiceTest {
Expand All @@ -32,26 +47,55 @@ public void testCreateRoute() throws Exception {
WebServerEventCollector<OpenShiftMockServer> collector = new WebServerEventCollector<>(mockServer);
mockServer.expect().get()
.withPath("/apis/route.openshift.io/v1/namespaces/default/routes/route")
.andReply(collector.record("get-route").andReturn(404, ""))
.andReply(collector.record("get-route").andReturn(HTTP_NOT_FOUND, ""))
.always();
mockServer.expect().post()
.withPath("/apis/route.openshift.io/v1/namespaces/default/routes")
.andReply(collector.record("new-route").andReturn(201, route))
.andReply(collector.record("new-route").andReturn(HTTP_CREATED, route))
.once();

applyService.apply(route, "route.yml");

collector.assertEventsRecordedInOrder("get-route", "new-route");
}

@Test
public void testUpdateRoute() throws Exception {
Route oldRoute = buildRoute();
Route newRoute = new RouteBuilder()
.withNewMetadataLike(oldRoute.getMetadata())
.addToAnnotations("haproxy.router.openshift.io/balance", "roundrobin")
.endMetadata()
.withSpec(oldRoute.getSpec())
.build();

WebServerEventCollector<OpenShiftMockServer> collector = new WebServerEventCollector<>(mockServer);
mockServer.expect().get()
.withPath("/apis/route.openshift.io/v1/namespaces/default/routes/route")
.andReply(collector.record("get-route").andReturn(HTTP_OK, oldRoute))
.always();
mockServer.expect().patch()
.withPath("/apis/route.openshift.io/v1/namespaces/default/routes/route")
.andReply(collector.record("patch-route")
.andReturn(HTTP_OK, new RouteBuilder()
.withMetadata(newRoute.getMetadata())
.withSpec(oldRoute.getSpec())
.build()))
.once();

applyService.apply(newRoute, "route.yml");

collector.assertEventsRecordedInOrder("get-route", "patch-route");
}

@Test
public void testCreateRouteInServiceOnlyMode() throws Exception {
Route route = buildRoute();

WebServerEventCollector<OpenShiftMockServer> collector = new WebServerEventCollector<>(mockServer);
mockServer.expect().get()
.withPath("/apis/route.openshift.io/v1/namespaces/default/routes/route")
.andReply(collector.record("get-route").andReturn(404, ""))
.andReply(collector.record("get-route").andReturn(HTTP_NOT_FOUND, ""))
.always();

applyService.setServicesOnlyMode(true);
Expand All @@ -68,7 +112,7 @@ public void testCreateRouteNotAllowed() throws Exception {
WebServerEventCollector<OpenShiftMockServer> collector = new WebServerEventCollector<>(mockServer);
mockServer.expect().get()
.withPath("/apis/route.openshift.io/v1/namespaces/default/routes/route")
.andReply(collector.record("get-route").andReturn(404, ""))
.andReply(collector.record("get-route").andReturn(HTTP_NOT_FOUND, ""))
.always();

applyService.setAllowCreate(false);
Expand All @@ -81,6 +125,7 @@ public void testCreateRouteNotAllowed() throws Exception {
private Route buildRoute() {
return new RouteBuilder()
.withNewMetadata()
.withNamespace("default")
.withName("route")
.endMetadata()
.withNewSpec()
Expand Down

0 comments on commit a0ecb56

Please sign in to comment.