diff --git a/Makefile b/Makefile index 73832dc9e33..e92965760b7 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,10 @@ VERIFY_IMPORTS_CONFIG = build/verify-imports/import-rules.yaml # Image URL to use all building/pushing image targets IMG ?= controller:latest -all: test build +all: fmt vet test build # Run tests +.PHONY: test test: generate fmt vet manifests go test ./pkg/... ./cmd/... -coverprofile cover.out @@ -20,56 +21,93 @@ build: manager hiveutil # Build manager binary -manager: generate fmt vet +manager: generate go build -o bin/manager github.com/openshift/hive/cmd/manager # Build hiveutil binary -hiveutil: fmt vet +hiveutil: go build -o bin/hiveutil github.com/openshift/hive/contrib/cmd/hiveutil # Run against the configured Kubernetes cluster in ~/.kube/config +.PHONY: run run: generate fmt vet go run ./cmd/manager/main.go # Install CRDs into a cluster +.PHONY: install install: manifests kubectl apply -f config/crds # Deploy controller in the configured Kubernetes cluster in ~/.kube/config +.PHONY: deploy deploy: manifests kubectl apply -f config/crds kustomize build config/default | kubectl apply -f - # Generate manifests e.g. CRD, RBAC etc. +.PHONY: manifests manifests: go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go all # Run go fmt against code +.PHONY: fmt fmt: go fmt ./pkg/... ./cmd/... ./contrib/... # Run go vet against code +.PHONY: vet vet: go vet ./pkg/... ./cmd/... ./contrib/... +# Run verification tests +.PHONY: verify +verify: hiveutil verify-imports verify-gofmt verify-lint verify-go-vet + # Check import naming +.PHONY: verify-imports verify-imports: @echo "Verifying import naming" - $(foreach file,$(GOFILES), \ - $(shell $(BINDIR)/hiveutil verify-imports -c $(VERIFY_IMPORTS_CONFIG) $(file))\ - ) + @sh -c \ + 'for file in $(GOFILES) ; do \ + $(BINDIR)/hiveutil verify-imports -c $(VERIFY_IMPORTS_CONFIG) $$file || exit 1 ; \ + done' +# Check import naming +.PHONY: verify-lint +verify-lint: + @echo Verifying golint + @sh -c \ + 'for file in $(GOFILES) ; do \ + golint --set_exit_status $$file || exit 1 ; \ + done' + +.PHONY: verify-gofmt +verify-gofmt: + @echo Verifying gofmt + @gofmt -l -s $(SRC_DIRS)>.out 2>&1 || true + @[ ! -s .out ] || \ + (echo && echo "*** Please 'gofmt -s -d' on the following:" && \ + cat .out && echo && rm .out && false) + @rm .out + +.PHONY: verify-go-vet +verify-go-vet: + @echo Verifying go vet + @go vet ./cmd/... ./contrib/... $(go list ./pkg/... | grep -v _generated) # Generate code +.PHONY: generate generate: go generate ./pkg/... ./cmd/... # Build the docker image +.PHONY: docker-build docker-build: test docker build . -t ${IMG} @echo "updating kustomize image patch file for manager resource" sed -i'' -e 's@image: .*@image: '"${IMG}"'@' ./config/default/manager_image_patch.yaml # Push the docker image +.PHONY: docker-push docker-push: docker push ${IMG} diff --git a/contrib/cmd/hiveutil/main.go b/contrib/cmd/hiveutil/main.go index 07bbe8f653c..8f182feff0e 100644 --- a/contrib/cmd/hiveutil/main.go +++ b/contrib/cmd/hiveutil/main.go @@ -23,7 +23,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "github.com/openshift/hive/contrib/pkg/aws_tag_deprovision" + "github.com/openshift/hive/contrib/pkg/awstagdeprovision" "github.com/openshift/hive/contrib/pkg/verification" ) @@ -31,7 +31,7 @@ func main() { log.SetOutput(os.Stdout) log.SetLevel(log.DebugLevel) - cmd := NewCOUtilityCommand() + cmd := newCOUtilityCommand() err := cmd.Execute() if err != nil { @@ -40,7 +40,7 @@ func main() { } } -func NewCOUtilityCommand() *cobra.Command { +func newCOUtilityCommand() *cobra.Command { cmd := &cobra.Command{ Use: "hiveutil SUB-COMMAND", Short: "Utilities for hive", @@ -49,7 +49,7 @@ func NewCOUtilityCommand() *cobra.Command { cmd.Usage() }, } - cmd.AddCommand(aws_tag_deprovision.NewDeprovisionAWSWithTagsCommand()) + cmd.AddCommand(awstagdeprovision.NewDeprovisionAWSWithTagsCommand()) cmd.AddCommand(verification.NewVerifyImportsCommand()) return cmd diff --git a/contrib/pkg/aws_tag_deprovision/aws_tag_deprovision.go b/contrib/pkg/awstagdeprovision/awstagdeprovision.go similarity index 98% rename from contrib/pkg/aws_tag_deprovision/aws_tag_deprovision.go rename to contrib/pkg/awstagdeprovision/awstagdeprovision.go index cfe2b051828..48251d8b143 100644 --- a/contrib/pkg/aws_tag_deprovision/aws_tag_deprovision.go +++ b/contrib/pkg/awstagdeprovision/awstagdeprovision.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package aws_tag_deprovision +package awstagdeprovision import ( "fmt" @@ -440,9 +440,9 @@ func deleteVPCs(awsSession *session.Session, filters awsFilter, logger log.Field if err != nil { logger.Debugf("error deleting VPC %v: %v", *vpc.VpcId, err) return false, nil - } else { - logger.WithField("id", *vpc.VpcId).Info("Deleted VPC") } + + logger.WithField("id", *vpc.VpcId).Info("Deleted VPC") } return false, nil @@ -526,9 +526,9 @@ func deleteNetworkIface(iface *string, ec2Client *ec2.EC2, logger log.FieldLogge if err != nil { logger.Debugf("error deleting network iface: %v", err) return err - } else { - logger.WithField("id", *i.NetworkInterfaceId).Info("Deleted network interface") } + + logger.WithField("id", *i.NetworkInterfaceId).Info("Deleted network interface") } return nil @@ -618,10 +618,10 @@ func deleteRolesFromInstanceProfile(ip *iam.InstanceProfile, iamClient *iam.IAM, if err != nil { logger.Debugf("error deleting policies from role: %v", err) return err - } else { - logger.Infof("Deleted all policies from role: %v", *role.RoleName) } + logger.Infof("Deleted all policies from role: %v", *role.RoleName) + // detach role from instance profile _, err = iamClient.RemoveRoleFromInstanceProfile(&iam.RemoveRoleFromInstanceProfileInput{ InstanceProfileName: ip.InstanceProfileName, @@ -630,10 +630,10 @@ func deleteRolesFromInstanceProfile(ip *iam.InstanceProfile, iamClient *iam.IAM, if err != nil { logger.Debugf("error removing role from instance profile: %v", err) return err - } else { - logger.Infof("Removed role %v from instance profile %v", *role.RoleName, *ip.InstanceProfileName) } + logger.Infof("Removed role %v from instance profile %v", *role.RoleName, *ip.InstanceProfileName) + // now delete the role // need to loop because this is the only time we'll have the name of the role // now that it has been detached from the instance profile @@ -927,9 +927,9 @@ func deleteRoutesFromTable(rt *ec2.RouteTable, ec2Client *ec2.EC2, logger log.Fi if err != nil { logger.Debugf("error deleting route from route table: %v", err) return err - } else { - logger.Infof("Deleted route %v from route table %v", *route.DestinationCidrBlock, *rt.RouteTableId) } + + logger.Infof("Deleted route %v from route table %v", *route.DestinationCidrBlock, *rt.RouteTableId) } return nil } @@ -1176,9 +1176,9 @@ func deleteEntriesFromSharedR53Zone(zoneID string, sharedZoneID string, r53Clien }) if err != nil { return err - } else { - logger.Infof("Deleted record %v from r53 zone %v", *sharedEntry.Name, sharedZoneID) } + + logger.Infof("Deleted record %v from r53 zone %v", *sharedEntry.Name, sharedZoneID) } } } @@ -1249,9 +1249,8 @@ func emptyAndDeleteRoute53Zone(zoneID string, r53Client *route53.Route53, logger }) if err != nil { return err - } else { - logger.Infof("Deleted record %v from r53 zone %v", *entry.Name, zoneID) } + logger.Infof("Deleted record %v from r53 zone %v", *entry.Name, zoneID) } // now delete zone @@ -1260,10 +1259,10 @@ func emptyAndDeleteRoute53Zone(zoneID string, r53Client *route53.Route53, logger }) if err != nil { return err - } else { - logger.WithField("id", zoneID).Info("Deleted route53 zone") } + logger.WithField("id", zoneID).Info("Deleted route53 zone") + return nil } diff --git a/pkg/apis/hive/v1alpha1/clusterdeployment_types.go b/pkg/apis/hive/v1alpha1/clusterdeployment_types.go index 0d4ef3b75e7..8827b44d921 100644 --- a/pkg/apis/hive/v1alpha1/clusterdeployment_types.go +++ b/pkg/apis/hive/v1alpha1/clusterdeployment_types.go @@ -30,6 +30,7 @@ type ClusterDeploymentSpec struct { PlatformSecrets PlatformSecrets `json:"platformSecrets"` } +// PlatformSecrets defines the secrets to be used by various clouds. type PlatformSecrets struct { // +optional AWS *AWSPlatformSecrets `json:"aws,omitempty"`