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