Skip to content

Commit

Permalink
*: Flatten repository structure (#10583)
Browse files Browse the repository at this point in the history
Signed-off-by: timflannagan <[email protected]>
  • Loading branch information
timflannagan authored Feb 6, 2025
1 parent 322714e commit eca3b94
Show file tree
Hide file tree
Showing 488 changed files with 1,436 additions and 1,437 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/pr-unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ env:
GITHUB_TOKEN: ${{ github.token }}

jobs:
# Runs the unit tests for `projects/gateway2`
# Runs the unit tests for `internal/gateway2`
kube_gateway_project:
# TODO(tim): rename this job or consolidate with the other workflows.
name: projects/gateway2
runs-on: ubuntu-22.04
timeout-minutes: 10
Expand All @@ -23,14 +24,14 @@ jobs:
with:
go-version-file: go.mod
- name: Build
run: go build -v ./projects/gateway2/...
run: go build -v ./internal/gateway2/...
- name: Install Test Utils
shell: bash
run: make -C ./projects/gateway2/ install-go-tools
run: make -C ./internal/gateway2/ install-go-tools
- name: Run Tests
shell: bash
env:
TEST_PKG: "./projects/gateway2/..."
TEST_PKG: "./internal/gateway2/..."
run: make go-test-with-coverage
- name: Validate Test Coverage
shell: bash
Expand Down
20 changes: 10 additions & 10 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ before:
- go mod download
builds:
- id: controller
main: ./projects/gateway2/cmd/
main: ./cmd/gateway2
binary: kgateway-linux-{{ .Arch }}
gcflags: "{{ .Env.GCFLAGS }}"
ldflags: "{{ .Env.LDFLAGS }}"
Expand All @@ -21,7 +21,7 @@ builds:
- amd64
- arm64
- id: sds
main: ./projects/sds/cmd/
main: ./cmd/sds
binary: sds-linux-{{ .Arch }}
gcflags: "{{ .Env.GCFLAGS }}"
ldflags: "{{ .Env.LDFLAGS }}"
Expand All @@ -36,7 +36,7 @@ builds:
- amd64
- arm64
- id: envoyinit
main: ./projects/envoyinit/cmd/
main: ./cmd/envoyinit
binary: envoyinit-linux-{{ .Arch }}
gcflags: "{{ .Env.GCFLAGS }}"
ldflags: "{{ .Env.LDFLAGS }}"
Expand All @@ -54,7 +54,7 @@ dockers:
- image_templates:
- &controller_arm_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.CONTROLLER_IMAGE_REPO }}:{{ .Env.VERSION }}-arm64"
use: buildx
dockerfile: &controller_dockerfile projects/gateway2/cmd/Dockerfile
dockerfile: &controller_dockerfile cmd/gateway2/Dockerfile
goos: linux
goarch: arm64
build_flag_templates:
Expand All @@ -76,7 +76,7 @@ dockers:
- image_templates:
- &sds_arm_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.SDS_IMAGE_REPO }}:{{ .Env.VERSION }}-arm64"
use: buildx
dockerfile: &sds_dockerfile projects/sds/cmd/Dockerfile
dockerfile: &sds_dockerfile cmd/sds/Dockerfile
goos: linux
goarch: arm64
build_flag_templates:
Expand All @@ -98,17 +98,17 @@ dockers:
- image_templates:
- &envoyinit_arm_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.ENVOYINIT_IMAGE_REPO }}:{{ .Env.VERSION }}-arm64"
use: buildx
dockerfile: &envoyinit_dockerfile projects/envoyinit/cmd/Dockerfile.envoyinit
dockerfile: &envoyinit_dockerfile cmd/envoyinit/Dockerfile.envoyinit
goos: linux
goarch: arm64
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
- "--build-arg=GOARCH=arm64"
- "--build-arg=ENTRYPOINT_SCRIPT=/projects/envoyinit/cmd/docker-entrypoint.sh"
- "--build-arg=ENTRYPOINT_SCRIPT=/cmd/envoyinit/docker-entrypoint.sh"
- "--build-arg=ENVOY_IMAGE={{ .Env.ENVOY_IMAGE }}"
extra_files:
- projects/envoyinit/cmd/docker-entrypoint.sh
- cmd/envoyinit/docker-entrypoint.sh
- image_templates:
- &envoyinit_amd_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.ENVOYINIT_IMAGE_REPO }}:{{ .Env.VERSION }}-amd64"
use: buildx
Expand All @@ -119,10 +119,10 @@ dockers:
- "--pull"
- "--platform=linux/amd64"
- "--build-arg=GOARCH=amd64"
- "--build-arg=ENTRYPOINT_SCRIPT=/projects/envoyinit/cmd/docker-entrypoint.sh"
- "--build-arg=ENTRYPOINT_SCRIPT=/cmd/envoyinit/docker-entrypoint.sh"
- "--build-arg=ENVOY_IMAGE={{ .Env.ENVOY_IMAGE }}"
extra_files:
- projects/envoyinit/cmd/docker-entrypoint.sh
- cmd/envoyinit/docker-entrypoint.sh
docker_manifests:
- name_template: "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.CONTROLLER_IMAGE_REPO }}:{{ .Env.VERSION }}"
image_templates:
Expand Down
34 changes: 17 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ mod-download: check-go-version

