-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support non-public cloud environments in the Azure Service Bus scaler #1907
Merged
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,33 @@ | ||
package azure | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
az "github.com/Azure/go-autorest/autorest/azure" | ||
) | ||
|
||
// EnvironmentSuffixProvider for different types of Azure scalers | ||
type EnvironmentSuffixProvider func(env az.Environment) (string, error) | ||
|
||
// ParseEndpointSuffix parses cloud and endpointSuffix metadata and returns the resolved endpoint suffix | ||
func ParseEndpointSuffix(metadata map[string]string, suffixProvider EnvironmentSuffixProvider) (string, error) { | ||
if val, ok := metadata["cloud"]; ok && val != "" { | ||
if strings.EqualFold(val, PrivateCloud) { | ||
if val, ok := metadata["endpointSuffix"]; ok && val != "" { | ||
return val, nil | ||
} | ||
return "", fmt.Errorf("endpointSuffix must be provided for %s cloud type", PrivateCloud) | ||
} | ||
|
||
env, err := az.EnvironmentFromName(val) | ||
if err != nil { | ||
return "", fmt.Errorf("invalid cloud environment %s", val) | ||
} | ||
|
||
return suffixProvider(env) | ||
} | ||
|
||
// Use public cloud suffix if `cloud` isn't specified | ||
return suffixProvider(az.PublicCloud) | ||
} |
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,52 @@ | ||
package azure | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
az "github.com/Azure/go-autorest/autorest/azure" | ||
) | ||
|
||
type parseEndpointSuffixTestData struct { | ||
metadata map[string]string | ||
endpointSuffix string | ||
suffixProvider EnvironmentSuffixProvider | ||
isError bool | ||
} | ||
|
||
var testSuffixProvider EnvironmentSuffixProvider = func(env az.Environment) (string, error) { | ||
if env == az.USGovernmentCloud { | ||
return "", fmt.Errorf("test endpoint is not available in %s", env.Name) | ||
} | ||
return fmt.Sprintf("%s.suffix", env.Name), nil | ||
} | ||
|
||
var parseEndpointSuffixTestDataset = []parseEndpointSuffixTestData{ | ||
{map[string]string{}, "AzurePublicCloud.suffix", testSuffixProvider, false}, | ||
{map[string]string{"cloud": "Invalid"}, "", testSuffixProvider, true}, | ||
{map[string]string{"cloud": "AzureUSGovernmentCloud"}, "", testSuffixProvider, true}, | ||
{map[string]string{"cloud": "AzureGermanCloud"}, "AzureGermanCloud.suffix", testSuffixProvider, false}, | ||
{map[string]string{"cloud": "Private"}, "", testSuffixProvider, true}, | ||
{map[string]string{"cloud": "Private", "endpointSuffix": "suffix.private.cloud"}, "suffix.private.cloud", testSuffixProvider, false}, | ||
{map[string]string{"endpointSuffix": "ignored"}, "AzurePublicCloud.suffix", testSuffixProvider, false}, | ||
} | ||
|
||
func TestParseEndpointSuffix(t *testing.T) { | ||
for _, testData := range parseEndpointSuffixTestDataset { | ||
endpointSuffix, err := ParseEndpointSuffix(testData.metadata, testData.suffixProvider) | ||
if !testData.isError && err != nil { | ||
t.Error("Expected success but got error", err) | ||
} | ||
if testData.isError && err == nil { | ||
t.Error("Expected error but got success") | ||
} | ||
if err == nil { | ||
if endpointSuffix != testData.endpointSuffix { | ||
t.Error( | ||
"For", testData.metadata, | ||
"expected endpointSuffix=", testData.endpointSuffix, | ||
"but got", endpointSuffix) | ||
} | ||
} | ||
} | ||
} |
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
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
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.
I think this is all it takes for the servicebus client to work in other cloud environments, hope I didn't miss anything.
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.
@ahmelsayed Can you confirm this?
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.
sorry for the delay, I've been out for a while and just got back.
There is also
namespace.Environment
that I see in the API. I don't have an easy way to validate it, but I'll try to get an environment where I can.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.
From what I could tell,
namespace.Environment
is only used for getting the service bus resource ID when calling NamespaceWithEnvironmentBinding to configure a namespace using environment details. Since we either create the namespace with connection string or with pod identity, I thinknamespace.Environment
isn't required. That also makes sense to me because as far as I know the service bus client should also support cloud environments that are not the publicly known clouds, like air gapped clouds.@ahmelsayed I might be able to test it in one of our clusters in US Gov if that helps.