Skip to content

Commit

Permalink
feat(kubernetes-client): allow for model module exclusions in native …
Browse files Browse the repository at this point in the history
…mode

Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa committed Nov 23, 2023
1 parent cd3a1d2 commit 7dd072e
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 192 deletions.
7 changes: 6 additions & 1 deletion extensions/openshift-client/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -70,4 +75,4 @@
</build>


</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package io.quarkus.it.openshift.client.runtime.graal;

import java.util.Arrays;
import java.util.function.BooleanSupplier;

import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.openshift.api.model.miscellaneous.apiserver.v1.APIRequestCount;
import io.fabric8.openshift.api.model.miscellaneous.apiserver.v1.APIRequestCountList;
import io.fabric8.openshift.api.model.miscellaneous.cloudcredential.v1.CredentialsRequest;
import io.fabric8.openshift.api.model.miscellaneous.cloudcredential.v1.CredentialsRequestList;
import io.fabric8.openshift.api.model.miscellaneous.cncf.cni.v1.NetworkAttachmentDefinition;
import io.fabric8.openshift.api.model.miscellaneous.cncf.cni.v1.NetworkAttachmentDefinitionList;
import io.fabric8.openshift.api.model.miscellaneous.imageregistry.operator.v1.Config;
import io.fabric8.openshift.api.model.miscellaneous.imageregistry.operator.v1.ConfigList;
import io.fabric8.openshift.api.model.miscellaneous.metal3.v1alpha1.BareMetalHost;
import io.fabric8.openshift.api.model.miscellaneous.metal3.v1alpha1.BareMetalHostList;
import io.fabric8.openshift.api.model.miscellaneous.metal3.v1beta1.Metal3Remediation;
import io.fabric8.openshift.api.model.miscellaneous.metal3.v1beta1.Metal3RemediationList;
import io.fabric8.openshift.api.model.miscellaneous.metal3.v1beta1.Metal3RemediationTemplate;
import io.fabric8.openshift.api.model.miscellaneous.metal3.v1beta1.Metal3RemediationTemplateList;
import io.fabric8.openshift.api.model.miscellaneous.network.operator.v1.EgressRouter;
import io.fabric8.openshift.api.model.miscellaneous.network.operator.v1.EgressRouterList;
import io.fabric8.openshift.api.model.miscellaneous.network.operator.v1.OperatorPKI;
import io.fabric8.openshift.api.model.miscellaneous.network.operator.v1.OperatorPKIList;

