Skip to content

Commit 63c2e50

Browse files
author
Prince Rachit Sinha
committed
Add wait for secret to be present before copying
1 parent 9794e10 commit 63c2e50

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

.werft/util/certs.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,26 @@ export async function issueCertficate(werft, params: IssueCertificateParams) {
7272
}
7373

7474
export async function installCertficate(werft, params: InstallCertificateParams) {
75+
let notReadyYet = true;
7576
werft.log('certificate', `copying certificate from "${params.certNamespace}/${params.certName}" to "${params.destinationNamespace}/${params.certSecretName}"`);
76-
// certmanager is configured to create a secret in the namespace "certs" with the name "${namespace}".
77-
exec(`export KUBECONFIG=${params.pathToKubeConfig} && kubectl get secret ${params.certName} --namespace=${params.certNamespace} -o yaml \
78-
| yq d - 'metadata.namespace' \
79-
| yq d - 'metadata.uid' \
80-
| yq d - 'metadata.resourceVersion' \
81-
| yq d - 'metadata.creationTimestamp' \
82-
| sed 's/${params.certName}/${params.certSecretName}/g' \
83-
| kubectl apply --namespace=${params.destinationNamespace} -f -`);
77+
const cmd = `export KUBECONFIG=${params.pathToKubeConfig} && kubectl get secret ${params.certName} --namespace=${params.certNamespace} -o yaml \
78+
| yq d - 'metadata.namespace' \
79+
| yq d - 'metadata.uid' \
80+
| yq d - 'metadata.resourceVersion' \
81+
| yq d - 'metadata.creationTimestamp' \
82+
| sed 's/${params.certName}/${params.certSecretName}/g' \
83+
| kubectl apply --namespace=${params.destinationNamespace} -f -`
84+
85+
for (let i = 0; i < 60 && notReadyYet; i++) {
86+
const result = exec(cmd, { silent: true, dontCheckRc: true });
87+
if (result != undefined && result.code === 0) {
88+
notReadyYet = false;
89+
break;
90+
}
91+
werft.log('certificate', `Could not copy "${params.certNamespace}/${params.certName}", will retry`);
92+
sleep(5000);
93+
}
94+
if (!notReadyYet) {
95+
werft.log('certificate', `copied certificate from "${params.certNamespace}/${params.certName}" to "${params.destinationNamespace}/${params.certSecretName}"`);
96+
}
8497
}

0 commit comments

Comments
 (0)