Skip to content

[OPENJDK-2992] Create DeploymentConfig and Route for jlink apps #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions templates/jlink/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ you need:
2. UBI9 OpenJDK ImageStreams that include `jlink-dev` changes (see below)
3. The template [jlinked-app.yaml](jlinked-app.yaml).

DISCLAIMER: This template requires OpenShift to be able to resolve ImageStreams, as such it can only be used in projects where the openshift.io/run-level label set to 0 or 1. This means it cannot be used with default, kube-public, kube-system, openshift, openshift-infra, openshift-node, and other system-created projects.

## Stage 0: UBI9 OpenJDK ImageStreams with jlink-dev changes

Until the `jlink-dev` work is merged, prior to trying out the template, we must first
Expand All @@ -16,29 +18,33 @@ prepare UBI9 OpenJDK ImageStreams with `jlink-dev` support.
repository](https://github.com/jboss-container-images/openjdk),
branch `jlink-dev`. e.g.

cekit --descriptor ubi9-openjdk-21.yaml build docker
cekit --descriptor ubi9-openjdk-21.yaml build podman

2. Create an OpenShift project

oc new-project $PROJECT

2. Within your OpenShift project,
3. Within your OpenShift project,

oc create imagestream openjdk-${JDK_VERSION}-jlink-tech-preview
oc create imagestream openjdk-21-jlink-tech-preview

3. You may need to configure your container engine to not TLS-verify the OpenShift
4. You may need to configure your container engine to not TLS-verify the OpenShift
registry. For Docker, add the following to `/etc/docker/daemon.json` and restart
the daemon:

{
"insecure-registries": [ "default-route-openshift-image-registry.apps-crc.testing" ]
}

4. Log into the OpenShift registry, e.g.
5. Log into the OpenShift registry, e.g.

REGISTRY_AUTH_PREFERENCE=docker oc registry login

5. tag and push the dev image into it. The OpenShift console gives you the
6. tag and push the dev image into it. The OpenShift console gives you the
exact URI for your instance

docker tag openjdk-tech-preview/openjdk-21-jlink-rhel9:latest default-route-openshift-image-registry.apps-crc.testing/jlink1/openjdk-21-jlink-tech-preview:latest
docker push default-route-openshift-image-registry.apps-crc.testing/jlink1/openjdk-21-jlink-tech-preview:latest
podman tag openjdk-tech-preview/openjdk-21-jlink-rhel9:latest default-route-openshift-image-registry.apps-crc.testing/$PROJECT/openjdk-21-jlink-tech-preview:latest
podman push default-route-openshift-image-registry.apps-crc.testing/$PROJECT/openjdk-21-jlink-tech-preview:latest

## Stage 1: Load the template into OpenShift and instantiate it

Expand All @@ -57,13 +63,17 @@ Some suitable test values for the parameters are
* REF: master
* CONTEXT_DIR: quarkus-quickstarts/getting-started-3.9.2-uberjar
* APPNAME: quarkus-quickstart
* TARGET_PORT: 8080
* SERVICE_PORT: 8080

oc process \
-p JDK_VERSION=21 \
-p APP_URI=https://github.com/jboss-container-images/openjdk-test-applications \
-p REF=master \
-p CONTEXT_DIR=quarkus-quickstarts/getting-started-3.9.2-uberjar \
-p APPNAME=quarkus-quickstart \
-p TARGET_PORT=8080 \
-p SERVICE_PORT=8080 \
templates/jlink-app-template \
| oc create -f -

Expand Down
77 changes: 75 additions & 2 deletions templates/jlink/jlinked-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ metadata:
parameters:
- description: JDK version to produce a jmods image and imagestream for
name: JDK_VERSION
value: "11"
value: "21"
required: true
- description: OpenJDK builder image version tag
name: BUILDER_IMAGE_TAG
Expand All @@ -32,6 +32,14 @@ parameters:
generate: expression
from: "[a-zA-Z0-9]{16}"
required: true
- description: Target port for the created Route
name: TARGET_PORT
value: "8080"
required: true
- description: Port for the created Service to listen on
name: SERVICE_PORT
value: "8181"
required: true
message: "... The GitHub webhook secret is ${GITHUB_WEBHOOK_SECRET} ..."
##############################################################################
# Following are the objects(imagestream and buildconfigs) for all the 3-stages
Expand Down Expand Up @@ -96,6 +104,9 @@ objects:
kind: ImageStream
metadata:
name: ${APPNAME}-intermediate
labels:
app: ${APPNAME}
app.kubernetes.io/part-of: ${APPNAME}
spec:
lookupPolicy:
local: false
Expand Down Expand Up @@ -171,7 +182,8 @@ objects:
app.kubernetes.io/part-of: ${APPNAME}
spec:
lookupPolicy:
local: false
# Must be true for the Deployment to resolve the ImageStream
local: true
##############################################################################
# stage-3: BuildConfig
- apiVersion: build.openshift.io/v1
Expand Down Expand Up @@ -233,3 +245,64 @@ objects:
from:
kind: ImageStreamTag
name: ${APPNAME}-ubimicro:latest # ImageStreamTag for registry.access.redhat.com/ubi9/ubi-micro
##############################################################################
# DeploymentConfig and Route object specs
# DeploymentConfigs are discouraged, however the documentation sugggests to still
# use them if features are missing from Deployments, which in our case they are.
- apiVersion: apps/v1
kind: Deployment
metadata:
name: ${APPNAME}-jlinked-app-deployment
labels:
app: ${APPNAME}
app.kubernetes.io/part-of: ${APPNAME}
spec:
replicas: 1
selector:
matchLabels:
app: ${APPNAME}
template:
metadata:
labels:
app: ${APPNAME}
app.kubernetes.io/part-of: ${APPNAME}
annotations:
# Allows Deployments to use ImageStreams
alpha.image.policy.openshift.io/resolve-names: '*'
spec:
containers:
- name: ${APPNAME}-jlinked-app-container
image: ${APPNAME}-lightweight-image:latest
ports:
- containerPort: ${{TARGET_PORT}}
protocol: TCP
strategy:
type: RollingUpdate
- apiVersion: v1
kind: Service
metadata:
name: ${APPNAME}-jlinked-app-service
labels:
app: ${APPNAME}
app.kubernetes.io/part-of: ${APPNAME}
spec:
selector:
app: ${APPNAME}
ports:
- protocol: TCP
name: target-${TARGET_PORT}-tcp
port: ${{SERVICE_PORT}}
targetPort: ${{TARGET_PORT}}
- apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: ${APPNAME}-jlinked-app-route
labels:
app: ${APPNAME}
app.kubernetes.io/part-of: ${APPNAME}
spec:
to:
kind: Service
name: ${APPNAME}-jlinked-app-service
port:
targetPort: ${{TARGET_PORT}}