github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/base/ca/override/service.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 "github.com/IBM-Blockchain/fabric-operator/version" 25 corev1 "k8s.io/api/core/v1" 26 v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 ) 28 29 func (o *Override) Service(object v1.Object, service *corev1.Service, action resources.Action) error { 30 switch action { 31 case resources.Create: 32 return o.CreateService(object, service) 33 case resources.Update: 34 return o.UpdateService(object, service) 35 } 36 37 return nil 38 } 39 40 func (o *Override) CreateService(instance v1.Object, service *corev1.Service) error { 41 42 switch instance.(type) { 43 case *current.IBPCA: 44 i := instance.(*current.IBPCA) 45 46 if i.Status.Version == "" || i.Status.Version == version.V210 { 47 return o.CreateServiceV210(instance.(*current.IBPCA), service) 48 } else { 49 return o.CreateServiceV213(instance.(*current.IBPCA), service) 50 } 51 } 52 53 return nil 54 } 55 56 func (o *Override) CreateServiceV213(instance *current.IBPCA, service *corev1.Service) error { 57 if instance.Spec.Service != nil { 58 serviceType := instance.Spec.Service.Type 59 if serviceType != "" { 60 service.Spec.Type = serviceType 61 } 62 } 63 64 return nil 65 } 66 67 func (o *Override) CreateServiceV210(instance *current.IBPCA, service *corev1.Service) error { 68 if instance.Spec.Service != nil { 69 serviceType := instance.Spec.Service.Type 70 if serviceType != "" { 71 service.Spec.Type = serviceType 72 } 73 } 74 75 return nil 76 } 77 78 func (o *Override) UpdateService(instance v1.Object, service *corev1.Service) error { 79 return nil 80 }