Skip to content

Commit

Permalink
Merge pull request #386 from SamuelStuchly/OCPCLOUD-1066-makefiles
Browse files Browse the repository at this point in the history
[OCPCLOUD-1066] Makefile fix
  • Loading branch information
openshift-merge-robot authored Mar 6, 2021
2 parents 237aa7e + 8453fe2 commit 2e91120
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 87 deletions.
41 changes: 27 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,27 @@ IMAGE = origin-aws-machine-controllers
all: generate build images check

NO_DOCKER ?= 0

ifeq ($(shell command -v podman > /dev/null 2>&1 ; echo $$? ), 0)
ENGINE=podman
else ifeq ($(shell command -v docker > /dev/null 2>&1 ; echo $$? ), 0)
ENGINE=docker
else
NO_DOCKER=1
endif

USE_DOCKER ?= 0
ifeq ($(USE_DOCKER), 1)
ENGINE=docker
endif

ifeq ($(NO_DOCKER), 1)
DOCKER_CMD =
IMAGE_BUILD_CMD = imagebuilder
CGO_ENABLED = 1
else
DOCKER_CMD := docker run --rm -e CGO_ENABLED=1 -v "$(PWD)":/go/src/sigs.k8s.io/cluster-api-provider-aws:Z -w /go/src/sigs.k8s.io/cluster-api-provider-aws openshift/origin-release:golang-1.15
IMAGE_BUILD_CMD = docker build
DOCKER_CMD := $(ENGINE) run --rm -e CGO_ENABLED=1 -v "$(PWD)":/go/src/sigs.k8s.io/cluster-api-provider-aws:Z -w /go/src/sigs.k8s.io/cluster-api-provider-aws openshift/origin-release:golang-1.15
IMAGE_BUILD_CMD = $(ENGINE) build
endif

.PHONY: vendor
Expand Down Expand Up @@ -73,44 +87,43 @@ build: ## build binaries

.PHONY: images
images: ## Create images
ifeq ($(NO_DOCKER), 1)
./hack/imagebuilder.sh
endif
$(IMAGE_BUILD_CMD) -t "$(IMAGE):$(VERSION)" -t "$(IMAGE):$(MUTABLE_TAG)" ./

.PHONY: push
push:
docker push "$(IMAGE):$(VERSION)"
docker push "$(IMAGE):$(MUTABLE_TAG)"
$(ENGINE) push "$(IMAGE):$(VERSION)"
$(ENGINE) push "$(IMAGE):$(MUTABLE_TAG)"

.PHONY: check
check: fmt vet lint test check-pkg ## Check your code

.PHONY: check-pkg
check-pkg:
./hack/verify-actuator-pkg.sh
check: fmt vet lint test # Check your code

.PHONY: unit
unit: # Run unit test
$(DOCKER_CMD) go test -race -cover ./cmd/... ./pkg/...

.PHONY: test-e2e
test-e2e: ## Run e2e tests
hack/e2e.sh
hack/e2e.sh

.PHONY: lint
lint: ## Go lint your code
hack/go-lint.sh -min_confidence 0.3 $$(go list -f '{{ .ImportPath }}' ./... | grep -v -e 'sigs.k8s.io/cluster-api-provider-aws/test' -e 'sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/client/mock')
$(DOCKER_CMD) hack/go-lint.sh -min_confidence 0.3 $$(go list -f '{{ .ImportPath }}' ./... | grep -v -e 'sigs.k8s.io/cluster-api-provider-aws/test' -e 'sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/client/mock')

.PHONY: fmt
fmt: ## Go fmt your code
hack/go-fmt.sh .
$(DOCKER_CMD) hack/go-fmt.sh .

.PHONY: goimports
goimports:
hack/goimports.sh .
$(DOCKER_CMD) hack/goimports.sh .
hack/verify-diff.sh

.PHONY: vet
vet: ## Apply go vet to all go files
hack/go-vet.sh ./...
$(DOCKER_CMD) hack/go-vet.sh ./...

.PHONY: help
help:
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,14 @@ Note: this info is RH only, it needs to be backported every time the `README.md`
1. **Build and run aws actuator outside of the cluster**

```sh
$ go build -o bin/manager sigs.k8s.io/cluster-api-provider-aws/cmd/manager
$ go build -o bin/machine-controller-manager sigs.k8s.io/cluster-api-provider-aws/cmd/manager
```

