func do(o options) error {
	// Refresh credentials if requested
	if o.getClientCert {
		if err := getCredentials(o); err != nil {
			return fmt.Errorf("get client cert: %v", err)
		}
	}
	// Create the new cluster entry
	d, err := describeCluster(o)
	if err != nil {
		return fmt.Errorf("describe auth: %v", err)
	}
	newCluster := kube.Cluster{
		Endpoint:             "https://" + d.Endpoint,
		ClusterCACertificate: d.Auth.ClusterCACertificate,
		ClientKey:            d.Auth.ClientKey,
		ClientCertificate:    d.Auth.ClientCertificate,
	}

	// Try to use this entry
	if !o.skipCheck {
		c, err := kube.NewClient(&newCluster, "kube-system")
		if err != nil {
			return fmt.Errorf("create client: %v", err)
		}
		if _, err = c.ListPods("k8s-app=kube-dns"); err != nil {
			logrus.WithError(err).Errorf("Failed to validate credentials (consider --get-client-cert)")
			return fmt.Errorf("list all pods to check new credentials: %v", err)
		}
	}

	// Just print this entry if requested
	if o.printEntry {
		data, err := kube.MarshalClusterMap(map[string]kube.Cluster{o.alias: newCluster})
		if err != nil {
			return fmt.Errorf("marshal %s: %v", o.alias, err)
		}
		fmt.Println(string(data))
		return nil
	}

	// Append the new entry to the current secret

	// First read in the secret from stdin
	b, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		return fmt.Errorf("read stdin: %v", err)
	}
	var s coreapi.Secret
	if err := yaml.Unmarshal(b, &s); err != nil {
		return fmt.Errorf("unmarshal stdin: %v", err)
	}

	// Now decode the {alias: cluster} map and print out current keys
	clusters, err := kube.UnmarshalClusterMap(s.Data["cluster"])
	if err != nil {
		return fmt.Errorf("unmarshal secret: %v", err)
	}
	var existing []string
	for a := range clusters {
		existing = append(existing, a)
	}
	logrus.Infof("Existing clusters: %s", strings.Join(existing, ", "))

	// Add new key
	_, ok := clusters[o.alias]
	if ok && !o.overwrite {
		return fmt.Errorf("cluster %s already exists", o.alias)
	}
	clusters[o.alias] = newCluster
	logrus.Infof("New cluster: %s", o.alias)

	// Marshal the {alias: cluster} map back into secret data
	data, err := kube.MarshalClusterMap(clusters)
	if err != nil {
		return fmt.Errorf("marshal clusters: %v", err)
	}

	if o.printData { // Just print the data outside of the secret
		fmt.Println(string(data))
		return nil
	}

	// Output the new secret
	s.Data["cluster"] = data
	buf, err := yaml.Marshal(s)
	if err != nil {
		return fmt.Errorf("marshal secret: %v", err)
	}
	fmt.Println(string(buf))
	return nil
}
func do(o options) error {
	
	if o.getClientCert {
		if err := getCredentials(o); err != nil {
			return fmt.Errorf("get client cert: %v", err)
		}
	}
	
	d, err := describeCluster(o)
	if err != nil {
		return fmt.Errorf("describe auth: %v", err)
	}
	newCluster := kube.Cluster{
		Endpoint:             "https:
		ClusterCACertificate: d.Auth.ClusterCACertificate,
		ClientKey:            d.Auth.ClientKey,
		ClientCertificate:    d.Auth.ClientCertificate,
	}

	
	if !o.skipCheck {
		c, err := kube.NewClient(&newCluster, "kube-system")
		if err != nil {
			return fmt.Errorf("create client: %v", err)
		}
		if _, err = c.ListPods("k8s-app=kube-dns"); err != nil {
			logrus.WithError(err).Errorf("Failed to validate credentials (consider --get-client-cert)")
			return fmt.Errorf("list all pods to check new credentials: %v", err)
		}
	}

	
	if o.printEntry {
		data, err := kube.MarshalClusterMap(map[string]kube.Cluster{o.alias: newCluster})
		if err != nil {
			return fmt.Errorf("marshal %s: %v", o.alias, err)
		}
		fmt.Println(string(data))
		return nil
	}

	

	
	b, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		return fmt.Errorf("read stdin: %v", err)
	}
	var s coreapi.Secret
	if err := yaml.Unmarshal(b, &s); err != nil {
		return fmt.Errorf("unmarshal stdin: %v", err)
	}

	
	clusters, err := kube.UnmarshalClusterMap(s.Data["cluster"])
	if err != nil {
		return fmt.Errorf("unmarshal secret: %v", err)
	}
	var existing []string
	for a := range clusters {
		existing = append(existing, a)
	}
	logrus.Infof("Existing clusters: %s", strings.Join(existing, ", "))

	
	_, ok := clusters[o.alias]
	if ok && !o.overwrite {
		return fmt.Errorf("cluster %s already exists", o.alias)
	}
	clusters[o.alias] = newCluster
	logrus.Infof("New cluster: %s", o.alias)

	
	data, err := kube.MarshalClusterMap(clusters)
	if err != nil {
		return fmt.Errorf("marshal clusters: %v", err)
	}

	if o.printData { 
		fmt.Println(string(data))
		return nil
	}

	
	s.Data["cluster"] = data
	buf, err := yaml.Marshal(s)
	if err != nil {
		return fmt.Errorf("marshal secret: %v", err)
	}
	fmt.Println(string(buf))
	return nil
}
func do ( o options ) error { // Refresh credentials if requested if o . getClientCert { if err := getCredentials ( o ) ; err != nil { return fmt . Errorf ( " " , err ) } } // Create the new cluster entry d , err := describeCluster ( o ) if err != nil { return fmt . Errorf ( " " , err ) } newCluster := kube . Cluster { Endpoint : " " + d . Endpoint , ClusterCACertificate : d . Auth . ClusterCACertificate , ClientKey : d . Auth . ClientKey , ClientCertificate : d . Auth . ClientCertificate , } // Try to use this entry if ! o . skipCheck { c , err := kube . NewClient ( & newCluster , " " ) if err != nil { return fmt . Errorf ( " " , err ) } if _ , err = c . ListPods ( " " ) ; err != nil { logrus . WithError ( err ) . Errorf ( " " ) return fmt . Errorf ( " " , err ) } } // Just print this entry if requested if o . printEntry { data , err := kube . MarshalClusterMap ( map [ string ] kube . Cluster { o . alias : newCluster } ) if err != nil { return fmt . Errorf ( " " , o . alias , err ) } fmt . Println ( string ( data ) ) return nil } // Append the new entry to the current secret // First read in the secret from stdin b , err := ioutil . ReadAll ( os . Stdin ) if err != nil { return fmt . Errorf ( " " , err ) } var s coreapi . Secret if err := yaml . Unmarshal ( b , & s ) ; err != nil { return fmt . Errorf ( " " , err ) } // Now decode the {alias: cluster} map and print out current keys clusters , err := kube . UnmarshalClusterMap ( s . Data [ " " ] ) if err != nil { return fmt . Errorf ( " " , err ) } var existing [ ] string for a := range clusters { existing = append ( existing , a ) } logrus . Infof ( " " , strings . Join ( existing , " " ) ) // Add new key _ , ok := clusters [ o . alias ] if ok && ! o . overwrite { return fmt . Errorf ( " " , o . alias ) } clusters [ o . alias ] = newCluster logrus . Infof ( " " , o . alias ) // Marshal the {alias: cluster} map back into secret data data , err := kube . MarshalClusterMap ( clusters ) if err != nil { return fmt . Errorf ( " " , err ) } if o . printData { // Just print the data outside of the secret fmt . Println ( string ( data ) ) return nil } // Output the new secret s . Data [ " " ] = data buf , err := yaml . Marshal ( s ) if err != nil { return fmt . Errorf ( " " , err ) } fmt . Println ( string ( buf ) ) return nil }
// do will get creds for the specified cluster and add them to the stdin secret
do will get creds for the specified cluster and add them to the stdin secret