Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Hepto
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
reminec
Hepto
Commits
45e4e373
Commit
45e4e373
authored
2 years ago
by
kaiyou
Browse files
Options
Downloads
Patches
Plain Diff
Use a pflag type for node role
parent
a90bdcbb
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmd/hepto/config.go
+1
-1
1 addition, 1 deletion
cmd/hepto/config.go
pkg/cluster/cluster.go
+19
-3
19 additions, 3 deletions
pkg/cluster/cluster.go
pkg/cluster/config.go
+27
-2
27 additions, 2 deletions
pkg/cluster/config.go
with
47 additions
and
6 deletions
cmd/hepto/config.go
+
1
−
1
View file @
45e4e373
...
@@ -64,5 +64,5 @@ func init() {
...
@@ -64,5 +64,5 @@ func init() {
rootCmd
.
Flags
()
.
IntVar
(
&
config
.
Node
.
Port
,
"discovery-port"
,
7123
,
"TCP port used for discovering the cluster"
)
rootCmd
.
Flags
()
.
IntVar
(
&
config
.
Node
.
Port
,
"discovery-port"
,
7123
,
"TCP port used for discovering the cluster"
)
rootCmd
.
Flags
()
.
StringVar
(
&
config
.
Node
.
Name
,
"name"
,
""
,
"Hepto node name"
)
rootCmd
.
Flags
()
.
StringVar
(
&
config
.
Node
.
Name
,
"name"
,
""
,
"Hepto node name"
)
rootCmd
.
Flags
()
.
StringSliceVar
(
&
config
.
Node
.
Anchors
,
"anchors"
,
[]
string
{},
"List of cluster anchors"
)
rootCmd
.
Flags
()
.
StringSliceVar
(
&
config
.
Node
.
Anchors
,
"anchors"
,
[]
string
{},
"List of cluster anchors"
)
rootCmd
.
Flags
()
.
String
Var
(
&
config
.
Node
.
Role
,
"role"
,
"node"
,
"Node role inside the cluster"
)
rootCmd
.
Flags
()
.
Var
(
&
config
.
Node
.
Role
,
"role"
,
"Node role inside the cluster"
)
}
}
This diff is collapsed.
Click to expand it.
pkg/cluster/cluster.go
+
19
−
3
View file @
45e4e373
...
@@ -3,11 +3,14 @@
...
@@ -3,11 +3,14 @@
package
cluster
package
cluster
import
(
import
(
"context"
"net"
"net"
"forge.tedomum.net/acides/hepto/hepto/pkg/sml"
"forge.tedomum.net/acides/hepto/hepto/pkg/sml"
"forge.tedomum.net/acides/hepto/hepto/pkg/wg"
"forge.tedomum.net/acides/hepto/hepto/pkg/wg"
"forge.tedomum.net/acides/hepto/hepto/pkg/wrappers"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
"go.etcd.io/etcd/server/v3/embed"
)
)
type
Cluster
struct
{
type
Cluster
struct
{
...
@@ -35,7 +38,7 @@ func New(settings *ClusterSettings, node *NodeSettings) (*Cluster, error) {
...
@@ -35,7 +38,7 @@ func New(settings *ClusterSettings, node *NodeSettings) (*Cluster, error) {
}
}
c
.
vpn
=
vpn
c
.
vpn
=
vpn
// Initialize cluster PKI and local keys
// Initialize cluster PKI and local keys
if
node
.
Role
==
"m
aster
"
{
if
node
.
Role
==
M
aster
{
pki
,
err
:=
NewClusterPKI
(
"pki"
)
pki
,
err
:=
NewClusterPKI
(
"pki"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -51,7 +54,7 @@ func New(settings *ClusterSettings, node *NodeSettings) (*Cluster, error) {
...
@@ -51,7 +54,7 @@ func New(settings *ClusterSettings, node *NodeSettings) (*Cluster, error) {
c
.
certs
=
certs
c
.
certs
=
certs
// Initialize node meta
// Initialize node meta
c
.
ml
.
Meta
.
VpnKey
=
vpn
.
PubKey
.
String
()
c
.
ml
.
Meta
.
VpnKey
=
vpn
.
PubKey
.
String
()
c
.
ml
.
Meta
.
Role
=
node
.
Role
c
.
ml
.
Meta
.
Role
=
string
(
node
.
Role
)
// Initialize cluster state
// Initialize cluster state
c
.
ml
.
State
.
PKI
=
c
.
pki
c
.
ml
.
State
.
PKI
=
c
.
pki
c
.
ml
.
State
.
Certificates
=
make
(
map
[
string
]
*
NodeCerts
)
c
.
ml
.
State
.
Certificates
=
make
(
map
[
string
]
*
NodeCerts
)
...
@@ -71,10 +74,11 @@ func (c *Cluster) Run() error {
...
@@ -71,10 +74,11 @@ func (c *Cluster) Run() error {
for
{
for
{
select
{
select
{
case
<-
events
:
case
<-
events
:
if
c
.
node
.
Role
==
"m
aster
"
{
if
c
.
node
.
Role
==
M
aster
{
c
.
handlePKI
()
c
.
handlePKI
()
}
}
c
.
updateVPN
()
c
.
updateVPN
()
c
.
updateServices
()
case
<-
instrUpdates
:
case
<-
instrUpdates
:
c
.
networking
.
MTU
=
instr
.
MinMTU
()
c
.
networking
.
MTU
=
instr
.
MinMTU
()
c
.
updateVPN
()
c
.
updateVPN
()
...
@@ -107,3 +111,15 @@ func (c *Cluster) updateVPN() {
...
@@ -107,3 +111,15 @@ func (c *Cluster) updateVPN() {
logrus
.
Debugf
(
"updating VPN mesh, %d peers, MTU %d"
,
len
(
peers
),
c
.
networking
.
MTU
)
logrus
.
Debugf
(
"updating VPN mesh, %d peers, MTU %d"
,
len
(
peers
),
c
.
networking
.
MTU
)
c
.
vpn
.
Update
(
peers
,
c
.
networking
.
MTU
)
c
.
vpn
.
Update
(
peers
,
c
.
networking
.
MTU
)
}
}
func
(
c
*
Cluster
)
updateServices
()
{
ctx
:=
context
.
Background
()
if
c
.
node
.
Role
==
Master
{
etcdConfig
:=
embed
.
NewConfig
()
etcdConfig
.
Dir
=
"/etcd"
_
,
err
:=
wrappers
.
ETCd
(
ctx
,
etcdConfig
)
if
err
!=
nil
{
logrus
.
Fatal
(
err
)
}
}
}
This diff is collapsed.
Click to expand it.
pkg/cluster/config.go
+
27
−
2
View file @
45e4e373
package
cluster
package
cluster
import
(
import
(
"errors"
"net"
"net"
"forge.tedomum.net/acides/hepto/hepto/pkg/types"
"forge.tedomum.net/acides/hepto/hepto/pkg/types"
...
@@ -16,8 +17,8 @@ type ClusterSettings struct {
...
@@ -16,8 +17,8 @@ type ClusterSettings struct {
type
NodeSettings
struct
{
type
NodeSettings
struct
{
// Node name, must be unique inside a cluster
// Node name, must be unique inside a cluster
Name
string
Name
string
// Node role
, TODO: switch to proper types
// Node role
Role
string
Role
NodeRole
// Port for initial memberlist negotiations
// Port for initial memberlist negotiations
Port
int
Port
int
// Public IPv6 address for the node
// Public IPv6 address for the node
...
@@ -26,6 +27,30 @@ type NodeSettings struct {
...
@@ -26,6 +27,30 @@ type NodeSettings struct {
Anchors
[]
string
Anchors
[]
string
}
}
type
NodeRole
string
const
(
Master
NodeRole
=
"master"
Node
=
"node"
)
func
(
r
*
NodeRole
)
String
()
string
{
return
string
(
*
r
)
}
func
(
r
*
NodeRole
)
Type
()
string
{
return
"NodeRole"
}
func
(
r
*
NodeRole
)
Set
(
v
string
)
error
{
cast
:=
(
NodeRole
)(
v
)
if
cast
==
Master
||
cast
==
Node
{
*
r
=
(
NodeRole
)(
cast
)
return
nil
}
return
errors
.
New
(
"wrong node type"
)
}
type
ClusterNetworking
struct
{
type
ClusterNetworking
struct
{
NodeNet
types
.
Address
NodeNet
types
.
Address
NodeAddress
types
.
Address
NodeAddress
types
.
Address
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment