github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/base/console/override/pvc.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 corev1 "k8s.io/api/core/v1" 25 "k8s.io/apimachinery/pkg/api/resource" 26 v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 ) 28 29 func (o *Override) PVC(object v1.Object, pvc *corev1.PersistentVolumeClaim, action resources.Action) error { 30 instance := object.(*current.IBPConsole) 31 switch action { 32 case resources.Create: 33 return o.CreatePVC(instance, pvc) 34 case resources.Update: 35 return o.UpdatePVC(instance, pvc) 36 } 37 38 return nil 39 } 40 41 func (o *Override) CreatePVC(instance *current.IBPConsole, pvc *corev1.PersistentVolumeClaim) error { 42 storage := instance.Spec.Storage 43 if storage != nil { 44 consoleStorage := storage.Console 45 if consoleStorage != nil { 46 if consoleStorage.Class != "" { 47 if consoleStorage.Class == "local" { 48 class := "manual" 49 pvc.Spec.StorageClassName = &class 50 } else { 51 pvc.Spec.StorageClassName = &consoleStorage.Class 52 } 53 } 54 55 if consoleStorage.Size != "" { 56 quantity, err := resource.ParseQuantity(consoleStorage.Size) 57 if err != nil { 58 return err 59 } 60 resourceMap := pvc.Spec.Resources.Requests 61 if resourceMap == nil { 62 resourceMap = corev1.ResourceList{} 63 } 64 resourceMap[corev1.ResourceStorage] = quantity 65 pvc.Spec.Resources.Requests = resourceMap 66 } 67 } 68 } 69 70 if pvc.ObjectMeta.Labels == nil { 71 pvc.ObjectMeta.Labels = map[string]string{} 72 } 73 if instance.Spec.Zone != "" { 74 pvc.ObjectMeta.Labels["zone"] = instance.Spec.Zone 75 } 76 77 if instance.Spec.Region != "" { 78 pvc.ObjectMeta.Labels["region"] = instance.Spec.Region 79 } 80 81 return nil 82 } 83 84 func (o *Override) UpdatePVC(instance *current.IBPConsole, pvc *corev1.PersistentVolumeClaim) error { 85 return nil 86 }