Skip to content

Commit fb09cdf

Browse files
authored
Merge pull request Azure#693 from Azure/go_coding_style
Go coding style
2 parents 5367ff2 + 1528b96 commit fb09cdf

21 files changed

+192
-122
lines changed

Makefile

+7-16
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,22 @@ prereqs:
1818
go get github.com/jteeuwen/go-bindata/...
1919
glide install
2020

21-
_build:
21+
build:
2222
go generate -v $(GOFILES)
2323
go build -v -ldflags="-X github.com/Azure/acs-engine/cmd.BuildSHA=${VERSION} -X github.com/Azure/acs-engine/cmd.BuildTime=${BUILD}"
2424
cd test/acs-engine-test; go build -v
2525

26-
build: prereqs _build
27-
28-
test: prereqs test_fmt
26+
test: test_fmt
2927
go test -v $(GOFILES)
3028

31-
test_fmt: prereqs
32-
test -z "$$(gofmt -s -l $(GOFILES) | tee /dev/stderr)"
29+
.PHONY: test-style
30+
test-style:
31+
@scripts/validate-go.sh
3332

34-
validate-generated: prereqs
33+
validate-generated:
3534
./scripts/validate-generated.sh
3635

37-
fmt:
38-
gofmt -s -l -w $(GOFILES)
39-
40-
lint: prereqs
41-
go get -u github.com/golang/lint/golint
42-
# TODO: fix lint errors, enable linting
43-
# golint -set_exit_status
44-
45-
ci: validate-generated build test lint
36+
ci: prereqs validate-generated build test lint
4637

4738
devenv:
4839
./scripts/devenv.sh

