Skip to content

Commit

Permalink
Add more verifications and fix verify failures
Browse files Browse the repository at this point in the history
Since gometalinter has been deprecated, it also switches to
golangci-lint.
  • Loading branch information
feiskyer committed Dec 26, 2019
1 parent 03dcbd5 commit e1db5ed
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 51 deletions.
39 changes: 17 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,19 @@ ifdef JUNIT
endif

.PHONY: test-check
test-check: test-lint-prepare test-lint test-boilerplate test-spelling
test-check: test-lint test-boilerplate test-spelling test-gofmt test-govet

.PHONY: test-lint-prepare
test-lint-prepare:
GO111MODULE=off go get -u gopkg.in/alecthomas/gometalinter.v1
GO111MODULE=off gometalinter.v1 -i
.PHONY: test-gofmt
test-gofmt:
hack/verify-gofmt.sh

.PHONY: test-govet
test-govet:
hack/verify-govet.sh

.PHONY: test-lint
test-lint:
gometalinter.v1 $(GOMETALINTER_OPTION) ./ ./cmd/cloud-controller-manager/...
gometalinter.v1 $(GOMETALINTER_OPTION) -e "should not use dot imports" tests/e2e/...
hack/verify-golint.sh

.PHONY: test-boilerplate
test-boilerplate:
Expand All @@ -134,27 +136,20 @@ test-spelling:
test-bazel:
hack/verify-bazel.sh

.PHONY: update-prepare
update-prepare:
go get -u github.com/sgotti/glide-vc
go get -u github.com/Masterminds/glide

.PHONY: update-dependencies
update:
hack/update-dependenciess.sh
update-dependencies:
hack/update-dependencies.sh

.PHONY: update-bazel
update-bazel:
hack/update-bazel.sh

.PHONY: test-update
test-update: update-prepare update-dependencies update-bazel
git checkout glide.lock
git add -A .
git diff --staged --name-status --exit-code || { \
echo "You have committed changes after running 'make update', please check"; \
exit 1; \
} \
.PHONY: update-gofmt
update-gofmt:
hack/update-gofmt.sh

.PHONY: update
update: update-dependencies update-bazel update-gofmt

