Created
August 21, 2018 07:47
-
-
Save akash-gautam/ec63c81d0061a0794e0875a4e51bd2d4 to your computer and use it in GitHub Desktop.
register.go contains the function which creates a client which is aware of our crd
This file contains 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 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