Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f62dd4f

Browse files
committedMay 22, 2023
HBASE-27831 Introduce zookeeper-single-instance component
1 parent 834889d commit f62dd4f

File tree

17 files changed

+1007
-0
lines changed

17 files changed

+1007
-0
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ linklint/
2626
*kubectl*
2727
*checksums.txt
2828
*.tar.gz
29+
*kubeconfig*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<!--
6+
/**
7+
* Licensed to the Apache Software Foundation (ASF) under one
8+
* or more contributor license agreements. See the NOTICE file
9+
* distributed with this work for additional information
10+
* regarding copyright ownership. The ASF licenses this file
11+
* to you under the Apache License, Version 2.0 (the
12+
* "License"); you may not use this file except in compliance
13+
* with the License. You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing, software
18+
* distributed under the License is distributed on an "AS IS" BASIS,
19+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
* See the License for the specific language governing permissions and
21+
* limitations under the License.
22+
*/
23+
-->
24+
<modelVersion>4.0.0</modelVersion>
25+
<parent>
26+
<artifactId>hbase-kubernetes-deployment</artifactId>
27+
<groupId>org.apache.hbase.operator.tools</groupId>
28+
<version>${revision}</version>
29+
<relativePath>..</relativePath>
30+
</parent>
31+
32+
<artifactId>hbase-kubernetes-kustomize</artifactId>
33+
<name>Apache HBase - Kubernetes Kustomize</name>
34+
<description>Kustomize deployment descriptors.</description>
35+
<packaging>pom</packaging>
36+
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.apache.hbase.operator.tools</groupId>
40+
<artifactId>hbase-kubernetes-testing-image</artifactId>
41+
<type>pom</type>
42+
<scope>test</scope>
43+
</dependency>
44+
</dependencies>
45+
46+
<build>
47+
<plugins>
48+
<plugin>
49+
<groupId>org.codehaus.mojo</groupId>
50+
<artifactId>exec-maven-plugin</artifactId>
51+
<configuration>
52+
<executable>src/test/resources/mvn_exec_run_kuttl.sh</executable>
53+
<useMavenLogger>true</useMavenLogger>
54+
<skip>${skipTests}</skip>
55+
</configuration>
56+
<executions>
57+
<execution>
58+
<id>kuttl-unit-tests</id>
59+
<phase>test</phase>
60+
<goals>
61+
<goal>exec</goal>
62+
</goals>
63+
<configuration>
64+
<arguments>
65+
<argument>--config</argument>
66+
<argument>src/test/resources/kuttl-test-unit.yaml</argument>
67+
<argument>--artifacts-dir</argument>
68+
<argument>target/kuttl-reports</argument>
69+
</arguments>
70+
</configuration>
71+
</execution>
72+
<execution>
73+
<id>kuttl-integration-tests</id>
74+
<phase>verify</phase>
75+
<goals>
76+
<goal>exec</goal>
77+
</goals>
78+
<configuration>
79+
<arguments>
80+
<argument>--config</argument>
81+
<argument>src/test/resources/kuttl-test-integration.yaml</argument>
82+
<argument>--artifacts-dir</argument>
83+
<argument>target/kuttl-reports</argument>
84+
</arguments>
85+
</configuration>
86+
</execution>
87+
</executions>
88+
</plugin>
89+
</plugins>
90+
</build>
91+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
Uses latest image from the apache zookeeper project.
20+
There is then a start script in 'single-instance/start.sh'
21+
which sets parameters for the zookeeper image and process
22+
on startup. Currently only logs to STDOUT/STDERR; there
23+
are no files in /var/log/zookeeper.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
---
17+
apiVersion: kustomize.config.k8s.io/v1alpha1
18+
kind: Component
19+
20+
configMapGenerator:
21+
- name: zookeeper-scripts
22+
files:
23+
- start.sh
24+
# Publish where the zk ensemble can be found.
25+
- name: zookeeper-quorum
26+
literals:
27+
# Hard-coded. Default we expect a simple standalone zk at this location.
28+
# One define is for hbase, the other for hadoop.
29+
- HBASE_ZOOKEEPER_QUORUM="zookeeper-0.zookeeper-headless"
30+
- HA_ZOOKEEPER_QUORUM="zookeeper-0.zookeeper-headless:2181"
31+
options:
32+
disableNameSuffixHash: true
33+
34+
resources:
35+
- zookeeper.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,358 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# Derived from work Copyright 2017 The Kubernetes Authors.
20+
# See https://github.com/kow3ns/kubernetes-zookeeper/blob/master/docker/scripts/start-zookeeper for more details
21+
# and then https://github.com/cloudurable/kube-zookeeper-statefulsets/
22+
# In the below we change the '--heap' argument to '--percentage' so
23+
# could set the server heap as a percentage of the container resource
24+
# limit rather than hard-code it.
25+
# Currently zookeeper.root.logger is CONSOLE only. We do not write
26+
# logs to files. Fix config. if you need it.
27+
#
28+
#
29+
# Usage: start-zookeeper [OPTIONS]
30+
# Starts a ZooKeeper server based on the supplied options.
31+
# --servers The number of servers in the ensemble. The default
32+
# value is 1.
33+
# --data_dir The directory where the ZooKeeper process will store its
34+
# snapshots. The default is /var/lib/zookeeper/data.
35+
# --data_log_dir The directory where the ZooKeeper process will store its
36+
# write ahead log. The default is
37+
# /var/lib/zookeeper/data/log.
38+
# --conf_dir The directory where the ZooKeeper process will store its
39+
# configuration. The default is /opt/zookeeper/conf.
40+
# --client_port The port on which the ZooKeeper process will listen for
41+
# client requests. The default is 2181.
42+
43+
# --election_port The port on which the ZooKeeper process will perform
44+
# leader election. The default is 3888.
45+
46+
# --server_port The port on which the ZooKeeper process will listen for
47+
# requests from other servers in the ensemble. The
48+
# default is 2888.
49+
50+
# --tick_time The length of a ZooKeeper tick in ms. The default is
51+
# 2000.
52+
53+
# --init_limit The number of Ticks that an ensemble member is allowed
54+
# to perform leader election. The default is 10.
55+
56+
# --sync_limit The maximum session timeout that the ensemble will
57+
# allows a client to request. The default is 5.
58+
59+
# --percentage The percentage of container memory to give to the JVM.
60+
61+
# --max_client_cnxns The maximum number of client connections that the
62+
# ZooKeeper process will accept simultaneously. The
63+
# default is 60.
64+
65+
# --snap_retain_count The maximum number of snapshots the ZooKeeper process
66+
# will retain if purge_interval is greater than 0. The
67+
# default is 3.
68+
69+
# --purge_interval The number of hours the ZooKeeper process will wait
70+
# between purging its old snapshots. If set to 0 old
71+
# snapshots will never be purged. The default is 0.
72+
73+
# --max_session_timeout The maximum time in milliseconds for a client session
74+
# timeout. The default value is 2 * tick time.
75+
76+
# --min_session_timeout The minimum time in milliseconds for a client session
77+
# timeout. The default value is 20 * tick time.
78+
79+
# --log_level The log level for the zookeeeper server. Either FATAL,
80+
# ERROR, WARN, INFO, DEBUG. The default is INFO.
81+
82+
# --quorum_listen_on_all_ips
83+
# When set to true the ZooKeeper server will listen for
84+
# connections from its peers on all available IP addresses,
85+
# and not only the address configured in the server list of
86+
# the configuration file. It affects the connections handling
87+
# the ZAB protocol and the Fast Leader Election protocol.
88+
# Default value is false.
89+
set -x
90+
91+
ZOOKEEPER_HOME="$( ls -d /apache-zookeeper* )"
92+
USER="$(whoami)"
93+
HOST="$(hostname -s)"
94+
DOMAIN="$(hostname -d)"
95+
LOG_LEVEL=INFO
96+
DATA_DIR="/var/lib/zookeeper/data"
97+
DATA_LOG_DIR="/var/lib/zookeeper/log"
98+
LOG_DIR="/var/log/zookeeper"
99+
CONF_DIR="/opt/zookeeper/conf"
100+
CLIENT_PORT=2181
101+
SERVER_PORT=2888
102+
ELECTION_PORT=3888
103+
PROM_PORT=7001
104+
TICK_TIME=2000
105+
INIT_LIMIT=10
106+
SYNC_LIMIT=5
107+
JVM_HEAP_PERCENTAGE_OF_RESOURCE_LIMIT=50
108+
MAX_CLIENT_CNXNS=1000
109+
SNAP_RETAIN_COUNT=3
110+
PURGE_INTERVAL=0
111+
SERVERS=1
112+
QUORUM_LISTEN_ON_ALL_IPS=false
113+
114+
function print_usage() {
115+
echo "\
116+
Usage: start-zookeeper [OPTIONS]
117+
Starts a ZooKeeper server based on the supplied options.
118+
--servers The number of servers in the ensemble. The default
119+
value is 1.
120+
121+
--data_dir The directory where the ZooKeeper process will store its
122+
snapshots. The default is /var/lib/zookeeper/data.
123+
124+
--data_log_dir The directory where the ZooKeeper process will store its
125+
write ahead log. The default is
126+
/var/lib/zookeeper/data/log.
127+
128+
--conf_dir The directoyr where the ZooKeeper process will store its
129+
configuration. The default is /opt/zookeeper/conf.
130+
131+
--client_port The port on which the ZooKeeper process will listen for
132+
client requests. The default is 2181.
133+
134+
--election_port The port on which the ZooKeeper process will perform
135+
leader election. The default is 3888.
136+
137+
--server_port The port on which the ZooKeeper process will listen for
138+
requests from other servers in the ensemble. The
139+
default is 2888.
140+
141+
--tick_time The length of a ZooKeeper tick in ms. The default is
142+
2000.
143+
144+
--init_limit The number of Ticks that an ensemble member is allowed
145+
to perform leader election. The default is 10.
146+
147+
--sync_limit The maximum session timeout that the ensemble will
148+
allows a client to request. The default is 5.
149+
150+
--percentage The percentage of container memory to give to the JVM.
151+
152+
--max_client_cnxns The maximum number of client connections that the
153+
ZooKeeper process will accept simultaneously. The
154+
default is 60.
155+
156+
--snap_retain_count The maximum number of snapshots the ZooKeeper process
157+
will retain if purge_interval is greater than 0. The
158+
default is 3.
159+
160+
--purge_interval The number of hours the ZooKeeper process will wait
161+
between purging its old snapshots. If set to 0 old
162+
snapshots will never be purged. The default is 0.
163+
164+
--max_session_timeout The maximum time in milliseconds for a client session
165+
timeout. The default value is 2 * tick time.
166+
167+
--min_session_timeout The minimum time in milliseconds for a client session
168+
timeout. The default value is 20 * tick time.
169+
170+
--log_level The log level for the zookeeeper server. Either FATAL,
171+
ERROR, WARN, INFO, DEBUG. The default is INFO.
172+
"
173+
}
174+
175+
function create_data_dirs() {
176+
if [ ! -d "$DATA_DIR" ]; then
177+
mkdir -p "$DATA_DIR"
178+
chown -R "$USER":"$USER" "$DATA_DIR"
179+
fi
180+
181+
if [ ! -d "$DATA_LOG_DIR" ]; then
182+
mkdir -p "$DATA_LOG_DIR"
183+
chown -R "$USER":"$USER" "$DATA_LOG_DIR"
184+
fi
185+
186+
if [ ! -d "$LOG_DIR" ]; then
187+
mkdir -p "$LOG_DIR"
188+
chown -R "$USER":"$USER" "$LOG_DIR"
189+
fi
190+
if [ ! -f "$ID_FILE" ] && [ "$SERVERS" -gt 1 ]; then
191+
echo "$MY_ID" >> "$ID_FILE"
192+
fi
193+
}
194+
195+
function print_servers() {
196+
for (( i=1; i<=SERVERS; i++ ))
197+
do
198+
echo "server.$i=$NAME-$((i-1)).$DOMAIN:$SERVER_PORT:$ELECTION_PORT"
199+
done
200+
}
201+
202+
function create_config() {
203+
rm -f "$CONFIG_FILE"
204+
{
205+
echo "#This file was autogenerated DO NOT EDIT"
206+
echo "clientPort=$CLIENT_PORT"
207+
echo "dataDir=$DATA_DIR"
208+
echo "dataLogDir=$DATA_LOG_DIR"
209+
echo "tickTime=$TICK_TIME"
210+
echo "initLimit=$INIT_LIMIT"
211+
echo "syncLimit=$SYNC_LIMIT"
212+
echo "maxClientCnxns=$MAX_CLIENT_CNXNS"
213+
echo "minSessionTimeout=$MIN_SESSION_TIMEOUT"
214+
echo "maxSessionTimeout=$MAX_SESSION_TIMEOUT"
215+
echo "autopurge.snapRetainCount=$SNAP_RETAIN_COUNT"
216+
echo "autopurge.purgeInteval=$PURGE_INTERVAL"
217+
echo "quorumListenOnAllIPs=$QUORUM_LISTEN_ON_ALL_IPS"
218+
# Allow running all zk commands.
219+
echo "4lw.commands.whitelist=*"
220+
if [ "$SERVERS" -gt 1 ]; then
221+
print_servers
222+
fi
223+
echo "metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider"
224+
echo "metricsProvider.httpPort=$PROM_PORT"
225+
} >> "$CONFIG_FILE"
226+
cat "$CONFIG_FILE" >&2
227+
}
228+
229+
function create_jvm_props() {
230+
rm -f "$JAVA_ENV_FILE"
231+
{
232+
echo "SERVER_JVMFLAGS=\"-XX:MaxRAMPercentage=${JVM_HEAP_PERCENTAGE_OF_RESOURCE_LIMIT} \
233+
-XX:InitialRAMPercentage=${JVM_HEAP_PERCENTAGE_OF_RESOURCE_LIMIT}\""
234+
echo "ZOO_LOG_DIR=$LOG_DIR"
235+
echo "JVMFLAGS="
236+
} >> "$JAVA_ENV_FILE"
237+
}
238+
239+
function create_log_props() {
240+
rm -f "$LOGGER_PROPS_FILE"
241+
echo "Creating ZooKeeper log4j configuration"
242+
{
243+
echo "zookeeper.root.logger=CONSOLE"
244+
echo "zookeeper.console.threshold=$LOG_LEVEL"
245+
echo "log4j.rootLogger=\${zookeeper.root.logger}"
246+
echo "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender"
247+
echo "log4j.appender.CONSOLE.Threshold=\${zookeeper.console.threshold}"
248+
echo "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout"
249+
echo "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n"
250+
} >> "$LOGGER_PROPS_FILE"
251+
}
252+
253+
optspec=":hv-:"
254+
while getopts "$optspec" optchar; do
255+
256+
case "${optchar}" in
257+
-)
258+
case "${OPTARG}" in
259+
servers=*)
260+
SERVERS=${OPTARG##*=}
261+
;;
262+
data_dir=*)
263+
DATA_DIR=${OPTARG##*=}
264+
;;
265+
data_log_dir=*)
266+
DATA_LOG_DIR=${OPTARG##*=}
267+
;;
268+
log_dir=*)
269+
LOG_DIR=${OPTARG##*=}
270+
;;
271+
conf_dir=*)
272+
CONF_DIR=${OPTARG##*=}
273+
;;
274+
client_port=*)
275+
CLIENT_PORT=${OPTARG##*=}
276+
;;
277+
election_port=*)
278+
ELECTION_PORT=${OPTARG##*=}
279+
;;
280+
server_port=*)
281+
SERVER_PORT=${OPTARG##*=}
282+
;;
283+
tick_time=*)
284+
TICK_TIME=${OPTARG##*=}
285+
;;
286+
init_limit=*)
287+
INIT_LIMIT=${OPTARG##*=}
288+
;;
289+
sync_limit=*)
290+
SYNC_LIMIT=${OPTARG##*=}
291+
;;
292+
percentage=*)
293+
JVM_HEAP_PERCENTAGE_OF_RESOURCE_LIMIT=${OPTARG##*=}
294+
;;
295+
max_client_cnxns=*)
296+
MAX_CLIENT_CNXNS=${OPTARG##*=}
297+
;;
298+
snap_retain_count=*)
299+
SNAP_RETAIN_COUNT=${OPTARG##*=}
300+
;;
301+
purge_interval=*)
302+
PURGE_INTERVAL=${OPTARG##*=}
303+
;;
304+
max_session_timeout=*)
305+
MAX_SESSION_TIMEOUT=${OPTARG##*=}
306+
;;
307+
min_session_timeout=*)
308+
MIN_SESSION_TIMEOUT=${OPTARG##*=}
309+
;;
310+
quorum_listen_on_all_ips=*)
311+
QUORUM_LISTEN_ON_ALL_IPS=${OPTARG##*=}
312+
;;
313+
log_level=*)
314+
LOG_LEVEL=${OPTARG##*=}
315+
;;
316+
*)
317+
echo "Unknown option --${OPTARG}" >&2
318+
exit 1
319+
;;
320+
esac;;
321+
h)
322+
print_usage
323+
exit
324+
;;
325+
v)
326+
echo "Parsing option: '-${optchar}'" >&2
327+
;;
328+
*)
329+
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
330+
echo "Non-option argument: '-${OPTARG}'" >&2
331+
fi
332+
;;
333+
esac
334+
done
335+
336+
MIN_SESSION_TIMEOUT=${MIN_SESSION_TIMEOUT:- $((TICK_TIME*2))}
337+
MAX_SESSION_TIMEOUT=${MAX_SESSION_TIMEOUT:- $((TICK_TIME*20))}
338+
ID_FILE="$DATA_DIR/myid"
339+
if [ ! -d "$CONF_DIR" ]; then
340+
mkdir -p "$CONF_DIR"
341+
chown -R "$USER":"$USER" "$CONF_DIR"
342+
fi
343+
CONFIG_FILE="$CONF_DIR/zoo.cfg"
344+
LOGGER_PROPS_FILE="$CONF_DIR/log4j.properties"
345+
JAVA_ENV_FILE="$CONF_DIR/java.env"
346+
347+
if [[ $HOST =~ (.*)-([0-9]+)$ ]]; then
348+
NAME=${BASH_REMATCH[1]}
349+
ORD=${BASH_REMATCH[2]}
350+
else
351+
echo "Failed to parse name and ordinal of Pod"
352+
exit 1
353+
fi
354+
355+
MY_ID=$((ORD+1))
356+
357+
export ZOOCFGDIR=${CONF_DIR}
358+
create_config && create_jvm_props && create_log_props && create_data_dirs && exec "${ZOOKEEPER_HOME}/bin/zkServer.sh" start-foreground
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
---
17+
apiVersion: apps/v1
18+
kind: StatefulSet
19+
metadata:
20+
name: zookeeper
21+
spec:
22+
replicas: 1
23+
serviceName: zookeeper-headless
24+
selector:
25+
matchLabels:
26+
cluster: zookeeper # has to match .spec.template.metadata.labels
27+
role: zookeeper
28+
updateStrategy:
29+
type: RollingUpdate
30+
podManagementPolicy: Parallel
31+
template:
32+
metadata:
33+
labels:
34+
cluster: zookeeper
35+
role: zookeeper
36+
spec:
37+
containers:
38+
- image: zookeeper
39+
name: zookeeper
40+
imagePullPolicy: IfNotPresent
41+
resources:
42+
requests:
43+
cpu: '0.1'
44+
memory: 768Mi
45+
limits:
46+
cpu: '1.0'
47+
memory: 1Gi
48+
env:
49+
- name: JAVA_HOME
50+
value: /usr/local/openjdk-11
51+
- name: LANG
52+
value: C.UTF-8
53+
- name: PATH
54+
value: /usr/local/openjdk-11/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
55+
- name: ZK_LOG_DIR
56+
value: /var/log/zookeeper
57+
ports:
58+
- containerPort: 2181
59+
name: client
60+
- containerPort: 2888
61+
name: server
62+
- containerPort: 3888
63+
name: leader-election
64+
- containerPort: 7001
65+
name: metrics
66+
command:
67+
- sh
68+
- -c
69+
- |-
70+
export LOG_DIR="${ZK_LOG_DIR}"
71+
/usr/bin/zookeeper/start.sh --servers=1 --percentage=50
72+
readinessProbe:
73+
exec:
74+
command:
75+
- /bin/bash
76+
- -c
77+
- |-
78+
[ "$(echo ruok | nc 127.0.0.1 2181)" == "imok" ]
79+
initialDelaySeconds: 10
80+
timeoutSeconds: 5
81+
livenessProbe:
82+
exec:
83+
command:
84+
- /bin/bash
85+
- -c
86+
- |-
87+
[ "$(echo ruok | nc 127.0.0.1 2181)" == "imok" ]
88+
initialDelaySeconds: 10
89+
timeoutSeconds: 5
90+
volumeMounts:
91+
- name: datadir
92+
mountPath: /var/lib/zookeeper
93+
- mountPath: /usr/bin/zookeeper
94+
name: zookeeper-scripts
95+
- mountPath: /var/log/zookeeper
96+
name: zk-logs
97+
volumes:
98+
- emptyDir: {}
99+
name: zk-logs
100+
- configMap:
101+
name: zookeeper-scripts
102+
defaultMode: 0555
103+
name: zookeeper-scripts
104+
volumeClaimTemplates:
105+
- metadata:
106+
name: datadir
107+
spec:
108+
accessModes: [ "ReadWriteOnce" ]
109+
resources:
110+
requests:
111+
storage: 2Gi
112+
---
113+
apiVersion: policy/v1
114+
kind: PodDisruptionBudget
115+
metadata:
116+
name: zookeeper-pdb
117+
spec:
118+
selector:
119+
matchLabels:
120+
cluster: zookeeper
121+
maxUnavailable: 1
122+
---
123+
apiVersion: v1
124+
kind: Service
125+
metadata:
126+
name: zookeeper-headless
127+
spec:
128+
ports:
129+
- port: 2888
130+
name: server
131+
- port: 3888
132+
name: leader-election
133+
- port: 2181
134+
name: client
135+
- port: 8080
136+
name: http
137+
clusterIP: None
138+
publishNotReadyAddresses: true
139+
# Select our zookeeper app. This is what gets us dns entries
140+
# https://kubernetes.io/docs/concepts/services-networking/service/#with-selectors
141+
selector:
142+
cluster: zookeeper
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# Asserts on the ZooKeeper portion of the deployment.
18+
#
19+
---
20+
# assert that there is a `StatefulSet` named "zookeeper" that has one live instance.
21+
apiVersion: apps/v1
22+
kind: StatefulSet
23+
metadata:
24+
name: zookeeper
25+
status:
26+
availableReplicas: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
---
17+
apiVersion: kuttl.dev/v1beta1
18+
kind: TestStep
19+
20+
commands:
21+
- script: ../../../resources/kustomize_into_tmpdir.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
---
17+
apiVersion: kustomize.config.k8s.io/v1beta1
18+
kind: Kustomization
19+
20+
images:
21+
- name: zookeeper
22+
newName: zookeeper
23+
newTag: 3.8.0
24+
25+
components:
26+
- ../../../../main/kustomize/components/zookeeper/single-instance
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# Asserts on the ZooKeeper portion of the deployment.
18+
#
19+
---
20+
# assert that there is a `ConfigMap` named "zookeeper-scripts-XXX"
21+
# TODO: kuttl does not support generated names
22+
#apiVersion: v1
23+
#kind: ConfigMap
24+
#metadata:
25+
# name: zookeeper-scripts-c94h8k249d
26+
---
27+
# assert that there is a `ConfigMap` named "zookeeper-quorum"
28+
apiVersion: v1
29+
kind: ConfigMap
30+
metadata:
31+
name: zookeeper-quorum
32+
---
33+
# assert that there is a `PodDisruptionBudget` named "zookeeper-pdb"
34+
apiVersion: policy/v1
35+
kind: PodDisruptionBudget
36+
metadata:
37+
name: zookeeper-pdb
38+
---
39+
# assert that there is a `StatefulSet` named "zookeeper" that:
40+
# - provides pods labeled role:zookeeper
41+
apiVersion: apps/v1
42+
kind: StatefulSet
43+
metadata:
44+
name: zookeeper
45+
spec:
46+
template:
47+
metadata:
48+
labels:
49+
role: zookeeper
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
---
17+
apiVersion: kuttl.dev/v1beta1
18+
kind: TestStep
19+
20+
commands:
21+
- script: ../../../resources/kustomize_into_tmpdir.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
---
17+
apiVersion: kustomize.config.k8s.io/v1beta1
18+
kind: Kustomization
19+
20+
components:
21+
- ../../../../main/kustomize/components/zookeeper/single-instance
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# Test runner using KUTTL against a target cluster.
20+
# https://kuttl.dev
21+
# https://kind.sigs.k8s.io
22+
#
23+
# Materialize a kustomize directory for a kuttl test.
24+
#
25+
# Kustomize is clunky for automated testing. It's pretty opinionated in that it will only evaluate
26+
# a directory off of disk -- you cannot generate a kustomization and pass it in via stdin.
27+
# In order to use kuttl generated namespaces within the kustomization, we have to modify the
28+
# kustomization.yaml before applying it. If we modify that file in the source tree, we end up with
29+
# the test namespace appended to the file under source control. So, this script creates a temp
30+
# directory, copies all the resources into that directory, and modifies the kustomization.yaml as
31+
# necessary. It then runs `kubectl apply -k` against that temporary directory.
32+
#
33+
34+
declare DEBUG="${DEBUG:false}"
35+
if [ "${DEBUG}" = 'true' ] ; then
36+
set -x
37+
fi
38+
39+
set -eou pipefail
40+
41+
declare NAMESPACE
42+
declare NEW_RESOURCES='[]'
43+
declare NEW_COMPONENTS='[]'
44+
declare kustomize_dir
45+
declare -a rewritten_resources=()
46+
declare -a rewritten_components=()
47+
48+
kustomize_dir="$(mktemp -d -p /tmp "${NAMESPACE}.XXXXXXXXXX")"
49+
trap '[ -d "${kustomize_dir}" ] && rm -rf "${kustomize_dir}"' EXIT
50+
51+
cp -r ./* "${kustomize_dir}/"
52+
53+
for r in $(yq '.resources[]' kustomization.yaml) ; do
54+
if [[ "${r}" =~ ^\.\./.* ]] ; then
55+
# resolve the new relative location for any resource path that is not in the local directory
56+
canonized="$(cd "${r}" ; pwd)"
57+
r="../..${canonized}"
58+
fi
59+
rewritten_resources+=("'${r}'")
60+
done
61+
if [ "${#rewritten_resources[@]}" -gt 0 ] ; then
62+
NEW_RESOURCES="[ $(printf '%s,' "${rewritten_resources[@]}") ]"
63+
fi
64+
65+
for r in $(yq '.components[]' kustomization.yaml) ; do
66+
if [[ "${r}" =~ ^\.\./.* ]] ; then
67+
# resolve the new relative location for any resource path that is not in the local directory
68+
canonized="$(cd "${r}" ; pwd)"
69+
r="../..${canonized}"
70+
fi
71+
rewritten_components+=("'${r}'")
72+
done
73+
if [ "${#rewritten_components[@]}" -gt 0 ] ; then
74+
NEW_COMPONENTS="[ $(printf '%s,' "${rewritten_components[@]}") ]"
75+
fi
76+
77+
env NAMESPACE="${NAMESPACE}" \
78+
NEW_RESOURCES="${NEW_RESOURCES}" \
79+
NEW_COMPONENTS="${NEW_COMPONENTS}" \
80+
yq -i '
81+
.namespace = strenv(NAMESPACE) |
82+
.resources = env(NEW_RESOURCES) |
83+
.components = env(NEW_COMPONENTS)
84+
' "${kustomize_dir}/kustomization.yaml"
85+
86+
if [ "${DEBUG}" = 'true' ] ; then
87+
cat "${kustomize_dir}/kustomization.yaml"
88+
fi
89+
90+
kubectl apply -k "${kustomize_dir}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# Test runner using KUTTL against a target cluster.
18+
# https://kuttl.dev
19+
# https://kind.sigs.k8s.io
20+
#
21+
# Test runner using KUTTL against a target cluster.
22+
# https://kuttl.dev
23+
# https://kind.sigs.k8s.io
24+
---
25+
# Does not use Kuttl's built-in KIND support -- it doesn't quite work correctly with a VM-based
26+
# (Docker Desktop) style of runtime. Instead, assumes the cluster is established outside of kuttl
27+
# and configuration is provided via `--env`.
28+
apiVersion: kuttl.dev/v1beta1
29+
kind: TestSuite
30+
testDirs:
31+
- ./src/test/kustomize/integration
32+
timeout:
33+
# these tests allocate several pods with dependencies between them, allow some time for
34+
# everything to launch and settle.
35+
300
36+
reportName: TEST-kuttl-report-integration
37+
reportFormat: xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# Test runner using KUTTL against a target cluster.
18+
# https://kuttl.dev
19+
# https://kind.sigs.k8s.io
20+
# Test runner using https://kuttl.dev
21+
---
22+
apiVersion: kuttl.dev/v1beta1
23+
kind: TestSuite
24+
startControlPlane: true
25+
testDirs:
26+
- ./src/test/kustomize/unit
27+
reportName: TEST-kuttl-report-unit
28+
reportFormat: xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# Wrap up the complexities of launching `kubectl kuttl test` via docker container.
19+
20+
set -euox pipefail
21+
22+
declare default_run_args
23+
default_run_args="--rm --mount type=bind,source=$(pwd),target=/workspace --workdir /workspace"
24+
25+
# from the calling environment
26+
declare DOCKER_EXE="${DOCKER_EXE:-"$(command -v docker 2>/dev/null)"}"
27+
declare DOCKER_CONTAINER_RUN_ADDITIONAL_ARGS="${DOCKER_CONTAINER_RUN_ADDITIONAL_ARGS:-"${default_run_args}"}"
28+
declare USER="${USER:-apache}"
29+
declare KUTTL_IMAGE="${KUTTL_IMAGE:-"${USER}/hbase/operator-tools/kuttl:latest"}"
30+
31+
declare run_args
32+
read -r -a run_args <<< "$DOCKER_CONTAINER_RUN_ADDITIONAL_ARGS"
33+
34+
exec "${DOCKER_EXE}" container run \
35+
"${run_args[@]}" \
36+
"${KUTTL_IMAGE}" \
37+
"$@"

‎hbase-kubernetes-deployment/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
<modules>
3838
<module>hbase-kubernetes-testing-image</module>
39+
<module>hbase-kubernetes-kustomize</module>
3940
</modules>
4041

4142
<dependencies />

0 commit comments

Comments
 (0)
Please sign in to comment.