test-e2e:
hack/test_k8s_e2e.sh $(TEST_E2E_ARGS)
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.4.0
gopkg.in/yaml.v2 v2.2.7 // indirect
k8s.io/api v0.0.0
k8s.io/apimachinery v0.0.0
k8s.io/apiserver v0.0.0
Expand Down Expand Up @@ -44,6 +45,7 @@ replace (
github.com/GoogleCloudPlatform/k8s-cloud-provider => github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20190822182118-27a4ced34534
github.com/JeffAshton/win_pdh => github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab
github.com/MakeNowJust/heredoc => github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd
github.com/Masterminds/vcs => github.com/Masterminds/vcs v1.13.1
github.com/Microsoft/go-winio => github.com/Microsoft/go-winio v0.4.11
github.com/Microsoft/hcsshim => github.com/Microsoft/hcsshim v0.0.0-20190417211021-672e52e9209d
github.com/NYTimes/gziphandler => github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46
Expand All @@ -69,6 +71,7 @@ replace (
github.com/bgentry/speakeasy => github.com/bgentry/speakeasy v0.1.0
github.com/bifurcation/mint => github.com/bifurcation/mint v0.0.0-20180715133206-93c51c6ce115
github.com/blang/semver => github.com/blang/semver v3.5.0+incompatible
github.com/bmatcuk/doublestar => github.com/bmatcuk/doublestar v1.2.2
github.com/boltdb/bolt => github.com/boltdb/bolt v1.3.1
github.com/bradfitz/go-smtpd => github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625
github.com/caddyserver/caddy => github.com/caddyserver/caddy v1.0.3
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ github.com/mholt/certmagic v0.6.2-0.20190624175158-6a42ef9fe8c2/go.mod h1:g4cOPx
github.com/miekg/dns v1.1.4/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/mindprince/gonvml v0.0.0-20190828220739-9ebdce4bb989/go.mod h1:2eu9pRWp8mo84xCg6KswZ+USQHjwgRhNp06sozOdsTY=
github.com/mistifyio/go-zfs v2.1.1+incompatible/go.mod h1:8AuVvqP/mXw1px98n46wfvcGfQ4ci2FwoAjKYxuo3Z4=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk=
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
Expand Down
19 changes: 19 additions & 0 deletions hack/update-gofmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -euo pipefail

find . -name "*.go" | grep -v "\/vendor\/" | xargs gofmt -s -w
28 changes: 28 additions & 0 deletions hack/verify-gofmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -euo pipefail

echo "Verifying gofmt"

readonly diff=$(find . -name "*.go" | grep -v "\/vendor\/" | xargs gofmt -s -d 2>&1)
if [[ -n "${diff}" ]]; then
echo "${diff}"
echo
echo "Please run hack/update-gofmt.sh to fix the issue(s)"
exit 1
fi
echo "No issue found"
23 changes: 23 additions & 0 deletions hack/verify-golint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -euo pipefail

GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint

golangci-lint run --deadline=10m

echo "Congratulations! All Go source files have been linted."
23 changes: 23 additions & 0 deletions hack/verify-govet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -euo pipefail

echo "Verifying govet"

go vet $(go list ./... | grep -v vendor)

echo "Done"
17 changes: 4 additions & 13 deletions tests/e2e/autoscaling/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ var _ = Describe("Cluster size autoscaler [Serial][Slow]", func() {
By("Scale up")
targetNodeCount := initNodeCount + 1
err = utils.WaitAutoScaleNodes(cs, targetNodeCount)
utils.LogPodStatus(cs, ns.Name)
Expect(err).NotTo(HaveOccurred())
err = utils.LogPodStatus(cs, ns.Name)
Expect(err).NotTo(HaveOccurred())

By("Scale down")
Expand All @@ -128,7 +129,8 @@ var _ = Describe("Cluster size autoscaler [Serial][Slow]", func() {
Expect(err).NotTo(HaveOccurred())
targetNodeCount = initNodeCount
err = utils.WaitAutoScaleNodes(cs, targetNodeCount)
utils.LogPodStatus(cs, ns.Name)
Expect(err).NotTo(HaveOccurred())
err = utils.LogPodStatus(cs, ns.Name)
Expect(err).NotTo(HaveOccurred())
})
})
Expand All @@ -151,17 +153,6 @@ func createPodSpec() (result v1.PodSpec) {
return
}

func createScalerPodManifest(name string) (result *v1.Pod) {
spec := createPodSpec()
result = &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: spec,
}
return
}

func createDeploymentManifest(name string, replicas int32, label map[string]string) (result *appsv1.Deployment) {
spec := createPodSpec()
result = &appsv1.Deployment{
Expand Down
13 changes: 6 additions & 7 deletions tests/e2e/network/service_annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ import (
)

var (
scalesetRE = regexp.MustCompile(`.*/subscriptions/(?:.*)/resourceGroups/(.+)/providers/Microsoft.Compute/virtualMachineScaleSets/(.+)/virtualMachines(?:.*)`)
lbNameRE = regexp.MustCompile(`^/subscriptions/(?:.*)/resourceGroups/(?:.*)/providers/Microsoft.Network/loadBalancers/(.+)/frontendIPConfigurations(?:.*)`)
backendIPConfigurationRE = regexp.MustCompile(`^/subscriptions/(?:.*)/resourceGroups/(?:.*)/providers/Microsoft.Compute/virtualMachineScaleSets/(.+)/virtualMachines(?:.*)`)
backendASIPConfigurationRE = regexp.MustCompile(`^/subscriptions/(?:.*)/resourceGroups/(?:.*)/providers/Microsoft.Compute/availabilitySets/(.+)/virtualMachines(?:.*)`)
scalesetRE = regexp.MustCompile(`.*/subscriptions/(?:.*)/resourceGroups/(.+)/providers/Microsoft.Compute/virtualMachineScaleSets/(.+)/virtualMachines(?:.*)`)
lbNameRE = regexp.MustCompile(`^/subscriptions/(?:.*)/resourceGroups/(?:.*)/providers/Microsoft.Network/loadBalancers/(.+)/frontendIPConfigurations(?:.*)`)
backendIPConfigurationRE = regexp.MustCompile(`^/subscriptions/(?:.*)/resourceGroups/(?:.*)/providers/Microsoft.Compute/virtualMachineScaleSets/(.+)/virtualMachines(?:.*)`)
)

const (
Expand Down Expand Up @@ -165,7 +164,8 @@ var _ = FDescribe("Service with annotation", func() {
By("Test subnet doesn't exist. Creating a new one...")
newSubnetCIDR, err = utils.GetNextSubnetCIDR(vNet)
Expect(err).NotTo(HaveOccurred())
azureTestClient.CreateSubnet(vNet, &subnetName, &newSubnetCIDR)
err = azureTestClient.CreateSubnet(vNet, &subnetName, &newSubnetCIDR)
Expect(err).NotTo(HaveOccurred())
}

annotation := map[string]string{
Expand Down Expand Up @@ -441,8 +441,7 @@ func createServiceWithAnnotation(cs clientset.Interface, serviceName, nsName str
// defaultDeployment returns a default deployment
// running nginx image which exposes port 80
func createNginxDeploymentManifest(name string, labels map[string]string) (result *appsv1.Deployment) {
var replicas int32
replicas = 5
var replicas int32 = 5
result = &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/utils/container_registry_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func (tc *AzureTestClient) DeleteContainerRegistry(registryName string) (err err

Logf("Deleting acr %s in resource group %s.", registryName, rgName)
future, err := acrClient.Delete(context.Background(), rgName, registryName)
if err != nil {
return fmt.Errorf("failed to delete acr %s in resource group %s with error: %v", registryName, rgName, err)
}
err = future.WaitForCompletionRef(context.Background(), acrClient.Client)
if err != nil {
return fmt.Errorf("failed to delete acr %s in resource group %s with error: %v", registryName, rgName, err)
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/utils/network_interface_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
var (
nicIDConfigurationRE = regexp.MustCompile(`^/subscriptions/(?:.*)/resourceGroups/(?:.*)/providers/Microsoft.Network/networkInterfaces/(.+)`)
vmasNamePrefixRE = regexp.MustCompile(`(.+)-nic-\d+`)
nicNameRE = regexp.MustCompile(`k8s-.+-\d+-.+`)
)

// ListNICs returns the NIC list in the given resource group
Expand Down
7 changes: 2 additions & 5 deletions tests/e2e/utils/node_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ func GetAllNodes(cs clientset.Interface) ([]v1.Node, error) {
if err != nil {
return nil, err
}
ret := make([]v1.Node, 0)
for _, node := range nodesList.Items {
ret = append(ret, node)
}
return ret, nil

return nodesList.Items, nil
}

// GetMaster returns the master node
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/utils/resource_group_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func CreateTestResourceGroup(tc *AzureTestClient) (*resources.Group, func(string
Expect(err).NotTo(HaveOccurred())
err = WaitForDeleteResourceGroupCompletion(gc, future, rgName)
Expect(err).NotTo(HaveOccurred())
return
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/utils/service_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func WaitServiceExposure(cs clientset.Interface, namespace string, name string)
}

IngressList := service.Status.LoadBalancer.Ingress
if IngressList == nil || len(IngressList) == 0 {
if len(IngressList) == 0 {
err = fmt.Errorf("Cannot find Ingress in limited time")
Logf("Fail to find ingress, retry it in 10 seconds")
return false, nil
Expand Down Expand Up @@ -111,7 +111,7 @@ func WaitUpdateServiceExposure(cs clientset.Interface, namespace string, name st
}

IngressList := service.Status.LoadBalancer.Ingress
if IngressList == nil || len(IngressList) == 0 {
if len(IngressList) == 0 {
err = fmt.Errorf("Cannot find Ingress in limited time")
Logf("Fail to get ingress, retry it in %v seconds", poll)
return false, nil
Expand Down

0 comments on commit e1db5ed

Please sign in to comment.