Skip to content

Commit

Permalink
fix fabric8io#4014: refactoring to remove openshift client jar
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Dec 21, 2022
1 parent 722dc49 commit cd86f2d
Show file tree
Hide file tree
Showing 22 changed files with 501 additions and 170 deletions.
Expand Up @@ -24,6 +24,7 @@
import io.fabric8.kubernetes.api.model.KubernetesResourceList;
import io.fabric8.kubernetes.api.model.RootPaths;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.NamespacedInOutCreateable;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.http.HttpClient;

Expand Down Expand Up @@ -142,6 +143,19 @@ public interface Client extends Closeable {
<T extends HasMetadata, L extends KubernetesResourceList<T>, R extends Resource<T>> MixedOperation<T, L, R> resources(
Class<T> resourceType, Class<L> listClass, Class<R> resourceClass);

/**
* Typed API for managing create only resources.
*
* @param <I>
* @param <O>
* @param inType
* @param outType
* @return
*/
<I extends KubernetesResource, O extends KubernetesResource> NamespacedInOutCreateable<I, O> createOnlyResources(
Class<I> inType,
Class<O> outType);

/**
* Typed API for managing resources. Any properly annotated POJO can be utilized as a resource.
*
Expand Down
Expand Up @@ -17,6 +17,9 @@
package io.fabric8.kubernetes.client;

import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.ServicePort;

import java.util.Objects;

public interface ServiceToURLProvider {
enum ServiceToUrlImplPriority {
Expand All @@ -40,4 +43,17 @@ public int getValue() {
int getPriority();

String getURL(Service service, String portName, String namespace, KubernetesClient client);

static ServicePort getServicePortByName(Service service, String portName) {
if (portName.isEmpty()) {
return service.getSpec().getPorts().iterator().next();
}

for (ServicePort servicePort : service.getSpec().getPorts()) {
if (Objects.equals(servicePort.getName(), portName)) {
return servicePort;
}
}
return null;
}
}
Expand Up @@ -16,5 +16,5 @@

package io.fabric8.kubernetes.client.dsl;

public interface NamespacedInOutCreateable<I, O> extends Namespaceable<InOutCreateable<I, O>> {
public interface NamespacedInOutCreateable<I, O> extends Namespaceable<InOutCreateable<I, O>>, InOutCreateable<I, O> {
}
Expand Up @@ -28,6 +28,7 @@
import io.fabric8.kubernetes.client.NamespacedKubernetesClient;
import io.fabric8.kubernetes.client.RequestConfig;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.NamespacedInOutCreateable;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.http.HttpClient;

Expand Down Expand Up @@ -129,6 +130,12 @@ public <T extends HasMetadata, L extends KubernetesResourceList<T>, R extends Re
return client.resources(resourceType, listClass, resourceClass);
}

@Override
public <I extends KubernetesResource, O extends KubernetesResource> NamespacedInOutCreateable<I, O> createOnlyResources(
Class<I> inType, Class<O> outType) {
return client.createOnlyResources(inType, outType);
}

public C inAnyNamespace() {
C result = newInstance();
result.init(client.adapt(NamespacedKubernetesClient.class).inAnyNamespace());
Expand Down

0 comments on commit cd86f2d

Please sign in to comment.