From b19a93e9844fd324763c3a1dc99bc8e6f8b882a4 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Tue, 9 Aug 2022 08:01:54 +0200 Subject: [PATCH] Merge pull request #55 from c3os-io/feature/cluster-provider Abstract Cluster Provisioning with Cluster Plugins --- internal/agent/agent.go | 3 ++- internal/agent/install.go | 3 ++- internal/agent/notify.go | 23 +++++++++++++++++++++++ internal/bus/bus.go | 4 +++- internal/provider/bootstrap.go | 3 ++- internal/provider/bootstrap_test.go | 3 ++- internal/provider/challenge.go | 3 ++- internal/provider/challenge_test.go | 3 ++- internal/provider/install.go | 3 ++- 9 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 internal/agent/notify.go diff --git a/internal/agent/agent.go b/internal/agent/agent.go index baf305e..47eafde 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -6,9 +6,10 @@ import ( "os" "path/filepath" + events "github.com/c3os-io/c3os/sdk/bus" + "github.com/c3os-io/c3os/internal/bus" machine "github.com/c3os-io/c3os/internal/machine" - events "github.com/c3os-io/c3os/pkg/bus" config "github.com/c3os-io/c3os/pkg/config" "github.com/nxadm/tail" ) diff --git a/internal/agent/install.go b/internal/agent/install.go index b7dbf81..3c1b9b1 100644 --- a/internal/agent/install.go +++ b/internal/agent/install.go @@ -10,7 +10,8 @@ import ( "syscall" "time" - events "github.com/c3os-io/c3os/pkg/bus" + events "github.com/c3os-io/c3os/sdk/bus" + config "github.com/c3os-io/c3os/pkg/config" "github.com/c3os-io/c3os/internal/bus" diff --git a/internal/agent/notify.go b/internal/agent/notify.go new file mode 100644 index 0000000..d9f5063 --- /dev/null +++ b/internal/agent/notify.go @@ -0,0 +1,23 @@ +package agent + +import ( + "github.com/c3os-io/c3os/internal/bus" + "github.com/c3os-io/c3os/pkg/config" + events "github.com/c3os-io/c3os/sdk/bus" + "github.com/mudler/go-pluggable" +) + +func Notify(event string, dirs []string) error { + bus.Manager.Initialize() + + c, err := config.Scan(config.Directories(dirs...)) + if err != nil { + return err + } + + _, err = bus.Manager.Publish(pluggable.EventType(event), events.EventPayload{ + Config: c.String(), + }) + + return err +} diff --git a/internal/bus/bus.go b/internal/bus/bus.go index 1189a3d..3f2fbf3 100644 --- a/internal/bus/bus.go +++ b/internal/bus/bus.go @@ -5,7 +5,8 @@ import ( "os" "os/exec" - "github.com/c3os-io/c3os/pkg/bus" + "github.com/c3os-io/c3os/sdk/bus" + "github.com/mudler/go-pluggable" ) @@ -15,6 +16,7 @@ var Manager = &Bus{ []pluggable.EventType{ bus.EventBootstrap, bus.EventChallenge, + bus.EventBoot, bus.EventInstall, }, ), diff --git a/internal/provider/bootstrap.go b/internal/provider/bootstrap.go index 8a097a1..987a4b0 100644 --- a/internal/provider/bootstrap.go +++ b/internal/provider/bootstrap.go @@ -6,6 +6,8 @@ import ( "fmt" "strings" + "github.com/c3os-io/c3os/sdk/bus" + logging "github.com/ipfs/go-log" edgeVPNClient "github.com/mudler/edgevpn/api/client" "go.uber.org/zap" @@ -18,7 +20,6 @@ import ( "github.com/c3os-io/c3os/internal/role" "github.com/c3os-io/c3os/internal/utils" - "github.com/c3os-io/c3os/pkg/bus" "github.com/c3os-io/c3os/pkg/config" "github.com/mudler/edgevpn/api/client/service" "github.com/mudler/go-pluggable" diff --git a/internal/provider/bootstrap_test.go b/internal/provider/bootstrap_test.go index 9c70785..0f23337 100644 --- a/internal/provider/bootstrap_test.go +++ b/internal/provider/bootstrap_test.go @@ -5,9 +5,10 @@ import ( "io/ioutil" "os" + "github.com/c3os-io/c3os/sdk/bus" + . "github.com/c3os-io/c3os/internal/provider" providerConfig "github.com/c3os-io/c3os/internal/provider/config" - "github.com/c3os-io/c3os/pkg/bus" "github.com/mudler/go-pluggable" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/internal/provider/challenge.go b/internal/provider/challenge.go index b7b2639..5f21c23 100644 --- a/internal/provider/challenge.go +++ b/internal/provider/challenge.go @@ -3,8 +3,9 @@ package provider import ( "encoding/json" + "github.com/c3os-io/c3os/sdk/bus" + providerConfig "github.com/c3os-io/c3os/internal/provider/config" - "github.com/c3os-io/c3os/pkg/bus" "github.com/c3os-io/c3os/pkg/config" "github.com/mudler/go-nodepair" diff --git a/internal/provider/challenge_test.go b/internal/provider/challenge_test.go index cbd0c65..06f8c02 100644 --- a/internal/provider/challenge_test.go +++ b/internal/provider/challenge_test.go @@ -5,10 +5,11 @@ import ( "io/ioutil" "os" + "github.com/c3os-io/c3os/sdk/bus" + providerConfig "github.com/c3os-io/c3os/internal/provider/config" . "github.com/c3os-io/c3os/internal/provider" - "github.com/c3os-io/c3os/pkg/bus" "github.com/mudler/go-pluggable" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/internal/provider/install.go b/internal/provider/install.go index ac25fb3..e25721c 100644 --- a/internal/provider/install.go +++ b/internal/provider/install.go @@ -4,7 +4,8 @@ import ( "context" "encoding/json" - "github.com/c3os-io/c3os/pkg/bus" + "github.com/c3os-io/c3os/sdk/bus" + "github.com/mudler/go-nodepair" "github.com/mudler/go-pluggable" )