#!/bin/bash
#
# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
# Licensed under the GNU General Public License Version 3 as shown at https://www.gnu.org/licenses/gpl-3.0.txt.

KUBECFG=$1
NS=$2
FILE=$3
ENCODED=$4

if [ -z "${NS}" ]; then
	if [ "${ENCODED}" = "true" ]; then
		echo "${FILE}" | base64 -d | kubectl --kubeconfig="${KUBECFG}" apply -f -
	else
		kubectl --kubeconfig="${KUBECFG}" apply -f "${FILE}"
	fi
else
	if [ "${ENCODED}" = "true" ]; then
		echo "${FILE}" | base64 -d | kubectl --kubeconfig="${KUBECFG}" apply -n "${NS}" -f -
	else
		kubectl --kubeconfig="${KUBECFG}" apply -n "${NS}" -f "${FILE}"
	fi
fi
