-
Notifications
You must be signed in to change notification settings - Fork 22
/
create.go
37 lines (30 loc) · 903 Bytes
/
create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package crd
import (
"context"
"github.com/ibuildthecloud/klum/pkg/apis/klum.cattle.io/v1alpha1"
"github.com/rancher/wrangler/pkg/schemas/openapi"
"github.com/rancher/wrangler/pkg/crd"
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/client-go/rest"
)
func Create(ctx context.Context, config *rest.Config) error {
factory, err := crd.NewFactoryFromClient(config)
if err != nil {
return err
}
return factory.BatchCreateCRDs(ctx,
newCRD("User.klum.cattle.io/v1alpha1", v1alpha1.User{}),
newCRD("Kubeconfig.klum.cattle.io/v1alpha1", v1alpha1.Kubeconfig{})).BatchWait()
}
func newCRD(name string, obj interface{}) crd.CRD {
return crd.NonNamespacedType(name).
WithStatus().
WithSchema(mustSchema(obj))
}
func mustSchema(obj interface{}) *v1.JSONSchemaProps {
result, err := openapi.ToOpenAPIFromStruct(obj)
if err != nil {
panic(err)
}
return result
}