@Test void testGetCluster() { Config config = getTestKubeConfig(); Context context = Objects.requireNonNull(KubeConfigUtils.getCurrentContext(config)).getContext(); Cluster cluster = KubeConfigUtils.getCluster(config, context); assertNotNull(cluster); }
public static Cluster getCluster(Config config, Context context) { Cluster cluster = null; if (config != null && context != null) { String clusterName = context.getCluster(); if (clusterName != null) { List<NamedCluster> clusters = config.getClusters(); if (clusters != null) { cluster = clusters.stream() .filter(c -> c.getName().equals(clusterName)) .findAny() .map(NamedCluster::getCluster) .orElse(null); } } } return cluster; }
KubeConfigUtils { public static Cluster getCluster(Config config, Context context) { Cluster cluster = null; if (config != null && context != null) { String clusterName = context.getCluster(); if (clusterName != null) { List<NamedCluster> clusters = config.getClusters(); if (clusters != null) { cluster = clusters.stream() .filter(c -> c.getName().equals(clusterName)) .findAny() .map(NamedCluster::getCluster) .orElse(null); } } } return cluster; } }
KubeConfigUtils { public static Cluster getCluster(Config config, Context context) { Cluster cluster = null; if (config != null && context != null) { String clusterName = context.getCluster(); if (clusterName != null) { List<NamedCluster> clusters = config.getClusters(); if (clusters != null) { cluster = clusters.stream() .filter(c -> c.getName().equals(clusterName)) .findAny() .map(NamedCluster::getCluster) .orElse(null); } } } return cluster; } private  KubeConfigUtils(); }
KubeConfigUtils { public static Cluster getCluster(Config config, Context context) { Cluster cluster = null; if (config != null && context != null) { String clusterName = context.getCluster(); if (clusterName != null) { List<NamedCluster> clusters = config.getClusters(); if (clusters != null) { cluster = clusters.stream() .filter(c -> c.getName().equals(clusterName)) .findAny() .map(NamedCluster::getCluster) .orElse(null); } } } return cluster; } private  KubeConfigUtils(); static Config parseConfig(File file); static Config parseConfigFromString(String contents); static NamedContext getCurrentContext(Config config); static String getUserToken(Config config, Context context); static AuthInfo getUserAuthInfo(Config config, Context context); static Cluster getCluster(Config config, Context context); static int getNamedUserIndexFromConfig(Config config, String userName); static void persistKubeConfigIntoFile(Config kubeConfig, String kubeConfigPath); }
KubeConfigUtils { public static Cluster getCluster(Config config, Context context) { Cluster cluster = null; if (config != null && context != null) { String clusterName = context.getCluster(); if (clusterName != null) { List<NamedCluster> clusters = config.getClusters(); if (clusters != null) { cluster = clusters.stream() .filter(c -> c.getName().equals(clusterName)) .findAny() .map(NamedCluster::getCluster) .orElse(null); } } } return cluster; } private  KubeConfigUtils(); static Config parseConfig(File file); static Config parseConfigFromString(String contents); static NamedContext getCurrentContext(Config config); static String getUserToken(Config config, Context context); static AuthInfo getUserAuthInfo(Config config, Context context); static Cluster getCluster(Config config, Context context); static int getNamedUserIndexFromConfig(Config config, String userName); static void persistKubeConfigIntoFile(Config kubeConfig, String kubeConfigPath);  }