github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/k8s/console/override/consolecm.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 "errors" 23 24 current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1" 25 consolev1 "github.com/IBM-Blockchain/fabric-operator/pkg/apis/console/v1" 26 "github.com/IBM-Blockchain/fabric-operator/pkg/manager/resources" 27 baseconsole "github.com/IBM-Blockchain/fabric-operator/pkg/offering/base/console/override" 28 corev1 "k8s.io/api/core/v1" 29 v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 30 "sigs.k8s.io/yaml" 31 ) 32 33 func (o *Override) ConsoleCM(object v1.Object, cm *corev1.ConfigMap, action resources.Action, options map[string]interface{}) error { 34 instance := object.(*current.IBPConsole) 35 switch action { 36 case resources.Create: 37 return o.CreateConsoleCM(instance, cm, options) 38 case resources.Update: 39 return o.UpdateConsoleCM(instance, cm, options) 40 } 41 42 return nil 43 } 44 45 func (o *Override) CreateConsoleCM(instance *current.IBPConsole, cm *corev1.ConfigMap, options map[string]interface{}) error { 46 data := cm.Data["settings.yaml"] 47 48 config := &consolev1.ConsoleSettingsConfig{} 49 err := yaml.Unmarshal([]byte(data), config) 50 if err != nil { 51 return err 52 } 53 54 if instance.Spec.NetworkInfo == nil || instance.Spec.NetworkInfo.Domain == "" { 55 return errors.New("domain not provided") 56 } 57 58 err = baseconsole.CommonConsoleCM(instance, config, options) 59 if err != nil { 60 return err 61 } 62 63 config.Infrastructure = baseconsole.K8S 64 // config.ProxyTLSUrl = "https://" + instance.Namespace + "-" + instance.Name + "-console." + instance.Spec.NetworkInfo.Domain + ":443" 65 66 bytes, err := yaml.Marshal(config) 67 if err != nil { 68 return err 69 } 70 71 if cm.Data == nil { 72 cm.Data = map[string]string{} 73 } 74 75 cm.Data["settings.yaml"] = string(bytes) 76 77 return nil 78 }