Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created June 11, 2020 07:25
Show Gist options
  • Save velotiotech/44dccc9f33968e7e3b95f7f6bfcec44f to your computer and use it in GitHub Desktop.
Save velotiotech/44dccc9f33968e7e3b95f7f6bfcec44f to your computer and use it in GitHub Desktop.
register.go contains the function which creates a client which is aware of our crd
package v1alpha1
import (
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/rest"
)
var SchemeGroupVersion = schema.GroupVersion{Group: CRDGroup, Version: CRDVersion}
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&SslConfig{},
&SslConfigList{},
)
meta_v1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
func NewClient(cfg *rest.Config) (*SslConfigV1Alpha1Client, error) {
scheme := runtime.NewScheme()
SchemeBuilder := runtime.NewSchemeBuilder(addKnownTypes)
if err := SchemeBuilder.AddToScheme(scheme); err != nil {
return nil, err
}
config := *cfg
config.GroupVersion = &SchemeGroupVersion
config.APIPath = "/apis"
config.ContentType = runtime.ContentTypeJSON
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: serializer.NewCodecFactory(scheme)}
client, err := rest.RESTClientFor(&config)
if err != nil {
return nil, err
}
return &SslConfigV1Alpha1Client{restClient: client}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment