Skip to content

Commit

Permalink
chore(refactor): migrate project from Kubebuilder v3 to v4 layout
Browse files Browse the repository at this point in the history
  • Loading branch information
programmer04 committed Apr 16, 2024
1 parent da74f41 commit 4c01263
Show file tree
Hide file tree
Showing 148 changed files with 234 additions and 231 deletions.
38 changes: 19 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ RUN --mount=type=cache,target=$GOPATH/pkg/mod \
--mount=type=bind,source=go.mod,target=go.mod \
go mod download -x

COPY main.go main.go
COPY cmd/main.go cmd/main.go
COPY modules/ modules/
COPY apis/ apis/
COPY controllers/ controllers/
COPY api/ api/
COPY controller/ controller/
COPY pkg/ pkg/
COPY internal/ internal/
COPY Makefile Makefile
Expand Down Expand Up @@ -62,13 +62,13 @@ ARG NAME="Kong Gateway Operator"
ARG DESCRIPTION="Kong Gateway Operator drives deployment via the Gateway resource. You can deploy a Gateway resource to the cluster which will result in the underlying control-plane (the Kong Kubernetes Ingress Controller) and the data-plane (the Kong Gateway)."

LABEL name="${NAME}" \
description="${DESCRIPTION}" \
org.opencontainers.image.description="${DESCRIPTION}" \
vendor="Kong" \
version="${TAG}" \
release="1" \
url="https://github.com/Kong/gateway-operator" \
summary="A Kubernetes Operator for the Kong Gateway."
description="${DESCRIPTION}" \
org.opencontainers.image.description="${DESCRIPTION}" \
vendor="Kong" \
version="${TAG}" \
release="1" \
url="https://github.com/Kong/gateway-operator" \
summary="A Kubernetes Operator for the Kong Gateway."

WORKDIR /
COPY --from=builder /workspace/bin/manager .
Expand All @@ -87,15 +87,15 @@ ARG NAME="Kong Gateway Operator"
ARG DESCRIPTION="Kong Gateway Operator drives deployment via the Gateway resource. You can deploy a Gateway resource to the cluster which will result in the underlying control-plane (the Kong Kubernetes Ingress Controller) and the data-plane (the Kong Gateway)."

LABEL name="${NAME}" \
io.k8s.display-name="${NAME}" \
description="${DESCRIPTION}" \
io.k8s.description="${DESCRIPTION}" \
org.opencontainers.image.description="${DESCRIPTION}" \
vendor="Kong" \
version="${TAG}" \
release="1" \
url="https://github.com/Kong/gateway-operator" \
summary="A Kubernetes Operator for the Kong Gateway."
io.k8s.display-name="${NAME}" \
description="${DESCRIPTION}" \
io.k8s.description="${DESCRIPTION}" \
org.opencontainers.image.description="${DESCRIPTION}" \
vendor="Kong" \
version="${TAG}" \
release="1" \
url="https://github.com/Kong/gateway-operator" \
summary="A Kubernetes Operator for the Kong Gateway."

# Create the user (ID 1000) and group that will be used in the
# running container to run the process as an unprivileged user.
Expand Down
8 changes: 4 additions & 4 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ by OpenAI (e.g. ChatGPT).
[caps]:https://sdk.operatorframework.io/docs/overview/operator-capabilities/
[mst]:https://github.com/kong/gateway-operator/milestone
[iss]:https://github.com/kong/gateway-operator/issues
[sp]:https://pkg.go.dev/github.com/kong/gateway-operator@main/apis/v1beta1#GatewayConfigurationSpec
[sp]:https://pkg.go.dev/github.com/kong/gateway-operator@main/api/v1beta1#GatewayConfigurationSpec
[gwapi]:https://gateway-api.sigs.k8s.io
[gw]:https://github.com/kong/kong
[gwcfg]:https://pkg.go.dev/github.com/kong/gateway-operator@main/apis/v1beta1#GatewayConfiguration
[gwcfg]:https://pkg.go.dev/github.com/kong/gateway-operator@main/api/v1beta1#GatewayConfiguration
[tops]:https://docs.konghq.com/gateway/latest/production/deployment-topologies/
[dapi]:https://pkg.go.dev/github.com/kong/gateway-operator@main/apis/v1beta1#DataPlane
[dapi]:https://pkg.go.dev/github.com/kong/gateway-operator@main/api/v1beta1#DataPlane
[kic]:https://github.com/kong/kubernetes-ingress-controller
[capi]:https://pkg.go.dev/github.com/kong/gateway-operator@main/apis/v1alpha1#ControlPlane
[capi]:https://pkg.go.dev/github.com/kong/gateway-operator@main/api/v1alpha1#ControlPlane
[dbl]:https://docs.konghq.com/gateway/latest/production/deployment-topologies/db-less-and-declarative-config/
[trd]:https://docs.konghq.com/gateway/latest/production/deployment-topologies/traditional/
[hybrd]:https://docs.konghq.com/gateway/latest/production/deployment-topologies/hybrid-mode/setup/#install-and-start-data-planes
Expand Down
31 changes: 19 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ _build.operator:
-X $(REPO)/modules/manager/metadata.Release=$(TAG) \
-X $(REPO)/modules/manager/metadata.Commit=$(COMMIT) \
-X $(REPO)/modules/manager/metadata.Repo=$(REPO_INFO)" \
main.go
cmd/main.go

.PHONY: build
build: generate
Expand Down Expand Up @@ -176,28 +176,35 @@ verify.generators: verify.repo generate verify.diff
# Build - Generators
# ------------------------------------------------------------------------------

APIS_DIR ?= apis
API_DIR ?= api

.PHONY: generate
generate: controller-gen generate.apis generate.clientsets generate.rbacs generate.gateway-api-urls generate.docs generate.k8sio-gomod-replace generate.testcases-registration generate.kic-webhook-config
generate: generate.api generate.clientsets generate.rbacs generate.gateway-api-urls generate.docs generate.k8sio-gomod-replace generate.testcases-registration generate.kic-webhook-config

.PHONY: generate.apis
generate.apis:
$(CONTROLLER_GEN) object:headerFile="hack/generators/boilerplate.go.txt" paths="./$(APIS_DIR)/..."
.PHONY: generate.api
generate.api: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/generators/boilerplate.go.txt" paths="./$(API_DIR)/..."

# this will generate the custom typed clients needed for end-users implementing logic in Go to use our API types.
.PHONY: generate.clientsets
generate.clientsets: client-gen
# We create a symlink to the apis/ directory as a hack because currently
# client-gen does not properly support the use of api/ as your API
# directory.
#
# See: https://github.com/kubernetes/code-generator/issues/167
ln -s api apis
$(CLIENT_GEN) \
--go-header-file ./hack/generators/boilerplate.go.txt \
--clientset-name clientset \
--input-base '' \
--input $(REPO)/$(APIS_DIR)/v1alpha1 \
--input $(REPO)/$(APIS_DIR)/v1beta1 \
--input $(REPO)/apis/v1alpha1 \
--input $(REPO)/apis/v1beta1 \
--output-base pkg/ \
--output-package $(REPO)/pkg/ \
--trim-path-prefix pkg/$(REPO)/

rm apis
find ./pkg/clientset/ -type f -name '*.go' -exec sed -i '' -e 's/github.com\/kong\/gateway-operator\/apis/github.com\/kong\/gateway-operator\/api/gI' {} \;
.PHONY: generate.rbacs
generate.rbacs: kic-role-generator
$(KIC_ROLE_GENERATOR) --force
Expand Down Expand Up @@ -231,7 +238,7 @@ check.rbacs: kic-role-generator
# ------------------------------------------------------------------------------

CONTROLLER_GEN_CRD_OPTIONS ?= "+crd:generateEmbeddedObjectMeta=true"
CONTROLLER_GEN_PATHS_RAW := ./pkg/utils/kubernetes/resources/clusterroles/ ./pkg/utils/kubernetes/reduce/ ./controllers/... ./$(APIS_DIR)/...
CONTROLLER_GEN_PATHS_RAW := ./pkg/utils/kubernetes/resources/clusterroles/ ./pkg/utils/kubernetes/reduce/ ./controller/... ./$(API_DIR)/...
CONTROLLER_GEN_PATHS := $(patsubst %,%;,$(strip $(CONTROLLER_GEN_PATHS_RAW)))

.PHONY: manifests
Expand Down Expand Up @@ -280,7 +287,7 @@ CONFORMANCE_TEST_TIMEOUT ?= "20m"
.PHONY: test
test: test.unit

UNIT_TEST_PATHS := ./controllers/... ./internal/... ./pkg/... ./modules/...
UNIT_TEST_PATHS := ./controller/... ./internal/... ./pkg/... ./modules/...

