github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/base/orderer/override/override_test.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 override_test 20 21 import ( 22 . "github.com/onsi/ginkgo/v2" 23 . "github.com/onsi/gomega" 24 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 26 current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1" 27 "github.com/IBM-Blockchain/fabric-operator/controllers/mocks" 28 "github.com/IBM-Blockchain/fabric-operator/pkg/manager/resources" 29 "github.com/IBM-Blockchain/fabric-operator/pkg/offering/base/orderer/override" 30 ) 31 32 var _ = Describe("K8S Orderer Overrides", func() { 33 var ( 34 overrider *override.Override 35 instance *current.IBPOrderer 36 ) 37 38 BeforeEach(func() { 39 overrider = &override.Override{ 40 Client: &mocks.Client{}, 41 } 42 instance = ¤t.IBPOrderer{} 43 }) 44 45 Context("Affnity", func() { 46 BeforeEach(func() { 47 instance = ¤t.IBPOrderer{ 48 Spec: current.IBPOrdererSpec{ 49 OrgName: "orderermsp", 50 Arch: []string{"test-arch"}, 51 Zone: "dal", 52 Region: "us-south", 53 }, 54 } 55 }) 56 57 It("returns an proper affinity when arch is passed", func() { 58 a := overrider.GetAffinity(instance) 59 Expect(a.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[0].MatchExpressions[0].Values).To(Equal([]string{"test-arch"})) 60 Expect(a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchExpressions[0].Key).To(Equal("orgname")) 61 Expect(a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchExpressions[0].Values).To(Equal([]string{"orderermsp"})) 62 Expect(a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].Weight).To(Equal(int32(100))) 63 }) 64 65 It("returns an proper affinity when no arch is passed", func() { 66 instance.Spec.Arch = []string{} 67 a := overrider.GetAffinity(instance) 68 Expect(a.NodeAffinity).NotTo(BeNil()) 69 Expect(a.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[0].MatchExpressions[0].Values).To(Equal([]string{"dal"})) 70 Expect(a.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[0].MatchExpressions[1].Values).To(Equal([]string{"us-south"})) 71 Expect(a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchExpressions[0].Key).To(Equal("orgname")) 72 Expect(a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchExpressions[0].Values).To(Equal([]string{"orderermsp"})) 73 Expect(a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].Weight).To(Equal(int32(100))) 74 }) 75 }) 76 77 Context("Deployment", func() { 78 var ( 79 orderernode *current.IBPOrderer 80 ) 81 82 nodenum := 2 83 84 BeforeEach(func() { 85 instance = ¤t.IBPOrderer{ 86 ObjectMeta: metav1.ObjectMeta{ 87 Name: "os1", 88 }, 89 Spec: current.IBPOrdererSpec{ 90 License: current.License{ 91 Accept: true, 92 }, 93 OrgName: "orderermsp", 94 MSPID: "orderermsp", 95 OrdererType: "solo", 96 ExternalAddress: "0.0.0.0", 97 GenesisProfile: "Initial", 98 Storage: ¤t.OrdererStorages{}, 99 Service: ¤t.Service{}, 100 Images: ¤t.OrdererImages{}, 101 Resources: ¤t.OrdererResources{}, 102 SystemChannelName: "testchainid", 103 Arch: []string{"test-arch"}, 104 Zone: "dal", 105 Region: "us-south", 106 ClusterSize: 2, 107 NodeNumber: &nodenum, 108 ClusterLocation: []current.IBPOrdererClusterLocation{ 109 current.IBPOrdererClusterLocation{ 110 Zone: "dal1", 111 Region: "us-south1", 112 }, 113 current.IBPOrdererClusterLocation{ 114 Zone: "dal2", 115 Region: "us-south2", 116 }, 117 }, 118 }, 119 } 120 121 orderernode = ¤t.IBPOrderer{ 122 Spec: current.IBPOrdererSpec{ 123 License: current.License{ 124 Accept: true, 125 }, 126 OrgName: "orderermsp", 127 MSPID: "orderermsp", 128 OrdererType: "solo", 129 ExternalAddress: "0.0.0.0", 130 GenesisProfile: "Initial", 131 Storage: ¤t.OrdererStorages{}, 132 Service: ¤t.Service{}, 133 Images: ¤t.OrdererImages{}, 134 Resources: ¤t.OrdererResources{}, 135 SystemChannelName: "testchainid", 136 Arch: []string{"test-arch"}, 137 Zone: "dal", 138 Region: "us-south", 139 }, 140 } 141 }) 142 143 Context("Create overrides", func() { 144 It("overides things correctly", func() { 145 err := overrider.OrdererNode(instance, orderernode, resources.Create) 146 Expect(err).NotTo(HaveOccurred()) 147 Expect(orderernode.Spec.Zone).To(Equal(instance.Spec.ClusterLocation[1].Zone)) 148 Expect(orderernode.Spec.Region).To(Equal(instance.Spec.ClusterLocation[1].Region)) 149 Expect(orderernode.GetName()).To(Equal(instance.GetName() + "node2")) 150 Expect(orderernode.Labels["parent"]).To(Equal(instance.Name)) 151 }) 152 }) 153 }) 154 })