github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/k8s/ca/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/ca/override"
    30  	"github.com/IBM-Blockchain/fabric-operator/pkg/util"
    31  )
    32  
    33  var _ = Describe("K8s CA Ingress Overrides", func() {
    34  	var (
    35  		err       error
    36  		overrider *override.Override
    37  		instance  *current.IBPCA
    38  		ingress   *networkingv1beta1.Ingress
    39  		cahost    string
    40  		operhost  string
    41  	)
    42  
    43  	BeforeEach(func() {
    44  		overrider = &override.Override{}
    45  		instance = &current.IBPCA{
    46  			Spec: current.IBPCASpec{
    47  				Domain: "test.domain",
    48  			},
    49  		}
    50  		ingress, err = util.GetIngressv1beta1FromFile("../../../../../definitions/ca/ingressv1beta1.yaml")
    51  		Expect(err).NotTo(HaveOccurred())
    52  
    53  		cahost = instance.Namespace + "-" + instance.Name + "-ca" + "." + instance.Spec.Domain
    54  		operhost = instance.Namespace + "-" + instance.Name + "-operations" + "." + instance.Spec.Domain
    55  	})
    56  
    57  	Context("create", func() {
    58  		It("appropriately overrides the respective values for ingress", func() {
    59  			err := overrider.Ingressv1beta1(instance, ingress, resources.Create)
    60  			Expect(err).NotTo(HaveOccurred())
    61  
    62  			By("setting rule", func() {
    63  				Expect(ingress.Spec.Rules).To(HaveLen(2))
    64  				Expect(ingress.Spec.Rules[0]).To(Equal(networkingv1beta1.IngressRule{
    65  					Host: cahost,
    66  					IngressRuleValue: networkingv1beta1.IngressRuleValue{
    67  						HTTP: &networkingv1beta1.HTTPIngressRuleValue{
    68  							Paths: []networkingv1beta1.HTTPIngressPath{
    69  								networkingv1beta1.HTTPIngressPath{
    70  									Backend: networkingv1beta1.IngressBackend{
    71  										ServiceName: instance.GetName(),
    72  										ServicePort: intstr.FromString("http"),
    73  									},
    74  									Path: "/",
    75  								},
    76  							},
    77  						},
    78  					},
    79  				}))
    80  				Expect(ingress.Spec.Rules[1]).To(Equal(networkingv1beta1.IngressRule{
    81  					Host: operhost,
    82  					IngressRuleValue: networkingv1beta1.IngressRuleValue{
    83  						HTTP: &networkingv1beta1.HTTPIngressRuleValue{
    84  							Paths: []networkingv1beta1.HTTPIngressPath{
    85  								networkingv1beta1.HTTPIngressPath{
    86  									Backend: networkingv1beta1.IngressBackend{
    87  										ServiceName: instance.GetName(),
    88  										ServicePort: intstr.FromString("operations"),
    89  									},
    90  									Path: "/",
    91  								},
    92  							},
    93  						},
    94  					},
    95  				}))
    96  			})
    97  
    98  			By("setting TLS hosts", func() {
    99  				Expect(ingress.Spec.TLS).To(HaveLen(2))
   100  				Expect(ingress.Spec.TLS[0].Hosts).To(Equal([]string{cahost}))
   101  				Expect(ingress.Spec.TLS[1].Hosts).To(Equal([]string{operhost}))
   102  			})
   103  		})
   104  	})
   105  })