github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/pkg/setup/create_crd.go (about) 1 /* 2 Copyright 2019 The OpenEBS Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package setup 18 19 // import ( 20 // "encoding/json" 21 // "fmt" 22 // apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" 23 // "k8s.io/apimachinery/pkg/api/errors" 24 // metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 // "k8s.io/apimachinery/pkg/types" 26 // "k8s.io/apimachinery/pkg/util/wait" 27 // ) 28 29 // // createBlockDeviceCRD creates a BlockDevice CRD 30 // func (sc Config) createBlockDeviceCRD() error { 31 // blockDeviceCRD, err := buildBlockDeviceCRD() 32 // if err != nil { 33 // return err 34 // } 35 // return sc.createCRD(blockDeviceCRD) 36 // } 37 38 // // createBlockDeviceClaimCRD creates a BlockDeviceClaim CRD 39 // func (sc Config) createBlockDeviceClaimCRD() error { 40 // blockDeviceClaimCRD, err := buildBlockDeviceClaimCRD() 41 // if err != nil { 42 // return err 43 // } 44 // return sc.createCRD(blockDeviceClaimCRD) 45 // } 46 47 // // createCRD creates a CRD in the cluster and waits for it to get into active state 48 // // It will return error, if the CRD creation failed, or the Name conflicts with other CRD already 49 // // in the group 50 // func (sc Config) createCRD(crd *apiext.CustomResourceDefinition) error { 51 // if _, err := sc.apiExtClient.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd); err != nil { 52 // if errors.IsAlreadyExists(err) { 53 // // if CRD already exists, we patch it with the new changes. 54 // // This will also handle the upgrades of CRDs 55 // patch, err := json.Marshal(crd) 56 // if err != nil { 57 // return fmt.Errorf("could not marshal new customResourceDefintion for %s : %v", crd.Name, err) 58 // } 59 // if _, err := sc.apiExtClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(crd.Name, types.MergePatchType, patch); err != nil { 60 // return fmt.Errorf("could not update customResourceDefinition for %s : %v", crd.Name, err) 61 // } 62 // } else { 63 // return err 64 // } 65 // } 66 67 // return wait.Poll(CRDRetryInterval, CRDTimeout, func() (done bool, err error) { 68 // c, err := sc.apiExtClient.ApiextensionsV1beta1().CustomResourceDefinitions().Get(crd.Name, metav1.GetOptions{}) 69 // if err != nil { 70 // return false, err 71 // } 72 // for _, cond := range c.Status.Conditions { 73 // switch cond.Type { 74 // case apiext.Established: 75 // if cond.Status == apiext.ConditionTrue { 76 // return true, err 77 // } 78 // case apiext.NamesAccepted: 79 // if cond.Status == apiext.ConditionFalse { 80 // return false, fmt.Errorf("name conflict for %s : %v", crd.Name, cond.Reason) 81 // } 82 // } 83 // } 84 85 // return false, err 86 // }) 87 // }