Skip to content

Commit

Permalink
Fix Release process for ARM (#155)
Browse files Browse the repository at this point in the history
* Update golangci version to 1.49.0
* Fix kubebuilder install script for ARM
* fix kustomize install for arm
* fix golangci config due to the version upgrade
* fix end2end test
  • Loading branch information
clamoriniere committed Sep 27, 2022
1 parent 256c54c commit 58d9cd2
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 62 deletions.
5 changes: 5 additions & 0 deletions .golangci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
[linters]
enable-all = true
disable = [
"exhaustruct",
"nosnakecase",
"logrlint",
"nonamedreturns",
"maligned",
"revive",
"lll",
"gas",
"dupl",
Expand Down
2 changes: 2 additions & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ core,"github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty",MIT
core,"github.com/onsi/ginkgo/types",MIT
core,"github.com/onsi/gomega",MIT
core,"github.com/onsi/gomega/format",MIT
core,"github.com/onsi/gomega/gbytes",MIT
core,"github.com/onsi/gomega/gexec",MIT
core,"github.com/onsi/gomega/internal",MIT
core,"github.com/onsi/gomega/matchers",MIT
core,"github.com/onsi/gomega/matchers/support/goraph/bipartitegraph",MIT
Expand Down
43 changes: 18 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ GIT_COMMIT?=$(shell git rev-parse HEAD)
DATE=$(shell date +%Y-%m-%d/%H:%M:%S )
LDFLAGS=-w -s -X ${BUILDINFOPKG}.Commit=${GIT_COMMIT} -X ${BUILDINFOPKG}.Version=${VERSION} -X ${BUILDINFOPKG}.BuildTime=${DATE}
GOARCH?=amd64
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

# Default bundle image tag
BUNDLE_IMG ?= controller-bundle:$(BUNDLE_VERSION)
Expand Down Expand Up @@ -46,7 +47,7 @@ gotest:
e2e: build manifests verify-license goe2e

# Runs e2e tests (expects a configured cluster)
goe2e:
goe2e: bin/kubebuilder-tools
go test --tags=e2e ./controllers -ginkgo.progress -ginkgo.v -test.v

# Build manager binary
Expand All @@ -59,16 +60,16 @@ run: generate lint manifests

# Install CRDs into a cluster
install: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl apply -f -
./bin/kustomize build config/crd | kubectl apply -f -

# Uninstall CRDs from a cluster
uninstall: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl delete -f -
./bin/kustomize build config/crd | kubectl delete -f -

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
cd config/manager && $(ROOT_DIR)/bin/kustomize edit set image controller=${IMG}
./bin/kustomize build config/default | kubectl apply -f -

# Generate manifests e.g. CRD, RBAC etc.
manifests: generate-manifests patch-crds
Expand Down Expand Up @@ -124,27 +125,13 @@ else
CONTROLLER_GEN=$(shell which controller-gen)
endif

kustomize:
ifeq (, $(shell which kustomize))
@{ \
set -e ;\
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/kustomize/kustomize/v3@v3.5.4 ;\
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
}
KUSTOMIZE=$(GOBIN)/kustomize
else
KUSTOMIZE=$(shell which kustomize)
endif

# Generate bundle manifests and metadata, then validate generated files.
.PHONY: bundle
bundle: manifests
bundle: manifests bin/kustomize
./bin/operator-sdk generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | ./bin/operator-sdk generate bundle -q --overwrite --version $(BUNDLE_VERSION) $(BUNDLE_METADATA_OPTS)
cd config/manager && $(ROOT_DIR)/bin/kustomize edit set image controller=$(IMG)
./bin/kustomize build config/manifests | ./bin/operator-sdk generate bundle -q --overwrite --version $(BUNDLE_VERSION) $(BUNDLE_METADATA_OPTS)
./bin/operator-sdk bundle validate ./bundle

# Build the bundle image.
Expand All @@ -156,7 +143,7 @@ bundle-build:
# Datadog Custom part
#
.PHONY: install-tools
install-tools: bin/golangci-lint bin/operator-sdk bin/yq bin/kubebuilder
install-tools: bin/golangci-lint bin/operator-sdk bin/yq bin/kubebuilder bin/kubebuilder-tools

.PHONY: generate-openapi
generate-openapi: bin/openapi-gen
Expand Down Expand Up @@ -193,7 +180,10 @@ check-eds: fmt vet lint
go build -ldflags '${LDFLAGS}' -o bin/check-eds ./cmd/check-eds/main.go

bin/kubebuilder:
./hack/install-kubebuilder.sh 2.3.2
./hack/install-kubebuilder.sh 2.3.2 ./bin

bin/kubebuilder-tools:
./hack/install-kubebuilder-tools.sh 1.24.1

bin/openapi-gen:
go build -o ./bin/openapi-gen k8s.io/kube-openapi/cmd/openapi-gen
Expand All @@ -202,10 +192,13 @@ bin/yq:
./hack/install-yq.sh 3.3.0

bin/golangci-lint:
hack/golangci-lint.sh v1.45.0
hack/golangci-lint.sh v1.49.0

bin/operator-sdk:
./hack/install-operator-sdk.sh v1.5.0

bin/wwhrd:
./hack/install-wwhrd.sh 0.2.4

bin/kustomize:
./hack/install_kustomize.sh 4.5.7 ./bin
1 change: 1 addition & 0 deletions controllers/extendeddaemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2019 Datadog, Inc.

//go:build !e2e
// +build !e2e

package controllers
Expand Down
16 changes: 13 additions & 3 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"os"
"path/filepath"
"testing"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -69,7 +71,7 @@ var _ = BeforeSuite(func(done Done) {
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases", testConfig.crdVersion)},
}
// Not present in envtest.Environment
err = os.Setenv("KUBEBUILDER_ASSETS", filepath.Join("..", "bin", "kubebuilder"))
err = os.Setenv("KUBEBUILDER_ASSETS", filepath.Join("..", "bin", "kubebuilder-tools", "bin"))
Expect(err).ToNot(HaveOccurred())

cfg, err = testEnv.Start()
Expand Down Expand Up @@ -115,14 +117,22 @@ var _ = BeforeSuite(func(done Done) {
defer GinkgoRecover()
err = mgr.Start(ctrl.SetupSignalHandler())
Expect(err).ToNot(HaveOccurred())

gexec.KillAndWait(10 * time.Second)

// Teardown the test environment once controller is finished.
// Otherwise from Kubernetes 1.21+, teardon timeouts waiting on
// kube-apiserver to return
err := testEnv.Stop()
Expect(err).ToNot(HaveOccurred())
}()

close(done)
}, 60)

var _ = AfterSuite(func() {
By("tearing down the test environment")
if testConfig.namespace != defaultNamespace {
/*if testConfig.namespace != defaultNamespace {
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: testConfig.namespace,
Expand All @@ -131,5 +141,5 @@ var _ = AfterSuite(func() {
Expect(k8sClient.Delete(context.Background(), ns)).Should(Succeed())
}
err := testEnv.Stop()
Expect(err).ToNot(HaveOccurred())
Expect(err).ToNot(HaveOccurred())*/
})
1 change: 1 addition & 0 deletions controllers/suite_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.

//go:build !e2e
// +build !e2e

package controllers
Expand Down
87 changes: 55 additions & 32 deletions hack/golangci-lint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/sh
set -e
# Code generated by godownloader on 2019-03-31T17:13:52Z. DO NOT EDIT.
#

usage() {
this=$1
Expand Down Expand Up @@ -52,7 +50,7 @@ execute() {
rm -rf "${srcdir}"
(cd "${tmpdir}" && untar "${TARBALL}")
test ! -d "${BINDIR}" && install -d "${BINDIR}"
for binexe in "golangci-lint" ; do
for binexe in $BINARIES; do
if [ "$OS" = "windows" ]; then
binexe="${binexe}.exe"
fi
Expand All @@ -61,27 +59,48 @@ execute() {
done
rm -rf "${tmpdir}"
}
is_supported_platform() {
platform=$1
found=1
case "$platform" in
darwin/amd64) found=0 ;;
darwin/386) found=0 ;;
windows/amd64) found=0 ;;
windows/386) found=0 ;;
linux/amd64) found=0 ;;
linux/386) found=0 ;;
get_binaries() {
case "$PLATFORM" in
darwin/amd64) BINARIES="golangci-lint" ;;
darwin/arm64) BINARIES="golangci-lint" ;;
darwin/armv6) BINARIES="golangci-lint" ;;
darwin/armv7) BINARIES="golangci-lint" ;;
darwin/mips64) BINARIES="golangci-lint" ;;
darwin/mips64le) BINARIES="golangci-lint" ;;
darwin/ppc64le) BINARIES="golangci-lint" ;;
darwin/s390x) BINARIES="golangci-lint" ;;
freebsd/386) BINARIES="golangci-lint" ;;
freebsd/amd64) BINARIES="golangci-lint" ;;
freebsd/armv6) BINARIES="golangci-lint" ;;
freebsd/armv7) BINARIES="golangci-lint" ;;
freebsd/mips64) BINARIES="golangci-lint" ;;
freebsd/mips64le) BINARIES="golangci-lint" ;;
freebsd/ppc64le) BINARIES="golangci-lint" ;;
freebsd/s390x) BINARIES="golangci-lint" ;;
linux/386) BINARIES="golangci-lint" ;;
linux/amd64) BINARIES="golangci-lint" ;;
linux/arm64) BINARIES="golangci-lint" ;;
linux/armv6) BINARIES="golangci-lint" ;;
linux/armv7) BINARIES="golangci-lint" ;;
linux/mips64) BINARIES="golangci-lint" ;;
linux/mips64le) BINARIES="golangci-lint" ;;
linux/ppc64le) BINARIES="golangci-lint" ;;
linux/s390x) BINARIES="golangci-lint" ;;
linux/riscv64) BINARIES="golangci-lint" ;;
windows/386) BINARIES="golangci-lint" ;;
windows/amd64) BINARIES="golangci-lint" ;;
windows/arm64) BINARIES="golangci-lint" ;;
windows/armv6) BINARIES="golangci-lint" ;;
windows/armv7) BINARIES="golangci-lint" ;;
windows/mips64) BINARIES="golangci-lint" ;;
windows/mips64le) BINARIES="golangci-lint" ;;
windows/ppc64le) BINARIES="golangci-lint" ;;
windows/s390x) BINARIES="golangci-lint" ;;
*)
log_crit "platform $PLATFORM is not supported. Make sure this script is up-to-date and file request at https://github.com/${PREFIX}/issues/new"
exit 1
;;
esac
return $found
}
check_platform() {
if is_supported_platform "$PLATFORM"; then
# optional logging goes here
true
else
log_crit "platform $PLATFORM is not supported. Make sure this script is up-to-date and file request at https://github.com/${PREFIX}/issues/new"
exit 1
fi
}
tag_to_version() {
if [ -z "${TAG}" ]; then
Expand All @@ -99,8 +118,8 @@ tag_to_version() {
VERSION=${TAG#v}
}
adjust_format() {
# change format (tar.gz or zip) based on ARCH
case ${ARCH} in
# change format (tar.gz or zip) based on OS
case ${OS} in
windows) FORMAT=zip ;;
esac
true
Expand Down Expand Up @@ -174,7 +193,10 @@ log_crit() {
uname_os() {
os=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$os" in
msys_nt) os="windows" ;;
msys*) os="windows" ;;
mingw*) os="windows" ;;
cygwin*) os="windows" ;;
win*) os="windows" ;;
esac
echo "$os"
}
Expand Down Expand Up @@ -207,7 +229,7 @@ uname_os_check() {
solaris) return 0 ;;
windows) return 0 ;;
esac
log_crit "uname_os_check '$(uname -s)' got converted to '$os' which is not a GOOS value. Please file bug at https://github.com/client9/shlib"
log_crit "uname_os_check '$(uname -s)' got converted to '$os' which is not a GOOS value."
return 1
}
uname_arch_check() {
Expand All @@ -226,16 +248,17 @@ uname_arch_check() {
mips64) return 0 ;;
mips64le) return 0 ;;
s390x) return 0 ;;
riscv64) return 0 ;;
amd64p32) return 0 ;;
esac
log_crit "uname_arch_check '$(uname -m)' got converted to '$arch' which is not a GOARCH value. Please file bug report at https://github.com/client9/shlib"
log_crit "uname_arch_check '$(uname -m)' got converted to '$arch' which is not a GOARCH value."
return 1
}
untar() {
tarball=$1
case "${tarball}" in
*.tar.gz | *.tgz) tar -xzf "${tarball}" ;;
*.tar) tar -xf "${tarball}" ;;
*.tar.gz | *.tgz) tar --no-same-owner -xzf "${tarball}" ;;
*.tar) tar --no-same-owner -xf "${tarball}" ;;
*.zip) unzip "${tarball}" ;;
*)
log_err "untar unknown archive format for ${tarball}"
Expand Down Expand Up @@ -363,7 +386,7 @@ uname_arch_check "$ARCH"

