Skip to content

Commit

Permalink
update delete.sh to support self-sign-certs
Browse files Browse the repository at this point in the history
Signed-off-by: jooho <[email protected]>
  • Loading branch information
Jooho authored and ckadner committed Sep 13, 2023
1 parent d4fc59a commit e3c6f56
Showing 1 changed file with 37 additions and 0 deletions.
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
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

0 comments on commit e3c6f56

Please sign in to comment.