Skip to content

Commit

Permalink
Support Istio in Kubernetes Client
Browse files Browse the repository at this point in the history
This PR supports v1alpha3 and v1beta1 Istio API
Solution is based on https://github.com/snowdrop/istio-java-api
Tests have been moved from the above repository to here.
Fixes #3593
  • Loading branch information
Sgitario authored and manusa committed Dec 14, 2021
1 parent 6af67cd commit f0d977b
Show file tree
Hide file tree
Showing 68 changed files with 16,177 additions and 0 deletions.
83 changes: 83 additions & 0 deletions extensions/istio/client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2015 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.fabric8</groupId>
<artifactId>istio-extension-pom</artifactId>
<version>5.11-SNAPSHOT</version>
</parent>

<artifactId>istio-client</artifactId>
<packaging>bundle</packaging>
<name>Fabric8 :: Istio :: Client</name>

<properties>
<osgi.import>
io.fabric8.kubernetes.api.builder,
!io.fabric8.istio.client.*,
*
</osgi.import>
<osgi.export>
io.fabric8.istio.client.*
</osgi.export>
<osgi.include.resources>
/META-INF/services/io.fabric8.kubernetes.client.ExtensionAdapter=target/classes/META-INF/services/io.fabric8.kubernetes.client.ExtensionAdapter,
</osgi.include.resources>
</properties>

<dependencies>
<dependency>
<groupId>io.sundr</groupId>
<artifactId>builder-annotations</artifactId>
</dependency>
<dependency>
<groupId>io.sundr</groupId>
<artifactId>transform-annotations</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>istio-model-v1alpha3</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>istio-model-v1beta1</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.istio.client;

