From 9d56f3eaa49a76d79af4b1c50755005f562727ff Mon Sep 17 00:00:00 2001 From: SamuelStuchly Date: Mon, 8 Feb 2021 18:51:24 +0100 Subject: [PATCH 1/2] Update make targets to run with podman and docker or without container, remove useless targets --- Makefile | 41 ++++++++++++++------- hack/go-fmt.sh | 22 +++-------- hack/go-lint.sh | 18 ++------- hack/go-vet.sh | 17 ++------- hack/goimports.sh | 17 ++------- hack/imagebuilder.sh | 4 ++ hack/verify-actuator-pkg.sh | 6 --- pkg/actuators/machine/machine_scope_test.go | 8 ++-- pkg/actuators/machine/stubs.go | 4 +- 9 files changed, 52 insertions(+), 85 deletions(-) create mode 100755 hack/imagebuilder.sh delete mode 100755 hack/verify-actuator-pkg.sh diff --git a/Makefile b/Makefile index c2d8353e07..b733ffae0f 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -73,19 +87,18 @@ 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 @@ -93,24 +106,24 @@ unit: # Run unit test .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: diff --git a/hack/go-fmt.sh b/hack/go-fmt.sh index 6ae96550fd..5bd41c8a45 100755 --- a/hack/go-fmt.sh +++ b/hack/go-fmt.sh @@ -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 + diff --git a/hack/go-lint.sh b/hack/go-lint.sh index 515f264e60..edbd8ab670 100755 --- a/hack/go-lint.sh +++ b/hack/go-lint.sh @@ -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 "${@}" + diff --git a/hack/go-vet.sh b/hack/go-vet.sh index c5bf6ed198..d4bc164305 100755 --- a/hack/go-vet.sh +++ b/hack/go-vet.sh @@ -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 "${@}" + diff --git a/hack/goimports.sh b/hack/goimports.sh index 2bc3122cc5..4b06f35d55 100755 --- a/hack/goimports.sh +++ b/hack/goimports.sh @@ -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 + diff --git a/hack/imagebuilder.sh b/hack/imagebuilder.sh new file mode 100755 index 0000000000..821fe2dfdd --- /dev/null +++ b/hack/imagebuilder.sh @@ -0,0 +1,4 @@ +#!/bin/sh +cd /tmp +go get -u github.com/openshift/imagebuilder/cmd/imagebuilder +cd - diff --git a/hack/verify-actuator-pkg.sh b/hack/verify-actuator-pkg.sh deleted file mode 100755 index 6da7069f0c..0000000000 --- a/hack/verify-actuator-pkg.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -set -e - -go get -mod=readonly -u github.com/openshift/cluster-api-actuator-pkg -exec git diff --exit-code diff --git a/pkg/actuators/machine/machine_scope_test.go b/pkg/actuators/machine/machine_scope_test.go index 28f29280f6..d0450b12c8 100644 --- a/pkg/actuators/machine/machine_scope_test.go +++ b/pkg/actuators/machine/machine_scope_test.go @@ -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, }, }, diff --git a/pkg/actuators/machine/stubs.go b/pkg/actuators/machine/stubs.go index 927f8eb851..c8737d3374 100644 --- a/pkg/actuators/machine/stubs.go +++ b/pkg/actuators/machine/stubs.go @@ -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{}, }, From 8453fe23d7f6f0f5206328223284ed0282e04ddc Mon Sep 17 00:00:00 2001 From: SamuelStuchly Date: Wed, 10 Feb 2021 12:02:20 +0100 Subject: [PATCH 2/2] Add script for fixing permission issues when running make targets with podman --- README.md | 6 ++++-- hack/owner_reset.sh | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100755 hack/owner_reset.sh diff --git a/README.md b/README.md index 68caea4cfb..b9ef07b666 100644 --- a/README.md +++ b/README.md @@ -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**: diff --git a/hack/owner_reset.sh b/hack/owner_reset.sh new file mode 100755 index 0000000000..cf7de566ce --- /dev/null +++ b/hack/owner_reset.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +sudo chown -R $USER bin \ + chown $USER .git/index + \ No newline at end of file