.PHONY: _test.unit
_test.unit: gotestsum
Expand Down Expand Up @@ -431,7 +438,7 @@ run: webhook-certs-dir manifests generate install-gateway-api-crds install _ensu
# etc didn't change in between the runs.
.PHONY: _run
_run:
GATEWAY_OPERATOR_DEVELOPMENT_MODE=true go run ./main.go \
GATEWAY_OPERATOR_DEVELOPMENT_MODE=true go run ./cmd/main.go \
--no-leader-election \
-cluster-ca-secret-namespace kong-system \
-enable-controller-controlplane \
Expand Down
13 changes: 7 additions & 6 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: gateway-operator.konghq.com
layout:
- go.kubebuilder.io/v3
- go.kubebuilder.io/v4
multigroup: true
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
Expand All @@ -17,37 +18,37 @@ resources:
controller: true
group: gateway-operator.konghq.com
kind: ControlPlane
path: github.com/kong/gateway-operator/apis/v1beta1
path: github.com/kong/gateway-operator/api/v1beta1
version: v1beta1
- api:
crdVersion: v1
namespaced: true
controller: true
group: gateway-operator.konghq.com
kind: DataPlane
path: github.com/kong/gateway-operator/apis/v1beta1
path: github.com/kong/gateway-operator/api/v1beta1
version: v1beta1
- api:
crdVersion: v1
namespaced: true
group: gateway-operator.konghq.com
kind: GatewayConfiguration
path: github.com/kong/gateway-operator/apis/v1beta1
path: github.com/kong/gateway-operator/api/v1beta1
version: v1beta1
- api:
crdVersion: v1
namespaced: true
controller: true
group: gateway-operator.konghq.com
kind: AIGateway
path: github.com/kong/gateway-operator/apis/v1alpha1
path: github.com/kong/gateway-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
group: gateway-operator.konghq.com
kind: DataPlaneMetricsExtension
path: github.com/kong/gateway-operator/apis/v1alpha1
path: github.com/kong/gateway-operator/api/v1alpha1
version: v1alpha1
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.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

"github.com/kong/gateway-operator/apis/v1alpha1"
"github.com/kong/gateway-operator/api/v1alpha1"
)

// Install is a callback from client-gen to add the scheme to the client
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"

"github.com/kong/gateway-operator/apis/v1alpha1"
"github.com/kong/gateway-operator/api/v1alpha1"
)

func init() {
Expand Down
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
Expand Up @@ -4,7 +4,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

"github.com/kong/gateway-operator/apis/v1beta1"
"github.com/kong/gateway-operator/api/v1beta1"
)

// Install is a callback from client-gen to add the scheme to the client
Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
7 changes: 1 addition & 6 deletions config/samples/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# Usage:
# -----
# go run internal/cmd/main.go
# kubectl apply -f examples/httpbin.yaml
# kubectl get secrets kong-config -o=go-template='{{index .data "networking.k8s.io-v1-Ingress-default-httpbin-ingress" }}' | base64 -d
---
apiVersion: apps/v1
kind: Deployment
Expand All @@ -22,7 +17,7 @@ spec:
spec:
containers:
- name: httpbin
image: kennethreitz/httpbin
image: kong/httpbin
ports:
- containerPort: 80
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"

operatorv1beta1 "github.com/kong/gateway-operator/apis/v1beta1"
"github.com/kong/gateway-operator/controllers/pkg/controlplane"
"github.com/kong/gateway-operator/controllers/pkg/log"
"github.com/kong/gateway-operator/controllers/pkg/op"
operatorv1beta1 "github.com/kong/gateway-operator/api/v1beta1"
"github.com/kong/gateway-operator/controller/pkg/controlplane"
"github.com/kong/gateway-operator/controller/pkg/log"
"github.com/kong/gateway-operator/controller/pkg/op"
operatorerrors "github.com/kong/gateway-operator/internal/errors"
"github.com/kong/gateway-operator/internal/versions"
"github.com/kong/gateway-operator/pkg/consts"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
k8stypes "k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

operatorv1beta1 "github.com/kong/gateway-operator/apis/v1beta1"
"github.com/kong/gateway-operator/controllers/pkg/controlplane"
"github.com/kong/gateway-operator/controllers/pkg/log"
"github.com/kong/gateway-operator/controllers/pkg/op"
"github.com/kong/gateway-operator/controllers/pkg/patch"
"github.com/kong/gateway-operator/controllers/pkg/secrets"
operatorv1beta1 "github.com/kong/gateway-operator/api/v1beta1"
"github.com/kong/gateway-operator/controller/pkg/controlplane"
"github.com/kong/gateway-operator/controller/pkg/log"
"github.com/kong/gateway-operator/controller/pkg/op"
"github.com/kong/gateway-operator/controller/pkg/patch"
"github.com/kong/gateway-operator/controller/pkg/secrets"
"github.com/kong/gateway-operator/internal/versions"
"github.com/kong/gateway-operator/pkg/consts"
k8sutils "github.com/kong/gateway-operator/pkg/utils/kubernetes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"

