github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/k8s/orderer/override/ingressv1beta1.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
    20  
    21  import (
    22  	current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
    23  	"github.com/IBM-Blockchain/fabric-operator/pkg/manager/resources"
    24  	networkingv1beta1 "k8s.io/api/networking/v1beta1"
    25  	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    26  	"k8s.io/apimachinery/pkg/util/intstr"
    27  )
    28  
    29  func (o *Override) Ingressv1beta1(object v1.Object, ingress *networkingv1beta1.Ingress, action resources.Action) error {
    30  	instance := object.(*current.IBPOrderer)
    31  
    32  	switch action {
    33  	case resources.Create:
    34  		return o.CreateIngressv1beta1(instance, ingress)
    35  	case resources.Update:
    36  		return o.UpdateIngressv1beta1(instance, ingress)
    37  	}
    38  
    39  	return nil
    40  }
    41  
    42  func (o *Override) CreateIngressv1beta1(instance *current.IBPOrderer, ingress *networkingv1beta1.Ingress) error {
    43  	return o.CommonIngressv1beta1(instance, ingress)
    44  }
    45  
    46  func (o *Override) UpdateIngressv1beta1(instance *current.IBPOrderer, ingress *networkingv1beta1.Ingress) error {
    47  	return o.CommonIngressv1beta1(instance, ingress)
    48  }
    49  
    50  func (o *Override) CommonIngressv1beta1(instance *current.IBPOrderer, ingress *networkingv1beta1.Ingress) error {
    51  
    52  	ingressClass := "nginx"
    53  	if instance.Spec.Ingress.Class != "" {
    54  		ingressClass = instance.Spec.Ingress.Class
    55  	}
    56  	ingress.ObjectMeta.Annotations["kubernetes.io/ingress.class"] = ingressClass
    57  
    58  	apihost := instance.Namespace + "-" + instance.Name + "-orderer" + "." + instance.Spec.Domain
    59  	operationshost := instance.Namespace + "-" + instance.Name + "-operations" + "." + instance.Spec.Domain
    60  	grpcwebhost := instance.Namespace + "-" + instance.Name + "-grpcweb" + "." + instance.Spec.Domain
    61  
    62  	ingress.Spec = networkingv1beta1.IngressSpec{
    63  		Rules: []networkingv1beta1.IngressRule{
    64  			networkingv1beta1.IngressRule{
    65  				Host: apihost,
    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("orderer-grpc"),
    73  								},
    74  								Path: "/",
    75  							},
    76  						},
    77  					},
    78  				},
    79  			},
    80  			networkingv1beta1.IngressRule{
    81  				Host: operationshost,
    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  			networkingv1beta1.IngressRule{
    97  				Host: grpcwebhost,
    98  				IngressRuleValue: networkingv1beta1.IngressRuleValue{
    99  					HTTP: &networkingv1beta1.HTTPIngressRuleValue{
   100  						Paths: []networkingv1beta1.HTTPIngressPath{
   101  							networkingv1beta1.HTTPIngressPath{
   102  								Backend: networkingv1beta1.IngressBackend{
   103  									ServiceName: instance.GetName(),
   104  									ServicePort: intstr.FromString("grpcweb"),
   105  								},
   106  								Path: "/",
   107  							},
   108  						},
   109  					},
   110  				},
   111  			},
   112  		},
   113  		TLS: []networkingv1beta1.IngressTLS{
   114  			networkingv1beta1.IngressTLS{
   115  				Hosts: []string{apihost},
   116  			},
   117  			networkingv1beta1.IngressTLS{
   118  				Hosts: []string{operationshost},
   119  			},
   120  			networkingv1beta1.IngressTLS{
   121  				Hosts: []string{grpcwebhost},
   122  			},
   123  		},
   124  	}
   125  
   126  	return nil
   127  }