Skip to content

Commit

Permalink
chore : Migrate to OSGi Service Component annotations to Kubernetes c…
Browse files Browse the repository at this point in the history
…lient

+ Remove Apache Felix SCR annotations as they're unsupported.
+ Add OSGi Service Component annotations to ManagedKubernetesClient and ManagedOpenShiftClient

Signed-off-by: Rohan Kumar <[email protected]>
  • Loading branch information
rohanKanojia committed Aug 26, 2024
1 parent 8b93dad commit 28b38e6
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 125 deletions.
7 changes: 7 additions & 0 deletions doc/MIGRATION-v7.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Contents
- [Bouncy Castle is no longer needed](#bouncy-castle)
- [Apache Felix SCR Annotations removed](#apache-felix-scr-annoatations)
- [Model Changes](#model-changes)
- [kubernetes-model artifact removed](#kubernetes-model-artifact-removed)
- [Deprecations and Removals](#deprecations-and-removals)
Expand All @@ -20,6 +21,12 @@ The Bouncy Castle library is no longer needed as a dependency.
In previous versions, this was an optional dependency needed for Elliptic Curve (EC) Keys.
The Kubernetes client now uses the default Java security provider which should be enough to handle all scenarios.

## Apache Felix SCR annotations removed <a href="#apache-felix-scr-annotations" id="apache-felix-scr-annotations" />

Apache Felix SCR annotations are not supported anymore by community. Fabric8 Kubernetes Client no longer uses Apache Felix SCR annotations for OSGi
Declarative Services. Fabric8 Kubernetes Client is now using official OSGi annotations instead. If you're using Apache Felix SCR
annotations, you need to switch to Official OSGi Component annotations.

## Model Changes <a href="#model-changes" id="model-changes"/>

### kubernetes-model artifact removed <a href="#kubernetes-model-artifact-removed" id="kubernetes-model-artifact-removed"/>
Expand Down
27 changes: 5 additions & 22 deletions kubernetes-client-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,11 @@
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>${scr.annotations.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>

<!-- Testing Dependencies -->
<dependency>
Expand Down Expand Up @@ -275,22 +274,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>${maven.scr.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>scr</goal>
</goals>
<configuration>
<specVersion>1.2</specVersion>
<strictMode>true</strictMode>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
Expand Down
21 changes: 2 additions & 19 deletions kubernetes-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>${scr.annotations.version}</version>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>
Expand Down Expand Up @@ -193,22 +192,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>${maven.scr.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>scr</goal>
</goals>
<configuration>
<specVersion>1.2</specVersion>
<strictMode>true</strictMode>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@
import io.fabric8.kubernetes.client.OAuthTokenProvider;
import io.fabric8.kubernetes.client.impl.KubernetesClientImpl;
import io.fabric8.kubernetes.client.impl.ResourceHandler;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.ConfigurationPolicy;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.ReferencePolicyOption;
import org.apache.felix.scr.annotations.References;
import org.apache.felix.scr.annotations.Service;

import java.util.Map;

Expand Down Expand Up @@ -62,12 +52,11 @@
import static io.fabric8.kubernetes.client.Config.KUBERNETES_WATCH_RECONNECT_LIMIT_SYSTEM_PROPERTY;
import static io.fabric8.kubernetes.client.Config.KUBERNETES_WEBSOCKET_PING_INTERVAL_SYSTEM_PROPERTY;

@Component(configurationPid = "io.fabric8.kubernetes.client", policy = ConfigurationPolicy.REQUIRE)
@Service({ KubernetesClient.class, NamespacedKubernetesClient.class })
@References({
@Reference(referenceInterface = ResourceHandler.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC, bind = "bindResourceHandler", unbind = "unbindResourceHandler"),
@Reference(referenceInterface = OAuthTokenProvider.class, cardinality = ReferenceCardinality.OPTIONAL_UNARY, policyOption = ReferencePolicyOption.GREEDY, bind = "bindOAuthTokenProvider", unbind = "unbindOAuthTokenProvider")
})
@org.osgi.service.component.annotations.Component(configurationPid = "io.fabric8.kubernetes.client", name = "io.fabric8.kubernetes.client.osgi.ManagedKubernetesClient", scope = org.osgi.service.component.annotations.ServiceScope.SINGLETON, service = {
KubernetesClient.class, NamespacedKubernetesClient.class }, reference = {
@org.osgi.service.component.annotations.Reference(name = "resourceHandler", service = io.fabric8.kubernetes.client.impl.ResourceHandler.class, cardinality = org.osgi.service.component.annotations.ReferenceCardinality.MULTIPLE, policy = org.osgi.service.component.annotations.ReferencePolicy.DYNAMIC, bind = "bindResourceHandler", unbind = "unbindResourceHandler"),
@org.osgi.service.component.annotations.Reference(name = "oAuthTokenProvider", service = OAuthTokenProvider.class, cardinality = org.osgi.service.component.annotations.ReferenceCardinality.OPTIONAL, policyOption = org.osgi.service.component.annotations.ReferencePolicyOption.GREEDY, bind = "bindOAuthTokenProvider", unbind = "unbindOAuthTokenProvider"),
}, configurationPolicy = org.osgi.service.component.annotations.ConfigurationPolicy.REQUIRE)
public class ManagedKubernetesClient extends NamespacedKubernetesClientAdapter<KubernetesClientImpl> {

public ManagedKubernetesClient() {
Expand All @@ -76,7 +65,7 @@ public ManagedKubernetesClient() {

private OAuthTokenProvider provider;

@Activate
@org.osgi.service.component.annotations.Activate
public void activate(Map<String, Object> properties) {
final ConfigBuilder builder = new ConfigBuilder();

Expand Down Expand Up @@ -166,7 +155,7 @@ public void activate(Map<String, Object> properties) {
this.init(new KubernetesClientBuilder().withConfig(builder.build()).build());
}

@Deactivate
@org.osgi.service.component.annotations.Deactivate
public void deactivate() {
this.close();
}
Expand Down
29 changes: 6 additions & 23 deletions openshift-client-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,12 @@
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>${scr.annotations.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>

<!-- Testing Dependencies -->
<dependency>
Expand Down Expand Up @@ -219,22 +218,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>${maven.scr.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>scr</goal>
</goals>
<configuration>
<specVersion>1.2</specVersion>
<strictMode>true</strictMode>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
Expand Down
29 changes: 6 additions & 23 deletions openshift-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>${scr.annotations.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>

<!-- Testing Dependencies -->
<dependency>
Expand Down Expand Up @@ -186,22 +185,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>${maven.scr.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>scr</goal>
</goals>
<configuration>
<specVersion>1.2</specVersion>
<strictMode>true</strictMode>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
import io.fabric8.kubernetes.client.Client;
import io.fabric8.kubernetes.client.extension.ExtensionAdapter;
import io.fabric8.openshift.client.NamespacedOpenShiftClient;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;

/**
* This class is necessary because the extension logic checks for an exact class match,
* even though an {@link OpenShiftClientImpl} is already known via the {@link OpenShiftExtensionAdapter}
*/
@Component
@Service
@org.osgi.service.component.annotations.Component(name = "io.fabric8.openshift.client.impl.NamespacedOpenShiftExtensionAdapter", scope = org.osgi.service.component.annotations.ServiceScope.SINGLETON, service = ExtensionAdapter.class)
public class NamespacedOpenShiftExtensionAdapter implements ExtensionAdapter<NamespacedOpenShiftClient> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@
import io.fabric8.openshift.client.dsl.internal.build.BuildOperationsImpl;
import io.fabric8.openshift.client.dsl.internal.core.TemplateOperationsImpl;
import io.fabric8.openshift.client.dsl.internal.project.ProjectOperationsImpl;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;

@Component
@Service
@org.osgi.service.component.annotations.Component(name = "io.fabric8.openshift.client.impl.OpenShiftExtensionAdapter", scope = org.osgi.service.component.annotations.ServiceScope.SINGLETON, service = {
ExtensionAdapter.class, InternalExtensionAdapter.class })
public class OpenShiftExtensionAdapter implements ExtensionAdapter<OpenShiftClient>, InternalExtensionAdapter {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
import io.fabric8.openshift.client.NamespacedOpenShiftClientAdapter;
import io.fabric8.openshift.client.OpenShiftClient;
import io.fabric8.openshift.client.OpenShiftConfigBuilder;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.ConfigurationPolicy;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;

import java.util.Map;

Expand Down Expand Up @@ -54,11 +49,12 @@
import static io.fabric8.openshift.client.OpenShiftConfig.OPENSHIFT_BUILD_TIMEOUT_SYSTEM_PROPERTY;
import static io.fabric8.openshift.client.OpenShiftConfig.OPENSHIFT_URL_SYSTEM_PROPERTY;

@Component(configurationPid = "io.fabric8.openshift.client", policy = ConfigurationPolicy.REQUIRE)
@Service({ OpenShiftClient.class, NamespacedOpenShiftClient.class })
@org.osgi.service.component.annotations.Component(configurationPid = "io.fabric8.openshift.client", name = "io.fabric8.openshift.client.osgi.ManagedOpenShiftClient", scope = org.osgi.service.component.annotations.ServiceScope.SINGLETON, service = {
OpenShiftClient.class,
NamespacedOpenShiftClient.class }, configurationPolicy = org.osgi.service.component.annotations.ConfigurationPolicy.REQUIRE)
public class ManagedOpenShiftClient extends NamespacedOpenShiftClientAdapter {

@Activate
@org.osgi.service.component.annotations.Activate
public void activate(Map<String, Object> properties) {
final OpenShiftConfigBuilder builder = new OpenShiftConfigBuilder();

Expand Down Expand Up @@ -145,7 +141,7 @@ public void activate(Map<String, Object> properties) {
this.init(delegate);
}

@Deactivate
@org.osgi.service.component.annotations.Deactivate
public void deactivate() {
getClient().close();
}
Expand Down
5 changes: 4 additions & 1 deletion platforms/karaf/features/src/main/resources/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
-->
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="kuberntes-features-${project.version}">

<feature name="scr" description="Declarative Service support" version="${project.version}">
<bundle start-level="30">mvn:org.apache.felix/org.apache.felix.scr/${felix.scr.version}</bundle>
</feature>
<feature name="kubernetes-client" description="Fabric8 Kubernetes Client" version="${project.version}">
<feature>scr</feature>
<bundle dependency='true'>mvn:com.google.code.findbugs/jsr305/${jsr305.version}</bundle>
<bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-core/${jackson.bundle.version}</bundle>
<bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson.bundle.version}</bundle>
Expand Down
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<commons-compress.version>1.27.1</commons-compress.version>
<commons-io.version>2.16.1</commons-io.version> <!-- Required by Gradle Testing Toolkit -->
<guava.version>33.3.0-jre</guava.version> <!-- Required by Gradle Testing Toolkit -->
<scr.annotations.version>1.12.0</scr.annotations.version>
<osgi.annotations.version>1.5.0</osgi.annotations.version>
<jsonschema2pojo.version>1.2.1</jsonschema2pojo.version>
<picocli.version>4.7.6</picocli.version>
<properties.maven.plugin.version>1.0.0</properties.maven.plugin.version>
Expand All @@ -147,7 +147,6 @@
<maven.buildhelper.plugin.version>3.6.0</maven.buildhelper.plugin.version>
<maven.jar.plugin.version>3.4.2</maven.jar.plugin.version>
<maven.surefire.plugin.version>3.4.0</maven.surefire.plugin.version>
<maven.scr.plugin.version>1.26.4</maven.scr.plugin.version>
<maven.resources.plugin.version>3.3.1</maven.resources.plugin.version>
<maven.release.plugin.version>3.1.1</maven.release.plugin.version>
<maven.javadoc.plugin.version>3.8.0</maven.javadoc.plugin.version>
Expand Down Expand Up @@ -882,6 +881,13 @@
<artifactId>okio</artifactId>
<version>${okio.version}</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>${osgi.annotations.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

<!-- Testing and Mocking -->
<dependency>
Expand Down

0 comments on commit 28b38e6

Please sign in to comment.