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

Support init jwt secret when create pulsar cluster #1072

Merged
merged 4 commits into from
Jul 31, 2023
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
115 changes: 115 additions & 0 deletions charts/sn-platform-slim/conf/toolset/pulsar/clean_tls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

set -e

CHART_HOME=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/../.. && pwd)
cd ${CHART_HOME}

namespace=${namespace:-pulsar}
release=${release:-pulsar-dev}
clientComponents=${clientComponents:-"toolset"}
serverComponents=${serverComponents:-"bookie,broker,proxy,recovery,zookeeper"}

usage() {
cat <<EOF
This script is used to delete tls certs for a given pulsar helm deployment generated by "upload_tls.sh".
Options:
-h,--help prints the usage message
-n,--namespace the k8s namespace to install the pulsar helm chart. Defaut to ${namespace}.
-k,--release the pulsar helm release name. Default to ${release}.
-c,--client-components the client components of pulsar cluster. a comma separated list of components. Default to ${clientComponents}.
-s,--server-components the server components of pulsar cluster. a comma separated list of components. Default to ${serverComponents}.
Usage:
$0 --namespace pulsar --release pulsar-dev
EOF
}

while [[ $# -gt 0 ]]
do
key="$1"

case $key in
-n|--namespace)
namespace="$2"
shift
shift
;;
-k|--release)
release="$2"
shift
shift
;;
-c|--client-components)
clientComponents="$2"
shift
shift
;;
-s|--server-components)
serverComponents="$2"
shift
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "unknown option: $key"
usage
exit 1
;;
esac
done

function delete_ca() {
local tls_ca_secret="${release}-ca-tls"
/pulsar/kubectl delete secret ${tls_ca_secret} -n ${namespace}
}

function delete_server_cert() {
local component=$1
local server_cert_secret="${release}-tls-${component}"

/pulsar/kubectl delete secret ${server_cert_secret} \
-n ${namespace}
}

function delete_client_cert() {
local component=$1
local client_cert_secret="${release}-tls-${component}"

/pulsar/kubectl delete secret ${client_cert_secret} \
-n ${namespace}
}

delete_ca

IFS=', ' read -r -a server_components <<< "$serverComponents"
for component in "${server_components[@]}"
do
delete_server_cert ${component}
done

IFS=', ' read -r -a client_components <<< "$clientComponents"
for component in "${client_components[@]}"
do
delete_client_cert ${component}
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

CHART_HOME=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/../.. && pwd)
cd ${CHART_HOME}

usage() {
cat <<EOF
This script is used to cleanup the credentials for a given pulsar helm release.
Options:
-h,--help prints the usage message
-n,--namespace the k8s namespace to install the pulsar helm chart
-k,--release the pulsar helm release name
-d,--delete-namespace flag to delete k8s namespace.
Usage:
$0 --namespace pulsar --release pulsar-release
EOF
}


while [[ $# -gt 0 ]]
do
key="$1"

delete_namespace=false

case $key in
-n|--namespace)
namespace="$2"
shift
shift
;;
-d|--delete-namespace)
delete_namespace=true
shift
;;
-k|--release)
release="$2"
shift
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "unknown option: $key"
usage
exit 1
;;
esac
done

namespace=${namespace:-pulsar}
release=${release:-pulsar-dev}

function delete_namespace() {
if [[ "${delete_namespace}" == "true" ]]; then
/pulsar/kubectl delete namespace ${namespace}
fi
}

# delete the cc admin secrets
/pulsar/kubectl delete -n ${namespace} secret ${release}-admin-secret

# delete tokens
/pulsar/kubectl get secrets -n ${namespace} | grep ${release}-token- | awk '{print $1}' | xargs /pulsar/kubectl delete secrets -n ${namespace}

# delete namespace
delete_namespace
54 changes: 54 additions & 0 deletions charts/sn-platform-slim/conf/toolset/pulsar/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# Checks that appropriate gke params are set and
# that gcloud and kubectl are properly installed and authenticated

function need_tool(){
local tool="${1}"
local url="${2}"

echo >&2 "${tool} is required. Please follow ${url}"
exit 1
}

function need_gcloud(){
need_tool "gcloud" "https://cloud.google.com/sdk/downloads"
}

function need_kubectl(){
need_tool "kubectl" "https://kubernetes.io/docs/tasks/tools/install-kubectl"
}

function need_helm(){
need_tool "helm" "https://github.com/helm/helm/#install"
}

function need_eksctl(){
need_tool "eksctl" "https://eksctl.io"
}

function validate_gke_required_tools(){
if [ -z "$PROJECT" ]; then
echo "\$PROJECT needs to be set to your project id";
exit 1;
fi

for comm in gcloud kubectl helm
do
command -v "${comm}" > /dev/null 2>&1 || "need_${comm}"
done

gcloud container clusters list --project $PROJECT >/dev/null 2>&1 || { echo >&2 "Gcloud seems to be configured incorrectly or authentication is unsuccessfull"; exit 1; }

}

function cluster_admin_password_gke(){
gcloud container clusters describe $CLUSTER_NAME --zone $ZONE --project $PROJECT --format='value(masterAuth.password)';
}

function validate_eks_required_tools(){
for comm in eksctl kubectl helm
do
command -v "${comm}" > /dev/null 2>&1 || "need_${comm}"
done
}
66 changes: 66 additions & 0 deletions charts/sn-platform-slim/conf/toolset/pulsar/common_auth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

if [ -z "$CHART_HOME" ]; then
echo "error: CHART_HOME should be initialized"
exit 1
fi

OUTPUT=${CHART_HOME}/output
OUTPUT_BIN=${OUTPUT}/bin
PULSARCTL_VERSION=v2.10.2.2
PULSARCTL_BIN=/pulsar/bin/pulsarctl
export PATH=${HOME}/.pulsarctl/plugins:${PATH}

discoverArch() {
ARCH=$(uname -m)
case $ARCH in
x86) ARCH="386";;
x86_64) ARCH="amd64";;
i686) ARCH="386";;
i386) ARCH="386";;
esac
}

discoverArch
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')

test -d "$OUTPUT_BIN" || mkdir -p "$OUTPUT_BIN"

function pulsar::verify_pulsarctl() {
if test -x "$PULSARCTL_BIN"; then
return
fi
return 1
}

function pulsar::ensure_pulsarctl() {
if pulsar::verify_pulsarctl; then
return 0
fi
echo "Get pulsarctl install.sh script ..."
install_script=$(mktemp)
trap "test -f $install_script && rm $install_script" RETURN
curl --retry 10 -L -o $install_script https://raw.githubusercontent.com/streamnative/pulsarctl/master/install.sh
chmod +x $install_script
$install_script --user --version ${PULSARCTL_VERSION}
}


Loading