Skip to content

Commit

Permalink
refactor(operator)!: Migrate project layout to kubebuilder go/v4 (gra…
Browse files Browse the repository at this point in the history
  • Loading branch information
periklis committed Oct 22, 2024
1 parent 1fae527 commit f39c7d1
Show file tree
Hide file tree
Showing 200 changed files with 2,253 additions and 4,403 deletions.
18 changes: 9 additions & 9 deletions operator/.bingo/Variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,23 @@ $(JSONNETFMT): $(BINGO_DIR)/jsonnetfmt.mod
@echo "(re)installing $(GOBIN)/jsonnetfmt-v0.20.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=jsonnetfmt.mod -o=$(GOBIN)/jsonnetfmt-v0.20.0 "github.com/google/go-jsonnet/cmd/jsonnetfmt"

KIND := $(GOBIN)/kind-v0.20.0
KIND := $(GOBIN)/kind-v0.23.0
$(KIND): $(BINGO_DIR)/kind.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/kind-v0.20.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=kind.mod -o=$(GOBIN)/kind-v0.20.0 "sigs.k8s.io/kind"
@echo "(re)installing $(GOBIN)/kind-v0.23.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=kind.mod -o=$(GOBIN)/kind-v0.23.0 "sigs.k8s.io/kind"

KUSTOMIZE := $(GOBIN)/kustomize-v4.5.7
KUSTOMIZE := $(GOBIN)/kustomize-v5.4.3
$(KUSTOMIZE): $(BINGO_DIR)/kustomize.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/kustomize-v4.5.7"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=kustomize.mod -o=$(GOBIN)/kustomize-v4.5.7 "sigs.k8s.io/kustomize/kustomize/v4"
@echo "(re)installing $(GOBIN)/kustomize-v5.4.3"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=kustomize.mod -o=$(GOBIN)/kustomize-v5.4.3 "sigs.k8s.io/kustomize/kustomize/v5"

OPERATOR_SDK := $(GOBIN)/operator-sdk-v1.32.0
OPERATOR_SDK := $(GOBIN)/operator-sdk-v1.37.0
$(OPERATOR_SDK): $(BINGO_DIR)/operator-sdk.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/operator-sdk-v1.32.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=operator-sdk.mod -o=$(GOBIN)/operator-sdk-v1.32.0 "github.com/operator-framework/operator-sdk/cmd/operator-sdk"
@echo "(re)installing $(GOBIN)/operator-sdk-v1.37.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=operator-sdk.mod -o=$(GOBIN)/operator-sdk-v1.37.0 "github.com/operator-framework/operator-sdk/cmd/operator-sdk"

PROMTOOL := $(GOBIN)/promtool-v0.47.1
$(PROMTOOL): $(BINGO_DIR)/promtool.mod
Expand Down
2 changes: 1 addition & 1 deletion operator/.bingo/kind.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.20

require sigs.k8s.io/kind v0.20.0
require sigs.k8s.io/kind v0.23.0
4 changes: 4 additions & 0 deletions operator/.bingo/kind.sum
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ sigs.k8s.io/kind v0.17.0 h1:CScmGz/wX66puA06Gj8OZb76Wmk7JIjgWf5JDvY7msM=
sigs.k8s.io/kind v0.17.0/go.mod h1:Qqp8AiwOlMZmJWs37Hgs31xcbiYXjtXlRBSftcnZXQk=
sigs.k8s.io/kind v0.20.0 h1:f0sc3v9mQbGnjBUaqSFST1dwIuiikKVGgoTwpoP33a8=
sigs.k8s.io/kind v0.20.0/go.mod h1:aBlbxg08cauDgZ612shr017/rZwqd7AS563FvpWKPVs=
sigs.k8s.io/kind v0.22.0 h1:z/+yr/azoOfzsfooqRsPw1wjJlqT/ukXP0ShkHwNlsI=
sigs.k8s.io/kind v0.22.0/go.mod h1:aBlbxg08cauDgZ612shr017/rZwqd7AS563FvpWKPVs=
sigs.k8s.io/kind v0.23.0 h1:8fyDGWbWTeCcCTwA04v4Nfr45KKxbSPH1WO9K+jVrBg=
sigs.k8s.io/kind v0.23.0/go.mod h1:ZQ1iZuJLh3T+O8fzhdi3VWcFTzsdXtNv2ppsHc8JQ7s=
sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
Expand Down
8 changes: 2 additions & 6 deletions operator/.bingo/kustomize.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.17
go 1.22.5

exclude sigs.k8s.io/kustomize/api v0.2.0

exclude sigs.k8s.io/kustomize/cmd/config v0.2.0

require sigs.k8s.io/kustomize/kustomize/v4 v4.5.7
require sigs.k8s.io/kustomize/kustomize/v5 v5.4.3
471 changes: 58 additions & 413 deletions operator/.bingo/kustomize.sum

Large diffs are not rendered by default.

10 changes: 2 additions & 8 deletions operator/.bingo/operator-sdk.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.20
go 1.22.5

replace github.com/containerd/containerd => github.com/containerd/containerd v1.4.11

replace github.com/docker/distribution => github.com/docker/distribution v0.0.0-20191216044856-a8371794149d

replace github.com/mattn/go-sqlite3 => github.com/mattn/go-sqlite3 v1.10.0

require github.com/operator-framework/operator-sdk v1.32.0 // cmd/operator-sdk
require github.com/operator-framework/operator-sdk v1.37.0 // cmd/operator-sdk
2,913 changes: 304 additions & 2,609 deletions operator/.bingo/operator-sdk.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions operator/.bingo/variables.env
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ JSONNET="${GOBIN}/jsonnet-v0.20.0"

JSONNETFMT="${GOBIN}/jsonnetfmt-v0.20.0"

KIND="${GOBIN}/kind-v0.20.0"
KIND="${GOBIN}/kind-v0.23.0"

KUSTOMIZE="${GOBIN}/kustomize-v4.5.7"
KUSTOMIZE="${GOBIN}/kustomize-v5.4.3"

OPERATOR_SDK="${GOBIN}/operator-sdk-v1.32.0"
OPERATOR_SDK="${GOBIN}/operator-sdk-v1.37.0"

PROMTOOL="${GOBIN}/promtool-v0.47.1"

7 changes: 7 additions & 0 deletions operator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
## Main

## Release 5.8.15

- [14568](https://github.com/grafana/loki/pull/14568) **periklis**: refactor(operator)!: Rename loki api go module
- [14447](https://github.com/grafana/loki/pull/14447) **periklis**: refactor(operator)!: Migrate project layout to kubebuilder go/v4
- [14445](https://github.com/grafana/loki/pull/14445) **periklis**: chore(operator): Upgrade operator-sdk 1.37.0 and kind 0.23.0

## Release 5.8.14

- [14416](https://github.com/grafana/loki/pull/14416) **periklis**: chore(operator): Update on Go1.22 (Partial backport)
- [14416](https://github.com/grafana/loki/pull/14416) **periklis**: chore(operator): Update build and runtime deps
- [14331](https://github.com/grafana/loki/pull/14331) **periklis**: feat!(operator): Update Loki operand to v3.2.0
- [14314](https://github.com/grafana/loki/pull/14314) **periklis**: fix(operator): Use empty initiliazed pod status map when no pods
- [14279](https://github.com/grafana/loki/pull/14279) **periklis**: fix(operator): Add missing groupBy label for all rules on OpenShift
Expand Down
7 changes: 3 additions & 4 deletions operator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ FROM golang:1.22.8 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
COPY apis/ apis/
COPY api/ api/
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY main.go main.go
COPY controllers/ controllers/
COPY cmd/loki-operator/main.go cmd/loki-operator/main.go
COPY internal/ internal/

# Build
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -mod=readonly -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -mod=readonly -a -o manager cmd/loki-operator/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
7 changes: 3 additions & 4 deletions operator/Dockerfile.cross
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ FROM --platform=linux/amd64 $BUILD_IMAGE as builder
COPY --from=goenv /goarch /goarm /
WORKDIR /workspace
# Copy the Go Modules manifests
COPY apis/ apis/
COPY api/ api/
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY main.go main.go
COPY controllers/ controllers/
COPY cmd/loki-operator/main.go cmd/loki-operator/main.go
COPY internal/ internal/

# Build
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on GOARCH=$(cat /goarch) GOARM=$(cat /goarm) go build -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on GOARCH=$(cat /goarch) GOARM=$(cat /goarm) go build -a -o manager cmd/loki-operator/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
26 changes: 18 additions & 8 deletions operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,24 @@ deps: go.mod go.sum
go mod download
go mod verify

.PHONY: deps-api
deps-api: api/loki/go.mod api/loki/go.sum
@cd ./api/loki/ && go mod tidy
@cd ./api/loki/ && go mod download
@cd ./api/loki/ && go mod verify

.PHONY: cli
cli: deps bin/loki-broker ## Build loki-broker CLI binary
bin/loki-broker: $(GO_FILES) | generate
go build -o $@ ./cmd/loki-broker/

.PHONY: manager
manager: deps generate ## Build manager binary
go build -o bin/manager main.go
go build -o bin/manager ./cmd/loki-operator/main.go

.PHONY: size-calculator
size-calculator: deps generate ## Build size-calculator binary
go build -o bin/size-calculator main.go
go build -o bin/size-calculator ./cmd/size-calculator/main.go

.PHONY: go-generate
go-generate: ## Run go generate
Expand All @@ -152,10 +158,14 @@ manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
$(CONTROLLER_GEN) rbac:roleName=lokistack-manager crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases

.PHONY: test
test: deps generate go-generate lint lint-prometheus manifests ## Run tests
test: deps deps-api generate go-generate lint lint-prometheus manifests test-unit-api ## Run tests
test: $(GO_FILES)
go test ./... -coverprofile cover.out

.PHONY: test-unit-api
test-unit-api: $(GO_FILES)
@cd ./api/loki/ && go test ./... -coverprofile cover.out

.PHONY: test-unit-prometheus
test-unit-prometheus: $(PROMTOOL) ## Run prometheus unit tests
@$(PROMTOOL) test rules ./internal/manifests/internal/alerts/testdata/test.yaml
Expand Down Expand Up @@ -228,7 +238,7 @@ quickstart-cleanup: $(KIND) ## Cleanup for quickstart set up

.PHONY: run
run: generate manifests ## Run against the configured Kubernetes cluster in ~/.kube/config
go run ./main.go
go run ./cmd/loki-operator/main.go

.PHONY: install
install: manifests $(KUSTOMIZE) ## Install CRDs into a cluster
Expand Down Expand Up @@ -303,17 +313,17 @@ oci-push-calculator: ## Push the calculator image
$(OCI_RUNTIME) push $(CALCULATOR_IMG)

##@ Website
TYPES_TARGET := $(shell find apis/loki -type f -iname "*_types.go")
TYPES_TARGET := $(shell find api/loki -type f -iname "*_types.go")
docs/operator/api.md: $(TYPES_TARGET) $(GEN_CRD_API_REFERENCE_DOCS)
$(GEN_CRD_API_REFERENCE_DOCS) -api-dir "github.com/grafana/loki/operator/apis/loki/" -config "$(PWD)/config/docs/config.json" -template-dir "$(PWD)/config/docs/templates" -out-file "$(PWD)/$@"
$(GEN_CRD_API_REFERENCE_DOCS) -api-dir "github.com/grafana/loki/operator/api/loki/" -config "$(PWD)/config/docs/config.json" -template-dir "$(PWD)/config/docs/templates" -out-file "$(PWD)/$@"
sed -i 's/+docs:/ docs:/' $@
sed -i 's/+parent:/ parent:/' $@
sed -i 's/##/\n##/' $@
sed -i 's/+newline/\n/' $@

FEATURE_GATES_TARGET := $(shell find apis/config -type f -iname "*_types.go")
FEATURE_GATES_TARGET := $(shell find api/config -type f -iname "*_types.go")
docs/operator/feature-gates.md: $(FEATURE_GATES_TARGET) $(GEN_CRD_API_REFERENCE_DOCS)
$(GEN_CRD_API_REFERENCE_DOCS) -api-dir "github.com/grafana/loki/operator/apis/config/v1/" -config "$(PWD)/config/docs/config.json" -template-dir "$(PWD)/config/docs/templates" -out-file "$(PWD)/$@"
$(GEN_CRD_API_REFERENCE_DOCS) -api-dir "github.com/grafana/loki/operator/api/config/v1/" -config "$(PWD)/config/docs/config.json" -template-dir "$(PWD)/config/docs/templates" -out-file "$(PWD)/$@"
sed -i 's/title: "API"/title: "Feature Gates"/' $@
sed -i 's/+docs:/ docs:/' $@
sed -i 's/+parent:/ parent:/' $@
Expand Down
18 changes: 9 additions & 9 deletions operator/PROJECT
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
componentConfig: true
domain: grafana.com
layout:
- go.kubebuilder.io/v3
- go.kubebuilder.io/v4
multigroup: true
plugins:
manifests.sdk.operatorframework.io/v2: {}
Expand All @@ -16,7 +16,7 @@ resources:
domain: grafana.com
group: loki
kind: LokiStack
path: github.com/grafana/loki/operator/apis/loki/v1beta1
path: github.com/grafana/loki/operator/api/loki/v1beta1
version: v1beta1
- api:
crdVersion: v1
Expand All @@ -25,7 +25,7 @@ resources:
domain: grafana.com
group: loki
kind: LokiStack
path: github.com/grafana/loki/operator/apis/loki/v1
path: github.com/grafana/loki/operator/api/loki/v1
version: v1
webhooks:
conversion: true
Expand All @@ -38,7 +38,7 @@ resources:
domain: grafana.com
group: loki
kind: AlertingRule
path: github.com/grafana/loki/operator/apis/loki/v1
path: github.com/grafana/loki/operator/api/loki/v1
version: v1
webhooks:
conversion: true
Expand All @@ -51,7 +51,7 @@ resources:
domain: grafana.com
group: loki
kind: AlertingRule
path: github.com/grafana/loki/operator/apis/loki/v1beta1
path: github.com/grafana/loki/operator/api/loki/v1beta1
version: v1beta1
webhooks:
validation: true
Expand All @@ -63,7 +63,7 @@ resources:
domain: grafana.com
group: loki
kind: RecordingRule
path: github.com/grafana/loki/operator/apis/loki/v1
path: github.com/grafana/loki/operator/api/loki/v1
version: v1
webhooks:
validation: true
Expand All @@ -76,7 +76,7 @@ resources:
domain: grafana.com
group: loki
kind: RecordingRule
path: github.com/grafana/loki/operator/apis/loki/v1beta1
path: github.com/grafana/loki/operator/api/loki/v1beta1
version: v1beta1
webhooks:
validation: true
Expand All @@ -88,7 +88,7 @@ resources:
domain: grafana.com
group: loki
kind: RulerConfig
path: github.com/grafana/loki/operator/apis/loki/v1
path: github.com/grafana/loki/operator/api/loki/v1
version: v1
- api:
crdVersion: v1
Expand All @@ -97,6 +97,6 @@ resources:
domain: grafana.com
group: loki
kind: RulerConfig
path: github.com/grafana/loki/operator/apis/loki/v1beta1
path: github.com/grafana/loki/operator/api/loki/v1beta1
version: v1beta1
version: "3"
File renamed without changes.
2 changes: 1 addition & 1 deletion operator/apis/loki/go.mod → operator/api/loki/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/grafana/loki/operator/apis/loki
module github.com/grafana/loki/operator/api/loki

go 1.19

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v1beta1

import (
v1 "github.com/grafana/loki/operator/apis/loki/v1"
v1 "github.com/grafana/loki/operator/api/loki/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package v1beta1_test
import (
"testing"

v1 "github.com/grafana/loki/operator/apis/loki/v1"
"github.com/grafana/loki/operator/apis/loki/v1beta1"
v1 "github.com/grafana/loki/operator/api/loki/v1"
"github.com/grafana/loki/operator/api/loki/v1beta1"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v1beta1

import (
v1 "github.com/grafana/loki/operator/apis/loki/v1"
v1 "github.com/grafana/loki/operator/api/loki/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/conversion"
Expand Down
Loading

0 comments on commit f39c7d1

Please sign in to comment.