This repository has been archived by the owner on Dec 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Container Hosts/Projects register in Consul + refactoring
Reorganized a lot of code to do with external connections and moved them out of the connections package Saves project metadata in Consul KV under its windlass_worker@hostname for below reasons Worker will check Consul KV for any projects associated with it on startup and spin up goroutine for health check Same topic, implemented Ping for LXD container host for said health check On creation of a project, it is also registered in Consul, KV and service LXD Host repo keeps in-memory the client TLS certs/keys while also persisting them in Vault for on next startup EstablishConnections checks connections on startup instead. Do we wanna change this to be in degraded state rather than outright not running?
- Loading branch information
Showing
18 changed files
with
564 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,39 @@ | ||
package connections | ||
|
||
import ( | ||
consul "github.com/hashicorp/consul/api" | ||
vault "github.com/hashicorp/vault/api" | ||
|
||
lxd "github.com/lxc/lxd/client" | ||
|
||
"github.com/Strum355/log" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
type Connections struct { | ||
lxd lxd.ContainerServer | ||
consul *ConsulProvider | ||
vault *VaultProvider | ||
} | ||
|
||
var group Connections | ||
"github.com/UCCNetworkingSociety/Windlass-worker/app/repositories/providers" | ||
) | ||
|
||
func EstablishConnections() error { | ||
func TestConnections() error { | ||
var err error | ||
|
||
if _, err = GetConsul(); err != nil { | ||
return err | ||
} | ||
|
||
if _, err = GetVault(); err != nil { | ||
return err | ||
} | ||
|
||
if err := group.consul.GetAndSetSharedSecret(); err != nil { | ||
if err = testConsul(); err != nil { | ||
return err | ||
} | ||
|
||
if _, err = GetLXD(); err != nil { | ||
if err = testVault(); err != nil { | ||
return err | ||
} | ||
|
||
log.Debug("connections established") | ||
log.Debug("connections tested successfully") | ||
return nil | ||
} | ||
|
||
func Close() { | ||
|
||
func testVault() error { | ||
_, err := providers.NewVaultProvider() | ||
return err | ||
} | ||
|
||
func GetVault() (*VaultProvider, error) { | ||
if group.vault != nil { | ||
return group.vault, nil | ||
} | ||
|
||
config := vault.Config{ | ||
Address: viper.GetString("vault.url"), | ||
} | ||
|
||
provider, err := newVaultProvider(&config) | ||
func testConsul() error { | ||
p, err := providers.NewConsulProvider() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
provider.client.SetToken(viper.GetString("vault.token")) | ||
|
||
return provider, nil | ||
} | ||
|
||
func GetConsul() (*ConsulProvider, error) { | ||
if group.consul != nil { | ||
return group.consul, nil | ||
} | ||
|
||
config := consul.Config{ | ||
Address: viper.GetString("consul.url"), | ||
Token: viper.GetString("consul.token"), | ||
} | ||
|
||
provider, err := newConsulProvider(&config) | ||
if err != nil { | ||
return nil, NewConnectionError(err, "Consul") | ||
} | ||
|
||
if err := provider.Register(); err != nil { | ||
return nil, NewConnectionError(err, "Consul") | ||
} | ||
|
||
group.consul = provider | ||
|
||
return group.consul, nil | ||
} | ||
|
||
func GetLXD() (lxd.ContainerServer, error) { | ||
if group.lxd != nil { | ||
return group.lxd, nil | ||
return err | ||
} | ||
|
||
lxdConn, err := lxd.ConnectLXDUnix(viper.GetString("lxd.socket"), &lxd.ConnectionArgs{ | ||
UserAgent: "Windlass", | ||
}) | ||
if err != nil { | ||
return nil, NewConnectionError(err, "LXD") | ||
if err := p.Register(); err != nil { | ||
return err | ||
} | ||
|
||
group.lxd = lxdConn | ||
|
||
return lxdConn, nil | ||
return p.GetAndSetSharedSecret() | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.