From 5914aa0f06ce778399c24b7412ec58d60ccab74f Mon Sep 17 00:00:00 2001 From: Andre Dietisheim Date: Mon, 13 Nov 2023 16:47:43 +0100 Subject: [PATCH] fix: allow to compare fileconfig-contexts (#201) Signed-off-by: Andre Dietisheim --- .../intellij/common/utils/ConfigHelper.java | 25 ++++ .../common/utils/ConfigHelperTest.java | 114 ++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/src/main/java/com/redhat/devtools/intellij/common/utils/ConfigHelper.java b/src/main/java/com/redhat/devtools/intellij/common/utils/ConfigHelper.java index 7ffc482..9c08b39 100644 --- a/src/main/java/com/redhat/devtools/intellij/common/utils/ConfigHelper.java +++ b/src/main/java/com/redhat/devtools/intellij/common/utils/ConfigHelper.java @@ -142,6 +142,31 @@ && areEqual(clientConfig.getContexts(), kubeConfig.getContexts()) && areEqualToken(kubeConfig, clientConfig); } + /** + * Returns {@code true} if the given {@link io.fabric8.kubernetes.api.model.Config} and + * (client runtime) {@link io.fabric8.kubernetes.client.Config} are equal. They are considered equal if they're + * equal in + * + * + * @param thisConfig the first (file) config to compare + * @param thatConfig the second (file) config to compare + * @return true if both configs are equal in context, contexts and token + */ + public static boolean areEqual(Config thisConfig, Config thatConfig) { + if (thisConfig == null) { + return thatConfig == null; + } else if (thatConfig == null) { + return false; + } + return areEqual(KubeConfigUtils.getCurrentContext(thisConfig), KubeConfigUtils.getCurrentContext(thatConfig)) + && areEqual(thisConfig.getContexts(), thatConfig.getContexts()) + && areEqualToken(getAuthInfo(thisConfig), getAuthInfo(thatConfig)); + } + /** * Returns {@code true} if both given contexts are equal. They are considered equal if they're equal in *