Skip to content
Merged
Changes from 1 commit
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
80 changes: 80 additions & 0 deletions cmd/upgrade/upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash
namespace=kubesphere-logging-system
deployment="fluentbit-operator"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
deployment="fluentbit-operator"
fluentbit-operator="fluentbit-operator"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been modified, it is better not to have - in the shell name, I modified it to FluentbitOperator


function error_exit {
echo "$1" 1>&2
exit 1
}

function converting(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

converting can be renamed to migrate

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

## Converting an existing configuration to a new one
local resource=$1
local kind=$2
local list=$(kubectl get $resource.logging.kubesphere.io -A -o json) || error_exit "Cannot get resource $reresource"
local name=($(echo $list | jq -r '.items[].metadata.name | @json'))
local labels=($(echo $list | jq -r '.items[].metadata.labels | @json'))
local spec=($(echo $list | jq -r '.items[].spec | @json'))
local ns=($(echo $list | jq -r '.items[].metadata.namespace | @json'))
local size=${#spec[*]}
echo "Number of original $resource configuration files:$size"
for((i=0;i<${size};i++));do
if [[ "${kind}" = "fluentbits" ]]; then
cluster_resource_list[i]="{
\"apiVersion\": \"fluentbit.fluent.io/v1alpha2\",
\"kind\": \"${kind}\",
\"metadata\": {
\"name\": ${name[i]},
\"labels\": ${labels[i]},
\"namespace\": \"${ns}\"
},
\"spec\": ${spec[i]}
}"
else
cluster_resource_list[i]="{
\"apiVersion\": \"fluentbit.fluent.io/v1alpha2\",
\"kind\": \"${kind}\",
\"metadata\": {
\"name\": ${name[i]},
\"labels\": ${labels[i]}
},
\"spec\": ${spec[i]}
}"
fi
done

## Uninstall the fluentbit-operator and the original configuration
for((i=0;i<${size};i++));do
echo "${name[i]}"
temp=$(echo ${name[i]} | sed 's/"//g')
echo "$temp"
kubectl delete $resource.logging.kubesphere.io $temp -n ${namespace}
done

for((i=0;i<${size};i++));do
echo ${cluster_resource_list[i]} | kubectl apply -f - || error_exit "Cannot apply resource $reresource"
done
}

converting "inputs" "ClusterInput"
converting "parsers" "ClusterParser"
converting "filters" "ClusterFilter"
converting "outputs" "ClusterOutput"
converting "fluentbitconfigs" "ClusterFluentBitConfig"
converting "fluentbits" "FluentBit"

# Determine if Deployment exists
if kubectl get deployment -n $namespace $deployment >/dev/null 2>&1; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if kubectl get deployment -n $namespace $deployment >/dev/null 2>&1; then
if kubectl get deployment -n $namespace $fluentbit-operator >/dev/null 2>&1; then

# Delete Deployment if it exists
kubectl delete deployment -n $namespace $deployment
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
kubectl delete deployment -n $namespace $deployment
kubectl delete deployment -n $namespace $fluentbit-operator

kubectl delete clusterrolebinding kubesphere:operator:fluentbit-operator
kubectl delete clusterrole kubesphere:operator:fluentbit-operator
kubectl delete serviceaccount fluentbit-operator -n $namespace
echo "Deployment $deployment deleted"
else
# If it does not exist, output the message
echo "Deployment $deployment does not exist"
fi

## Delete the old crd
kubectl get crd -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | grep "logging.kubesphere.io" | xargs -I crd_name kubectl delete crd crd_name