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

Adding an api layer to isolate Okhttp #3549

Merged
merged 29 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
488d0dc
introducing a jdk like set of interfaces to encapsulate okhttp
shawkins Nov 1, 2021
c19b903
further refining httpclientutils and simplifying mock client creation
shawkins Nov 1, 2021
acce11c
adding default client construction
shawkins Nov 2, 2021
8f1eb4f
moving as much as possible to common configuration
shawkins Nov 2, 2021
6a9377c
Merge branch 'master' of github.com:fabric8io/kubernetes-client into
shawkins Nov 2, 2021
19b1227
javadoc corrections
shawkins Nov 2, 2021
5e78d42
canceling only if the future is canceled
shawkins Nov 2, 2021
0d0b45d
addressing code smells and re-enabling the token test
shawkins Nov 3, 2021
4775881
Merge branch 'master' of github.com:fabric8io/kubernetes-client into
shawkins Nov 3, 2021
1897c66
creating a utility class to move more test logic off okhttp
shawkins Nov 4, 2021
49b8f5c
migrating the rest of the tests off of okhttp
shawkins Nov 4, 2021
23a9ebd
checking for empty status
shawkins Nov 9, 2021
0ca5e58
Merge branch 'master' of github.com:fabric8io/kubernetes-client into
shawkins Nov 17, 2021
63226d6
isolating how much the httpclient is passed around
shawkins Nov 18, 2021
282c53e
ensuring websocket closure
shawkins Nov 18, 2021
777e05b
adding a changelog and ensuring consistency with the prior header calls
shawkins Nov 19, 2021
b84fb64
various updates to allow the jdk client to work
shawkins Nov 19, 2021
268874a
adding back deprecated constructors and httpclientutils methods
shawkins Nov 30, 2021
32c0ab7
Merge branch 'master' of github.com:fabric8io/kubernetes-client into
shawkins Nov 30, 2021
f897e50
addressing code smells
shawkins Nov 30, 2021
b2e97d6
moving okhttp to a non-internal package, and refining the ExecListener
shawkins Dec 9, 2021
12cf9b9
making interceptor name constants, removing todo, splitting lines
shawkins Dec 9, 2021
44952d8
encapsulating additionalConfig on the client factory
shawkins Dec 10, 2021
37f31a3
correcting javadoc
shawkins Dec 10, 2021
ee243f1
one more change to mention
shawkins Dec 14, 2021
8f45110
removing zero width character
shawkins Dec 15, 2021
c4130f8
Merge branch 'master' of github.com:fabric8io/kubernetes-client into …
shawkins Dec 15, 2021
3a5a2ae
converting the istio client to the new api
shawkins Dec 15, 2021
112db7c
renaming clientstate to clientcontext
shawkins Dec 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
* Fix #3593: Add support for Istio extension

#### _**Note**_: Breaking changes in the API
* Refactoring #3547: due to an abstraction layer added over okHttp, the following api changes were made:
* OperationContext withOkHttpClient was removed, it should be needed to be directly called
* PatchType.getMediaType was replaced with PatchType.getContentType
* ExecListener no longer passes the okhttp3.Response to onOpen. onFailure will pass a simplified ExecListener.Response when possible.
* okhttp3.TlsVersions has been replaced by io.fabric8.kubernetes.client.http.TlsVersion
* HttpClientUtils.createHttpClient(config, additionalConfig) has been deprecated and now returns an OkHttpClientImpl
* The client is no longer adaptable to an OkHttpClient, use Client.getHttpClient instead

### 5.10.1 (2021-11-12)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@
*/
package io.fabric8.camelk.client;

import io.fabric8.kubernetes.client.ExtensionAdapterSupport;
import io.fabric8.kubernetes.client.Client;
import io.fabric8.kubernetes.client.ExtensionAdapter;
import okhttp3.OkHttpClient;
import io.fabric8.kubernetes.client.ExtensionAdapterSupport;

