Simplification of configuration

This removes the duplication of peers and has a seperate entry for remote and local peers
This commit is contained in:
Dan Finneran
2020-02-09 14:47:54 +00:00
parent 6b340146b7
commit 2f78cf79fa
4 changed files with 14 additions and 8 deletions

View File

@@ -94,7 +94,8 @@ var kubeVipSampleManifest = &cobra.Command{
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "kube-vip",
Name: "kube-vip",
Namespace: "kube-system",
},
Spec: appv1.PodSpec{
Containers: []appv1.Container{
@@ -110,7 +111,7 @@ var kubeVipSampleManifest = &cobra.Command{
},
},
Command: []string{
"/kube/vip",
"/kube-vip",
"start",
"-c",
"/vip.yaml",
@@ -128,7 +129,7 @@ var kubeVipSampleManifest = &cobra.Command{
Name: "config",
VolumeSource: appv1.VolumeSource{
HostPath: &appv1.HostPathVolumeSource{
Path: "/path/to/config",
Path: "/etc/kube-vip/config.yaml",
},
},
},

View File

@@ -87,13 +87,18 @@ func (cluster *Cluster) StartCluster(c *kubevip.Config) error {
// Cluster configuration
configuration := raft.Configuration{}
for x := range c.Peers {
// Add Local Peer
configuration.Servers = append(configuration.Servers, raft.Server{
ID: raft.ServerID(c.LocalPeer.ID),
Address: raft.ServerAddress(fmt.Sprintf("%s:%d", c.LocalPeer.Address, c.LocalPeer.Port))})
for x := range c.RemotePeers {
// Build the address from the peer configuration
peerAddress := fmt.Sprintf("%s:%d", c.Peers[x].Address, c.Peers[x].Port)
peerAddress := fmt.Sprintf("%s:%d", c.RemotePeers[x].Address, c.RemotePeers[x].Port)
// Set this peer into the raft configuration
configuration.Servers = append(configuration.Servers, raft.Server{
ID: raft.ServerID(c.Peers[x].ID),
ID: raft.ServerID(c.RemotePeers[x].ID),
Address: raft.ServerAddress(peerAddress)})
}

View File

@@ -45,7 +45,7 @@ func SampleConfig() {
// Generate Sample configuration
c := &Config{
// Generate sample peers
Peers: []RaftPeer{
RemotePeers: []RaftPeer{
RaftPeer{
ID: "server1",
Address: "192.168.0.1",

View File

@@ -6,7 +6,7 @@ import "net/url"
type Config struct {
// Peers are all of the peers within the RAFT cluster
Peers []RaftPeer `yaml:"peers"`
RemotePeers []RaftPeer `yaml:"remotePeers"`
// LocalPeer is the configuration of this host
LocalPeer RaftPeer `yaml:"localPeer"`