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 21, 2024
1 parent ff6ad87 commit c0993d1
Show file tree
Hide file tree
Showing 110 changed files with 1,805 additions and 1,645 deletions.
6 changes: 3 additions & 3 deletions operator/.bingo/Variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ $(KIND): $(BINGO_DIR)/kind.mod
@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.37.0
$(OPERATOR_SDK): $(BINGO_DIR)/operator-sdk.mod
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.

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

go 1.22.8
go 1.22.5

require github.com/operator-framework/operator-sdk v1.37.0 // cmd/operator-sdk
2 changes: 1 addition & 1 deletion operator/.bingo/variables.env
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ JSONNETFMT="${GOBIN}/jsonnetfmt-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.37.0"

Expand Down
4 changes: 4 additions & 0 deletions operator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Main

## Release 6.0.2

- [14447](https://github.com/grafana/loki/pull/14447) **periklis**: refactor(operator)!: Migrate project layout to kubebuilder go/v4

## Release 6.0.1

- [14445](https://github.com/grafana/loki/pull/14445) **periklis**: chore(operator): Upgrade operator-sdk 1.37.0 and kind 0.23.0
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
22 changes: 11 additions & 11 deletions operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ deps: go.mod go.sum
go mod verify

.PHONY: deps-api
deps-api: apis/loki/go.mod apis/loki/go.sum
@cd ./apis/loki/ && go mod tidy
@cd ./apis/loki/ && go mod download
@cd ./apis/loki/ && go mod verify
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
Expand All @@ -138,11 +138,11 @@ bin/loki-broker: $(GO_FILES) | generate

.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 @@ -163,7 +163,7 @@ test: $(GO_FILES)

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

.PHONY: test-unit-prometheus
test-unit-prometheus: $(PROMTOOL) ## Run prometheus unit tests
Expand Down Expand Up @@ -237,7 +237,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 @@ -312,17 +312,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)/$@"
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.
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion operator/bundle/community-openshift/bundle.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LABEL operators.operatorframework.io.bundle.channels.v1=alpha
LABEL operators.operatorframework.io.bundle.channel.default.v1=alpha
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-unknown
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v4

# Labels for testing.
LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
secret:
key: service-ca.crt
name: loki-operator-controller-manager-metrics-token
serverName: loki-operator-controller-manager-metrics-service.kubernetes-operators.svc
serverName: loki-operator-controller-manager-metrics-service.openshift-operators-redhat.svc
selector:
matchLabels:
app.kubernetes.io/component: metrics
Expand Down
Loading

0 comments on commit c0993d1

Please sign in to comment.