Skip to content

Commit

Permalink
Merge pull request #1353 from avano/openshift-sa
Browse files Browse the repository at this point in the history
[Openshift] Create a serviceaccount for the app by default
  • Loading branch information
jsafarik authored Feb 20, 2025
2 parents 7ec1b42 + fc95f4a commit eaddb2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import cz.xtf.core.openshift.helpers.ResourceFunctions;
import io.fabric8.kubernetes.api.model.IntOrString;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.ServiceAccount;
import io.fabric8.kubernetes.api.model.ServiceAccountBuilder;
import io.fabric8.kubernetes.api.model.ServiceBuilder;
import io.fabric8.openshift.api.model.RouteBuilder;
import io.fabric8.openshift.api.model.RoutePort;
Expand All @@ -55,6 +57,10 @@ public OpenshiftQuarkusApp(AbstractIntegrationBuilder<?> integrationBuilder) {

@Override
public void start() {
LOG.trace("Creating service account for the integration {}", getName());
ServiceAccount sa = new ServiceAccountBuilder().withNewMetadata().withName(getName()).endMetadata().build();
OpenshiftClient.get().serviceAccounts().resource(sa).serverSideApply();

final BuildRequest.Builder builder = new BuildRequest.Builder()
.withBaseDirectory(TestConfiguration.appLocation().resolve(getName()))
.withArgs("package")
Expand Down Expand Up @@ -121,6 +127,7 @@ private Map<String, String> getProperties() {
"quarkus.kubernetes.deploy", "true",
"quarkus.native.container-build", "true",
"quarkus.openshift.build-strategy", "docker",
"quarkus.openshift.service-account", getName(),
"skipTests", "true"
));
if (!QuarkusConfiguration.isQuarkusNative()) {
Expand Down Expand Up @@ -152,6 +159,7 @@ public void stop() {
LOG.info("Undeploying integration resources");
OpenshiftClient.get().routes().withName(getName()).delete();
OpenshiftClient.get().services().withName(getName()).delete();
OpenshiftClient.get().serviceAccounts().withName(getName()).delete();
Path openshiftResources = TestConfiguration.appLocation().resolve(getName()).resolve("target").resolve("kubernetes/openshift.yml");

try (InputStream is = IOUtils.toInputStream(Files.readString(openshiftResources), "UTF-8")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@
</build>
</image>
</images>
<resources>
<serviceAccounts>
<serviceAccount>
<name>${project.build.finalName}</name>
<deploymentRef>${project.build.finalName}</deploymentRef>
</serviceAccount>
</serviceAccounts>
</resources>
</configuration>

0 comments on commit eaddb2d

Please sign in to comment.