Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Reduce required config values by setting reasonable defaults. (#22)
Browse files Browse the repository at this point in the history
The entries required by the base config have been reduced to: nodes.number, consensus, quorum version, and tessera version.  An example of the minimal config is added under `examples/config/qubes-minimal.yaml` and shown here: 

```
nodes:
  number: 4
quorum:
  # supported: (raft | istanbul)
  consensus: istanbul
  quorum:
    Quorum_Version: 2.2.5
  tm:
    # (tessera|constellation)
    Name: tessera
    Tm_Version: 0.11
```

All other values will receive reasonable defaults, e.g. geth ports will be the default geth ports. The default values are as follows: 
```
Raft_Port = 50401
Tm_Port = 9001
Node_RPCPort = 8545
geth p2p port = 30303
service.type =  "NodePort"
geth.verbosity = 9
geth.chainId = 1101
Tessera_Config_Dir = "out/config"   
Genesis_File = "out/config/genesis.json"
Permissioned_Nodes_File = "out/config/permissioned-nodes.json"
Key_Dir_Base = "out/config"
Node_DataDir = "/etc/quorum/qdata"
```
The default values will be overridden, If set in the config yaml used to generate the network.
  • Loading branch information
libby authored Apr 28, 2020
1 parent 663fd34 commit dfd1d8d
Show file tree
Hide file tree
Showing 18 changed files with 179 additions and 92 deletions.
18 changes: 18 additions & 0 deletions examples/config/qubes-minimal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This is the simplest configuration file, only specifying:
# 1. the number of nodes
# 2. quorum's consensus (istanbul IBFT, or Raft)
# 3. the version of the quorum container and the transaction manger container.
# Reasonable defaults will be chosen for the rest of the values, ports, associated K8s resources, etc.

# number of nodes to deploy
nodes:
number: 4
quorum:
# supported: (raft | istanbul)
consensus: istanbul
quorum:
Quorum_Version: 2.2.5
tm:
# (tessera|constellation)
Name: tessera
Tm_Version: 0.11
67 changes: 57 additions & 10 deletions qubernetes
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,59 @@ puts "using config file: " + @CONFIG_FILE
@config = YAML.load_file(@CONFIG_FILE)

@nodes = YAML.load_file("nodes.yaml")["nodes"]
@Raft_Port = @config["quorum"]["quorum"]["Raft_Port"]
@Node_RPCPort = @config["geth"]["Node_RPCPort"]
@NodeP2P_ListenAddr = @config["geth"]["NodeP2P_ListenAddr"]

## set defaults for config if not set, else use the values from the config.

# used in deployment.yaml.erb to set quorum data dir.
@Node_DataDir = "/etc/quorum/qdata"
if @config["quorum"]["Node_DataDir"]
@Node_DataDir = @config["quorum"]["Node_DataDir"]
end

# used by quorum-shared-config.yaml.erb and quorum-keystore.yaml.erb to load keys.
@Key_Dir_Base = "out/config"
if @config["quorum"]["Key_Dir_Base"]
@Key_Dir_Base = @config["quorum"]["Key_Dir_Base"]
end

# used by quorum-shared-config.yaml.erb to load the permissioned-nodes.json in configmaps
@Permissioned_Nodes_File = "out/config/permissioned-nodes.json"
if @config["quorum"]["Permissioned_Nodes_File"]
@Permissioned_Nodes_File = @config["quorum"]["Permissioned_Nodes_File"]
end

# used by quorum-genesis-config.yaml.erb and quorum-shared-config.yaml.erb
@Genesis_File = "out/config/genesis.json"
if @config["quorum"]["Genesis_File"]
@Genesis_File = @config["quorum"]["Genesis_File"]
end

# used in quorum-shared-config.yaml.erb to make tessera config available to deployments.
@Tessera_Config_Dir = "out/config"
if @config["quorum"]["tm"]["Tessera_Config_Dir"]
@Tessera_Config_Dir = @config["quorum"]["tm"]["Tessera_Config_Dir"]
end

## default the ports if they aren't set
@Raft_Port = 50401
if @config["quorum"]["quorum"]["Raft_Port"]
@Raft_Port = @config["quorum"]["quorum"]["Raft_Port"]
end

@Tm_Port = 9001
if @config["quorum"]["tm"]["Port"]
@Tm_Port = @config["quorum"]["tm"]["Port"]
end

@Node_RPCPort = 8545
if @config["geth"] and @config["geth"]["Node_RPCPort"]
@Node_RPCPort = @config["geth"]["Node_RPCPort"]
end

@NodeP2P_ListenAddr = 30303
if @config["geth"] and @config["geth"]["NodeP2P_ListenAddr"]
@NodeP2P_ListenAdd = @config["geth"]["NodeP2P_ListenAddr"]
end


# Generate deployments in a single file, or in separate files.
Expand Down Expand Up @@ -81,28 +131,25 @@ end

@base_template_path = "templates/k8s"
#puts (sed_string)
puts "PVC start"
puts "PVC"
if @Storage_Type == "PVC"
File.open("out/00-quorum-persistent-volumes.yaml", "w") do |f|
f.puts (ERB.new(File.read(@base_template_path + "/persistent-volumes.yaml.erb"), nil, "-").result)
end
end
puts "PVC end"
File.open("out/01-quorum-genesis.yaml", "w") do |f|
f.puts (ERB.new(File.read(@base_template_path + "/quorum-genesis-config.yaml.erb"), nil, "-").result)
end
File.open("out/02-quorum-shared-config.yaml", "w") do |f|
f.puts (ERB.new(File.read(@base_template_path + "/quorum-shared-config.yaml.erb"), nil, "-").result)
end

# Create the service resources
File.open("out/03.0-quorum-services.yaml", "w") do |f|
f.puts (ERB.new(File.read(@base_template_path + "/quorum-services.yaml.erb"), nil, "-").result)
end


# Create the Ingress resources if they are configured
if @config["service"]["Ingress"]
if @config["service"] and @config["service"]["Ingress"]
File.open("out/03.1-quorum-ingress.yaml", "w") do |f|
f.puts (ERB.new(File.read(@base_template_path + "/quorum-ingress.yaml.erb"), nil, "-").result)
end
Expand All @@ -114,12 +161,12 @@ File.open("out/04-quorum-keyconfigs.yaml", "w") do |f|
end

# if a network policy was requested create one for the namespace (NetworkPolicy = true in yaml config)
if @config["service"]["NetworkPolicy"]
if @config["service"] and @config["service"]["NetworkPolicy"]
File.open("out/05-quorum-network-policy.yaml", "w") do |f|
f.puts (ERB.new(File.read(@base_template_path + "/network-policy.yaml.erb"), nil, "-").result)
end
end

puts "deployments"
@Kubectl_Cmd=" $> kubectl apply -f out"
if @sep_deployment_files
`mkdir -p out/deployments`
Expand Down
51 changes: 45 additions & 6 deletions quorum-config
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,53 @@ puts "using config file: " + @CONFIG_FILE
@config = YAML.load_file(@CONFIG_FILE)
@nodes = YAML.load_file("nodes.yaml")["nodes"]

@Raft_Port = @config["quorum"]["quorum"]["Raft_Port"]
@Permissioned_Nodes_File = @config["quorum"]["Permissioned_Nodes_File"]
@Genesis_File = @config["quorum"]["Genesis_File"]
## set defaults for config if not set, else use the values from the config.

@Tessera_Config_Dir = @config["quorum"]["tm"]["Tessera_Config_Dir"]
# directory where the genesis.json will be stored after it is generated.
@Genesis_File = "out/config/genesis.json"
if @config["quorum"]["Genesis_File"]
@Genesis_File = @config["quorum"]["Genesis_File"]
end

# used by genesis.json.erb, gen-keys.sh.erb, and .
@Key_Dir_Base = "out/config"
if @config["quorum"]["Key_Dir_Base"]
@Key_Dir_Base = @config["quorum"]["Key_Dir_Base"]
end

# used in tessera-config-*.json.erb(s)
@Node_DataDir = "/etc/quorum/qdata"
if @config["quorum"]["Node_DataDir"]
@Node_DataDir = @config["quorum"]["Node_DataDir"]
end

# directory where the permissioned-node.json will be stored after it is generated.
@Permissioned_Nodes_File = "out/config/permissioned-nodes.json"
if @config["quorum"]["Permissioned_Nodes_File"]
@Permissioned_Nodes_File = @config["quorum"]["Permissioned_Nodes_File"]
end

# directory where the tessera-config.json files. will be stored after it is generated.
@Tessera_Config_Dir = "out/config"
if @config["quorum"]["tm"]["Tessera_Config_Dir"]
@Tessera_Config_Dir = @config["quorum"]["tm"]["Tessera_Config_Dir"]
end

@Node_RPCPort = @config["geth"]["Node_RPCPort"]
@NodeP2P_ListenAddr = @config["geth"]["NodeP2P_ListenAddr"]
## set ports needed for the quorum templates
# Tm_Port used in tessera config templates
@Tm_Port = 9001
if @config["quorum"]["tm"]["Port"]
@Tm_Port = @config["quorum"]["tm"]["Port"]
end
# used by permissioned-nodes.json.erb to set enode URLs
@Raft_Port = 50401
if @config["quorum"]["quorum"]["Raft_Port"]
@Raft_Port = @config["quorum"]["quorum"]["Raft_Port"]
end
@NodeP2P_ListenAddr = 30303
if @config["geth"] and @config["geth"]["NodeP2P_ListenAddr"]
@NodeP2P_ListenAdd = @config["geth"]["NodeP2P_ListenAddr"]
end

#####################################################
# Generate genesis.json and permissioned-nodes.json
Expand Down
6 changes: 6 additions & 0 deletions quorum-keygen
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ puts "using config file: " + @CONFIG_FILE

@base_template_path = "templates/quorum"

# used by gen-keys.sh.erb
@Key_Dir_Base = "out/config"
if @config["quorum"]["Key_Dir_Base"]
@Key_Dir_Base = @config["quorum"]["Key_Dir_Base"]
end

File.open(@base_template_path + "/gen-node-keys.sh", "w") do |f|
f.puts (ERB.new(File.read(@base_template_path + "/gen-keys.sh.erb"), nil, "-").result)
end
Expand Down
5 changes: 0 additions & 5 deletions templates/k8s/network-policy.yaml.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
<%
@TM_Port = @config["quorum"]["tm"]["Port"]
@Node_RPCPort = @config["geth"]["Node_RPCPort"]
@NodeP2P_ListenAddr = @config["geth"]["NodeP2P_ListenAddr"]
%>
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
Expand Down
33 changes: 19 additions & 14 deletions templates/k8s/persistent-volumes.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@ end
# default the capacity to 200Mi if not set in qubernetes.yaml file.
@Capacity = "200Mi"
@Annotations = []

## TODO: changing the basic config to not longer use `type` under storage, as the only type supported not is PVC
## staying backwards compatible with the old configuration style for now, `storage: type: PVC` but this will
## be removed in the future and only `storage: PVC: [Annotations: Capacity]` will be supported.
if @config["quorum"]["storage"]["PVC"]
@Storage_Config = @config["quorum"]["storage"]["PVC"]
else
@Storage_Config = @config["quorum"]["storage"]
end

if @Storage_Config["Capacity"]
@Capacity = @Storage_Config["Capacity"]
end
if @config["quorum"]["storage"]["PVC"] and @config["quorum"]["storage"]["PVC"]["annotations"]
@Annotations = @config["quorum"]["storage"]["PVC"]["annotations"]
end
if @config["quorum"]["storage"]["PVC"] and @config["quorum"]["storage"]["PVC"]["storageClassName"]
@Storage_Class_Name = "storageClassName: "+ @config["quorum"]["storage"]["PVC"]["storageClassName"]
# if the user set storage params, override the defaults, and add their config.
if @config["quorum"]["storage"]
if @config["quorum"]["storage"]["PVC"]
@Storage_Config = @config["quorum"]["storage"]["PVC"]
@Capacity = @Storage_Config["Capacity"]
else
@Storage_Config = @config["quorum"]["storage"]
@Capacity = @Storage_Config["Capacity"]
end

puts "got storage config"

if @Storage_Config["annotations"]
@Annotations = @Storage_Config["annotations"]
end
if @Storage_Config["storageClassName"]
@Storage_Class_Name = "storageClassName: "+ @Storage_Config["storageClassName"]
end

end
-%>
Expand Down
24 changes: 14 additions & 10 deletions templates/k8s/quorum-deployment.yaml.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#<%- File.readlines("#{@Keystore_Dir}/#{@Node_Key_Dir}/enode").each do |line| -%><%= line -%><% end -%>
#<%- File.readlines("#{@Key_Dir_Base}/#{@Node_Key_Dir}/enode").each do |line| -%><%= line -%><% end -%>
<%
@Service_Prefix = (@Node_UserIdent.upcase).gsub("-", "_")
@Geth_Verbosity = @config["geth"]["verbosity"]
@Geth_Network_Id = @config["geth"]["network"]["id"]
@Node_RPCPort = @config["geth"]["Node_RPCPort"]
@NodeP2P_ListenAddr = @config["geth"]["NodeP2P_ListenAddr"]

if @config["geth"]["Geth_Startup_Params"]
@Geth_Verbosity = 9
if @config["geth"] and @config["geth"]["verbosity"]
@Geth_Verbosity = @config["geth"]["verbosity"]
end

@Geth_Network_Id = 1101
if @config["geth"] and @config["geth"]["network"] and @config["geth"]["network"]["id"]
@Geth_Network_Id = @config["geth"]["network"]["id"]
end

if @config["geth"] and @config["geth"]["Geth_Startup_Params"]
@Geth_Startup_Params = @config["geth"]["Geth_Startup_Params"]
else
@Geth_Startup_Params = ""
end

@Node_DataDir = @config["quorum"]["Node_DataDir"]
@Quorum_Version = @config["quorum"]["quorum"]["Quorum_Version"]
# default quorumengineering/quorum
if @config["quorum"]["quorum"]["Docker_Repo"]
Expand All @@ -27,7 +32,6 @@ else
@Tm_Docker_Repo = "quorumengineering"
end
@Tm_Version = @config["quorum"]["tm"]["Tm_Version"]
@Tm_Port = @config["quorum"]["tm"]["Port"]
@Tm_Name = @config["quorum"]["tm"]["Name"]
# Storage for data directories, default PVC.
@Storage_Type = "PVC"
Expand Down Expand Up @@ -212,7 +216,7 @@ spec:

chmod 644 $QUORUM_DATA_DIR/keystore/key;
<%- if @Tm_Name == "tessera" -%>
<%- if @Security_Context -%> <%# if a security context is set, assume we cannot install packages, e.g. curl, so sleep for 60 to give the TM time to startup. %>
<%- if @Security_Context != [] -%> <%# if a security context is set, assume we cannot install packages, e.g. curl, so sleep for 60 to give the TM time to startup. %>
echo sleeping for 60 seconds to wait for the transaction manager to startup.
sleep 60;
<%- else -%> <%# if a security context not set, assume we can install packages, e.g. curl, we can do a check to see when the TM comes up. %>
Expand Down Expand Up @@ -268,7 +272,7 @@ spec:
- name: THIS_NODE_ID
value: <%= @Node_UserIdent%>
- name: THIS_ENODE
value: <%- File.readlines("#{@Keystore_Dir}/#{@Node_Key_Dir}/enode").each do |line| -%><%= line -%><% end -%>
value: <%- File.readlines("#{@Key_Dir_Base}/#{@Node_Key_Dir}/enode").each do |line| -%><%= line -%><% end -%>
volumeMounts:
- name: genesis-config-persistent-storage
mountPath: /etc/quorum/genesis/genesis-geth.json
Expand Down
4 changes: 0 additions & 4 deletions templates/k8s/quorum-genesis-config.yaml.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<%-
@Genesis_File = @config["quorum"]["Genesis_File"]
%>
<%- if @Namespace != "" %>
apiVersion: v1
kind: Namespace
Expand Down
5 changes: 0 additions & 5 deletions templates/k8s/quorum-ingress.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ def set_node_template_vars(values)
return
end

@Service_Prefix = (@Node_UserIdent.upcase).gsub("-", "_")
@TM_Port = @config["quorum"]["tm"]["Port"]
@Node_RPCPort = @config["geth"]["Node_RPCPort"]
@NodeP2P_ListenAddr = @config["geth"]["NodeP2P_ListenAddr"]

if @config["service"]["Ingress"] then
@Ingress = true
# OneForAll
Expand Down
11 changes: 5 additions & 6 deletions templates/k8s/quorum-keystore.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def set_node_template_vars(values)
end

# keys are named the same inside their respective directories.
@Keystore_Dir = @config["quorum"]["Key_Dir_Base"]
-%>
Expand All @@ -31,12 +30,12 @@ metadata:
name: <%= @Node_UserIdent %>-tm-key-config
data:
tm.key: |-
<%- File.readlines("#{@Keystore_Dir}/#{@Node_Key_Dir}/tm.key").each do |line| -%>
<%- File.readlines("#{@Key_Dir_Base}/#{@Node_Key_Dir}/tm.key").each do |line| -%>
<%= line -%>
<% end -%>

tm.pub: |-
<%- File.readlines("#{@Keystore_Dir}/#{@Node_Key_Dir}/tm.pub").each do |line| -%>
<%- File.readlines("#{@Key_Dir_Base}/#{@Node_Key_Dir}/tm.pub").each do |line| -%>
<%= line -%>
<% end -%>

Expand All @@ -53,7 +52,7 @@ metadata:
name: <%= @Node_UserIdent %>-nodekey-config
data:
nodekey: |
<%- File.readlines("#{@Keystore_Dir}/#{@Node_Key_Dir}/nodekey").each do |line| -%>
<%- File.readlines("#{@Key_Dir_Base}/#{@Node_Key_Dir}/nodekey").each do |line| -%>
<%= line -%>
<% end -%>

Expand All @@ -70,7 +69,7 @@ metadata:
name: <%= @Node_UserIdent %>-enode-config
data:
enode: |
<%- File.readlines("#{@Keystore_Dir}/#{@Node_Key_Dir}/enode").each do |line| -%>
<%- File.readlines("#{@Key_Dir_Base}/#{@Node_Key_Dir}/enode").each do |line| -%>
<%= line -%>
<% end -%>

Expand All @@ -88,7 +87,7 @@ metadata:
data:
key: |-

<%- @Keystore_File=Dir[@Keystore_Dir + "/" + @Node_Key_Dir + "/UTC*"][0] %>
<%- @Keystore_File=Dir[@Key_Dir_Base + "/" + @Node_Key_Dir + "/UTC*"][0] %>
<%- File.readlines("#{@Keystore_File}").each do |line| -%>
<%= line -%>
<% end -%>
Expand Down
Loading

0 comments on commit dfd1d8d

Please sign in to comment.