KubeConfigUtils { public static NamedContext getCurrentContext(Config config) { String contextName = config.getCurrentContext(); if (contextName != null) { List<NamedContext> contexts = config.getContexts(); if (contexts != null) { for (NamedContext context : contexts) { if (contextName.equals(context.getName())) { return context; } } } } return null; } 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);  }
@Test void testGetCurrentContext() { Config config = getTestKubeConfig(); NamedContext namedContext = KubeConfigUtils.getCurrentContext(config); assertNotNull(namedContext); assertEquals("test-context", namedContext.getName()); assertEquals("ns1", namedContext.getContext().getNamespace()); assertEquals("system:admin/api-testing:6334", namedContext.getContext().getUser()); assertEquals("api-testing:6334", namedContext.getContext().getCluster()); }