Skip to content

Commit c716694

Browse files
authored
Move controller-utils code. (#1)
* Initial CoLa/controller-utils commit * merge code from cloud-orchastrator/controller-utils * remove checked-in binaries * generated file * fix test * remove uneeded config * mv hack/goimports_version * rename the module * update modules * initial action * bump controller runtime * fix ci
1 parent 31cad14 commit c716694

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+7821
-0
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
name: Bug Report
3+
about: Report a bug
4+
labels: kind/bug
5+
6+
---
7+
8+
**What happened**:
9+
10+
**What you expected to happen**:
11+
12+
**How to reproduce it (as minimally and precisely as possible)**:
13+
14+
**Anything else we need to know**:
15+
16+
**Environment**:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: Enhancement Request
3+
about: Suggest an enhancement
4+
labels: kind/enhancement
5+
6+
---
7+
8+
**What would you like to be added**:
9+
10+
**Why is this needed**:

.github/pull_request_template.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
**What this PR does / why we need it**:
2+
3+
**Which issue(s) this PR fixes**:
4+
Fixes #
5+
6+
**Special notes for your reviewer**:
7+
8+
**Release note**:
9+
<!-- Write your release note:
10+
1. Enter your release note in the below block.
11+
2. If no release note is required, just write "NONE" within the block.
12+
13+
Format of block header: <category> <target_group>
14+
Possible values:
15+
- category: breaking|feature|bugfix|doc|other
16+
- target_group: user|operator|developer|dependency
17+
-->
18+
```feature user
19+
20+
```

.github/workflows/ci.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: ci
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
branches:
7+
- master
8+
- main
9+
pull_request:
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-24.04
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version-file: go.mod
23+
24+
- name: make tidy
25+
run: |
26+
make tidy
27+
git diff --exit-code
28+
29+
- name: make verify
30+
run: make verify
31+
32+
- name: make test
33+
run: make test

.gitignore

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
bin/*
11+
12+
# Test binary, built with `go test -c`
13+
*.test
14+
15+
# Output of the go coverage tool, specifically when used with LiteIDE
16+
cover.html
17+
*.out
18+
19+
# Go workspace file
20+
go.work
21+
go.work.sum
22+
23+
tmp/
24+
.vscode/
25+
.idea

.golangci.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
run:
2+
concurrency: 4
3+
timeout: 10m
4+
5+
issues:
6+
exclude-files:
7+
- "zz_generated.*\\.go$"
8+
- "tmp/.*"

Makefile

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
PROJECT_FULL_NAME := controller-utils
2+
REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
3+
EFFECTIVE_VERSION := $(shell $(REPO_ROOT)/hack/get-version.sh)
4+
5+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
6+
ifeq (,$(shell go env GOBIN))
7+
GOBIN=$(shell go env GOPATH)/bin
8+
else
9+
GOBIN=$(shell go env GOBIN)
10+
endif
11+
12+
# CONTAINER_TOOL defines the container tool to be used for building images.
13+
# Be aware that the target commands are only tested with Docker which is
14+
# scaffolded by default. However, you might want to replace it to use other
15+
# tools. (i.e. podman)
16+
CONTAINER_TOOL ?= docker
17+
18+
# Setting SHELL to bash allows bash commands to be executed by recipes.
19+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
20+
SHELL = /usr/bin/env bash -o pipefail
21+
.SHELLFLAGS = -ec
22+
23+
ROOT_CODE_DIRS := $(REPO_ROOT)/pkg/...
24+
25+
##@ General
26+
27+
# The help target prints out all targets with their descriptions organized
28+
# beneath their categories. The categories are represented by '##@' and the
29+
# target descriptions by '##'. The awk commands is responsible for reading the
30+
# entire set of makefiles included in this invocation, looking for lines of the
31+
# file as xyz: ## something, and then pretty-format the target and help. Then,
32+
# if there's a line with ##@ something, that gets pretty-printed as a category.
33+
# More info on the usage of ANSI control characters for terminal formatting:
34+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
35+
# More info on the awk command:
36+
# http://linuxcommand.org/lc3_adv_awk.php
37+
38+
.PHONY: help
39+
help: ## Display this help.
40+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
41+
42+
##@ Development
43+
44+
.PHONY: tidy
45+
tidy: ## Runs 'go mod tidy' for all modules in this repo.
46+
@$(REPO_ROOT)/hack/tidy.sh
47+
48+
.PHONY: format
49+
format: goimports ## Formats the imports.
50+
@FORMATTER=$(FORMATTER) $(REPO_ROOT)/hack/format.sh $(ROOT_CODE_DIRS)
51+
52+
.PHONY: verify
53+
verify: golangci-lint goimports ## Runs linter, 'go vet', and checks if the formatter has been run.
54+
@( echo "> Verifying root module ..." && \
55+
pushd $(REPO_ROOT) &>/dev/null && \
56+
go vet $(ROOT_CODE_DIRS) && \
57+
$(LINTER) run -c $(REPO_ROOT)/.golangci.yaml $(ROOT_CODE_DIRS) && \
58+
popd &>/dev/null )
59+
@test "$(SKIP_FORMATTING_CHECK)" = "true" || \
60+
( echo "> Checking for unformatted files ..." && \
61+
FORMATTER=$(FORMATTER) $(REPO_ROOT)/hack/format.sh --verify $(ROOT_CODE_DIRS) )
62+
63+
.PHONY: test
64+
test: ## Run tests.
65+
go test $(ROOT_CODE_DIRS) -coverprofile cover.out
66+
go tool cover --html=cover.out -o cover.html
67+
go tool cover -func cover.out | tail -n 1
68+
69+
##@ Release
70+
71+
.PHONY: prepare-release
72+
prepare-release: tidy format verify test
73+
74+
.PHONY: release-major
75+
release-major: prepare-release ## Creates a new major release.
76+
@$(REPO_ROOT)/hack/release.sh major
77+
78+
.PHONY: release-minor
79+
release-minor: prepare-release ## Creates a new minor release.
80+
@$(REPO_ROOT)/hack/release.sh minor
81+
82+
.PHONY: release-patch
83+
release-patch: prepare-release ## Creates a new patch release.
84+
@$(REPO_ROOT)/hack/release.sh patch
85+
86+
##@ Build Dependencies
87+
88+
## Location to install dependencies to
89+
LOCALBIN ?= $(REPO_ROOT)/bin
90+
91+
## Tool Binaries
92+
FORMATTER ?= $(LOCALBIN)/goimports
93+
LINTER ?= $(LOCALBIN)/golangci-lint
94+
95+
## Tool Versions
96+
FORMATTER_VERSION ?= v0.22.0
97+
LINTER_VERSION ?= 1.61.0
98+
99+
.PHONY: localbin
100+
localbin:
101+
@test -d $(LOCALBIN) || mkdir -p $(LOCALBIN)
102+
103+
.PHONY: goimports
104+
goimports: localbin ## Download goimports locally if necessary. If wrong version is installed, it will be overwritten.
105+
@test -s $(FORMATTER) && test -s ./hack/goimports_version && cat ./hack/goimports_version | grep -q $(FORMATTER_VERSION) || \
106+
( echo "Installing goimports $(FORMATTER_VERSION) ..."; \
107+
GOBIN=$(LOCALBIN) go install golang.org/x/tools/cmd/goimports@$(FORMATTER_VERSION) && \
108+
echo $(FORMATTER_VERSION) > ./hack/goimports_version )
109+
110+
.PHONY: golangci-lint
111+
golangci-lint: localbin ## Download golangci-lint locally if necessary. If wrong version is installed, it will be overwritten.
112+
@test -s $(LINTER) && $(LINTER) --version | grep -q $(LINTER_VERSION) || \
113+
( echo "Installing golangci-lint $(LINTER_VERSION) ..."; \
114+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCALBIN) v$(LINTER_VERSION) )
115+
116+
117+
118+
119+
120+
## Location to install dependencies to
121+
LOCALBIN ?= $(shell pwd)/bin
122+
$(LOCALBIN):
123+
mkdir -p $(LOCALBIN)
124+
125+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
126+
CONTROLLER_TOOLS_VERSION ?= v0.15.0
127+
128+
.PHONY: generate
129+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
130+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
131+
132+
.PHONY: controller-gen
133+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
134+
$(CONTROLLER_GEN): $(LOCALBIN)
135+
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
136+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.3.0

go.mod

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
module github.com/openmcp-project/controller-utils
2+
3+
go 1.23.0
4+
5+
require (
6+
github.com/go-logr/logr v1.4.2
7+
github.com/go-logr/zapr v1.3.0
8+
github.com/onsi/ginkgo v1.16.5
9+
github.com/onsi/ginkgo/v2 v2.22.0
10+
github.com/onsi/gomega v1.36.1
11+
github.com/openmcp-project/controller-utils/api v0.0.0-00010101000000-000000000000
12+
github.com/spf13/pflag v1.0.6
13+
github.com/stretchr/testify v1.10.0
14+
go.uber.org/zap v1.27.0
15+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
16+
gopkg.in/yaml.v3 v3.0.1
17+
k8s.io/api v0.32.2
18+
k8s.io/apiextensions-apiserver v0.32.2
19+
k8s.io/apimachinery v0.32.2
20+
k8s.io/client-go v0.32.2
21+
k8s.io/utils v0.0.0-20241210054802-24370beab758
22+
sigs.k8s.io/controller-runtime v0.20.2
23+
sigs.k8s.io/yaml v1.4.0
24+
)
25+
26+
require (
27+
github.com/beorn7/perks v1.0.1 // indirect
28+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
29+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
30+
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
31+
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
32+
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
33+
github.com/fsnotify/fsnotify v1.8.0 // indirect
34+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
35+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
36+
github.com/go-openapi/jsonreference v0.21.0 // indirect
37+
github.com/go-openapi/swag v0.23.0 // indirect
38+
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
39+
github.com/gogo/protobuf v1.3.2 // indirect
40+
github.com/golang/protobuf v1.5.4 // indirect
41+
github.com/google/btree v1.1.3 // indirect
42+
github.com/google/gnostic-models v0.6.9 // indirect
43+
github.com/google/go-cmp v0.6.0 // indirect
44+
github.com/google/gofuzz v1.2.0 // indirect
45+
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
46+
github.com/google/uuid v1.6.0 // indirect
47+
github.com/josharian/intern v1.0.0 // indirect
48+
github.com/json-iterator/go v1.1.12 // indirect
49+
github.com/klauspost/compress v1.17.11 // indirect
50+
github.com/mailru/easyjson v0.9.0 // indirect
51+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
52+
github.com/modern-go/reflect2 v1.0.2 // indirect
53+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
54+
github.com/nxadm/tail v1.4.8 // indirect
55+
github.com/pkg/errors v0.9.1 // indirect
56+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
57+
github.com/prometheus/client_golang v1.20.5 // indirect
58+
github.com/prometheus/client_model v0.6.1 // indirect
59+
github.com/prometheus/common v0.62.0 // indirect
60+
github.com/prometheus/procfs v0.15.1 // indirect
61+
github.com/x448/float16 v0.8.4 // indirect
62+
go.uber.org/multierr v1.11.0 // indirect
63+
golang.org/x/net v0.35.0 // indirect
64+
golang.org/x/oauth2 v0.26.0 // indirect
65+
golang.org/x/sync v0.11.0 // indirect
66+
golang.org/x/sys v0.30.0 // indirect
67+
golang.org/x/term v0.29.0 // indirect
68+
golang.org/x/text v0.22.0 // indirect
69+
golang.org/x/time v0.10.0 // indirect
70+
golang.org/x/tools v0.26.0 // indirect
71+
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
72+
google.golang.org/protobuf v1.36.5 // indirect
73+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
74+
gopkg.in/inf.v0 v0.9.1 // indirect
75+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
76+
k8s.io/klog/v2 v2.130.1 // indirect
77+
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 // indirect
78+
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
79+
sigs.k8s.io/structured-merge-diff/v4 v4.5.0 // indirect
80+
)
81+
82+
replace github.com/openmcp-project/controller-utils/api => ./pkg/api

0 commit comments

Comments
 (0)