-
Notifications
You must be signed in to change notification settings - Fork 36
/
main.go
205 lines (186 loc) · 8.98 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* Copyright contributors to the Hyperledger Fabric Operator project
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"fmt"
"path/filepath"
"time"
config "github.com/IBM-Blockchain/fabric-operator/operatorconfig"
"github.com/IBM-Blockchain/fabric-operator/pkg/command"
cainit "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/ca"
ordererinit "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/orderer"
peerinit "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/peer"
"github.com/IBM-Blockchain/fabric-operator/pkg/util"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
ibpv1beta1 "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
// +kubebuilder:scaffold:imports
)
const (
defaultConfigs = "./defaultconfig"
defaultPeerDef = "./definitions/peer"
defaultCADef = "./definitions/ca"
defaultOrdererDef = "./definitions/orderer"
defaultConsoleDef = "./definitions/console"
)
var log = logf.Log.WithName("cmd")
var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
)
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(ibpv1beta1.AddToScheme(scheme))
// +kubebuilder:scaffold:scheme
}
func main() {
operatorCfg := &config.Config{}
setDefaultCADefinitions(operatorCfg)
setDefaultPeerDefinitions(operatorCfg)
setDefaultOrdererDefinitions(operatorCfg)
setDefaultConsoleDefinitions(operatorCfg)
operatorCfg.Operator.SetDefaults()
zaplogger, err := util.SetupLogging("DEBUG")
if err != nil {
fmt.Print("error initiating the logger", err)
}
operatorCfg.Logger = zaplogger
if err := command.Operator(operatorCfg); err != nil {
log.Error(err, "failed to start operator")
time.Sleep(15 * time.Second)
}
// TODO
// if err = (&ibpca.IBPCAReconciler{
// Client: mgr.GetClient(),
// Log: ctrl.Log.WithName("controllers").WithName("IBPCA"),
// Scheme: mgr.GetScheme(),
// }).SetupWithManager(mgr); err != nil {
// setupLog.Error(err, "unable to create controller", "controller", "IBPCA")
// os.Exit(1)
// }
// if err = (&controllers.IBPPeerReconciler{
// Client: mgr.GetClient(),
// Log: ctrl.Log.WithName("controllers").WithName("IBPPeer"),
// Scheme: mgr.GetScheme(),
// }).SetupWithManager(mgr); err != nil {
// setupLog.Error(err, "unable to create controller", "controller", "IBPPeer")
// os.Exit(1)
// }
// if err = (&controllers.IBPOrdererReconciler{
// Client: mgr.GetClient(),
// Log: ctrl.Log.WithName("controllers").WithName("IBPOrderer"),
// Scheme: mgr.GetScheme(),
// }).SetupWithManager(mgr); err != nil {
// setupLog.Error(err, "unable to create controller", "controller", "IBPOrderer")
// os.Exit(1)
// }
// if err = (&controllers.IBPConsoleReconciler{
// Client: mgr.GetClient(),
// Log: ctrl.Log.WithName("controllers").WithName("IBPConsole"),
// Scheme: mgr.GetScheme(),
// }).SetupWithManager(mgr); err != nil {
// setupLog.Error(err, "unable to create controller", "controller", "IBPConsole")
// os.Exit(1)
// }
// +kubebuilder:scaffold:builder
}
func setDefaultCADefinitions(cfg *config.Config) {
cfg.CAInitConfig = &cainit.Config{
CADefaultConfigPath: filepath.Join(defaultConfigs, "ca/ca.yaml"),
TLSCADefaultConfigPath: filepath.Join(defaultConfigs, "ca/tlsca.yaml"),
DeploymentFile: filepath.Join(defaultCADef, "deployment.yaml"),
PVCFile: filepath.Join(defaultCADef, "pvc.yaml"),
ServiceFile: filepath.Join(defaultCADef, "service.yaml"),
RoleFile: filepath.Join(defaultCADef, "role.yaml"),
ServiceAccountFile: filepath.Join(defaultCADef, "serviceaccount.yaml"),
RoleBindingFile: filepath.Join(defaultCADef, "rolebinding.yaml"),
ConfigMapFile: filepath.Join(defaultCADef, "configmap-caoverride.yaml"),
IngressFile: filepath.Join(defaultCADef, "ingress.yaml"),
Ingressv1beta1File: filepath.Join(defaultCADef, "ingressv1beta1.yaml"),
RouteFile: filepath.Join(defaultCADef, "route.yaml"),
SharedPath: "/tmp/data",
}
}
func setDefaultPeerDefinitions(cfg *config.Config) {
cfg.PeerInitConfig = &peerinit.Config{
OUFile: filepath.Join(defaultConfigs, "peer/ouconfig.yaml"),
InterOUFile: filepath.Join(defaultConfigs, "peer/ouconfig-inter.yaml"),
CorePeerFile: filepath.Join(defaultConfigs, "peer/core.yaml"),
CorePeerV2File: filepath.Join(defaultConfigs, "peer/v2/core.yaml"),
CorePeerV25File: filepath.Join(defaultConfigs, "peer/v25/core.yaml"),
DeploymentFile: filepath.Join(defaultPeerDef, "deployment.yaml"),
PVCFile: filepath.Join(defaultPeerDef, "pvc.yaml"),
CouchDBPVCFile: filepath.Join(defaultPeerDef, "couchdb-pvc.yaml"),
ServiceFile: filepath.Join(defaultPeerDef, "service.yaml"),
RoleFile: filepath.Join(defaultPeerDef, "role.yaml"),
ServiceAccountFile: filepath.Join(defaultPeerDef, "serviceaccount.yaml"),
RoleBindingFile: filepath.Join(defaultPeerDef, "rolebinding.yaml"),
CouchContainerFile: filepath.Join(defaultPeerDef, "couchdb.yaml"),
CouchInitContainerFile: filepath.Join(defaultPeerDef, "couchdb-init.yaml"),
IngressFile: filepath.Join(defaultPeerDef, "ingress.yaml"),
Ingressv1beta1File: filepath.Join(defaultPeerDef, "ingressv1beta1.yaml"),
CCLauncherFile: filepath.Join(defaultPeerDef, "chaincode-launcher.yaml"),
RouteFile: filepath.Join(defaultPeerDef, "route.yaml"),
StoragePath: "/tmp/peerinit",
}
}
func setDefaultOrdererDefinitions(cfg *config.Config) {
cfg.OrdererInitConfig = &ordererinit.Config{
OrdererV2File: filepath.Join(defaultConfigs, "orderer/v2/orderer.yaml"),
OrdererV24File: filepath.Join(defaultConfigs, "orderer/v24/orderer.yaml"),
OrdererV25File: filepath.Join(defaultConfigs, "orderer/v25/orderer.yaml"),
OrdererFile: filepath.Join(defaultConfigs, "orderer/orderer.yaml"),
ConfigTxFile: filepath.Join(defaultConfigs, "orderer/configtx.yaml"),
OUFile: filepath.Join(defaultConfigs, "orderer/ouconfig.yaml"),
InterOUFile: filepath.Join(defaultConfigs, "orderer/ouconfig-inter.yaml"),
DeploymentFile: filepath.Join(defaultOrdererDef, "deployment.yaml"),
PVCFile: filepath.Join(defaultOrdererDef, "pvc.yaml"),
ServiceFile: filepath.Join(defaultOrdererDef, "service.yaml"),
CMFile: filepath.Join(defaultOrdererDef, "configmap.yaml"),
RoleFile: filepath.Join(defaultOrdererDef, "role.yaml"),
ServiceAccountFile: filepath.Join(defaultOrdererDef, "serviceaccount.yaml"),
RoleBindingFile: filepath.Join(defaultOrdererDef, "rolebinding.yaml"),
IngressFile: filepath.Join(defaultOrdererDef, "ingress.yaml"),
Ingressv1beta1File: filepath.Join(defaultOrdererDef, "ingressv1beta1.yaml"),
RouteFile: filepath.Join(defaultOrdererDef, "route.yaml"),
StoragePath: "/tmp/ordererinit",
}
}
func setDefaultConsoleDefinitions(cfg *config.Config) {
cfg.ConsoleInitConfig = &config.ConsoleConfig{
DeploymentFile: filepath.Join(defaultConsoleDef, "deployment.yaml"),
PVCFile: filepath.Join(defaultConsoleDef, "pvc.yaml"),
ServiceFile: filepath.Join(defaultConsoleDef, "service.yaml"),
DeployerServiceFile: filepath.Join(defaultConsoleDef, "deployer-service.yaml"),
CMFile: filepath.Join(defaultConsoleDef, "configmap.yaml"),
ConsoleCMFile: filepath.Join(defaultConsoleDef, "console-configmap.yaml"),
DeployerCMFile: filepath.Join(defaultConsoleDef, "deployer-configmap.yaml"),
RoleFile: filepath.Join(defaultConsoleDef, "role.yaml"),
ServiceAccountFile: filepath.Join(defaultConsoleDef, "serviceaccount.yaml"),
RoleBindingFile: filepath.Join(defaultConsoleDef, "rolebinding.yaml"),
IngressFile: filepath.Join(defaultConsoleDef, "ingress.yaml"),
Ingressv1beta1File: filepath.Join(defaultConsoleDef, "ingressv1beta1.yaml"),
RouteFile: filepath.Join(defaultConsoleDef, "route.yaml"),
NetworkPolicyIngressFile: filepath.Join(defaultConsoleDef, "networkpolicy-ingress.yaml"),
NetworkPolicyDenyAllFile: filepath.Join(defaultConsoleDef, "networkpolicy-denyall.yaml"),
}
}