import java.net.URL;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class CamelKExtensionAdapter extends ExtensionAdapterSupport implements ExtensionAdapter<CamelKClient> {

static final ConcurrentMap<URL, Boolean> IS_CAMELK = new ConcurrentHashMap<>();
static final ConcurrentMap<URL, Boolean> USES_CAMELK_APIGROUPS = new ConcurrentHashMap<>();

@Override
public Class<CamelKClient> getExtensionType() {
return CamelKClient.class;
Expand All @@ -41,7 +40,7 @@ public Boolean isAdaptable(Client client) {

@Override
public CamelKClient adapt(Client client) {
return new DefaultCamelKClient(client.adapt(OkHttpClient.class), client.getConfiguration());
return new DefaultCamelKClient(client);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
package io.fabric8.camelk.client;

import io.fabric8.camelk.client.dsl.V1alpha1APIGroupDSL;
import io.fabric8.camelk.client.dsl.V1APIGroupDSL;
import okhttp3.OkHttpClient;
import io.fabric8.camelk.client.dsl.V1alpha1APIGroupDSL;
import io.fabric8.kubernetes.client.BaseClient;
import io.fabric8.kubernetes.client.ClientState;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.RequestConfig;
import io.fabric8.kubernetes.client.WithRequestCallable;
import io.fabric8.kubernetes.client.dsl.FunctionCallable;
import io.fabric8.kubernetes.client.BaseClient;
import io.fabric8.kubernetes.client.Config;

public class DefaultCamelKClient extends BaseClient implements NamespacedCamelKClient {

Expand All @@ -35,8 +35,8 @@ public DefaultCamelKClient(Config configuration) {
super(configuration);
}

public DefaultCamelKClient(OkHttpClient httpClient, Config configuration) {
super(httpClient, configuration);
public DefaultCamelKClient(ClientState clientState) {
super(clientState);
}

@Override
Expand All @@ -50,10 +50,10 @@ public NamespacedCamelKClient inNamespace(String namespace) {
.withNamespace(namespace)
.build();

return new DefaultCamelKClient(getHttpClient(), updated);
return new DefaultCamelKClient(newState(updated));
}

@Override
@Override
public FunctionCallable<NamespacedCamelKClient> withRequestConfig(RequestConfig requestConfig) {
return new WithRequestCallable<>(this, requestConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
*/
package io.fabric8.camelk.client;

import io.fabric8.kubernetes.client.BaseClient;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.Handlers;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.camelk.client.dsl.V1APIGroupDSL;
import io.fabric8.camelk.v1.Build;
import io.fabric8.camelk.v1.BuildList;
Expand All @@ -32,40 +26,44 @@
import io.fabric8.camelk.v1.IntegrationList;
import io.fabric8.camelk.v1.IntegrationPlatform;
import io.fabric8.camelk.v1.IntegrationPlatformList;
import okhttp3.OkHttpClient;
import io.fabric8.kubernetes.client.BaseClient;
import io.fabric8.kubernetes.client.ClientState;
import io.fabric8.kubernetes.client.Handlers;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.Resource;

public class V1APIGroupClient extends BaseClient implements V1APIGroupDSL {
public V1APIGroupClient() {
super();
}

public V1APIGroupClient(OkHttpClient httpClient, final Config config) {
super(httpClient, config);
public V1APIGroupClient(ClientState clientState) {
super(clientState);
}

@Override
public MixedOperation<Build, BuildList, Resource<Build>> builds() {
return Handlers.getOperation(Build.class, BuildList.class, httpClient, getConfiguration());
return Handlers.getOperation(Build.class, BuildList.class, this);
}

@Override
public MixedOperation<CamelCatalog, CamelCatalogList, Resource<CamelCatalog>> camelCatalogs() {
return Handlers.getOperation(CamelCatalog.class, CamelCatalogList.class, httpClient, getConfiguration());
return Handlers.getOperation(CamelCatalog.class, CamelCatalogList.class, this);
}

@Override
public MixedOperation<Integration, IntegrationList, Resource<Integration>> integrations() {
return Handlers.getOperation(Integration.class, IntegrationList.class, httpClient, getConfiguration());
return Handlers.getOperation(Integration.class, IntegrationList.class, this);
}

@Override
public MixedOperation<IntegrationKit, IntegrationKitList, Resource<IntegrationKit>> integrationKits() {
return Handlers.getOperation(IntegrationKit.class, IntegrationKitList.class, httpClient, getConfiguration());
return Handlers.getOperation(IntegrationKit.class, IntegrationKitList.class, this);
}

@Override
public MixedOperation<IntegrationPlatform, IntegrationPlatformList, Resource<IntegrationPlatform>> integrationPlatforms() {
return Handlers.getOperation(IntegrationPlatform.class, IntegrationPlatformList.class, httpClient, getConfiguration());
return Handlers.getOperation(IntegrationPlatform.class, IntegrationPlatformList.class, this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import io.fabric8.kubernetes.client.APIGroupExtensionAdapter;
import io.fabric8.kubernetes.client.Client;
import okhttp3.OkHttpClient;

public class V1APIGroupExtensionAdapter extends APIGroupExtensionAdapter<V1APIGroupClient> {
@Override
Expand All @@ -32,6 +31,6 @@ public Class<V1APIGroupClient> getExtensionType() {

@Override
protected V1APIGroupClient newInstance(Client client) {
return new V1APIGroupClient(client.adapt(OkHttpClient.class), client.getConfiguration());
return new V1APIGroupClient(client);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,27 @@
*/
package io.fabric8.camelk.client;

import io.fabric8.camelk.client.dsl.V1alpha1APIGroupDSL;
import io.fabric8.camelk.v1alpha1.Kamelet;
import io.fabric8.camelk.v1alpha1.KameletList;
import io.fabric8.kubernetes.client.BaseClient;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ClientState;
import io.fabric8.kubernetes.client.Handlers;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.camelk.client.dsl.V1alpha1APIGroupDSL;
import io.fabric8.camelk.v1alpha1.Kamelet;
import io.fabric8.camelk.v1alpha1.KameletList;
import okhttp3.OkHttpClient;

public class V1alpha1APIGroupClient extends BaseClient implements V1alpha1APIGroupDSL {

public V1alpha1APIGroupClient() {
super();
}

public V1alpha1APIGroupClient(OkHttpClient httpClient, final Config config) {
super(httpClient, config);
public V1alpha1APIGroupClient(ClientState clientState) {
super(clientState);
}

@Override
public MixedOperation<Kamelet, KameletList, Resource<Kamelet>> kamelets() {
return Handlers.getOperation(Kamelet.class, KameletList.class, httpClient, getConfiguration());
return Handlers.getOperation(Kamelet.class, KameletList.class, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import io.fabric8.kubernetes.client.APIGroupExtensionAdapter;
import io.fabric8.kubernetes.client.Client;
import okhttp3.OkHttpClient;

public class V1alpha1APIGroupExtensionAdapter extends APIGroupExtensionAdapter<V1alpha1APIGroupClient> {
@Override
Expand All @@ -32,6 +31,6 @@ public Class<V1alpha1APIGroupClient> getExtensionType() {

@Override
protected V1alpha1APIGroupClient newInstance(Client client) {
return new V1alpha1APIGroupClient(client.adapt(OkHttpClient.class), client.getConfiguration());
return new V1alpha1APIGroupClient(client);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,19 @@
*/
package io.fabric8.camelk.mock;

import io.fabric8.camelk.client.DefaultCamelKClient;
import io.fabric8.camelk.client.NamespacedCamelKClient;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
import io.fabric8.mockwebserver.Context;
import io.fabric8.mockwebserver.ServerRequest;
import io.fabric8.mockwebserver.ServerResponse;
import io.fabric8.camelk.client.DefaultCamelKClient;
import io.fabric8.camelk.client.CamelKClient;
import okhttp3.mockwebserver.Dispatcher;
import okhttp3.mockwebserver.MockWebServer;

import java.util.Map;
import java.util.Queue;

import static io.fabric8.kubernetes.client.utils.HttpClientUtils.createHttpClientForMockServer;
import static okhttp3.TlsVersion.TLS_1_2;

public class CamelKMockServer extends KubernetesMockServer {
private boolean disableApiGroupCheck = true;

public CamelKMockServer() {
super();
Expand All @@ -54,12 +47,6 @@ public String[] getRootPaths() {
}

public NamespacedCamelKClient createCamelKClient() {
Config config = new ConfigBuilder()
.withMasterUrl(url("/"))
.withNamespace("test")
.withTrustCerts(true)
.withTlsVersions(TLS_1_2)
.build();
return new DefaultCamelKClient(createHttpClientForMockServer(config), config);
return new DefaultCamelKClient(getMockConfiguration());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
*/
package io.fabric8.certmanager.client;

import io.fabric8.kubernetes.client.ExtensionAdapterSupport;
import io.fabric8.kubernetes.client.Client;
import io.fabric8.kubernetes.client.ExtensionAdapter;
import okhttp3.OkHttpClient;
import io.fabric8.kubernetes.client.ExtensionAdapterSupport;

import java.net.URL;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -42,6 +41,6 @@ public Boolean isAdaptable(Client client) {

@Override
public CertManagerClient adapt(Client client) {
return new DefaultCertManagerClient(client.adapt(OkHttpClient.class), client.getConfiguration());
return new DefaultCertManagerClient(client);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
import io.fabric8.certmanager.client.dsl.V1alpha2APIGroupDSL;
import io.fabric8.certmanager.client.dsl.V1alpha3APIGroupDSL;
import io.fabric8.certmanager.client.dsl.V1beta1APIGroupDSL;
import io.fabric8.kubernetes.client.*;
import io.fabric8.kubernetes.client.BaseClient;
import io.fabric8.kubernetes.client.ClientState;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.RequestConfig;
import io.fabric8.kubernetes.client.WithRequestCallable;
import io.fabric8.kubernetes.client.dsl.FunctionCallable;
import okhttp3.OkHttpClient;

public class DefaultCertManagerClient extends BaseClient implements NamespacedCertManagerClient {

Expand All @@ -33,8 +37,8 @@ public DefaultCertManagerClient(Config configuration) {
super(configuration);
}

public DefaultCertManagerClient(OkHttpClient httpClient, Config configuration) {
super(httpClient, configuration);
public DefaultCertManagerClient(ClientState clientState) {
super(clientState);
}

@Override
Expand All @@ -48,7 +52,7 @@ public NamespacedCertManagerClient inNamespace(String namespace) {
.withNamespace(namespace)
.build();

return new DefaultCertManagerClient(getHttpClient(), updated);
return new DefaultCertManagerClient(newState(updated));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,56 @@
import io.fabric8.certmanager.api.model.acme.v1.ChallengeList;
import io.fabric8.certmanager.api.model.acme.v1.Order;
import io.fabric8.certmanager.api.model.acme.v1.OrderList;
import io.fabric8.certmanager.api.model.v1.*;
import io.fabric8.certmanager.api.model.v1.Certificate;
import io.fabric8.certmanager.api.model.v1.CertificateList;
import io.fabric8.certmanager.api.model.v1.CertificateRequest;
import io.fabric8.certmanager.api.model.v1.CertificateRequestList;
import io.fabric8.certmanager.api.model.v1.ClusterIssuer;
import io.fabric8.certmanager.api.model.v1.ClusterIssuerList;
import io.fabric8.certmanager.api.model.v1.Issuer;
import io.fabric8.certmanager.api.model.v1.IssuerList;
import io.fabric8.certmanager.client.dsl.V1APIGroupDSL;
import io.fabric8.kubernetes.client.BaseClient;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ClientState;
import io.fabric8.kubernetes.client.Handlers;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import okhttp3.OkHttpClient;

public class V1APIGroupClient extends BaseClient implements V1APIGroupDSL {
public V1APIGroupClient() {super();}

public V1APIGroupClient(OkHttpClient httpClient, final Config config) {
super(httpClient, config);
public V1APIGroupClient(ClientState clientState) {
super(clientState);
}

@Override
public MixedOperation<Certificate, CertificateList, Resource<Certificate>> certificates() {
return Handlers.getOperation(Certificate.class, CertificateList.class, this.getHttpClient(), this.getConfiguration());
return Handlers.getOperation(Certificate.class, CertificateList.class, this);
}

@Override
public MixedOperation<CertificateRequest, CertificateRequestList, Resource<CertificateRequest>> certificateRequests() {
return Handlers.getOperation(CertificateRequest.class, CertificateRequestList.class, this.getHttpClient(), this.getConfiguration());
return Handlers.getOperation(CertificateRequest.class, CertificateRequestList.class, this);
}

@Override
public MixedOperation<Issuer, IssuerList, Resource<Issuer>> issuers() {
return Handlers.getOperation(Issuer.class, IssuerList.class, this.getHttpClient(), this.getConfiguration());
return Handlers.getOperation(Issuer.class, IssuerList.class, this);
}

@Override
public NonNamespaceOperation<ClusterIssuer, ClusterIssuerList, Resource<ClusterIssuer>> clusterIssuers() {
return Handlers.getOperation(ClusterIssuer.class, ClusterIssuerList.class, this.getHttpClient(), this.getConfiguration());
return Handlers.getOperation(ClusterIssuer.class, ClusterIssuerList.class, this);
}

@Override
public MixedOperation<Challenge, ChallengeList, Resource<Challenge>> challenges() {
return Handlers.getOperation(Challenge.class, ChallengeList.class, this.getHttpClient(), this.getConfiguration());
return Handlers.getOperation(Challenge.class, ChallengeList.class, this);
}

@Override
public MixedOperation<Order, OrderList, Resource<Order>> orders() {
return Handlers.getOperation(Order.class, OrderList.class, this.getHttpClient(), this.getConfiguration());
return Handlers.getOperation(Order.class, OrderList.class, this);
}
}
Loading