Skip to content

Commit

Permalink
resource-group-updates (#195)
Browse files Browse the repository at this point in the history
* resource-group-updates

* resource-group-updates
  • Loading branch information
narkarum authored and arahamad-zz committed Dec 17, 2019
1 parent 0f9bd88 commit 75ce88d
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GOLINTPACKAGES=$(shell go list ./... | grep -v /vendor/ | grep -v /e2e | grep -v
ARCH = $(shell uname -m)

.PHONY: all
all: deps fmt vet test
all: deps dofmt vet test

.PHONY: deps
deps:
Expand Down
1 change: 1 addition & 0 deletions volume-providers/vpc/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func NewProvider(conf *config.Config, logger *zap.Logger) (local.Provider, error
HTTPClient: httpClient,
APIVersion: conf.VPC.APIVersion,
APIGeneration: conf.VPC.VPCAPIGeneration,
ResourceGroup: conf.VPC.ResourceGroupID,
},
}
// Update VPC config for IKS deployment
Expand Down
7 changes: 6 additions & 1 deletion volume-providers/vpc/vpcclient/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type client struct {
}

// New creates a new instance of a SessionClient
func New(ctx context.Context, baseURL string, queryValues url.Values, httpClient *http.Client, contextID string) SessionClient {
func New(ctx context.Context, baseURL string, queryValues url.Values, httpClient *http.Client, contextID string, resourceGroupID string) SessionClient {
return &client{
baseURL: baseURL,
httpClient: httpClient,
Expand All @@ -55,6 +55,7 @@ func New(ctx context.Context, baseURL string, queryValues url.Values, httpClient
authenHandler: &authenticationHandler{},
contextID: contextID,
context: ctx,
resourceGroup: resourceGroupID,
}
}

Expand All @@ -68,6 +69,10 @@ func (c *client) NewRequest(operation *Operation) *Request {
headers.Set("X-Transaction-ID", c.contextID) // To avoid IKS cloudflare overriding X-Request-ID
}

if c.resourceGroup != "" {
headers.Set("X-Auth-Resource-Group-ID", c.resourceGroup)
}

// Copy the query values to a new map
qv := url.Values{}
for k, v := range c.queryValues {
Expand Down
8 changes: 4 additions & 4 deletions volume-providers/vpc/vpcclient/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func TestDebugMode(t *testing.T) {

log = &bytes.Buffer{}

riaas = client.New(context.Background(), s.URL, queryValues, http.DefaultClient, "test-context").WithDebug(log).WithAuthToken("auth-token")
riaas = client.New(context.Background(), s.URL, queryValues, http.DefaultClient, "test-context", "default").WithDebug(log).WithAuthToken("auth-token")

defer s.Close()

Expand Down Expand Up @@ -320,7 +320,7 @@ func TestOperationURLProcessing(t *testing.T) {
for _, testcase := range testcases {

t.Run(testcase.name, func(t *testing.T) {
c := client.New(context.Background(), testcase.baseURL, queryValues, http.DefaultClient, "test-context")
c := client.New(context.Background(), testcase.baseURL, queryValues, http.DefaultClient, "test-context", "default")
actualURL := c.NewRequest(testcase.operation).URL()
assert.Equal(t, testcase.expectedURL, actualURL)
})
Expand All @@ -338,7 +338,7 @@ func TestWithPathParameter(t *testing.T) {
"generation": []string{strconv.Itoa(models.APIGeneration)},
}

riaas := client.New(context.Background(), s.URL, queryValues, http.DefaultClient, "test-context").WithDebug(log).WithAuthToken("auth-token").WithPathParameter("test", "test")
riaas := client.New(context.Background(), s.URL, queryValues, http.DefaultClient, "test-context", "default").WithDebug(log).WithAuthToken("auth-token").WithPathParameter("test", "test")
assert.NotNil(t, riaas)
defer s.Close()
}
Expand All @@ -354,7 +354,7 @@ func TestWithQueryValue(t *testing.T) {
"generation": []string{strconv.Itoa(models.APIGeneration)},
}

riaas := client.New(context.Background(), s.URL, queryValues, http.DefaultClient, "test-context").WithDebug(log).WithAuthToken("auth-token").WithQueryValue("test", "test")
riaas := client.New(context.Background(), s.URL, queryValues, http.DefaultClient, "test-context", "default").WithDebug(log).WithAuthToken("auth-token").WithQueryValue("test", "test")
assert.NotNil(t, riaas)
defer s.Close()
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (vs *IKSVolumeAttachService) AttachVolume(volumeAttachmentTemplate *models.
vol := *volumeAttachmentTemplate.Volume
operationRequest = operationRequest.SetQueryValue(IksVolumeQueryKey, vol.ID)

ctxLogger.Info("Equivalent curl command and query parameters", zap.Reflect("URL", operationRequest.URL()), zap.Reflect("Payload", volumeAttachmentTemplate), zap.Reflect("Operation", operation), zap.Reflect(IksClusterQueryKey, volumeAttachmentTemplate.InstanceID), zap.Reflect(IksWorkerQueryKey, volumeAttachmentTemplate.InstanceID), zap.Reflect(IksVolumeQueryKey, vol.ID))
ctxLogger.Info("Equivalent curl command and query parameters", zap.Reflect("URL", operationRequest.URL()), zap.Reflect("Payload", volumeAttachmentTemplate), zap.Reflect("Operation", operation), zap.Reflect(IksClusterQueryKey, volumeAttachmentTemplate.ClusterID), zap.Reflect(IksWorkerQueryKey, volumeAttachmentTemplate.InstanceID), zap.Reflect(IksVolumeQueryKey, vol.ID))

_, err := operationRequest.JSONBody(volumeAttachmentTemplate).JSONSuccess(&volumeAttachment).JSONError(apiErr).Invoke()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion volume-providers/vpc/vpcclient/riaas/riaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func New(config Config) (*Session, error) {
"generation": []string{strconv.Itoa(apiGen)},
}

riaasClient := client.New(ctx, config.baseURL(), queryValues, config.httpClient(), config.ContextID)
riaasClient := client.New(ctx, config.baseURL(), queryValues, config.httpClient(), config.ContextID, config.ResourceGroup)

if config.DebugWriter != nil {
riaasClient.WithDebug(config.DebugWriter)
Expand Down
2 changes: 1 addition & 1 deletion volume-providers/vpc/vpcclient/riaas/test/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func SetupServer(t *testing.T) (m *http.ServeMux, c client.SessionClient, teardo

queryValues := url.Values{"version": []string{models.APIVersion}}

c = client.New(context.Background(), s.URL, queryValues, http.DefaultClient, "test-context").WithDebug(log).WithAuthToken("auth-token")
c = client.New(context.Background(), s.URL, queryValues, http.DefaultClient, "test-context", "default").WithDebug(log).WithAuthToken("auth-token")

teardown = func() {
s.Close()
Expand Down

0 comments on commit 75ce88d

Please sign in to comment.