Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Commit

Permalink
Generate proto file for KubeConfig (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalsaha committed Dec 18, 2017
1 parent cfb56ef commit 830e7e3
Show file tree
Hide file tree
Showing 14 changed files with 1,748 additions and 427 deletions.
1,657 changes: 1,345 additions & 312 deletions apis/v1alpha1/generated.pb.go

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions apis/v1alpha1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 107 additions & 0 deletions apis/v1alpha1/kubeconfig.go
@@ -0,0 +1,107 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)

// Config holds the information needed to build connect to remote kubernetes clusters as a given user
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type KubeConfig struct {
metav1.TypeMeta `json:",inline,omitempty,omitempty"`
// Preferences holds general information to be use for cli interactions
Preferences Preferences `json:"preferences" protobuf:"bytes,1,opt,name=preferences"`
// Clusters is a map of referencable names to cluster configs
Cluster NamedCluster `json:"cluster" protobuf:"bytes,2,opt,name=cluster"`
// AuthInfos is a map of referencable names to user configs
AuthInfo NamedAuthInfo `json:"user" protobuf:"bytes,3,opt,name=user"`
// Contexts is a map of referencable names to context configs
Context NamedContext `json:"context" protobuf:"bytes,4,opt,name=context"`
}

type Preferences struct {
// +optional
Colors bool `json:"colors,omitempty" protobuf:"varint,1,opt,name=colors"`
}

// NamedCluster relates nicknames to cluster information
type NamedCluster struct {
// Name is the nickname for this Cluster
Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
// Server is the address of the kubernetes cluster (https://hostname:port).
Server string `json:"server" protobuf:"bytes,2,opt,name=server"`
// CertificateAuthorityData contains PEM-encoded certificate authority certificates. Overrides CertificateAuthorityData
// +optional
CertificateAuthorityData []byte `json:"certificateAuthorityData,omitempty" protobuf:"bytes,3,opt,name=certificateAuthorityData"`
}

// NamedContext relates nicknames to context information
type NamedContext struct {
// Name is the nickname for this Context
Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
// Cluster is the name of the cluster for this context
Cluster string `json:"cluster" protobuf:"bytes,2,opt,name=cluster"`
// AuthInfo is the name of the authInfo for this context
AuthInfo string `json:"user" protobuf:"bytes,3,opt,name=user"`
}

// NamedAuthInfo relates nicknames to auth information
type NamedAuthInfo struct {
// Name is the nickname for this AuthInfo
Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
// ClientCertificateData contains PEM-encoded data from a client cert file for TLS.
// +optional
ClientCertificateData []byte `json:"clientCertificateData,omitempty" protobuf:"bytes,2,opt,name=clientCertificateData"`
// ClientKeyData contains PEM-encoded data from a client key file for TLS.
// +optional
ClientKeyData []byte `json:"clientKeyData,omitempty" protobuf:"bytes,3,opt,name=clientKeyData"`
// Token is the bearer token for authentication to the kubernetes cluster.
// +optional
Token string `json:"token,omitempty" protobuf:"bytes,4,opt,name=token"`
}

func Convert_KubeConfig_To_Config(in *KubeConfig) *clientcmdapi.Config {
return &clientcmdapi.Config{
Kind: "Config",
APIVersion: clientcmdapi.SchemeGroupVersion.String(),
Preferences: clientcmdapi.Preferences{
Colors: in.Preferences.Colors,
},
Clusters: map[string]*clientcmdapi.Cluster{
in.Cluster.Name: {
CertificateAuthorityData: append([]byte(nil), in.Cluster.CertificateAuthorityData...),
},
},
AuthInfos: map[string]*clientcmdapi.AuthInfo{
in.AuthInfo.Name: {
Token: in.AuthInfo.Token,
ClientCertificateData: append([]byte(nil), in.AuthInfo.ClientCertificateData...),
ClientKeyData: append([]byte(nil), in.AuthInfo.ClientKeyData...),
},
},
Contexts: map[string]*clientcmdapi.Context{
in.Context.Name: {
Cluster: in.Context.Cluster,
AuthInfo: in.Context.AuthInfo,
},
},
CurrentContext: in.Context.Name,
}
}

