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 Detail

      • parseConfig

        public static io.fabric8.kubernetes.api.model.Config parseConfig​(File kubeconfig)
      • parseConfigFromString

        public static io.fabric8.kubernetes.api.model.Config parseConfigFromString​(String contents)
      • persistKubeConfigIntoFile

        public static void persistKubeConfigIntoFile​(io.fabric8.kubernetes.api.model.Config kubeconfig,
                                                     File kubeConfigPath)
                                              throws IOException
        Persist KUBECONFIG file from the provided Config object.
        Parameters:
        kubeconfig - modified Config object.
        kubeConfigPath - path to KUBECONFIG.
        Throws:
        IOException - in case of failure while writing to file.
      • getFileWithNamedContext

        public static File getFileWithNamedContext​(io.fabric8.kubernetes.api.model.NamedContext namedContext)
        Returns the file containing the context information if it was loaded using KubeConfigUtils#parseConfig.
        Parameters:
        namedContext - the context to get the file from.
        Returns:
        the file containing the context information if it was loaded using KubeConfigUtils#parseConfig or null.
      • getFileWithNamedCluster

        public static File getFileWithNamedCluster​(io.fabric8.kubernetes.api.model.NamedContext namedContext)
        Returns the file containing the cluster information if it was loaded using KubeConfigUtils#parseConfig.
        Parameters:
        namedContext - the context to get the file from.
        Returns:
        the file containing the cluster information if it was loaded using KubeConfigUtils#parseConfig or null.
      • getFileWithNamedAuthInfo

        public static File getFileWithNamedAuthInfo​(io.fabric8.kubernetes.api.model.NamedContext namedContext)
        Returns the file containing the auth info information if it was loaded using KubeConfigUtils#parseConfig.
        Parameters:
        namedContext - the context to get the file from.
        Returns:
        the file containing the auth info information if it was loaded using KubeConfigUtils#parseConfig or null.
      • merge

        public static void merge​(Config clientConfig,
                                 String context,
                                 io.fabric8.kubernetes.api.model.Config... kubeconfigs)
        Merges the provided Config objects into the provided Config object.

        The following precedence is followed:

        1. Incomplete Contexts, Clusters, and Users are ignored
        2. Context argument provided by the user is used if provided and exists
        3. The first Config object to set a value wins
      • getExecCredentialFromExecConfig

        protected static Config.ExecCredential getExecCredentialFromExecConfig​(io.fabric8.kubernetes.api.model.ExecConfig exec,
                                                                               File configFile)
      • getAuthenticatorCommandFromExecConfig

        protected static List<String> getAuthenticatorCommandFromExecConfig​(io.fabric8.kubernetes.api.model.ExecConfig exec,
                                                                            File configFile,
                                                                            String systemPathValue)
      • findExecutable

        protected static String findExecutable​(String command,
                                               String pathValue)