Skip to content

Commit 06a2d7f

Browse files
authored
Merge pull request #514 from Josh-Matsuoka/jaya-cleanup
[OPENJDK-2992] Create DeploymentConfig and Route for jlink apps
2 parents 8e77d86 + b474239 commit 06a2d7f

File tree

2 files changed

+93
-10
lines changed

2 files changed

+93
-10
lines changed

templates/jlink/README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ you need:
77
2. UBI9 OpenJDK ImageStreams that include `jlink-dev` changes (see below)
88
3. The template [jlinked-app.yaml](jlinked-app.yaml).
99

10+
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.
11+
1012
## Stage 0: UBI9 OpenJDK ImageStreams with jlink-dev changes
1113

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

19-
cekit --descriptor ubi9-openjdk-21.yaml build docker
21+
cekit --descriptor ubi9-openjdk-21.yaml build podman
22+
23+
2. Create an OpenShift project
24+
25+
oc new-project $PROJECT
2026

21-
2. Within your OpenShift project,
27+
3. Within your OpenShift project,
2228

23-
oc create imagestream openjdk-${JDK_VERSION}-jlink-tech-preview
29+
oc create imagestream openjdk-21-jlink-tech-preview
2430

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

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

33-
4. Log into the OpenShift registry, e.g.
39+
5. Log into the OpenShift registry, e.g.
3440

3541
REGISTRY_AUTH_PREFERENCE=docker oc registry login
3642

37-
5. tag and push the dev image into it. The OpenShift console gives you the
43+
6. tag and push the dev image into it. The OpenShift console gives you the
3844
exact URI for your instance
3945

40-
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
41-
docker push default-route-openshift-image-registry.apps-crc.testing/jlink1/openjdk-21-jlink-tech-preview:latest
46+
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
47+
podman push default-route-openshift-image-registry.apps-crc.testing/$PROJECT/openjdk-21-jlink-tech-preview:latest
4248

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

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

6169
oc process \
6270
-p JDK_VERSION=21 \
6371
-p APP_URI=https://github.com/jboss-container-images/openjdk-test-applications \
6472
-p REF=master \
6573
-p CONTEXT_DIR=quarkus-quickstarts/getting-started-3.9.2-uberjar \
6674
-p APPNAME=quarkus-quickstart \
75+
-p TARGET_PORT=8080 \
76+
-p SERVICE_PORT=8080 \
6777
templates/jlink-app-template \
6878
| oc create -f -
6979

templates/jlink/jlinked-app.yaml

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ metadata:
1010
parameters:
1111
- description: JDK version to produce a jmods image and imagestream for
1212
name: JDK_VERSION
13-
value: "11"
13+
value: "21"
1414
required: true
1515
- description: OpenJDK builder image version tag
1616
name: BUILDER_IMAGE_TAG
@@ -32,6 +32,14 @@ parameters:
3232
generate: expression
3333
from: "[a-zA-Z0-9]{16}"
3434
required: true
35+
- description: Target port for the created Route
36+
name: TARGET_PORT
37+
value: "8080"
38+
required: true
39+
- description: Port for the created Service to listen on
40+
name: SERVICE_PORT
41+
value: "8181"
42+
required: true
3543
message: "... The GitHub webhook secret is ${GITHUB_WEBHOOK_SECRET} ..."
3644
##############################################################################
3745
# Following are the objects(imagestream and buildconfigs) for all the 3-stages
@@ -96,6 +104,9 @@ objects:
96104
kind: ImageStream
97105
metadata:
98106
name: ${APPNAME}-intermediate
107+
labels:
108+
app: ${APPNAME}
109+
app.kubernetes.io/part-of: ${APPNAME}
99110
spec:
100111
lookupPolicy:
101112
local: false
@@ -171,7 +182,8 @@ objects:
171182
app.kubernetes.io/part-of: ${APPNAME}
172183
spec:
173184
lookupPolicy:
174-
local: false
185+
# Must be true for the Deployment to resolve the ImageStream
186+
local: true
175187
##############################################################################
176188
# stage-3: BuildConfig
177189
- apiVersion: build.openshift.io/v1
@@ -233,3 +245,64 @@ objects:
233245
from:
234246
kind: ImageStreamTag
235247
name: ${APPNAME}-ubimicro:latest # ImageStreamTag for registry.access.redhat.com/ubi9/ubi-micro
248+
##############################################################################
249+
# DeploymentConfig and Route object specs
250+
# DeploymentConfigs are discouraged, however the documentation sugggests to still
251+
# use them if features are missing from Deployments, which in our case they are.
252+
- apiVersion: apps/v1
253+
kind: Deployment
254+
metadata:
255+
name: ${APPNAME}-jlinked-app-deployment
256+
labels:
257+
app: ${APPNAME}
258+
app.kubernetes.io/part-of: ${APPNAME}
259+
spec:
260+
replicas: 1
261+
selector:
262+
matchLabels:
263+
app: ${APPNAME}
264+
template:
265+
metadata:
266+
labels:
267+
app: ${APPNAME}
268+
app.kubernetes.io/part-of: ${APPNAME}
269+
annotations:
270+
# Allows Deployments to use ImageStreams
271+
alpha.image.policy.openshift.io/resolve-names: '*'
272+
spec:
273+
containers:
274+
- name: ${APPNAME}-jlinked-app-container
275+
image: ${APPNAME}-lightweight-image:latest
276+
ports:
277+
- containerPort: ${{TARGET_PORT}}
278+
protocol: TCP
279+
strategy:
280+
type: RollingUpdate
281+
- apiVersion: v1
282+
kind: Service
283+
metadata:
284+
name: ${APPNAME}-jlinked-app-service
285+
labels:
286+
app: ${APPNAME}
287+
app.kubernetes.io/part-of: ${APPNAME}
288+
spec:
289+
selector:
290+
app: ${APPNAME}
291+
ports:
292+
- protocol: TCP
293+
name: target-${TARGET_PORT}-tcp
294+
port: ${{SERVICE_PORT}}
295+
targetPort: ${{TARGET_PORT}}
296+
- apiVersion: route.openshift.io/v1
297+
kind: Route
298+
metadata:
299+
name: ${APPNAME}-jlinked-app-route
300+
labels:
301+
app: ${APPNAME}
302+
app.kubernetes.io/part-of: ${APPNAME}
303+
spec:
304+
to:
305+
kind: Service
306+
name: ${APPNAME}-jlinked-app-service
307+
port:
308+
targetPort: ${{TARGET_PORT}}

0 commit comments

Comments
 (0)