Class KubeConfigUtils


  • public class KubeConfigUtils
    extends Object
    Helper class for working with the YAML config file thats located in ~/.kube/config which is updated when you use commands like osc login and osc project myproject
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static io.fabric8.kubernetes.api.model.Cluster getCluster​(io.fabric8.kubernetes.api.model.Config config, io.fabric8.kubernetes.api.model.Context context)
      Returns the current Cluster for the current context
      static io.fabric8.kubernetes.api.model.NamedContext getCurrentContext​(io.fabric8.kubernetes.api.model.Config config)
      Returns the current context in the given config
      static int getNamedUserIndexFromConfig​(io.fabric8.kubernetes.api.model.Config config, String userName)
      Get User index from Config object
      static io.fabric8.kubernetes.api.model.AuthInfo getUserAuthInfo​(io.fabric8.kubernetes.api.model.Config config, io.fabric8.kubernetes.api.model.Context context)
      Returns the current AuthInfo for the current context and user
      static String getUserToken​(io.fabric8.kubernetes.api.model.Config config, io.fabric8.kubernetes.api.model.Context context)
      Returns the current user token for the config and current context
      static io.fabric8.kubernetes.api.model.Config parseConfig​(File file)  
      static io.fabric8.kubernetes.api.model.Config parseConfigFromString​(String contents)  
      static void persistKubeConfigIntoFile​(io.fabric8.kubernetes.api.model.Config kubeConfig, String kubeConfigPath)
      Modify KUBECONFIG file
    • Method Detail

      • parseConfig

        public static io.fabric8.kubernetes.api.model.Config parseConfig​(File file)
                                                                  throws IOException
        Throws:
        IOException
      • parseConfigFromString

        public static io.fabric8.kubernetes.api.model.Config parseConfigFromString​(String contents)
                                                                            throws IOException
        Throws:
        IOException
      • getCurrentContext

        public static io.fabric8.kubernetes.api.model.NamedContext getCurrentContext​(io.fabric8.kubernetes.api.model.Config config)
        Returns the current context in the given config
        Parameters:
        config - Config object
        Returns:
        returns context in config if found, otherwise null
      • getUserToken

        public static String getUserToken​(io.fabric8.kubernetes.api.model.Config config,
                                          io.fabric8.kubernetes.api.model.Context context)
        Returns the current user token for the config and current context
        Parameters:
        config - Config object
        context - Context object
        Returns:
        returns current user based upon provided parameters.
      • getUserAuthInfo

        public static io.fabric8.kubernetes.api.model.AuthInfo getUserAuthInfo​(io.fabric8.kubernetes.api.model.Config config,
                                                                               io.fabric8.kubernetes.api.model.Context context)
        Returns the current AuthInfo for the current context and user
        Parameters:
        config - Config object
        context - Context object
        Returns:
        AuthInfo for current context
      • getCluster

        public static io.fabric8.kubernetes.api.model.Cluster getCluster​(io.fabric8.kubernetes.api.model.Config config,
                                                                         io.fabric8.kubernetes.api.model.Context context)
        Returns the current Cluster for the current context
        Parameters:
        config - Config config object
        context - Context context object
        Returns:
        current Cluster for current context
      • getNamedUserIndexFromConfig

        public static int getNamedUserIndexFromConfig​(io.fabric8.kubernetes.api.model.Config config,
                                                      String userName)
        Get User index from Config object
        Parameters:
        config - Config Kube Config
        userName - username inside Config
        Returns:
        index of user in users array
      • persistKubeConfigIntoFile

        public static void persistKubeConfigIntoFile​(io.fabric8.kubernetes.api.model.Config kubeConfig,
                                                     String kubeConfigPath)
                                              throws IOException
        Modify KUBECONFIG file
        Parameters:
        kubeConfig - modified Config object
        kubeConfigPath - path to KUBECONFIG
        Throws:
        IOException - in case of failure while writing to file