#/bin/bash
FOLLOW_UP="yes"
NS_DOMAIN="cdci-librecloud-online"
PIPELINE_NAME="cdci-webhook-pipeline"
[ "$1" == "-s" ]  && FOLLOW_UP=""
is_running=`kubectl get pods -n $NS_DOMAIN | grep $PIPELINE_NAME 2>/dev/null`
if [ -n "$is_running" ] ; then
   kubectl delete -f pipeline-run.yaml 2>/dev/null
   kubectl delete -f pipeline.yaml 2>/dev/null
   kubectl delete -f task.yaml 2>/dev/null
   kubectl delete -f pipe-resource.yaml 2>/dev/null
fi
kubectl delete -f PersistentVolumeCDCI.yaml 2>/dev/null
kubectl create -f PersistentVolumeCDCI.yaml
#.  lib_dply.sh
#make_host_alias task
kubectl apply -f pipe-resource.yaml
kubectl apply -f task.yaml
kubectl apply -f pipeline.yaml
kubectl apply -f pipeline-run.yaml
if [ -n "$FOLLOW_UP" ] ; then
  has_tkn=`type tkn 2>/dev/null`
  [ -n "$has_tkn" ] &&  tkn pipelinerun logs -f $PIPELINE_NAME -n $NS_DOMAIN
fi