/**
* Allows the exclusion of the openshift-model-miscellaneous model without breaking the --link-at-build-time check.
*/
@TargetClass(className = "io.fabric8.openshift.client.impl.OpenShiftClientImpl", onlyWith = MiscellaneousSubstitutions.NoOpenShiftMiscellaneousModel.class)
public final class MiscellaneousSubstitutions {

@Substitute
public NonNamespaceOperation<APIRequestCount, APIRequestCountList, Resource<APIRequestCount>> apiRequestCounts() {
throw new RuntimeException(Constants.ERROR_MESSAGE);
}

@Substitute
public MixedOperation<BareMetalHost, BareMetalHostList, Resource<BareMetalHost>> bareMetalHosts() {
throw new RuntimeException(Constants.ERROR_MESSAGE);
}

@Substitute
public MixedOperation<CredentialsRequest, CredentialsRequestList, Resource<CredentialsRequest>> credentialsRequests() {
throw new RuntimeException(Constants.ERROR_MESSAGE);
}

@Substitute
public MixedOperation<EgressRouter, EgressRouterList, Resource<EgressRouter>> egressRouters() {
throw new RuntimeException(Constants.ERROR_MESSAGE);
}

@Substitute
public NonNamespaceOperation<Config, ConfigList, Resource<Config>> imageRegistryOperatorConfigs() {
throw new RuntimeException(Constants.ERROR_MESSAGE);
}

@Substitute
public MixedOperation<Metal3Remediation, Metal3RemediationList, Resource<Metal3Remediation>> metal3Remediations() {
throw new RuntimeException(Constants.ERROR_MESSAGE);
}

@Substitute
public MixedOperation<Metal3RemediationTemplate, Metal3RemediationTemplateList, Resource<Metal3RemediationTemplate>> metal3RemediationTemplates() {
throw new RuntimeException(Constants.ERROR_MESSAGE);
}

@Substitute
public MixedOperation<NetworkAttachmentDefinition, NetworkAttachmentDefinitionList, Resource<NetworkAttachmentDefinition>> networkAttachmentDefinitions() {
throw new RuntimeException(Constants.ERROR_MESSAGE);
}

@Substitute
public MixedOperation<OperatorPKI, OperatorPKIList, Resource<OperatorPKI>> operatorPKIs() {
throw new RuntimeException(Constants.ERROR_MESSAGE);
}

static final class Constants {
private static final String ERROR_MESSAGE = "OpenShift Miscellaneous API is not available, please add the openshift-model-miscellaneous module to your classpath";
}

static final class NoOpenShiftMiscellaneousModel implements BooleanSupplier {

private static final String OPENSHIFT_MODEL_MISCELLANEOUS_PACKAGE = "io.fabric8.openshift.api.model.miscellaneous.";
static final Boolean OPENSHIFT_MODEL_MISCELLANEOUS_PRESENT = Arrays.stream(Package.getPackages())
.map(Package::getName).anyMatch(p -> p.startsWith(OPENSHIFT_MODEL_MISCELLANEOUS_PACKAGE));

@Override
public boolean getAsBoolean() {
return !OPENSHIFT_MODEL_MISCELLANEOUS_PRESENT;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.it.openshift.client.runtime.graal;

import java.util.Arrays;
import java.util.function.BooleanSupplier;

import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

import io.fabric8.openshift.client.dsl.OpenShiftOperatorAPIGroupDSL;

/**
* Allows the exclusion of the openshift-model-operator model without breaking the --link-at-build-time check.
*/
@TargetClass(className = "io.fabric8.openshift.client.impl.OpenShiftClientImpl", onlyWith = OperatorSubstitutions.NoOpenShiftOperatorModel.class)
public final class OperatorSubstitutions {

@Substitute
public OpenShiftOperatorAPIGroupDSL operator() {
throw new RuntimeException(
"OpenShift Operator API is not available, please add the openshift-model-operator module to your classpath");
}

static final class NoOpenShiftOperatorModel implements BooleanSupplier {

private static final String OPENSHIFT_MODEL_OPERATOR_PACKAGE = "io.fabric8.openshift.api.model.operator.";
static final Boolean OPENSHIFT_MODEL_OPERATOR_PRESENT = Arrays.stream(Package.getPackages())
.map(Package::getName).anyMatch(p -> p.startsWith(OPENSHIFT_MODEL_OPERATOR_PACKAGE));

@Override
public boolean getAsBoolean() {
return !OPENSHIFT_MODEL_OPERATOR_PRESENT;
}
}
}

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions integration-tests/kubernetes-client-hack-extension/pom.xml

This file was deleted.

48 changes: 0 additions & 48 deletions integration-tests/kubernetes-client-hack-extension/runtime/pom.xml

This file was deleted.

This file was deleted.

26 changes: 6 additions & 20 deletions integration-tests/kubernetes-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,21 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-config</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-integration-test-kubernetes-client-hack-extension</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-openshift-client</artifactId>
<exclusions>
<exclusion>
<groupId>io.fabric8</groupId>
<artifactId>openshift-model-operator</artifactId>
<artifactId>openshift-model-hive</artifactId>
</exclusion>
<exclusion>
<groupId>io.fabric8</groupId>
<artifactId>openshift-model-operator-hub</artifactId>
<artifactId>openshift-model-miscellaneous</artifactId>
</exclusion>
<exclusion>
<groupId>io.fabric8</groupId>
<artifactId>openshift-model-operator</artifactId>
</exclusion>
</exclusions>
</dependency>
Expand Down Expand Up @@ -90,19 +89,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-integration-test-kubernetes-client-hack-extension-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-openshift-client-deployment</artifactId>
Expand Down
Loading

0 comments on commit 7dd072e

Please sign in to comment.