```sh
$ ./bin/manager --kubeconfig ~/.kube/config --logtostderr -v 5 -alsologtostderr
$ .bin/machine-controller-manager --kubeconfig ~/.kube/config --logtostderr -v 5 -alsologtostderr
```
If running in container with `podman`, or locally without `docker` installed, and encountering issues, see [hacking-guide](https://github.com/openshift/machine-api-operator/blob/master/docs/dev/hacking-guide.md#troubleshooting-make-targets).


1. **Deploy k8s apiserver through machine manifest**:

Expand Down
22 changes: 5 additions & 17 deletions hack/go-fmt.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
#!/bin/sh

REPO_NAME=$(basename "${PWD}")
if [ "$IS_CONTAINER" != "" ]; then
for TARGET in "${@}"; do
find "${TARGET}" -name '*.go' ! -path '*/vendor/*' ! -path '*/.build/*' -exec gofmt -s -w {} \+
done
git diff --exit-code
else
docker run -it --rm \
--env GO111MODULE="$GO111MODULE" \
--env GOFLAGS="$GOFLAGS" \
--env GOPROXY="$GOPROXY" \
--env IS_CONTAINER=TRUE \
--volume "${PWD}:/go/src/sigs.k8s.io/${REPO_NAME}:z" \
--workdir "/go/src/sigs.k8s.io/${REPO_NAME}" \
openshift/origin-release:golang-1.15 \
./hack/go-fmt.sh "${@}"
fi
for TARGET in "${@}"; do
find "${TARGET}" -name '*.go' ! -path '*/vendor/*' ! -path '*/.build/*' -exec gofmt -s -w {} \+
done
git diff --exit-code

18 changes: 3 additions & 15 deletions hack/go-lint.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
#!/bin/sh
# Example: ./hack/go-lint.sh installer/... pkg/... tests/smoke

REPO_NAME=$(basename "${PWD}")
if [ "$IS_CONTAINER" != "" ]; then
golint -set_exit_status "${@}"
else
docker run --rm \
--env GO111MODULE="$GO111MODULE" \
--env GOFLAGS="$GOFLAGS" \
--env GOPROXY="$GOPROXY" \
--env IS_CONTAINER=TRUE \
--volume "${PWD}:/go/src/sigs.k8s.io/${REPO_NAME}:z" \
--workdir "/go/src/sigs.k8s.io/${REPO_NAME}" \
openshift/origin-release:golang-1.15 \
./hack/go-lint.sh "${@}"
fi

golint -set_exit_status "${@}"

17 changes: 3 additions & 14 deletions hack/go-vet.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
#!/bin/sh
REPO_NAME=$(basename "${PWD}")
if [ "$IS_CONTAINER" != "" ]; then
go vet "${@}"
else
docker run --rm \
--env GO111MODULE="$GO111MODULE" \
--env GOFLAGS="$GOFLAGS" \
--env GOPROXY="$GOPROXY" \
--env IS_CONTAINER=TRUE \
--volume "${PWD}:/go/src/sigs.k8s.io/${REPO_NAME}:z" \
--workdir "/go/src/sigs.k8s.io/${REPO_NAME}" \
openshift/origin-release:golang-1.15 \
./hack/go-vet.sh "${@}"
fi;

go vet "${@}"

17 changes: 4 additions & 13 deletions hack/goimports.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#!/bin/sh

REPO_NAME=$(basename "${PWD}")
if [ "$IS_CONTAINER" != "" ]; then
for TARGET in "${@}"; do
find "${TARGET}" -name '*.go' ! -path '*/vendor/*' ! -path '*/.build/*' -exec goimports -w {} \+
done
else
docker run -it --rm \
--env IS_CONTAINER=TRUE \
--volume "${PWD}:/go/src/sigs.k8s.io/${REPO_NAME}:z" \
--workdir "/go/src/sigs.k8s.io/${REPO_NAME}" \
openshift/origin-release:golang-1.15 \
./hack/goimports.sh "${@}"
fi
for TARGET in "${@}"; do
find "${TARGET}" -name '*.go' ! -path '*/vendor/*' ! -path '*/.build/*' -exec goimports -w {} \+
done

4 changes: 4 additions & 0 deletions hack/imagebuilder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
cd /tmp
go get -u github.com/openshift/imagebuilder/cmd/imagebuilder
cd -
5 changes: 5 additions & 0 deletions hack/owner_reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

sudo chown -R $USER bin \
chown $USER .git/index

6 changes: 0 additions & 6 deletions hack/verify-actuator-pkg.sh

This file was deleted.

8 changes: 4 additions & 4 deletions pkg/actuators/machine/machine_scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,18 @@ func TestGetCustomDomainFromDHCP(t *testing.T) {
expectedDomains := "openshift.com openshift.io"
mockAWSClient.EXPECT().DescribeVpcs(gomock.Any()).Return(&ec2.DescribeVpcsOutput{
Vpcs: []*ec2.Vpc{
&ec2.Vpc{DhcpOptionsId: &dhcpID},
{DhcpOptionsId: &dhcpID},
},
}, nil).AnyTimes()

mockAWSClient.EXPECT().DescribeDHCPOptions(gomock.Any()).Return(&ec2.DescribeDhcpOptionsOutput{
DhcpOptions: []*ec2.DhcpOptions{
&ec2.DhcpOptions{
{
DhcpConfigurations: []*ec2.DhcpConfiguration{
&ec2.DhcpConfiguration{
{
Key: &dhcpDomainKeyName,
Values: []*ec2.AttributeValue{
&ec2.AttributeValue{
{
Value: &expectedDomains,
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/actuators/machine/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ func StubDescribeDHCPOptions() (*ec2.DescribeDhcpOptionsOutput, error) {
key := "key"
return &ec2.DescribeDhcpOptionsOutput{
DhcpOptions: []*ec2.DhcpOptions{
&ec2.DhcpOptions{
{
DhcpConfigurations: []*ec2.DhcpConfiguration{
&ec2.DhcpConfiguration{
{
Key: &key,
Values: []*ec2.AttributeValue{},
},
Expand Down

0 comments on commit 2e91120

Please sign in to comment.