Skip to content

Commit

Permalink
chore: upgrade pulsar addon to v1.0 API and add scripts ut (#1111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Rookie authored Oct 23, 2024
1 parent 9245acc commit 4fdc89b
Show file tree
Hide file tree
Showing 56 changed files with 2,723 additions and 2,197 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ KubeBlocks add-ons.
| orioledb | orioledb-14.7.2-beta1 | OrioleDB is a new storage engine for PostgreSQL, bringing a modern approach to database capacity, capabilities and performance to the world's most-loved database platform. | 1aal |
| polardbx | polardbx-v2.3 | PolarDB-X is a cloud native distributed SQL Database designed for high concurrency, massive storage, complex querying scenarios. | Vettal Wu |
| postgresql | postgresql-12.14.0<br>postgresql-12.14.1<br>postgresql-12.15.0<br>postgresql-14.7.2<br>postgresql-14.8.0<br>postgresql-15.7.0<br>postgresql-16.4.0 | A PostgreSQL (with Patroni HA) cluster definition Helm chart for Kubernetes | ldming |
| pulsar | pulsar-bkrecovery-2.11.2<br>pulsar-bkrecovery-3.0.2<br>pulsar-bookkeeper-2.11.2<br>pulsar-bookkeeper-3.0.2<br>pulsar-broker-2.11.2<br>pulsar-broker-3.0.2<br>pulsar-proxy-2.11.2<br>pulsar-proxy-3.0.2<br>pulsar-zookeeper-2.11.2<br>pulsar-zookeeper-3.0.2 | Apache Pulsar is an open-source, distributed messaging and streaming platform built for the cloud. | caiq1nyu |
| pulsar | pulsar-bookies-recovery-2.11.2<br>pulsar-bookies-recovery-3.0.2<br>pulsar-bookkeeper-2.11.2<br>pulsar-bookkeeper-3.0.2<br>pulsar-broker-2.11.2<br>pulsar-broker-3.0.2<br>pulsar-proxy-2.11.2<br>pulsar-proxy-3.0.2<br>pulsar-zookeeper-2.11.2<br>pulsar-zookeeper-3.0.2 | Apache Pulsar is an open-source, distributed messaging and streaming platform built for the cloud. | caiq1nyu |
| qdrant | qdrant-1.10.0<br>qdrant-1.5.0<br>qdrant-1.7.3<br>qdrant-1.8.1<br>qdrant-1.8.4 | High-performance, massive-scale Vector Database for the next generation of AI. | iziang |
| rabbitmq | rabbitmq-3.10.25<br>rabbitmq-3.11.28<br>rabbitmq-3.12.14<br>rabbitmq-3.13.2<br>rabbitmq-3.8.14<br>rabbitmq-3.9.29 | RabbitMQ is a reliable and mature messaging and streaming broker. | xuriwuyun |
| redis | redis-7.0.6<br>redis-7.2.4<br>redis-cluster-7.0.6<br>redis-cluster-7.2.4<br>redis-sentinel-7.0.6<br>redis-sentinel-7.2.4<br>redis-twemproxy-0.5.0 | Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes, Streams, HyperLogLogs, Bitmaps. | Y-Rookie |
Expand Down
2 changes: 1 addition & 1 deletion addons-cluster/pulsar/templates/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ spec:
{{- if or (eq .Values.mode "pulsar-enhanced-cluster") ( and (not $topologyEnable) .Values.bookiesRecovery.enabled) }}
- name: bookies-recovery
{{- if not $topologyEnable }}
componentDef: pulsar-bkrecovery
componentDef: pulsar-bookies-recovery
{{- end }}
{{ include "pulsar-zookeeper-ref" . | nindent 6 }}
replicas: {{ .Values.bookiesRecovery.replicaCount | default 3 }}
Expand Down
9 changes: 8 additions & 1 deletion addons/pulsar/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ version: 1.0.0-alpha.0
# The current default value is the highest version of the Pulsar supported in KubeBlocks.
appVersion: 3.0.2

# Add a dependency to the kubeblocks definition library chart
dependencies:
- name: kblib
version: 0.1.0
repository: file://../kblib
alias: extra

home: https://pulsar.apache.org/
icon: https://pulsar.apache.org/img/logo-black.svg
keywords:
Expand All @@ -30,6 +37,6 @@ maintainers:
url: https://github.com/apecloud/kubeblocks/

annotations:
addon.kubeblocks.io/kubeblocks-version: ">=0.9.0"
addon.kubeblocks.io/kubeblocks-version: ">=1.0.0"
addon.kubeblocks.io/model: "streaming"
addon.kubeblocks.io/provider: "community"
1,498 changes: 0 additions & 1,498 deletions addons/pulsar/config/broker-config-constraint.cue

This file was deleted.

362 changes: 0 additions & 362 deletions addons/pulsar/config/proxy-config-constraint.cue

This file was deleted.

12 changes: 0 additions & 12 deletions addons/pulsar/config/zookeeper-server-config.tpl

This file was deleted.

20 changes: 0 additions & 20 deletions addons/pulsar/config/zookeeper-servers.tpl

This file was deleted.

88 changes: 88 additions & 0 deletions addons/pulsar/scripts-ut-spec/bookies_member_leave_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# shellcheck shell=bash
# shellcheck disable=SC2034

# validate_shell_type_and_version defined in shellspec/spec_helper.sh used to validate the expected shell type and version this script needs to run.
if ! validate_shell_type_and_version "bash" 4 &>/dev/null; then
echo "bookies_member_leave_spec.sh skip cases because dependency bash version 4 or higher is not installed."
exit 0
fi

Describe "Pulsar Bookies Member Leave Bash Script Tests"
# load the scripts to be tested and dependencies
Include ../scripts/bookies-member-leave.sh

init() {
ut_mode="true"
}
BeforeAll "init"

Describe "format_bookie()"
It "formats bookie with force and deleteCookie"
bin/bookkeeper() {
if [ "$1" = "shell" ] && [ "$2" = "bookieformat" ] && [ "$3" = "-nonInteractive" ] && [ "$4" = "-force" ] && [ "$5" = "-deleteCookie" ]; then
echo "Bookie formatted with force and deleteCookie"
return 0
fi
return 1
}

When call format_bookie "true" "true"
The output should include "Formatting Bookie..."
The output should include "Bookie formatted with force and deleteCookie"
The status should be success
End

It "formats bookie without force and deleteCookie"
bin/bookkeeper() {
if [ "$1" = "shell" ] && [ "$2" = "bookieformat" ] && [ "$3" = "-nonInteractive" ]; then
echo "Bookie formatted"
return 0
fi
return 1
}

When call format_bookie "false" "false"
The output should include "Formatting Bookie..."
The output should include "Bookie formatted"
The status should be success
End
End

Describe "should_format_bookie()"
It "returns true when pod index is greater than or equal to replicas"
When call should_format_bookie "pod-3" "2"
The status should be success
End

It "returns false when pod index is less than replicas"
When call should_format_bookie "pod-1" "2"
The status should be failure
End
End

Describe "bookies_member_leave()"
setup() {
export CURRENT_POD_NAME="pod-3"
export BOOKKEEPER_COMP_REPLICAS="2"
}

It "formats bookie when condition is met"
setup

format_bookie() {
echo "format_bookie called with $1 $2"
}

When call bookies_member_leave
The output should include "format_bookie called with true true"
End

It "skips formatting when condition is not met"
export CURRENT_POD_NAME="pod-1"
export BOOKKEEPER_COMP_REPLICAS="2"

When call bookies_member_leave
The output should include "Skipping Bookie formatting"
End
End
End
64 changes: 64 additions & 0 deletions addons/pulsar/scripts-ut-spec/check_bookies_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# shellcheck shell=bash
# shellcheck disable=SC2034

# validate_shell_type_and_version defined in shellspec/spec_helper.sh used to validate the expected shell type and version this script needs to run.
if ! validate_shell_type_and_version "bash" 4 &>/dev/null; then
echo "check_bookies_spec.sh skip cases because dependency bash version 4 or higher is not installed."
exit 0
fi

Describe "Pulsar Check Bookies Bash Script Tests"
# load the scripts to be tested and dependencies
Include ../scripts/check-bookies.sh

init() {
ut_mode="true"
}
BeforeAll "init"

Describe "apply_config_from_env()"
It "applies configuration from environment variables"
# mock command to apply configuration from environment variables
bin/apply-config-from-env.py() {
return 0
}

When call apply_config_from_env
The output should include "Applying configuration from environment variables:"
The output should include " - Command: bin/apply-config-from-env.py conf/bookkeeper.conf"
The status should be success
End
End

Describe "wait_for_bookkeeper()"
It "waits for bookkeeper to start"
# mock command to check if bookkeeper instance id is available
bin/bookkeeper() {
if [ "$1" = "shell" ] && [ "$2" = "whatisinstanceid" ]; then
return 0
fi
return 1
}

When run wait_for_bookkeeper
The output should include "Waiting for bookkeeper to start..."
The output should include "Bookkeeper started successfully"
The status should be success
End
End

Describe "set_tcp_keepalive()"
It "sets TCP keepalive parameters"
sysctl() {
return 0
}

When run set_tcp_keepalive
The output should include "Setting TCP keepalive parameters:"
The output should include " - net.ipv4.tcp_keepalive_time=1"
The output should include " - net.ipv4.tcp_keepalive_intvl=11"
The output should include " - net.ipv4.tcp_keepalive_probes=3"
The status should be success
End
End
End
125 changes: 125 additions & 0 deletions addons/pulsar/scripts-ut-spec/init_bookies_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# shellcheck shell=bash
# shellcheck disable=SC2034

# validate_shell_type_and_version defined in shellspec/spec_helper.sh used to validate the expected shell type and version this script needs to run.
if ! validate_shell_type_and_version "bash" 4 &>/dev/null; then
echo "init_bookies_spec.sh skip cases because dependency bash version 4 or higher is not installed."
exit 0
fi

Describe "Pulsar Init Bookies Bash Script Tests"
# load the scripts to be tested and dependencies
Include ../scripts/init-bookies.sh

init() {
ut_mode="true"
}
BeforeAll "init"

Describe "wait_for_zookeeper()"
It "waits for Zookeeper to be ready"
nc() {
if [ "$1" = "-q" ] && [ "$2" = "1" ] && [ "$3" = "zookeeper.example.com" ] && [ "$4" = "2181" ]; then
echo "imok"
fi
}

When call wait_for_zookeeper "zookeeper.example.com:2181"
The output should include "Waiting for Zookeeper at zookeeper.example.com:2181 to be ready..."
The output should include "Zookeeper is ready"
End
End

Describe "merge_bookkeeper_config()"
It "merges Pulsar configuration files"
python3() {
echo "$1 $2 $3"
}

When run merge_bookkeeper_config
The output should include "/kb-scripts/merge_pulsar_config.py"
The output should include "Merging Pulsar configuration files:"
The output should include " - Source: conf/bookkeeper.conf"
The output should include " - Destination: /opt/pulsar/conf/bookkeeper.conf"
The status should be success
End
End

Describe "apply_config_from_env()"
It "applies configuration from environment variables"
bin/apply-config-from-env.py() {
return 0
}

When run apply_config_from_env
The output should include "Applying configuration from environment variables to conf/bookkeeper.conf"
The status should be success
End
End

Describe "init_bookkeeper_cluster()"
It "initializes new BookKeeper cluster if not already initialized"
bin/bookkeeper() {
if [ "$1" = "shell" ] && [ "$2" = "whatisinstanceid" ]; then
return 1
elif [ "$1" = "shell" ] && [ "$2" = "initnewcluster" ]; then
return 0
fi
}

When run init_bookkeeper_cluster
The output should include "Checking if BookKeeper cluster is already initialized..."
The output should include "Initializing new BookKeeper cluster"
The status should be success
End

It "skips initialization if BookKeeper cluster is already initialized"
bin/bookkeeper() {
if [ "$1" = "shell" ] && [ "$2" = "whatisinstanceid" ]; then
return 0
fi
}

When run init_bookkeeper_cluster
The output should include "Checking if BookKeeper cluster is already initialized..."
The output should include "BookKeeper cluster is already initialized"
The status should be success
End
End

Describe "init_bookies()"
It "initializes bookies"
export zkServers="zookeeper.example.com:2181"

wait_for_zookeeper() {
echo "wait_for_zookeeper called"
}

merge_bookkeeper_config() {
echo "merge_bookkeeper_config called"
}

apply_config_from_env() {
echo "apply_config_from_env called"
}

init_bookkeeper_cluster() {
echo "init_bookkeeper_cluster called"
}

When run init_bookies
The output should include "wait_for_zookeeper called"
The output should include "merge_bookkeeper_config called"
The output should include "apply_config_from_env called"
The output should include "init_bookkeeper_cluster called"
End

It "exits with status 1 when zkServers environment variable is not set"
unset zkServers

When run init_bookies
The output should include "Error: zkServers environment variable is not set, Please set the zkServers environment variable and try again."
The status should be failure
End
End
End
Loading

0 comments on commit 4fdc89b

Please sign in to comment.