parse_args "$@"

check_platform
get_binaries

tag_to_version

Expand All @@ -382,4 +405,4 @@ CHECKSUM=${PROJECT_NAME}-${VERSION}-checksums.txt
CHECKSUM_URL=${GITHUB_DOWNLOAD}/${TAG}/${CHECKSUM}


execute
execute
33 changes: 33 additions & 0 deletions hack/install-kubebuilder-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

ROOT=$(git rev-parse --show-toplevel)
WORK_DIR=$(mktemp -d)
cleanup() {
rm -rf "$WORK_DIR"
}
trap "cleanup" EXIT SIGINT

VERSION=$1

TEST_DEPS_PATH=${2:-"$ROOT/bin/kubebuilder-tools"}

if [ -z "$VERSION" ];
then
echo "usage: bin/install-kubebuilder-tools.sh <version>"
exit 1
fi


OS=$(go env GOOS)
ARCH=$(go env GOARCH)

curl -L https://storage.googleapis.com/kubebuilder-tools/kubebuilder-tools-${VERSION}-${OS}-${ARCH}.tar.gz | tar -xz -C $WORK_DIR

# move to repo_path/bin/kubebuilder - you'll need to set the KUBEBUILDER_ASSETS env var with
rm -rf ${TEST_DEPS_PATH}
mkdir -p ${TEST_DEPS_PATH}
mv $WORK_DIR/kubebuilder/bin/ ${TEST_DEPS_PATH}
3 changes: 1 addition & 2 deletions hack/install-kubebuilder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ arch=$(go env GOARCH)
# download kubebuilder and extract it to tmp
curl -L https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${VERSION}/kubebuilder_${VERSION}_${os}_${arch}.tar.gz | tar -xz -C $WORK_DIR

# move to repo_path/bin/kubebuilder - you'll need to set the KUBEBUILDER_ASSETS env var with
rm -rf "$ROOT/bin/kubebuilder"
mv "$WORK_DIR/kubebuilder_${VERSION}_${os}_${arch}/bin" "$ROOT/bin/kubebuilder"
mv "$WORK_DIR/kubebuilder_${VERSION}_${os}_${arch}/bin" "$ROOT/bin/kubebuilder"
Loading

0 comments on commit 58d9cd2

Please sign in to comment.