Skip to content

Commit e23b8ee

Browse files
Delyan Raychevakshaysngupta
authored andcommitted
Lint fixes; Better DevOps linter (#533)
1 parent e28a138 commit e23b8ee

File tree

25 files changed

+108
-42
lines changed

25 files changed

+108
-42
lines changed

.pipelines/build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ steps:
1414

1515
- script: |
1616
go get -u golang.org/x/lint/golint
17-
golint $(find . -type f -name '*.go' -not -path "./vendor/*") > /tmp/lint.out
18-
cat /tmp/lint.out
17+
golint $(go list ./... | grep -v /vendor/) | tee /tmp/lint.out
1918
if [ -s /tmp/lint.out ]; then
2019
echo -e "\e[101;97m golint FAILED \e[0m"``
2120
exit 1

cmd/appgw-ingress/errors.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

cmd/appgw-ingress/main.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ import (
4848
const (
4949
verbosityFlag = "verbosity"
5050
maxAuthRetryCount = 10
51-
tenSeconds = 10 * time.Second
52-
thirtySeconds = 30 * time.Second
51+
retryPause = 10 * time.Second
52+
resyncPause = 30 * time.Second
5353
)
5454

5555
var (
5656
flags = pflag.NewFlagSet(`appgw-ingress`, pflag.ExitOnError)
5757
inCluster = flags.Bool("in-cluster", true, "If running in a Kubernetes cluster, use the pod secrets for creating a Kubernetes client. Optional.")
5858
apiServerHost = flags.String("apiserver-host", "", "The address of the Kubernetes API Server. Optional if running in cluster; if omitted, local discovery is attempted.")
5959
kubeConfigFile = flags.String("kubeconfig", "", "Path to kubeconfig file with authorization and master location information.")
60-
resyncPeriod = flags.Duration("sync-period", thirtySeconds, "Interval at which to re-list and confirm cloud resources.")
60+
resyncPeriod = flags.Duration("sync-period", resyncPause, "Interval at which to re-list and confirm cloud resources.")
6161
versionInfo = flags.Bool("version", false, "Print version")
6262
verbosity = flags.Int(verbosityFlag, 1, "Set logging verbosity level")
6363
)
@@ -210,8 +210,8 @@ func getAuthorizerWithRetry(env environment.EnvVariables, maxAuthRetryCount int)
210210
return nil, errors.New("failed obtaining auth token")
211211
}
212212
retryCount++
213-
glog.Errorf("Failed fetching authorization token for ARM. Will retry in %v. Error: %s", tenSeconds, err)
214-
time.Sleep(tenSeconds)
213+
glog.Errorf("Failed fetching authorization token for ARM. Will retry in %v. Error: %s", retryPause, err)
214+
time.Sleep(retryPause)
215215
}
216216
}
217217

@@ -241,8 +241,8 @@ func waitForAzureAuth(env environment.EnvVariables, appGwClient n.ApplicationGat
241241
return errors.New("failed arm auth")
242242
}
243243
retryCount++
244-
glog.Errorf("Failed fetching config for App Gateway instance %s. Will retry in %v. Error: %s", env.AppGwName, tenSeconds, err)
245-
time.Sleep(tenSeconds)
244+
glog.Errorf("Failed fetching config for App Gateway instance %s. Will retry in %v. Error: %s", env.AppGwName, retryPause, err)
245+
time.Sleep(retryPause)
246246
}
247247
}
248248

pkg/appgw/errors.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,42 @@ package appgw
88
import "errors"
99

1010
var (
11+
// ErrEmptyConfig is an error.
1112
ErrEmptyConfig = errors.New("empty App Gateway config")
12-
ErrResolvingBackendPortForService = errors.New("unable to resolve backend port for some services")
13+
14+
// ErrMultipleServiceBackendPortBinding is an error.
1315
ErrMultipleServiceBackendPortBinding = errors.New("more than one service-backend port binding is not allowed")
16+
17+
// ErrGeneratingProbes is an error.
1418
ErrGeneratingProbes = errors.New("unable to generate health probes")
19+
20+
// ErrGeneratingBackendSettings is an error.
1521
ErrGeneratingBackendSettings = errors.New("unable to generate backend http settings")
22+
23+
// ErrGeneratingPools is an error.
1624
ErrGeneratingPools = errors.New("unable to generate backend address pools")
25+
26+
// ErrGeneratingListeners is an error.
1727
ErrGeneratingListeners = errors.New("unable to generate frontend listeners")
28+
29+
// ErrGeneratingRoutingRules is an error.
1830
ErrGeneratingRoutingRules = errors.New("unable to generate request routing rules")
31+
32+
// ErrKeyNoDefaults is an error.
1933
ErrKeyNoDefaults = errors.New("either a DefaultRedirectConfiguration or (DefaultBackendAddressPool + DefaultBackendHTTPSettings) must be configured")
34+
35+
// ErrKeyEitherDefaults is an error.
2036
ErrKeyEitherDefaults = errors.New("URL Path Map must have either DefaultRedirectConfiguration or (DefaultBackendAddressPool + DefaultBackendHTTPSettings) but not both")
37+
38+
// ErrKeyNoBorR is an error.
2139
ErrKeyNoBorR = errors.New("A valid path rule must have one of RedirectConfiguration or (BackendAddressPool + BackendHTTPSettings)")
40+
41+
// ErrKeyEitherBorR is an error.
2242
ErrKeyEitherBorR = errors.New("A Path Rule must have either RedirectConfiguration or (BackendAddressPool + BackendHTTPSettings) but not both")
43+
44+
// ErrKeyNoPrivateIP is an error.
2345
ErrKeyNoPrivateIP = errors.New("A Private IP must be present in the Application Gateway FrontendIPConfiguration if the controller is configured to UsePrivateIP for routing rules")
46+
47+
// ErrKeyNoPublicIP is an error.
2448
ErrKeyNoPublicIP = errors.New("A Public IP must be present in the Application Gateway FrontendIPConfiguration")
2549
)

