-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support non-public cloud environments in the Azure Service Bus scaler (…
…#1907) Signed-off-by: amirschw <24677563+amirschw@users.noreply.github.com>
- Loading branch information
Showing
7 changed files
with
143 additions
and
38 deletions.
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