-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Append ClusterIP fetched from Service from Kubernetes API to the Service loaded from resource manifests in order to avoid patch error Signed-off-by: Rohan Kumar <[email protected]>
- Loading branch information
1 parent
798aec3
commit 00c878f
Showing
3 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...src/test/java/org/eclipse/jkube/kit/config/service/ApplyServiceWithoutMockServerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* 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.kubernetes.api.model.IntOrString; | ||
import io.fabric8.kubernetes.api.model.Service; | ||
import io.fabric8.kubernetes.api.model.ServiceBuilder; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import mockit.Expectations; | ||
import mockit.Mocked; | ||
import mockit.Verifications; | ||
import org.eclipse.jkube.kit.common.KitLogger; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.Objects; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
public class ApplyServiceWithoutMockServerTest { | ||
private ApplyService applyService; | ||
|
||
@Mocked | ||
private KubernetesClient client; | ||
|
||
@Mocked | ||
private KitLogger log; | ||
|
||
@Mocked | ||
private PatchService patchService; | ||
|
||
@Before | ||
public void setUp() { | ||
patchService = new PatchService(client, log); | ||
applyService = new ApplyService(client, patchService, log); | ||
applyService.setNamespace("default"); | ||
} | ||
|
||
@Test | ||
public void testServiceRedeploy() { | ||
Service serviceManifest = createServiceBuilder() | ||
.editSpec().withType("ClusterIP").endSpec() | ||
.build(); | ||
Service serviceFromServer = createServiceBuilder() | ||
.editSpec().withClusterIP("12.23.43.12").endSpec() | ||
.build(); | ||
new Expectations() {{ | ||
client.services().inNamespace("default").withName("foo-svc").get(); | ||
result = serviceFromServer; | ||
}}; | ||
|
||
applyService.applyService(serviceManifest, "test"); | ||
|
||
new Verifications() {{ | ||
Service finalMergedSvc = null; | ||
patchService.compareAndPatchEntity("default", finalMergedSvc = withCapture(), serviceFromServer); | ||
|
||
assertThat(finalMergedSvc).isNotNull() | ||
.hasFieldOrPropertyWithValue("metadata.name", "foo-svc") | ||
.hasFieldOrPropertyWithValue("spec.clusterIP", "12.23.43.12") | ||
.hasFieldOrPropertyWithValue("spec.type", "ClusterIP"); | ||
}}; | ||
} | ||
|
||
private ServiceBuilder createServiceBuilder() { | ||
return new ServiceBuilder() | ||
.withNewMetadata().withName("foo-svc").endMetadata() | ||
.withNewSpec() | ||
.addToSelector(Collections.singletonMap("foo", "bar")) | ||
.addNewPort() | ||
.withProtocol("TCP") | ||
.withPort(80) | ||
.withTargetPort(new IntOrString(9376)) | ||
.endPort() | ||
.endSpec(); | ||
} | ||
} |