2019-02-13 13:28:16 +00:00
#!/bin/bash
2019-02-13 17:57:18 +00:00
for i in " $@ "
do
case $i in
2019-02-19 16:01:47 +00:00
--service= *)
service_name = " ${ i #*= } "
shift
; ;
2019-02-13 17:57:18 +00:00
--namespace= *)
namespace = " ${ i #*= } "
shift
; ;
--serverIp= *)
serverIp = " ${ i #*= } "
shift
; ;
esac
done
2019-02-13 13:28:16 +00:00
hub_user_name = "nirmata"
2019-05-22 01:36:24 +00:00
project_name = "kyverno"
2019-02-13 13:28:16 +00:00
2019-02-19 16:01:47 +00:00
if [ -z " ${ service_name } " ] ; then
service_name = " ${ project_name } -svc "
fi
2019-02-13 13:28:16 +00:00
echo " Generating certificate for the service ${ service_name } ... "
2019-02-13 17:57:18 +00:00
2019-02-13 13:28:16 +00:00
certsGenerator = "./scripts/generate-server-cert.sh"
chmod +x " ${ certsGenerator } "
2019-02-19 16:01:47 +00:00
if [ -z " ${ namespace } " ] ; then # controller should be launched locally
2019-02-15 18:00:49 +00:00
2019-02-19 16:01:47 +00:00
${ certsGenerator } " --service= ${ service_name } " " --serverIp= ${ serverIp } " || exit 2
2019-02-13 17:57:18 +00:00
echo "Applying webhook..."
2019-05-06 16:12:37 +00:00
kubectl delete -f definitions/MutatingWebhookConfiguration_debug.yaml
kubectl create -f definitions/MutatingWebhookConfiguration_debug.yaml || exit 3
2019-02-13 13:28:16 +00:00
2019-05-06 16:12:37 +00:00
kubectl delete -f definitions/install.yaml
kubectl create -f definitions/install.yaml || exit 3
2019-03-07 16:48:02 +00:00
2019-05-22 01:36:24 +00:00
echo -e "\n### You can build and run kyverno project locally.\n### To check its work, run it with parameters -cert, -key and -kubeconfig parameters (see paths of -cert and -key in the log above)."
2019-02-13 13:28:16 +00:00
2019-02-19 16:01:47 +00:00
else # controller should be launched within a cluster
2019-02-13 17:57:18 +00:00
${ certsGenerator } " --service= ${ service_name } " " --namespace= ${ namespace } " " --serverIp= ${ serverIp } " || exit 2
secret_name = " ${ project_name } -secret "
echo " Generating secret ${ secret_name } ... "
kubectl delete secret " ${ secret_name } " 2>/dev/null
kubectl create secret generic ${ secret_name } --namespace ${ namespace } --from-file= ./certs || exit 3
echo " Creating the service ${ service_name } ... "
kubectl delete -f crd/service.yaml
kubectl create -f crd/service.yaml || exit 4
echo "Creating deployment..."
kubectl delete -f crd/deployment.yaml
kubectl create -f crd/deployment.yaml || exit 5
echo "Applying webhook..."
kubectl delete -f crd/MutatingWebhookConfiguration.yaml
kubectl create -f crd/MutatingWebhookConfiguration.yaml || exit 3
2019-03-07 16:48:02 +00:00
kubectl delete -f crd/crd.yaml
kubectl create -f crd/crd.yaml || exit 3
2019-02-13 17:57:18 +00:00
echo -e "\n### Controller is running in cluster.\n### You can use compile-image.sh to rebuild its image and then the current script to redeploy the controller.\n### Check its work by 'kubectl logs <controller_pod> command'"
fi