Skip to content

Commit

Permalink
Alias the Azure network package to single letter: n (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
draychev authored Jun 26, 2019
1 parent 0ed7ca1 commit aac1c9f
Show file tree
Hide file tree
Showing 18 changed files with 205 additions and 197 deletions.
8 changes: 4 additions & 4 deletions cmd/appgw-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network"
n "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/Azure/go-autorest/autorest/to"
Expand Down Expand Up @@ -86,7 +86,7 @@ func main() {
_ = flag.Lookup("logtostderr").Value.Set("true")
_ = flag.Set("v", strconv.Itoa(*verbosity))

appGwClient := network.NewApplicationGatewaysClient(env.SubscriptionID)
appGwClient := n.NewApplicationGatewaysClient(env.SubscriptionID)

var err error
if appGwClient.Authorizer, err = getAzAuth(env); err != nil || appGwClient.Authorizer == nil {
Expand Down Expand Up @@ -165,10 +165,10 @@ func getAzAuth(vars environment.EnvVariables) (autorest.Authorizer, error) {
return auth.NewAuthorizerFromEnvironment()
}
glog.V(1).Infoln("Creating authorizer from file referenced by AZURE_AUTH_LOCATION")
return auth.NewAuthorizerFromFile(network.DefaultBaseURI)
return auth.NewAuthorizerFromFile(n.DefaultBaseURI)
}

func waitForAzureAuth(envVars environment.EnvVariables, client network.ApplicationGatewaysClient) {
func waitForAzureAuth(envVars environment.EnvVariables, client n.ApplicationGatewaysClient) {
const retryTime = 10 * time.Second
for counter := 0; counter <= maxAuthRetry; counter++ {
if _, err := client.Get(context.Background(), envVars.ResourceGroupName, envVars.AppGwName); err != nil {
Expand Down
92 changes: 46 additions & 46 deletions pkg/appgw/appgw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io/ioutil"
"time"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network"
n "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network"
"github.com/Azure/go-autorest/autorest/to"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -29,8 +29,8 @@ import (
)

type appGWSettingsChecker struct {
total int // Number of expected sub-resources of this setting.
checker func(*network.ApplicationGatewayPropertiesFormat) // A method to test the values with this setting. Will be run if the checker is not null.
total int // Number of expected sub-resources of this setting.
checker func(*n.ApplicationGatewayPropertiesFormat) // A method to test the values with this setting. Will be run if the checker is not null.
}

type appGwConfigSettings struct {
Expand Down Expand Up @@ -183,13 +183,13 @@ var _ = Describe("Tests `appgw.ConfigBuilder`", func() {
return ingressList
}

defaultHealthProbesChecker := func(appGW *network.ApplicationGatewayPropertiesFormat) {
defaultHealthProbesChecker := func(appGW *n.ApplicationGatewayPropertiesFormat) {
expectedBackend := &ingress.Spec.Rules[0].IngressRuleValue.HTTP.Paths[0].Backend
probeName := generateProbeName(expectedBackend.ServiceName, expectedBackend.ServicePort.String(), ingress)
probe := &network.ApplicationGatewayProbe{
probe := &n.ApplicationGatewayProbe{
Name: &probeName,
ApplicationGatewayProbePropertiesFormat: &network.ApplicationGatewayProbePropertiesFormat{
Protocol: network.HTTP,
ApplicationGatewayProbePropertiesFormat: &n.ApplicationGatewayProbePropertiesFormat{
Protocol: n.HTTP,
Host: to.StringPtr(tests.Host),
Path: to.StringPtr(tests.URLPath),
Interval: to.Int32Ptr(20),
Expand All @@ -207,16 +207,16 @@ var _ = Describe("Tests `appgw.ConfigBuilder`", func() {
Expect(probes).To(ContainElement(*probe))
}

defaultBackendHTTPSettingsChecker := func(appGW *network.ApplicationGatewayPropertiesFormat) {
defaultBackendHTTPSettingsChecker := func(appGW *n.ApplicationGatewayPropertiesFormat) {
appGwIdentifier := Identifier{}
expectedBackend := &ingress.Spec.Rules[0].IngressRuleValue.HTTP.Paths[0].Backend
probeID := appGwIdentifier.probeID(generateProbeName(expectedBackend.ServiceName, expectedBackend.ServicePort.String(), ingress))
httpSettingsName := generateHTTPSettingsName(generateBackendID(ingress, nil, nil, expectedBackend).serviceFullName(), fmt.Sprintf("%d", servicePort), backendPort, ingress.Name)
httpSettings := &network.ApplicationGatewayBackendHTTPSettings{
httpSettings := &n.ApplicationGatewayBackendHTTPSettings{
Etag: to.StringPtr("*"),
Name: &httpSettingsName,
ApplicationGatewayBackendHTTPSettingsPropertiesFormat: &network.ApplicationGatewayBackendHTTPSettingsPropertiesFormat{
Protocol: network.HTTP,
ApplicationGatewayBackendHTTPSettingsPropertiesFormat: &n.ApplicationGatewayBackendHTTPSettingsPropertiesFormat{
Protocol: n.HTTP,
Port: &backendPort,
Path: nil,
HostName: nil,
Expand All @@ -230,15 +230,15 @@ var _ = Describe("Tests `appgw.ConfigBuilder`", func() {
Expect(*appGW.BackendHTTPSettingsCollection).To(ContainElement(*httpSettings))
}

defaultBackendAddressPoolChecker := func(appGW *network.ApplicationGatewayPropertiesFormat) {
defaultBackendAddressPoolChecker := func(appGW *n.ApplicationGatewayPropertiesFormat) {
expectedBackend := &ingress.Spec.Rules[0].IngressRuleValue.HTTP.Paths[0].Backend
addressPoolName := generateAddressPoolName(generateBackendID(ingress, nil, nil, expectedBackend).serviceFullName(), fmt.Sprintf("%d", servicePort), backendPort)
addressPoolAddresses := []network.ApplicationGatewayBackendAddress{{IPAddress: &endpoint1}, {IPAddress: &endpoint2}, {IPAddress: &endpoint3}}
addressPoolAddresses := []n.ApplicationGatewayBackendAddress{{IPAddress: &endpoint1}, {IPAddress: &endpoint2}, {IPAddress: &endpoint3}}

addressPool := &network.ApplicationGatewayBackendAddressPool{
addressPool := &n.ApplicationGatewayBackendAddressPool{
Etag: to.StringPtr("*"),
Name: &addressPoolName,
ApplicationGatewayBackendAddressPoolPropertiesFormat: &network.ApplicationGatewayBackendAddressPoolPropertiesFormat{
ApplicationGatewayBackendAddressPoolPropertiesFormat: &n.ApplicationGatewayBackendAddressPoolPropertiesFormat{
BackendAddresses: &addressPoolAddresses,
},
}
Expand All @@ -249,39 +249,39 @@ var _ = Describe("Tests `appgw.ConfigBuilder`", func() {
Expect(*appGW.BackendAddressPools).To(ContainElement(*addressPool))
}

defaultListenersChecker := func(appGW *network.ApplicationGatewayPropertiesFormat) {
defaultListenersChecker := func(appGW *n.ApplicationGatewayPropertiesFormat) {
// Test the listener.
appGwIdentifier := Identifier{}
frontendPortID := appGwIdentifier.frontendPortID(generateFrontendPortName(80))
listenerName := generateListenerName(listenerIdentifier{80, domainName})
listener := &network.ApplicationGatewayHTTPListener{
listener := &n.ApplicationGatewayHTTPListener{
Etag: to.StringPtr("*"),
Name: &listenerName,
ApplicationGatewayHTTPListenerPropertiesFormat: &network.ApplicationGatewayHTTPListenerPropertiesFormat{
ApplicationGatewayHTTPListenerPropertiesFormat: &n.ApplicationGatewayHTTPListenerPropertiesFormat{
FrontendIPConfiguration: resourceRef("*"),
FrontendPort: resourceRef(frontendPortID),
Protocol: network.HTTP,
Protocol: n.HTTP,
HostName: &domainName,
},
}

Expect((*appGW.HTTPListeners)[0]).To(Equal(*listener))
}

baseRequestRoutingRulesChecker := func(appGW *network.ApplicationGatewayPropertiesFormat, listener int32, host string) {
baseRequestRoutingRulesChecker := func(appGW *n.ApplicationGatewayPropertiesFormat, listener int32, host string) {
Expect(*((*appGW.RequestRoutingRules)[0].Name)).To(Equal(generateRequestRoutingRuleName(listenerIdentifier{listener, host})))
Expect((*appGW.RequestRoutingRules)[0].RuleType).To(Equal(network.PathBasedRouting))
Expect((*appGW.RequestRoutingRules)[0].RuleType).To(Equal(n.PathBasedRouting))
}

defaultRequestRoutingRulesChecker := func(appGW *network.ApplicationGatewayPropertiesFormat) {
defaultRequestRoutingRulesChecker := func(appGW *n.ApplicationGatewayPropertiesFormat) {
baseRequestRoutingRulesChecker(appGW, 80, domainName)
}

defaultHTTPSRequestRoutingRulesChecker := func(appGW *network.ApplicationGatewayPropertiesFormat) {
defaultHTTPSRequestRoutingRulesChecker := func(appGW *n.ApplicationGatewayPropertiesFormat) {
baseRequestRoutingRulesChecker(appGW, 443, domainName)
}

baseURLPathMapsChecker := func(appGW *network.ApplicationGatewayPropertiesFormat, listener int32, host string) {
baseURLPathMapsChecker := func(appGW *n.ApplicationGatewayPropertiesFormat, listener int32, host string) {
Expect(*((*appGW.URLPathMaps)[0].Name)).To(Equal(generateURLPathMapName(listenerIdentifier{listener, host})))
// Check the `pathRule` stored within the `urlPathMap`.
Expect(len(*((*appGW.URLPathMaps)[0].PathRules))).To(Equal(1), "Expected one path based rule, but got: %d", len(*((*appGW.URLPathMaps)[0].PathRules)))
Expand All @@ -292,11 +292,11 @@ var _ = Describe("Tests `appgw.ConfigBuilder`", func() {
Expect((*pathRule.Paths)[0]).To(Equal("/hi"))
}

defaultURLPathMapsChecker := func(appGW *network.ApplicationGatewayPropertiesFormat) {
defaultURLPathMapsChecker := func(appGW *n.ApplicationGatewayPropertiesFormat) {
baseURLPathMapsChecker(appGW, 80, domainName)
}

defaultHTTPSURLPathMapsChecker := func(appGW *network.ApplicationGatewayPropertiesFormat) {
defaultHTTPSURLPathMapsChecker := func(appGW *n.ApplicationGatewayPropertiesFormat) {
baseURLPathMapsChecker(appGW, 443, domainName)
}

Expand Down Expand Up @@ -422,21 +422,21 @@ var _ = Describe("Tests `appgw.ConfigBuilder`", func() {
Expect(ctxt).ShouldNot(BeNil(), "Unable to create `k8scontext`")

// Initialize the `ConfigBuilder`
configBuilder = NewConfigBuilder(ctxt, &Identifier{}, &network.ApplicationGatewayPropertiesFormat{}, record.NewFakeRecorder(100))
configBuilder = NewConfigBuilder(ctxt, &Identifier{}, &n.ApplicationGatewayPropertiesFormat{}, record.NewFakeRecorder(100))

builder, ok := configBuilder.(*appGwConfigBuilder)
Expect(ok).Should(BeTrue(), "Unable to get the more specific configBuilder implementation")

// Since this is a mock the `Application Gateway v2` does not have a public IP. During configuration process
// the controller would expect the `Application Gateway v2` to have some public IP before it starts generating
// configuration for the application gateway, hence creating this dummy configuration in the application gateway configuration.
builder.appGwConfig.FrontendIPConfigurations = &[]network.ApplicationGatewayFrontendIPConfiguration{
builder.appGwConfig.FrontendIPConfigurations = &[]n.ApplicationGatewayFrontendIPConfiguration{
{
Name: to.StringPtr("*"),
Etag: to.StringPtr("*"),
ID: to.StringPtr("*"),
ApplicationGatewayFrontendIPConfigurationPropertiesFormat: &network.ApplicationGatewayFrontendIPConfigurationPropertiesFormat{
PublicIPAddress: &network.SubResource{
ApplicationGatewayFrontendIPConfigurationPropertiesFormat: &n.ApplicationGatewayFrontendIPConfigurationPropertiesFormat{
PublicIPAddress: &n.SubResource{
ID: to.StringPtr("x/y/z"),
},
},
Expand Down Expand Up @@ -503,19 +503,19 @@ var _ = Describe("Tests `appgw.ConfigBuilder`", func() {
// Get all the ingresses
ingressList := testIngress()

EmptyHealthProbeChecker := func(appGW *network.ApplicationGatewayPropertiesFormat) {
EmptyHealthProbeChecker := func(appGW *n.ApplicationGatewayPropertiesFormat) {
Expect((*appGW.Probes)[0]).To(Equal(defaultProbe()))
}

EmptyBackendHTTPSettingsChecker := func(appGW *network.ApplicationGatewayPropertiesFormat) {
EmptyBackendHTTPSettingsChecker := func(appGW *n.ApplicationGatewayPropertiesFormat) {
appGwIdentifier := Identifier{}
expectedBackend := &ingress.Spec.Rules[0].IngressRuleValue.HTTP.Paths[0].Backend
httpSettingsName := generateHTTPSettingsName(generateBackendID(ingress, nil, nil, expectedBackend).serviceFullName(), fmt.Sprintf("%d", servicePort), servicePort, ingress.Name)
httpSettings := &network.ApplicationGatewayBackendHTTPSettings{
httpSettings := &n.ApplicationGatewayBackendHTTPSettings{
Etag: to.StringPtr("*"),
Name: &httpSettingsName,
ApplicationGatewayBackendHTTPSettingsPropertiesFormat: &network.ApplicationGatewayBackendHTTPSettingsPropertiesFormat{
Protocol: network.HTTP,
ApplicationGatewayBackendHTTPSettingsPropertiesFormat: &n.ApplicationGatewayBackendHTTPSettingsPropertiesFormat{
Protocol: n.HTTP,
Port: &servicePort,
Path: nil,
Probe: resourceRef(appGwIdentifier.probeID(defaultProbeName)),
Expand All @@ -528,7 +528,7 @@ var _ = Describe("Tests `appgw.ConfigBuilder`", func() {
Expect((*appGW.BackendHTTPSettingsCollection)).To(ContainElement(*httpSettings))
}

EmptyBackendAddressPoolChecker := func(appGW *network.ApplicationGatewayPropertiesFormat) {
EmptyBackendAddressPoolChecker := func(appGW *n.ApplicationGatewayPropertiesFormat) {
// Test the default backend address pool.
Expect((*appGW.BackendAddressPools)).To(ContainElement(*defaultBackendAddressPool()))
}
Expand Down Expand Up @@ -620,7 +620,7 @@ var _ = Describe("Tests `appgw.ConfigBuilder`", func() {
pfxCert := ctxt.CertificateSecretStore.GetPfxCertificate(secKey)
Expect(pfxCert).ShouldNot(BeNil())

httpsOnlyListenersChecker := func(appGW *network.ApplicationGatewayPropertiesFormat) {
httpsOnlyListenersChecker := func(appGW *n.ApplicationGatewayPropertiesFormat) {
// Test the listener.
appGwIdentifier := Identifier{}
secretID := secretIdentifier{
Expand All @@ -631,14 +631,14 @@ var _ = Describe("Tests `appgw.ConfigBuilder`", func() {
frontendPortID := appGwIdentifier.frontendPortID(generateFrontendPortName(443))
httpsListenerName := generateListenerName(listenerIdentifier{443, domainName})
sslCert := appGwIdentifier.sslCertificateID(secretID.secretFullName())
httpsListener := &network.ApplicationGatewayHTTPListener{
httpsListener := &n.ApplicationGatewayHTTPListener{
Etag: to.StringPtr("*"),
Name: &httpsListenerName,
ApplicationGatewayHTTPListenerPropertiesFormat: &network.ApplicationGatewayHTTPListenerPropertiesFormat{
ApplicationGatewayHTTPListenerPropertiesFormat: &n.ApplicationGatewayHTTPListenerPropertiesFormat{
FrontendIPConfiguration: resourceRef("*"),
FrontendPort: resourceRef(frontendPortID),
SslCertificate: resourceRef(sslCert),
Protocol: network.HTTPS,
Protocol: n.HTTPS,
HostName: &domainName,

// RequireServerNameIndication is not used in Application Gateway v2
Expand Down Expand Up @@ -731,22 +731,22 @@ var _ = Describe("Tests `appgw.ConfigBuilder`", func() {
// Get all the ingresses
ingressList := annotationIngress()

annotationsHTTPSettingsChecker := func(appGW *network.ApplicationGatewayPropertiesFormat) {
annotationsHTTPSettingsChecker := func(appGW *n.ApplicationGatewayPropertiesFormat) {
appGwIdentifier := Identifier{}
expectedBackend := &ingress.Spec.Rules[0].IngressRuleValue.HTTP.Paths[0].Backend
probeID := appGwIdentifier.probeID(generateProbeName(expectedBackend.ServiceName, expectedBackend.ServicePort.String(), ingress))
httpSettingsName := generateHTTPSettingsName(generateBackendID(ingress, nil, nil, expectedBackend).serviceFullName(), fmt.Sprintf("%d", servicePort), backendPort, ingress.Name)
httpSettings := &network.ApplicationGatewayBackendHTTPSettings{
httpSettings := &n.ApplicationGatewayBackendHTTPSettings{
Etag: to.StringPtr("*"),
Name: &httpSettingsName,
ApplicationGatewayBackendHTTPSettingsPropertiesFormat: &network.ApplicationGatewayBackendHTTPSettingsPropertiesFormat{
Protocol: network.HTTP,
ApplicationGatewayBackendHTTPSettingsPropertiesFormat: &n.ApplicationGatewayBackendHTTPSettingsPropertiesFormat{
Protocol: n.HTTP,
Port: &backendPort,
Path: to.StringPtr("/test"),
Probe: resourceRef(probeID),
HostName: nil,
CookieBasedAffinity: network.Enabled,
ConnectionDraining: &network.ApplicationGatewayConnectionDraining{
CookieBasedAffinity: n.Enabled,
ConnectionDraining: &n.ApplicationGatewayConnectionDraining{
Enabled: to.BoolPtr(true),
DrainTimeoutInSec: to.Int32Ptr(10),
},
Expand Down
Loading

0 comments on commit aac1c9f

Please sign in to comment.