Skip to content

Commit

Permalink
chore: use latest sundrio and kubernetes-client
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Sep 5, 2022
1 parent 7020706 commit ffbdb0c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@

import io.dekorate.prometheus.model.ServiceMonitor;
import io.dekorate.prometheus.model.ServiceMonitorList;
import io.fabric8.kubernetes.client.ClientContext;
import io.fabric8.kubernetes.client.Client;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation;
import io.fabric8.kubernetes.client.dsl.base.OperationContext;
import io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperation;
import io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperationsImpl;
import io.fabric8.kubernetes.client.dsl.internal.OperationContext;

public class ServiceMonitorOperationsImpl
extends HasMetadataOperation<ServiceMonitor, ServiceMonitorList, Resource<ServiceMonitor>> {

public ServiceMonitorOperationsImpl(ClientContext clientContext) {
this(HasMetadataOperationsImpl.defaultContext(clientContext));
public ServiceMonitorOperationsImpl(Client client) {
this(HasMetadataOperationsImpl.defaultContext(client));
}

public ServiceMonitorOperationsImpl(OperationContext context) {
Expand Down
1 change: 1 addition & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ limitations under the License.
<optional>true</optional>
</dependency>


<dependency>
<groupId>io.dekorate</groupId>
<artifactId>dekorate-templates</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
Expand All @@ -28,10 +29,11 @@
import io.dekorate.utils.Strings;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.http.HttpClient;
import io.fabric8.kubernetes.client.http.HttpRequest;
import io.fabric8.kubernetes.client.http.HttpResponse;
import io.fabric8.kubernetes.client.utils.URLUtils;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;


public class CustomResourceCondition implements ExecutionCondition, WithKubernetesClient {

Expand All @@ -53,7 +55,8 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con

KubernetesClient client = getKubernetesClient(context);
Config config = client.getConfiguration();
OkHttpClient http = client.adapt(OkHttpClient.class);

HttpClient httpClient = client.getHttpClient();

List<String> parts = new ArrayList<>();
parts.add(config.getMasterUrl());
Expand All @@ -71,9 +74,11 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
}
parts.add(plural);
String requestUrl = URLUtils.join(parts.stream().toArray(s -> new String[s]));
Request request = new Request.Builder().get().url(requestUrl).build();
Response response = http.newCall(request).execute();

final HttpRequest request = httpClient.newHttpRequestBuilder()
.uri(requestUrl)
.build();
HttpResponse<String> response = httpClient.sendAsync(request, String.class).get(10, TimeUnit.SECONDS);
if (!response.isSuccessful()) {
return ConditionEvaluationResult.disabled("Could not lookup custom resource.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.fabric8.kubernetes.api.model.apps.ReplicaSet;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable;
import io.fabric8.kubernetes.client.dsl.PodResource;

public class Pods {

Expand Down Expand Up @@ -80,7 +81,7 @@ public PodList list(Object resource) {
* @param deployment The {@link Deployment}
*/
protected PodList map(Deployment deployment) {
FilterWatchListDeletable<Pod, PodList> podLister = client.pods()
FilterWatchListDeletable<Pod, PodList, PodResource> podLister = client.pods()
.inNamespace(deployment.getMetadata().getNamespace());
if (deployment.getSpec().getSelector().getMatchLabels() != null) {
podLister.withLabels(deployment.getSpec().getSelector().getMatchLabels());
Expand Down Expand Up @@ -112,7 +113,7 @@ protected PodList map(Deployment deployment) {
* @param replicaSet The {@link ReplicaSet}
*/
protected PodList map(ReplicaSet replicaSet) {
FilterWatchListDeletable<Pod, PodList> podLister = client.pods()
FilterWatchListDeletable<Pod, PodList, PodResource> podLister = client.pods()
.inNamespace(replicaSet.getMetadata().getNamespace());
if (replicaSet.getSpec().getSelector().getMatchLabels() != null) {
podLister.withLabels(replicaSet.getSpec().getSelector().getMatchLabels());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import io.dekorate.DekorateException;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.client.BaseClient;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.KubernetesClientException;

/**
Expand Down Expand Up @@ -88,7 +88,7 @@ default KubernetesClient getKubernetesClient(ExtensionContext context) {
return (KubernetesClient) client;
}

client = new DefaultKubernetesClient();
client = new KubernetesClientBuilder().build();
context.getStore(DEKORATE_STORE).put(KUBERNETES_CLIENT, client);
return (KubernetesClient) client;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.ReplicaSet;
import io.fabric8.kubernetes.api.model.apps.StatefulSet;
import io.fabric8.kubernetes.client.internal.readiness.Readiness;
import io.fabric8.kubernetes.client.readiness.Readiness;
import io.fabric8.kubernetes.client.utils.Utils;

public class KnativeReadiness {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ private void startProject(ExtensionContext context, Project project) throws Inte
try {
HasMetadata r = client.resource(i).fromServer().get();
if (r == null) {
client.resource(i).apply();
client.resource(i).createOrReplace();
} else if (r instanceof ImageStream) {
//let's not delete image streams at this point
} else if (deleteAndWait(context, i, 1, TimeUnit.MINUTES)) {
client.resource(i).apply();
client.resource(i).createOrReplace();
}
} catch (Exception e) {
e.printStackTrace(System.err);
Expand Down

0 comments on commit ffbdb0c

Please sign in to comment.