Skip to content

Commit

Permalink
Merge pull request #1126 from cloud-ark/develop
Browse files Browse the repository at this point in the history
Ensuring that KubePlus Pod comes up without error after a restart
  • Loading branch information
devdattakulkarni authored Mar 8, 2023
2 parents 9def460 + a235cd3 commit c1a3f45
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
40 changes: 20 additions & 20 deletions deploy/kubeconfiggenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,19 @@ def run_command(self, cmd):
#print("Inside run_command")
print(cmd)
cmdOut = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).communicate()
out = cmdOut[0]
err = cmdOut[1]
out = cmdOut[0].decode('utf-8')
err = cmdOut[1].decode('utf-8')
print(out)
if out != '':
return out
#printlines(out.decode('utf-8'))
print("---")
print(err)
return out, err
#if out != '':
# return out
# #printlines(out.decode('utf-8'))
#print("Error:")
#print(err)
if err != '':
return err
#if err != '':
# return err
#printlines(err.decode('utf-8'))

def _create_kubecfg_file(self, sa, namespace, token, ca, server):
Expand Down Expand Up @@ -147,8 +150,7 @@ def _create_kubecfg_file(self, sa, namespace, token, ca, server):
cmd = "kubectl create configmap " + configmapName + " -n " + namespace + " --from-file=" + os.getenv("HOME") + "/" + fileName
self.run_command(cmd)
get_cmd = "kubectl get configmap " + configmapName + " -n " + namespace
output = self.run_command(get_cmd)
output = output.decode('utf-8')
output, error = self.run_command(get_cmd)
if 'Error from server (NotFound)' in output:
time.sleep(2)
print("Trying again..")
Expand Down Expand Up @@ -398,16 +400,13 @@ def _create_secret(self, sa, namespace):
print("---")
created = False
while not created:
cmd = " kubectl create -f " + filePath
out = self.run_command(cmd)
if out != '':
out = out.decode('utf-8').strip()
print(out)
if 'created' in out:
created = True
else:
time.sleep(2)
print("Create secret:" + out)
cmd = " kubectl create -f " + filePath
out, err = self.run_command(cmd)
if 'created' in out or 'AlreadyExists' in err:
created = True
else:
time.sleep(2)
#print("Create secret:" + out)
return out

def _generate_kubeconfig(self, sa, namespace):
Expand All @@ -423,7 +422,8 @@ def _generate_kubeconfig(self, sa, namespace):
secretName = sa
out = self._create_secret(secretName, namespace)
print("Create secret:" + out)
if 'secret/' + sa + ' created' in out:
#if 'secret/' + sa + ' created' in out:
if True: # do this always
#json_output = json.loads(out)
#secretName = json_output["secrets"][0]["name"]
#print("Secret Name:" + secretName)
Expand Down
7 changes: 7 additions & 0 deletions deploy/webhook-create-self-signed-ca-cert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ echo $secret
echo $service
csrName=${service}.${namespace}

# Check if mutatingwebhookconfiguration object is present; if so, we can assume that the webhook has been installed;
op=$(kubectl get mutatingwebhookconfigurations platform-as-code.crd-binding 2>&1 || true)
if [[ $op == *"AGE"* ]]; then
echo "Mutating webhook is already configured."
exit
fi

# Source: https://www.funkypenguin.co.nz/blog/self-signed-certificate-on-mutating-webhook-requires-double-encryption/
# 1. Create CA key and CA cert
openssl genrsa -out rootCA.key 4096
Expand Down

0 comments on commit c1a3f45

Please sign in to comment.