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

fix: Update delete.sh to support self-sign-certs #400

Merged
merged 1 commit into from
Sep 13, 2023
Merged
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
37 changes: 37 additions & 0 deletions scripts/delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,37 @@ if [[ ! -z $user_ns_array ]]; then
rm runtimes.yaml
fi

# If there is `modelmesh-webhook-server-cert` Certificate object in a namespace, it assumes that cert-manager operator is being used for generating a certificate.
# However, if there is no Certificate object in the namespace, it needs to exclude cert-manager part from kustomization.yaml to generate manifests properly.
export enable_self_signed_ca=true
Jooho marked this conversation as resolved.
Show resolved Hide resolved
if kubectl get certificates modelmesh-webhook-server-cert -n $namespace &> /dev/null; then
echo "Cert Manager is installed"
export enable_self_signed_ca=false
fi

if [[ $enable_self_signed_ca == "true" ]]; then
echo "Enabled Self Signed CA: Update manifest"
if [[ ! -f certmanager/kustomization.yaml.ori ]]; then
cp certmanager/kustomization.yaml certmanager/kustomization.yaml.ori
fi
cd certmanager; kustomize edit remove resource certificate.yaml; cd ../

if [[ ! -f default/kustomization.yaml.ori ]]; then
cp default/kustomization.yaml default/kustomization.yaml.ori
fi
cd default; kustomize edit remove resource ../certmanager; cd ../

# comment out vars
configMapGeneratorStartLine=$(grep -n configMapGenerator ./default/kustomization.yaml |cut -d':' -f1)
configMapGeneratorBeforeLine=$((configMapGeneratorStartLine-1))
sed -i.bak "1,${configMapGeneratorBeforeLine}s/^/#/g" default/kustomization.yaml

# remove webhookcainjection_patch.yaml
sed -i.bak '/webhookcainjection_patch.yaml/d' default/kustomization.yaml

rm default/kustomization.yaml.bak
fi

# Determine whether a modelmesh-controller-rolebinding clusterrolebinding exists and is
# associated with the service account in this namespace. If not, don't delete the cluster level RBAC.
set +e
Expand All @@ -147,3 +178,9 @@ kubectl delete -f dependencies/fvt.yaml --ignore-not-found=true
if [[ "$namespace" != "$old_namespace" ]]; then
kubectl config set-context --current --namespace=${old_namespace}
fi

if [[ $enable_self_signed_ca == "true" ]]; then
cp certmanager/kustomization.yaml.ori certmanager/kustomization.yaml
cp default/kustomization.yaml.ori default/kustomization.yaml
rm certmanager/kustomization.yaml.ori default/kustomization.yaml.ori
fi