github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/openshift/orderer/override/adminroute.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  	"fmt"
    23  
    24  	current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
    25  	"github.com/IBM-Blockchain/fabric-operator/pkg/manager/resources"
    26  	"github.com/IBM-Blockchain/fabric-operator/pkg/manager/resources/service"
    27  	"github.com/IBM-Blockchain/fabric-operator/version"
    28  	routev1 "github.com/openshift/api/route/v1"
    29  	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    30  	"k8s.io/apimachinery/pkg/util/intstr"
    31  )
    32  
    33  func (o *Override) AdminRoute(object v1.Object, route *routev1.Route, action resources.Action) error {
    34  	instance := object.(*current.IBPOrderer)
    35  	currentVer := version.String(instance.Spec.FabricVersion)
    36  	if !(currentVer.EqualWithoutTag(version.V2_4_1) || currentVer.GreaterThan(version.V2_4_1)) {
    37  		return nil
    38  	}
    39  	switch action {
    40  	case resources.Create:
    41  		return o.CreateAdminRouteOverride(instance, route)
    42  	case resources.Update:
    43  		return o.UpdateAdminRouteOverride(instance, route)
    44  	}
    45  
    46  	return nil
    47  }
    48  
    49  func (o *Override) CreateAdminRouteOverride(instance *current.IBPOrderer, route *routev1.Route) error {
    50  	route.Name = fmt.Sprintf("%s-admin", instance.GetName())
    51  	route.Spec.Host = instance.Namespace + "-" + instance.GetName() + "-admin" + "." + instance.Spec.Domain
    52  	weight := int32(100)
    53  	route.Spec.To = routev1.RouteTargetReference{
    54  		Kind:   "Service",
    55  		Name:   service.GetName(instance.Name),
    56  		Weight: &weight,
    57  	}
    58  
    59  	route.Spec.Port = &routev1.RoutePort{
    60  		TargetPort: intstr.FromString("orderer-admin"),
    61  	}
    62  
    63  	route.Spec.TLS = &routev1.TLSConfig{
    64  		Termination: routev1.TLSTerminationPassthrough,
    65  	}
    66  
    67  	return nil
    68  }
    69  
    70  func (o *Override) UpdateAdminRouteOverride(instance *current.IBPOrderer, route *routev1.Route) error {
    71  	return nil
    72  }