Skip to content

Commit

Permalink
Merge pull request #60 from DaspawnW/bugfix
Browse files Browse the repository at this point in the history
Fix issue that could occur during startup, that produces an endless l…
  • Loading branch information
DaspawnW authored Jan 29, 2021
2 parents 19d219a + b3f6548 commit a20c22d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
java-version: 1.8

- uses: engineerd/setup-kind@v0.4.0
- uses: engineerd/setup-kind@v0.5.0
with:
version: "v0.8.1"
image: "${{ matrix.kubernetes_version }}"
Expand Down
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 a20c22d

Please sign in to comment.