Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Switch to structural CRD schema #29

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Switch to structural schema for CRDs
CRDs are GA in Kubernetes 1.16

* Update k8s.io/apiextensions to v1
* PreserveUnknownFields is specified on individual fields
Mario Manno committed Feb 18, 2020
commit 1168643e81bcf2a68dfb737b88b2f437fd3225d6
19 changes: 9 additions & 10 deletions pkg/crd/crd.go
Original file line number Diff line number Diff line change
@@ -4,18 +4,18 @@ import (
"reflect"
"time"

"code.cloudfoundry.org/quarks-utils/pkg/pointers"
"github.com/pkg/errors"
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
extv1client "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1"

extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
extv1client "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/wait"
)

// ApplyCRD creates or updates the CRD
func ApplyCRD(client extv1client.ApiextensionsV1beta1Interface, crdName, kind, plural string, shortNames []string, groupVersion schema.GroupVersion, validation *extv1.CustomResourceValidation) error {
func ApplyCRD(client extv1client.ApiextensionsV1Interface, crdName, kind, plural string, shortNames []string, groupVersion schema.GroupVersion, validation *extv1.CustomResourceValidation) error {
crd := &extv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdName,
@@ -27,13 +27,12 @@ func ApplyCRD(client extv1client.ApiextensionsV1beta1Interface, crdName, kind, p
Name: groupVersion.Version,
Served: true,
Storage: true,
Schema: validation,
Subresources: &extv1.CustomResourceSubresources{
Status: &extv1.CustomResourceSubresourceStatus{},
},
},
},
Validation: validation,
PreserveUnknownFields: pointers.Bool(false),
Subresources: &extv1.CustomResourceSubresources{
Status: &extv1.CustomResourceSubresourceStatus{},
},
Scope: extv1.NamespaceScoped,
Names: extv1.CustomResourceDefinitionNames{
Kind: kind,
@@ -67,7 +66,7 @@ func ApplyCRD(client extv1client.ApiextensionsV1beta1Interface, crdName, kind, p
}

// WaitForCRDReady blocks until the CRD is ready.
func WaitForCRDReady(client extv1client.ApiextensionsV1beta1Interface, crdName string) error {
func WaitForCRDReady(client extv1client.ApiextensionsV1Interface, crdName string) error {
err := wait.ExponentialBackoff(
wait.Backoff{
Duration: time.Second,