Skip to content

Commit

Permalink
Update Kubernetes Client to v4.13.0
Browse files Browse the repository at this point in the history
This should also fix eclipse-jkube#387

+ Updated Kubernetes Client to v4.13.0
+ Added a test to verify `networking.k8s.io/v1` `Ingress` is loaded
  • Loading branch information
rohanKanojia committed Nov 26, 2020
1 parent db9c522 commit 0d57f04
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Usage:
* Fix #268: Generator and HealthCheck enrichers for Micronaut framework (JVM)
* Fix #488: Controller enricher replica count can be set to `0` when ResourceConfig is provided
* Fix #485: Filter with placeholders in Dockerfile is broken
* Fix #387: Update Fabric8 Kubernetes Client to v4.13.0 to support `networking.k8s.io/v1` `Ingress`

### 1.0.2 (2020-10-30)
* Fix #429: Added quickstart for Micronaut framework
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable;
import io.fabric8.kubernetes.client.dsl.LogWatch;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
Expand Down Expand Up @@ -574,8 +573,8 @@ public static String getBuildStatusReason(Build build) {



public static FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> withSelector(NonNamespaceOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods, LabelSelector selector, KitLogger log) {
FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> answer = pods;
public static FilterWatchListDeletable<Pod, PodList, Boolean, Watch> withSelector(NonNamespaceOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods, LabelSelector selector, KitLogger log) {
FilterWatchListDeletable<Pod, PodList, Boolean, Watch> answer = pods;
Map<String, String> matchLabels = selector.getMatchLabels();
if (matchLabels != null && !matchLabels.isEmpty()) {
answer = answer.withLabels(matchLabels);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import io.fabric8.kubernetes.api.model.Secret;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.ServiceAccount;
import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apps.DaemonSet;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.ReplicaSet;
Expand Down Expand Up @@ -420,7 +420,7 @@ public void applyCustomResourceDefinition(CustomResourceDefinition entity, Strin
log.debug("Only processing Services right now so ignoring Custom Resource Definition: " + namespace + ":" + id);
return;
}
CustomResourceDefinition old = kubernetesClient.customResourceDefinitions().withName(id).get();
CustomResourceDefinition old = kubernetesClient.apiextensions().v1beta1().customResourceDefinitions().withName(id).get();
if (isRunning(old)) {
if (UserConfigurationCompare.configEqual(entity, old)) {
log.info("Custom Resource Definition has not changed so not doing anything");
Expand All @@ -445,7 +445,7 @@ public void applyCustomResourceDefinition(CustomResourceDefinition entity, Strin
private void doCreateCustomResourceDefinition(CustomResourceDefinition entity, String sourceName) {
log.info("Creating a Custom Resource Definition from " + sourceName + " name " + getName(entity));
try {
CustomResourceDefinition answer = kubernetesClient.customResourceDefinitions().create(entity);
CustomResourceDefinition answer = kubernetesClient.apiextensions().v1beta1().customResourceDefinitions().create(entity);
log.info("Created Custom Resource Definition result: %s", answer.getMetadata().getName());
} catch (Exception e) {
onApplyError("Failed to create Custom Resource Definition from " + sourceName + ". " + e + ". " + entity, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import io.fabric8.kubernetes.api.model.batch.DoneableJob;
import io.fabric8.kubernetes.api.model.batch.Job;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.DoneableCustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.DoneableCustomResourceDefinition;
import io.fabric8.openshift.api.model.BuildConfig;
import io.fabric8.openshift.api.model.DoneableBuildConfig;
import io.fabric8.openshift.api.model.DoneableImageStream;
Expand Down Expand Up @@ -218,7 +218,7 @@ private static EntityPatcher<CustomResourceDefinition> crdPatcher() {
}

DoneableCustomResourceDefinition entity =
client.customResourceDefinitions()
client.apiextensions().v1beta1().customResourceDefinitions()
.withName(oldObj.getMetadata().getName())
.edit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void run() {

private void waitAndLogPods(final KubernetesClient kubernetes, final String namespace, LabelSelector selector, final boolean watchAddedPodsOnly, final String ctrlCMessage, final boolean
followLog, Date ignorePodsOlderThan, boolean waitInCurrentThread) {
FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> pods = withSelector(kubernetes.pods().inNamespace(namespace), selector, log);
FilterWatchListDeletable<Pod, PodList, Boolean, Watch> pods = withSelector(kubernetes.pods().inNamespace(namespace), selector, log);
if (context.getPodName() != null) {
log.info("Watching pod with selector %s, and name %s waiting for a running pod...", selector, context.getPodName());
pods = pods.withField("metadata.name", context.getPodName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private boolean podEquals(Pod pod1, Pod pod2) {
}

private Pod getNewestPod(LabelSelector selector) {
FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> pods =
FilterWatchListDeletable<Pod, PodList, Boolean, Watch> pods =
KubernetesHelper.withSelector(kubernetes.pods(), selector, log);

PodList list = pods.list();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.api.model.PodStatus;
import io.fabric8.kubernetes.api.model.ReplicationController;
import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.ReplicaSet;
import io.fabric8.kubernetes.client.KubernetesClient;
Expand Down Expand Up @@ -127,8 +127,8 @@ private static String getS2IBuildName(ImageName imageName, String s2iBuildNameSu
}


public static FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> withSelector(NonNamespaceOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods, LabelSelector selector, KitLogger log) {
FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> answer = pods;
public static FilterWatchListDeletable<Pod, PodList, Boolean, Watch> withSelector(NonNamespaceOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods, LabelSelector selector, KitLogger log) {
FilterWatchListDeletable<Pod, PodList, Boolean, Watch> answer = pods;
Map<String, String> matchLabels = selector.getMatchLabels();
if (matchLabels != null && !matchLabels.isEmpty()) {
answer = answer.withLabels(matchLabels);
Expand Down Expand Up @@ -284,7 +284,7 @@ public static String doGetCustomResourceAsString(File customResourceFile) throws
public static List<CustomResourceDefinitionContext> getCustomResourceDefinitionContext(KubernetesClient client, List<String> customResources) {
List<CustomResourceDefinitionContext> crdContexts = new ArrayList<>();
for(String customResource : customResources) {
CustomResourceDefinition customResourceDefinition = client.customResourceDefinitions()
CustomResourceDefinition customResourceDefinition = client.apiextensions().v1beta1().customResourceDefinitions()
.withName(customResource).get();
if(customResourceDefinition != null) {
crdContexts.add(new CustomResourceDefinitionContext.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

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

import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinitionBuilder;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionBuilder;
import io.fabric8.openshift.api.model.Route;
import io.fabric8.openshift.api.model.RouteBuilder;
import io.fabric8.openshift.client.server.mock.OpenShiftMockServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.PodBuilder;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinitionBuilder;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionBuilder;
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext;
import io.fabric8.openshift.api.model.Project;
import io.fabric8.openshift.api.model.ProjectBuilder;
Expand Down Expand Up @@ -90,7 +90,7 @@ public void undeployWithManifestShouldDeleteApplicableEntities(@Mocked File file
file.exists(); result = true;
file.isFile(); result = true;
kubernetesHelper.loadResources(file);
result = new HashSet<>(Arrays.asList(new Project(), namespace, pod, service));
result = new HashSet<>(Arrays.asList(namespace, pod, service));
}};
// @formatter:on
// When
Expand Down Expand Up @@ -129,7 +129,7 @@ public void undeployWithManifestAndCustomResourcesShouldDeleteApplicableEntities
new Expectations() {{
kubernetesHelper.loadResources(manifest); result = new HashSet<>(Collections.singletonList(service));
resourceConfig.getCustomResourceDefinitions(); result = Collections.singletonList(crdId);
jKubeServiceHub.getClient().customResourceDefinitions().withName(crdId).get(); result = crd;
jKubeServiceHub.getClient().apiextensions().v1beta1().customResourceDefinitions().withName(crdId).get(); result = crd;
kubernetesHelper.getCustomResourcesFileToNameMap((File)any, (List<String>)any, logger);
result = Collections.singletonMap(crManifest, crdId);
kubernetesHelper.unmarshalCustomResourceFile(crManifest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ protected WebServerEventCollector<OpenShiftMockServer> createMockServer(
.always();

mockServer.expect().withPath("/apis/build.openshift.io/v1/namespaces/test/builds/" + projectName).andReturn(200, build).always();
mockServer.expect().withPath("/apis/build.openshift.io/v1/namespaces/test/builds?fieldSelector=metadata.name%3D" + projectName + "&watch=true")
mockServer.expect().withPath("/apis/build.openshift.io/v1/namespaces/test/builds/" + projectName + "?watch=true")
.andUpgradeToWebSocket().open()
.waitFor(buildDelay)
.andEmit(new WatchEvent(build, "MODIFIED"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
import io.fabric8.kubernetes.api.model.PodSpecBuilder;
import io.fabric8.kubernetes.api.model.Quantity;
import org.eclipse.jkube.kit.config.image.ImageConfiguration;
import org.eclipse.jkube.kit.common.JavaProject;
import org.eclipse.jkube.kit.config.resource.GroupArtifactVersion;
import org.eclipse.jkube.kit.config.resource.PlatformMode;
import org.eclipse.jkube.kit.config.resource.ResourceVersioning;
import mockit.Mocked;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -50,9 +48,6 @@ public class KubernetesResourceUtilTest {

private static File jkubeDir;

@Mocked
JavaProject project;

@BeforeClass
public static void initPath() throws UnsupportedEncodingException {
ClassLoader classLoader = KubernetesResourceUtil.class.getClassLoader();
Expand Down Expand Up @@ -256,6 +251,21 @@ public void testMergePodSpecDefaultContainerNameWhenWhenFragmentNullSidecarEnabl
assertEquals("spring-boot", defaultContainerName);
}

@Test
public void testGetResourceShouldLoadNetworkV1Ingress() throws IOException {
// Given
File resourceFragment = new File(jkubeDir, "network-v1-ingress.yml");

// When
HasMetadata result = KubernetesResourceUtil.getResource(PlatformMode.kubernetes, KubernetesResourceUtil.DEFAULT_RESOURCE_VERSIONING, resourceFragment, "app");

// Then
assertNotNull(result);
assertEquals("networking.k8s.io/v1", result.getApiVersion());
assertEquals("Ingress", result.getKind());
assertEquals("my-ingress", result.getMetadata().getName());
}

private PodSpec getDefaultGeneratedPodSpec() {
return new PodSpecBuilder()
.addNewContainer()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
tls:
- hosts:
- my.host.com
secretName: letsencrypt-prod
rules:
- host: my.host.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-service
port:
number: 8080
2 changes: 1 addition & 1 deletion jkube-kit/parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<version.json-path-assert>2.2.0</version.json-path-assert>
<version.jsr305>3.0.2</version.jsr305>
<version.JUnitParams>1.1.1</version.JUnitParams>
<version.kubernetes-client>4.10.3</version.kubernetes-client>
<version.kubernetes-client>4.13.0</version.kubernetes-client>
<version.lombok>1.18.12</version.lombok>
<version.maven-archiver>3.5.0</version.maven-archiver>
<version.maven-core>3.5.4</version.maven-core>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected void applyEntities(KubernetesClient kubernetes, String namespace, Stri

private String waitForRunningPodWithEnvVar(final KubernetesClient kubernetes, final String namespace, LabelSelector selector, final Map<String, String> envVars) throws MojoExecutionException {
// wait for the newest pod to be ready with the given env var
FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> pods = withSelector(kubernetes.pods().inNamespace(namespace), selector, log);
FilterWatchListDeletable<Pod, PodList, Boolean, Watch> pods = withSelector(kubernetes.pods().inNamespace(namespace), selector, log);
log.info("Waiting for debug pod with selector " + selector + " and environment variables " + envVars);
podWaitLog = createLogger("[[Y]][W][[Y]] [[s]]");
PodList list = pods.list();
Expand Down

0 comments on commit 0d57f04

Please sign in to comment.