func NewRestConfig(in *KubeConfig) *rest.Config {
out := &rest.Config{
Host: in.Cluster.Server,
TLSClientConfig: rest.TLSClientConfig{
CAData: append([]byte(nil), in.Cluster.CertificateAuthorityData...),
},
}
if in.AuthInfo.Token == "" {
out.TLSClientConfig.CertData = append([]byte(nil), in.AuthInfo.ClientCertificateData...)
out.TLSClientConfig.KeyData = append([]byte(nil), in.AuthInfo.ClientKeyData...)
} else {
out.BearerToken = in.AuthInfo.Token
}
return out
}
129 changes: 129 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go
Expand Up @@ -105,6 +105,10 @@ func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
in.(*GoogleSpec).DeepCopyInto(out.(*GoogleSpec))
return nil
}, InType: reflect.TypeOf(&GoogleSpec{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*KubeConfig).DeepCopyInto(out.(*KubeConfig))
return nil
}, InType: reflect.TypeOf(&KubeConfig{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*LightsailCloudConfig).DeepCopyInto(out.(*LightsailCloudConfig))
return nil
Expand All @@ -121,6 +125,18 @@ func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
in.(*LocalSpec).DeepCopyInto(out.(*LocalSpec))
return nil
}, InType: reflect.TypeOf(&LocalSpec{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*NamedAuthInfo).DeepCopyInto(out.(*NamedAuthInfo))
return nil
}, InType: reflect.TypeOf(&NamedAuthInfo{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*NamedCluster).DeepCopyInto(out.(*NamedCluster))
return nil
}, InType: reflect.TypeOf(&NamedCluster{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*NamedContext).DeepCopyInto(out.(*NamedContext))
return nil
}, InType: reflect.TypeOf(&NamedContext{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Networking).DeepCopyInto(out.(*Networking))
return nil
Expand Down Expand Up @@ -169,6 +185,10 @@ func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
in.(*PostgresSpec).DeepCopyInto(out.(*PostgresSpec))
return nil
}, InType: reflect.TypeOf(&PostgresSpec{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Preferences).DeepCopyInto(out.(*Preferences))
return nil
}, InType: reflect.TypeOf(&Preferences{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*ReservedIP).DeepCopyInto(out.(*ReservedIP))
return nil
Expand Down Expand Up @@ -657,6 +677,36 @@ func (in *GoogleSpec) DeepCopy() *GoogleSpec {
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *KubeConfig) DeepCopyInto(out *KubeConfig) {
*out = *in
out.TypeMeta = in.TypeMeta
out.Preferences = in.Preferences
in.Cluster.DeepCopyInto(&out.Cluster)
in.AuthInfo.DeepCopyInto(&out.AuthInfo)
out.Context = in.Context
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KubeConfig.
func (in *KubeConfig) DeepCopy() *KubeConfig {
if in == nil {
return nil
}
out := new(KubeConfig)
in.DeepCopyInto(out)
return out
}

// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *KubeConfig) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *LightsailCloudConfig) DeepCopyInto(out *LightsailCloudConfig) {
*out = *in
Expand Down Expand Up @@ -721,6 +771,69 @@ func (in *LocalSpec) DeepCopy() *LocalSpec {
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NamedAuthInfo) DeepCopyInto(out *NamedAuthInfo) {
*out = *in
if in.ClientCertificateData != nil {
in, out := &in.ClientCertificateData, &out.ClientCertificateData
*out = make([]byte, len(*in))
copy(*out, *in)
}
if in.ClientKeyData != nil {
in, out := &in.ClientKeyData, &out.ClientKeyData
*out = make([]byte, len(*in))
copy(*out, *in)
}
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NamedAuthInfo.
func (in *NamedAuthInfo) DeepCopy() *NamedAuthInfo {
if in == nil {
return nil
}
out := new(NamedAuthInfo)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NamedCluster) DeepCopyInto(out *NamedCluster) {
*out = *in
if in.CertificateAuthorityData != nil {
in, out := &in.CertificateAuthorityData, &out.CertificateAuthorityData
*out = make([]byte, len(*in))
copy(*out, *in)
}
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NamedCluster.
func (in *NamedCluster) DeepCopy() *NamedCluster {
if in == nil {
return nil
}
out := new(NamedCluster)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NamedContext) DeepCopyInto(out *NamedContext) {
*out = *in
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NamedContext.
func (in *NamedContext) DeepCopy() *NamedContext {
if in == nil {
return nil
}
out := new(NamedContext)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Networking) DeepCopyInto(out *Networking) {
*out = *in
Expand Down Expand Up @@ -963,6 +1076,22 @@ func (in *PostgresSpec) DeepCopy() *PostgresSpec {
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Preferences) DeepCopyInto(out *Preferences) {
*out = *in
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Preferences.
func (in *Preferences) DeepCopy() *Preferences {
if in == nil {
return nil
}
out := new(Preferences)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ReservedIP) DeepCopyInto(out *ReservedIP) {
*out = *in
Expand Down

0 comments on commit 830e7e3

Please sign in to comment.