add minikube labels to kubecontext extenions

pull/10126/head
Medya Gh 2021-01-11 13:36:11 -08:00
parent 79bcfde690
commit d8fdb5cf5b
1 changed files with 44 additions and 0 deletions

View File

@ -20,9 +20,11 @@ import (
"io/ioutil"
"path/filepath"
"sync/atomic"
"time"
"github.com/juju/mutex"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/clientcmd/api"
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/util/lock"
@ -83,6 +85,14 @@ func PopulateFromSettings(cfg *Settings, apiCfg *api.Config) error {
} else {
cluster.CertificateAuthority = cfg.CertificateAuthority
}
lastUpdate := time.Now().String()
ext := &internalExtension{
CreatedBy: "minikube.sigs.k8s.io",
LastUpdate: lastUpdate,
}
cluster.Extensions = map[string]runtime.Object{"cluster_info": ext.DeepCopy()}
apiCfg.Clusters[clusterName] = cluster
// user
@ -109,6 +119,7 @@ func PopulateFromSettings(cfg *Settings, apiCfg *api.Config) error {
context.Cluster = cfg.ClusterName
context.Namespace = cfg.Namespace
context.AuthInfo = userName
context.Extensions = map[string]runtime.Object{"context_info": ext.DeepCopy()}
apiCfg.Contexts[contextName] = context
// Only set current context to minikube if the user has not used the keepContext flag
@ -149,3 +160,36 @@ func Update(kcs *Settings) error {
}
return nil
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// implementing the runtime.Object internally so we can write extensions to kubeconfig
type internalExtension struct {
runtime.TypeMeta `json:",inline"`
CreatedBy string `json:"created_by"`
LastUpdate string `json:"last_update"`
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InternalSimple.
func (in *internalExtension) DeepCopy() *internalExtension {
if in == nil {
return nil
}
out := new(internalExtension)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *internalExtension) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *internalExtension) DeepCopyInto(out *internalExtension) {
*out = *in
out.TypeMeta = in.TypeMeta
return
}