github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/k8s/orderer/override/ingressv1beta1_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  	networkingv1beta1 "k8s.io/api/networking/v1beta1"
    25  	"k8s.io/apimachinery/pkg/util/intstr"
    26  
    27  	current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
    28  	"github.com/IBM-Blockchain/fabric-operator/pkg/manager/resources"
    29  	"github.com/IBM-Blockchain/fabric-operator/pkg/offering/k8s/orderer/override"
    30  	"github.com/IBM-Blockchain/fabric-operator/pkg/util"
    31  )
    32  
    33  var _ = Describe("K8s Orderer Ingress Overrides", func() {
    34  	var (
    35  		err            error
    36  		overrider      *override.Override
    37  		instance       *current.IBPOrderer
    38  		ingress        *networkingv1beta1.Ingress
    39  		apihost        string
    40  		operationshost string
    41  		grpcwebhost    string
    42  	)
    43  
    44  	BeforeEach(func() {
    45  		overrider = &override.Override{}
    46  		instance = &current.IBPOrderer{
    47  			Spec: current.IBPOrdererSpec{
    48  				Domain: "test.domain",
    49  			},
    50  		}
    51  		ingress, err = util.GetIngressv1beta1FromFile("../../../../../definitions/orderer/ingressv1beta1.yaml")
    52  		Expect(err).NotTo(HaveOccurred())
    53  
    54  		apihost = instance.Namespace + "-" + instance.Name + "-orderer" + "." + instance.Spec.Domain
    55  		operationshost = instance.Namespace + "-" + instance.Name + "-operations" + "." + instance.Spec.Domain
    56  		grpcwebhost = instance.Namespace + "-" + instance.Name + "-grpcweb" + "." + instance.Spec.Domain
    57  	})
    58  
    59  	Context("create", func() {
    60  		It("appropriately overrides the respective values for ingress", func() {
    61  			err := overrider.Ingressv1beta1(instance, ingress, resources.Create)
    62  			Expect(err).NotTo(HaveOccurred())
    63  
    64  			By("setting rules", func() {
    65  				Expect(ingress.Spec.Rules).To(HaveLen(3))
    66  				Expect(ingress.Spec.Rules[0]).To(Equal(networkingv1beta1.IngressRule{
    67  					Host: apihost,
    68  					IngressRuleValue: networkingv1beta1.IngressRuleValue{
    69  						HTTP: &networkingv1beta1.HTTPIngressRuleValue{
    70  							Paths: []networkingv1beta1.HTTPIngressPath{
    71  								networkingv1beta1.HTTPIngressPath{
    72  									Backend: networkingv1beta1.IngressBackend{
    73  										ServiceName: instance.GetName(),
    74  										ServicePort: intstr.FromString("orderer-grpc"),
    75  									},
    76  									Path: "/",
    77  								},
    78  							},
    79  						},
    80  					},
    81  				}))
    82  				Expect(ingress.Spec.Rules[1]).To(Equal(networkingv1beta1.IngressRule{
    83  					Host: operationshost,
    84  					IngressRuleValue: networkingv1beta1.IngressRuleValue{
    85  						HTTP: &networkingv1beta1.HTTPIngressRuleValue{
    86  							Paths: []networkingv1beta1.HTTPIngressPath{
    87  								networkingv1beta1.HTTPIngressPath{
    88  									Backend: networkingv1beta1.IngressBackend{
    89  										ServiceName: instance.GetName(),
    90  										ServicePort: intstr.FromString("operations"),
    91  									},
    92  									Path: "/",
    93  								},
    94  							},
    95  						},
    96  					},
    97  				}))
    98  				Expect(ingress.Spec.Rules[2]).To(Equal(networkingv1beta1.IngressRule{
    99  					Host: grpcwebhost,
   100  					IngressRuleValue: networkingv1beta1.IngressRuleValue{
   101  						HTTP: &networkingv1beta1.HTTPIngressRuleValue{
   102  							Paths: []networkingv1beta1.HTTPIngressPath{
   103  								networkingv1beta1.HTTPIngressPath{
   104  									Backend: networkingv1beta1.IngressBackend{
   105  										ServiceName: instance.GetName(),
   106  										ServicePort: intstr.FromString("grpcweb"),
   107  									},
   108  									Path: "/",
   109  								},
   110  							},
   111  						},
   112  					},
   113  				}))
   114  			})
   115  
   116  			By("setting TLS hosts", func() {
   117  				Expect(ingress.Spec.TLS).To(HaveLen(3))
   118  				Expect(ingress.Spec.TLS[0].Hosts).To(Equal([]string{apihost}))
   119  				Expect(ingress.Spec.TLS[1].Hosts).To(Equal([]string{operationshost}))
   120  				Expect(ingress.Spec.TLS[2].Hosts).To(Equal([]string{grpcwebhost}))
   121  			})
   122  
   123  		})
   124  	})
   125  })