Skip to content

Commit

Permalink
Stop pausing/resuming connectors when deploying
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneGuerlais committed Nov 17, 2022
1 parent 5cb7d6e commit e033f95
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 31 deletions.
10 changes: 7 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ require (
github.com/hashicorp/go-multierror v1.0.0
github.com/pkg/errors v0.8.1
github.com/spf13/cobra v0.0.1
github.com/stretchr/testify v1.1.4
github.com/stretchr/testify v1.2.2
gopkg.in/jarcoal/httpmock.v1 v1.0.0-20181117152235-275e9df93516
gopkg.in/resty.v1 v1.11.0
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.0 // indirect
github.com/stretchr/objx v0.1.1 // indirect
golang.org/x/net v0.0.0-20181220203305-927f97764cc3 // indirect
github.com/vektra/mockery v1.1.2 // indirect
golang.org/x/mod v0.2.0 // indirect
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect
golang.org/x/tools v0.0.0-20200323144430-8dcfad9e016e // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
)
27 changes: 27 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ bou.ke/monkey v1.0.1 h1:zEMLInw9xvNakzUUPjfS4Ds6jYPqCFx3m7bRmG5NH2U=
bou.ke/monkey v1.0.1/go.mod h1:FgHuK96Rv2Nlf+0u1OOVDpCMdsWyOFmeeketDHE7LIg=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
Expand All @@ -20,8 +22,33 @@ github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.1.4 h1:ToftOQTytwshuOSj6bDSolVUa3GINfJP/fg3OkkOzQQ=
github.com/stretchr/testify v1.1.4/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/vektra/mockery v1.1.2 h1:uc0Yn67rJpjt8U/mAZimdCKn9AeA97BOkjpmtBSlfP4=
github.com/vektra/mockery v1.1.2/go.mod h1:VcfZjKaFOPO+MpN4ZvwPjs4c48lkq1o3Ym8yHZJu0jU=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3 h1:eH6Eip3UpmR+yM/qI9Ijluzb1bNv/cAU/n+6l8tRSis=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200323144430-8dcfad9e016e h1:ssd5ulOvVWlh4kDSUF2SqzmMeWfjmwDXM+uGw/aQjRE=
golang.org/x/tools v0.0.0-20200323144430-8dcfad9e016e/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/jarcoal/httpmock.v1 v1.0.0-20181117152235-275e9df93516 h1:H6trpavCIuipdInWrab8l34Mf+GGVfphniHostMdMaQ=
gopkg.in/jarcoal/httpmock.v1 v1.0.0-20181117152235-275e9df93516/go.mod h1:d3R+NllX3X5e0zlG1Rful3uLvsGC/Q3OHut5464DEQw=
gopkg.in/resty.v1 v1.11.0 h1:z5nqGs/W/h91PLOc+WZefPj8rRZe8Ctlgxg/AtbJ+NE=
Expand Down
7 changes: 5 additions & 2 deletions lib/connectors/base_client_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
//go:build !integration

package connectors

import (
"github.com/stretchr/testify/assert"
"gopkg.in/jarcoal/httpmock.v1"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
"gopkg.in/jarcoal/httpmock.v1"
)

// This test a side effect of resty: when retry on 409 the error of response is not reinitialized
Expand Down
2 changes: 1 addition & 1 deletion lib/connectors/connector_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//+build !unit
//go:build !unit

package connectors

Expand Down
17 changes: 2 additions & 15 deletions lib/connectors/highlevel_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,37 +277,24 @@ func tryUntil(exec func() bool, limit time.Duration) bool {

//DeployConnector checks if the configuration changed before deploying.
//It does nothing if it is the same
func (c *highLevelClient) DeployConnector(req CreateConnectorRequest) (err error) {
func (c *highLevelClient) DeployConnector(req CreateConnectorRequest) error {
existingConnector, err := c.GetConnector(ConnectorRequest{Name: req.Name})
if err != nil {
return err
}

if existingConnector.Code != 404 {
var upToDate bool
upToDate, err = c.IsUpToDate(req.Name, req.Config)
upToDate, err := c.IsUpToDate(req.Name, req.Config)
if err != nil {
return err
}
// Connector is already up to date, stop there and return ok
if upToDate {
return nil
}

_, err = c.PauseConnector(ConnectorRequest{Name: req.Name}, true)
if err != nil {
return err
}

defer func() {
_, err = c.ResumeConnector(ConnectorRequest{Name: req.Name}, true)
}()
}

_, err = c.UpdateConnector(req, true)
if err != nil {
return err
}

return err
}
Expand Down
13 changes: 3 additions & 10 deletions lib/connectors/highlevel_client_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//+build !integration
//go:build !integration

package connectors

import (
"github.com/pkg/errors"
"reflect"
"sync"
"testing"
"time"

"github.com/pkg/errors"

"bou.ke/monkey"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -142,14 +143,6 @@ func Test_DeployConnector_Ok(t *testing.T) {
Return(ConnectorResponse{Name: "test1", Config: configOnline}, nil)
mockBaseClient.On("GetConnectorConfig", mock.Anything).
Return(GetConnectorConfigResponse{Config: configOnline}, nil).Once()
mockBaseClient.On("PauseConnector", mock.Anything, mock.Anything).
Return(EmptyResponse{}, nil)
mockBaseClient.On("GetConnectorStatus", mock.Anything).
Return(GetConnectorStatusResponse{EmptyResponse: EmptyResponse{Code: 200}, ConnectorStatus: map[string]string{"state": "PAUSED"}}, nil).Once()
mockBaseClient.On("ResumeConnector", mock.Anything, mock.Anything).
Return(EmptyResponse{}, nil)
mockBaseClient.On("GetConnectorStatus", mock.Anything).
Return(GetConnectorStatusResponse{EmptyResponse: EmptyResponse{Code: 200}, ConnectorStatus: map[string]string{"state": "RUNNING"}}, nil).Once()
mockBaseClient.On("UpdateConnector", mock.Anything).
Return(ConnectorResponse{}, nil)
mockBaseClient.On("GetConnectorConfig", mock.Anything).
Expand Down

0 comments on commit e033f95

Please sign in to comment.