github.com/IBM-Blockchain/fabric-operator@v1.0.4/integration/helper/orderer.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 helper 20 21 import ( 22 "context" 23 "strings" 24 25 current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1" 26 "github.com/IBM-Blockchain/fabric-operator/integration" 27 ibpclient "github.com/IBM-Blockchain/fabric-operator/pkg/client" 28 29 k8serrors "k8s.io/apimachinery/pkg/api/errors" 30 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 31 "k8s.io/client-go/kubernetes" 32 ) 33 34 func CreateOrderer(crClient *ibpclient.IBPClient, orderer *current.IBPOrderer) error { 35 result := crClient.Post().Namespace(orderer.Namespace).Resource("ibporderers").Body(orderer).Do(context.TODO()) 36 err := result.Error() 37 if !k8serrors.IsAlreadyExists(err) { 38 return err 39 } 40 return nil 41 } 42 43 type Orderer struct { 44 Domain string 45 Name string 46 Namespace string 47 NodeName string 48 Nodes []Orderer 49 WorkingDir string 50 51 CR *current.IBPOrderer 52 CRClient *ibpclient.IBPClient 53 KClient *kubernetes.Clientset 54 55 integration.NativeResourcePoller 56 } 57 58 func (o *Orderer) PollForParentCRStatus() current.IBPCRStatusType { 59 crStatus := ¤t.IBPOrderer{} 60 61 result := o.CRClient.Get().Namespace(o.Namespace).Resource("ibporderers").Name(o.Name).Do(context.TODO()) 62 // Not handling this as this is integration test 63 _ = result.Into(crStatus) 64 65 return crStatus.Status.Type 66 } 67 68 func (o *Orderer) PollForCRStatus() current.IBPCRStatusType { 69 crStatus := ¤t.IBPOrderer{} 70 71 result := o.CRClient.Get().Namespace(o.Namespace).Resource("ibporderers").Name(o.NodeName).Do(context.TODO()) 72 // Not handling this as this is integration test 73 _ = result.Into(crStatus) 74 75 return crStatus.Status.Type 76 } 77 78 func (o *Orderer) JobWithPrefixFound(prefix, namespace string) bool { 79 jobs, err := o.KClient.BatchV1().Jobs(namespace).List(context.TODO(), metav1.ListOptions{}) 80 if err != nil { 81 return false 82 } 83 84 for _, job := range jobs.Items { 85 if strings.HasPrefix(job.GetName(), prefix) { 86 return true 87 } 88 } 89 90 return false 91 }