Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #802: Update Fabric8 Kubernetes Client to v5.10.1 #1120

Merged
merged 3 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:

sonar:
docker:
- image: cimg/openjdk:11.0
- image: eclipse-temurin:11
steps:
- checkout
- restore_cache:
Expand All @@ -78,7 +78,7 @@ jobs:

sonar-pr:
docker:
- image: cimg/openjdk:11.0
- image: eclipse-temurin:11
steps:
- checkout
- restore_cache:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Usage:
```
### 1.6.0-SNAPSHOT
* Fix #887: Incorrect warning about overriding environment variable
* Fix #802: Update Fabric8 kubernetes Client to v5.10.1

### 1.5.1 (2021-10-28)
* Fix #1084: Gradle dependencies should be test or provided scope
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import io.fabric8.kubernetes.api.model.HTTPHeader;
import org.eclipse.jkube.kit.common.GenericCustomResource;
import io.fabric8.kubernetes.client.utils.ApiVersionUtil;
import org.eclipse.jkube.kit.common.KitLogger;
import org.eclipse.jkube.kit.common.ResourceFileType;

Expand Down Expand Up @@ -70,9 +69,6 @@
import io.fabric8.kubernetes.api.model.ReplicationController;
import io.fabric8.kubernetes.api.model.ReplicationControllerSpec;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionList;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionVersion;
import io.fabric8.kubernetes.api.model.apps.DaemonSet;
import io.fabric8.kubernetes.api.model.apps.DaemonSetSpec;
import io.fabric8.kubernetes.api.model.apps.Deployment;
Expand All @@ -91,16 +87,13 @@
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.PodResource;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext;
import io.fabric8.openshift.api.model.Build;
import io.fabric8.openshift.api.model.DeploymentConfig;
import io.fabric8.openshift.api.model.DeploymentConfigSpec;
import io.fabric8.openshift.api.model.Template;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import static io.fabric8.kubernetes.client.utils.ApiVersionUtil.trimGroup;
import static io.fabric8.kubernetes.client.utils.ApiVersionUtil.trimVersion;

/**
* @author roland
Expand Down Expand Up @@ -864,8 +857,9 @@ private static File[] listRemoteResourceFragments(List<String> remotes, KitLogge
return new File[0];
}

public static String getFullyQualifiedApiGroupWithKind(CustomResourceDefinitionContext crdContext) {
return crdContext.getGroup() + "/" + crdContext.getVersion() + "#" + crdContext.getKind();
public static String getFullyQualifiedApiGroupWithKind(HasMetadata item) {
return ApiVersionUtil.joinApiGroupAndVersion(ApiVersionUtil.trimGroup(item.getApiVersion()), ApiVersionUtil.trimVersion(item.getApiVersion())) +
"#" + item.getKind();
}

public static String getNewestApplicationPodName(KubernetesClient client, String namespace, Collection<HasMetadata> resources) {
Expand Down Expand Up @@ -952,12 +946,6 @@ public static boolean isControllerResource(HasMetadata h) {
return Arrays.stream(POD_CONTROLLER_KINDS).anyMatch(c -> c.equals(h.getKind()));
}

public static CustomResourceDefinitionContext getCrdContext(CustomResourceDefinitionList customResourceDefinitionList, GenericCustomResource customResource) {
return findCrdForCustomResource(customResourceDefinitionList, customResource)
.map(CustomResourceDefinitionContext::fromCrd)
.orElse(null);
}

public static List<HTTPHeader> convertMapToHTTPHeaderList(Map<String, String> headers) {
List<HTTPHeader> httpHeaders = new ArrayList<>();
if (headers != null) {
Expand All @@ -967,34 +955,5 @@ public static List<HTTPHeader> convertMapToHTTPHeaderList(Map<String, String> he
}
return httpHeaders;
}

private static Optional<CustomResourceDefinition> findCrdForCustomResource(CustomResourceDefinitionList crdList, GenericCustomResource gcr) {
return crdList.getItems().stream()
.filter(hasGroup(gcr))
.filter(isVersionPresentInSpecVersion(gcr).or(isVersionPresentInVersionsList(gcr)))
.filter(hasKind(gcr))
.findFirst();
}

private static Predicate<CustomResourceDefinition> hasGroup(GenericCustomResource gcr) {
return crd -> crd.getSpec().getGroup().equals(trimGroup(gcr.getApiVersion()));
}

private static Predicate<CustomResourceDefinition> isVersionPresentInSpecVersion(GenericCustomResource gcr) {
final String gcrVersion = trimVersion(gcr.getApiVersion());
return crd -> crd.getSpec().getVersion() != null && crd.getSpec().getVersion().equals(gcrVersion);
}

private static Predicate<CustomResourceDefinition> isVersionPresentInVersionsList(GenericCustomResource gcr) {
final String gcrVersion = trimVersion(gcr.getApiVersion());
return crd -> crd.getSpec().getVersions() != null && crd.getSpec().getVersions()
.stream()
.map(CustomResourceDefinitionVersion::getName)
.anyMatch(n -> n.equals(gcrVersion));
}

private static Predicate<CustomResourceDefinition> hasKind(GenericCustomResource gcr) {
return crd -> crd.getSpec().getNames().getKind().equals(gcr.getKind());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.gson.JsonObject;
import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.KubernetesList;
import io.fabric8.kubernetes.api.model.KubernetesResource;
import io.fabric8.openshift.api.model.Template;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.eclipse.jkube.kit.common.GenericCustomResource;
import org.eclipse.jkube.kit.common.ResourceFileType;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -95,7 +95,7 @@ private static List<HasMetadata> parseKubernetesListOrTemplate(ObjectMapper mapp
private static List<HasMetadata> parseKubernetesList(ObjectMapper mapper, Map<String, Object> manifest) {
final List<Map<String, Object>> items = (List<Map<String, Object>>)manifest.get("items");
return items.stream().map(item -> {
final GenericCustomResource fallback = mapper.convertValue(item, GenericCustomResource.class);
final GenericKubernetesResource fallback = mapper.convertValue(item, GenericKubernetesResource.class);
try {
// Convert Using KubernetesDeserializer or fail and return fallback generic
return mapper.convertValue(fallback, HasMetadata.class);
Expand All @@ -111,17 +111,17 @@ public static <T extends KubernetesResource> T load(File file, Class<T> clazz) t
return load(file, clazz, type);
}

private static boolean isGenericCustomResourceCompatible(Class<?> clazz){
return clazz.isAssignableFrom(GenericCustomResource.class);
private static boolean isGenericKubernetesResourceCompatible(Class<?> clazz){
return clazz.isAssignableFrom(GenericKubernetesResource.class);
Copy link
Member

@manusa manusa Nov 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably need to change, especially in scope of #778 + #1113 + #1114

}

public static <T extends KubernetesResource> T load(File file, Class<T> clazz, ResourceFileType resourceFileType)
throws IOException {
try {
return getObjectMapper(resourceFileType).readValue(file, clazz);
} catch(IOException ex) {
if (isGenericCustomResourceCompatible(clazz)) {
return clazz.cast(getObjectMapper(resourceFileType).readValue(file, GenericCustomResource.class));
if (isGenericKubernetesResourceCompatible(clazz)) {
return clazz.cast(getObjectMapper(resourceFileType).readValue(file, GenericKubernetesResource.class));
}
throw ex;
}
Expand All @@ -134,8 +134,8 @@ public static <T extends KubernetesResource> T load(InputStream in, Class<T> cla
IOUtils.copy(in, baos);
return getObjectMapper(resourceFileType).readValue(baos.toByteArray(), clazz);
} catch(IOException ex) {
if (isGenericCustomResourceCompatible(clazz)) {
return clazz.cast(getObjectMapper(resourceFileType).readValue(baos.toByteArray(), GenericCustomResource.class));
if (isGenericKubernetesResourceCompatible(clazz)) {
return clazz.cast(getObjectMapper(resourceFileType).readValue(baos.toByteArray(), GenericKubernetesResource.class));
}
throw ex;
}
Expand Down
Loading