Skip to content

Commit

Permalink
Fix issue that could occur during startup, that produces an endless l…
Browse files Browse the repository at this point in the history
…oop in add events

Add rotation for statefulset
  • Loading branch information
Björn Wenzel committed Jan 29, 2021
1 parent 19d219a commit 6478e2e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public void handle(Vault resource) {
case "deployment":
rotateDeployment(resource.getMetadata().getNamespace(), changeAdjustmentCallback.getName());
break;
case "statefulset":
rotateStatefulSet(resource.getMetadata().getNamespace(), changeAdjustmentCallback.getName());
break;
default:
log.info("Currently a change adjustment is only supported for type deployment. Resource {} in namespace {} has type {}",
resource.getMetadata().getName(), resource.getMetadata().getNamespace(), changeAdjustmentCallback.getType());
Expand Down Expand Up @@ -54,4 +57,25 @@ private void rotateDeployment(String namespace, String name) {
log.error("Failed to rotate deployment {} in namespace {} with exception:", name, namespace, ex);
}
}

private void rotateStatefulSet(String namespace, String name) {
try {
log.info("Start rotation of statefulSet {} in namespace {}", name, namespace);
client.apps()
.statefulSets()
.inNamespace(namespace)
.withName(name)
.edit()
.editSpec()
.editTemplate()
.editMetadata()
.addToAnnotations("certificate-change-on", "vault-crd_" + System.currentTimeMillis())
.endMetadata()
.endTemplate()
.endSpec()
.done();
} catch (Exception ex) {
log.error("Failed to rotate statefulSet {} in namespace {} with exception:", name, namespace, ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import de.koudingspawn.vault.crd.Vault;
import de.koudingspawn.vault.vault.VaultSecret;
import de.koudingspawn.vault.vault.VaultService;
import de.koudingspawn.vault.vault.communication.SecretNotAccessibleException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
Expand All @@ -28,7 +27,7 @@ public void addHandler(Vault resource) {
try {
VaultSecret secretContent = vaultService.generateSecret(resource);
kubernetesService.createSecret(resource, secretContent);
} catch (SecretNotAccessibleException e) {
} catch (Exception e) {
log.error("Failed to generate secret for vault resource {} in namespace {} failed with exception:",
resource.getMetadata().getName(), resource.getMetadata().getNamespace(), e);
}
Expand All @@ -48,7 +47,7 @@ public void modifyHandler(Vault resource) {
if (resource.getSpec().getChangeAdjustmentCallback() != null) {
changeAdjustmentService.handle(resource);
}
} catch (SecretNotAccessibleException e) {
} catch (Exception e) {
log.error("Failed to modify secret for vault resource {} in namespace {} failed with exception:",
resource.getMetadata().getName(), resource.getMetadata().getNamespace(), e);
}
Expand Down

0 comments on commit 6478e2e

Please sign in to comment.