Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/provision/explorer/source.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package explorer

import (
"errors"
"fmt"
"sort"

"github.com/rs/zerolog/log"

"github.com/threefoldtech/tfexplorer/client"
"github.com/threefoldtech/zos/pkg"
"github.com/threefoldtech/zos/pkg/provision"
"github.com/threefoldtech/zos/pkg/provision/primitives"
)

// Poller is an implementation of the provision.ReservationPoller
Expand Down Expand Up @@ -41,6 +45,10 @@ func (r *Poller) Poll(nodeID pkg.Identifier, from uint64) ([]*provision.Reservat
for _, wl := range list {
r, err := r.inputConv(wl)
if err != nil {
if errors.Is(err, primitives.ErrUnsupportedWorkload) {
log.Warn().Err(err).Msgf("received unsupported workload, skipping")
continue
}
return nil, 0, err
}

Expand Down
71 changes: 71 additions & 0 deletions pkg/provision/explorer/source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package explorer

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/threefoldtech/tfexplorer/client"
"github.com/threefoldtech/tfexplorer/models/generated/workloads"
wrklds "github.com/threefoldtech/tfexplorer/pkg/workloads"
"github.com/threefoldtech/tfexplorer/schema"
"github.com/threefoldtech/zos/pkg"
"github.com/threefoldtech/zos/pkg/provision/primitives"
)

type clientMock struct {
workloads []workloads.ReservationWorkload
}

func (c *clientMock) Create(reservation workloads.Reservation) (resp wrklds.ReservationCreateResponse, err error) {
return
}
func (c *clientMock) List(nextAction *workloads.NextActionEnum, customerTid int64, page *client.Pager) (reservation []workloads.Reservation, err error) {
return
}
func (c *clientMock) Get(id schema.ID) (reservation workloads.Reservation, err error) {
return
}
func (c *clientMock) SignProvision(id schema.ID, user schema.ID, signature string) error {
return nil
}
func (c *clientMock) SignDelete(id schema.ID, user schema.ID, signature string) error {
return nil
}

func (c *clientMock) Workloads(nodeID string, from uint64) ([]workloads.ReservationWorkload, uint64, error) {
return c.workloads, 0, nil
}
func (c *clientMock) WorkloadGet(gwid string) (result workloads.ReservationWorkload, err error) {
return
}
func (c *clientMock) WorkloadPutResult(nodeID, gwid string, result workloads.Result) error {
return nil
}
func (c *clientMock) WorkloadPutDeleted(nodeID, gwid string) error {
return nil
}

func TestSkipUnsupportedType(t *testing.T) {
type UnsupportedWorkload struct{}

client := &clientMock{
workloads: []workloads.ReservationWorkload{
{
Content: workloads.Container{},
},
{
Content: UnsupportedWorkload{},
},
},
}

p := &Poller{
wl: client,
inputConv: primitives.WorkloadToProvisionType,
}

result, _, err := p.Poll(pkg.StrIdentifier(""), 0)
assert.NoError(t, err)
assert.Equal(t, 1, len(result))
}
7 changes: 6 additions & 1 deletion pkg/provision/primitives/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"

"github.com/pkg/errors"
"github.com/threefoldtech/tfexplorer/models/generated/workloads"
"github.com/threefoldtech/tfexplorer/schema"
"github.com/threefoldtech/zos/pkg"
Expand All @@ -16,6 +17,10 @@ import (
"github.com/threefoldtech/zos/pkg/provision"
)

// ErrUnsupportedWorkload is return when a workload of a type not supported by
// provisiond is received from the explorer
var ErrUnsupportedWorkload = errors.New("workload type not supported")

// ContainerToProvisionType converts TfgridReservationContainer1 to Container
func ContainerToProvisionType(c workloads.Container, reservationID string) (Container, string, error) {
container := Container{
Expand Down Expand Up @@ -259,7 +264,7 @@ func WorkloadToProvisionType(w workloads.ReservationWorkload) (*provision.Reserv
return nil, err
}
default:
return nil, fmt.Errorf("unknown workload type (%s) (%T)", w.Type.String(), tmp)
return nil, fmt.Errorf("%w (%s) (%T)", ErrUnsupportedWorkload, w.Type.String(), tmp)
}

reservation.Data, err = json.Marshal(data)
Expand Down