Skip to content

Commit

Permalink
Deprecate vcsim provider
Browse files Browse the repository at this point in the history
With all the required fixes around event collector and simulator in
recent govmomi versions, we don't need to maintain a separate vcsim
provider anymore. The vcenter event provider will now work correctly
against a vcsim instance.

Signed-off-by: Michael Gasch <mgasch@vmware.com>
  • Loading branch information
Michael Gasch committed Feb 10, 2021
1 parent ab74cdf commit b12f536
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 6 deletions.
10 changes: 7 additions & 3 deletions vmware-event-router/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ events to configurable event `processors` (see below).
**Supported event providers:**

- [VMware vCenter Server](https://www.vmware.com/products/vcenter-server.html)
- vCenter Simulator [vcsim](https://github.com/vmware/govmomi/tree/master/vcsim) (for
testing purposes only)
- vCenter Simulator [vcsim](https://github.com/vmware/govmomi/tree/master/vcsim) (DEPRECATED)

**Supported event processors:**

Expand Down Expand Up @@ -231,8 +230,13 @@ vCenter Server and the respective type values and examples for these fields.

#### Provider Type `vcsim`

⚠️ This provider is **DEPRECATED** and will be removed in future versions. The
`vcenter` provider will work correctly against a `vcsim` instance.

The following table lists allowed and required fields for connecting to the
govmomi vCenter Simulator [vcsim](https://github.com/vmware/govmomi/tree/master/vcsim) and the respective type values and examples for these fields.
govmomi vCenter Simulator
[vcsim](https://github.com/vmware/govmomi/tree/master/vcsim) and the respective
type values and examples for these fields.

| Field | Type | Description | Required | Example |
| ------------- | ------- | ------------------------------------- | -------- | -------------------------------- |
Expand Down
2 changes: 1 addition & 1 deletion vmware-event-router/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/openfaas-incubator/connector-sdk v0.0.0-20200902074656-7f648543d4aa
github.com/openfaas/faas-provider v0.15.1
github.com/pkg/errors v0.9.1
github.com/vmware/govmomi v0.22.2
github.com/vmware/govmomi v0.24.1-0.20210210035757-ed60338583b0
go.uber.org/zap v1.16.0
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
Expand Down
4 changes: 2 additions & 2 deletions vmware-event-router/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw=
github.com/vmware/govmomi v0.22.2 h1:hmLv4f+RMTTseqtJRijjOWzwELiaLMIoHv2D6H3bF4I=
github.com/vmware/govmomi v0.22.2/go.mod h1:Y+Wq4lst78L85Ge/F8+ORXIWiKYqaro1vhAulACy9Lc=
github.com/vmware/govmomi v0.24.1-0.20210210035757-ed60338583b0 h1:pV5tmtOx0iZXhs1qP4di1lAKWoKz+ysR7oLf7u19scM=
github.com/vmware/govmomi v0.24.1-0.20210210035757-ed60338583b0/go.mod h1:Y+Wq4lst78L85Ge/F8+ORXIWiKYqaro1vhAulACy9Lc=
github.com/vmware/vmw-guestinfo v0.0.0-20170707015358-25eff159a728/go.mod h1:x9oS4Wk2s2u4tS29nEaDLdzvuHdB19CvSGJjPgkZJNk=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
Expand Down
1 change: 1 addition & 0 deletions vmware-event-router/internal/config/v1alpha1/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Provider struct {
// +optional
VCenter *ProviderConfigVCenter `yaml:"vcenter,omitempty" json:"vcenter,omitempty" jsonschema:"oneof_required=vcenter"`
// VCenter simulator configuration settings
// DEPRECATED: use provider vcenter instead
// +optional
VCSIM *ProviderConfigVCSIM `yaml:"vcsim,omitempty" json:"vcsim,omitempty" jsonschema:"oneof_required=vcsim"`
// VCD configuration settings
Expand Down
170 changes: 170 additions & 0 deletions vmware-event-router/internal/provider/vcenter/vcenter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// +build unit

package vcenter

import (
"context"
"fmt"
"testing"
"time"

cloudevents "github.com/cloudevents/sdk-go/v2"
"github.com/vmware/govmomi"
"github.com/vmware/govmomi/session"
"github.com/vmware/govmomi/simulator"
"github.com/vmware/govmomi/vim25"
"go.uber.org/zap/zaptest"
"golang.org/x/sync/errgroup"
"knative.dev/pkg/logging"

"github.com/vmware-samples/vcenter-event-broker-appliance/vmware-event-router/internal/metrics"
)

func TestEventStream_stream(t *testing.T) {
type args struct {
enableCheckpoint bool
}
type fields struct {
begin time.Time
}
tests := []struct {
name string
args args
fields fields
want int
wantErr error
}{
{
name: "expect no events",
fields: fields{
begin: time.Time{}, // will be "now" in test
},
args: args{
enableCheckpoint: false,
},
want: 0,
wantErr: context.Canceled,
},
{
name: "expect all events",
fields: fields{
begin: time.Now().UTC().Add(time.Hour * -1),
},
args: args{
enableCheckpoint: false,
},
want: 26, // current number returned by default VPX simulator model
wantErr: context.Canceled,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
simulator.Run(func(simCtx context.Context, client *vim25.Client) error {
logger := zaptest.NewLogger(t).Sugar()
simCtx = logging.WithLogger(simCtx, logger)

ctx, cancel := context.WithCancel(simCtx)
defer cancel()

c := govmomi.Client{
Client: client,
SessionManager: session.NewManager(client),
}

vc := &EventStream{
client: c,
Logger: logger,
checkpoint: tt.args.enableCheckpoint,
stats: metrics.EventStats{
EventsTotal: new(int),
EventsErr: new(int),
EventsSec: new(float64),
},
}

begin := time.Now().UTC()
if !tt.fields.begin.IsZero() {
begin = tt.fields.begin
}

coll, err := newHistoryCollector(ctx, client, &begin)
if err != nil {
t.Fatalf("create history collector: %v", err)
}

proc := fakeProcessor{
expect: tt.want,
doneCh: make(chan struct{}),
}

eg, egCtx := errgroup.WithContext(ctx)

// stream
eg.Go(func() error {
return vc.stream(egCtx, &proc, coll, tt.args.enableCheckpoint)
})

// give streamer a bit time to establish vc connection
time.Sleep(time.Second)

// processor
eg.Go(func() error {
if proc.expect == 0 {
cancel()
return nil
}

select {
case <-egCtx.Done():
return egCtx.Err()
case <-proc.doneCh:
cancel()
return nil
}
})

// cancel early in case of issues
eg.Go(func() error {
select {
case <-time.After(time.Second * 3):
return fmt.Errorf("timed out")
case <-egCtx.Done():
return egCtx.Err()
}
})

if err = eg.Wait(); err != tt.wantErr {
t.Errorf("stream() error = %v, wantErr %v", err, tt.wantErr)
}

if tt.want != proc.got {
t.Errorf("stream() events got = %v, want %v", proc.got, tt.want)
}

return nil
})
})
}
}

type fakeProcessor struct {
got int
expect int
doneCh chan struct{}
}

func (f *fakeProcessor) Process(ctx context.Context, ce cloudevents.Event) error {
logging.FromContext(ctx).Debugf("processing event: %s", ce.String())
f.got++
if f.expect == f.got {
close(f.doneCh)
}
return nil
}

func (f *fakeProcessor) PushMetrics(_ context.Context, _ metrics.Receiver) {
}

func (f *fakeProcessor) Shutdown(_ context.Context) error {
return nil
}
3 changes: 3 additions & 0 deletions vmware-event-router/internal/provider/vcsim/vcsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func NewEventStream(ctx context.Context, cfg *config.ProviderConfigVCSIM, ms met
}

go vcsim.PushMetrics(ctx, ms)

// this processor is deprecated since we have the appropriate fixes in govmomi
vcsim.Logger.Warn("this processor is deprecated, use vcenter processor instead")
return &vcsim, nil
}

Expand Down

0 comments on commit b12f536

Please sign in to comment.