github.com/IBM-Blockchain/fabric-operator@v1.0.4/main.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 main 20 21 import ( 22 "path/filepath" 23 "time" 24 25 config "github.com/IBM-Blockchain/fabric-operator/operatorconfig" 26 "github.com/IBM-Blockchain/fabric-operator/pkg/command" 27 cainit "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/ca" 28 ordererinit "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/orderer" 29 peerinit "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/peer" 30 31 logf "sigs.k8s.io/controller-runtime/pkg/log" 32 33 "k8s.io/apimachinery/pkg/runtime" 34 utilruntime "k8s.io/apimachinery/pkg/util/runtime" 35 clientgoscheme "k8s.io/client-go/kubernetes/scheme" 36 _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" 37 ctrl "sigs.k8s.io/controller-runtime" 38 39 ibpv1beta1 "github.com/IBM-Blockchain/fabric-operator/api/v1beta1" 40 // +kubebuilder:scaffold:imports 41 ) 42 43 const ( 44 defaultConfigs = "./defaultconfig" 45 defaultPeerDef = "./definitions/peer" 46 defaultCADef = "./definitions/ca" 47 defaultOrdererDef = "./definitions/orderer" 48 defaultConsoleDef = "./definitions/console" 49 ) 50 51 var log = logf.Log.WithName("cmd") 52 53 var ( 54 scheme = runtime.NewScheme() 55 setupLog = ctrl.Log.WithName("setup") 56 ) 57 58 func init() { 59 utilruntime.Must(clientgoscheme.AddToScheme(scheme)) 60 utilruntime.Must(ibpv1beta1.AddToScheme(scheme)) 61 // +kubebuilder:scaffold:scheme 62 } 63 64 func main() { 65 66 operatorCfg := &config.Config{} 67 68 setDefaultCADefinitions(operatorCfg) 69 setDefaultPeerDefinitions(operatorCfg) 70 setDefaultOrdererDefinitions(operatorCfg) 71 setDefaultConsoleDefinitions(operatorCfg) 72 73 operatorCfg.Operator.SetDefaults() 74 75 if err := command.Operator(operatorCfg); err != nil { 76 log.Error(err, "failed to start operator") 77 time.Sleep(15 * time.Second) 78 } 79 80 // TODO 81 // if err = (&ibpca.IBPCAReconciler{ 82 // Client: mgr.GetClient(), 83 // Log: ctrl.Log.WithName("controllers").WithName("IBPCA"), 84 // Scheme: mgr.GetScheme(), 85 // }).SetupWithManager(mgr); err != nil { 86 // setupLog.Error(err, "unable to create controller", "controller", "IBPCA") 87 // os.Exit(1) 88 // } 89 // if err = (&controllers.IBPPeerReconciler{ 90 // Client: mgr.GetClient(), 91 // Log: ctrl.Log.WithName("controllers").WithName("IBPPeer"), 92 // Scheme: mgr.GetScheme(), 93 // }).SetupWithManager(mgr); err != nil { 94 // setupLog.Error(err, "unable to create controller", "controller", "IBPPeer") 95 // os.Exit(1) 96 // } 97 // if err = (&controllers.IBPOrdererReconciler{ 98 // Client: mgr.GetClient(), 99 // Log: ctrl.Log.WithName("controllers").WithName("IBPOrderer"), 100 // Scheme: mgr.GetScheme(), 101 // }).SetupWithManager(mgr); err != nil { 102 // setupLog.Error(err, "unable to create controller", "controller", "IBPOrderer") 103 // os.Exit(1) 104 // } 105 // if err = (&controllers.IBPConsoleReconciler{ 106 // Client: mgr.GetClient(), 107 // Log: ctrl.Log.WithName("controllers").WithName("IBPConsole"), 108 // Scheme: mgr.GetScheme(), 109 // }).SetupWithManager(mgr); err != nil { 110 // setupLog.Error(err, "unable to create controller", "controller", "IBPConsole") 111 // os.Exit(1) 112 // } 113 // +kubebuilder:scaffold:builder 114 } 115 116 func setDefaultCADefinitions(cfg *config.Config) { 117 cfg.CAInitConfig = &cainit.Config{ 118 CADefaultConfigPath: filepath.Join(defaultConfigs, "ca/ca.yaml"), 119 TLSCADefaultConfigPath: filepath.Join(defaultConfigs, "ca/tlsca.yaml"), 120 DeploymentFile: filepath.Join(defaultCADef, "deployment.yaml"), 121 PVCFile: filepath.Join(defaultCADef, "pvc.yaml"), 122 ServiceFile: filepath.Join(defaultCADef, "service.yaml"), 123 RoleFile: filepath.Join(defaultCADef, "role.yaml"), 124 ServiceAccountFile: filepath.Join(defaultCADef, "serviceaccount.yaml"), 125 RoleBindingFile: filepath.Join(defaultCADef, "rolebinding.yaml"), 126 ConfigMapFile: filepath.Join(defaultCADef, "configmap-caoverride.yaml"), 127 IngressFile: filepath.Join(defaultCADef, "ingress.yaml"), 128 Ingressv1beta1File: filepath.Join(defaultCADef, "ingressv1beta1.yaml"), 129 RouteFile: filepath.Join(defaultCADef, "route.yaml"), 130 SharedPath: "/tmp/data", 131 } 132 } 133 134 func setDefaultPeerDefinitions(cfg *config.Config) { 135 cfg.PeerInitConfig = &peerinit.Config{ 136 OUFile: filepath.Join(defaultConfigs, "peer/ouconfig.yaml"), 137 InterOUFile: filepath.Join(defaultConfigs, "peer/ouconfig-inter.yaml"), 138 CorePeerFile: filepath.Join(defaultConfigs, "peer/core.yaml"), 139 CorePeerV2File: filepath.Join(defaultConfigs, "peer/v2/core.yaml"), 140 DeploymentFile: filepath.Join(defaultPeerDef, "deployment.yaml"), 141 PVCFile: filepath.Join(defaultPeerDef, "pvc.yaml"), 142 CouchDBPVCFile: filepath.Join(defaultPeerDef, "couchdb-pvc.yaml"), 143 ServiceFile: filepath.Join(defaultPeerDef, "service.yaml"), 144 RoleFile: filepath.Join(defaultPeerDef, "role.yaml"), 145 ServiceAccountFile: filepath.Join(defaultPeerDef, "serviceaccount.yaml"), 146 RoleBindingFile: filepath.Join(defaultPeerDef, "rolebinding.yaml"), 147 FluentdConfigMapFile: filepath.Join(defaultPeerDef, "fluentd-configmap.yaml"), 148 CouchContainerFile: filepath.Join(defaultPeerDef, "couchdb.yaml"), 149 CouchInitContainerFile: filepath.Join(defaultPeerDef, "couchdb-init.yaml"), 150 IngressFile: filepath.Join(defaultPeerDef, "ingress.yaml"), 151 Ingressv1beta1File: filepath.Join(defaultPeerDef, "ingressv1beta1.yaml"), 152 CCLauncherFile: filepath.Join(defaultPeerDef, "chaincode-launcher.yaml"), 153 RouteFile: filepath.Join(defaultPeerDef, "route.yaml"), 154 StoragePath: "/tmp/peerinit", 155 } 156 } 157 158 func setDefaultOrdererDefinitions(cfg *config.Config) { 159 cfg.OrdererInitConfig = &ordererinit.Config{ 160 OrdererV2File: filepath.Join(defaultConfigs, "orderer/v2/orderer.yaml"), 161 OrdererV24File: filepath.Join(defaultConfigs, "orderer/v24/orderer.yaml"), 162 OrdererFile: filepath.Join(defaultConfigs, "orderer/orderer.yaml"), 163 ConfigTxFile: filepath.Join(defaultConfigs, "orderer/configtx.yaml"), 164 OUFile: filepath.Join(defaultConfigs, "orderer/ouconfig.yaml"), 165 InterOUFile: filepath.Join(defaultConfigs, "orderer/ouconfig-inter.yaml"), 166 DeploymentFile: filepath.Join(defaultOrdererDef, "deployment.yaml"), 167 PVCFile: filepath.Join(defaultOrdererDef, "pvc.yaml"), 168 ServiceFile: filepath.Join(defaultOrdererDef, "service.yaml"), 169 CMFile: filepath.Join(defaultOrdererDef, "configmap.yaml"), 170 RoleFile: filepath.Join(defaultOrdererDef, "role.yaml"), 171 ServiceAccountFile: filepath.Join(defaultOrdererDef, "serviceaccount.yaml"), 172 RoleBindingFile: filepath.Join(defaultOrdererDef, "rolebinding.yaml"), 173 IngressFile: filepath.Join(defaultOrdererDef, "ingress.yaml"), 174 Ingressv1beta1File: filepath.Join(defaultOrdererDef, "ingressv1beta1.yaml"), 175 RouteFile: filepath.Join(defaultOrdererDef, "route.yaml"), 176 StoragePath: "/tmp/ordererinit", 177 } 178 } 179 180 func setDefaultConsoleDefinitions(cfg *config.Config) { 181 cfg.ConsoleInitConfig = &config.ConsoleConfig{ 182 DeploymentFile: filepath.Join(defaultConsoleDef, "deployment.yaml"), 183 PVCFile: filepath.Join(defaultConsoleDef, "pvc.yaml"), 184 ServiceFile: filepath.Join(defaultConsoleDef, "service.yaml"), 185 DeployerServiceFile: filepath.Join(defaultConsoleDef, "deployer-service.yaml"), 186 CMFile: filepath.Join(defaultConsoleDef, "configmap.yaml"), 187 ConsoleCMFile: filepath.Join(defaultConsoleDef, "console-configmap.yaml"), 188 DeployerCMFile: filepath.Join(defaultConsoleDef, "deployer-configmap.yaml"), 189 RoleFile: filepath.Join(defaultConsoleDef, "role.yaml"), 190 ServiceAccountFile: filepath.Join(defaultConsoleDef, "serviceaccount.yaml"), 191 RoleBindingFile: filepath.Join(defaultConsoleDef, "rolebinding.yaml"), 192 IngressFile: filepath.Join(defaultConsoleDef, "ingress.yaml"), 193 Ingressv1beta1File: filepath.Join(defaultConsoleDef, "ingressv1beta1.yaml"), 194 RouteFile: filepath.Join(defaultConsoleDef, "route.yaml"), 195 NetworkPolicyIngressFile: filepath.Join(defaultConsoleDef, "networkpolicy-ingress.yaml"), 196 NetworkPolicyDenyAllFile: filepath.Join(defaultConsoleDef, "networkpolicy-denyall.yaml"), 197 } 198 }