Skip to content
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

Modules required for jkube-java update #55

Merged
merged 8 commits into from
Jun 21, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/sh

# Check whether a given config is contained in AB_JOLOKIA_OPTS
is_in_jolokia_opts() {
local prop=$1
if [ -n "${AB_JOLOKIA_OPTS}" ] && [ x"${AB_JOLOKIA_OPTS}" != x"${AB_JOLOKIA_OPTS/${prop}/}" ]; then
echo "yes"
else
echo "no"
fi
}

get_jolokia_properties() {

echo "host=${AB_JOLOKIA_HOST:-*}"
echo "port=${AB_JOLOKIA_PORT:-8778}"
echo "discoveryEnabled=${AB_JOLOKIA_DISCOVERY_ENABLED:=false}"

if [ -n "$AB_JOLOKIA_PASSWORD" ]; then
echo "user=${AB_JOLOKIA_USER:-jolokia}"
echo "password=${AB_JOLOKIA_PASSWORD}"
fi
if [ -n "$AB_JOLOKIA_HTTPS" ]; then
echo "protocol=https"
use_https=1
fi

# Integration with OpenShift client cert auth is enabled
# by default if not explicitly turned off by setting to 'false'
if [ "x${AB_JOLOKIA_AUTH_OPENSHIFT}" != "xfalse" ] && [ -f "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" ]; then
echo "useSslClientAuthentication=true"
echo "extraClientCheck=true"

if [ -z ${use_https+x} ]; then
echo "protocol=https"
fi
if [ $(is_in_jolokia_opts "caCert") != "yes" ]; then
echo "caCert=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
fi

if [ $(is_in_jolokia_opts "clientPrincipal") != "yes" ]; then
if [ x"${AB_JOLOKIA_AUTH_OPENSHIFT}" != x"${AB_JOLOKIA_AUTH_OPENSHIFT/=/}" ]; then
# Supposed to contain a principal name to check
echo "clientPrincipal=`echo ${AB_JOLOKIA_AUTH_OPENSHIFT} | sed -e 's/ /\\\\ /g'`"
else
echo "clientPrincipal=cn=system:master-proxy"
fi
fi
fi

# Add extra opts
if [ -n "${AB_JOLOKIA_OPTS}" ]; then
echo "${AB_JOLOKIA_OPTS}" | tr "," "\n"
fi

}

write_jolokia_properties() {
local jolokia_property_file="$1"

# Setup Jolokia to accept basic auth, using a randomly generated password that is stored
# in the container in the ${DEPLOYMENTS_DIR}/jolokia.pw file.
if [ "$AB_JOLOKIA_PASSWORD_RANDOM" == "true" ]; then
pw_file="${JBOSS_CONTAINER_JOLOKIA_MODULE}/etc/jolokia.pw"
if [ -f "${pw_file}" ] ; then
AB_JOLOKIA_PASSWORD=`cat "${pw_file}"`
else
AB_JOLOKIA_PASSWORD=`tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1`
touch "${pw_file}"
chmod 660 "${pw_file}"
cat > "${pw_file}" <<EOF
$AB_JOLOKIA_PASSWORD
EOF
fi
export AB_JOLOKIA_PASSWORD
fi

touch "${jolokia_property_file}"
chmod 660 "${jolokia_property_file}"
cat > "${jolokia_property_file}" <<EOF
$(get_jolokia_properties)
EOF

}

if [ -z "${AB_JOLOKIA_OFF+x}" ]; then
if [ -z "${AB_JOLOKIA_CONFIG}" ]; then
AB_JOLOKIA_CONFIG="${JBOSS_CONTAINER_JOLOKIA_MODULE}/etc/jolokia.properties"
write_jolokia_properties "$AB_JOLOKIA_CONFIG"
fi
echo "-javaagent:/usr/share/java/jolokia-jvm-agent/jolokia-jvm.jar=config=${AB_JOLOKIA_CONFIG}"
fi
23 changes: 23 additions & 0 deletions modules/org.eclipse.jkube.jolokia/2.0.0/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
# Configure module
set -e

SCRIPT_DIR=$(dirname $0)
ARTIFACTS_DIR=${SCRIPT_DIR}/artifacts

# Copy main artifact
mkdir -p /usr/share/java/jolokia-jvm-agent/
cp /tmp/artifacts/jolokia-jvm.jar /usr/share/java/jolokia-jvm-agent/

