From 28b38e697d0d0cdb80daaf1ca0483e63118ece73 Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Wed, 21 Aug 2024 23:42:44 +0530 Subject: [PATCH] chore : Migrate to OSGi Service Component annotations to Kubernetes client + Remove Apache Felix SCR annotations as they're unsupported. + Add OSGi Service Component annotations to ManagedKubernetesClient and ManagedOpenShiftClient Signed-off-by: Rohan Kumar --- doc/MIGRATION-v7.md | 7 +++++ kubernetes-client-api/pom.xml | 27 ++++------------- kubernetes-client/pom.xml | 21 ++------------ .../client/osgi/ManagedKubernetesClient.java | 25 +++++----------- openshift-client-api/pom.xml | 29 ++++--------------- openshift-client/pom.xml | 29 ++++--------------- .../NamespacedOpenShiftExtensionAdapter.java | 5 +--- .../impl/OpenShiftExtensionAdapter.java | 6 ++-- .../client/osgi/ManagedOpenShiftClient.java | 14 ++++----- .../features/src/main/resources/feature.xml | 5 +++- pom.xml | 10 +++++-- 11 files changed, 53 insertions(+), 125 deletions(-) diff --git a/doc/MIGRATION-v7.md b/doc/MIGRATION-v7.md index 5988731f79f..3e1ba3faf21 100644 --- a/doc/MIGRATION-v7.md +++ b/doc/MIGRATION-v7.md @@ -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) @@ -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 + +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 ### kubernetes-model artifact removed diff --git a/kubernetes-client-api/pom.xml b/kubernetes-client-api/pom.xml index 021785f00fa..56fbf44db8a 100644 --- a/kubernetes-client-api/pom.xml +++ b/kubernetes-client-api/pom.xml @@ -180,12 +180,11 @@ lombok - org.apache.felix - org.apache.felix.scr.annotations - ${scr.annotations.version} - compile - true - + org.osgi + org.osgi.service.component.annotations + compile + true + @@ -275,22 +274,6 @@ - - org.apache.felix - maven-scr-plugin - ${maven.scr.plugin.version} - - - - scr - - - 1.2 - true - - - - org.apache.felix maven-bundle-plugin diff --git a/kubernetes-client/pom.xml b/kubernetes-client/pom.xml index 20a2b613cf8..278503c4631 100644 --- a/kubernetes-client/pom.xml +++ b/kubernetes-client/pom.xml @@ -97,9 +97,8 @@ lombok - org.apache.felix - org.apache.felix.scr.annotations - ${scr.annotations.version} + org.osgi + org.osgi.service.component.annotations compile true @@ -193,22 +192,6 @@ - - org.apache.felix - maven-scr-plugin - ${maven.scr.plugin.version} - - - - scr - - - 1.2 - true - - - - org.apache.felix maven-bundle-plugin diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/osgi/ManagedKubernetesClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/osgi/ManagedKubernetesClient.java index ab7916c1f01..caaab25a2e6 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/osgi/ManagedKubernetesClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/osgi/ManagedKubernetesClient.java @@ -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; @@ -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 { public ManagedKubernetesClient() { @@ -76,7 +65,7 @@ public ManagedKubernetesClient() { private OAuthTokenProvider provider; - @Activate + @org.osgi.service.component.annotations.Activate public void activate(Map properties) { final ConfigBuilder builder = new ConfigBuilder(); @@ -166,7 +155,7 @@ public void activate(Map properties) { this.init(new KubernetesClientBuilder().withConfig(builder.build()).build()); } - @Deactivate + @org.osgi.service.component.annotations.Deactivate public void deactivate() { this.close(); } diff --git a/openshift-client-api/pom.xml b/openshift-client-api/pom.xml index e3f65f36b98..ff2a647d053 100644 --- a/openshift-client-api/pom.xml +++ b/openshift-client-api/pom.xml @@ -128,13 +128,12 @@ lombok - - org.apache.felix - org.apache.felix.scr.annotations - ${scr.annotations.version} - compile - true - + + org.osgi + org.osgi.service.component.annotations + compile + true + @@ -219,22 +218,6 @@ - - org.apache.felix - maven-scr-plugin - ${maven.scr.plugin.version} - - - - scr - - - 1.2 - true - - - - org.apache.felix maven-bundle-plugin diff --git a/openshift-client/pom.xml b/openshift-client/pom.xml index 66f25352e29..5bb6d8433c3 100644 --- a/openshift-client/pom.xml +++ b/openshift-client/pom.xml @@ -78,13 +78,12 @@ lombok - - org.apache.felix - org.apache.felix.scr.annotations - ${scr.annotations.version} - compile - true - + + org.osgi + org.osgi.service.component.annotations + compile + true + @@ -186,22 +185,6 @@ - - org.apache.felix - maven-scr-plugin - ${maven.scr.plugin.version} - - - - scr - - - 1.2 - true - - - - org.apache.felix maven-bundle-plugin diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/impl/NamespacedOpenShiftExtensionAdapter.java b/openshift-client/src/main/java/io/fabric8/openshift/client/impl/NamespacedOpenShiftExtensionAdapter.java index 053c0e9f243..afdf898676e 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/impl/NamespacedOpenShiftExtensionAdapter.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/impl/NamespacedOpenShiftExtensionAdapter.java @@ -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 { @Override diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/impl/OpenShiftExtensionAdapter.java b/openshift-client/src/main/java/io/fabric8/openshift/client/impl/OpenShiftExtensionAdapter.java index 3280442e7d2..68b6f70c773 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/impl/OpenShiftExtensionAdapter.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/impl/OpenShiftExtensionAdapter.java @@ -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, InternalExtensionAdapter { @Override diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/osgi/ManagedOpenShiftClient.java b/openshift-client/src/main/java/io/fabric8/openshift/client/osgi/ManagedOpenShiftClient.java index 6ed35a139e4..24fc9e538a5 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/osgi/ManagedOpenShiftClient.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/osgi/ManagedOpenShiftClient.java @@ -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; @@ -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 properties) { final OpenShiftConfigBuilder builder = new OpenShiftConfigBuilder(); @@ -145,7 +141,7 @@ public void activate(Map properties) { this.init(delegate); } - @Deactivate + @org.osgi.service.component.annotations.Deactivate public void deactivate() { getClient().close(); } diff --git a/platforms/karaf/features/src/main/resources/feature.xml b/platforms/karaf/features/src/main/resources/feature.xml index f53b7c076ef..d340c9fec61 100644 --- a/platforms/karaf/features/src/main/resources/feature.xml +++ b/platforms/karaf/features/src/main/resources/feature.xml @@ -16,8 +16,11 @@ --> - + + mvn:org.apache.felix/org.apache.felix.scr/${felix.scr.version} + + scr mvn:com.google.code.findbugs/jsr305/${jsr305.version} mvn:com.fasterxml.jackson.core/jackson-core/${jackson.bundle.version} mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson.bundle.version} diff --git a/pom.xml b/pom.xml index f88771795b0..bfda35f6966 100644 --- a/pom.xml +++ b/pom.xml @@ -133,7 +133,7 @@ 1.27.1 2.16.1 33.3.0-jre - 1.12.0 + 1.5.0 1.2.1 4.7.6 1.0.0 @@ -147,7 +147,6 @@ 3.6.0 3.4.2 3.4.0 - 1.26.4 3.3.1 3.1.1 3.8.0 @@ -882,6 +881,13 @@ okio ${okio.version} + + org.osgi + org.osgi.service.component.annotations + ${osgi.annotations.version} + compile + true +