import io.fabric8.kubernetes.client.BaseClient;
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 DefaultIstioClient extends BaseClient implements NamespacedIstioClient {

public DefaultIstioClient() {
super();
}

public DefaultIstioClient(Config configuration) {
super(configuration);
}

public DefaultIstioClient(OkHttpClient httpClient, Config configuration) {
super(httpClient, configuration);
}

@Override
public NamespacedIstioClient inAnyNamespace() {
return inNamespace(null);
}

@Override
public NamespacedIstioClient inNamespace(String namespace) {
Config updated = new ConfigBuilder(getConfiguration())
.withNamespace(namespace)
.build();

return new DefaultIstioClient(getHttpClient(), updated);
}

@Override
public FunctionCallable<NamespacedIstioClient> withRequestConfig(RequestConfig requestConfig) {
return new WithRequestCallable<>(this, requestConfig);
}

@Override
public V1alpha3APIGroupDSL v1alpha3() {
return adapt(V1alpha3APIGroupDSL.class);
}

@Override
public V1beta1APIGroupDSL v1beta1() {
return adapt(V1beta1APIGroupDSL.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.istio.client;

import io.fabric8.kubernetes.client.Client;
import io.fabric8.kubernetes.client.dsl.AnyNamespaceable;
import io.fabric8.kubernetes.client.dsl.Namespaceable;
import io.fabric8.kubernetes.client.dsl.RequestConfigurable;

public interface GenericIstioClient<C extends Client>
extends Client, IstioClient, Namespaceable<C>, AnyNamespaceable<C>, RequestConfigurable<C> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.istio.client;

import io.fabric8.kubernetes.client.Client;

/**
* Main interface for Istio Client.
*/
public interface IstioClient extends Client {
/**
* API entrypoint for istio.io/v1beta1 API group resources
*
* @return {@link V1beta1APIGroupDSL} for Istio resource operations in this API group.
*/
V1beta1APIGroupDSL v1beta1();

/**
* API entrypoint for istio.io/v1alpha3 API group resources
*
* @return {@link V1alpha3APIGroupDSL} for Istio resource operations in this API group.
*/
V1alpha3APIGroupDSL v1alpha3();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.istio.client;

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

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

public class IstioExtensionAdapter extends ExtensionAdapterSupport implements ExtensionAdapter<IstioClient> {

private static final ConcurrentMap<URL, Boolean> IS_ISTIO = new ConcurrentHashMap<>();
private static final ConcurrentMap<URL, Boolean> USES_ISTIO_APIGROUPS = new ConcurrentHashMap<>();

@Override
public Class<IstioClient> getExtensionType() {
return IstioClient.class;
}

@Override
public Boolean isAdaptable(Client client) {
return isAdaptable(client, IS_ISTIO, USES_ISTIO_APIGROUPS, "istio.io");
}

@Override
public IstioClient adapt(Client client) {
return new DefaultIstioClient(client.adapt(OkHttpClient.class), client.getConfiguration());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.istio.client;

public interface NamespacedIstioClient extends IstioClient, GenericIstioClient<NamespacedIstioClient> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.istio.client;

import io.fabric8.istio.api.networking.v1alpha3.DestinationRule;
import io.fabric8.istio.api.networking.v1alpha3.DestinationRuleList;
import io.fabric8.istio.api.networking.v1alpha3.EnvoyFilter;
import io.fabric8.istio.api.networking.v1alpha3.EnvoyFilterList;
import io.fabric8.istio.api.networking.v1alpha3.Gateway;
import io.fabric8.istio.api.networking.v1alpha3.GatewayList;
import io.fabric8.istio.api.networking.v1alpha3.ServiceEntry;
import io.fabric8.istio.api.networking.v1alpha3.ServiceEntryList;
import io.fabric8.istio.api.networking.v1alpha3.Sidecar;
import io.fabric8.istio.api.networking.v1alpha3.SidecarList;
import io.fabric8.istio.api.networking.v1alpha3.VirtualService;
import io.fabric8.istio.api.networking.v1alpha3.VirtualServiceList;
import io.fabric8.istio.api.networking.v1alpha3.WorkloadEntry;
import io.fabric8.istio.api.networking.v1alpha3.WorkloadEntryList;
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.Resource;
import okhttp3.OkHttpClient;

public class V1alpha3APIGroupClient extends BaseClient implements V1alpha3APIGroupDSL {

public V1alpha3APIGroupClient() {
super();
}

public V1alpha3APIGroupClient(Config configuration) {
super(configuration);
}

public V1alpha3APIGroupClient(OkHttpClient httpClient, Config configuration) {
super(httpClient, configuration);
}

// networking

@Override
public MixedOperation<DestinationRule, DestinationRuleList, Resource<DestinationRule>> destinationRules() {
return Handlers.getOperation(DestinationRule.class, DestinationRuleList.class, this.getHttpClient(),
this.getConfiguration());
}

@Override
public MixedOperation<EnvoyFilter, EnvoyFilterList, Resource<EnvoyFilter>> envoyFilters() {
return Handlers.getOperation(EnvoyFilter.class, EnvoyFilterList.class, this.getHttpClient(),
this.getConfiguration());
}

@Override
public MixedOperation<Gateway, GatewayList, Resource<Gateway>> gateways() {
return Handlers.getOperation(Gateway.class, GatewayList.class, this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<ServiceEntry, ServiceEntryList, Resource<ServiceEntry>> serviceEntries() {
return Handlers.getOperation(ServiceEntry.class, ServiceEntryList.class, this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<Sidecar, SidecarList, Resource<Sidecar>> sidecars() {
return Handlers.getOperation(Sidecar.class, SidecarList.class, this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<VirtualService, VirtualServiceList, Resource<VirtualService>> virtualServices() {
return Handlers.getOperation(VirtualService.class, VirtualServiceList.class, this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<WorkloadEntry, WorkloadEntryList, Resource<WorkloadEntry>> workloadEntries() {
return Handlers.getOperation(WorkloadEntry.class, WorkloadEntryList.class, this.getHttpClient(), this.getConfiguration());
}
}
Loading

0 comments on commit f0d977b

Please sign in to comment.