Created
June 11, 2020 07:24
-
-
Save velotiotech/cbdf87b529c406a63822c7d4f99a9f3b 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 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