From 379d5bf7f60ba1d86de2055be867a788b66bba2b Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Wed, 30 Jun 2021 17:25:43 +0530 Subject: [PATCH] Fix #253: Refactor JKubeServiceHub's BuildService election mechanism + Use ServiceLoader to load all Build Services and pick up service which is applicable in current context. This requires BuildService implementations to have zero-arg constructors so I need to set the elements from setters instead. + Added isApplicable(), setJKubeServiceHub(), methods in BuildService interface Signed-off-by: Rohan Kumar --- CHANGELOG.md | 1 + .../kit/config/service/BuildService.java | 14 +++++ .../kit/config/service/JKubeServiceHub.java | 43 +++++++------- .../kubernetes/DockerBuildService.java | 14 ++++- .../service/kubernetes/JibBuildService.java | 23 ++++++-- .../openshift/OpenshiftBuildService.java | 59 ++++++++++++++----- ...ipse.jkube.kit.config.service.BuildService | 3 + .../config/service/JKubeServiceHubTest.java | 50 +++++++--------- .../kubernetes/DockerBuildServiceTest.java | 1 + .../JibBuildServiceBuildIntegrationTest.java | 3 +- .../kubernetes/JibBuildServiceTest.java | 4 +- .../openshift/OpenshiftBuildServiceTest.java | 31 +++++----- 12 files changed, 157 insertions(+), 89 deletions(-) create mode 100644 jkube-kit/config/service/src/main/resources/META-INF/services/org.eclipse.jkube.kit.config.service.BuildService diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d1cb8403d..f0cd4f21f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Usage: ./scripts/extract-changelog-for-version.sh 1.3.37 5 ``` ### 1.4.0-SNAPSHOT +* Fix #253: Refactor JKubeServiceHub's BuildService election mechanism via ServiceLoader * Fix #741: Private constructor added to Utility classes * Fix #725: Upgrade HttpClient from 4.5.10 to 4.5.13 * Fix #653: `k8s:watch` port-forward websocket error due to wrong arguments in PortForwardService diff --git a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/BuildService.java b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/BuildService.java index 68bd0c55c8..c596efe0c1 100644 --- a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/BuildService.java +++ b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/BuildService.java @@ -48,4 +48,18 @@ public interface BuildService { */ void postProcess(BuildServiceConfig config); + /** + * Check whether provided Build Service implementation is applicable in current context or not. + * + * @param jKubeServiceHub {@link JKubeServiceHub} + * @return boolean value specifying whether provided BuildService implementation should be used. + */ + boolean isApplicable(JKubeServiceHub jKubeServiceHub); + + /** + * Set {@link JKubeServiceHub} + * + * @param jKubeServiceHub {@link JKubeServiceHub} + */ + void setJKubeServiceHub(JKubeServiceHub jKubeServiceHub); } diff --git a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/JKubeServiceHub.java b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/JKubeServiceHub.java index 1493bfdda1..2c94db933a 100644 --- a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/JKubeServiceHub.java +++ b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/JKubeServiceHub.java @@ -14,8 +14,10 @@ package org.eclipse.jkube.kit.config.service; import java.io.Closeable; +import java.util.Iterator; import java.util.Objects; import java.util.Optional; +import java.util.ServiceLoader; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.openshift.client.OpenShiftClient; @@ -30,11 +32,8 @@ import org.eclipse.jkube.kit.common.util.LazyBuilder; import org.eclipse.jkube.kit.config.access.ClusterAccess; import org.eclipse.jkube.kit.config.access.ClusterConfiguration; -import org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy; import org.eclipse.jkube.kit.common.JKubeConfiguration; import org.eclipse.jkube.kit.config.resource.RuntimeMode; -import org.eclipse.jkube.kit.config.service.kubernetes.DockerBuildService; -import org.eclipse.jkube.kit.config.service.kubernetes.JibBuildService; import org.eclipse.jkube.kit.config.service.kubernetes.KubernetesUndeployService; import org.eclipse.jkube.kit.config.service.openshift.OpenshiftBuildService; import org.eclipse.jkube.kit.config.service.openshift.OpenshiftUndeployService; @@ -53,6 +52,7 @@ public class JKubeServiceHub implements Closeable { @Getter @Setter private RuntimeMode platformMode; + @Getter private KitLogger log; @Getter private ServiceHub dockerServiceHub; @@ -166,25 +166,7 @@ private void initClusterAccessAndLazyBuilders() { } return new KubernetesUndeployService(this, log); }); - buildService = new LazyBuilder<>(() -> { - BuildService ret; - if (JKubeBuildStrategy.jib == buildServiceConfig.getJKubeBuildStrategy()) { - return new JibBuildService(JKubeServiceHub.this, log); - } - // Creating platform-dependent services - if (platformMode == RuntimeMode.OPENSHIFT) { - validateIfConnectedToCluster(); - if (!isOpenShift(client)) { - throw new IllegalStateException("OpenShift platform has been specified but OpenShift has not been detected!"); - } - // OpenShift services - ret = new OpenshiftBuildService((OpenShiftClient) client, log, JKubeServiceHub.this); - } else { - // Kubernetes services - ret = new DockerBuildService(JKubeServiceHub.this); - } - return ret; - }); + buildService = new LazyBuilder<>(this::resolveBuildService); } private void validateIfConnectedToCluster() { @@ -192,4 +174,21 @@ private void validateIfConnectedToCluster() { throw new IllegalArgumentException("Connection to Cluster required. Please check if offline mode is set to false"); } } + + private BuildService resolveBuildService() { + ServiceLoader buildServices = ServiceLoader.load(BuildService.class, Thread.currentThread().getContextClassLoader()); + Iterator buildServiceIterator = buildServices.iterator(); + + BuildService selectedBuildService = null; + while (buildServiceIterator.hasNext()) { + BuildService b = buildServiceIterator.next(); + if (b.isApplicable(JKubeServiceHub.this)) { + selectedBuildService = b; + selectedBuildService.setJKubeServiceHub(JKubeServiceHub.this); + break; + } + } + + return selectedBuildService; + } } diff --git a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/kubernetes/DockerBuildService.java b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/kubernetes/DockerBuildService.java index a7fdc908ed..297d40b758 100644 --- a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/kubernetes/DockerBuildService.java +++ b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/kubernetes/DockerBuildService.java @@ -19,6 +19,7 @@ import org.eclipse.jkube.kit.config.image.ImageConfiguration; import org.eclipse.jkube.kit.common.RegistryConfig; +import org.eclipse.jkube.kit.config.resource.RuntimeMode; import org.eclipse.jkube.kit.config.service.BuildService; import org.eclipse.jkube.kit.config.service.BuildServiceConfig; import org.eclipse.jkube.kit.config.service.JKubeServiceException; @@ -32,7 +33,9 @@ public class DockerBuildService implements BuildService { private JKubeServiceHub jKubeServiceHub; - public DockerBuildService(JKubeServiceHub jKubeServiceHub) { + public DockerBuildService() { } + + DockerBuildService(JKubeServiceHub jKubeServiceHub) { Objects.requireNonNull(jKubeServiceHub.getDockerServiceHub(), "dockerServiceHub"); Objects.requireNonNull(jKubeServiceHub.getBuildServiceConfig(), "BuildServiceConfig is required"); this.jKubeServiceHub = jKubeServiceHub; @@ -68,4 +71,13 @@ public void postProcess(BuildServiceConfig config) { // No post processing required } + @Override + public boolean isApplicable(JKubeServiceHub jKubeServiceHub) { + return jKubeServiceHub.getRuntimeMode() == RuntimeMode.KUBERNETES; + } + + @Override + public void setJKubeServiceHub(JKubeServiceHub jKubeServiceHub) { + this.jKubeServiceHub = jKubeServiceHub; + } } diff --git a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildService.java b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildService.java index b4f458b5fe..03cf609297 100644 --- a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildService.java +++ b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildService.java @@ -30,6 +30,7 @@ import org.eclipse.jkube.kit.config.image.ImageName; import org.eclipse.jkube.kit.common.RegistryConfig; import org.eclipse.jkube.kit.common.JKubeConfiguration; +import org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy; import org.eclipse.jkube.kit.config.service.BuildService; import org.eclipse.jkube.kit.config.service.BuildServiceConfig; import org.eclipse.jkube.kit.config.service.JKubeServiceException; @@ -53,13 +54,14 @@ public class JibBuildService implements BuildService { "docker.io", "index.docker.io", "registry.hub.docker.com" ); private static final String PUSH_REGISTRY = "jkube.docker.push.registry"; - private final JKubeServiceHub jKubeServiceHub; - private final KitLogger log; + private JKubeServiceHub jKubeServiceHub; + private KitLogger log; - public JibBuildService(JKubeServiceHub jKubeServiceHub, KitLogger logger) { + public JibBuildService() { } + + JibBuildService(JKubeServiceHub jKubeServiceHub) { Objects.requireNonNull(jKubeServiceHub.getBuildServiceConfig(), "BuildServiceConfig is required"); - this.jKubeServiceHub = jKubeServiceHub; - this.log = logger; + setJKubeServiceHub(jKubeServiceHub); } @Override @@ -118,6 +120,17 @@ public void postProcess(BuildServiceConfig config) { // No post processing required } + @Override + public boolean isApplicable(JKubeServiceHub jKubeServiceHub) { + return jKubeServiceHub.getBuildServiceConfig().getJKubeBuildStrategy() == JKubeBuildStrategy.jib; + } + + @Override + public void setJKubeServiceHub(JKubeServiceHub jKubeServiceHub) { + this.jKubeServiceHub = jKubeServiceHub; + this.log = jKubeServiceHub.getLog(); + } + static ImageConfiguration prependRegistry(ImageConfiguration imageConfiguration, String registry) { ImageName imageName = new ImageName(imageConfiguration.getName()); if (!imageName.hasRegistry() && registry != null) { diff --git a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildService.java b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildService.java index fe7f619a7b..bd36b150e6 100644 --- a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildService.java +++ b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildService.java @@ -39,12 +39,15 @@ import org.eclipse.jkube.kit.common.util.IoUtil; import org.eclipse.jkube.kit.common.util.KubernetesHelper; import org.eclipse.jkube.kit.common.util.OpenshiftHelper; +import org.eclipse.jkube.kit.config.access.ClusterAccess; +import org.eclipse.jkube.kit.config.access.ClusterConfiguration; import org.eclipse.jkube.kit.config.image.ImageConfiguration; import org.eclipse.jkube.kit.config.image.ImageName; import org.eclipse.jkube.kit.common.RegistryConfig; import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; import org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy; import org.eclipse.jkube.kit.common.JKubeConfiguration; +import org.eclipse.jkube.kit.config.resource.RuntimeMode; import org.eclipse.jkube.kit.config.service.BuildService; import org.eclipse.jkube.kit.config.service.BuildServiceConfig; import org.eclipse.jkube.kit.config.service.JKubeServiceException; @@ -84,6 +87,7 @@ import static org.eclipse.jkube.kit.build.api.helper.BuildUtil.extractBaseFromConfiguration; +import static org.eclipse.jkube.kit.common.util.OpenshiftHelper.isOpenShift; import static org.eclipse.jkube.kit.config.service.openshift.ImageStreamService.resolveImageStreamName; /** @@ -99,28 +103,28 @@ public class OpenshiftBuildService implements BuildService { public static final String REQUESTS = "requests"; public static final String LIMITS = "limits"; - private final OpenShiftClient client; - private final KitLogger log; - private final JKubeServiceHub jKubeServiceHub; - private final BuildServiceConfig config; + private OpenShiftClient client; + private KitLogger log; + private JKubeServiceHub jKubeServiceHub; + private BuildServiceConfig config; private AuthConfigFactory authConfigFactory; + public OpenshiftBuildService() { } - public OpenshiftBuildService(OpenShiftClient client, KitLogger log, JKubeServiceHub jKubeServiceHub) { - Objects.requireNonNull(client, "client"); - Objects.requireNonNull(log, "log"); - Objects.requireNonNull(jKubeServiceHub.getConfiguration(), "JKubeConfiguration"); - Objects.requireNonNull(jKubeServiceHub.getDockerServiceHub(), "dockerServiceHub"); - Objects.requireNonNull(jKubeServiceHub.getBuildServiceConfig(), "config"); - + OpenshiftBuildService(OpenShiftClient client, JKubeServiceHub jKubeServiceHub) { this.client = client; - this.log = log; - this.jKubeServiceHub = jKubeServiceHub; - config = jKubeServiceHub.getBuildServiceConfig(); + setJKubeServiceHub(jKubeServiceHub); + } + + public void setOpenShiftClient(OpenShiftClient openShiftClient) { + this.client = openShiftClient; } @Override public void build(ImageConfiguration imageConfig) throws JKubeServiceException { + Objects.requireNonNull(jKubeServiceHub.getConfiguration(), "JKubeConfiguration"); + Objects.requireNonNull(jKubeServiceHub.getDockerServiceHub(), "dockerServiceHub"); + Objects.requireNonNull(jKubeServiceHub.getBuildServiceConfig(), "config"); String buildName = null; try { final ImageConfiguration.ImageConfigurationBuilder applicableImageConfigBuilder = imageConfig.toBuilder(); @@ -137,6 +141,7 @@ public void build(ImageConfiguration imageConfig) throws JKubeServiceException { KubernetesListBuilder builder = new KubernetesListBuilder(); // Check for buildconfig / imagestream / pullSecret and create them if necessary + initOpenShiftClient(); String openshiftPullSecret = config.getOpenshiftPullSecret(); final boolean usePullSecret = checkOrCreatePullSecret(client, builder, openshiftPullSecret, applicableImageConfig); if (usePullSecret) { @@ -232,6 +237,18 @@ public void postProcess(BuildServiceConfig config) { config.attachArtifact("is", getImageStreamFile()); } + @Override + public boolean isApplicable(JKubeServiceHub jKubeServiceHub) { + return jKubeServiceHub.getRuntimeMode() == RuntimeMode.OPENSHIFT; + } + + @Override + public void setJKubeServiceHub(JKubeServiceHub jKubeServiceHub) { + this.jKubeServiceHub = jKubeServiceHub; + this.config = jKubeServiceHub.getBuildServiceConfig(); + this.log = jKubeServiceHub.getLog(); + } + protected String updateOrCreateBuildConfig(BuildServiceConfig config, OpenShiftClient client, KubernetesListBuilder builder, ImageConfiguration imageConfig, String openshiftPullSecret) { ImageName imageName = new ImageName(imageConfig.getName()); String buildName = getS2IBuildName(config, imageName); @@ -776,4 +793,18 @@ private Map> getRequestsAndLimits() { return keyToQuantityMap; } + private void initOpenShiftClient() { + if (client == null) { + ClusterAccess clusterAccess = jKubeServiceHub.getClusterAccess(); + if (clusterAccess == null) { + clusterAccess = new ClusterAccess(log, + ClusterConfiguration.from(System.getProperties(), jKubeServiceHub.getConfiguration().getProject().getProperties()).build()); + } + client = clusterAccess.createDefaultClient(); + if (!isOpenShift(client)) { + throw new IllegalStateException("OpenShift platform has been specified but OpenShift has not been detected!"); + } + } + } + } diff --git a/jkube-kit/config/service/src/main/resources/META-INF/services/org.eclipse.jkube.kit.config.service.BuildService b/jkube-kit/config/service/src/main/resources/META-INF/services/org.eclipse.jkube.kit.config.service.BuildService new file mode 100644 index 0000000000..b130bcba13 --- /dev/null +++ b/jkube-kit/config/service/src/main/resources/META-INF/services/org.eclipse.jkube.kit.config.service.BuildService @@ -0,0 +1,3 @@ +org.eclipse.jkube.kit.config.service.kubernetes.JibBuildService +org.eclipse.jkube.kit.config.service.kubernetes.DockerBuildService +org.eclipse.jkube.kit.config.service.openshift.OpenshiftBuildService diff --git a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/JKubeServiceHubTest.java b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/JKubeServiceHubTest.java index 8f22f7811c..5e3b5251e5 100644 --- a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/JKubeServiceHubTest.java +++ b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/JKubeServiceHubTest.java @@ -31,12 +31,7 @@ import java.util.Properties; -import static junit.framework.TestCase.assertTrue; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.Assert.assertThrows; @SuppressWarnings({"ResultOfMethodCallIgnored", "unused"}) @@ -101,9 +96,9 @@ public void testBasicInit() { .build() ) { // Then - assertThat(jKubeServiceHub, notNullValue()); - assertThat(jKubeServiceHub.getClient(), notNullValue()); - assertThat(jKubeServiceHub.getRuntimeMode(), is(RuntimeMode.KUBERNETES)); + assertThat(jKubeServiceHub).isNotNull(); + assertThat(jKubeServiceHub.getClient()).isNotNull(); + assertThat(jKubeServiceHub.getRuntimeMode()).isEqualTo(RuntimeMode.KUBERNETES); } } @@ -116,8 +111,8 @@ public void testGetBuildServiceInKubernetes() { // When BuildService buildService = hub.getBuildService(); // Then - assertNotNull(buildService); - assertTrue(buildService instanceof DockerBuildService); + assertThat(buildService).isNotNull(); + assertThat(buildService).isInstanceOf(DockerBuildService.class); } @Test @@ -126,7 +121,6 @@ public void testGetBuildServiceInOpenShift() { // @formatter:off new Expectations() {{ buildServiceConfig.getJKubeBuildStrategy(); result = null; - openShiftClient.isAdaptable(OpenShiftClient.class); result = true; }}; // @formatter:on JKubeServiceHub hub = commonInit() @@ -135,8 +129,8 @@ public void testGetBuildServiceInOpenShift() { // When BuildService buildService = hub.getBuildService(); // Then - assertNotNull(buildService); - assertTrue(buildService instanceof OpenshiftBuildService); + assertThat(buildService).isNotNull(); + assertThat(buildService).isInstanceOf(OpenshiftBuildService.class); } @Test @@ -145,7 +139,7 @@ public void testGetArtifactResolverService() { .platformMode(RuntimeMode.KUBERNETES) .build(); - assertNotNull(hub.getArtifactResolverService()); + assertThat(hub.getArtifactResolverService()).isNotNull(); } @Test @@ -162,8 +156,8 @@ public void testGetJibBuildServiceInKubernetes() { // When BuildService buildService = hub.getBuildService(); // Then - assertNotNull(buildService); - assertTrue(buildService instanceof JibBuildService); + assertThat(buildService).isNotNull(); + assertThat(buildService).isInstanceOf(JibBuildService.class); } @Test @@ -175,8 +169,8 @@ public void testGetUndeployServiceInKubernetes() { // When final UndeployService result = hub.getUndeployService(); // Then - assertNotNull(result); - assertTrue(result instanceof KubernetesUndeployService); + assertThat(result).isNotNull(); + assertThat(result).isInstanceOf(KubernetesUndeployService.class); } @Test @@ -193,8 +187,8 @@ public void testGetUndeployServiceInOpenShiftWithInvalidClient() { // When final UndeployService result = hub.getUndeployService(); // Then - assertNotNull(result); - assertTrue(result instanceof KubernetesUndeployService); + assertThat(result).isNotNull(); + assertThat(result).isInstanceOf(KubernetesUndeployService.class); } @Test @@ -211,8 +205,8 @@ public void testGetUndeployServiceInOpenShiftWithValidClient() { // When final UndeployService result = hub.getUndeployService(); // Then - assertNotNull(result); - assertTrue(result instanceof OpenshiftUndeployService); + assertThat(result).isNotNull(); + assertThat(result).isInstanceOf(OpenshiftUndeployService.class); } @Test @@ -226,7 +220,7 @@ public void testGetPortForwardService() { final PortForwardService portForwardService = hub.getPortForwardService(); // Then - assertNotNull(portForwardService); + assertThat(portForwardService).isNotNull(); } @Test @@ -240,7 +234,7 @@ public void testGetDebugService() { final DebugService debugService = hub.getDebugService(); // Then - assertNotNull(debugService); + assertThat(debugService).isNotNull(); } @Test @@ -248,8 +242,8 @@ public void testBasicInitWithOffline() { // Given + When try (final JKubeServiceHub jKubeServiceHub = commonInit().platformMode(RuntimeMode.KUBERNETES).offline(true).build()) { // Then - assertThat(jKubeServiceHub, notNullValue()); - assertThat(jKubeServiceHub.getClient(), nullValue()); + assertThat(jKubeServiceHub).isNotNull(); + assertThat(jKubeServiceHub.getClient()).isNull(); } } @@ -258,7 +252,7 @@ public void testAccessServiceWithNonInitializedClientThrowsException() { // Given + When try (final JKubeServiceHub jKubeServiceHub = commonInit().platformMode(RuntimeMode.KUBERNETES).offline(true).build()) { // Then - assertThat(jKubeServiceHub, notNullValue()); + assertThat(jKubeServiceHub).isNotNull(); assertThrows(IllegalArgumentException.class, jKubeServiceHub::getApplyService); } } diff --git a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/DockerBuildServiceTest.java b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/DockerBuildServiceTest.java index d365951588..7e0d8e7965 100644 --- a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/DockerBuildServiceTest.java +++ b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/DockerBuildServiceTest.java @@ -14,6 +14,7 @@ package org.eclipse.jkube.kit.config.service.kubernetes; import mockit.Expectations; +import org.eclipse.jkube.kit.common.KitLogger; import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; import org.eclipse.jkube.kit.config.image.ImageConfiguration; import org.eclipse.jkube.kit.build.service.docker.ImagePullManager; diff --git a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceBuildIntegrationTest.java b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceBuildIntegrationTest.java index d32285651d..84914dc0ae 100644 --- a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceBuildIntegrationTest.java +++ b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceBuildIntegrationTest.java @@ -82,9 +82,10 @@ public void setUp() throws Exception { // @formatter:off new Expectations() {{ hub.getConfiguration(); result = configuration; + hub.getLog(); result = log; }}; // @formatter:on - jibBuildService = new JibBuildService(hub, log); + jibBuildService = new JibBuildService(hub); } @Test diff --git a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceTest.java b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceTest.java index b5907adf55..6ff0462821 100644 --- a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceTest.java +++ b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceTest.java @@ -138,7 +138,7 @@ public void testPrependRegistry() { @Test public void testPushWithNoConfigurations(@Mocked JibServiceUtil jibServiceUtil) throws Exception { // When - new JibBuildService(serviceHub, logger).push(Collections.emptyList(), 1, null, false); + new JibBuildService(serviceHub).push(Collections.emptyList(), 1, null, false); // Then // @formatter:off new Verifications() {{ @@ -155,7 +155,7 @@ public void testPushWithConfiguration(@Mocked JibServiceUtil jibServiceUtil) thr final RegistryConfig registryConfig = RegistryConfig.builder() .build(); // When - new JibBuildService(serviceHub, logger).push(Collections.singletonList(imageConfiguration), 1, registryConfig, false); + new JibBuildService(serviceHub).push(Collections.singletonList(imageConfiguration), 1, registryConfig, false); // Then // @formatter:off new Verifications() {{ diff --git a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildServiceTest.java b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildServiceTest.java index 349f8fe9e7..73a5ab1850 100644 --- a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildServiceTest.java +++ b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildServiceTest.java @@ -44,7 +44,6 @@ import org.eclipse.jkube.kit.config.service.JKubeServiceException; import mockit.Expectations; import mockit.Mocked; -import mockit.Tested; import mockit.Verifications; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; @@ -192,7 +191,7 @@ public void testSuccessfulBuild() throws Exception { LOG.info("Current write timeout is : {}", client.getHttpClient().writeTimeoutMillis()); LOG.info("Current read timeout is : {}", client.getHttpClient().readTimeoutMillis()); LOG.info("Retry on failure : {}", client.getHttpClient().retryOnConnectionFailure()); - OpenshiftBuildService service = new OpenshiftBuildService(client, logger, jKubeServiceHub); + OpenshiftBuildService service = new OpenshiftBuildService(client, jKubeServiceHub); service.build(image); // we should Foadd a better way to assert that a certain call has been made @@ -221,7 +220,7 @@ public void testSuccessfulBuildNoS2iSuffix() throws Exception { LOG.info("Current write timeout is : {}", client.getHttpClient().writeTimeoutMillis()); LOG.info("Current read timeout is : {}", client.getHttpClient().readTimeoutMillis()); LOG.info("Retry on failure : {}", client.getHttpClient().retryOnConnectionFailure()); - OpenshiftBuildService service = new OpenshiftBuildService(client, logger, jKubeServiceHub); + OpenshiftBuildService service = new OpenshiftBuildService(client, jKubeServiceHub); service.build(image); // we should Foadd a better way to assert that a certain call has been made @@ -249,7 +248,7 @@ public void testDockerBuild() throws Exception { false, false); DefaultOpenShiftClient client = (DefaultOpenShiftClient) mockServer.getOpenshiftClient(); - OpenshiftBuildService service = new OpenshiftBuildService(client, logger, jKubeServiceHub); + OpenshiftBuildService service = new OpenshiftBuildService(client, jKubeServiceHub); service.build(image); assertTrue(mockServer.getMockServer().getRequestCount() > 8); @@ -277,7 +276,7 @@ public void testDockerBuildWithMultiComponentImageName() throws Exception { dockerConfig, true, 50, false, false); DefaultOpenShiftClient client = (DefaultOpenShiftClient) mockServer.getOpenshiftClient(); - OpenshiftBuildService service = new OpenshiftBuildService(client, logger, jKubeServiceHub); + OpenshiftBuildService service = new OpenshiftBuildService(client, jKubeServiceHub); service.build(image); assertTrue(mockServer.getMockServer().getRequestCount() > 8); @@ -304,7 +303,7 @@ public void testDockerBuildNoS2iSuffix() throws Exception { false, false); DefaultOpenShiftClient client = (DefaultOpenShiftClient) mockServer.getOpenshiftClient(); - OpenshiftBuildService service = new OpenshiftBuildService(client, logger, jKubeServiceHub); + OpenshiftBuildService service = new OpenshiftBuildService(client, jKubeServiceHub); service.build(image); assertTrue(mockServer.getMockServer().getRequestCount() > 8); @@ -332,7 +331,7 @@ public void testDockerBuildFromExt() throws Exception { false, false); DefaultOpenShiftClient client = (DefaultOpenShiftClient) mockServer.getOpenshiftClient(); - OpenshiftBuildService service = new OpenshiftBuildService(client, logger, jKubeServiceHub); + OpenshiftBuildService service = new OpenshiftBuildService(client, jKubeServiceHub); Map fromExt = ImmutableMap.of("name", "app:1.2-1", "kind", "ImageStreamTag", "namespace", "my-project"); @@ -368,7 +367,7 @@ public void testSuccessfulBuildSecret() throws Exception { LOG.info("Current write timeout is : {}", client.getHttpClient().writeTimeoutMillis()); LOG.info("Current read timeout is : {}", client.getHttpClient().readTimeoutMillis()); LOG.info("Retry on failure : {}", client.getHttpClient().retryOnConnectionFailure()); - OpenshiftBuildService service = new OpenshiftBuildService(client, logger, jKubeServiceHub); + OpenshiftBuildService service = new OpenshiftBuildService(client, jKubeServiceHub); service.build(image); // we should Foadd a better way to assert that a certain call has been made @@ -388,7 +387,7 @@ public void testFailedBuild() throws Exception { // @formatter:off OpenShiftClient client = mockServer.getOpenshiftClient(); - OpenshiftBuildService service = new OpenshiftBuildService(client, logger, jKubeServiceHub); + OpenshiftBuildService service = new OpenshiftBuildService(client, jKubeServiceHub); service.build(image); } @@ -402,7 +401,7 @@ public void testFailedBuildSecret() throws Exception { // @formatter:off OpenShiftClient client = mockServer.getOpenshiftClient(); - OpenshiftBuildService service = new OpenshiftBuildService(client, logger, jKubeServiceHub); + OpenshiftBuildService service = new OpenshiftBuildService(client, jKubeServiceHub); service.build(image); } @@ -418,7 +417,7 @@ public void testSuccessfulSecondBuild() throws Exception { WebServerEventCollector collector = createMockServer(config, true, 50, true, true); OpenShiftClient client = mockServer.getOpenshiftClient(); - OpenshiftBuildService service = new OpenshiftBuildService(client, logger, jKubeServiceHub); + OpenshiftBuildService service = new OpenshiftBuildService(client, jKubeServiceHub); service.build(image); assertTrue(mockServer.getMockServer().getRequestCount() > 8); @@ -438,7 +437,7 @@ public void checkTarPackage() throws Exception { // @formatter:off OpenShiftClient client = mockServer.getOpenshiftClient(); - final OpenshiftBuildService service = new OpenshiftBuildService(client, logger, jKubeServiceHub); + final OpenshiftBuildService service = new OpenshiftBuildService(client, jKubeServiceHub); ImageConfiguration imageWithEnv = image.toBuilder() .build(image.getBuildConfiguration().toBuilder() @@ -486,7 +485,7 @@ public void checkTarPackageSecret() throws Exception { // @formatter:off OpenShiftClient client = mockServer.getOpenshiftClient(); - final OpenshiftBuildService service = new OpenshiftBuildService(client, logger, jKubeServiceHub); + final OpenshiftBuildService service = new OpenshiftBuildService(client, jKubeServiceHub); ImageConfiguration imageWithEnv = image.toBuilder() .build(image.getBuildConfiguration().toBuilder() @@ -542,7 +541,7 @@ public void testBuildConfigResourceConfig() throws Exception { // @formatter:off OpenShiftClient client = mockServer.getOpenshiftClient(); - final OpenshiftBuildService service = new OpenshiftBuildService(client, logger, jKubeServiceHub); + final OpenshiftBuildService service = new OpenshiftBuildService(client, jKubeServiceHub); ImageConfiguration imageWithEnv = image.toBuilder() .build(image.getBuildConfiguration().toBuilder() @@ -579,7 +578,7 @@ public void testSuccessfulDockerImageOutputBuild() throws Exception { LOG.info("Current write timeout is : {}", client.getHttpClient().writeTimeoutMillis()); LOG.info("Current read timeout is : {}", client.getHttpClient().readTimeoutMillis()); LOG.info("Retry on failure : {}", client.getHttpClient().retryOnConnectionFailure()); - OpenshiftBuildService service = new OpenshiftBuildService(client, logger, jKubeServiceHub); + OpenshiftBuildService service = new OpenshiftBuildService(client, jKubeServiceHub); service.build(image); // we should add a better way to assert that a certain call has been made @@ -606,7 +605,7 @@ public void testSuccessfulDockerImageOutputBuildSecret() throws Exception { LOG.info("Current write timeout is : {}", client.getHttpClient().writeTimeoutMillis()); LOG.info("Current read timeout is : {}", client.getHttpClient().readTimeoutMillis()); LOG.info("Retry on failure : {}", client.getHttpClient().retryOnConnectionFailure()); - OpenshiftBuildService service = new OpenshiftBuildService(client, logger, jKubeServiceHub); + OpenshiftBuildService service = new OpenshiftBuildService(client, jKubeServiceHub); service.build(image); // we should add a better way to assert that a certain call has been made