Skip to content

Commit 24f1b8e

Browse files
authored
refactor(osgi): migrated to OSGi Service Component annotations from Apache Felix XC
+ 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]>
1 parent 150c111 commit 24f1b8e

File tree

11 files changed

+54
-125
lines changed

11 files changed

+54
-125
lines changed

doc/MIGRATION-v7.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

24+
## Apache Felix SCR annotations removed <a href="#apache-felix-scr-annotations" id="apache-felix-scr-annotations" />
25+
26+
[Apache Felix SCR annotations](https://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin/scr-annotations.html) are not supported anymore by community. Fabric8 Kubernetes Client no longer uses Apache Felix SCR annotations for OSGi
27+
Declarative Services. Fabric8 Kubernetes Client is now using official OSGi annotations instead. If you're using Apache Felix SCR
28+
annotations, you need to switch to [Official OSGi Component annotations](https://docs.osgi.org/javadoc/r6/cmpn/org/osgi/service/component/annotations/package-summary.html).
29+
2330
## Model Changes <a href="#model-changes" id="model-changes"/>
2431

2532
### kubernetes-model artifact removed <a href="#kubernetes-model-artifact-removed" id="kubernetes-model-artifact-removed"/>

kubernetes-client-api/pom.xml

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,11 @@
180180
<artifactId>lombok</artifactId>
181181
</dependency>
182182
<dependency>
183-
<groupId>org.apache.felix</groupId>
184-
<artifactId>org.apache.felix.scr.annotations</artifactId>
185-
<version>${scr.annotations.version}</version>
186-
<scope>compile</scope>
187-
<optional>true</optional>
188-
</dependency>
183+
<groupId>org.osgi</groupId>
184+
<artifactId>org.osgi.service.component.annotations</artifactId>
185+
<scope>compile</scope>
186+
<optional>true</optional>
187+
</dependency>
189188

190189
<!-- Testing Dependencies -->
191190
<dependency>
@@ -275,22 +274,6 @@
275274
</execution>
276275
</executions>
277276
</plugin>
278-
<plugin>
279-
<groupId>org.apache.felix</groupId>
280-
<artifactId>maven-scr-plugin</artifactId>
281-
<version>${maven.scr.plugin.version}</version>
282-
<executions>
283-
<execution>
284-
<goals>
285-
<goal>scr</goal>
286-
</goals>
287-
<configuration>
288-
<specVersion>1.2</specVersion>
289-
<strictMode>true</strictMode>
290-
</configuration>
291-
</execution>
292-
</executions>
293-
</plugin>
294277
<plugin>
295278
<groupId>org.apache.felix</groupId>
296279
<artifactId>maven-bundle-plugin</artifactId>

kubernetes-client/pom.xml

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@
9797
<artifactId>lombok</artifactId>
9898
</dependency>
9999
<dependency>
100-
<groupId>org.apache.felix</groupId>
101-
<artifactId>org.apache.felix.scr.annotations</artifactId>
102-
<version>${scr.annotations.version}</version>
100+
<groupId>org.osgi</groupId>
101+
<artifactId>org.osgi.service.component.annotations</artifactId>
103102
<scope>compile</scope>
104103
<optional>true</optional>
105104
</dependency>
@@ -193,22 +192,6 @@
193192
</execution>
194193
</executions>
195194
</plugin>
196-
<plugin>
197-
<groupId>org.apache.felix</groupId>
198-
<artifactId>maven-scr-plugin</artifactId>
199-
<version>${maven.scr.plugin.version}</version>
200-
<executions>
201-
<execution>
202-
<goals>
203-
<goal>scr</goal>
204-
</goals>
205-
<configuration>
206-
<specVersion>1.2</specVersion>
207-
<strictMode>true</strictMode>
208-
</configuration>
209-
</execution>
210-
</executions>
211-
</plugin>
212195
<plugin>
213196
<groupId>org.apache.felix</groupId>
214197
<artifactId>maven-bundle-plugin</artifactId>

kubernetes-client/src/main/java/io/fabric8/kubernetes/client/osgi/ManagedKubernetesClient.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@
2323
import io.fabric8.kubernetes.client.OAuthTokenProvider;
2424
import io.fabric8.kubernetes.client.impl.KubernetesClientImpl;
2525
import io.fabric8.kubernetes.client.impl.ResourceHandler;
26-
import org.apache.felix.scr.annotations.Activate;
27-
import org.apache.felix.scr.annotations.Component;
28-
import org.apache.felix.scr.annotations.ConfigurationPolicy;
29-
import org.apache.felix.scr.annotations.Deactivate;
30-
import org.apache.felix.scr.annotations.Reference;
31-
import org.apache.felix.scr.annotations.ReferenceCardinality;
32-
import org.apache.felix.scr.annotations.ReferencePolicy;
33-
import org.apache.felix.scr.annotations.ReferencePolicyOption;
34-
import org.apache.felix.scr.annotations.References;
35-
import org.apache.felix.scr.annotations.Service;
3626

3727
import java.util.Map;
3828

@@ -62,12 +52,11 @@
6252
import static io.fabric8.kubernetes.client.Config.KUBERNETES_WATCH_RECONNECT_LIMIT_SYSTEM_PROPERTY;
6353
import static io.fabric8.kubernetes.client.Config.KUBERNETES_WEBSOCKET_PING_INTERVAL_SYSTEM_PROPERTY;
6454

65-
@Component(configurationPid = "io.fabric8.kubernetes.client", policy = ConfigurationPolicy.REQUIRE)
66-
@Service({ KubernetesClient.class, NamespacedKubernetesClient.class })
67-
@References({
68-
@Reference(referenceInterface = ResourceHandler.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC, bind = "bindResourceHandler", unbind = "unbindResourceHandler"),
69-
@Reference(referenceInterface = OAuthTokenProvider.class, cardinality = ReferenceCardinality.OPTIONAL_UNARY, policyOption = ReferencePolicyOption.GREEDY, bind = "bindOAuthTokenProvider", unbind = "unbindOAuthTokenProvider")
70-
})
55+
@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 = {
56+
KubernetesClient.class, NamespacedKubernetesClient.class }, reference = {
57+
@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"),
58+
@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"),
59+
}, configurationPolicy = org.osgi.service.component.annotations.ConfigurationPolicy.REQUIRE)
7160
public class ManagedKubernetesClient extends NamespacedKubernetesClientAdapter<KubernetesClientImpl> {
7261

7362
public ManagedKubernetesClient() {
@@ -76,7 +65,7 @@ public ManagedKubernetesClient() {
7665

7766
private OAuthTokenProvider provider;
7867

79-
@Activate
68+
@org.osgi.service.component.annotations.Activate
8069
public void activate(Map<String, Object> properties) {
8170
final ConfigBuilder builder = new ConfigBuilder();
8271

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

169-
@Deactivate
158+
@org.osgi.service.component.annotations.Deactivate
170159
public void deactivate() {
171160
this.close();
172161
}

openshift-client-api/pom.xml

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,12 @@
128128
<artifactId>lombok</artifactId>
129129
</dependency>
130130

131-
<dependency>
132-
<groupId>org.apache.felix</groupId>
133-
<artifactId>org.apache.felix.scr.annotations</artifactId>
134-
<version>${scr.annotations.version}</version>
135-
<scope>compile</scope>
136-
<optional>true</optional>
137-
</dependency>
131+
<dependency>
132+
<groupId>org.osgi</groupId>
133+
<artifactId>org.osgi.service.component.annotations</artifactId>
134+
<scope>compile</scope>
135+
<optional>true</optional>
136+
</dependency>
138137

139138
<!-- Testing Dependencies -->
140139
<dependency>
@@ -219,22 +218,6 @@
219218
</execution>
220219
</executions>
221220
</plugin>
222-
<plugin>
223-
<groupId>org.apache.felix</groupId>
224-
<artifactId>maven-scr-plugin</artifactId>
225-
<version>${maven.scr.plugin.version}</version>
226-
<executions>
227-
<execution>
228-
<goals>
229-
<goal>scr</goal>
230-
</goals>
231-
<configuration>
232-
<specVersion>1.2</specVersion>
233-
<strictMode>true</strictMode>
234-
</configuration>
235-
</execution>
236-
</executions>
237-
</plugin>
238221
<plugin>
239222
<groupId>org.apache.felix</groupId>
240223
<artifactId>maven-bundle-plugin</artifactId>

openshift-client/pom.xml

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,12 @@
7878
<artifactId>lombok</artifactId>
7979
</dependency>
8080

81-
<dependency>
82-
<groupId>org.apache.felix</groupId>
83-
<artifactId>org.apache.felix.scr.annotations</artifactId>
84-
<version>${scr.annotations.version}</version>
85-
<scope>compile</scope>
86-
<optional>true</optional>
87-
</dependency>
81+
<dependency>
82+
<groupId>org.osgi</groupId>
83+
<artifactId>org.osgi.service.component.annotations</artifactId>
84+
<scope>compile</scope>
85+
<optional>true</optional>
86+
</dependency>
8887

8988
<!-- Testing Dependencies -->
9089
<dependency>
@@ -186,22 +185,6 @@
186185
</execution>
187186
</executions>
188187
</plugin>
189-
<plugin>
190-
<groupId>org.apache.felix</groupId>
191-
<artifactId>maven-scr-plugin</artifactId>
192-
<version>${maven.scr.plugin.version}</version>
193-
<executions>
194-
<execution>
195-
<goals>
196-
<goal>scr</goal>
197-
</goals>
198-
<configuration>
199-
<specVersion>1.2</specVersion>
200-
<strictMode>true</strictMode>
201-
</configuration>
202-
</execution>
203-
</executions>
204-
</plugin>
205188
<plugin>
206189
<groupId>org.apache.felix</groupId>
207190
<artifactId>maven-bundle-plugin</artifactId>

openshift-client/src/main/java/io/fabric8/openshift/client/impl/NamespacedOpenShiftExtensionAdapter.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@
1818
import io.fabric8.kubernetes.client.Client;
1919
import io.fabric8.kubernetes.client.extension.ExtensionAdapter;
2020
import io.fabric8.openshift.client.NamespacedOpenShiftClient;
21-
import org.apache.felix.scr.annotations.Component;
22-
import org.apache.felix.scr.annotations.Service;
2321

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

3229
@Override

openshift-client/src/main/java/io/fabric8/openshift/client/impl/OpenShiftExtensionAdapter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@
4747
import io.fabric8.openshift.client.dsl.internal.build.BuildOperationsImpl;
4848
import io.fabric8.openshift.client.dsl.internal.core.TemplateOperationsImpl;
4949
import io.fabric8.openshift.client.dsl.internal.project.ProjectOperationsImpl;
50-
import org.apache.felix.scr.annotations.Component;
51-
import org.apache.felix.scr.annotations.Service;
5250

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

5755
@Override

openshift-client/src/main/java/io/fabric8/openshift/client/osgi/ManagedOpenShiftClient.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
import io.fabric8.openshift.client.NamespacedOpenShiftClientAdapter;
2222
import io.fabric8.openshift.client.OpenShiftClient;
2323
import io.fabric8.openshift.client.OpenShiftConfigBuilder;
24-
import org.apache.felix.scr.annotations.Activate;
25-
import org.apache.felix.scr.annotations.Component;
26-
import org.apache.felix.scr.annotations.ConfigurationPolicy;
27-
import org.apache.felix.scr.annotations.Deactivate;
28-
import org.apache.felix.scr.annotations.Service;
2924

3025
import java.util.Map;
3126

@@ -54,11 +49,12 @@
5449
import static io.fabric8.openshift.client.OpenShiftConfig.OPENSHIFT_BUILD_TIMEOUT_SYSTEM_PROPERTY;
5550
import static io.fabric8.openshift.client.OpenShiftConfig.OPENSHIFT_URL_SYSTEM_PROPERTY;
5651

57-
@Component(configurationPid = "io.fabric8.openshift.client", policy = ConfigurationPolicy.REQUIRE)
58-
@Service({ OpenShiftClient.class, NamespacedOpenShiftClient.class })
52+
@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 = {
53+
OpenShiftClient.class,
54+
NamespacedOpenShiftClient.class }, configurationPolicy = org.osgi.service.component.annotations.ConfigurationPolicy.REQUIRE)
5955
public class ManagedOpenShiftClient extends NamespacedOpenShiftClientAdapter {
6056

61-
@Activate
57+
@org.osgi.service.component.annotations.Activate
6258
public void activate(Map<String, Object> properties) {
6359
final OpenShiftConfigBuilder builder = new OpenShiftConfigBuilder();
6460

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

148-
@Deactivate
144+
@org.osgi.service.component.annotations.Deactivate
149145
public void deactivate() {
150146
getClient().close();
151147
}

platforms/karaf/features/src/main/resources/feature.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
1717
-->
1818
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="kuberntes-features-${project.version}">
19-
19+
<feature name="scr" description="Declarative Service support" version="${project.version}">
20+
<bundle start-level="30">mvn:org.apache.felix/org.apache.felix.scr/${felix.scr.version}</bundle>
21+
</feature>
2022
<feature name="kubernetes-client" description="Fabric8 Kubernetes Client" version="${project.version}">
23+
<feature>scr</feature>
2124
<bundle dependency='true'>mvn:com.google.code.findbugs/jsr305/${jsr305.version}</bundle>
2225
<bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-core/${jackson.bundle.version}</bundle>
2326
<bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson.bundle.version}</bundle>

0 commit comments

Comments
 (0)