Skip to content

Commit ae569e3

Browse files
author
Thomas Wiest
committed
Add make verify target
- [x] Add make verify target - [x] Add verify-lint target - [x] Add verify-gofmt target - [x] Add verify-go-vet target - [x] Fix make verify-imports target to error when verify-imports fails. - [x] Fix golint errors in codebase - [x] Remove fmt and vet targets from build targets (necessary for make verify to work) - [x] Add .PHONY to Makefile targets that don't produce files of the same name.
1 parent 296cb99 commit ae569e3

File tree

4 files changed

+67
-29
lines changed

4 files changed

+67
-29
lines changed

Makefile

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ VERIFY_IMPORTS_CONFIG = build/verify-imports/import-rules.yaml
88
# Image URL to use all building/pushing image targets
99
IMG ?= controller:latest
1010

11-
all: test build
11+
all: fmt vet test build
1212

1313
# Run tests
14+
.PHONY: test
1415
test: generate fmt vet manifests
1516
go test ./pkg/... ./cmd/... -coverprofile cover.out
1617

@@ -20,56 +21,93 @@ build: manager hiveutil
2021

2122

2223
# Build manager binary
23-
manager: generate fmt vet
24+
manager: generate
2425
go build -o bin/manager github.com/openshift/hive/cmd/manager
2526

2627
# Build hiveutil binary
27-
hiveutil: fmt vet
28+
hiveutil:
2829
go build -o bin/hiveutil github.com/openshift/hive/contrib/cmd/hiveutil
2930

3031
# Run against the configured Kubernetes cluster in ~/.kube/config
32+
.PHONY: run
3133
run: generate fmt vet
3234
go run ./cmd/manager/main.go
3335

3436
# Install CRDs into a cluster
37+
.PHONY: install
3538
install: manifests
3639
kubectl apply -f config/crds
3740

3841
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
42+
.PHONY: deploy
3943
deploy: manifests
4044
kubectl apply -f config/crds
4145
kustomize build config/default | kubectl apply -f -
4246

4347
# Generate manifests e.g. CRD, RBAC etc.
48+
.PHONY: manifests
4449
manifests:
4550
go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go all
4651

4752
# Run go fmt against code
53+
.PHONY: fmt
4854
fmt:
4955
go fmt ./pkg/... ./cmd/... ./contrib/...
5056

5157
# Run go vet against code
58+
.PHONY: vet
5259
vet:
5360
go vet ./pkg/... ./cmd/... ./contrib/...
5461

62+
# Run verification tests
63+
.PHONY: verify
64+
verify: hiveutil verify-imports verify-gofmt verify-lint verify-go-vet
65+
5566
# Check import naming
67+
.PHONY: verify-imports
5668
verify-imports:
5769
@echo "Verifying import naming"
58-
$(foreach file,$(GOFILES), \
59-
$(shell $(BINDIR)/hiveutil verify-imports -c $(VERIFY_IMPORTS_CONFIG) $(file))\
60-
)
70+
@sh -c \
71+
'for file in $(GOFILES) ; do \
72+
$(BINDIR)/hiveutil verify-imports -c $(VERIFY_IMPORTS_CONFIG) $$file || exit 1 ; \
73+
done'
6174

75+
# Check import naming
76+
.PHONY: verify-lint
77+
verify-lint:
78+
@echo Verifying golint
79+
@sh -c \
80+
'for file in $(GOFILES) ; do \
81+
golint --set_exit_status $$file || exit 1 ; \
82+
done'
83+
84+
.PHONY: verify-gofmt
85+
verify-gofmt:
86+
@echo Verifying gofmt
87+
@gofmt -l -s $(SRC_DIRS)>.out 2>&1 || true
88+
@[ ! -s .out ] || \
89+
(echo && echo "*** Please 'gofmt -s -d' on the following:" && \
90+
cat .out && echo && rm .out && false)
91+
@rm .out
92+
93+
.PHONY: verify-go-vet
94+
verify-go-vet:
95+
@echo Verifying go vet
96+
@go vet ./cmd/... ./contrib/... $(go list ./pkg/... | grep -v _generated)
6297

