From 5c4ecaf8ea36dcd6bb8645e80a416bcb5f8b189b Mon Sep 17 00:00:00 2001 From: Todd Loisel <2481693+tloisel1@users.noreply.github.com> Date: Fri, 19 Jul 2024 10:41:17 -0400 Subject: [PATCH 1/2] Add validation error to check for unique constraint on Taints Taint key / effect combination must be unique --- .../gyro/aws/eks/EksNodegroupResource.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/gyro/aws/eks/EksNodegroupResource.java b/src/main/java/gyro/aws/eks/EksNodegroupResource.java index c58c57a46..b76c0a3d9 100644 --- a/src/main/java/gyro/aws/eks/EksNodegroupResource.java +++ b/src/main/java/gyro/aws/eks/EksNodegroupResource.java @@ -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; @@ -596,6 +597,26 @@ public void delete(GyroUI ui, State state) throws Exception { .until(() -> getNodegroup(client) == null); } + @Override + public List validate(Set configuredFields) { + List errors = new ArrayList<>(); + + if (configuredFields.contains("taint")) { + // Key-Effect combination must be unique + Set 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; From 32bac8ad76a2708db50bd84e5d3aeeb92e8618ad Mon Sep 17 00:00:00 2001 From: Todd Loisel <2481693+tloisel1@users.noreply.github.com> Date: Fri, 19 Jul 2024 10:42:01 -0400 Subject: [PATCH 2/2] Update logic for detecting taint updates to include taint effect --- .../java/gyro/aws/eks/EksNodegroupResource.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/gyro/aws/eks/EksNodegroupResource.java b/src/main/java/gyro/aws/eks/EksNodegroupResource.java index b76c0a3d9..ebd140dde 100644 --- a/src/main/java/gyro/aws/eks/EksNodegroupResource.java +++ b/src/main/java/gyro/aws/eks/EksNodegroupResource.java @@ -534,14 +534,15 @@ public void update( Set 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 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 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);