.PHONY: check-format
check-format:
NOT_FORMATTED=$$(gofmt -l ./projects/ ./pkg/ ./test/) && if [ -n "$$NOT_FORMATTED" ]; then echo These files are not formatted: $$NOT_FORMATTED; exit 1; fi
NOT_FORMATTED=$$(gofmt -l ./pkg/ ./internal/ ./test/) && if [ -n "$$NOT_FORMATTED" ]; then echo These files are not formatted: $$NOT_FORMATTED; exit 1; fi

.PHONY: check-spelling
check-spelling:
Expand Down Expand Up @@ -301,7 +301,7 @@ generated-code: fmt

.PHONY: go-generate-all
go-generate-all: ## Run all go generate directives in the repo, including codegen for protos, mockgen, and more
GO111MODULE=on go generate ./projects/gateway2/...
GO111MODULE=on go generate ./hack/...

.PHONY: go-generate-mocks
go-generate-mocks: ## Runs all generate directives for mockgen in the repo
Expand All @@ -311,7 +311,7 @@ go-generate-mocks: ## Runs all generate directives for mockgen in the repo
# TODO: do we still want this?
.PHONY: getter-check
getter-check:
go run github.com/saiskee/gettercheck -ignoretests -ignoregenerated -write ./projects/gateway2/...
go run github.com/saiskee/gettercheck -ignoretests -ignoregenerated -write ./internal/gateway2/...

.PHONY: mod-tidy
mod-tidy:
Expand All @@ -336,7 +336,7 @@ generate-crd-reference-docs:
# Distroless base images
#----------------------------------------------------------------------------------

DISTROLESS_DIR=projects/distroless
DISTROLESS_DIR=internal/distroless
DISTROLESS_OUTPUT_DIR=$(OUTPUT_DIR)/$(DISTROLESS_DIR)

$(DISTROLESS_OUTPUT_DIR)/Dockerfile: $(DISTROLESS_DIR)/Dockerfile
Expand Down Expand Up @@ -365,20 +365,20 @@ distroless-with-utils-docker: distroless-docker $(DISTROLESS_OUTPUT_DIR)/Dockerf
# Controller
#----------------------------------------------------------------------------------

K8S_GATEWAY_DIR=projects/gateway2
K8S_GATEWAY_DIR=internal/gateway2
K8S_GATEWAY_SOURCES=$(call get_sources,$(K8S_GATEWAY_DIR))
CONTROLLER_OUTPUT_DIR=$(OUTPUT_DIR)/$(K8S_GATEWAY_DIR)
export CONTROLLER_IMAGE_REPO ?= kgateway

