-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use region specific API calls with VMSS #1850
Merged
k8s-ci-robot
merged 1 commit into
kubernetes-sigs:main
from
devigned:regional-vmss-client
Nov 12, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package azure | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"path" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
type aliasAuth = Authorizer | ||
|
||
// baseURIAdapter wraps an azure.Authorizer and adds a region to the BaseURI. This is useful if you need to make direct | ||
// calls to a specific Azure region. One possible case is to avoid replication delay when listing resources within a | ||
// resource group. For example, listing the VMSSes within a resource group. | ||
type baseURIAdapter struct { | ||
aliasAuth | ||
Region string | ||
parsedURL *url.URL | ||
} | ||
|
||
// WithRegionalBaseURI returns an authorizer that has a regional base URI, like `https://{region}.management.azure.com`. | ||
func WithRegionalBaseURI(authorizer Authorizer, region string) (Authorizer, error) { | ||
parsedURI, err := url.Parse(authorizer.BaseURI()) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to parse the base URI of client") | ||
} | ||
|
||
return &baseURIAdapter{ | ||
aliasAuth: authorizer, | ||
Region: region, | ||
parsedURL: parsedURI, | ||
}, nil | ||
} | ||
|
||
// BaseURI return a regional base URI, like `https://{region}.management.azure.com`. | ||
func (a *baseURIAdapter) BaseURI() string { | ||
if a == nil || a.parsedURL == nil || a.Region == "" { | ||
return a.aliasAuth.BaseURI() | ||
} | ||
|
||
sansScheme := path.Join(fmt.Sprintf("%s.%s", a.Region, a.parsedURL.Host), a.parsedURL.Path) | ||
return fmt.Sprintf("%s://%s", a.parsedURL.Scheme, sansScheme) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package azure | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
. "github.com/onsi/gomega" | ||
|
||
"sigs.k8s.io/cluster-api-provider-azure/azure/mock_azure" | ||
) | ||
|
||
func TestWithRegionalBaseURI(t *testing.T) { | ||
cases := []struct { | ||
Name string | ||
AuthorizerFactory func(authMock *mock_azure.MockAuthorizer) Authorizer | ||
Region string | ||
Result string | ||
}{ | ||
{ | ||
Name: "with a region", | ||
AuthorizerFactory: func(authMock *mock_azure.MockAuthorizer) Authorizer { | ||
authMock.EXPECT().BaseURI().Return("http://foo.bar").AnyTimes() | ||
return authMock | ||
}, | ||
Region: "bazz", | ||
Result: "http://bazz.foo.bar", | ||
}, | ||
{ | ||
Name: "with no region", | ||
AuthorizerFactory: func(authMock *mock_azure.MockAuthorizer) Authorizer { | ||
authMock.EXPECT().BaseURI().Return("http://foo.bar").AnyTimes() | ||
return authMock | ||
}, | ||
Result: "http://foo.bar", | ||
}, | ||
{ | ||
Name: "with a region and path", | ||
AuthorizerFactory: func(authMock *mock_azure.MockAuthorizer) Authorizer { | ||
authMock.EXPECT().BaseURI().Return("http://foo.bar/something/id").AnyTimes() | ||
return authMock | ||
}, | ||
Region: "bazz", | ||
Result: "http://bazz.foo.bar/something/id", | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
c := c | ||
t.Run(c.Name, func(t *testing.T) { | ||
g := NewWithT(t) | ||
mockCtrl := gomock.NewController(t) | ||
defer mockCtrl.Finish() | ||
authMock := mock_azure.NewMockAuthorizer(mockCtrl) | ||
regionalAuth, err := WithRegionalBaseURI(c.AuthorizerFactory(authMock), c.Region) | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
g.Expect(regionalAuth.BaseURI()).To(Equal(c.Result)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,12 +74,21 @@ func (a *AgentPoolVMSSNotFoundError) Is(target error) bool { | |
} | ||
|
||
// newAzureManagedMachinePoolService populates all the services based on input scope. | ||
func newAzureManagedMachinePoolService(scope *scope.ManagedControlPlaneScope) *azureManagedMachinePoolService { | ||
func newAzureManagedMachinePoolService(scope *scope.ManagedControlPlaneScope) (*azureManagedMachinePoolService, error) { | ||
var authorizer azure.Authorizer = scope | ||
if scope.Location() != "" { | ||
regionalAuthorizer, err := azure.WithRegionalBaseURI(scope, scope.Location()) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to create a regional authorizer") | ||
} | ||
authorizer = regionalAuthorizer | ||
} | ||
|
||
return &azureManagedMachinePoolService{ | ||
scope: scope, | ||
agentPoolsSvc: agentpools.New(scope), | ||
scaleSetsSvc: scalesets.NewClient(scope), | ||
} | ||
scaleSetsSvc: scalesets.NewClient(authorizer), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
}, nil | ||
} | ||
|
||
// Reconcile reconciles all the services in a predetermined order. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
templates/test/ci/prow-aks-multi-tenancy/patch_location.yaml
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually want path.join() (os filepath separator) here, versus a hardcoded slash? Wouldn’t this now be platform dependent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm, I might be thinking filepath.join()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are good: https://cs.opensource.google/go/go/+/refs/tags/go1.17.3:src/path/path.go;l=174