operatorv1beta1 "github.com/kong/gateway-operator/apis/v1beta1"
operatorv1beta1 "github.com/kong/gateway-operator/api/v1beta1"
"github.com/kong/gateway-operator/pkg/consts"
k8sutils "github.com/kong/gateway-operator/pkg/utils/kubernetes"
"github.com/kong/gateway-operator/test/helpers"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"

operatorv1alpha1 "github.com/kong/gateway-operator/apis/v1alpha1"
operatorv1beta1 "github.com/kong/gateway-operator/apis/v1beta1"
"github.com/kong/gateway-operator/controllers/pkg/controlplane"
operatorv1alpha1 "github.com/kong/gateway-operator/api/v1alpha1"
operatorv1beta1 "github.com/kong/gateway-operator/api/v1beta1"
"github.com/kong/gateway-operator/controller/pkg/controlplane"
"github.com/kong/gateway-operator/pkg/consts"
k8sutils "github.com/kong/gateway-operator/pkg/utils/kubernetes"
"github.com/kong/gateway-operator/pkg/vars"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

operatorv1beta1 "github.com/kong/gateway-operator/apis/v1beta1"
operatorv1beta1 "github.com/kong/gateway-operator/api/v1beta1"
operatorerrors "github.com/kong/gateway-operator/internal/errors"
"github.com/kong/gateway-operator/internal/utils/index"
k8sutils "github.com/kong/gateway-operator/pkg/utils/kubernetes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
controllerruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
fakectrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"

operatorv1beta1 "github.com/kong/gateway-operator/apis/v1beta1"
operatorv1beta1 "github.com/kong/gateway-operator/api/v1beta1"
"github.com/kong/gateway-operator/pkg/consts"
k8sutils "github.com/kong/gateway-operator/pkg/utils/kubernetes"
k8sresources "github.com/kong/gateway-operator/pkg/utils/kubernetes/resources"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package controlplane
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

operatorv1beta1 "github.com/kong/gateway-operator/apis/v1beta1"
operatorv1beta1 "github.com/kong/gateway-operator/api/v1beta1"
k8sutils "github.com/kong/gateway-operator/pkg/utils/kubernetes"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

operatorv1beta1 "github.com/kong/gateway-operator/apis/v1beta1"
operatorv1beta1 "github.com/kong/gateway-operator/api/v1beta1"
k8sutils "github.com/kong/gateway-operator/pkg/utils/kubernetes"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

operatorv1beta1 "github.com/kong/gateway-operator/apis/v1beta1"
"github.com/kong/gateway-operator/controllers/pkg/address"
"github.com/kong/gateway-operator/controllers/pkg/ctxinjector"
"github.com/kong/gateway-operator/controllers/pkg/dataplane"
"github.com/kong/gateway-operator/controllers/pkg/log"
"github.com/kong/gateway-operator/controllers/pkg/op"
operatorv1beta1 "github.com/kong/gateway-operator/api/v1beta1"
"github.com/kong/gateway-operator/controller/pkg/address"
"github.com/kong/gateway-operator/controller/pkg/ctxinjector"
"github.com/kong/gateway-operator/controller/pkg/dataplane"
"github.com/kong/gateway-operator/controller/pkg/log"
"github.com/kong/gateway-operator/controller/pkg/op"
"github.com/kong/gateway-operator/pkg/consts"
k8sutils "github.com/kong/gateway-operator/pkg/utils/kubernetes"
k8sresources "github.com/kong/gateway-operator/pkg/utils/kubernetes/resources"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
fakectrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

operatorv1beta1 "github.com/kong/gateway-operator/apis/v1beta1"
"github.com/kong/gateway-operator/controllers/pkg/builder"
"github.com/kong/gateway-operator/controllers/pkg/dataplane"
"github.com/kong/gateway-operator/controllers/pkg/op"
operatorv1beta1 "github.com/kong/gateway-operator/api/v1beta1"
"github.com/kong/gateway-operator/controller/pkg/builder"
"github.com/kong/gateway-operator/controller/pkg/dataplane"
"github.com/kong/gateway-operator/controller/pkg/op"
dpv "github.com/kong/gateway-operator/internal/validation/dataplane"
"github.com/kong/gateway-operator/pkg/consts"
k8sutils "github.com/kong/gateway-operator/pkg/utils/kubernetes"
Expand Down
Loading

0 comments on commit 4c01263

Please sign in to comment.