# We include the files in EDGE_GATEWAY_DIR and K8S_GATEWAY_DIR as dependencies to the gloo build
# so changes in those directories cause the make target to rebuild
$(CONTROLLER_OUTPUT_DIR)/kgateway-linux-$(GOARCH): $(K8S_GATEWAY_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ $(K8S_GATEWAY_DIR)/cmd/main.go
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ cmd/gateway2/main.go

.PHONY: kgateway
kgateway: $(CONTROLLER_OUTPUT_DIR)/kgateway-linux-$(GOARCH)

$(CONTROLLER_OUTPUT_DIR)/Dockerfile: $(K8S_GATEWAY_DIR)/cmd/Dockerfile
$(CONTROLLER_OUTPUT_DIR)/Dockerfile: cmd/gateway2/Dockerfile
cp $< $@

.PHONY: kgateway-docker
Expand All @@ -388,7 +388,7 @@ kgateway-docker: $(CONTROLLER_OUTPUT_DIR)/kgateway-linux-$(GOARCH) $(CONTROLLER_
--build-arg ENVOY_IMAGE=$(ENVOY_IMAGE) \
-t $(IMAGE_REGISTRY)/$(CONTROLLER_IMAGE_REPO):$(VERSION)

$(CONTROLLER_OUTPUT_DIR)/Dockerfile.distroless: $(K8S_GATEWAY_DIR)/cmd/Dockerfile.distroless
$(CONTROLLER_OUTPUT_DIR)/Dockerfile.distroless: cmd/gateway2/Dockerfile.distroless
cp $< $@

# Explicitly specify the base image is amd64 as we only build the amd64 flavour of envoy
Expand All @@ -404,18 +404,18 @@ kgateway-distroless-docker: $(CONTROLLER_OUTPUT_DIR)/kgateway-linux-$(GOARCH) $(
# SDS Server - gRPC server for serving Secret Discovery Service config
#----------------------------------------------------------------------------------

SDS_DIR=projects/sds
SDS_DIR=internal/sds
SDS_SOURCES=$(call get_sources,$(SDS_DIR))
SDS_OUTPUT_DIR=$(OUTPUT_DIR)/$(SDS_DIR)
export SDS_IMAGE_REPO ?= sds

$(SDS_OUTPUT_DIR)/sds-linux-$(GOARCH): $(SDS_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ $(SDS_DIR)/cmd/main.go
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ cmd/sds/main.go

.PHONY: sds
sds: $(SDS_OUTPUT_DIR)/sds-linux-$(GOARCH)

$(SDS_OUTPUT_DIR)/Dockerfile.sds: $(SDS_DIR)/cmd/Dockerfile
$(SDS_OUTPUT_DIR)/Dockerfile.sds: cmd/sds/Dockerfile
cp $< $@

.PHONY: sds-docker
Expand All @@ -425,7 +425,7 @@ sds-docker: $(SDS_OUTPUT_DIR)/sds-linux-$(GOARCH) $(SDS_OUTPUT_DIR)/Dockerfile.s
--build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) \
-t $(IMAGE_REGISTRY)/$(SDS_IMAGE_REPO):$(VERSION)

$(SDS_OUTPUT_DIR)/Dockerfile.sds.distroless: $(SDS_DIR)/cmd/Dockerfile.distroless
$(SDS_OUTPUT_DIR)/Dockerfile.sds.distroless: cmd/sds/Dockerfile.distroless
cp $< $@

.PHONY: sds-distroless-docker
Expand All @@ -439,21 +439,21 @@ sds-distroless-docker: $(SDS_OUTPUT_DIR)/sds-linux-$(GOARCH) $(SDS_OUTPUT_DIR)/D
# Envoy init (BASE/SIDECAR)
#----------------------------------------------------------------------------------

ENVOYINIT_DIR=projects/envoyinit/cmd
ENVOYINIT_DIR=internal/envoyinit
ENVOYINIT_SOURCES=$(call get_sources,$(ENVOYINIT_DIR))
ENVOYINIT_OUTPUT_DIR=$(OUTPUT_DIR)/$(ENVOYINIT_DIR)
export ENVOYINIT_IMAGE_REPO ?= envoy-wrapper

$(ENVOYINIT_OUTPUT_DIR)/envoyinit-linux-$(GOARCH): $(ENVOYINIT_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ $(ENVOYINIT_DIR)/main.go
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ cmd/envoyinit/main.go

.PHONY: envoyinit
envoyinit: $(ENVOYINIT_OUTPUT_DIR)/envoyinit-linux-$(GOARCH)

$(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit: $(ENVOYINIT_DIR)/Dockerfile.envoyinit
$(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit: cmd/envoyinit/Dockerfile.envoyinit
cp $< $@

$(ENVOYINIT_OUTPUT_DIR)/docker-entrypoint.sh: $(ENVOYINIT_DIR)/docker-entrypoint.sh
$(ENVOYINIT_OUTPUT_DIR)/docker-entrypoint.sh: cmd/envoyinit/docker-entrypoint.sh
cp $< $@

.PHONY: envoy-wrapper-docker
Expand All @@ -463,7 +463,7 @@ envoy-wrapper-docker: $(ENVOYINIT_OUTPUT_DIR)/envoyinit-linux-$(GOARCH) $(ENVOYI
--build-arg ENVOY_IMAGE=$(ENVOY_IMAGE) \
-t $(IMAGE_REGISTRY)/$(ENVOYINIT_IMAGE_REPO):$(VERSION)

$(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit.distroless: $(ENVOYINIT_DIR)/Dockerfile.envoyinit.distroless
$(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit.distroless: cmd/envoyinit/Dockerfile.envoyinit.distroless
cp $< $@

# Explicitly specify the base image is amd64 as we only build the amd64 flavour of envoy
Expand Down
6 changes: 3 additions & 3 deletions projects/gateway2/api/README.md → api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ These are the steps required to add a new CRD to be used in the Kubernetes Gatew

1. If creating a new API version (e.g. `v1`, `v2alpha1`), create a new directory for the version and create a `doc.go` file with the `// +kubebuilder:object:generate=true` annotation, so that Go types in that directory will be converted into CRDs when codegen is run.
- The `groupName` marker specifies the API group name for the generated CRD.
2. Create a `_types.go` file in the API version directory. Following [gateway_parameters_types.go](/projects/gateway2/api/v1alpha1/gateway_parameters_types.go) as an example:
2. Create a `_types.go` file in the API version directory. Following [gateway_parameters_types.go](/api/v1alpha1/gateway_parameters_types.go) as an example:
- Define a struct for the resource (containing the metadata fields, `Spec`, and `Status`)
- Tip: For spec fields, try to use pointer values when appropriate, as it makes inheritance easier (allows us to differentiate between zero values and nil).
- Define getters for each field, as these are not generated automatically.
Expand All @@ -17,12 +17,12 @@ These are the steps required to add a new CRD to be used in the Kubernetes Gatew
- Avoid using slices with pointers. see: https://github.com/kubernetes/code-generator/issues/166
- Define RBAC rules using the `+kubebuilder:rbac` annotation (note: this annotation should not belong to the type, but rather the file or package.). Alternativly, define RBAC rules in the helm chart in `install/helm/gloo/templates/44-rbac.yaml`.
- Define a struct for the resource list (containing the metadata fields and `Items`)
3. Run codegen via `make generated-code -B`. This will invoke the `controller-gen` command specified in [generate.go](/projects/gateway2/generate.go), which should result in the following:
3. Run codegen via `make generated-code -B`. This will invoke the `controller-gen` command specified in [generate.go](/hack/generate.go), which should result in the following:
- A `zz_generated.deepcopy.go` file is created in the same directory as the Go types.
- A `zz_generated.register.go` file is created in the same directory as the Go types. To help with registering the Go types with the scheme.
- A CRD file is generated in [install/helm/gloo/crds](/install/helm/gloo/crds)
- RBAC role is generated in `install/helm/gloo/files/rbac/role.yaml`
- Updates the `projects/gateway2/api/applyconfiguration` `projects/gateway2/pkg/generated` and `projects/gateway2/pkg/client` folders with kube clients. These are used in plugin initialization and the fake client is used in tests.
- Updates the `api/applyconfiguration` `pkg/generated` and `pkg/client` folders with kube clients. These are used in plugin initialization and the fake client is used in tests.

## Background

Expand Down

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

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

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

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

File renamed without changes.

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

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

File renamed without changes.

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

Loading

0 comments on commit eca3b94

Please sign in to comment.