# Copy module artifacts
chown -R jboss:root $SCRIPT_DIR
chmod -R ug+rwX $SCRIPT_DIR
chmod ug+x ${ARTIFACTS_DIR}/opt/jboss/container/jolokia/*

pushd ${ARTIFACTS_DIR}
cp -pr * /
popd

mkdir -p /opt/jboss/container/jolokia/etc
chmod 775 /opt/jboss/container/jolokia/etc
chown -R jboss:root /opt/jboss/container/jolokia/etc
68 changes: 68 additions & 0 deletions modules/org.eclipse.jkube.jolokia/2.0.0/module.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Ported from https://github.com/jboss-openshift/cct_module/tree/8411125f8e1b45d48c93c8bcd51d39541ce4a755/jboss/container/jolokia/8.2
# Uses Maven Central Artifact instead of RPM package because there's no package (yet) for RHEL 9
schema_version: 1

name: org.eclipse.jkube.jolokia
version: '2.0.0'
description: ^
Provides support for configuring Jolokia. Basic usage is
opts="$JBOSS_CONTAINER_JOLOKIA_MODULE/jolokia-opts"

labels:
- name: io.fabric8.s2i.version.jolokia
value: "2.0.0"

envs:
- name: JOLOKIA_VERSION
description: Version of Jolokia being used.
value: "2.0.0"
- name: AB_JOLOKIA_PASSWORD_RANDOM
description: Determines if a random AB_JOLOKIA_PASSWORD be generated. Set to **true** to generate random password. Generated value will be written to `/opt/jolokia/etc/jolokia.pw`.
value: "true"
- name: AB_JOLOKIA_AUTH_OPENSHIFT
description: Switch on client authentication for OpenShift TLS communication. The value of this parameter can be a relative distinguished name which must be contained in a presented client's certificate. Enabling this parameter will automatically switch Jolokia into https communication mode. The default CA cert is set to `/var/run/secrets/kubernetes.io/serviceaccount/ca.crt`.
value: "true"
- name: AB_JOLOKIA_HTTPS
description: Switch on secure communication with https. By default self signed server certificates are generated if no `serverCert` configuration is given in **AB_JOLOKIA_OPTS**.
value: "true"
- name: AB_JOLOKIA_OFF
description: If set disables activation of Joloka (i.e. echos an empty value). By default, Jolokia is enabled.
example: "true"
- name: AB_JOLOKIA_CONFIG
description: If set uses this file (including path) as Jolokia JVM agent properties (as described in Jolokia's link:https://www.jolokia.org/reference/html/agents.html#agents-jvm[reference manual]). If not set, the `/opt/jolokia/etc/jolokia.properties` will be created using the settings as defined in the manual. Otherwise the rest of the settings in this document are ignored.
example: "/opt/jolokia/custom.properties"
- name: AB_JOLOKIA_HOST
description: Host address to bind to. Defaults to **0.0.0.0**.
example: "127.0.0.1"
- name: AB_JOLOKIA_PORT
description: Port to listen to. Defaults to **8778**.
example: "5432"
- name: AB_JOLOKIA_USER
description: User for basic authentication. Defaults to **jolokia**.
example: "myusername"
- name: AB_JOLOKIA_PASSWORD
description: Password for basic authentication. By default authentication is switched off.
example: "mypassword"
- name: AB_JOLOKIA_ID
description: Agent ID to use (`$HOSTNAME` by default, which is the container id).
example: "openjdk-app-1-xqlsj"
- name: AB_JOLOKIA_DISCOVERY_ENABLED
description: Enable Jolokia discovery. Defaults to **false**.
example: "true"
- name: AB_JOLOKIA_OPTS
description: Additional options to be appended to the agent configuration. They should be given in the format `key=value,key=value,...`.
example: "backlog=20"
- name: JBOSS_CONTAINER_JOLOKIA_MODULE
value: /opt/jboss/container/jolokia

ports:
- value: 8778

artifacts:
- name: jolokia-jvm.jar
target: jolokia-jvm.jar
url: https://repo1.maven.org/maven2/org/jolokia/jolokia-agent-jvm/2.0.0/jolokia-agent-jvm-2.0.0-javaagent.jar
md5: 6f4d49d8f2e389878a2b698ee2ad586b

execute:
- script: configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

# Check for debug options and echo them if enabled. Meant to be included by
# a run script.

debug_options() {
if [ "x${JAVA_ENABLE_DEBUG}" != "x" -o "x${JAVA_DEBUG_ENABLE}" != "x" -o "x${JAVA_DEBUG}" != "x" ]; then
local debug_port="${JAVA_DEBUG_PORT:-5005}"
local suspend_mode="n"
if [ -n "${JAVA_DEBUG_SUSPEND:-}" ]; then
if ! echo "${JAVA_DEBUG_SUSPEND}" | grep -q -e '^\(false\|n\|no\|0\)$'; then
suspend_mode="y"
fi
fi
echo "-agentlib:jdwp=transport=dt_socket,server=y,suspend=${suspend_mode},address=${debug_port}"
fi
}

## Echo options, trimming trailing and multiple spaces
echo "$(debug_options)" | awk '$1=$1'
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/sh
# =================================================================
# Detect whether running in a container and set appropriate options
# for limiting Java VM resources
#
# Usage: JAVA_OPTS="$(java-default-options.sh)"

# stubs for jvm specific overrides
jvm_specific_options() {
:
}

jvm_specific_diagnostics() {
:
}

# Include overridden jvm_specific_*() functions
if [ -f "${JBOSS_CONTAINER_OPENJDK_JDK_MODULE}/jvm-options" ]; then
source "${JBOSS_CONTAINER_OPENJDK_JDK_MODULE}/jvm-options"
fi

# Check for memory options and calculate a sane default if not given
max_memory() {
case "$JAVA_MAX_MEM_RATIO" in
"0") # explicitly disabled
return
;;
"")
maxmem="80.0"
;;
*)
maxmem="$(printf "%.0f.0" "$JAVA_MAX_MEM_RATIO")"
;;
esac
echo "-XX:MaxRAMPercentage=$maxmem"
}

# Switch on diagnostics except when switched off
diagnostics() {
if [ "x$JAVA_DIAGNOSTICS" != "x" ]; then
echo "$(jvm_specific_diagnostics)"
fi
}

gc_config() {
local minHeapFreeRatio=${GC_MIN_HEAP_FREE_RATIO:-10}
local maxHeapFreeRatio=${GC_MAX_HEAP_FREE_RATIO:-20}
local timeRatio=${GC_TIME_RATIO:-4}
local adaptiveSizePolicyWeight=${GC_ADAPTIVE_SIZE_POLICY_WEIGHT:-90}
local gcOptions="${GC_CONTAINER_OPTIONS:--XX:+UseParallelGC}"

# for compat reasons we don't set a default value for metaspaceSize
local metaspaceSize
# We also don't set a default value for maxMetaspaceSize
local maxMetaspaceSize=${GC_MAX_METASPACE_SIZE}

if [ -n "${GC_METASPACE_SIZE}" ]; then
metaspaceSize=${GC_METASPACE_SIZE}
if [ -n "${maxMetaspaceSize}" ]; then
# clamp the max size of metaspaceSize to be <= maxMetaspaceSize
if [ "${metaspaceSize}" -gt "${maxMetaspaceSize}" ]; then
metaspaceSize=${maxMetaspaceSize}
fi
fi
fi

local allOptions="$(jvm_specific_options) "
allOptions+="${gcOptions} "
allOptions+="-XX:MinHeapFreeRatio=${minHeapFreeRatio} "
allOptions+="-XX:MaxHeapFreeRatio=${maxHeapFreeRatio} "
allOptions+="-XX:GCTimeRatio=${timeRatio} "
allOptions+="-XX:AdaptiveSizePolicyWeight=${adaptiveSizePolicyWeight} "
# if no value was specified for maxMetaSpaceSize we should skip passing it entirely
if [ -n "${maxMetaspaceSize}" ]; then
allOptions+="-XX:MaxMetaspaceSize=${maxMetaspaceSize}m "
fi
if [ -n "${metaspaceSize}" ]; then
allOptions+="-XX:MetaspaceSize=${metaspaceSize}m "
fi

echo "${allOptions}"
}

error_handling() {
echo "-XX:+ExitOnOutOfMemoryError"
}

## Echo options, trimming trailing and multiple spaces
echo "$(max_memory) $(gc_config) $(diagnostics) $(error_handling)" | awk '$1=$1'
14 changes: 14 additions & 0 deletions modules/org.eclipse.jkube.jvm/bash/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
# Configure module
set -e

SCRIPT_DIR=$(dirname $0)
ARTIFACTS_DIR=${SCRIPT_DIR}/artifacts

chown -R $USER:root $SCRIPT_DIR
chmod -R ug+rwX $SCRIPT_DIR
chmod ug+x ${ARTIFACTS_DIR}/opt/jboss/container/java/jvm/*

pushd ${ARTIFACTS_DIR}
cp -pr * /
popd
62 changes: 62 additions & 0 deletions modules/org.eclipse.jkube.jvm/bash/module.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
schema_version: 1
name: org.eclipse.jkube.jvm.bash
version: 1.0.0
description: >
Provides support for configuring Java JVM, e.g. GC settings, etc. Basic usage
is opts=$($JBOSS_CONTAINER_JAVA_JVM_MODULE/java-default-options).

Adapted from:
- https://github.com/jboss-container-images/openjdk/blob/d14ec7f363956b73684409c8b6bd9c766507013b/modules/jvm/
- https://github.com/jboss-openshift/cct_module/blob/f91fb2f80dd880ed7498d4dfc3afb35dfcef60bd/jboss/container/java/jvm/bash/

execute:
- script: configure.sh

modules:
install:
- name: org.eclipse.jkube.user
- name: jboss.container.java.proxy.bash

envs:
- name: JBOSS_CONTAINER_JAVA_JVM_MODULE
value: /opt/jboss/container/java/jvm
- name: JAVA_OPTS
description: JVM options passed to the `java` command.
example: "-verbose:class"
- name: JAVA_OPTS_APPEND
description: User specified Java options to be appended to the generated options.
This variable has no effect if `JAVA_OPTS` has been defined.
example: "-Dsome.property=foo"
- name: JAVA_MAX_MEM_RATIO
description: Specify the maximum heap memory. Corresponds to the JVM argument `-XX:MaxRAMPercentage`. The default is `80.0` which means 80% of the available memory. You can disable this mechanism by setting the value to `0`. The supplied value can be an integer or float, but only the whole number part is used.
example: "90.0"
- name: JAVA_DIAGNOSTICS
description: "Set this to get some diagnostics information to standard output when things are happening. **Note: ** This option, if set to true, will set `-XX :+UnlockDiagnosticVMOptions`. **Disabled by default.**"
example: "true"
- name: JAVA_DEBUG
description: If set remote debugging will be switched on. **Disabled by default.**
example: "true"
- name: JAVA_DEBUG_PORT
description: Port used for remote debugging. Defaults to *5005*.
example: "8787"
- name: GC_MIN_HEAP_FREE_RATIO
description: Minimum percentage of heap free after GC to avoid expansion.
example: "20"
- name: GC_MAX_HEAP_FREE_RATIO
description: Maximum percentage of heap free after GC to avoid shrinking.
example: "40"
- name: GC_TIME_RATIO
description: Specifies the ratio of the time spent outside the garbage collection (for example, the time spent for application execution) to the time spent in the garbage collection.
example: "4"
- name: GC_ADAPTIVE_SIZE_POLICY_WEIGHT
description: The weighting given to the current GC time versus previous GC times.
example: "90"
- name: GC_METASPACE_SIZE
description: The initial metaspace size.
example: "20"
- name: GC_MAX_METASPACE_SIZE
description: The maximum metaspace size.
example: "100"
- name: GC_CONTAINER_OPTIONS
description: specify Java GC to use. The value of this variable should contain the necessary JRE command-line options to specify the required GC, which will override the default of `-:+UseParallelGC`.
example: -XX:+UseG1GC
12 changes: 12 additions & 0 deletions modules/org.eclipse.jkube.maven/8.2.3.8/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
set -e

# This file is shipped by a Maven package and sets JAVA_HOME to
# an OpenJDK-specific path. This causes problems for OpenJ9 containers
# as the path is not correct for them. We don't need this in any of
# the containers because ww set JAVA_HOME in the container metadata.
# Blank the file rather than removing it, to avoid a warning message
# from /usr/bin/mvn.
if [ -f /etc/java/maven.conf ]; then
:> /etc/java/maven.conf
fi
Loading
Loading