From bb03307b9e0e7cfd58b92974ca0564d764b539dc Mon Sep 17 00:00:00 2001 From: pb Date: Fri, 4 Apr 2025 18:01:14 +0200 Subject: [PATCH] corrected how the kubeconfig info are stored in /admiralty/kubeconfig (POST) --- controllers/admiralty.go | 4 ++-- models/kubeconfig.go | 44 ++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/controllers/admiralty.go b/controllers/admiralty.go index c3acb21..5574ac0 100644 --- a/controllers/admiralty.go +++ b/controllers/admiralty.go @@ -484,7 +484,7 @@ func (c *AdmiraltyController) GetAdmiraltyKubeconfig() { return } - b, err := yaml.Marshal(kubeconfig) + b, err := json.Marshal(kubeconfig) if err != nil { fmt.Println("Error while marshalling kubeconfig") c.Ctx.Output.SetStatus(500) @@ -517,7 +517,7 @@ func NewHostKubeWithToken(token string) (*models.KubeConfigValue, error){ { Name: "default", Cluster: models.KubeconfigCluster{ - Server: conf.GetConfig().KubeHost, + Server: "https://" + conf.GetConfig().KubeHost + ":6443", CertificateAuthorityData: encodedCA, }, }, diff --git a/models/kubeconfig.go b/models/kubeconfig.go index 5c1d652..3a14a83 100644 --- a/models/kubeconfig.go +++ b/models/kubeconfig.go @@ -2,55 +2,55 @@ package models // KubeConfigValue is a struct used to create a kubectl configuration YAML file. type KubeConfigValue struct { - APIVersion string `yaml:"apiVersion"` - Kind string `yaml:"kind"` - Clusters []KubeconfigNamedCluster `yaml:"clusters"` - Users []KubeconfigUser `yaml:"users"` - Contexts []KubeconfigNamedContext `yaml:"contexts"` - CurrentContext string `yaml:"current-context"` - Preferences struct{} `yaml:"preferences"` + APIVersion string `yaml:"apiVersion" json:"apiVersion"` + Kind string `yaml:"kind" json:"kind"` + Clusters []KubeconfigNamedCluster `yaml:"clusters" json:"clusters"` + Users []KubeconfigUser `yaml:"users" json:"users"` + Contexts []KubeconfigNamedContext `yaml:"contexts" json:"contexts"` + CurrentContext string `yaml:"current-context" json:"current-context"` + Preferences struct{} `yaml:"preferences" json:"preferences"` } // KubeconfigUser is a struct used to create a kubectl configuration YAML file type KubeconfigUser struct { - Name string `yaml:"name"` - User KubeconfigUserKeyPair `yaml:"user"` + Name string `yaml:"name" json:"name"` + User KubeconfigUserKeyPair `yaml:"user" json:"user"` } // KubeconfigUserKeyPair is a struct used to create a kubectl configuration YAML file type KubeconfigUserKeyPair struct { - Token string `yaml:"token"` + Token string `yaml:"token" json:"token"` } // KubeconfigAuthProvider is a struct used to create a kubectl authentication provider type KubeconfigAuthProvider struct { - Name string `yaml:"name"` - Config map[string]string `yaml:"config"` + Name string `yaml:"name" json:"name"` + Config map[string]string `yaml:"config" json:"config"` } // KubeconfigNamedCluster is a struct used to create a kubectl configuration YAML file type KubeconfigNamedCluster struct { - Name string `yaml:"name"` - Cluster KubeconfigCluster `yaml:"cluster"` + Name string `yaml:"name" json:"name"` + Cluster KubeconfigCluster `yaml:"cluster" json:"cluster"` } // KubeconfigCluster is a struct used to create a kubectl configuration YAML file type KubeconfigCluster struct { - Server string `yaml:"server"` - CertificateAuthorityData string `yaml:"certificate-authority-data"` - CertificateAuthority string `yaml:"certificate-authority"` + Server string `yaml:"server" json:"server"` + CertificateAuthorityData string `yaml:"certificate-authority-data" json:"certificate-authority-data"` + CertificateAuthority string `yaml:"certificate-authority" json:"certificate-authority"` } // KubeconfigNamedContext is a struct used to create a kubectl configuration YAML file type KubeconfigNamedContext struct { - Name string `yaml:"name"` - Context KubeconfigContext `yaml:"context"` + Name string `yaml:"name" json:"name"` + Context KubeconfigContext `yaml:"context" json:"context"` } // KubeconfigContext is a struct used to create a kubectl configuration YAML file type KubeconfigContext struct { - Cluster string `yaml:"cluster"` - Namespace string `yaml:"namespace,omitempty"` - User string `yaml:"user"` + Cluster string `yaml:"cluster" json:"cluster"` + Namespace string `yaml:"namespace,omitempty" json:"namespace,omitempty"` + User string `yaml:"user" json:"user"` } \ No newline at end of file