+# Stop the policy agent
+# args: -
+# args: -
+# (Function for test scripts)
+stop_policy_agent() {
+ echo -e $BOLD"Stopping $POLICY_AGENT_DISPLAY_NAME"$EBOLD
+
+ if [ $RUNMODE == "KUBE" ]; then
+
+ __check_prestarted_image "PA"
+ if [ $? -eq 0 ]; then
+ echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
+ res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
+ __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
+ return 0
+ fi
+ __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
+ echo " Deleting the replica set - a new will be started when the app is started"
+ tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
+ if [ $? -ne 0 ]; then
+ echo -e $RED" Could not delete replica set "$RED
+ ((RES_CONF_FAIL++))
+ return 1
+ fi
+ else
+ docker stop $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
+ if [ $? -ne 0 ]; then
+ __print_err "Could not stop $POLICY_AGENT_APP_NAME" $@
+ cat ./tmp/.dockererr
+ ((RES_CONF_FAIL++))
+ return 1
+ fi
+ fi
+ echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
+ echo ""
+ return 0
+}
+
+# Start a previously stopped policy agent
+# args: -
+# (Function for test scripts)
+start_stopped_policy_agent() {
+ echo -e $BOLD"Starting (the previously stopped) $POLICY_AGENT_DISPLAY_NAME"$EBOLD
+
+ if [ $RUNMODE == "KUBE" ]; then
+
+ __check_prestarted_image "PA"
+ if [ $? -eq 0 ]; then
+ echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
+ res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
+ __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
+ __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
+ return 0
+ fi
+
+ # Tie the PMS to the same worker node it was initially started on
+ # A PVC of type hostPath is mounted to PMS, for persistent storage, so the PMS must always be on the node which mounted the volume
+ if [ -z "$__PA_WORKER_NODE" ]; then
+ echo -e $RED" No initial worker node found for pod "$RED
+ ((RES_CONF_FAIL++))
+ return 1
+ else
+ echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__PA_WORKER_NODE to deployment for $POLICY_AGENT_APP_NAME. Pod will always run on this worker node: $__PA_WORKER_NODE"$BOLD
+ echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
+ tmp=$(kubectl patch deployment $POLICY_AGENT_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__PA_WORKER_NODE'"}}}}}')
+ if [ $? -ne 0 ]; then
+ echo -e $YELLOW" Cannot set nodeSelector to deployment for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
+ fi
+ __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
+ fi
+ else
+ docker start $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
+ if [ $? -ne 0 ]; then
+ __print_err "Could not start (the stopped) $POLICY_AGENT_APP_NAME" $@
+ cat ./tmp/.dockererr
+ ((RES_CONF_FAIL++))
+ return 1
+ fi
+ fi
+ __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
+ if [ $? -ne 0 ]; then
+ return 1
+ fi
+ echo ""
+ return 0
+}
+
+
+