3 # ============LICENSE_START=======================================================
4 # Copyright (C) 2023 Nordix Foundation.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # SPDX-License-Identifier: Apache-2.0
19 # ============LICENSE_END=========================================================
25 echo "Usage: $0 -n secretName -s sourceNamespace -d destinationNamespace"
26 echo -e "\t-n Name of the secret"
27 echo -e "\t-s Namespace of the secret"
28 echo -e "\t-d Namespace to copy the secret to"
32 while getopts "n:s:d:" opt
35 n ) secretName="$OPTARG" ;;
36 s ) sourceNS="$OPTARG" ;;
37 d ) destinationNS="$OPTARG" ;;
42 # Check if any of the paramters are empty
43 if [ -z "$secretName" ] || [ -z "$sourceNS" ] || [ -z "$destinationNS" ]
45 echo "Some or all of the parameters are empty";
49 # Check if the secret exits
50 kubectl get secret $secretName -n $sourceNS >/dev/null 2>/dev/null
53 echo "$secretName in $sourceNS does not exist"
57 # Check if the destination namespace exists
58 kubectl get ns $destinationNS >/dev/null 2>/dev/null
61 echo "$destinationNS does not exist"
65 # Begin script in case all parameters are correct
66 echo "Copying $secretName from $sourceNS to $destinationNS"
68 tlsCrt=$(kubectl get secret ${secretName} -n ${sourceNS} -o json -o=jsonpath="{.data.tls\.crt}")
69 tlsKey=$(kubectl get secret ${secretName} -n ${sourceNS} -o json -o=jsonpath="{.data.tls\.key}")
70 caCrt=$(kubectl get secret ${secretName} -n ${sourceNS} -o json -o=jsonpath="{.data.ca\.crt}")
72 kubectl apply -f - <<EOF
81 namespace: ${destinationNS}
82 type: kubernetes.io/tls