github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/command/crdinstall.go (about)

     1  /*
     2   * Copyright contributors to the Hyperledger Fabric Operator project
     3   *
     4   * SPDX-License-Identifier: Apache-2.0
     5   *
     6   * Licensed under the Apache License, Version 2.0 (the "License");
     7   * you may not use this file except in compliance with the License.
     8   * You may obtain a copy of the License at:
     9   *
    10   * 	  http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing, software
    13   * distributed under the License is distributed on an "AS IS" BASIS,
    14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15   * See the License for the specific language governing permissions and
    16   * limitations under the License.
    17   */
    18  
    19  package command
    20  
    21  import (
    22  	"github.com/IBM-Blockchain/fabric-operator/pkg/crd"
    23  	"github.com/IBM-Blockchain/fabric-operator/pkg/k8s/clientset"
    24  	"github.com/pkg/errors"
    25  	"k8s.io/client-go/rest"
    26  )
    27  
    28  func CRDInstall(dir string) error {
    29  	config, err := rest.InClusterConfig()
    30  	if err != nil {
    31  		return errors.Wrap(err, "failed to get cluster config")
    32  	}
    33  
    34  	err = CRDInstallUsingConfig(config, dir)
    35  	if err != nil {
    36  		return errors.Wrap(err, "failed to install CRDs")
    37  	}
    38  
    39  	return nil
    40  }
    41  
    42  func CRDInstallUsingConfig(config *rest.Config, dir string) error {
    43  	clientSet, err := clientset.New(config)
    44  	if err != nil {
    45  		return errors.Wrap(err, "failed to get client")
    46  	}
    47  
    48  	crds := crd.GetCRDListFromDir(dir)
    49  	manager, err := crd.NewManager(clientSet, crds...)
    50  	if err != nil {
    51  		return errors.Wrap(err, "failed to create CRD manager")
    52  	}
    53  
    54  	err = manager.Create()
    55  	if err != nil {
    56  		return errors.Wrap(err, "failed to create CRDs")
    57  	}
    58  
    59  	return nil
    60  }