Last active
October 15, 2020 01:58
-
-
Save stevenctl/371c5c67351124659fc7eaf0df0efc5a to your computer and use it in GitHub Desktop.
Istio Kubeconfig Extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"encoding/json" | |
"istio.io/istio/pkg/kube" | |
"k8s.io/apimachinery/pkg/runtime" | |
) | |
/* | |
Kubeconfig contains something like: | |
apiVersion: v1 | |
extensions: | |
- name: istio | |
extension: | |
types: | |
- config | |
- secret | |
network: nw1 | |
*/ | |
const Kubeconfig = "/Users/landow/kubeconf/kind-istio-testing.yaml" | |
type IstioKubeconfigType string | |
const ( | |
Config IstioKubeconfigType = "config" | |
Secret = "secret" | |
) | |
type IstioKubeconfigExtension struct { | |
Network string `json:"network"` | |
Types []IstioKubeconfigType `json:"types"` | |
} | |
func main() { | |
clientConfig := kube.BuildClientCmd(Kubeconfig, "") | |
rawConfig, err := clientConfig.RawConfig() | |
if err != nil { | |
panic(err) | |
} | |
ext := rawConfig.Clusters["kind-istio-testing"].Extensions["istio"] | |
if ext == nil { | |
panic("istio extension not found") | |
} | |
istioExt := IstioKubeconfigExtension{} | |
if err := json.Unmarshal(ext.(*runtime.Unknown).Raw, &istioExt); err != nil { | |
panic(err) | |
} | |
fmt.Println(istioExt) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment