Created
August 21, 2018 07:40
-
-
Save akash-gautam/05e5220b3b5744c69f9bdeb808af41bf to your computer and use it in GitHub Desktop.
createcrd.go contains the function which creates the custom resource definition for our object
This file contains hidden or 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 ( | |
"reflect" | |
apiextensionv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" | |
apiextension "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" | |
apierrors "k8s.io/apimachinery/pkg/api/errors" | |
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | |
) | |
const ( | |
CRDPlural string = "sslconfigs" | |
CRDGroup string = "blog.velotio.com" | |
CRDVersion string = "v1alpha1" | |
FullCRDName string = CRDPlural + "." + CRDGroup | |
) | |
func CreateCRD(clientset apiextension.Interface) error { | |
crd := &apiextensionv1beta1.CustomResourceDefinition{ | |
ObjectMeta: meta_v1.ObjectMeta{Name: FullCRDName}, | |
Spec: apiextensionv1beta1.CustomResourceDefinitionSpec{ | |
Group: CRDGroup, | |
Version: CRDVersion, | |
Scope: apiextensionv1beta1.NamespaceScoped, | |
Names: apiextensionv1beta1.CustomResourceDefinitionNames{ | |
Plural: CRDPlural, | |
Kind: reflect.TypeOf(SslConfig{}).Name(), | |
}, | |
}, | |
} | |
_, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) | |
if err != nil && apierrors.IsAlreadyExists(err) { | |
return nil | |
} | |
return err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment