github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/openshift/ca/override/operationroute.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  	routev1 "github.com/openshift/api/route/v1"
    28  	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    29  	"k8s.io/apimachinery/pkg/util/intstr"
    30  )
    31  
    32  func (o *Override) OperationsRoute(object v1.Object, route *routev1.Route, action resources.Action) error {
    33  	instance := object.(*current.IBPCA)
    34  	switch action {
    35  	case resources.Create:
    36  		return o.CreateOperationsRouteOverride(instance, route)
    37  	case resources.Update:
    38  		return o.UpdateOperationsRouteOverride(instance, route)
    39  	}
    40  
    41  	return nil
    42  }
    43  
    44  func (o *Override) CreateOperationsRouteOverride(instance *current.IBPCA, route *routev1.Route) error {
    45  	route.Name = fmt.Sprintf("%s-operations", instance.GetName())
    46  	route.Spec.Host = instance.Namespace + "-" + instance.GetName() + "-operations" + "." + instance.Spec.Domain
    47  	weight := int32(100)
    48  	route.Spec.To = routev1.RouteTargetReference{
    49  		Kind:   "Service",
    50  		Name:   service.GetName(instance.Name),
    51  		Weight: &weight,
    52  	}
    53  
    54  	route.Spec.Port = &routev1.RoutePort{
    55  		TargetPort: intstr.FromString("operations"),
    56  	}
    57  
    58  	route.Spec.TLS = &routev1.TLSConfig{
    59  		Termination: routev1.TLSTerminationPassthrough,
    60  	}
    61  
    62  	return nil
    63  }
    64  
    65  func (o *Override) UpdateOperationsRouteOverride(instance *current.IBPCA, route *routev1.Route) error {
    66  	return nil
    67  }