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"
project_name = "kube-policy"
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..."
kubectl delete -f crd/MutatingWebhookConfiguration_local.yaml
kubectl create -f crd/MutatingWebhookConfiguration_local.yaml || exit 3
2019-02-13 13:28:16 +00:00
2019-02-13 17:57:18 +00:00
echo -e "\n### You can build and run kube-policy project locally.\n### To check its work, run it with parameters -cert and -key, which contain generated TLS certificate and key (see their paths in 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
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