Skip to content

Commit

Permalink
Merge pull request #739 from threefoldtech/tfgateway
Browse files Browse the repository at this point in the history
make provision package re-usable by others
  • Loading branch information
zaibon authored Apr 23, 2020
2 parents 0ddc48e + 42405ac commit 95198c1
Show file tree
Hide file tree
Showing 206 changed files with 1,274 additions and 15,972 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,10 @@ jobs:
- name: Run tests
run: |
cd pkg
make coverage
make testrace
env:
GO111MODULE: on

- name: Send coverage
if: success()
run: |
cd pkg
bash <(curl -s https://codecov.io/bash)
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Build binaries
run: |
cd cmds
Expand Down
4 changes: 2 additions & 2 deletions cmds/capacityd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (

"github.com/cenkalti/backoff/v3"

"github.com/threefoldtech/tfexplorer/client"
"github.com/threefoldtech/tfexplorer/models/generated/directory"
"github.com/threefoldtech/zos/pkg/app"
"github.com/threefoldtech/zos/pkg/capacity"
"github.com/threefoldtech/zos/pkg/monitord"
"github.com/threefoldtech/zos/pkg/stubs"
"github.com/threefoldtech/zos/pkg/utils"
"github.com/threefoldtech/zos/tools/client"
"github.com/threefoldtech/zos/tools/explorer/models/generated/directory"

"github.com/rs/zerolog/log"

Expand Down
4 changes: 2 additions & 2 deletions cmds/identityd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
"github.com/jbenet/go-base58"

"github.com/pkg/errors"
"github.com/threefoldtech/tfexplorer/client"
"github.com/threefoldtech/tfexplorer/models/generated/directory"
"github.com/threefoldtech/zos/pkg/app"
"github.com/threefoldtech/zos/pkg/flist"
"github.com/threefoldtech/zos/pkg/geoip"
"github.com/threefoldtech/zos/pkg/network"
"github.com/threefoldtech/zos/pkg/stubs"
"github.com/threefoldtech/zos/pkg/upgrade"
"github.com/threefoldtech/zos/tools/client"
"github.com/threefoldtech/zos/tools/explorer/models/generated/directory"

"github.com/cenkalti/backoff/v3"
"github.com/threefoldtech/zos/pkg"
Expand Down
6 changes: 3 additions & 3 deletions cmds/networkd/addr_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"time"

"github.com/cenkalti/backoff/v3"
"github.com/threefoldtech/tfexplorer/client"
"github.com/threefoldtech/tfexplorer/models/generated/directory"
"github.com/threefoldtech/zos/pkg"
"github.com/threefoldtech/zos/pkg/network/ifaceutil"
"github.com/threefoldtech/zos/pkg/network/types"
"github.com/threefoldtech/zos/pkg/schema"
"github.com/threefoldtech/zos/tools/client"
"github.com/threefoldtech/zos/tools/explorer/models/generated/directory"
"github.com/threefoldtech/tfexplorer/schema"
"github.com/vishvananda/netlink"
)

Expand Down
2 changes: 1 addition & 1 deletion cmds/networkd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/cenkalti/backoff/v3"
"github.com/rs/zerolog/log"
"github.com/threefoldtech/tfexplorer/client"
"github.com/threefoldtech/zbus"
"github.com/threefoldtech/zos/pkg"
"github.com/threefoldtech/zos/pkg/app"
Expand All @@ -19,7 +20,6 @@ import (
"github.com/threefoldtech/zos/pkg/stubs"
"github.com/threefoldtech/zos/pkg/utils"
"github.com/threefoldtech/zos/pkg/version"
"github.com/threefoldtech/zos/tools/client"
)

const redisSocket = "unix:///var/run/redis.sock"
Expand Down
2 changes: 1 addition & 1 deletion cmds/networkd/pubiface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (

"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/threefoldtech/tfexplorer/client"
"github.com/threefoldtech/zos/pkg"
"github.com/threefoldtech/zos/pkg/network"
"github.com/threefoldtech/zos/pkg/network/namespace"
"github.com/threefoldtech/zos/pkg/network/types"
"github.com/threefoldtech/zos/tools/client"
)

// ErrNoPubIface is the error returns by ReadPubIface when no public
Expand Down
51 changes: 30 additions & 21 deletions cmds/provisiond/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"github.com/threefoldtech/zos/pkg"
"github.com/threefoldtech/zos/pkg/app"
"github.com/threefoldtech/zos/pkg/environment"
"github.com/threefoldtech/zos/pkg/provision/explorer"
"github.com/threefoldtech/zos/pkg/provision/primitives"
"github.com/threefoldtech/zos/pkg/provision/primitives/cache"

"github.com/threefoldtech/zos/pkg/stubs"
"github.com/threefoldtech/zos/pkg/utils"
Expand Down Expand Up @@ -81,47 +84,54 @@ func main() {
if err != nil {
log.Fatal().Err(err).Msg("failed to connect to message broker")
}
client, err := zbus.NewRedisClient(msgBrokerCon)
zbusCl, err := zbus.NewRedisClient(msgBrokerCon)
if err != nil {
log.Fatal().Err(err).Msg("fail to connect to message broker server")
}

identity := stubs.NewIdentityManagerStub(client)
identity := stubs.NewIdentityManagerStub(zbusCl)
nodeID := identity.NodeID()

// to get reservation from tnodb
cl, err := app.ExplorerClient()
e, err := app.ExplorerClient()
if err != nil {
log.Fatal().Err(err).Msg("failed to instantiate BCDB client")
}

// keep track of resource unnits reserved and amount of workloads provisionned
statser := &primitives.Counters{}

// to store reservation locally on the node
localStore, err := provision.NewFSStore(filepath.Join(storageDir, "reservations"))
localStore, err := cache.NewFSStore(filepath.Join(storageDir, "reservations"))
if err != nil {
log.Fatal().Err(err).Msg("failed to create local reservation store")
}
// to get the user ID of a reservation
ownerCache := provision.NewCache(localStore, provision.ReservationGetterFromWorkloads(cl.Workloads))

// create context and add middlewares
ctx := context.Background()
ctx = provision.WithZBus(ctx, client)
ctx = provision.WithOwnerCache(ctx, ownerCache)

// From here we start the real provision engine that will live
// for the rest of the life of the node
source := provision.CombinedSource(
provision.PollSource(provision.ReservationPollerFromWorkloads(cl.Workloads), nodeID),
provision.NewDecommissionSource(localStore),
)

engine := provision.New(nodeID.Identity(), source, localStore, cl)
// update stats from the local reservation cache
localStore.Sync(statser)

provisioner := primitives.NewProvisioner(localStore, zbusCl)

engine := provision.New(provision.EngineOps{
NodeID: nodeID.Identity(),
Cache: localStore,
Source: provision.CombinedSource(
provision.PollSource(explorer.NewPoller(e, primitives.WorkloadToProvisionType, primitives.ProvisionOrder), nodeID),
provision.NewDecommissionSource(localStore),
),
Provisioners: provisioner.Provisioners,
Decomissioners: provisioner.Decommissioners,
Feedback: explorer.NewFeedback(e, primitives.ResultToSchemaType),
Signer: identity,
Statser: statser,
})

server.Register(zbus.ObjectID{Name: module, Version: "0.0.1"}, pkg.ProvisionMonitor(engine))

log.Info().
Str("broker", msgBrokerCon).
Msg("starting provision module")

ctx := context.Background()
ctx, _ = utils.WithSignal(ctx)
utils.OnDone(ctx, func(_ error) {
log.Info().Msg("shutting down")
Expand All @@ -141,7 +151,6 @@ func main() {
}

type store interface {
provision.ReservationGetter
provision.ReservationPoller
provision.Feedbacker
}
44 changes: 4 additions & 40 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,81 +4,45 @@ go 1.13

require (
github.com/BurntSushi/toml v0.3.1
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412
github.com/alexflint/go-filemutex v0.0.0-20171028004239-d358565f3c3f
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 // indirect
github.com/blang/semver v3.5.1+incompatible
github.com/cenkalti/backoff/v3 v3.0.0
github.com/containerd/cgroups v0.0.0-20200327175542-b44481373989
github.com/containerd/containerd v1.3.2
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 // indirect
github.com/containerd/fifo v0.0.0-20191213151349-ff969a566b00 // indirect
github.com/containerd/ttrpc v0.0.0-20191028202541-4f1b8fe65a5c // indirect
github.com/containerd/continuity v0.0.0-20200413184840-d3ef23f19fbb // indirect
github.com/containerd/ttrpc v1.0.0 // indirect
github.com/containerd/typeurl v0.0.0-20190911142611-5eb25027c9fd
github.com/containernetworking/cni v0.7.2-0.20190807151350-8c6c47d1c7fc
github.com/containernetworking/plugins v0.8.4
github.com/dave/jennifer v1.3.0
github.com/deckarep/golang-set v1.7.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
github.com/emicklei/dot v0.10.1
github.com/firecracker-microvm/firecracker-go-sdk v0.19.1-0.20200110212531-741fc8cb0f2e
github.com/fsnotify/fsnotify v1.4.7
github.com/gizak/termui/v3 v3.1.0
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/go-openapi/analysis v0.19.7 // indirect
github.com/go-openapi/errors v0.19.3 // indirect
github.com/go-openapi/runtime v0.19.9 // indirect
github.com/go-openapi/spec v0.19.5 // indirect
github.com/go-openapi/strfmt v0.19.4 // indirect
github.com/go-openapi/swag v0.19.6 // indirect
github.com/go-openapi/validate v0.19.5 // indirect
github.com/go-redis/redis v6.15.5+incompatible
github.com/gogo/googleapis v1.3.0 // indirect
github.com/golang/protobuf v1.3.3 // indirect
github.com/gogo/googleapis v1.3.2 // indirect
github.com/gomodule/redigo v2.0.0+incompatible
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf
github.com/google/uuid v1.1.1
github.com/gorilla/handlers v1.4.2
github.com/gorilla/mux v1.7.4
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365
github.com/imdario/mergo v0.3.8 // indirect
github.com/jbenet/go-base58 v0.0.0-20150317085156-6237cf65f3a6
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/runc v0.1.1 // indirect
github.com/opencontainers/runtime-spec v1.0.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.5.1
github.com/rakyll/statik v0.1.7
github.com/rs/zerolog v1.18.0
github.com/rusart/muxprom v0.0.0-20200323164249-36ea051efbe6
github.com/shirou/gopsutil v2.19.11+incompatible
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
github.com/stellar/go v0.0.0-20200325172527-9cabbc6b9388
github.com/stretchr/testify v1.5.1
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2 // indirect
github.com/termie/go-shutil v0.0.0-20140729215957-bcacb06fecae
github.com/threefoldtech/tfexplorer v0.2.5
github.com/threefoldtech/zbus v0.1.3
github.com/tyler-smith/go-bip39 v1.0.2
github.com/urfave/cli v1.22.3
github.com/vishvananda/netlink v1.0.0
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/whs/nacl-sealed-box v0.0.0-20180930164530-92b9ba845d8d
github.com/xdg/stringprep v1.0.0 // indirect
github.com/zaibon/httpsig v0.0.0-20200401133919-ea9cb57b0946
go.etcd.io/bbolt v1.3.3 // indirect
go.mongodb.org/mongo-driver v1.3.0
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4
golang.org/x/net v0.0.0-20200301022130-244492dfa37a
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20191219145116-fa6499c8e75f
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/grpc v1.24.0 // indirect
gopkg.in/yaml.v2 v2.2.7
gotest.tools v2.2.0+incompatible
)
Expand Down
Loading

0 comments on commit 95198c1

Please sign in to comment.