Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with EKS Taint updates #651

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions src/main/java/gyro/aws/eks/EksNodegroupResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import gyro.core.scope.State;
import gyro.core.validation.Required;
import gyro.core.validation.ValidStrings;
import gyro.core.validation.ValidationError;
import software.amazon.awssdk.services.eks.EksClient;
import software.amazon.awssdk.services.eks.model.AMITypes;
import software.amazon.awssdk.services.eks.model.CapacityTypes;
Expand Down Expand Up @@ -533,14 +534,15 @@ public void update(
Set<Taint> taintsToRemove = new HashSet<>(currentTaints);
taintsToRemove.removeAll(taints);

// Taint key cannot be in both added and removed, this means it's an update, so remove from remove set.
Set<String> taintKeysToAddOrUpdate = taintsToAddOrUpdate.stream()
.map(Taint::key)
.collect(Collectors.toSet());
// Detect true updates.
// taint key and effect is the same, but the value is different.
Set<Taint> taintsToUpdate = new HashSet<>();
for (Taint taint : taintsToRemove) {
if (taintKeysToAddOrUpdate.contains(taint.key())) {
taintsToUpdate.add(taint);
for (Taint taintToBeRemoved : taintsToRemove) {
for (Taint taintToBeAdded : taintsToAddOrUpdate) {
if (taintToBeRemoved.key().equals(taintToBeAdded.key()) &&
taintToBeRemoved.effect().equals(taintToBeAdded.effect())) {
taintsToUpdate.add(taintToBeRemoved);
}
}
}
taintsToRemove.removeAll(taintsToUpdate);
Expand Down Expand Up @@ -596,6 +598,26 @@ public void delete(GyroUI ui, State state) throws Exception {
.until(() -> getNodegroup(client) == null);
}

@Override
public List<ValidationError> validate(Set<String> configuredFields) {
List<ValidationError> errors = new ArrayList<>();

if (configuredFields.contains("taint")) {
// Key-Effect combination must be unique
Set<String> keyEffect = new HashSet<>();
for (EksNodegroupTaint taint : getTaint()) {
if (!keyEffect.add(taint.getKey() + taint.getTaintEffect())) {
errors.add(new ValidationError(
this,
"taint",
"Found multiple taints with key '" + taint.getKey() + "' and effect '" + taint.getTaintEffect() + "'"));
}
}
}

return errors;
}

private Nodegroup getNodegroup(EksClient client) {
Nodegroup nodegroup = null;

Expand Down
Loading