diff --git a/charts/sn-platform-slim/conf/toolset/pulsar/clean_tls.sh b/charts/sn-platform-slim/conf/toolset/pulsar/clean_tls.sh new file mode 100755 index 000000000..884cc383e --- /dev/null +++ b/charts/sn-platform-slim/conf/toolset/pulsar/clean_tls.sh @@ -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 <&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 +} diff --git a/charts/sn-platform-slim/conf/toolset/pulsar/common_auth.sh b/charts/sn-platform-slim/conf/toolset/pulsar/common_auth.sh new file mode 100755 index 000000000..ede8c86eb --- /dev/null +++ b/charts/sn-platform-slim/conf/toolset/pulsar/common_auth.sh @@ -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} +} + + diff --git a/charts/sn-platform-slim/conf/toolset/pulsar/decommission_bookies.sh b/charts/sn-platform-slim/conf/toolset/pulsar/decommission_bookies.sh new file mode 100755 index 000000000..55e2823f7 --- /dev/null +++ b/charts/sn-platform-slim/conf/toolset/pulsar/decommission_bookies.sh @@ -0,0 +1,96 @@ +#!/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} + +usage() { + cat <=1; i--)) +do + j=$((i-1)) + echo /pulsar/kubectl -n ${namespace} scale --replicas=${j} sts/${statefulset} + /pulsar/kubectl -n ${namespace} scale --replicas=${j} sts/${statefulset} + echo /pulsar/kubectl -n ${autorecovery_namespace} exec -it ${autorecovery_pod} -- bin/bookkeeper shell decommissionbookie -bookieid ${statefulset}-${j}.${statefulset}.${namespace}.svc.cluster.local:3181 + /pulsar/kubectl -n ${autorecovery_namespace} exec -it ${autorecovery_pod} -- bin/bookkeeper shell decommissionbookie -bookieid ${statefulset}-${j}.${statefulset}.${namespace}.svc.cluster.local:3181 +done diff --git a/charts/sn-platform-slim/conf/toolset/pulsar/generate_token.sh b/charts/sn-platform-slim/conf/toolset/pulsar/generate_token.sh new file mode 100755 index 000000000..7dd1b656e --- /dev/null +++ b/charts/sn-platform-slim/conf/toolset/pulsar/generate_token.sh @@ -0,0 +1,125 @@ +#!/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} + +usage() { + cat < +EOF +} + +symmetric=false + +while [[ $# -gt 0 ]] +do +key="$1" + +case $key in + -n|--namespace) + namespace="$2" + shift + shift + ;; + -k|--release) + release="$2" + shift + shift + ;; + -r|--role) + role="$2" + shift + shift + ;; + -s|--symmetric) + symmetric=true + shift + ;; + -h|--help) + usage + exit 0 + ;; + *) + echo "unknown option: $key" + usage + exit 1 + ;; +esac +done + +if [[ "x${role}" == "x" ]]; then + echo "No pulsar role is provided!" + usage + exit 1 +fi + +source ${CHART_HOME}/scripts/pulsar/common_auth.sh + +# pulsar::ensure_pulsarctl + +namespace=${namespace:-pulsar} +release=${release:-pulsar-dev} + +function pulsar::jwt::generate_symmetric_token() { + local token_name="${release}-token-${role}" + local secret_name="${release}-token-symmetric-key" + + tmpfile=$(mktemp) + trap "test -f $tmpfile && rm $tmpfile" RETURN + tokentmpfile=$(mktemp) + trap "test -f $tokentmpfile && rm $tokentmpfile" RETURN + /pulsar/kubectl get -n ${namespace} secrets ${secret_name} -o jsonpath="{.data['SECRETKEY']}" | base64 --decode > ${tmpfile} + ${PULSARCTL_BIN} token create -a HS256 --secret-key-file ${tmpfile} --subject ${role} 2&> ${tokentmpfile} + newtokentmpfile=$(mktemp) + tr -d '\n' < ${tokentmpfile} > ${newtokentmpfile} + /pulsar/kubectl create secret generic ${token_name} -n ${namespace} --from-file="TOKEN=${newtokentmpfile}" --from-literal="TYPE=symmetric" +} + +function pulsar::jwt::generate_asymmetric_token() { + local token_name="${release}-token-${role}" + local secret_name="${release}-token-asymmetric-key" + + privatekeytmpfile=$(mktemp) + trap "test -f $privatekeytmpfile && rm $privatekeytmpfile" RETURN + tokentmpfile=$(mktemp) + trap "test -f $tokentmpfile && rm $tokentmpfile" RETURN + /pulsar/kubectl get -n ${namespace} secrets ${secret_name} -o jsonpath="{.data['PRIVATEKEY']}" | base64 --decode > ${privatekeytmpfile} + ${PULSARCTL_BIN} token create -a RS256 --private-key-file ${privatekeytmpfile} --subject ${role} 2&> ${tokentmpfile} + newtokentmpfile=$(mktemp) + tr -d '\n' < ${tokentmpfile} > ${newtokentmpfile} + /pulsar/kubectl create secret generic ${token_name} -n ${namespace} --from-file="TOKEN=${newtokentmpfile}" --from-literal="TYPE=asymmetric" +} + +if [[ "${symmetric}" == "true" ]]; then + pulsar::jwt::generate_symmetric_token +else + pulsar::jwt::generate_asymmetric_token +fi diff --git a/charts/sn-platform-slim/conf/toolset/pulsar/generate_token_secret_key.sh b/charts/sn-platform-slim/conf/toolset/pulsar/generate_token_secret_key.sh new file mode 100755 index 000000000..f5c9f28a3 --- /dev/null +++ b/charts/sn-platform-slim/conf/toolset/pulsar/generate_token_secret_key.sh @@ -0,0 +1,109 @@ +#!/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} + +usage() { + cat < +EOF +} + +while [[ $# -gt 0 ]] +do +key="$1" + +case $key in + -n|--namespace) + namespace="$2" + shift + shift + ;; + -k|--release) + release="$2" + shift + shift + ;; + -r|--role) + role="$2" + shift + shift + ;; + -h|--help) + usage + exit 0 + ;; + *) + echo "unknown option: $key" + usage + exit 1 + ;; +esac +done + +if [[ "x${role}" == "x" ]]; then + echo "No pulsar role is provided!" + usage + exit 1 +fi + +source ${CHART_HOME}/scripts/pulsar/common_auth.sh + +# pulsar::ensure_pulsarctl + +namespace=${namespace:-pulsar} +release=${release:-pulsar-dev} + +function pulsar::jwt::get_token() { + local token_name="${release}-token-${role}" + + local token=$(/pulsar/kubectl get -n ${namespace} secrets ${token_name} -o jsonpath="{.data['TOKEN']}" | base64 --decode) + local token_type=$(/pulsar/kubectl get -n ${namespace} secrets ${token_name} -o jsonpath="{.data['TYPE']}" | base64 --decode) + + echo "token type: ${token_type}" + echo "-------------------------" + echo "${token}" +} + +pulsar::jwt::get_token diff --git a/charts/sn-platform-slim/conf/toolset/pulsar/gke_bootstrap_script.sh b/charts/sn-platform-slim/conf/toolset/pulsar/gke_bootstrap_script.sh new file mode 100755 index 000000000..e6f20599a --- /dev/null +++ b/charts/sn-platform-slim/conf/toolset/pulsar/gke_bootstrap_script.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +set -e + +REGION=${REGION:-"us-east1"} +ZONE_EXTENSION=${ZONE_EXTENSION:-"b"} +ZONE=${REGION}-${ZONE_EXTENSION} +CLUSTER_NAME=${CLUSTER_NAME:-"pulsar-dev"} +MACHINE_TYPE=${MACHINE_TYPE:-"n1-standard-4"} +NUM_NODES=${NUM_NODES:-"4"} +INT_NETWORK=${INT_NETWORK:-"default"} +PREEMPTIBLE=${PREEMPTIBLE-false} +EXTRA_CREATE_ARGS=${EXTRA_CREATE_ARGS:-""} +USE_LOCAL_SSD=${USE_LOCAL_SSD-false} +LOCAL_SSD_COUNT=${LOCAL_SSD_COUNT:-"4"} +CONFDIR=${CONFDIR:-"${HOME}/.config/streamnative"} + +# MacOS does not support readlink, but it does have perl +KERNEL_NAME=$(uname -s) +BINDIR=$(dirname "$0") +SCRIPTS_DIR=`cd ${BINDIR};pwd` + +source ${SCRIPTS_DIR}/common.sh; + +function bootstrap(){ + set -e + validate_gke_required_tools; + + # Use the default cluster version for the specified zone if not provided + if [ -z "${CLUSTER_VERSION}" ]; then + CLUSTER_VERSION=$(gcloud container get-server-config --zone $ZONE --project $PROJECT --format='value(defaultClusterVersion)'); + fi + + if $PREEMPTIBLE; then + EXTRA_CREATE_ARGS="$EXTRA_CREATE_ARGS --preemptible" + fi + if ${USE_LOCAL_SSD}; then + EXTRA_CREATE_ARGS="$EXTRA_CREATE_ARGS --local-ssd-count ${LOCAL_SSD_COUNT}" + fi + + gcloud container clusters create $CLUSTER_NAME \ + --zone $ZONE \ + --cluster-version $CLUSTER_VERSION \ + --machine-type $MACHINE_TYPE \ + --scopes "default","https://www.googleapis.com/auth/ndev.clouddns.readwrite" \ + --node-version ${CLUSTER_VERSION} \ + --num-nodes $NUM_NODES \ + --enable-ip-alias \ + --network $INT_NETWORK \ + --project $PROJECT \ + $EXTRA_CREATE_ARGS; + + mkdir -p ${CONFDIR}/.kube; + touch ${CONFDIR}/.kube/config; + export KUBECONFIG=${CONFDIR}/.kube/config; + + gcloud container clusters get-credentials $CLUSTER_NAME --zone $ZONE --project $PROJECT; + + echo "Wait for metrics API service" + # Helm 2.15 and 3.0 bug https://github.com/helm/helm/issues/6361#issuecomment-550503455 + /pulsar/kubectl --namespace=kube-system wait --for=condition=Available --timeout=5m apiservices/v1beta1.metrics.k8s.io + + helm repo update +} + +#Deletes everything created during bootstrap +function cleanup_gke_resources(){ + validate_gke_required_tools; + + gcloud container clusters delete -q $CLUSTER_NAME --zone $ZONE --project $PROJECT; + echo "Deleted $CLUSTER_NAME cluster successfully"; + + echo "\033[;33m Warning: Disks, load balancers, DNS records, and other cloud resources created during the helm deployment are not deleted, please delete them manually from the gcp console \033[0m"; +} + +gke_help() { + cat < +where command is one of: + up Create a GKE cluster + down Delete a GKE cluster + +Environment variables: + PROJECT Name of the GCP project. It is not set by default. + + CLUSTER_NAME Name of the GKE cluster. Defaults to ${CLUSTER_NAME}. + CONFDIR Configuration directory to store kubernetes config. Defaults to ${CONFDIR} + INT_NETWORK The Compute Engine Network that the cluster will connect to. Defaults to the '${INT_NETWORK}' network. + LOCAL_SSD_COUNT The number of local ssd counts. Defaults to ${LOCAL_SSD_COUNT}. + MACHINE_TYPE The type of machine to use for nodes. Defaults to ${MACHINE_TYPE}. + NUM_NODES The number of nodes to be created in each of the cluster's zones. Defaults to ${NUM_NODES}. + PREEMPTIBLE Create nodes using preemptible VM instances in the new cluster. Defaults to ${PREEMPTIBLE}. + REGION Compute region for the cluster. Defaults to ${REGION}. + USE_LOCAL_SSD Flag to create a cluster with local SSDs. Defaults to ${USE_LOCAL_SSD}. + ZONE Compute zone for the cluster. Defaults to ${ZONE}. + ZONE_EXTENSION Compute zone extension for the cluster. Defaults to ${ZONE_EXTENSION}. + + EXTRA_CREATE_ARGS Extra arguments passed to create command. +EOF +} + +if [ -z "$1" ]; then + gke_help + exit 1 +fi + +case $1 in + up) + bootstrap; + ;; + down) + cleanup_gke_resources; + ;; + *) + echo "Unknown command $1"; + exit 1; + ;; +esac diff --git a/charts/sn-platform-slim/conf/toolset/pulsar/prepare_helm_release.sh b/charts/sn-platform-slim/conf/toolset/pulsar/prepare_helm_release.sh new file mode 100755 index 000000000..68e55a300 --- /dev/null +++ b/charts/sn-platform-slim/conf/toolset/pulsar/prepare_helm_release.sh @@ -0,0 +1,159 @@ +#!/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 + exit 1; +fi + +PROJECT_ID=$1 +RESOLVER_NAME=$2 +HELM_RELEASE=$3 +NAMESPACE=$4 + +echo "Create a service acccount : ${RESOLVER_NAME}." +gcloud iam service-accounts create ${RESOLVER_NAME} --display-name "${RESOLVER_NAME}" + +echo "Bind service account '${RESOLVER_NAME}' as role 'dns.admin'." +gcloud projects add-iam-policy-binding $PROJECT_ID \ + --member serviceAccount:${RESOLVER_NAME}@$PROJECT_ID.iam.gserviceaccount.com \ + --role roles/dns.admin + +echo "Create a key for service account '${RESOLVER_NAME}' as role 'dns.admin'." +gcloud iam service-accounts keys create ${RESOLVER_NAME}-key.json \ + --iam-account ${RESOLVER_NAME}@$PROJECT_ID.iam.gserviceaccount.com + +echo "Save the service account key as a kubernete secret '${HELM_RELEASE}-${RESOLVER_NAME}-svc-acct' in namespace '${NAMESPACE}'." +/pulsar/kubectl create secret generic ${HELM_RELEASE}-${RESOLVER_NAME}-svc-acct \ + --from-file=${RESOLVER_NAME}-key.json -n ${NAMESPACE} + +echo "Remove the generated key." +rm ${RESOLVER_NAME}-key.json \ No newline at end of file diff --git a/charts/sn-platform-slim/conf/toolset/pulsar/upload-lets-encrypt-ca.sh b/charts/sn-platform-slim/conf/toolset/pulsar/upload-lets-encrypt-ca.sh new file mode 100755 index 000000000..d84b9cefb --- /dev/null +++ b/charts/sn-platform-slim/conf/toolset/pulsar/upload-lets-encrypt-ca.sh @@ -0,0 +1,33 @@ +# +# 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. +# + +#!/usr/bin/env bash + +BINDIR=`dirname "$0"` +HELM_HOME=`cd $BINDIR/../..;pwd` + +cd $HELM_HOME/hack/pulsar/conf + +CA_NAME=lets-encrypt-x3-cross-signed +PEM="${CA_NAME}.pem" + +NAMESPACE=$1 + +/pulsar/kubectl create secret generic ${CA_NAME} \ + --from-file=${PEM} -n ${NAMESPACE} diff --git a/charts/sn-platform-slim/conf/toolset/pulsar/upload_tls.sh b/charts/sn-platform-slim/conf/toolset/pulsar/upload_tls.sh new file mode 100755 index 000000000..94b3f764d --- /dev/null +++ b/charts/sn-platform-slim/conf/toolset/pulsar/upload_tls.sh @@ -0,0 +1,135 @@ +#!/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} +tlsdir=${tlsdir:-"${HOME}/.config/pulsar/security_tool/gen/ca"} +clientComponents=${clientComponents:-""} +serverComponents=${serverComponents:-"bookie,broker,proxy,recovery,zookeeper,toolset"} + +usage() { + cat < + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"; + chmod +x /pulsar/kubectl; + mkdir -p scripts/pulsar; + cp scripts/jwt-secret-config/* scripts/pulsar; + chmod +x scripts/pulsar/*; + usingSecretKey={{ .Values.auth.authentication.jwt.usingSecretKey }}; + if [ "${usingSecretKey}" = "true" ]; then + ./scripts/pulsar/prepare_helm_release.sh -n {{ template "pulsar.namespace" . }} -k {{ .Release.Name }} --symmetric; + else + ./scripts/pulsar/prepare_helm_release.sh -n {{ template "pulsar.namespace" . }} -k {{ .Release.Name }}; + fi; + {{- if .Values.toolset.resources }} + resources: +{{ toYaml .Values.toolset.resources | indent 10 }} + {{- end }} + volumeMounts: + - mountPath: /pulsar/scripts/jwt-secret-config + name: {{ template "pulsar.fullname" . }}-jwt-secret-init-config + restartPolicy: Never + {{- if .Values.toolset.securityContext }} + securityContext: {{- toYaml .Values.toolset.securityContext | nindent 8 }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/sn-platform/conf/toolset/pulsar/clean_tls.sh b/charts/sn-platform/conf/toolset/pulsar/clean_tls.sh new file mode 100755 index 000000000..884cc383e --- /dev/null +++ b/charts/sn-platform/conf/toolset/pulsar/clean_tls.sh @@ -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 <&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 +} diff --git a/charts/sn-platform/conf/toolset/pulsar/common_auth.sh b/charts/sn-platform/conf/toolset/pulsar/common_auth.sh new file mode 100755 index 000000000..ede8c86eb --- /dev/null +++ b/charts/sn-platform/conf/toolset/pulsar/common_auth.sh @@ -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} +} + + diff --git a/charts/sn-platform/conf/toolset/pulsar/decommission_bookies.sh b/charts/sn-platform/conf/toolset/pulsar/decommission_bookies.sh new file mode 100755 index 000000000..55e2823f7 --- /dev/null +++ b/charts/sn-platform/conf/toolset/pulsar/decommission_bookies.sh @@ -0,0 +1,96 @@ +#!/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} + +usage() { + cat <=1; i--)) +do + j=$((i-1)) + echo /pulsar/kubectl -n ${namespace} scale --replicas=${j} sts/${statefulset} + /pulsar/kubectl -n ${namespace} scale --replicas=${j} sts/${statefulset} + echo /pulsar/kubectl -n ${autorecovery_namespace} exec -it ${autorecovery_pod} -- bin/bookkeeper shell decommissionbookie -bookieid ${statefulset}-${j}.${statefulset}.${namespace}.svc.cluster.local:3181 + /pulsar/kubectl -n ${autorecovery_namespace} exec -it ${autorecovery_pod} -- bin/bookkeeper shell decommissionbookie -bookieid ${statefulset}-${j}.${statefulset}.${namespace}.svc.cluster.local:3181 +done diff --git a/charts/sn-platform/conf/toolset/pulsar/generate_token.sh b/charts/sn-platform/conf/toolset/pulsar/generate_token.sh new file mode 100755 index 000000000..7dd1b656e --- /dev/null +++ b/charts/sn-platform/conf/toolset/pulsar/generate_token.sh @@ -0,0 +1,125 @@ +#!/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} + +usage() { + cat < +EOF +} + +symmetric=false + +while [[ $# -gt 0 ]] +do +key="$1" + +case $key in + -n|--namespace) + namespace="$2" + shift + shift + ;; + -k|--release) + release="$2" + shift + shift + ;; + -r|--role) + role="$2" + shift + shift + ;; + -s|--symmetric) + symmetric=true + shift + ;; + -h|--help) + usage + exit 0 + ;; + *) + echo "unknown option: $key" + usage + exit 1 + ;; +esac +done + +if [[ "x${role}" == "x" ]]; then + echo "No pulsar role is provided!" + usage + exit 1 +fi + +source ${CHART_HOME}/scripts/pulsar/common_auth.sh + +# pulsar::ensure_pulsarctl + +namespace=${namespace:-pulsar} +release=${release:-pulsar-dev} + +function pulsar::jwt::generate_symmetric_token() { + local token_name="${release}-token-${role}" + local secret_name="${release}-token-symmetric-key" + + tmpfile=$(mktemp) + trap "test -f $tmpfile && rm $tmpfile" RETURN + tokentmpfile=$(mktemp) + trap "test -f $tokentmpfile && rm $tokentmpfile" RETURN + /pulsar/kubectl get -n ${namespace} secrets ${secret_name} -o jsonpath="{.data['SECRETKEY']}" | base64 --decode > ${tmpfile} + ${PULSARCTL_BIN} token create -a HS256 --secret-key-file ${tmpfile} --subject ${role} 2&> ${tokentmpfile} + newtokentmpfile=$(mktemp) + tr -d '\n' < ${tokentmpfile} > ${newtokentmpfile} + /pulsar/kubectl create secret generic ${token_name} -n ${namespace} --from-file="TOKEN=${newtokentmpfile}" --from-literal="TYPE=symmetric" +} + +function pulsar::jwt::generate_asymmetric_token() { + local token_name="${release}-token-${role}" + local secret_name="${release}-token-asymmetric-key" + + privatekeytmpfile=$(mktemp) + trap "test -f $privatekeytmpfile && rm $privatekeytmpfile" RETURN + tokentmpfile=$(mktemp) + trap "test -f $tokentmpfile && rm $tokentmpfile" RETURN + /pulsar/kubectl get -n ${namespace} secrets ${secret_name} -o jsonpath="{.data['PRIVATEKEY']}" | base64 --decode > ${privatekeytmpfile} + ${PULSARCTL_BIN} token create -a RS256 --private-key-file ${privatekeytmpfile} --subject ${role} 2&> ${tokentmpfile} + newtokentmpfile=$(mktemp) + tr -d '\n' < ${tokentmpfile} > ${newtokentmpfile} + /pulsar/kubectl create secret generic ${token_name} -n ${namespace} --from-file="TOKEN=${newtokentmpfile}" --from-literal="TYPE=asymmetric" +} + +if [[ "${symmetric}" == "true" ]]; then + pulsar::jwt::generate_symmetric_token +else + pulsar::jwt::generate_asymmetric_token +fi diff --git a/charts/sn-platform/conf/toolset/pulsar/generate_token_secret_key.sh b/charts/sn-platform/conf/toolset/pulsar/generate_token_secret_key.sh new file mode 100755 index 000000000..f5c9f28a3 --- /dev/null +++ b/charts/sn-platform/conf/toolset/pulsar/generate_token_secret_key.sh @@ -0,0 +1,109 @@ +#!/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} + +usage() { + cat < +EOF +} + +while [[ $# -gt 0 ]] +do +key="$1" + +case $key in + -n|--namespace) + namespace="$2" + shift + shift + ;; + -k|--release) + release="$2" + shift + shift + ;; + -r|--role) + role="$2" + shift + shift + ;; + -h|--help) + usage + exit 0 + ;; + *) + echo "unknown option: $key" + usage + exit 1 + ;; +esac +done + +if [[ "x${role}" == "x" ]]; then + echo "No pulsar role is provided!" + usage + exit 1 +fi + +source ${CHART_HOME}/scripts/pulsar/common_auth.sh + +# pulsar::ensure_pulsarctl + +namespace=${namespace:-pulsar} +release=${release:-pulsar-dev} + +function pulsar::jwt::get_token() { + local token_name="${release}-token-${role}" + + local token=$(/pulsar/kubectl get -n ${namespace} secrets ${token_name} -o jsonpath="{.data['TOKEN']}" | base64 --decode) + local token_type=$(/pulsar/kubectl get -n ${namespace} secrets ${token_name} -o jsonpath="{.data['TYPE']}" | base64 --decode) + + echo "token type: ${token_type}" + echo "-------------------------" + echo "${token}" +} + +pulsar::jwt::get_token diff --git a/charts/sn-platform/conf/toolset/pulsar/gke_bootstrap_script.sh b/charts/sn-platform/conf/toolset/pulsar/gke_bootstrap_script.sh new file mode 100755 index 000000000..e6f20599a --- /dev/null +++ b/charts/sn-platform/conf/toolset/pulsar/gke_bootstrap_script.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +set -e + +REGION=${REGION:-"us-east1"} +ZONE_EXTENSION=${ZONE_EXTENSION:-"b"} +ZONE=${REGION}-${ZONE_EXTENSION} +CLUSTER_NAME=${CLUSTER_NAME:-"pulsar-dev"} +MACHINE_TYPE=${MACHINE_TYPE:-"n1-standard-4"} +NUM_NODES=${NUM_NODES:-"4"} +INT_NETWORK=${INT_NETWORK:-"default"} +PREEMPTIBLE=${PREEMPTIBLE-false} +EXTRA_CREATE_ARGS=${EXTRA_CREATE_ARGS:-""} +USE_LOCAL_SSD=${USE_LOCAL_SSD-false} +LOCAL_SSD_COUNT=${LOCAL_SSD_COUNT:-"4"} +CONFDIR=${CONFDIR:-"${HOME}/.config/streamnative"} + +# MacOS does not support readlink, but it does have perl +KERNEL_NAME=$(uname -s) +BINDIR=$(dirname "$0") +SCRIPTS_DIR=`cd ${BINDIR};pwd` + +source ${SCRIPTS_DIR}/common.sh; + +function bootstrap(){ + set -e + validate_gke_required_tools; + + # Use the default cluster version for the specified zone if not provided + if [ -z "${CLUSTER_VERSION}" ]; then + CLUSTER_VERSION=$(gcloud container get-server-config --zone $ZONE --project $PROJECT --format='value(defaultClusterVersion)'); + fi + + if $PREEMPTIBLE; then + EXTRA_CREATE_ARGS="$EXTRA_CREATE_ARGS --preemptible" + fi + if ${USE_LOCAL_SSD}; then + EXTRA_CREATE_ARGS="$EXTRA_CREATE_ARGS --local-ssd-count ${LOCAL_SSD_COUNT}" + fi + + gcloud container clusters create $CLUSTER_NAME \ + --zone $ZONE \ + --cluster-version $CLUSTER_VERSION \ + --machine-type $MACHINE_TYPE \ + --scopes "default","https://www.googleapis.com/auth/ndev.clouddns.readwrite" \ + --node-version ${CLUSTER_VERSION} \ + --num-nodes $NUM_NODES \ + --enable-ip-alias \ + --network $INT_NETWORK \ + --project $PROJECT \ + $EXTRA_CREATE_ARGS; + + mkdir -p ${CONFDIR}/.kube; + touch ${CONFDIR}/.kube/config; + export KUBECONFIG=${CONFDIR}/.kube/config; + + gcloud container clusters get-credentials $CLUSTER_NAME --zone $ZONE --project $PROJECT; + + echo "Wait for metrics API service" + # Helm 2.15 and 3.0 bug https://github.com/helm/helm/issues/6361#issuecomment-550503455 + /pulsar/kubectl --namespace=kube-system wait --for=condition=Available --timeout=5m apiservices/v1beta1.metrics.k8s.io + + helm repo update +} + +#Deletes everything created during bootstrap +function cleanup_gke_resources(){ + validate_gke_required_tools; + + gcloud container clusters delete -q $CLUSTER_NAME --zone $ZONE --project $PROJECT; + echo "Deleted $CLUSTER_NAME cluster successfully"; + + echo "\033[;33m Warning: Disks, load balancers, DNS records, and other cloud resources created during the helm deployment are not deleted, please delete them manually from the gcp console \033[0m"; +} + +gke_help() { + cat < +where command is one of: + up Create a GKE cluster + down Delete a GKE cluster + +Environment variables: + PROJECT Name of the GCP project. It is not set by default. + + CLUSTER_NAME Name of the GKE cluster. Defaults to ${CLUSTER_NAME}. + CONFDIR Configuration directory to store kubernetes config. Defaults to ${CONFDIR} + INT_NETWORK The Compute Engine Network that the cluster will connect to. Defaults to the '${INT_NETWORK}' network. + LOCAL_SSD_COUNT The number of local ssd counts. Defaults to ${LOCAL_SSD_COUNT}. + MACHINE_TYPE The type of machine to use for nodes. Defaults to ${MACHINE_TYPE}. + NUM_NODES The number of nodes to be created in each of the cluster's zones. Defaults to ${NUM_NODES}. + PREEMPTIBLE Create nodes using preemptible VM instances in the new cluster. Defaults to ${PREEMPTIBLE}. + REGION Compute region for the cluster. Defaults to ${REGION}. + USE_LOCAL_SSD Flag to create a cluster with local SSDs. Defaults to ${USE_LOCAL_SSD}. + ZONE Compute zone for the cluster. Defaults to ${ZONE}. + ZONE_EXTENSION Compute zone extension for the cluster. Defaults to ${ZONE_EXTENSION}. + + EXTRA_CREATE_ARGS Extra arguments passed to create command. +EOF +} + +if [ -z "$1" ]; then + gke_help + exit 1 +fi + +case $1 in + up) + bootstrap; + ;; + down) + cleanup_gke_resources; + ;; + *) + echo "Unknown command $1"; + exit 1; + ;; +esac diff --git a/charts/sn-platform/conf/toolset/pulsar/prepare_helm_release.sh b/charts/sn-platform/conf/toolset/pulsar/prepare_helm_release.sh new file mode 100755 index 000000000..68e55a300 --- /dev/null +++ b/charts/sn-platform/conf/toolset/pulsar/prepare_helm_release.sh @@ -0,0 +1,159 @@ +#!/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 + exit 1; +fi + +PROJECT_ID=$1 +RESOLVER_NAME=$2 +HELM_RELEASE=$3 +NAMESPACE=$4 + +echo "Create a service acccount : ${RESOLVER_NAME}." +gcloud iam service-accounts create ${RESOLVER_NAME} --display-name "${RESOLVER_NAME}" + +echo "Bind service account '${RESOLVER_NAME}' as role 'dns.admin'." +gcloud projects add-iam-policy-binding $PROJECT_ID \ + --member serviceAccount:${RESOLVER_NAME}@$PROJECT_ID.iam.gserviceaccount.com \ + --role roles/dns.admin + +echo "Create a key for service account '${RESOLVER_NAME}' as role 'dns.admin'." +gcloud iam service-accounts keys create ${RESOLVER_NAME}-key.json \ + --iam-account ${RESOLVER_NAME}@$PROJECT_ID.iam.gserviceaccount.com + +echo "Save the service account key as a kubernete secret '${HELM_RELEASE}-${RESOLVER_NAME}-svc-acct' in namespace '${NAMESPACE}'." +/pulsar/kubectl create secret generic ${HELM_RELEASE}-${RESOLVER_NAME}-svc-acct \ + --from-file=${RESOLVER_NAME}-key.json -n ${NAMESPACE} + +echo "Remove the generated key." +rm ${RESOLVER_NAME}-key.json \ No newline at end of file diff --git a/charts/sn-platform/conf/toolset/pulsar/upload-lets-encrypt-ca.sh b/charts/sn-platform/conf/toolset/pulsar/upload-lets-encrypt-ca.sh new file mode 100755 index 000000000..d84b9cefb --- /dev/null +++ b/charts/sn-platform/conf/toolset/pulsar/upload-lets-encrypt-ca.sh @@ -0,0 +1,33 @@ +# +# 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. +# + +#!/usr/bin/env bash + +BINDIR=`dirname "$0"` +HELM_HOME=`cd $BINDIR/../..;pwd` + +cd $HELM_HOME/hack/pulsar/conf + +CA_NAME=lets-encrypt-x3-cross-signed +PEM="${CA_NAME}.pem" + +NAMESPACE=$1 + +/pulsar/kubectl create secret generic ${CA_NAME} \ + --from-file=${PEM} -n ${NAMESPACE} diff --git a/charts/sn-platform/conf/toolset/pulsar/upload_tls.sh b/charts/sn-platform/conf/toolset/pulsar/upload_tls.sh new file mode 100755 index 000000000..94b3f764d --- /dev/null +++ b/charts/sn-platform/conf/toolset/pulsar/upload_tls.sh @@ -0,0 +1,135 @@ +#!/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} +tlsdir=${tlsdir:-"${HOME}/.config/pulsar/security_tool/gen/ca"} +clientComponents=${clientComponents:-""} +serverComponents=${serverComponents:-"bookie,broker,proxy,recovery,zookeeper,toolset"} + +usage() { + cat < + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"; + chmod +x /pulsar/kubectl; + mkdir -p scripts/pulsar; + cp scripts/jwt-secret-config/* scripts/pulsar; + chmod +x scripts/pulsar/*; + usingSecretKey={{ .Values.auth.authentication.jwt.usingSecretKey }}; + if [ "${usingSecretKey}" = "true" ]; then + ./scripts/pulsar/prepare_helm_release.sh -n {{ template "pulsar.namespace" . }} -k {{ .Release.Name }} --symmetric; + else + ./scripts/pulsar/prepare_helm_release.sh -n {{ template "pulsar.namespace" . }} -k {{ .Release.Name }}; + fi; + {{- if .Values.toolset.resources }} + resources: +{{ toYaml .Values.toolset.resources | indent 10 }} + {{- end }} + volumeMounts: + - mountPath: /pulsar/scripts/jwt-secret-config + name: {{ template "pulsar.fullname" . }}-jwt-secret-init-config + restartPolicy: Never + {{- if .Values.toolset.securityContext }} + securityContext: {{- toYaml .Values.toolset.securityContext | nindent 8 }} + {{- end }} +{{- end }} \ No newline at end of file