Class KubeConfig


  • public class KubeConfig
    extends Object
    Encapsulates KubeConfig data, its construction from Cluster data, and its output to Yaml. NOTE(craigatgoogle): This is a temporary stop-gap measure which will be replaced once the GKE API supports a server-side method for this functionality: b/120097899.
    • Method Detail

      • getContexts

        public com.google.common.collect.ImmutableList<Object> getContexts()
        Returns:
        This config's contexts.
      • getClusters

        public com.google.common.collect.ImmutableList<Object> getClusters()
        Returns:
        This config's clusters.
      • getUsers

        public com.google.common.collect.ImmutableList<Object> getUsers()
        Returns:
        This config's users.
      • getCurrentContext

        public String getCurrentContext()
        Returns:
        This config's current context.
      • toYaml

        public String toYaml()
                      throws IOException
        Write a Yaml dump of this KubeConfig's data to the specified Writer. NOTE(craigatgoogle): The logic here is taken directly from the `gcloud containers clutsers get-credentials` command's implementation: link.
        Returns:
        A string containing a Yaml dump of this KubeConfig.
        Throws:
        IOException - If an error was encountered while exporting to Yaml.
      • fromCluster

        public static KubeConfig fromCluster​(String projectId,
                                             com.google.api.services.container.model.Cluster cluster,
                                             String accessToken)
        Creates a KubeConfig from the specified Cluster.
        Parameters:
        projectId - The ID of the project the cluster resides in.
        cluster - The cluster data will be drawn from.
        accessToken - Access token for GKE API access.
        Returns:
        A KubeConfig from the specified Cluster.