IBM / cloud-operators

Provision and bind IBM Cloud services to your Kubernetes cluster in a Kubernetes-native way
Apache License 2.0
42 stars 33 forks source link

fix(crd): bump controller-gen to 0.4.1 #266

Closed greglanthier closed 2 years ago

greglanthier commented 2 years ago

Attempts to address comments in issue #258.

Our team uses this operator to manage connections to IBM Cloud hosted databases. We will be moving to OpenShift 4.9 / Kubernetes 1.22 in the near future and we would like to continue using this operator.

This Red Hat OpenShift blog post provides some recommendations on how to update existing operators to support the move to Kubernetes 1.22.

This PR bumps the controller-gen version to 0.4.1 and regenerates the CRDs using the apiextensions.k8s.io/v1 group.

This PR also does the following:

Signed-off-by: Greg Lanthier greg.lanthier@gmail.com

JohnStarich commented 2 years ago

After these tweaks to genolm:

diff --git a/internal/cmd/genolm/crd.go b/internal/cmd/genolm/crd.go
index 03e22e61..1ebda8c8 100644
--- a/internal/cmd/genolm/crd.go
+++ b/internal/cmd/genolm/crd.go
@@ -10,7 +10,7 @@ import (

    "github.com/ghodss/yaml"
    "github.com/pkg/errors"
-   apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
+   apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
 )

 type CRD struct {
@@ -41,7 +41,7 @@ type Descriptor struct {

 func getCRDs(repoRoot string) ([]CRD, error) {
    var crds []CRD
-   var bindingCRD apiextensionsv1beta1.CustomResourceDefinition
+   var bindingCRD apiextensionsv1.CustomResourceDefinition
    bindingCRDBytes, err := ioutil.ReadFile(filepath.Join(repoRoot, "out/apiextensions.k8s.io_v1_customresourcedefinition_bindings.ibmcloud.ibm.com.yaml")) // #nosec G304 repoRoot comes from user input
    if err != nil {
        return nil, errors.Wrap(err, "Error reading generated CRD file. Did kustomize run yet?")
@@ -55,15 +55,15 @@ func getCRDs(repoRoot string) ([]CRD, error) {
        []TypeMeta{
            {Kind: "Secret", Name: "", Version: "v1"},
            {Kind: "ConfigMap", Name: "", Version: "v1"},
-           {Kind: "Binding", Name: "", Version: "v1beta1"},
-           {Kind: "Service", Name: "", Version: "v1beta1"},
+           {Kind: "Binding", Name: "", Version: "v1"},
+           {Kind: "Service", Name: "", Version: "v1"},
        },
        map[string][]string{
            "secretName": {"urn:alm:descriptor:text", "urn:alm:descriptor:io.kubernetes:Secret", "binding:env:object:secret"},
        },
    ))

-   var serviceCRD apiextensionsv1beta1.CustomResourceDefinition
+   var serviceCRD apiextensionsv1.CustomResourceDefinition
    serviceCRDBytes, err := ioutil.ReadFile(filepath.Join(repoRoot, "out/apiextensions.k8s.io_v1_customresourcedefinition_services.ibmcloud.ibm.com.yaml")) // #nosec G304 repoRoot comes from user input
    if err != nil {
        return nil, errors.Wrap(err, "Error reading generated CRD file. Did kustomize run yet?")
@@ -77,8 +77,8 @@ func getCRDs(repoRoot string) ([]CRD, error) {
        []TypeMeta{
            {Kind: "Secret", Name: "", Version: "v1"},
            {Kind: "ConfigMap", Name: "", Version: "v1"},
-           {Kind: "Binding", Name: "", Version: "v1beta1"},
-           {Kind: "Service", Name: "", Version: "v1beta1"},
+           {Kind: "Binding", Name: "", Version: "v1"},
+           {Kind: "Service", Name: "", Version: "v1"},
        },
        map[string][]string{
            "secretName": {"urn:alm:descriptor:text", "urn:alm:descriptor:io.kubernetes:Secret", "binding:env:object:secret"},
@@ -87,7 +87,7 @@ func getCRDs(repoRoot string) ([]CRD, error) {
    return crds, nil
 }

-func NewCRD(src apiextensionsv1beta1.CustomResourceDefinition, ownedResources []TypeMeta, xDescriptors map[string][]string) CRD {
+func NewCRD(src apiextensionsv1.CustomResourceDefinition, ownedResources []TypeMeta, xDescriptors map[string][]string) CRD {
    if len(src.Spec.Versions) == 0 {
        panic(fmt.Sprintf("Versions section is empty: %#v", src.Spec))
    }
@@ -102,11 +102,11 @@ func NewCRD(src apiextensionsv1beta1.CustomResourceDefinition, ownedResources []
        OwnedResources:    ownedResources,
        SpecDescriptors:   descriptorsFor("spec", latestVersion, xDescriptors),
        StatusDescriptors: descriptorsFor("status", latestVersion, xDescriptors),
-       Version:           src.Spec.Version,
+       Version:           src.Spec.Versions[0].Name,
    }
 }

-func descriptorsFor(kind string, version apiextensionsv1beta1.CustomResourceDefinitionVersion, xDescriptors map[string][]string) []Descriptor {
+func descriptorsFor(kind string, version apiextensionsv1.CustomResourceDefinitionVersion, xDescriptors map[string][]string) []Descriptor {
    props := version.Schema.OpenAPIV3Schema.Properties[kind].Properties
    defaultXDescriptor := []string{"urn:alm:descriptor:text"}

And learning the new-new test deployment system for openshift (happens every time somehow 😛), I'm hitting this new error:

image

I think this is a result of IBM Cloud Operator's more flexible schema conflicting with the strict typing system used in CRD v1. Looks like we'll need to dig in a bit more.

JohnStarich commented 2 years ago

Merged via #267