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