docs/developers.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Developers Guide
2+
3+
This guide explains how to set up your environment for developing on
4+
acs-engine.
5+
6+
## Prerequisites
7+
8+
- Go 1.6.0 or later
9+
- Glide 0.12.0 or later
10+
- kubectl 1.5 or later
11+
- An Azure account (needed for deploying VMs and Azure infrastructure)
12+
- Git
13+
14+
## Contribution Guidelines
15+
16+
We welcome contributions. This project has set up some guidelines in
17+
order to ensure that (a) code quality remains high, (b) the project
18+
remains consistent, and (c) contributions follow the open source legal
19+
requirements. Our intent is not to burden contributors, but to build
20+
elegant and high-quality open source code so that our users will benefit.
21+
22+
Make sure you have read and understood the main CONTRIBUTING guide:
23+
24+
https://github.com/Azure/acs-engine/blob/master/CONTRIBUTING.md
25+
26+
### Structure of the Code
27+
28+
The code for the acs-engine project is organized as follows:
29+
30+
- The individual programs are located in `cmd/`. Code inside of `cmd/`
31+
is not designed for library re-use.
32+
- Shared libraries are stored in `pkg/`.
33+
- The `tests/` directory contains a number of utility scripts. Most of these
34+
are used by the CI/CD pipeline.
35+
- The `docs/` folder is used for documentation and examples.
36+
37+
Go dependencies are managed with
38+
[Glide](https://github.com/Masterminds/glide) and stored in the
39+
`vendor/` directory.
40+
41+
### Git Conventions
42+
43+
We use Git for our version control system. The `master` branch is the
44+
home of the current development candidate. Releases are tagged.
45+
46+
We accept changes to the code via GitHub Pull Requests (PRs). One
47+
workflow for doing this is as follows:
48+
49+
1. Use `go get` to clone the acs-engine repository: `go get github.com/Azure/acs-engine`
50+
2. Fork that repository into your GitHub account
51+
3. Add your repository as a remote for `$GOPATH/github.com/Azure/acs-engine`
52+
4. Create a new working branch (`git checkout -b feat/my-feature`) and
53+
do your work on that branch.
54+
5. When you are ready for us to review, push your branch to GitHub, and
55+
then open a new pull request with us.
56+
57+
### Go Conventions
58+
59+
We follow the Go coding style standards very closely. Typically, running
60+
`go fmt` will make your code beautiful for you.
61+
62+
We also typically follow the conventions recommended by `go lint` and
63+
`gometalinter`. Run `make test-style` to test the style conformance.
64+
65+
Read more:
66+
67+
- Effective Go [introduces formatting](https://golang.org/doc/effective_go.html#formatting).
68+
- The Go Wiki has a great article on [formatting](https://github.com/golang/go/wiki/CodeReviewComments).

pkg/acsengine/const.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const (
3030
// DefaultAgentIPAddressCount is the default number of IP addresses per network interface on agents
3131
DefaultAgentIPAddressCount = 1
3232
// DefaultAgentMultiIPAddressCount is the default number of IP addresses per network interface on agents,
33-
// when VNET integration is enabled. It can be overriden per pool by setting the pool's IPAdddressCount property.
33+
// when VNET integration is enabled. It can be overridden per pool by setting the pool's IPAdddressCount property.
3434
DefaultAgentMultiIPAddressCount = 128
3535
// DefaultKubernetesClusterDomain is the dns suffix used in the cluster (used as a SAN in the PKI generation)
3636
DefaultKubernetesClusterDomain = "cluster.local"
@@ -42,14 +42,15 @@ const (
4242
)
4343

4444
const (
45-
// Master represents the master node type
45+
// DCOSMaster represents the master node type
4646
DCOSMaster DCOSNodeType = "DCOSMaster"
47-
// PrivateAgent represents the private agent node type
47+
// DCOSPrivateAgent represents the private agent node type
4848
DCOSPrivateAgent DCOSNodeType = "DCOSPrivateAgent"
49-
// PublicAgent represents the public agent node type
49+
// DCOSPublicAgent represents the public agent node type
5050
DCOSPublicAgent DCOSNodeType = "DCOSPublicAgent"
5151
)
5252

53+
// KubeImages represents Docker images used for Kubernetes components based on Kubernetes version
5354
var KubeImages = map[api.OrchestratorVersion]map[string]string{
5455
api.Kubernetes166: {
5556
"hyperkube": "hyperkube-amd64:v1.6.6",

pkg/acsengine/defaults.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ var (
2121
},
2222

2323
DCOSSpecConfig: DCOSSpecConfig{
24-
DCOS173_BootstrapDownloadURL: fmt.Sprintf(MsecndDCOSBootstrapDownloadURL, "testing", "df308b6fc3bd91e1277baa5a3db928ae70964722"),
25-
DCOS184_BootstrapDownloadURL: fmt.Sprintf(AzureEdgeDCOSBootstrapDownloadURL, "testing", "5b4aa43610c57ee1d60b4aa0751a1fb75824c083"),
26-
DCOS187_BootstrapDownloadURL: fmt.Sprintf(AzureEdgeDCOSBootstrapDownloadURL, "stable", "e73ba2b1cd17795e4dcb3d6647d11a29b9c35084"),
27-
DCOS188_BootstrapDownloadURL: fmt.Sprintf(AzureEdgeDCOSBootstrapDownloadURL, "stable", "5df43052907c021eeb5de145419a3da1898c58a5"),
28-
DCOS190_BootstrapDownloadURL: fmt.Sprintf(AzureEdgeDCOSBootstrapDownloadURL, "stable", "58fd0833ce81b6244fc73bf65b5deb43217b0bd7"),
24+
DCOS173BootstrapDownloadURL: fmt.Sprintf(MsecndDCOSBootstrapDownloadURL, "testing", "df308b6fc3bd91e1277baa5a3db928ae70964722"),
25+
DCOS184BootstrapDownloadURL: fmt.Sprintf(AzureEdgeDCOSBootstrapDownloadURL, "testing", "5b4aa43610c57ee1d60b4aa0751a1fb75824c083"),
26+
DCOS187BootstrapDownloadURL: fmt.Sprintf(AzureEdgeDCOSBootstrapDownloadURL, "stable", "e73ba2b1cd17795e4dcb3d6647d11a29b9c35084"),
27+
DCOS188BootstrapDownloadURL: fmt.Sprintf(AzureEdgeDCOSBootstrapDownloadURL, "stable", "5df43052907c021eeb5de145419a3da1898c58a5"),
28+
DCOS190BootstrapDownloadURL: fmt.Sprintf(AzureEdgeDCOSBootstrapDownloadURL, "stable", "58fd0833ce81b6244fc73bf65b5deb43217b0bd7"),
2929
},
3030
}
3131

@@ -41,10 +41,10 @@ var (
4141
KubeBinariesSASURLBase: "https://acs-mirror.azureedge.net/wink8s/",
4242
},
4343
DCOSSpecConfig: DCOSSpecConfig{
44-
DCOS173_BootstrapDownloadURL: fmt.Sprintf(AzureChinaCloudDCOSBootstrapDownloadURL, "df308b6fc3bd91e1277baa5a3db928ae70964722"),
45-
DCOS184_BootstrapDownloadURL: fmt.Sprintf(AzureChinaCloudDCOSBootstrapDownloadURL, "5b4aa43610c57ee1d60b4aa0751a1fb75824c083"),
46-
DCOS187_BootstrapDownloadURL: fmt.Sprintf(AzureChinaCloudDCOSBootstrapDownloadURL, "e73ba2b1cd17795e4dcb3d6647d11a29b9c35084"),
47-
DCOS188_BootstrapDownloadURL: fmt.Sprintf(AzureChinaCloudDCOSBootstrapDownloadURL, "5df43052907c021eeb5de145419a3da1898c58a5"),
44+
DCOS173BootstrapDownloadURL: fmt.Sprintf(AzureChinaCloudDCOSBootstrapDownloadURL, "df308b6fc3bd91e1277baa5a3db928ae70964722"),
45+
DCOS184BootstrapDownloadURL: fmt.Sprintf(AzureChinaCloudDCOSBootstrapDownloadURL, "5b4aa43610c57ee1d60b4aa0751a1fb75824c083"),
46+
DCOS187BootstrapDownloadURL: fmt.Sprintf(AzureChinaCloudDCOSBootstrapDownloadURL, "e73ba2b1cd17795e4dcb3d6647d11a29b9c35084"),
47+
DCOS188BootstrapDownloadURL: fmt.Sprintf(AzureChinaCloudDCOSBootstrapDownloadURL, "5df43052907c021eeb5de145419a3da1898c58a5"),
4848
},
4949
}
5050
)

pkg/acsengine/engine.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ type KeyVaultRef struct {
169169
SecretVersion string `json:"secretVersion,omitempty"`
170170
}
171171

172-
var keyvaultSecretPath_re *regexp.Regexp
172+
var keyvaultSecretPathRe *regexp.Regexp
173173

174174
func init() {
175-
keyvaultSecretPath_re = regexp.MustCompile(`^(/subscriptions/\S+/resourceGroups/\S+/providers/Microsoft.KeyVault/vaults/\S+)/secrets/([^/\s]+)(/(\S+))?$`)
175+
keyvaultSecretPathRe = regexp.MustCompile(`^(/subscriptions/\S+/resourceGroups/\S+/providers/Microsoft.KeyVault/vaults/\S+)/secrets/([^/\s]+)(/(\S+))?$`)
176176
}
177177

178178
func (t *TemplateGenerator) verifyFiles() error {
@@ -402,20 +402,20 @@ func getParameters(cs *api.ContainerService, isClassicMode bool) (map[string]int
402402
}
403403

404404
if strings.HasPrefix(string(properties.OrchestratorProfile.OrchestratorType), string(api.DCOS)) {
405-
dcosBootstrapURL := cloudSpecConfig.DCOSSpecConfig.DCOS188_BootstrapDownloadURL
405+
dcosBootstrapURL := cloudSpecConfig.DCOSSpecConfig.DCOS188BootstrapDownloadURL
406406
switch properties.OrchestratorProfile.OrchestratorType {
407407
case api.DCOS:
408408
switch properties.OrchestratorProfile.OrchestratorVersion {
409409
case api.DCOS173:
410-
dcosBootstrapURL = cloudSpecConfig.DCOSSpecConfig.DCOS173_BootstrapDownloadURL
410+
dcosBootstrapURL = cloudSpecConfig.DCOSSpecConfig.DCOS173BootstrapDownloadURL
411411
case api.DCOS184:
412-
dcosBootstrapURL = cloudSpecConfig.DCOSSpecConfig.DCOS184_BootstrapDownloadURL
412+
dcosBootstrapURL = cloudSpecConfig.DCOSSpecConfig.DCOS184BootstrapDownloadURL
413413
case api.DCOS187:
414-
dcosBootstrapURL = cloudSpecConfig.DCOSSpecConfig.DCOS187_BootstrapDownloadURL
414+
dcosBootstrapURL = cloudSpecConfig.DCOSSpecConfig.DCOS187BootstrapDownloadURL
415415
case api.DCOS188:
416-
dcosBootstrapURL = cloudSpecConfig.DCOSSpecConfig.DCOS188_BootstrapDownloadURL
416+
dcosBootstrapURL = cloudSpecConfig.DCOSSpecConfig.DCOS188BootstrapDownloadURL
417417
case api.DCOS190:
418-
dcosBootstrapURL = cloudSpecConfig.DCOSSpecConfig.DCOS190_BootstrapDownloadURL
418+
dcosBootstrapURL = cloudSpecConfig.DCOSSpecConfig.DCOS190BootstrapDownloadURL
419419
}
420420
}
421421
addValue(parametersMap, "dcosBootstrapURL", dcosBootstrapURL)
@@ -468,7 +468,7 @@ func addSecret(m map[string]interface{}, k string, v interface{}, encode bool) {
468468
addValue(m, k, v)
469469
return
470470
}
471-
parts := keyvaultSecretPath_re.FindStringSubmatch(str)
471+
parts := keyvaultSecretPathRe.FindStringSubmatch(str)
472472
if parts == nil || len(parts) != 5 {
473473
if encode {
474474
addValue(m, k, base64.StdEncoding.EncodeToString([]byte(str)))
@@ -1283,12 +1283,12 @@ write_files:
12831283

12841284
func getKubernetesSubnets(properties *api.Properties) string {
12851285
subnetString := `{
1286-
"name": "podCIDR%d",
1286+
"name": "podCIDR%d",
12871287
"properties": {
1288-
"addressPrefix": "10.244.%d.0/24",
1288+
"addressPrefix": "10.244.%d.0/24",
12891289
"networkSecurityGroup": {
12901290
"id": "[variables('nsgID')]"
1291-
},
1291+
},
12921292
"routeTable": {
12931293
"id": "[variables('routeTableID')]"
12941294
}

pkg/acsengine/pki.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ func privateKeyToPem(privateKey *rsa.PrivateKey) []byte {
182182
func pemToCertificate(raw string) (*x509.Certificate, error) {
183183
cpb, _ := pem.Decode([]byte(raw))
184184
if cpb == nil {
185-
return nil, errors.New("The raw pem is not a valid PEM formatted block.")
185+
return nil, errors.New("The raw pem is not a valid PEM formatted block")
186186
}
187187
return x509.ParseCertificate(cpb.Bytes)
188188
}
189189

190190
func pemToKey(raw string) (*rsa.PrivateKey, error) {
191191
kpb, _ := pem.Decode([]byte(raw))
192192
if kpb == nil {
193-
return nil, errors.New("The raw pem is not a valid PEM formatted block.")
193+
return nil, errors.New("The raw pem is not a valid PEM formatted block")
194194
}
195195
return x509.ParsePKCS1PrivateKey(kpb.Bytes)
196196
}

pkg/acsengine/tenantid.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
log "github.com/Sirupsen/logrus"
1111
)
1212

13-
// findTenantID figures out the AAD tenant ID of the subscription by making an
13+
// GetTenantID figures out the AAD tenant ID of the subscription by making an
1414
// unauthenticated request to the Get Subscription Details endpoint and parses
1515
// the value from WWW-Authenticate header.
1616
func GetTenantID(env azure.Environment, subscriptionID string) (string, error) {

pkg/acsengine/types.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ type DockerSpecConfig struct {
3232

3333
//DCOSSpecConfig is the configurations of DCOS
3434
type DCOSSpecConfig struct {
35-
DCOS173_BootstrapDownloadURL string
36-
DCOS184_BootstrapDownloadURL string
37-
DCOS187_BootstrapDownloadURL string
38-
DCOS188_BootstrapDownloadURL string
39-
DCOS190_BootstrapDownloadURL string
35+
DCOS173BootstrapDownloadURL string
36+
DCOS184BootstrapDownloadURL string
37+
DCOS187BootstrapDownloadURL string
38+
DCOS188BootstrapDownloadURL string
39+
DCOS190BootstrapDownloadURL string
4040
}
4141

4242
//KubernetesSpecConfig is the kubernetes container images used.

pkg/api/convertertoupgradeapi.go

-14
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,3 @@ func ConvertVLabsUpgradeContainerService(vlabs *vlabs.UpgradeContainerService) *
1717
convertVLabsOrchestratorProfile(vlabs.OrchestratorProfile, ucs.OrchestratorProfile)
1818
return ucs
1919
}
20-
21-
func convertVLabsUpgradeOrchestratorProfile(vlabscs *vlabs.OrchestratorProfile, api *OrchestratorProfile) {
22-
api.OrchestratorType = OrchestratorType(vlabscs.OrchestratorType)
23-
if api.OrchestratorType == Kubernetes {
24-
switch vlabscs.OrchestratorVersion {
25-
case vlabs.Kubernetes162:
26-
api.OrchestratorVersion = Kubernetes162
27-
case vlabs.Kubernetes160:
28-
api.OrchestratorVersion = Kubernetes160
29-
default:
30-
api.OrchestratorVersion = KubernetesLatest
31-
}
32-
}
33-
}

pkg/api/v20160330/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type Properties struct {
4141
DiagnosticsProfile *DiagnosticsProfile `json:"diagnosticsProfile,omitempty"`
4242

4343
// JumpboxProfile has made it into the new ACS RP stack for
44-
// backward compability.
44+
// backward compatibility.
4545
// TODO: Version this field so that newer versions don't
4646
// allow jumpbox creation
4747
JumpboxProfile *JumpboxProfile `json:"jumpboxProfile,omitempty"`

pkg/api/v20160330/validate.go

-11
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,3 @@ func validateUniqueProfileNames(profiles []*AgentPoolProfile) error {
148148
}
149149
return nil
150150
}
151-
152-
func validateUniquePorts(ports []int, name string) error {
153-
portMap := make(map[int]bool)
154-
for _, port := range ports {
155-
if _, ok := portMap[port]; ok {
156-
return fmt.Errorf("agent profile '%s' has duplicate port '%d', ports must be unique", name, port)
157-
}
158-
portMap[port] = true
159-
}
160-
return nil
161-
}

pkg/api/v20160930/const.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ const (
1818
)
1919

2020
const (
21+
// Windows string constant for VMs
2122
Windows OSType = "Windows"
22-
Linux OSType = "Linux"
23+
// Linux string constant for VMs
24+
Linux OSType = "Linux"
2325
)
2426

2527
// validation values

pkg/api/v20160930/validate.go

-11
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,3 @@ func validateUniqueProfileNames(profiles []*AgentPoolProfile) error {
164164
}
165165
return nil
166166
}
167-
168-
func validateUniquePorts(ports []int, name string) error {
169-
portMap := make(map[int]bool)
170-
for _, port := range ports {
171-
if _, ok := portMap[port]; ok {
172-
return fmt.Errorf("agent profile '%s' has duplicate port '%d', ports must be unique", name, port)
173-
}
174-
portMap[port] = true
175-
}
176-
return nil
177-
}

pkg/api/v20170131/const.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ const (
2020
)
2121

2222
const (
23+
// Windows string constant for VMs
2324
Windows OSType = "Windows"
24-
Linux OSType = "Linux"
25+
// Linux string constant for VMs
26+
Linux OSType = "Linux"
2527
)
2628

2729
// validation values

pkg/api/v20170131/validate.go

-11
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,3 @@ func validateUniqueProfileNames(profiles []*AgentPoolProfile) error {
167167
}
168168
return nil
169169
}
170-
171-
func validateUniquePorts(ports []int, name string) error {
172-
portMap := make(map[int]bool)
173-
for _, port := range ports {
174-
if _, ok := portMap[port]; ok {
175-
return fmt.Errorf("agent profile '%s' has duplicate port '%d', ports must be unique", name, port)
176-
}
177-
portMap[port] = true
178-
}
179-
return nil
180-
}

pkg/api/vlabs/upgradetypesandvalidate.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ func (ucs *UpgradeContainerService) Validate() error {
1313
case DCOS:
1414
case Swarm:
1515
case SwarmMode:
16-
return fmt.Errorf("Upgrade is not supported for orchestrator: %s \n", ucs.OrchestratorProfile.OrchestratorType)
16+
return fmt.Errorf("Upgrade is not supported for orchestrator: %s", ucs.OrchestratorProfile.OrchestratorType)
1717
case Kubernetes:
1818
switch ucs.OrchestratorProfile.OrchestratorVersion {
1919
case Kubernetes162:
2020
case Kubernetes160:
2121
default:
22-
return fmt.Errorf("Invalid orchestrator version: %s \n", ucs.OrchestratorProfile.OrchestratorVersion)
22+
return fmt.Errorf("Invalid orchestrator version: %s", ucs.OrchestratorProfile.OrchestratorVersion)
2323
}
2424
}
2525

0 commit comments

Comments
 (0)