pkg/appgw/frontend_listeners.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ func (c *appGwConfigBuilder) newListener(cbCtx *ConfigBuilderContext, listenerID
169169

170170
func (c *appGwConfigBuilder) groupListenersByListenerIdentifier(cbCtx *ConfigBuilderContext) map[listenerIdentifier]*n.ApplicationGatewayHTTPListener {
171171
listeners, ports := c.getListeners(cbCtx)
172-
portsById := make(map[string]n.ApplicationGatewayFrontendPort)
172+
portsByID := make(map[string]n.ApplicationGatewayFrontendPort)
173173
for _, port := range *ports {
174-
portsById[*port.ID] = port
174+
portsByID[*port.ID] = port
175175
}
176176

177177
listenersByID := make(map[listenerIdentifier]*n.ApplicationGatewayHTTPListener)
178178
// Update the listenerMap with the final listener lists
179179
for idx, listener := range *listeners {
180-
port := portsById[*listener.FrontendPort.ID]
180+
port := portsByID[*listener.FrontendPort.ID]
181181
listenerID := listenerIdentifier{
182182
HostName: *listener.HostName,
183183
FrontendPort: Port(*port.Port),

pkg/appgw/identifier.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func (agw Identifier) gatewayResourceID(subResourceKind string, resourceName str
2929
return agw.resourceID("Microsoft.Network", "applicationGateways", resourcePath)
3030
}
3131

32+
// AddressPoolID generates an ID for a backend address pool.
3233
func (agw Identifier) AddressPoolID(poolName string) string {
3334
return agw.gatewayResourceID("backendAddressPools", poolName)
3435
}
@@ -45,6 +46,7 @@ func (agw Identifier) sslCertificateID(certname string) string {
4546
return agw.gatewayResourceID("sslCertificates", certname)
4647
}
4748

49+
// HTTPSettingsID generates an ID for App Gateway HTTP settings resource.
4850
func (agw Identifier) HTTPSettingsID(settingsName string) string {
4951
return agw.gatewayResourceID("backendHttpSettingsCollection", settingsName)
5052
}

pkg/appgw/ingress_rules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (c *appGwConfigBuilder) getFrontendPortsFromIngress(ingress *v1beta1.Ingres
2323
}
2424

2525
ruleFrontendPorts, _ := c.processIngressRule(rule, ingress, env)
26-
for port, _ := range ruleFrontendPorts {
26+
for port := range ruleFrontendPorts {
2727
frontendPorts[port] = nil
2828
}
2929
}

pkg/appgw/internaltypes.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ func generatePathRuleName(namespace, ingress, suffix string) string {
148148
return formatPropName(fmt.Sprintf("%s%s-%s-%s-%s", agPrefix, prefixPathRule, namespace, ingress, suffix))
149149
}
150150

151+
// DefaultBackendHTTPSettingsName is the name to be assigned to App Gateway's default HTTP settings resource.
151152
var DefaultBackendHTTPSettingsName = fmt.Sprintf("%sdefaulthttpsetting", agPrefix)
153+
154+
// DefaultBackendAddressPoolName is the name to be assigned to App Gateway's default backend pool resource.
152155
var DefaultBackendAddressPoolName = fmt.Sprintf("%sdefaultaddresspool", agPrefix)
153156

154157
func defaultProbeName(protocol n.ApplicationGatewayProtocol) string {

pkg/appgw/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ func (cbCtx *ConfigBuilderContext) InIngressList(ingress *v1beta1.Ingress) bool
3838
return false
3939
}
4040

41+
// Port is a type alias for int32, representing a port number.
4142
type Port int32

pkg/brownfield/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ package brownfield
88
import "errors"
99

1010
var (
11+
// ErrListenerLookup is an error.
1112
ErrListenerLookup = errors.New("failed looking up listener")
1213
)

0 commit comments

Comments
 (0)