github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/examples/container/download_config/main.go (about)

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"log"
     7  	"os"
     8  
     9  	v2 "github.com/IBM-Cloud/bluemix-go/api/container/containerv2"
    10  	"github.com/IBM-Cloud/bluemix-go/session"
    11  	"github.com/IBM-Cloud/bluemix-go/trace"
    12  )
    13  
    14  func main() {
    15  	var clusterName string
    16  	flag.StringVar(&clusterName, "clustername", "", "The cluster whose config will be downloaded")
    17  
    18  	var path string
    19  	flag.StringVar(&path, "path", "", "The Path where the config will be downloaded")
    20  
    21  	var resourceGroup string
    22  	flag.StringVar(&resourceGroup, "resourcegroup", "", "ResourceGroup where the cluster is deployed")
    23  
    24  	var endpointType string
    25  	flag.StringVar(&endpointType, "endpoint", "", "Endpoint defines how the kubeconfig will connect to the cluster. Can be public, private and vpe in case of VPC")
    26  
    27  	var admin bool
    28  	flag.BoolVar(&admin, "admin", false, "If true download the admin config")
    29  
    30  	var network bool
    31  	flag.BoolVar(&network, "network", false, "If true download the calico network config")
    32  
    33  	flag.Parse()
    34  	trace.Logger = trace.NewLogger("true")
    35  	if clusterName == "" || path == "" {
    36  		flag.Usage()
    37  		os.Exit(1)
    38  	}
    39  	sess, err := session.New()
    40  	if err != nil {
    41  		log.Fatal(err)
    42  	}
    43  	target := v2.ClusterTargetHeader{
    44  		ResourceGroup: resourceGroup,
    45  	}
    46  	clusterClient, err := v2.New(sess)
    47  	if err != nil {
    48  		log.Fatal(err)
    49  	}
    50  	clustersAPI := clusterClient.Clusters()
    51  
    52  	if network {
    53  		kubeConfig, configPath, err := clustersAPI.StoreConfigDetail(clusterName, path, admin, network, target, endpointType)
    54  		if err != nil {
    55  			log.Fatal(err)
    56  		}
    57  		fmt.Println(kubeConfig, configPath.FilePath)
    58  	} else {
    59  		configPath, err := clustersAPI.GetClusterConfigDetail(clusterName, path, admin, target, endpointType)
    60  		if err != nil {
    61  			log.Fatal(err)
    62  		}
    63  		fmt.Println(configPath.FilePath)
    64  	}
    65  }