6398
# Generate code
99+
.PHONY: generate
64100
generate:
65101
go generate ./pkg/... ./cmd/...
66102

67103
# Build the docker image
104+
.PHONY: docker-build
68105
docker-build: test
69106
docker build . -t ${IMG}
70107
@echo "updating kustomize image patch file for manager resource"
71108
sed -i'' -e 's@image: .*@image: '"${IMG}"'@' ./config/default/manager_image_patch.yaml
72109

73110
# Push the docker image
111+
.PHONY: docker-push
74112
docker-push:
75113
docker push ${IMG}

contrib/cmd/hiveutil/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ import (
2323
log "github.com/sirupsen/logrus"
2424
"github.com/spf13/cobra"
2525

26-
"github.com/openshift/hive/contrib/pkg/aws_tag_deprovision"
26+
"github.com/openshift/hive/contrib/pkg/awstagdeprovision"
2727
"github.com/openshift/hive/contrib/pkg/verification"
2828
)
2929

3030
func main() {
3131
log.SetOutput(os.Stdout)
3232
log.SetLevel(log.DebugLevel)
3333

34-
cmd := NewCOUtilityCommand()
34+
cmd := newCOUtilityCommand()
3535

3636
err := cmd.Execute()
3737
if err != nil {
@@ -40,7 +40,7 @@ func main() {
4040
}
4141
}
4242

43-
func NewCOUtilityCommand() *cobra.Command {
43+
func newCOUtilityCommand() *cobra.Command {
4444
cmd := &cobra.Command{
4545
Use: "hiveutil SUB-COMMAND",
4646
Short: "Utilities for hive",
@@ -49,7 +49,7 @@ func NewCOUtilityCommand() *cobra.Command {
4949
cmd.Usage()
5050
},
5151
}
52-
cmd.AddCommand(aws_tag_deprovision.NewDeprovisionAWSWithTagsCommand())
52+
cmd.AddCommand(awstagdeprovision.NewDeprovisionAWSWithTagsCommand())
5353
cmd.AddCommand(verification.NewVerifyImportsCommand())
5454

5555
return cmd

contrib/pkg/aws_tag_deprovision/aws_tag_deprovision.go renamed to contrib/pkg/awstagdeprovision/awstagdeprovision.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package aws_tag_deprovision
17+
package awstagdeprovision
1818

1919
import (
2020
"fmt"
@@ -427,9 +427,9 @@ func deleteVPCs(awsSession *session.Session, filters awsFilter, clusterName stri
427427
if err != nil {
428428
logger.Debugf("error deleting VPC %v: %v", *vpc.VpcId, err)
429429
return false, nil
430-
} else {
431-
logger.WithField("id", *vpc.VpcId).Info("Deleted VPC")
432430
}
431+
432+
logger.WithField("id", *vpc.VpcId).Info("Deleted VPC")
433433
}
434434

435435
return false, nil
@@ -513,9 +513,9 @@ func deleteNetworkIface(iface *string, ec2Client *ec2.EC2, logger log.FieldLogge
513513
if err != nil {
514514
logger.Debugf("error deleting network iface: %v", err)
515515
return err
516-
} else {
517-
logger.WithField("id", *i.NetworkInterfaceId).Info("Deleted network interface")
518516
}
517+
518+
logger.WithField("id", *i.NetworkInterfaceId).Info("Deleted network interface")
519519
}
520520

521521
return nil
@@ -604,10 +604,10 @@ func deleteRolesFromInstanceProfile(ip *iam.InstanceProfile, iamClient *iam.IAM,
604604
if err != nil {
605605
logger.Debugf("error deleting policies from role: %v", err)
606606
return err
607-
} else {
608-
logger.Infof("Deleted all policies from role: %v", *role.RoleName)
609607
}
610608

609+
logger.Infof("Deleted all policies from role: %v", *role.RoleName)
610+
611611
// detach role from instance profile
612612
_, err = iamClient.RemoveRoleFromInstanceProfile(&iam.RemoveRoleFromInstanceProfileInput{
613613
InstanceProfileName: ip.InstanceProfileName,
@@ -616,10 +616,10 @@ func deleteRolesFromInstanceProfile(ip *iam.InstanceProfile, iamClient *iam.IAM,
616616
if err != nil {
617617
logger.Debugf("error removing role from instance profile: %v", err)
618618
return err
619-
} else {
620-
logger.Infof("Removed role %v from instance profile %v", *role.RoleName, *ip.InstanceProfileName)
621619
}
622620

621+
logger.Infof("Removed role %v from instance profile %v", *role.RoleName, *ip.InstanceProfileName)
622+
623623
// now delete the role
624624
// need to loop because this is the only time we'll have the name of the role
625625
// now that it has been detached from the instance profile
@@ -748,8 +748,8 @@ func tryDeleteRoleProfileByName(roleName string, profileName string, session *se
748748
func deleteIAMresources(session *session.Session, filter awsFilter, clusterName string, logger log.FieldLogger) (bool, error) {
749749
logger.Debugf("Deleting IAM resources")
750750
defer logger.Debugf("Exiting deleting IAM resources")
751-
installer_type := []string{"master", "worker", "bootstrap"}
752-
for _, t := range installer_type {
751+
installerType := []string{"master", "worker", "bootstrap"}
752+
for _, t := range installerType {
753753
// Naming of IAM resources expected from https://github.com/openshift/installer as follows:
754754
// $CLUSTER_NAME-master-role $CLUSTER_NAME-worker-role $CLUSTER_NAME-bootstrap-role
755755
// $CLUSTER_NAME-master-profile $CLUSTER_NAME-worker-profile $CLUSTER_NAME-bootstrap-profile
@@ -993,9 +993,9 @@ func deleteRoutesFromTable(rt *ec2.RouteTable, ec2Client *ec2.EC2, logger log.Fi
993993
if err != nil {
994994
logger.Debugf("error deleting route from route table: %v", err)
995995
return err
996-
} else {
997-
logger.Infof("Deleted route %v from route table %v", *route.DestinationCidrBlock, *rt.RouteTableId)
998996
}
997+
998+
logger.Infof("Deleted route %v from route table %v", *route.DestinationCidrBlock, *rt.RouteTableId)
999999
}
10001000
return nil
10011001
}
@@ -1232,9 +1232,9 @@ func deleteEntriesFromSharedR53Zone(zoneID string, sharedZoneID string, r53Clien
12321232
})
12331233
if err != nil {
12341234
return err
1235-
} else {
1236-
logger.Infof("Deleted record %v from r53 zone %v", *sharedEntry.Name, sharedZoneID)
12371235
}
1236+
1237+
logger.Infof("Deleted record %v from r53 zone %v", *sharedEntry.Name, sharedZoneID)
12381238
}
12391239
}
12401240
}
@@ -1305,9 +1305,8 @@ func emptyAndDeleteRoute53Zone(zoneID string, r53Client *route53.Route53, logger
13051305
})
13061306
if err != nil {
13071307
return err
1308-
} else {
1309-
logger.Infof("Deleted record %v from r53 zone %v", *entry.Name, zoneID)
13101308
}
1309+
logger.Infof("Deleted record %v from r53 zone %v", *entry.Name, zoneID)
13111310
}
13121311

13131312
// now delete zone
@@ -1316,10 +1315,10 @@ func emptyAndDeleteRoute53Zone(zoneID string, r53Client *route53.Route53, logger
13161315
})
13171316
if err != nil {
13181317
return err
1319-
} else {
1320-
logger.WithField("id", zoneID).Info("Deleted route53 zone")
13211318
}
13221319

1320+
logger.WithField("id", zoneID).Info("Deleted route53 zone")
1321+
13231322
return nil
13241323
}
13251324

pkg/apis/hive/v1alpha1/clusterdeployment_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type ClusterDeploymentSpec struct {
3030
PlatformSecrets PlatformSecrets `json:"platformSecrets"`
3131
}
3232

33+
// PlatformSecrets defines the secrets to be used by various clouds.
3334
type PlatformSecrets struct {
3435
// +optional
3536
AWS *AWSPlatformSecrets `json:"aws,omitempty"`

0 commit comments

Comments
 (0)