Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller update fixes #1

Merged
merged 13 commits into from
Apr 25, 2024
55 changes: 55 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: golangci-lint
on:
push:
branches:
- master
- main
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.54

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"
46 changes: 8 additions & 38 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,18 @@ on:

jobs:
tests:

runs-on: ubuntu-latest

steps:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.14.6'
- name: Checkout code
uses: actions/checkout@v2
with:
path: ./src/github.com/${{ github.repository }}
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
path: |
./src/github.com/${{ github.repository }}/vendor
~/go/bin
${{ github.workspace }}/kubebuilder_2.3.1_linux_amd64
key: ${{ runner.os }}-build-depcache-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-build-depcache-
- name: Setup test tooling
run: |
GO111MODULE=on go get github.com/onsi/ginkgo/ginkgo@v1.14.2
if ! [[ -x $(go env GOPATH)/bin/golangci-lint ]]; then echo "golangci-lint not found; fetching"; curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0; fi
if ! [[ -d ${{ github.workspace }}/kubebuilder_2.3.1_linux_amd64 ]]; then echo "kubebuilder not found; fetching"; curl -sSfL https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.1/kubebuilder_2.3.1_linux_amd64.tar.gz | tar zxvf -; fi
if ! [[ -x $(go env GOPATH)/bin/kustomize ]]; then echo "kustomize not found; fetching"; GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/v3; fi
- name: Download dependencies
run: |
export GOPATH=$(go env GOPATH):$(pwd)
echo "Running go mod tidy"
cd ./src/github.com/${{ github.repository }}
go mod tidy
- name: Configure
run: |
export GOPATH=$(go env GOPATH)
export PATH=$GOPATH/bin:$PATH
./configure --with-kubebuilder=${{ github.workspace }}/kubebuilder_2.3.1_linux_amd64/bin --with-kubectl=${{ github.workspace }}/kubebuilder_2.3.1_linux_amd64/bin/kubectl
working-directory: ./src/github.com/${{ github.repository }}
go-version: '1.22.1'
cache-dependency-path: |
go.sum
go.sum
- name: Run Tests
run: |
export GOPATH=$(go env GOPATH):$(pwd)
cd ./src/github.com/${{ github.repository }}
make check
make test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ cover.out

# Specific directories
/wave
bin/

# OS generated files
**/.DS_Store
Expand All @@ -38,3 +39,4 @@ kubebuilder
.idea
.vscode
default.etcd/

2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run:
tests: false
60 changes: 26 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
include Makefile.tools
include .env

GO ?= go
GOBIN ?= $(shell $(GO) env GOPATH)/bin
BINARY := wave
VERSION := $(shell git describe --always --dirty --tags 2>/dev/null || echo "undefined")
ECHO := echo
CONTROLLER_GEN ?= controller-gen
GINKGO ?= ginkgo
CONTROLLER_TOOLS_VERSION ?= v0.14.0
ENVTEST_K8S_VERSION = 1.29.0

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest

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

# Image URL to use all building/pushing image targets
IMG ?= quay.io/wave-k8s/wave

# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"

.NOTPARALLEL:

.PHONY: all
Expand Down Expand Up @@ -77,9 +79,9 @@ lint: tidy
@ $(ECHO)

# Run tests
export TEST_ASSET_KUBECTL := $(TEST_ASSET_DIR)/kubectl
export TEST_ASSET_KUBE_APISERVER := $(TEST_ASSET_DIR)/kube-apiserver
export TEST_ASSET_ETCD := $(TEST_ASSET_DIR)/etcd
#export TEST_ASSET_KUBECTL := $(TEST_ASSET_DIR)/kubectl
#export TEST_ASSET_KUBE_APISERVER := $(TEST_ASSET_DIR)/kube-apiserver
#export TEST_ASSET_ETCD := $(TEST_ASSET_DIR)/etcd

tidy:
@ $(ECHO) "\033[36mPuling dependencies\033[0m"
Expand All @@ -90,10 +92,8 @@ tidy:
check: fmt lint vet test

.PHONY: test
test: tidy generate manifests ginkgo
@ $(ECHO) "\033[36mRunning test suite in Ginkgo\033[0m"
$(GINKGO) -v -randomizeAllSpecs ./pkg/... ./cmd/... -- -report-dir=$$ARTIFACTS
@ $(ECHO)
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -v ./... -coverprofile cover.out

# Build manager binary
$(BINARY): generate fmt vet
Expand Down Expand Up @@ -138,7 +138,7 @@ deploy: manifests
.PHONY: manifests
manifests: tidy controller-gen
@ $(ECHO) "\033[36mGenerating manifests\033[0m"
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
@ $(ECHO)

# Build the docker image
Expand All @@ -158,24 +158,16 @@ PUSH_TAGS ?= ${VERSION},latest
docker-push:
@IFS=","; tags=${PUSH_TAGS}; for tag in $${tags}; do docker push ${IMG}:$${tag}; $(ECHO) "\033[36mPushed $(IMG):$${tag}\033[0m"; done

# find, or download controller-gen if missing
controller-gen:
ifeq (, $(shell which controller-gen))
@$(ECHO) "controller-gen not found, downloading..."
$(GO) install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.4
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif

ginkgo:
ifeq (, $(shell which ginkgo))
@$(ECHO) "ginkgo not found, downloading..."
$(GO) install github.com/onsi/ginkgo/ginkgo@v1.16.4
GINKGO=$(GOBIN)/ginkgo
else
GINKGO=$(shell which ginkgo)
endif
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: deepcopy-gen
deepcopy-gen:
Expand Down
47 changes: 0 additions & 47 deletions Makefile.tools

This file was deleted.

9 changes: 7 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
"fmt"
"os"
"runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"time"

"sigs.k8s.io/controller-runtime/pkg/cache"

"github.com/go-logr/glogr"
flag "github.com/spf13/pflag"
"github.com/wave-k8s/wave/pkg/apis"
Expand All @@ -46,7 +47,11 @@ var (

func main() {
// Setup flags
goflag.Lookup("logtostderr").Value.Set("true")
err := goflag.Lookup("logtostderr").Value.Set("true")
if err != nil {
fmt.Printf("unable to set logtostderr %v", err)
os.Exit(1)
}
flag.CommandLine.AddGoFlagSet(goflag.CommandLine)
flag.Parse()

Expand Down
Loading