Initial commit
This commit is contained in:
25
.devcontainer/devcontainer.json
Normal file
25
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"name": "Kubebuilder DevContainer",
|
||||||
|
"image": "golang:1.22",
|
||||||
|
"features": {
|
||||||
|
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
|
||||||
|
"ghcr.io/devcontainers/features/git:1": {}
|
||||||
|
},
|
||||||
|
|
||||||
|
"runArgs": ["--network=host"],
|
||||||
|
|
||||||
|
"customizations": {
|
||||||
|
"vscode": {
|
||||||
|
"settings": {
|
||||||
|
"terminal.integrated.shell.linux": "/bin/bash"
|
||||||
|
},
|
||||||
|
"extensions": [
|
||||||
|
"ms-kubernetes-tools.vscode-kubernetes-tools",
|
||||||
|
"ms-azuretools.vscode-docker"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"onCreateCommand": "bash .devcontainer/post-install.sh"
|
||||||
|
}
|
||||||
|
|
||||||
23
.devcontainer/post-install.sh
Normal file
23
.devcontainer/post-install.sh
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -x
|
||||||
|
|
||||||
|
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
|
||||||
|
chmod +x ./kind
|
||||||
|
mv ./kind /usr/local/bin/kind
|
||||||
|
|
||||||
|
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
|
||||||
|
chmod +x kubebuilder
|
||||||
|
mv kubebuilder /usr/local/bin/
|
||||||
|
|
||||||
|
KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
|
||||||
|
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
|
||||||
|
chmod +x kubectl
|
||||||
|
mv kubectl /usr/local/bin/kubectl
|
||||||
|
|
||||||
|
docker network create -d=bridge --subnet=172.19.0.0/24 kind
|
||||||
|
|
||||||
|
kind version
|
||||||
|
kubebuilder version
|
||||||
|
docker --version
|
||||||
|
go version
|
||||||
|
kubectl version --client
|
||||||
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
|
||||||
|
# Ignore build and test binaries.
|
||||||
|
bin/
|
||||||
23
.github/workflows/lint.yml
vendored
Normal file
23
.github/workflows/lint.yml
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
name: Lint
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
name: Run on Ubuntu
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Clone the code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: '~1.22'
|
||||||
|
|
||||||
|
- name: Run linter
|
||||||
|
uses: golangci/golangci-lint-action@v6
|
||||||
|
with:
|
||||||
|
version: v1.61
|
||||||
44
.github/workflows/release.yml
vendored
Normal file
44
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
name: Release
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- v0.**
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
packages: write
|
||||||
|
contents: read
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
-
|
||||||
|
name: Login to DockerHub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
-
|
||||||
|
name: Get the tag name
|
||||||
|
id: get_tag_name
|
||||||
|
run: |
|
||||||
|
# Extract tag name and remove "v" if present
|
||||||
|
TAG_NAME="${GITHUB_REF#refs/tags/}"
|
||||||
|
VERSION="${TAG_NAME#v}"
|
||||||
|
echo "VERSION=${VERSION}" >> $GITHUB_ENV
|
||||||
|
echo BUILD_TIME=$(date) >> ${GITHUB_ENV}
|
||||||
|
-
|
||||||
|
name: Build and push
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
file: "./Dockerfile"
|
||||||
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
|
tags: |
|
||||||
|
"${{vars.BUILDKIT_IMAGE}}:${{ env.VERSION }}"
|
||||||
|
"${{vars.BUILDKIT_IMAGE}}:latest"
|
||||||
|
|
||||||
35
.github/workflows/test-e2e.yml
vendored
Normal file
35
.github/workflows/test-e2e.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
name: E2E Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test-e2e:
|
||||||
|
name: Run on Ubuntu
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Clone the code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: '~1.22'
|
||||||
|
|
||||||
|
- name: Install the latest version of kind
|
||||||
|
run: |
|
||||||
|
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
|
||||||
|
chmod +x ./kind
|
||||||
|
sudo mv ./kind /usr/local/bin/kind
|
||||||
|
|
||||||
|
- name: Verify kind installation
|
||||||
|
run: kind version
|
||||||
|
|
||||||
|
- name: Create kind cluster
|
||||||
|
run: kind create cluster
|
||||||
|
|
||||||
|
- name: Running Test e2e
|
||||||
|
run: |
|
||||||
|
go mod tidy
|
||||||
|
make test-e2e
|
||||||
23
.github/workflows/test.yml
vendored
Normal file
23
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
name: Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
name: Run on Ubuntu
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Clone the code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: '~1.22'
|
||||||
|
|
||||||
|
- name: Running Tests
|
||||||
|
run: |
|
||||||
|
go mod tidy
|
||||||
|
make test
|
||||||
27
.gitignore
vendored
Normal file
27
.gitignore
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Binaries for programs and plugins
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
bin/*
|
||||||
|
Dockerfile.cross
|
||||||
|
|
||||||
|
# Test binary, built with `go test -c`
|
||||||
|
*.test
|
||||||
|
|
||||||
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
|
*.out
|
||||||
|
|
||||||
|
# Go workspace file
|
||||||
|
go.work
|
||||||
|
|
||||||
|
# Kubernetes Generated files - skip generated files, except for vendored files
|
||||||
|
!vendor/**/zz_generated.*
|
||||||
|
|
||||||
|
# editor and IDE paraphernalia
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*~
|
||||||
43
.golangci.yml
Normal file
43
.golangci.yml
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
run:
|
||||||
|
timeout: 5m
|
||||||
|
allow-parallel-runners: true
|
||||||
|
|
||||||
|
issues:
|
||||||
|
# don't skip warning about doc comments
|
||||||
|
# don't exclude the default set of lint
|
||||||
|
exclude-use-default: false
|
||||||
|
# restore some of the defaults
|
||||||
|
# (fill in the rest as needed)
|
||||||
|
exclude-rules:
|
||||||
|
- path: "api/*"
|
||||||
|
linters:
|
||||||
|
- lll
|
||||||
|
- path: "internal/*"
|
||||||
|
linters:
|
||||||
|
- dupl
|
||||||
|
- lll
|
||||||
|
linters:
|
||||||
|
disable-all: true
|
||||||
|
enable:
|
||||||
|
- dupl
|
||||||
|
- errcheck
|
||||||
|
- copyloopvar
|
||||||
|
- ginkgolinter
|
||||||
|
- goconst
|
||||||
|
- gocyclo
|
||||||
|
- gofmt
|
||||||
|
- gosimple
|
||||||
|
- ineffassign
|
||||||
|
- lll
|
||||||
|
- misspell
|
||||||
|
- nakedret
|
||||||
|
- prealloc
|
||||||
|
- revive
|
||||||
|
- typecheck
|
||||||
|
- unparam
|
||||||
|
- unused
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
revive:
|
||||||
|
rules:
|
||||||
|
- name: comment-spacings
|
||||||
33
Dockerfile
Normal file
33
Dockerfile
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Build the manager binary
|
||||||
|
FROM golang:1.22 AS builder
|
||||||
|
ARG TARGETOS
|
||||||
|
ARG TARGETARCH
|
||||||
|
|
||||||
|
WORKDIR /workspace
|
||||||
|
# Copy the Go Modules manifests
|
||||||
|
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 cmd/main.go cmd/main.go
|
||||||
|
COPY api/ api/
|
||||||
|
COPY internal/ internal/
|
||||||
|
|
||||||
|
# Build
|
||||||
|
# the GOARCH has not a default value to allow the binary be built according to the host where the command
|
||||||
|
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
|
||||||
|
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
|
||||||
|
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
|
||||||
|
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
|
||||||
|
|
||||||
|
# Use distroless as minimal base image to package the manager binary
|
||||||
|
# Refer to https://github.com/GoogleContainerTools/distroless for more details
|
||||||
|
FROM gcr.io/distroless/static:nonroot
|
||||||
|
WORKDIR /
|
||||||
|
COPY --from=builder /workspace/manager .
|
||||||
|
USER 65532:65532
|
||||||
|
|
||||||
|
ENTRYPOINT ["/manager"]
|
||||||
201
LICENSE
Normal file
201
LICENSE
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright 2024 Jonas Kaninda
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
212
Makefile
Normal file
212
Makefile
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
# Image URL to use all building/pushing image targets
|
||||||
|
IMG ?= jkaninda/goma-operator:0.1.0-rc.1
|
||||||
|
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
|
||||||
|
ENVTEST_K8S_VERSION = 1.31.0
|
||||||
|
|
||||||
|
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
|
||||||
|
ifeq (,$(shell go env GOBIN))
|
||||||
|
GOBIN=$(shell go env GOPATH)/bin
|
||||||
|
else
|
||||||
|
GOBIN=$(shell go env GOBIN)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# CONTAINER_TOOL defines the container tool to be used for building images.
|
||||||
|
# Be aware that the target commands are only tested with Docker which is
|
||||||
|
# scaffolded by default. However, you might want to replace it to use other
|
||||||
|
# tools. (i.e. podman)
|
||||||
|
CONTAINER_TOOL ?= docker
|
||||||
|
|
||||||
|
# Setting SHELL to bash allows bash commands to be executed by recipes.
|
||||||
|
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
|
||||||
|
SHELL = /usr/bin/env bash -o pipefail
|
||||||
|
.SHELLFLAGS = -ec
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all: build
|
||||||
|
|
||||||
|
##@ General
|
||||||
|
|
||||||
|
# The help target prints out all targets with their descriptions organized
|
||||||
|
# beneath their categories. The categories are represented by '##@' and the
|
||||||
|
# target descriptions by '##'. The awk command is responsible for reading the
|
||||||
|
# entire set of makefiles included in this invocation, looking for lines of the
|
||||||
|
# file as xyz: ## something, and then pretty-format the target and help. Then,
|
||||||
|
# if there's a line with ##@ something, that gets pretty-printed as a category.
|
||||||
|
# More info on the usage of ANSI control characters for terminal formatting:
|
||||||
|
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
|
||||||
|
# More info on the awk command:
|
||||||
|
# http://linuxcommand.org/lc3_adv_awk.php
|
||||||
|
|
||||||
|
.PHONY: help
|
||||||
|
help: ## Display this help.
|
||||||
|
@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)
|
||||||
|
|
||||||
|
##@ Development
|
||||||
|
|
||||||
|
.PHONY: manifests
|
||||||
|
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
|
||||||
|
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
|
||||||
|
|
||||||
|
.PHONY: generate
|
||||||
|
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
|
||||||
|
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
|
||||||
|
|
||||||
|
.PHONY: fmt
|
||||||
|
fmt: ## Run go fmt against code.
|
||||||
|
go fmt ./...
|
||||||
|
|
||||||
|
.PHONY: vet
|
||||||
|
vet: ## Run go vet against code.
|
||||||
|
go vet ./...
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test: manifests generate fmt vet envtest ## Run tests.
|
||||||
|
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
|
||||||
|
|
||||||
|
# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
|
||||||
|
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
|
||||||
|
# Prometheus and CertManager are installed by default; skip with:
|
||||||
|
# - PROMETHEUS_INSTALL_SKIP=true
|
||||||
|
# - CERT_MANAGER_INSTALL_SKIP=true
|
||||||
|
.PHONY: test-e2e
|
||||||
|
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
|
||||||
|
@command -v kind >/dev/null 2>&1 || { \
|
||||||
|
echo "Kind is not installed. Please install Kind manually."; \
|
||||||
|
exit 1; \
|
||||||
|
}
|
||||||
|
@kind get clusters | grep -q 'kind' || { \
|
||||||
|
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
|
||||||
|
exit 1; \
|
||||||
|
}
|
||||||
|
go test ./test/e2e/ -v -ginkgo.v
|
||||||
|
|
||||||
|
.PHONY: lint
|
||||||
|
lint: golangci-lint ## Run golangci-lint linter
|
||||||
|
$(GOLANGCI_LINT) run
|
||||||
|
|
||||||
|
.PHONY: lint-fix
|
||||||
|
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
|
||||||
|
$(GOLANGCI_LINT) run --fix
|
||||||
|
|
||||||
|
##@ Build
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
|
build: manifests generate fmt vet ## Build manager binary.
|
||||||
|
go build -o bin/manager cmd/main.go
|
||||||
|
|
||||||
|
.PHONY: run
|
||||||
|
run: manifests generate fmt vet ## Run a controller from your host.
|
||||||
|
go run ./cmd/main.go
|
||||||
|
|
||||||
|
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
|
||||||
|
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
|
||||||
|
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
|
||||||
|
.PHONY: docker-build
|
||||||
|
docker-build: ## Build docker image with the manager.
|
||||||
|
$(CONTAINER_TOOL) build -t ${IMG} .
|
||||||
|
|
||||||
|
.PHONY: docker-push
|
||||||
|
docker-push: ## Push docker image with the manager.
|
||||||
|
$(CONTAINER_TOOL) push ${IMG}
|
||||||
|
|
||||||
|
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
|
||||||
|
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
|
||||||
|
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
|
||||||
|
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
|
||||||
|
# - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
|
||||||
|
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
|
||||||
|
PLATFORMS ?= linux/arm64,linux/amd64,linux/arm/v7
|
||||||
|
.PHONY: docker-buildx
|
||||||
|
docker-buildx: ## Build and push docker image for the manager for cross-platform support
|
||||||
|
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
|
||||||
|
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
|
||||||
|
- $(CONTAINER_TOOL) buildx create --name goma-operator-builder
|
||||||
|
$(CONTAINER_TOOL) buildx use goma-operator-builder
|
||||||
|
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
|
||||||
|
- $(CONTAINER_TOOL) buildx rm goma-operator-builder
|
||||||
|
rm Dockerfile.cross
|
||||||
|
|
||||||
|
.PHONY: build-installer
|
||||||
|
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
|
||||||
|
mkdir -p dist
|
||||||
|
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
|
||||||
|
$(KUSTOMIZE) build config/default > dist/install.yaml
|
||||||
|
|
||||||
|
##@ Deployment
|
||||||
|
|
||||||
|
ifndef ignore-not-found
|
||||||
|
ignore-not-found = false
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: install
|
||||||
|
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
|
||||||
|
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
|
||||||
|
|
||||||
|
.PHONY: uninstall
|
||||||
|
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
|
||||||
|
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
|
||||||
|
|
||||||
|
.PHONY: deploy
|
||||||
|
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
|
||||||
|
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
|
||||||
|
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
|
||||||
|
|
||||||
|
.PHONY: undeploy
|
||||||
|
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
|
||||||
|
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
|
||||||
|
|
||||||
|
##@ Dependencies
|
||||||
|
|
||||||
|
## Location to install dependencies to
|
||||||
|
LOCALBIN ?= $(shell pwd)/bin
|
||||||
|
$(LOCALBIN):
|
||||||
|
mkdir -p $(LOCALBIN)
|
||||||
|
|
||||||
|
## Tool Binaries
|
||||||
|
KUBECTL ?= kubectl
|
||||||
|
KUSTOMIZE ?= $(LOCALBIN)/kustomize
|
||||||
|
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
|
||||||
|
ENVTEST ?= $(LOCALBIN)/setup-envtest
|
||||||
|
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
|
||||||
|
|
||||||
|
## Tool Versions
|
||||||
|
KUSTOMIZE_VERSION ?= v5.5.0
|
||||||
|
CONTROLLER_TOOLS_VERSION ?= v0.16.4
|
||||||
|
ENVTEST_VERSION ?= release-0.19
|
||||||
|
GOLANGCI_LINT_VERSION ?= v1.61.0
|
||||||
|
|
||||||
|
.PHONY: kustomize
|
||||||
|
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
|
||||||
|
$(KUSTOMIZE): $(LOCALBIN)
|
||||||
|
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
|
||||||
|
|
||||||
|
.PHONY: controller-gen
|
||||||
|
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
|
||||||
|
$(CONTROLLER_GEN): $(LOCALBIN)
|
||||||
|
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
|
||||||
|
|
||||||
|
.PHONY: envtest
|
||||||
|
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
|
||||||
|
$(ENVTEST): $(LOCALBIN)
|
||||||
|
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
|
||||||
|
|
||||||
|
.PHONY: golangci-lint
|
||||||
|
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
|
||||||
|
$(GOLANGCI_LINT): $(LOCALBIN)
|
||||||
|
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
|
||||||
|
|
||||||
|
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
|
||||||
|
# $1 - target path with name of binary
|
||||||
|
# $2 - package url which can be installed
|
||||||
|
# $3 - specific version of package
|
||||||
|
define go-install-tool
|
||||||
|
@[ -f "$(1)-$(3)" ] || { \
|
||||||
|
set -e; \
|
||||||
|
package=$(2)@$(3) ;\
|
||||||
|
echo "Downloading $${package}" ;\
|
||||||
|
rm -f $(1) || true ;\
|
||||||
|
GOBIN=$(LOCALBIN) go install $${package} ;\
|
||||||
|
mv $(1) $(1)-$(3) ;\
|
||||||
|
} ;\
|
||||||
|
ln -sf $(1)-$(3) $(1)
|
||||||
|
endef
|
||||||
37
PROJECT
Normal file
37
PROJECT
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Code generated by tool. DO NOT EDIT.
|
||||||
|
# This file is used to track the info used to scaffold your project
|
||||||
|
# and allow the plugins properly work.
|
||||||
|
# More info: https://book.kubebuilder.io/reference/project-config.html
|
||||||
|
domain: github.io
|
||||||
|
layout:
|
||||||
|
- go.kubebuilder.io/v4
|
||||||
|
projectName: goma-operator
|
||||||
|
repo: github.com/jkaninda/goma-operator
|
||||||
|
resources:
|
||||||
|
- api:
|
||||||
|
crdVersion: v1
|
||||||
|
namespaced: true
|
||||||
|
controller: true
|
||||||
|
domain: github.io
|
||||||
|
group: gomaproj
|
||||||
|
kind: Gateway
|
||||||
|
path: github.com/jkaninda/goma-operator/api/v1beta1
|
||||||
|
version: v1beta1
|
||||||
|
- api:
|
||||||
|
crdVersion: v1
|
||||||
|
namespaced: true
|
||||||
|
controller: true
|
||||||
|
domain: github.io
|
||||||
|
group: gomaproj
|
||||||
|
kind: Route
|
||||||
|
path: github.com/jkaninda/goma-operator/api/v1beta1
|
||||||
|
version: v1beta1
|
||||||
|
- api:
|
||||||
|
crdVersion: v1
|
||||||
|
namespaced: true
|
||||||
|
domain: github.io
|
||||||
|
group: gomaproj
|
||||||
|
kind: Middleware
|
||||||
|
path: github.com/jkaninda/goma-operator/api/v1beta1
|
||||||
|
version: v1beta1
|
||||||
|
version: "3"
|
||||||
43
README.md
Normal file
43
README.md
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# Goma Gateway Kubernetes operator
|
||||||
|
A Kubernetes operator for managing Goma Gateway.
|
||||||
|
|
||||||
|
[](https://github.com/jkaninda/goma-operator/actions/workflows/test.yml)
|
||||||
|
[](https://github.com/jkaninda/goma-operator/releases)
|
||||||
|
[](https://goreportcard.com/report/github.com/jkaninda/goma-operator)
|
||||||
|
[](https://pkg.go.dev/github.com/jkaninda/goma-operator)
|
||||||
|

|
||||||
|
|
||||||
|
## Links:
|
||||||
|
|
||||||
|
- [Docker Hub](https://hub.docker.com/r/jkaninda/goma-operator)
|
||||||
|
- [Github](https://github.com/jkaninda/goma-operator)
|
||||||
|
|
||||||
|
### Documentation is found at <https://jkaninda.github.io/goma-gateway/install/kuberntes-advanced.html>
|
||||||
|
|
||||||
|
|
||||||
|
### 1. Kubernetes installation
|
||||||
|
|
||||||
|
**Install the CRDs and Operator into the cluster:**
|
||||||
|
|
||||||
|
```sh
|
||||||
|
kubectl apply -f https://raw.githubusercontent.com/jkaninda/goma-operator/main/dist/install.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
64
api/v1beta1/gateway_types.go
Normal file
64
api/v1beta1/gateway_types.go
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package v1beta1
|
||||||
|
|
||||||
|
import (
|
||||||
|
v1 "k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GatewaySpec defines the desired state of Gateway.
|
||||||
|
type GatewaySpec struct {
|
||||||
|
GatewayVersion string `json:"gatewayVersion,omitempty"`
|
||||||
|
Server Server `json:"server,omitempty"`
|
||||||
|
ReplicaCount int32 `json:"replicaCount,omitempty"`
|
||||||
|
AutoScaling AutoScaling `json:"autoScaling,omitempty"`
|
||||||
|
Resources v1.ResourceRequirements `json:"resources,omitempty"`
|
||||||
|
Affinity *v1.Affinity `json:"affinity,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GatewayStatus defines the observed state of Gateway.
|
||||||
|
type GatewayStatus struct {
|
||||||
|
Replicas int32 `json:"replicas,omitempty"`
|
||||||
|
Routes int32 `json:"routes,omitempty"`
|
||||||
|
Conditions []metav1.Condition `json:"conditions,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// +kubebuilder:object:root=true
|
||||||
|
// +kubebuilder:subresource:status
|
||||||
|
|
||||||
|
// Gateway is the Schema for the gateways API.
|
||||||
|
type Gateway struct {
|
||||||
|
metav1.TypeMeta `json:",inline"`
|
||||||
|
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||||
|
|
||||||
|
Spec GatewaySpec `json:"spec,omitempty"`
|
||||||
|
Status GatewayStatus `json:"status,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// +kubebuilder:object:root=true
|
||||||
|
|
||||||
|
// GatewayList contains a list of Gateway.
|
||||||
|
type GatewayList struct {
|
||||||
|
metav1.TypeMeta `json:",inline"`
|
||||||
|
metav1.ListMeta `json:"metadata,omitempty"`
|
||||||
|
Items []Gateway `json:"items"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
SchemeBuilder.Register(&Gateway{}, &GatewayList{})
|
||||||
|
}
|
||||||
36
api/v1beta1/groupversion_info.go
Normal file
36
api/v1beta1/groupversion_info.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package v1beta1 contains API Schema definitions for the gomaproj v1beta1 API group.
|
||||||
|
// +kubebuilder:object:generate=true
|
||||||
|
// +groupName=gomaproj.github.io
|
||||||
|
package v1beta1
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/scheme"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// GroupVersion is group version used to register these objects.
|
||||||
|
GroupVersion = schema.GroupVersion{Group: "gomaproj.github.io", Version: "v1beta1"}
|
||||||
|
|
||||||
|
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
|
||||||
|
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
|
||||||
|
|
||||||
|
// AddToScheme adds the types in this group-version to the given scheme.
|
||||||
|
AddToScheme = SchemeBuilder.AddToScheme
|
||||||
|
)
|
||||||
67
api/v1beta1/middleware_types.go
Normal file
67
api/v1beta1/middleware_types.go
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package v1beta1
|
||||||
|
|
||||||
|
import (
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
|
||||||
|
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
|
||||||
|
|
||||||
|
// MiddlewareSpec defines the desired state of Middleware.
|
||||||
|
type MiddlewareSpec struct {
|
||||||
|
// Type contains authentication types
|
||||||
|
//
|
||||||
|
// basic, jwt, auth0, rateLimit, access
|
||||||
|
Type string `json:"type" yaml:"type"` // Middleware type [basic, jwt, auth0, rateLimit, access]
|
||||||
|
Paths []string `json:"paths" yaml:"paths"` // Protected paths
|
||||||
|
// Rule contains rule type of
|
||||||
|
Rule runtime.RawExtension `json:"rule,omitempty" yaml:"rule"` // Middleware rule
|
||||||
|
}
|
||||||
|
|
||||||
|
// MiddlewareStatus defines the observed state of Middleware.
|
||||||
|
type MiddlewareStatus struct {
|
||||||
|
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
|
||||||
|
// Important: Run "make" to regenerate code after modifying this file
|
||||||
|
}
|
||||||
|
|
||||||
|
// +kubebuilder:object:root=true
|
||||||
|
// +kubebuilder:subresource:status
|
||||||
|
|
||||||
|
// Middleware is the Schema for the middlewares API.
|
||||||
|
type Middleware struct {
|
||||||
|
metav1.TypeMeta `json:",inline"`
|
||||||
|
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||||
|
|
||||||
|
Spec MiddlewareSpec `json:"spec,omitempty"`
|
||||||
|
Status MiddlewareStatus `json:"status,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// +kubebuilder:object:root=true
|
||||||
|
|
||||||
|
// MiddlewareList contains a list of Middleware.
|
||||||
|
type MiddlewareList struct {
|
||||||
|
metav1.TypeMeta `json:",inline"`
|
||||||
|
metav1.ListMeta `json:"metadata,omitempty"`
|
||||||
|
Items []Middleware `json:"items"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
SchemeBuilder.Register(&Middleware{}, &MiddlewareList{})
|
||||||
|
}
|
||||||
61
api/v1beta1/route_types.go
Normal file
61
api/v1beta1/route_types.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package v1beta1
|
||||||
|
|
||||||
|
import (
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
|
||||||
|
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
|
||||||
|
|
||||||
|
// RouteSpec defines the desired state of Route.
|
||||||
|
type RouteSpec struct {
|
||||||
|
Gateway string `json:"gateway"`
|
||||||
|
Routes []RouteConfig `json:"routes"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RouteStatus defines the observed state of Route.
|
||||||
|
type RouteStatus struct {
|
||||||
|
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
|
||||||
|
// Important: Run "make" to regenerate code after modifying this file
|
||||||
|
}
|
||||||
|
|
||||||
|
// +kubebuilder:object:root=true
|
||||||
|
// +kubebuilder:subresource:status
|
||||||
|
|
||||||
|
// Route is the Schema for the routes API.
|
||||||
|
type Route struct {
|
||||||
|
metav1.TypeMeta `json:",inline"`
|
||||||
|
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||||
|
|
||||||
|
Spec RouteSpec `json:"spec,omitempty"`
|
||||||
|
Status RouteStatus `json:"status,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// +kubebuilder:object:root=true
|
||||||
|
|
||||||
|
// RouteList contains a list of Route.
|
||||||
|
type RouteList struct {
|
||||||
|
metav1.TypeMeta `json:",inline"`
|
||||||
|
metav1.ListMeta `json:"metadata,omitempty"`
|
||||||
|
Items []Route `json:"items"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
SchemeBuilder.Register(&Route{}, &RouteList{})
|
||||||
|
}
|
||||||
87
api/v1beta1/types.go
Normal file
87
api/v1beta1/types.go
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
package v1beta1
|
||||||
|
|
||||||
|
type GatewayConfig struct {
|
||||||
|
GatewayConf GatewaySpec `yaml:"gateway,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Cors struct {
|
||||||
|
// Cors contains Allowed origins,
|
||||||
|
Origins []string `json:"origins,omitempty" yaml:"origins,omitempty"`
|
||||||
|
// Headers contains custom headers
|
||||||
|
Headers map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tls struct {
|
||||||
|
CredentialName string `json:"credentialName"` // CredentialName fetches certs from Kubernetes secret
|
||||||
|
}
|
||||||
|
|
||||||
|
type AutoScaling struct {
|
||||||
|
Enabled bool `json:"enabled,omitempty"`
|
||||||
|
MinReplicas int32 `json:"minReplicas,omitempty"`
|
||||||
|
MaxReplicas int32 `json:"maxReplicas,omitempty"`
|
||||||
|
TargetCPUUtilizationPercentage int32 `json:"targetCPUUtilizationPercentage,omitempty"`
|
||||||
|
TargetMemoryUtilizationPercentage int32 `json:"targetMemoryUtilizationPercentage,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Middlewares struct {
|
||||||
|
Middlewares []MiddlewareSpec `json:"middlewares,omitempty" yaml:"middlewares,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Server struct {
|
||||||
|
// WriteTimeout defines proxy write timeout
|
||||||
|
WriteTimeout int `json:"writeTimeout,omitempty" yaml:"writeTimeout,omitempty"`
|
||||||
|
// ReadTimeout defines proxy read timeout
|
||||||
|
ReadTimeout int `json:"readTimeout,omitempty" yaml:"readTimeout,omitempty"`
|
||||||
|
// IdleTimeout defines proxy idle timeout
|
||||||
|
IdleTimeout int `json:"idleTimeout,omitempty" yaml:"idleTimeout,omitempty"`
|
||||||
|
// LogLevel log level, info, debug, trace, off
|
||||||
|
LogLevel string `json:"logLevel,omitempty" yaml:"logLevel,omitempty"`
|
||||||
|
// Cors holds proxy global cors
|
||||||
|
Cors Cors `json:"cors,omitempty" yaml:"cors,omitempty,omitempty"`
|
||||||
|
// InterceptErrors holds the status codes to intercept the error from backend
|
||||||
|
InterceptErrors []int `json:"interceptErrors,omitempty" yaml:"interceptErrors,omitempty"`
|
||||||
|
// DisableHealthCheckStatus enable and disable routes health check
|
||||||
|
DisableHealthCheckStatus bool `json:"disableHealthCheckStatus,omitempty" yaml:"disableHealthCheckStatus"`
|
||||||
|
// DisableKeepAlive allows enabling and disabling KeepALive server
|
||||||
|
DisableKeepAlive bool `json:"disableKeepAlive,omitempty" yaml:"disableKeepAlive"`
|
||||||
|
// EnableMetrics enable and disable server metrics
|
||||||
|
EnableMetrics bool `json:"enableMetrics,omitempty" yaml:"enableMetrics"`
|
||||||
|
}
|
||||||
|
type RouteConfig struct {
|
||||||
|
// Path defines route path
|
||||||
|
Path string `json:"path" yaml:"path"`
|
||||||
|
// Name defines route name
|
||||||
|
Name string `json:"name" yaml:"name"`
|
||||||
|
// Hosts Domains/hosts based request routing
|
||||||
|
Hosts []string `json:"hosts,omitempty" yaml:"hosts"`
|
||||||
|
// Rewrite rewrites route path to desired path
|
||||||
|
Rewrite string `json:"rewrite,omitempty" yaml:"rewrite"`
|
||||||
|
// Methods allowed method
|
||||||
|
Methods []string `json:"methods,omitempty" yaml:"methods"`
|
||||||
|
// Destination Defines backend URL
|
||||||
|
Destination string `json:"destination,omitempty" yaml:"destination"`
|
||||||
|
Backends []string `json:"backends,omitempty" yaml:"backends"`
|
||||||
|
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty" yaml:"insecureSkipVerify"`
|
||||||
|
// HealthCheck Defines the backend is health
|
||||||
|
HealthCheck RouteHealthCheck `json:"healthCheck,omitempty" yaml:"healthCheck,omitempty"`
|
||||||
|
// Cors contains the route cors headers
|
||||||
|
Cors Cors `json:"cors,omitempty" yaml:"cors"`
|
||||||
|
RateLimit int `json:"rateLimit,omitempty" yaml:"rateLimit"`
|
||||||
|
// DisableHostFording Disable host forwarding.
|
||||||
|
DisableHostFording bool `json:"disableHostFording,omitempty" yaml:"disableHostFording"`
|
||||||
|
// InterceptErrors intercepts backend errors based on the status codes
|
||||||
|
InterceptErrors []int `json:"interceptErrors,omitempty" yaml:"interceptErrors"`
|
||||||
|
// BlockCommonExploits enable, disable block common exploits
|
||||||
|
BlockCommonExploits bool `json:"blockCommonExploits,omitempty" yaml:"blockCommonExploits"`
|
||||||
|
// Middlewares Defines route middleware
|
||||||
|
Middlewares []string `json:"middlewares,omitempty" yaml:"middlewares"`
|
||||||
|
}
|
||||||
|
type RoutesConfig struct {
|
||||||
|
Routes []RouteConfig `json:"routes" yaml:"routes"`
|
||||||
|
}
|
||||||
|
type RouteHealthCheck struct {
|
||||||
|
Path string `json:"path,omitempty" yaml:"path"`
|
||||||
|
Interval string `json:"interval,omitempty" yaml:"interval"`
|
||||||
|
Timeout string `json:"timeout,omitempty" yaml:"timeout"`
|
||||||
|
HealthyStatuses []int `json:"healthyStatuses,omitempty" yaml:"healthyStatuses"`
|
||||||
|
}
|
||||||
522
api/v1beta1/zz_generated.deepcopy.go
Normal file
522
api/v1beta1/zz_generated.deepcopy.go
Normal file
@@ -0,0 +1,522 @@
|
|||||||
|
//go:build !ignore_autogenerated
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Code generated by controller-gen. DO NOT EDIT.
|
||||||
|
|
||||||
|
package v1beta1
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *AutoScaling) DeepCopyInto(out *AutoScaling) {
|
||||||
|
*out = *in
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutoScaling.
|
||||||
|
func (in *AutoScaling) DeepCopy() *AutoScaling {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(AutoScaling)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *Cors) DeepCopyInto(out *Cors) {
|
||||||
|
*out = *in
|
||||||
|
if in.Origins != nil {
|
||||||
|
in, out := &in.Origins, &out.Origins
|
||||||
|
*out = make([]string, len(*in))
|
||||||
|
copy(*out, *in)
|
||||||
|
}
|
||||||
|
if in.Headers != nil {
|
||||||
|
in, out := &in.Headers, &out.Headers
|
||||||
|
*out = make(map[string]string, len(*in))
|
||||||
|
for key, val := range *in {
|
||||||
|
(*out)[key] = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Cors.
|
||||||
|
func (in *Cors) DeepCopy() *Cors {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(Cors)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *Gateway) DeepCopyInto(out *Gateway) {
|
||||||
|
*out = *in
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||||
|
in.Spec.DeepCopyInto(&out.Spec)
|
||||||
|
in.Status.DeepCopyInto(&out.Status)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Gateway.
|
||||||
|
func (in *Gateway) DeepCopy() *Gateway {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(Gateway)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||||
|
func (in *Gateway) DeepCopyObject() runtime.Object {
|
||||||
|
if c := in.DeepCopy(); c != nil {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *GatewayConfig) DeepCopyInto(out *GatewayConfig) {
|
||||||
|
*out = *in
|
||||||
|
in.GatewayConf.DeepCopyInto(&out.GatewayConf)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GatewayConfig.
|
||||||
|
func (in *GatewayConfig) DeepCopy() *GatewayConfig {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(GatewayConfig)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *GatewayList) DeepCopyInto(out *GatewayList) {
|
||||||
|
*out = *in
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
in.ListMeta.DeepCopyInto(&out.ListMeta)
|
||||||
|
if in.Items != nil {
|
||||||
|
in, out := &in.Items, &out.Items
|
||||||
|
*out = make([]Gateway, len(*in))
|
||||||
|
for i := range *in {
|
||||||
|
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GatewayList.
|
||||||
|
func (in *GatewayList) DeepCopy() *GatewayList {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(GatewayList)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||||
|
func (in *GatewayList) DeepCopyObject() runtime.Object {
|
||||||
|
if c := in.DeepCopy(); c != nil {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *GatewaySpec) DeepCopyInto(out *GatewaySpec) {
|
||||||
|
*out = *in
|
||||||
|
in.Server.DeepCopyInto(&out.Server)
|
||||||
|
out.AutoScaling = in.AutoScaling
|
||||||
|
in.Resources.DeepCopyInto(&out.Resources)
|
||||||
|
if in.Affinity != nil {
|
||||||
|
in, out := &in.Affinity, &out.Affinity
|
||||||
|
*out = new(v1.Affinity)
|
||||||
|
(*in).DeepCopyInto(*out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GatewaySpec.
|
||||||
|
func (in *GatewaySpec) DeepCopy() *GatewaySpec {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(GatewaySpec)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *GatewayStatus) DeepCopyInto(out *GatewayStatus) {
|
||||||
|
*out = *in
|
||||||
|
if in.Conditions != nil {
|
||||||
|
in, out := &in.Conditions, &out.Conditions
|
||||||
|
*out = make([]metav1.Condition, len(*in))
|
||||||
|
for i := range *in {
|
||||||
|
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GatewayStatus.
|
||||||
|
func (in *GatewayStatus) DeepCopy() *GatewayStatus {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(GatewayStatus)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *Middleware) DeepCopyInto(out *Middleware) {
|
||||||
|
*out = *in
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||||
|
in.Spec.DeepCopyInto(&out.Spec)
|
||||||
|
out.Status = in.Status
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Middleware.
|
||||||
|
func (in *Middleware) DeepCopy() *Middleware {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(Middleware)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||||
|
func (in *Middleware) DeepCopyObject() runtime.Object {
|
||||||
|
if c := in.DeepCopy(); c != nil {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *MiddlewareList) DeepCopyInto(out *MiddlewareList) {
|
||||||
|
*out = *in
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
in.ListMeta.DeepCopyInto(&out.ListMeta)
|
||||||
|
if in.Items != nil {
|
||||||
|
in, out := &in.Items, &out.Items
|
||||||
|
*out = make([]Middleware, len(*in))
|
||||||
|
for i := range *in {
|
||||||
|
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MiddlewareList.
|
||||||
|
func (in *MiddlewareList) DeepCopy() *MiddlewareList {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(MiddlewareList)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||||
|
func (in *MiddlewareList) DeepCopyObject() runtime.Object {
|
||||||
|
if c := in.DeepCopy(); c != nil {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *MiddlewareSpec) DeepCopyInto(out *MiddlewareSpec) {
|
||||||
|
*out = *in
|
||||||
|
if in.Paths != nil {
|
||||||
|
in, out := &in.Paths, &out.Paths
|
||||||
|
*out = make([]string, len(*in))
|
||||||
|
copy(*out, *in)
|
||||||
|
}
|
||||||
|
in.Rule.DeepCopyInto(&out.Rule)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MiddlewareSpec.
|
||||||
|
func (in *MiddlewareSpec) DeepCopy() *MiddlewareSpec {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(MiddlewareSpec)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *MiddlewareStatus) DeepCopyInto(out *MiddlewareStatus) {
|
||||||
|
*out = *in
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MiddlewareStatus.
|
||||||
|
func (in *MiddlewareStatus) DeepCopy() *MiddlewareStatus {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(MiddlewareStatus)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *Middlewares) DeepCopyInto(out *Middlewares) {
|
||||||
|
*out = *in
|
||||||
|
if in.Middlewares != nil {
|
||||||
|
in, out := &in.Middlewares, &out.Middlewares
|
||||||
|
*out = make([]MiddlewareSpec, len(*in))
|
||||||
|
for i := range *in {
|
||||||
|
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Middlewares.
|
||||||
|
func (in *Middlewares) DeepCopy() *Middlewares {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(Middlewares)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *Route) DeepCopyInto(out *Route) {
|
||||||
|
*out = *in
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||||
|
in.Spec.DeepCopyInto(&out.Spec)
|
||||||
|
out.Status = in.Status
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Route.
|
||||||
|
func (in *Route) DeepCopy() *Route {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(Route)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||||
|
func (in *Route) DeepCopyObject() runtime.Object {
|
||||||
|
if c := in.DeepCopy(); c != nil {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *RouteConfig) DeepCopyInto(out *RouteConfig) {
|
||||||
|
*out = *in
|
||||||
|
if in.Hosts != nil {
|
||||||
|
in, out := &in.Hosts, &out.Hosts
|
||||||
|
*out = make([]string, len(*in))
|
||||||
|
copy(*out, *in)
|
||||||
|
}
|
||||||
|
if in.Methods != nil {
|
||||||
|
in, out := &in.Methods, &out.Methods
|
||||||
|
*out = make([]string, len(*in))
|
||||||
|
copy(*out, *in)
|
||||||
|
}
|
||||||
|
if in.Backends != nil {
|
||||||
|
in, out := &in.Backends, &out.Backends
|
||||||
|
*out = make([]string, len(*in))
|
||||||
|
copy(*out, *in)
|
||||||
|
}
|
||||||
|
in.HealthCheck.DeepCopyInto(&out.HealthCheck)
|
||||||
|
in.Cors.DeepCopyInto(&out.Cors)
|
||||||
|
if in.InterceptErrors != nil {
|
||||||
|
in, out := &in.InterceptErrors, &out.InterceptErrors
|
||||||
|
*out = make([]int, len(*in))
|
||||||
|
copy(*out, *in)
|
||||||
|
}
|
||||||
|
if in.Middlewares != nil {
|
||||||
|
in, out := &in.Middlewares, &out.Middlewares
|
||||||
|
*out = make([]string, len(*in))
|
||||||
|
copy(*out, *in)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteConfig.
|
||||||
|
func (in *RouteConfig) DeepCopy() *RouteConfig {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(RouteConfig)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *RouteHealthCheck) DeepCopyInto(out *RouteHealthCheck) {
|
||||||
|
*out = *in
|
||||||
|
if in.HealthyStatuses != nil {
|
||||||
|
in, out := &in.HealthyStatuses, &out.HealthyStatuses
|
||||||
|
*out = make([]int, len(*in))
|
||||||
|
copy(*out, *in)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteHealthCheck.
|
||||||
|
func (in *RouteHealthCheck) DeepCopy() *RouteHealthCheck {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(RouteHealthCheck)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *RouteList) DeepCopyInto(out *RouteList) {
|
||||||
|
*out = *in
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
in.ListMeta.DeepCopyInto(&out.ListMeta)
|
||||||
|
if in.Items != nil {
|
||||||
|
in, out := &in.Items, &out.Items
|
||||||
|
*out = make([]Route, len(*in))
|
||||||
|
for i := range *in {
|
||||||
|
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteList.
|
||||||
|
func (in *RouteList) DeepCopy() *RouteList {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(RouteList)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||||
|
func (in *RouteList) DeepCopyObject() runtime.Object {
|
||||||
|
if c := in.DeepCopy(); c != nil {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *RouteSpec) DeepCopyInto(out *RouteSpec) {
|
||||||
|
*out = *in
|
||||||
|
if in.Routes != nil {
|
||||||
|
in, out := &in.Routes, &out.Routes
|
||||||
|
*out = make([]RouteConfig, len(*in))
|
||||||
|
for i := range *in {
|
||||||
|
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteSpec.
|
||||||
|
func (in *RouteSpec) DeepCopy() *RouteSpec {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(RouteSpec)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *RouteStatus) DeepCopyInto(out *RouteStatus) {
|
||||||
|
*out = *in
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteStatus.
|
||||||
|
func (in *RouteStatus) DeepCopy() *RouteStatus {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(RouteStatus)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *RoutesConfig) DeepCopyInto(out *RoutesConfig) {
|
||||||
|
*out = *in
|
||||||
|
if in.Routes != nil {
|
||||||
|
in, out := &in.Routes, &out.Routes
|
||||||
|
*out = make([]RouteConfig, len(*in))
|
||||||
|
for i := range *in {
|
||||||
|
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RoutesConfig.
|
||||||
|
func (in *RoutesConfig) DeepCopy() *RoutesConfig {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(RoutesConfig)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *Server) DeepCopyInto(out *Server) {
|
||||||
|
*out = *in
|
||||||
|
in.Cors.DeepCopyInto(&out.Cors)
|
||||||
|
if in.InterceptErrors != nil {
|
||||||
|
in, out := &in.InterceptErrors, &out.InterceptErrors
|
||||||
|
*out = make([]int, len(*in))
|
||||||
|
copy(*out, *in)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Server.
|
||||||
|
func (in *Server) DeepCopy() *Server {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(Server)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *Tls) DeepCopyInto(out *Tls) {
|
||||||
|
*out = *in
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Tls.
|
||||||
|
func (in *Tls) DeepCopy() *Tls {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(Tls)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
175
cmd/main.go
Normal file
175
cmd/main.go
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"flag"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
|
||||||
|
// to ensure that exec-entrypoint and run can make use of them.
|
||||||
|
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
|
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/healthz"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
|
||||||
|
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||||
|
|
||||||
|
gomaprojv1beta1 "github.com/jkaninda/goma-operator/api/v1beta1"
|
||||||
|
"github.com/jkaninda/goma-operator/internal/controller"
|
||||||
|
// +kubebuilder:scaffold:imports
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
scheme = runtime.NewScheme()
|
||||||
|
setupLog = ctrl.Log.WithName("setup")
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
|
||||||
|
|
||||||
|
utilruntime.Must(gomaprojv1beta1.AddToScheme(scheme))
|
||||||
|
// +kubebuilder:scaffold:scheme
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var metricsAddr string
|
||||||
|
var enableLeaderElection bool
|
||||||
|
var probeAddr string
|
||||||
|
var secureMetrics bool
|
||||||
|
var enableHTTP2 bool
|
||||||
|
var tlsOpts []func(*tls.Config)
|
||||||
|
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
|
||||||
|
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
|
||||||
|
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
|
||||||
|
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
|
||||||
|
"Enable leader election for controller manager. "+
|
||||||
|
"Enabling this will ensure there is only one active controller manager.")
|
||||||
|
flag.BoolVar(&secureMetrics, "metrics-secure", true,
|
||||||
|
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
|
||||||
|
flag.BoolVar(&enableHTTP2, "enable-http2", false,
|
||||||
|
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
|
||||||
|
opts := zap.Options{
|
||||||
|
Development: true,
|
||||||
|
}
|
||||||
|
opts.BindFlags(flag.CommandLine)
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
|
||||||
|
|
||||||
|
// if the enable-http2 flag is false (the default), http/2 should be disabled
|
||||||
|
// due to its vulnerabilities. More specifically, disabling http/2 will
|
||||||
|
// prevent from being vulnerable to the HTTP/2 Stream Cancellation and
|
||||||
|
// Rapid Reset CVEs. For more information see:
|
||||||
|
// - https://github.com/advisories/GHSA-qppj-fm5r-hxr3
|
||||||
|
// - https://github.com/advisories/GHSA-4374-p667-p6c8
|
||||||
|
disableHTTP2 := func(c *tls.Config) {
|
||||||
|
setupLog.Info("disabling http/2")
|
||||||
|
c.NextProtos = []string{"http/1.1"}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !enableHTTP2 {
|
||||||
|
tlsOpts = append(tlsOpts, disableHTTP2)
|
||||||
|
}
|
||||||
|
|
||||||
|
webhookServer := webhook.NewServer(webhook.Options{
|
||||||
|
TLSOpts: tlsOpts,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
|
||||||
|
// More info:
|
||||||
|
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.1/pkg/metrics/server
|
||||||
|
// - https://book.kubebuilder.io/reference/metrics.html
|
||||||
|
metricsServerOptions := metricsserver.Options{
|
||||||
|
BindAddress: metricsAddr,
|
||||||
|
SecureServing: secureMetrics,
|
||||||
|
TLSOpts: tlsOpts,
|
||||||
|
}
|
||||||
|
|
||||||
|
if secureMetrics {
|
||||||
|
// FilterProvider is used to protect the metrics endpoint with authn/authz.
|
||||||
|
// These configurations ensure that only authorized users and service accounts
|
||||||
|
// can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info:
|
||||||
|
// https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.1/pkg/metrics/filters#WithAuthenticationAndAuthorization
|
||||||
|
metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization
|
||||||
|
|
||||||
|
// TODO(user): If CertDir, CertName, and KeyName are not specified, controller-runtime will automatically
|
||||||
|
// generate self-signed certificates for the metrics server. While convenient for development and testing,
|
||||||
|
// this setup is not recommended for production.
|
||||||
|
}
|
||||||
|
|
||||||
|
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
|
||||||
|
Scheme: scheme,
|
||||||
|
Metrics: metricsServerOptions,
|
||||||
|
WebhookServer: webhookServer,
|
||||||
|
HealthProbeBindAddress: probeAddr,
|
||||||
|
LeaderElection: enableLeaderElection,
|
||||||
|
LeaderElectionID: "9c4cdf27.github.io",
|
||||||
|
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
|
||||||
|
// when the Manager ends. This requires the binary to immediately end when the
|
||||||
|
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
|
||||||
|
// speeds up voluntary leader transitions as the new leader don't have to wait
|
||||||
|
// LeaseDuration time first.
|
||||||
|
//
|
||||||
|
// In the default scaffold provided, the program ends immediately after
|
||||||
|
// the manager stops, so would be fine to enable this option. However,
|
||||||
|
// if you are doing or is intended to do any operation such as perform cleanups
|
||||||
|
// after the manager stops then its usage might be unsafe.
|
||||||
|
// LeaderElectionReleaseOnCancel: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
setupLog.Error(err, "unable to start manager")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = (&controller.GatewayReconciler{
|
||||||
|
Client: mgr.GetClient(),
|
||||||
|
Scheme: mgr.GetScheme(),
|
||||||
|
}).SetupWithManager(mgr); err != nil {
|
||||||
|
setupLog.Error(err, "unable to create controller", "controller", "Gateway")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if err = (&controller.RouteReconciler{
|
||||||
|
Client: mgr.GetClient(),
|
||||||
|
Scheme: mgr.GetScheme(),
|
||||||
|
}).SetupWithManager(mgr); err != nil {
|
||||||
|
setupLog.Error(err, "unable to create controller", "controller", "Route")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
// +kubebuilder:scaffold:builder
|
||||||
|
|
||||||
|
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
|
||||||
|
setupLog.Error(err, "unable to set up health check")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
|
||||||
|
setupLog.Error(err, "unable to set up ready check")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
setupLog.Info("starting manager")
|
||||||
|
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
|
||||||
|
setupLog.Error(err, "problem running manager")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
1160
config/crd/bases/gomaproj.github.io_gateways.yaml
Normal file
1160
config/crd/bases/gomaproj.github.io_gateways.yaml
Normal file
File diff suppressed because it is too large
Load Diff
67
config/crd/bases/gomaproj.github.io_middlewares.yaml
Normal file
67
config/crd/bases/gomaproj.github.io_middlewares.yaml
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
---
|
||||||
|
apiVersion: apiextensions.k8s.io/v1
|
||||||
|
kind: CustomResourceDefinition
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
controller-gen.kubebuilder.io/version: v0.16.4
|
||||||
|
name: middlewares.gomaproj.github.io
|
||||||
|
spec:
|
||||||
|
group: gomaproj.github.io
|
||||||
|
names:
|
||||||
|
kind: Middleware
|
||||||
|
listKind: MiddlewareList
|
||||||
|
plural: middlewares
|
||||||
|
singular: middleware
|
||||||
|
scope: Namespaced
|
||||||
|
versions:
|
||||||
|
- name: v1beta1
|
||||||
|
schema:
|
||||||
|
openAPIV3Schema:
|
||||||
|
description: Middleware is the Schema for the middlewares API.
|
||||||
|
properties:
|
||||||
|
apiVersion:
|
||||||
|
description: |-
|
||||||
|
APIVersion defines the versioned schema of this representation of an object.
|
||||||
|
Servers should convert recognized schemas to the latest internal value, and
|
||||||
|
may reject unrecognized values.
|
||||||
|
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
|
||||||
|
type: string
|
||||||
|
kind:
|
||||||
|
description: |-
|
||||||
|
Kind is a string value representing the REST resource this object represents.
|
||||||
|
Servers may infer this from the endpoint the client submits requests to.
|
||||||
|
Cannot be updated.
|
||||||
|
In CamelCase.
|
||||||
|
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
|
||||||
|
type: string
|
||||||
|
metadata:
|
||||||
|
type: object
|
||||||
|
spec:
|
||||||
|
description: MiddlewareSpec defines the desired state of Middleware.
|
||||||
|
properties:
|
||||||
|
paths:
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
|
rule:
|
||||||
|
description: Rule contains rule type of
|
||||||
|
type: object
|
||||||
|
x-kubernetes-preserve-unknown-fields: true
|
||||||
|
type:
|
||||||
|
description: |-
|
||||||
|
Type contains authentication types
|
||||||
|
|
||||||
|
basic, jwt, auth0, rateLimit, access
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- paths
|
||||||
|
- type
|
||||||
|
type: object
|
||||||
|
status:
|
||||||
|
description: MiddlewareStatus defines the observed state of Middleware.
|
||||||
|
type: object
|
||||||
|
type: object
|
||||||
|
served: true
|
||||||
|
storage: true
|
||||||
|
subresources:
|
||||||
|
status: {}
|
||||||
139
config/crd/bases/gomaproj.github.io_routes.yaml
Normal file
139
config/crd/bases/gomaproj.github.io_routes.yaml
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
---
|
||||||
|
apiVersion: apiextensions.k8s.io/v1
|
||||||
|
kind: CustomResourceDefinition
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
controller-gen.kubebuilder.io/version: v0.16.4
|
||||||
|
name: routes.gomaproj.github.io
|
||||||
|
spec:
|
||||||
|
group: gomaproj.github.io
|
||||||
|
names:
|
||||||
|
kind: Route
|
||||||
|
listKind: RouteList
|
||||||
|
plural: routes
|
||||||
|
singular: route
|
||||||
|
scope: Namespaced
|
||||||
|
versions:
|
||||||
|
- name: v1beta1
|
||||||
|
schema:
|
||||||
|
openAPIV3Schema:
|
||||||
|
description: Route is the Schema for the routes API.
|
||||||
|
properties:
|
||||||
|
apiVersion:
|
||||||
|
description: |-
|
||||||
|
APIVersion defines the versioned schema of this representation of an object.
|
||||||
|
Servers should convert recognized schemas to the latest internal value, and
|
||||||
|
may reject unrecognized values.
|
||||||
|
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
|
||||||
|
type: string
|
||||||
|
kind:
|
||||||
|
description: |-
|
||||||
|
Kind is a string value representing the REST resource this object represents.
|
||||||
|
Servers may infer this from the endpoint the client submits requests to.
|
||||||
|
Cannot be updated.
|
||||||
|
In CamelCase.
|
||||||
|
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
|
||||||
|
type: string
|
||||||
|
metadata:
|
||||||
|
type: object
|
||||||
|
spec:
|
||||||
|
description: RouteSpec defines the desired state of Route.
|
||||||
|
properties:
|
||||||
|
gateway:
|
||||||
|
type: string
|
||||||
|
routes:
|
||||||
|
items:
|
||||||
|
properties:
|
||||||
|
backends:
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
|
blockCommonExploits:
|
||||||
|
description: BlockCommonExploits enable, disable block common
|
||||||
|
exploits
|
||||||
|
type: boolean
|
||||||
|
cors:
|
||||||
|
description: Cors contains the route cors headers
|
||||||
|
properties:
|
||||||
|
headers:
|
||||||
|
additionalProperties:
|
||||||
|
type: string
|
||||||
|
description: Headers contains custom headers
|
||||||
|
type: object
|
||||||
|
origins:
|
||||||
|
description: Cors contains Allowed origins,
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
|
type: object
|
||||||
|
destination:
|
||||||
|
description: Destination Defines backend URL
|
||||||
|
type: string
|
||||||
|
disableHostFording:
|
||||||
|
description: DisableHostFording Disable host forwarding.
|
||||||
|
type: boolean
|
||||||
|
healthCheck:
|
||||||
|
description: HealthCheck Defines the backend is health
|
||||||
|
properties:
|
||||||
|
healthyStatuses:
|
||||||
|
items:
|
||||||
|
type: integer
|
||||||
|
type: array
|
||||||
|
interval:
|
||||||
|
type: string
|
||||||
|
path:
|
||||||
|
type: string
|
||||||
|
timeout:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
hosts:
|
||||||
|
description: Hosts Domains/hosts based request routing
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
|
insecureSkipVerify:
|
||||||
|
type: boolean
|
||||||
|
interceptErrors:
|
||||||
|
description: InterceptErrors intercepts backend errors based
|
||||||
|
on the status codes
|
||||||
|
items:
|
||||||
|
type: integer
|
||||||
|
type: array
|
||||||
|
methods:
|
||||||
|
description: Methods allowed method
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
|
middlewares:
|
||||||
|
description: Middlewares Defines route middleware
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
|
name:
|
||||||
|
description: Name defines route name
|
||||||
|
type: string
|
||||||
|
path:
|
||||||
|
description: Path defines route path
|
||||||
|
type: string
|
||||||
|
rateLimit:
|
||||||
|
type: integer
|
||||||
|
rewrite:
|
||||||
|
description: Rewrite rewrites route path to desired path
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- name
|
||||||
|
- path
|
||||||
|
type: object
|
||||||
|
type: array
|
||||||
|
required:
|
||||||
|
- gateway
|
||||||
|
- routes
|
||||||
|
type: object
|
||||||
|
status:
|
||||||
|
description: RouteStatus defines the observed state of Route.
|
||||||
|
type: object
|
||||||
|
type: object
|
||||||
|
served: true
|
||||||
|
storage: true
|
||||||
|
subresources:
|
||||||
|
status: {}
|
||||||
22
config/crd/kustomization.yaml
Normal file
22
config/crd/kustomization.yaml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# This kustomization.yaml is not intended to be run by itself,
|
||||||
|
# since it depends on service name and namespace that are out of this kustomize package.
|
||||||
|
# It should be run by config/default
|
||||||
|
resources:
|
||||||
|
- bases/gomaproj.github.io_gateways.yaml
|
||||||
|
- bases/gomaproj.github.io_routes.yaml
|
||||||
|
- bases/gomaproj.github.io_middlewares.yaml
|
||||||
|
# +kubebuilder:scaffold:crdkustomizeresource
|
||||||
|
|
||||||
|
patches:
|
||||||
|
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
|
||||||
|
# patches here are for enabling the conversion webhook for each CRD
|
||||||
|
# +kubebuilder:scaffold:crdkustomizewebhookpatch
|
||||||
|
|
||||||
|
# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
|
||||||
|
# patches here are for enabling the CA injection for each CRD
|
||||||
|
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
|
||||||
|
|
||||||
|
# [WEBHOOK] To enable webhook, uncomment the following section
|
||||||
|
# the following config is for teaching kustomize how to do kustomization for CRDs.
|
||||||
|
#configurations:
|
||||||
|
#- kustomizeconfig.yaml
|
||||||
19
config/crd/kustomizeconfig.yaml
Normal file
19
config/crd/kustomizeconfig.yaml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# This file is for teaching kustomize how to substitute name and namespace reference in CRD
|
||||||
|
nameReference:
|
||||||
|
- kind: Service
|
||||||
|
version: v1
|
||||||
|
fieldSpecs:
|
||||||
|
- kind: CustomResourceDefinition
|
||||||
|
version: v1
|
||||||
|
group: apiextensions.k8s.io
|
||||||
|
path: spec/conversion/webhook/clientConfig/service/name
|
||||||
|
|
||||||
|
namespace:
|
||||||
|
- kind: CustomResourceDefinition
|
||||||
|
version: v1
|
||||||
|
group: apiextensions.k8s.io
|
||||||
|
path: spec/conversion/webhook/clientConfig/service/namespace
|
||||||
|
create: false
|
||||||
|
|
||||||
|
varReference:
|
||||||
|
- path: metadata/annotations
|
||||||
177
config/default/kustomization.yaml
Normal file
177
config/default/kustomization.yaml
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
# Adds namespace to all resources.
|
||||||
|
namespace: goma-operator-system
|
||||||
|
|
||||||
|
# Value of this field is prepended to the
|
||||||
|
# names of all resources, e.g. a deployment named
|
||||||
|
# "wordpress" becomes "alices-wordpress".
|
||||||
|
# Note that it should also match with the prefix (text before '-') of the namespace
|
||||||
|
# field above.
|
||||||
|
namePrefix: goma-operator-
|
||||||
|
|
||||||
|
# Labels to add to all resources and selectors.
|
||||||
|
#labels:
|
||||||
|
#- includeSelectors: true
|
||||||
|
# pairs:
|
||||||
|
# someName: someValue
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- ../crd
|
||||||
|
- ../rbac
|
||||||
|
- ../manager
|
||||||
|
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
|
||||||
|
# crd/kustomization.yaml
|
||||||
|
#- ../webhook
|
||||||
|
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
|
||||||
|
#- ../certmanager
|
||||||
|
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
|
||||||
|
#- ../prometheus
|
||||||
|
# [METRICS] Expose the controller manager metrics service.
|
||||||
|
- metrics_service.yaml
|
||||||
|
# [NETWORK POLICY] Protect the /metrics endpoint and Webhook Server with NetworkPolicy.
|
||||||
|
# Only Pod(s) running a namespace labeled with 'metrics: enabled' will be able to gather the metrics.
|
||||||
|
# Only CR(s) which requires webhooks and are applied on namespaces labeled with 'webhooks: enabled' will
|
||||||
|
# be able to communicate with the Webhook Server.
|
||||||
|
#- ../network-policy
|
||||||
|
|
||||||
|
# Uncomment the patches line if you enable Metrics, and/or are using webhooks and cert-manager
|
||||||
|
patches:
|
||||||
|
# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443.
|
||||||
|
# More info: https://book.kubebuilder.io/reference/metrics
|
||||||
|
- path: manager_metrics_patch.yaml
|
||||||
|
target:
|
||||||
|
kind: Deployment
|
||||||
|
|
||||||
|
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
|
||||||
|
# crd/kustomization.yaml
|
||||||
|
#- path: manager_webhook_patch.yaml
|
||||||
|
|
||||||
|
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
|
||||||
|
# Uncomment the following replacements to add the cert-manager CA injection annotations
|
||||||
|
#replacements:
|
||||||
|
# - source: # Uncomment the following block if you have any webhook
|
||||||
|
# kind: Service
|
||||||
|
# version: v1
|
||||||
|
# name: webhook-service
|
||||||
|
# fieldPath: .metadata.name # Name of the service
|
||||||
|
# targets:
|
||||||
|
# - select:
|
||||||
|
# kind: Certificate
|
||||||
|
# group: cert-manager.io
|
||||||
|
# version: v1
|
||||||
|
# fieldPaths:
|
||||||
|
# - .spec.dnsNames.0
|
||||||
|
# - .spec.dnsNames.1
|
||||||
|
# options:
|
||||||
|
# delimiter: '.'
|
||||||
|
# index: 0
|
||||||
|
# create: true
|
||||||
|
# - source:
|
||||||
|
# kind: Service
|
||||||
|
# version: v1
|
||||||
|
# name: webhook-service
|
||||||
|
# fieldPath: .metadata.namespace # Namespace of the service
|
||||||
|
# targets:
|
||||||
|
# - select:
|
||||||
|
# kind: Certificate
|
||||||
|
# group: cert-manager.io
|
||||||
|
# version: v1
|
||||||
|
# fieldPaths:
|
||||||
|
# - .spec.dnsNames.0
|
||||||
|
# - .spec.dnsNames.1
|
||||||
|
# options:
|
||||||
|
# delimiter: '.'
|
||||||
|
# index: 1
|
||||||
|
# create: true
|
||||||
|
#
|
||||||
|
# - source: # Uncomment the following block if you have a ValidatingWebhook (--programmatic-validation)
|
||||||
|
# kind: Certificate
|
||||||
|
# group: cert-manager.io
|
||||||
|
# version: v1
|
||||||
|
# name: serving-cert # This name should match the one in certificate.yaml
|
||||||
|
# fieldPath: .metadata.namespace # Namespace of the certificate CR
|
||||||
|
# targets:
|
||||||
|
# - select:
|
||||||
|
# kind: ValidatingWebhookConfiguration
|
||||||
|
# fieldPaths:
|
||||||
|
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
|
||||||
|
# options:
|
||||||
|
# delimiter: '/'
|
||||||
|
# index: 0
|
||||||
|
# create: true
|
||||||
|
# - source:
|
||||||
|
# kind: Certificate
|
||||||
|
# group: cert-manager.io
|
||||||
|
# version: v1
|
||||||
|
# name: serving-cert # This name should match the one in certificate.yaml
|
||||||
|
# fieldPath: .metadata.name
|
||||||
|
# targets:
|
||||||
|
# - select:
|
||||||
|
# kind: ValidatingWebhookConfiguration
|
||||||
|
# fieldPaths:
|
||||||
|
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
|
||||||
|
# options:
|
||||||
|
# delimiter: '/'
|
||||||
|
# index: 1
|
||||||
|
# create: true
|
||||||
|
#
|
||||||
|
# - source: # Uncomment the following block if you have a DefaultingWebhook (--defaulting )
|
||||||
|
# kind: Certificate
|
||||||
|
# group: cert-manager.io
|
||||||
|
# version: v1
|
||||||
|
# name: serving-cert # This name should match the one in certificate.yaml
|
||||||
|
# fieldPath: .metadata.namespace # Namespace of the certificate CR
|
||||||
|
# targets:
|
||||||
|
# - select:
|
||||||
|
# kind: MutatingWebhookConfiguration
|
||||||
|
# fieldPaths:
|
||||||
|
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
|
||||||
|
# options:
|
||||||
|
# delimiter: '/'
|
||||||
|
# index: 0
|
||||||
|
# create: true
|
||||||
|
# - source:
|
||||||
|
# kind: Certificate
|
||||||
|
# group: cert-manager.io
|
||||||
|
# version: v1
|
||||||
|
# name: serving-cert # This name should match the one in certificate.yaml
|
||||||
|
# fieldPath: .metadata.name
|
||||||
|
# targets:
|
||||||
|
# - select:
|
||||||
|
# kind: MutatingWebhookConfiguration
|
||||||
|
# fieldPaths:
|
||||||
|
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
|
||||||
|
# options:
|
||||||
|
# delimiter: '/'
|
||||||
|
# index: 1
|
||||||
|
# create: true
|
||||||
|
#
|
||||||
|
# - source: # Uncomment the following block if you have a ConversionWebhook (--conversion)
|
||||||
|
# kind: Certificate
|
||||||
|
# group: cert-manager.io
|
||||||
|
# version: v1
|
||||||
|
# name: serving-cert # This name should match the one in certificate.yaml
|
||||||
|
# fieldPath: .metadata.namespace # Namespace of the certificate CR
|
||||||
|
# targets:
|
||||||
|
# - select:
|
||||||
|
# kind: CustomResourceDefinition
|
||||||
|
# fieldPaths:
|
||||||
|
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
|
||||||
|
# options:
|
||||||
|
# delimiter: '/'
|
||||||
|
# index: 0
|
||||||
|
# create: true
|
||||||
|
# - source:
|
||||||
|
# kind: Certificate
|
||||||
|
# group: cert-manager.io
|
||||||
|
# version: v1
|
||||||
|
# name: serving-cert # This name should match the one in certificate.yaml
|
||||||
|
# fieldPath: .metadata.name
|
||||||
|
# targets:
|
||||||
|
# - select:
|
||||||
|
# kind: CustomResourceDefinition
|
||||||
|
# fieldPaths:
|
||||||
|
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
|
||||||
|
# options:
|
||||||
|
# delimiter: '/'
|
||||||
|
# index: 1
|
||||||
|
# create: true
|
||||||
4
config/default/manager_metrics_patch.yaml
Normal file
4
config/default/manager_metrics_patch.yaml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# This patch adds the args to allow exposing the metrics endpoint using HTTPS
|
||||||
|
- op: add
|
||||||
|
path: /spec/template/spec/containers/0/args/0
|
||||||
|
value: --metrics-bind-address=:8443
|
||||||
17
config/default/metrics_service.yaml
Normal file
17
config/default/metrics_service.yaml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
control-plane: controller-manager
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: controller-manager-metrics-service
|
||||||
|
namespace: system
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- name: https
|
||||||
|
port: 8443
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 8443
|
||||||
|
selector:
|
||||||
|
control-plane: controller-manager
|
||||||
8
config/manager/kustomization.yaml
Normal file
8
config/manager/kustomization.yaml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
resources:
|
||||||
|
- manager.yaml
|
||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
images:
|
||||||
|
- name: controller
|
||||||
|
newName: jkaninda/goma-operator
|
||||||
|
newTag: 0.1.0-rc.1
|
||||||
95
config/manager/manager.yaml
Normal file
95
config/manager/manager.yaml
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
control-plane: controller-manager
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: system
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: controller-manager
|
||||||
|
namespace: system
|
||||||
|
labels:
|
||||||
|
control-plane: controller-manager
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
control-plane: controller-manager
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
kubectl.kubernetes.io/default-container: manager
|
||||||
|
labels:
|
||||||
|
control-plane: controller-manager
|
||||||
|
spec:
|
||||||
|
# TODO(user): Uncomment the following code to configure the nodeAffinity expression
|
||||||
|
# according to the platforms which are supported by your solution.
|
||||||
|
# It is considered best practice to support multiple architectures. You can
|
||||||
|
# build your manager image using the makefile target docker-buildx.
|
||||||
|
# affinity:
|
||||||
|
# nodeAffinity:
|
||||||
|
# requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
# nodeSelectorTerms:
|
||||||
|
# - matchExpressions:
|
||||||
|
# - key: kubernetes.io/arch
|
||||||
|
# operator: In
|
||||||
|
# values:
|
||||||
|
# - amd64
|
||||||
|
# - arm64
|
||||||
|
# - ppc64le
|
||||||
|
# - s390x
|
||||||
|
# - key: kubernetes.io/os
|
||||||
|
# operator: In
|
||||||
|
# values:
|
||||||
|
# - linux
|
||||||
|
securityContext:
|
||||||
|
runAsNonRoot: true
|
||||||
|
# TODO(user): For common cases that do not require escalating privileges
|
||||||
|
# it is recommended to ensure that all your Pods/Containers are restrictive.
|
||||||
|
# More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
|
||||||
|
# Please uncomment the following code if your project does NOT have to work on old Kubernetes
|
||||||
|
# versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ).
|
||||||
|
# seccompProfile:
|
||||||
|
# type: RuntimeDefault
|
||||||
|
containers:
|
||||||
|
- command:
|
||||||
|
- /manager
|
||||||
|
args:
|
||||||
|
- --leader-elect
|
||||||
|
- --health-probe-bind-address=:8081
|
||||||
|
image: controller:latest
|
||||||
|
name: manager
|
||||||
|
securityContext:
|
||||||
|
allowPrivilegeEscalation: false
|
||||||
|
capabilities:
|
||||||
|
drop:
|
||||||
|
- "ALL"
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /healthz
|
||||||
|
port: 8081
|
||||||
|
initialDelaySeconds: 15
|
||||||
|
periodSeconds: 20
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /readyz
|
||||||
|
port: 8081
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
periodSeconds: 10
|
||||||
|
# TODO(user): Configure the resources accordingly based on the project requirements.
|
||||||
|
# More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpu: 500m
|
||||||
|
memory: 128Mi
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 64Mi
|
||||||
|
serviceAccountName: controller-manager
|
||||||
|
terminationGracePeriodSeconds: 10
|
||||||
26
config/network-policy/allow-metrics-traffic.yaml
Normal file
26
config/network-policy/allow-metrics-traffic.yaml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# This NetworkPolicy allows ingress traffic
|
||||||
|
# with Pods running on namespaces labeled with 'metrics: enabled'. Only Pods on those
|
||||||
|
# namespaces are able to gathering data from the metrics endpoint.
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: NetworkPolicy
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: allow-metrics-traffic
|
||||||
|
namespace: system
|
||||||
|
spec:
|
||||||
|
podSelector:
|
||||||
|
matchLabels:
|
||||||
|
control-plane: controller-manager
|
||||||
|
policyTypes:
|
||||||
|
- Ingress
|
||||||
|
ingress:
|
||||||
|
# This allows ingress traffic from any namespace with the label metrics: enabled
|
||||||
|
- from:
|
||||||
|
- namespaceSelector:
|
||||||
|
matchLabels:
|
||||||
|
metrics: enabled # Only from namespaces with this label
|
||||||
|
ports:
|
||||||
|
- port: 8443
|
||||||
|
protocol: TCP
|
||||||
2
config/network-policy/kustomization.yaml
Normal file
2
config/network-policy/kustomization.yaml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
resources:
|
||||||
|
- allow-metrics-traffic.yaml
|
||||||
2
config/prometheus/kustomization.yaml
Normal file
2
config/prometheus/kustomization.yaml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
resources:
|
||||||
|
- monitor.yaml
|
||||||
30
config/prometheus/monitor.yaml
Normal file
30
config/prometheus/monitor.yaml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# Prometheus Monitor Service (Metrics)
|
||||||
|
apiVersion: monitoring.coreos.com/v1
|
||||||
|
kind: ServiceMonitor
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
control-plane: controller-manager
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: controller-manager-metrics-monitor
|
||||||
|
namespace: system
|
||||||
|
spec:
|
||||||
|
endpoints:
|
||||||
|
- path: /metrics
|
||||||
|
port: https # Ensure this is the name of the port that exposes HTTPS metrics
|
||||||
|
scheme: https
|
||||||
|
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
|
||||||
|
tlsConfig:
|
||||||
|
# TODO(user): The option insecureSkipVerify: true is not recommended for production since it disables
|
||||||
|
# certificate verification. This poses a significant security risk by making the system vulnerable to
|
||||||
|
# man-in-the-middle attacks, where an attacker could intercept and manipulate the communication between
|
||||||
|
# Prometheus and the monitored services. This could lead to unauthorized access to sensitive metrics data,
|
||||||
|
# compromising the integrity and confidentiality of the information.
|
||||||
|
# Please use the following options for secure configurations:
|
||||||
|
# caFile: /etc/metrics-certs/ca.crt
|
||||||
|
# certFile: /etc/metrics-certs/tls.crt
|
||||||
|
# keyFile: /etc/metrics-certs/tls.key
|
||||||
|
insecureSkipVerify: true
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
control-plane: controller-manager
|
||||||
27
config/rbac/gateway_editor_role.yaml
Normal file
27
config/rbac/gateway_editor_role.yaml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# permissions for end users to edit gateways.
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: gateway-editor-role
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- gomaproj.github.io
|
||||||
|
resources:
|
||||||
|
- gateways
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- delete
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- gomaproj.github.io
|
||||||
|
resources:
|
||||||
|
- gateways/status
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
23
config/rbac/gateway_viewer_role.yaml
Normal file
23
config/rbac/gateway_viewer_role.yaml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# permissions for end users to view gateways.
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: gateway-viewer-role
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- gomaproj.github.io
|
||||||
|
resources:
|
||||||
|
- gateways
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- gomaproj.github.io
|
||||||
|
resources:
|
||||||
|
- gateways/status
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
31
config/rbac/kustomization.yaml
Normal file
31
config/rbac/kustomization.yaml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
resources:
|
||||||
|
# All RBAC will be applied under this service account in
|
||||||
|
# the deployment namespace. You may comment out this resource
|
||||||
|
# if your manager will use a service account that exists at
|
||||||
|
# runtime. Be sure to update RoleBinding and ClusterRoleBinding
|
||||||
|
# subjects if changing service account names.
|
||||||
|
- service_account.yaml
|
||||||
|
- role.yaml
|
||||||
|
- role_binding.yaml
|
||||||
|
- leader_election_role.yaml
|
||||||
|
- leader_election_role_binding.yaml
|
||||||
|
# The following RBAC configurations are used to protect
|
||||||
|
# the metrics endpoint with authn/authz. These configurations
|
||||||
|
# ensure that only authorized users and service accounts
|
||||||
|
# can access the metrics endpoint. Comment the following
|
||||||
|
# permissions if you want to disable this protection.
|
||||||
|
# More info: https://book.kubebuilder.io/reference/metrics.html
|
||||||
|
- metrics_auth_role.yaml
|
||||||
|
- metrics_auth_role_binding.yaml
|
||||||
|
- metrics_reader_role.yaml
|
||||||
|
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
|
||||||
|
# default, aiding admins in cluster management. Those roles are
|
||||||
|
# not used by the Project itself. You can comment the following lines
|
||||||
|
# if you do not want those helpers be installed with your Project.
|
||||||
|
- middleware_editor_role.yaml
|
||||||
|
- middleware_viewer_role.yaml
|
||||||
|
- route_editor_role.yaml
|
||||||
|
- route_viewer_role.yaml
|
||||||
|
- gateway_editor_role.yaml
|
||||||
|
- gateway_viewer_role.yaml
|
||||||
|
|
||||||
40
config/rbac/leader_election_role.yaml
Normal file
40
config/rbac/leader_election_role.yaml
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# permissions to do leader election.
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: Role
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: leader-election-role
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- configmaps
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- watch
|
||||||
|
- create
|
||||||
|
- update
|
||||||
|
- patch
|
||||||
|
- delete
|
||||||
|
- apiGroups:
|
||||||
|
- coordination.k8s.io
|
||||||
|
resources:
|
||||||
|
- leases
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- watch
|
||||||
|
- create
|
||||||
|
- update
|
||||||
|
- patch
|
||||||
|
- delete
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- events
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- patch
|
||||||
15
config/rbac/leader_election_role_binding.yaml
Normal file
15
config/rbac/leader_election_role_binding.yaml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: RoleBinding
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: leader-election-rolebinding
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: Role
|
||||||
|
name: leader-election-role
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: controller-manager
|
||||||
|
namespace: system
|
||||||
17
config/rbac/metrics_auth_role.yaml
Normal file
17
config/rbac/metrics_auth_role.yaml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
name: metrics-auth-role
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- authentication.k8s.io
|
||||||
|
resources:
|
||||||
|
- tokenreviews
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- apiGroups:
|
||||||
|
- authorization.k8s.io
|
||||||
|
resources:
|
||||||
|
- subjectaccessreviews
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
12
config/rbac/metrics_auth_role_binding.yaml
Normal file
12
config/rbac/metrics_auth_role_binding.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
name: metrics-auth-rolebinding
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: metrics-auth-role
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: controller-manager
|
||||||
|
namespace: system
|
||||||
9
config/rbac/metrics_reader_role.yaml
Normal file
9
config/rbac/metrics_reader_role.yaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
name: metrics-reader
|
||||||
|
rules:
|
||||||
|
- nonResourceURLs:
|
||||||
|
- "/metrics"
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
27
config/rbac/middleware_editor_role.yaml
Normal file
27
config/rbac/middleware_editor_role.yaml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# permissions for end users to edit middlewares.
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: middleware-editor-role
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- gomaproj.github.io
|
||||||
|
resources:
|
||||||
|
- middlewares
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- delete
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- gomaproj.github.io
|
||||||
|
resources:
|
||||||
|
- middlewares/status
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
23
config/rbac/middleware_viewer_role.yaml
Normal file
23
config/rbac/middleware_viewer_role.yaml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# permissions for end users to view middlewares.
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: middleware-viewer-role
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- gomaproj.github.io
|
||||||
|
resources:
|
||||||
|
- middlewares
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- gomaproj.github.io
|
||||||
|
resources:
|
||||||
|
- middlewares/status
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
83
config/rbac/role.yaml
Normal file
83
config/rbac/role.yaml
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
name: manager-role
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- configmaps
|
||||||
|
- services
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- delete
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- events
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- apiGroups:
|
||||||
|
- apps
|
||||||
|
resources:
|
||||||
|
- deployments
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- delete
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- autoscaling
|
||||||
|
resources:
|
||||||
|
- horizontalpodautoscalers
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- delete
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- gomaproj.github.io
|
||||||
|
resources:
|
||||||
|
- gateways
|
||||||
|
- middlewares
|
||||||
|
- routes
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- delete
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- gomaproj.github.io
|
||||||
|
resources:
|
||||||
|
- gateways/finalizers
|
||||||
|
- middlewares/finalizers
|
||||||
|
- routes/finalizers
|
||||||
|
verbs:
|
||||||
|
- update
|
||||||
|
- apiGroups:
|
||||||
|
- gomaproj.github.io
|
||||||
|
resources:
|
||||||
|
- gateways/status
|
||||||
|
- middlewares/status
|
||||||
|
- routes/status
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
15
config/rbac/role_binding.yaml
Normal file
15
config/rbac/role_binding.yaml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: manager-rolebinding
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: manager-role
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: controller-manager
|
||||||
|
namespace: system
|
||||||
27
config/rbac/route_editor_role.yaml
Normal file
27
config/rbac/route_editor_role.yaml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# permissions for end users to edit routes.
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: route-editor-role
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- gomaproj.github.io
|
||||||
|
resources:
|
||||||
|
- routes
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- delete
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- gomaproj.github.io
|
||||||
|
resources:
|
||||||
|
- routes/status
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
23
config/rbac/route_viewer_role.yaml
Normal file
23
config/rbac/route_viewer_role.yaml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# permissions for end users to view routes.
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: route-viewer-role
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- gomaproj.github.io
|
||||||
|
resources:
|
||||||
|
- routes
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- gomaproj.github.io
|
||||||
|
resources:
|
||||||
|
- routes/status
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
8
config/rbac/service_account.yaml
Normal file
8
config/rbac/service_account.yaml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: controller-manager
|
||||||
|
namespace: system
|
||||||
30
config/samples/gomaproj_v1beta1_gateway.yaml
Normal file
30
config/samples/gomaproj_v1beta1_gateway.yaml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
apiVersion: gomaproj.github.io/v1beta1
|
||||||
|
kind: Gateway
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: gateway-sample
|
||||||
|
spec:
|
||||||
|
gatewayVersion: latest
|
||||||
|
server:
|
||||||
|
writeTimeout: 10
|
||||||
|
readTimeout: 15
|
||||||
|
idleTimeout: 30
|
||||||
|
logLevel: info
|
||||||
|
disableHealthCheckStatus: false
|
||||||
|
disableKeepAlive: false
|
||||||
|
enableMetrics: true
|
||||||
|
replicaCount: 1
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 128Mi
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 128Mi
|
||||||
|
autoScaling:
|
||||||
|
enabled: true
|
||||||
|
minReplicas: 2
|
||||||
|
maxReplicas: 5
|
||||||
|
targetCPUUtilizationPercentage: 80
|
||||||
14
config/samples/gomaproj_v1beta1_middleware.yaml
Normal file
14
config/samples/gomaproj_v1beta1_middleware.yaml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
apiVersion: gomaproj.github.io/v1beta1
|
||||||
|
kind: Middleware
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: middleware-sample
|
||||||
|
spec:
|
||||||
|
type: basic
|
||||||
|
paths:
|
||||||
|
- /*
|
||||||
|
rule:
|
||||||
|
username: admin
|
||||||
|
password: admin
|
||||||
35
config/samples/gomaproj_v1beta1_route.yaml
Normal file
35
config/samples/gomaproj_v1beta1_route.yaml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
apiVersion: gomaproj.github.io/v1beta1
|
||||||
|
kind: Route
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: goma-operator
|
||||||
|
app.kubernetes.io/managed-by: kustomize
|
||||||
|
name: route-sample
|
||||||
|
spec:
|
||||||
|
gateway: gateway-sample
|
||||||
|
routes:
|
||||||
|
- path: /
|
||||||
|
name: Example
|
||||||
|
hosts: []
|
||||||
|
rewrite: /
|
||||||
|
methods:
|
||||||
|
- GET
|
||||||
|
destination: https://example.com
|
||||||
|
backends: []
|
||||||
|
insecureSkipVerify: false
|
||||||
|
healthCheck:
|
||||||
|
path: /
|
||||||
|
interval: 10s
|
||||||
|
timeout: 10s
|
||||||
|
healthyStatuses:
|
||||||
|
- 200
|
||||||
|
- 404
|
||||||
|
cors:
|
||||||
|
origins: []
|
||||||
|
headers: {}
|
||||||
|
rateLimit: 15
|
||||||
|
disableHostFording: true
|
||||||
|
interceptErrors: []
|
||||||
|
blockCommonExploits: false
|
||||||
|
middlewares:
|
||||||
|
- middleware-sample
|
||||||
6
config/samples/kustomization.yaml
Normal file
6
config/samples/kustomization.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
## Append samples of your project ##
|
||||||
|
resources:
|
||||||
|
- gomaproj_v1beta1_gateway.yaml
|
||||||
|
- gomaproj_v1beta1_route.yaml
|
||||||
|
- gomaproj_v1beta1_middleware.yaml
|
||||||
|
# +kubebuilder:scaffold:manifestskustomizesamples
|
||||||
1808
dist/install.yaml
vendored
Normal file
1808
dist/install.yaml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
98
go.mod
Normal file
98
go.mod
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
module github.com/jkaninda/goma-operator
|
||||||
|
|
||||||
|
go 1.22.0
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/onsi/ginkgo/v2 v2.19.0
|
||||||
|
github.com/onsi/gomega v1.33.1
|
||||||
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
|
k8s.io/api v0.31.0
|
||||||
|
k8s.io/apimachinery v0.31.0
|
||||||
|
k8s.io/client-go v0.31.0
|
||||||
|
sigs.k8s.io/controller-runtime v0.19.1
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
|
||||||
|
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
|
||||||
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
|
github.com/blang/semver/v4 v4.0.0 // indirect
|
||||||
|
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||||
|
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
|
||||||
|
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
|
||||||
|
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||||
|
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
|
||||||
|
github.com/go-logr/logr v1.4.2 // indirect
|
||||||
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
|
github.com/go-logr/zapr v1.3.0 // indirect
|
||||||
|
github.com/go-openapi/jsonpointer v0.19.6 // indirect
|
||||||
|
github.com/go-openapi/jsonreference v0.20.2 // indirect
|
||||||
|
github.com/go-openapi/swag v0.22.4 // indirect
|
||||||
|
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
|
||||||
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
|
github.com/golang/protobuf v1.5.4 // indirect
|
||||||
|
github.com/google/cel-go v0.20.1 // indirect
|
||||||
|
github.com/google/gnostic-models v0.6.8 // indirect
|
||||||
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
|
github.com/google/gofuzz v1.2.0 // indirect
|
||||||
|
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af // indirect
|
||||||
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
|
||||||
|
github.com/imdario/mergo v0.3.6 // indirect
|
||||||
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/prometheus/client_golang v1.19.1 // indirect
|
||||||
|
github.com/prometheus/client_model v0.6.1 // indirect
|
||||||
|
github.com/prometheus/common v0.55.0 // indirect
|
||||||
|
github.com/prometheus/procfs v0.15.1 // indirect
|
||||||
|
github.com/spf13/cobra v1.8.1 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
github.com/stoewer/go-strcase v1.2.0 // indirect
|
||||||
|
github.com/x448/float16 v0.8.4 // indirect
|
||||||
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
|
||||||
|
go.opentelemetry.io/otel v1.28.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/metric v1.28.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/sdk v1.28.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/trace v1.28.0 // indirect
|
||||||
|
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
|
||||||
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
|
go.uber.org/zap v1.26.0 // indirect
|
||||||
|
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
|
||||||
|
golang.org/x/net v0.26.0 // indirect
|
||||||
|
golang.org/x/oauth2 v0.21.0 // indirect
|
||||||
|
golang.org/x/sync v0.7.0 // indirect
|
||||||
|
golang.org/x/sys v0.21.0 // indirect
|
||||||
|
golang.org/x/term v0.21.0 // indirect
|
||||||
|
golang.org/x/text v0.16.0 // indirect
|
||||||
|
golang.org/x/time v0.3.0 // indirect
|
||||||
|
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
|
||||||
|
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
|
||||||
|
google.golang.org/grpc v1.65.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.34.2 // indirect
|
||||||
|
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
k8s.io/apiextensions-apiserver v0.31.0 // indirect
|
||||||
|
k8s.io/apiserver v0.31.0 // indirect
|
||||||
|
k8s.io/component-base v0.31.0 // indirect
|
||||||
|
k8s.io/klog/v2 v2.130.1 // indirect
|
||||||
|
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
|
||||||
|
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
|
||||||
|
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // indirect
|
||||||
|
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
|
||||||
|
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
|
||||||
|
sigs.k8s.io/yaml v1.4.0 // indirect
|
||||||
|
)
|
||||||
251
go.sum
Normal file
251
go.sum
Normal file
@@ -0,0 +1,251 @@
|
|||||||
|
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
|
||||||
|
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
|
||||||
|
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
|
||||||
|
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
||||||
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
|
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
|
||||||
|
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
|
||||||
|
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||||
|
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||||
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
|
||||||
|
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
|
||||||
|
github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8P3k=
|
||||||
|
github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ=
|
||||||
|
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
|
||||||
|
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
|
||||||
|
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||||
|
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||||
|
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
|
||||||
|
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
|
||||||
|
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
|
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||||
|
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
|
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||||
|
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||||
|
github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ=
|
||||||
|
github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg=
|
||||||
|
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
|
||||||
|
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
|
||||||
|
github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE=
|
||||||
|
github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
|
||||||
|
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
||||||
|
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
|
||||||
|
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
||||||
|
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
|
||||||
|
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
|
||||||
|
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||||
|
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||||
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
|
||||||
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||||
|
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||||
|
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||||
|
github.com/google/cel-go v0.20.1 h1:nDx9r8S3L4pE61eDdt8igGj8rf5kjYR3ILxWIpWNi84=
|
||||||
|
github.com/google/cel-go v0.20.1/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg=
|
||||||
|
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
||||||
|
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
||||||
|
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||||
|
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af h1:kmjWCqn2qkEml422C2Rrd27c3VGxi6a/6HNq8QmHRKM=
|
||||||
|
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo=
|
||||||
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
|
||||||
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
|
||||||
|
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
|
||||||
|
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||||
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
|
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||||
|
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||||
|
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||||
|
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
|
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
|
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||||
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
|
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||||
|
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||||
|
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||||
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||||
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||||
|
github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA=
|
||||||
|
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
|
||||||
|
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
|
||||||
|
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
|
||||||
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||||
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
|
||||||
|
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
|
||||||
|
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
||||||
|
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
||||||
|
github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc=
|
||||||
|
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
|
||||||
|
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
||||||
|
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
||||||
|
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
|
||||||
|
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
|
||||||
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
|
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
|
||||||
|
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
|
||||||
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
|
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
|
github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU=
|
||||||
|
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
||||||
|
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
|
||||||
|
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 h1:4K4tsIXefpVJtvA/8srF4V4y0akAoPHkIslgAkjixJA=
|
||||||
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0/go.mod h1:jjdQuTGVsXV4vSs+CJ2qYDeDPf9yIJV23qlIzBm73Vg=
|
||||||
|
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
|
||||||
|
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
|
||||||
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 h1:3Q/xZUyC1BBkualc9ROb4G8qkH90LXEIICcs5zv1OYY=
|
||||||
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0/go.mod h1:s75jGIWA9OfCMzF0xr+ZgfrB5FEbbV7UuYo32ahUiFI=
|
||||||
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 h1:qFffATk0X+HD+f1Z8lswGiOQYKHRlzfmdJm0wEaVrFA=
|
||||||
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0/go.mod h1:MOiCmryaYtc+V0Ei+Tx9o5S1ZjA7kzLucuVuyzBZloQ=
|
||||||
|
go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q=
|
||||||
|
go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s=
|
||||||
|
go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE=
|
||||||
|
go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg=
|
||||||
|
go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g=
|
||||||
|
go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
|
||||||
|
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
|
||||||
|
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
|
||||||
|
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||||
|
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||||
|
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||||
|
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||||
|
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
|
||||||
|
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6Rrf6TF9htwo2pJVSjIU=
|
||||||
|
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
|
||||||
|
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||||
|
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
|
||||||
|
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
|
||||||
|
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
|
||||||
|
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||||
|
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
|
||||||
|
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA=
|
||||||
|
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||||
|
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||||
|
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
|
||||||
|
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||||
|
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
|
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
||||||
|
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw=
|
||||||
|
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
|
||||||
|
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 h1:7whR9kGa5LUwFtpLm2ArCEejtnxlGeLbAyjFY8sGNFw=
|
||||||
|
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157/go.mod h1:99sLkeliLXfdj2J75X3Ho+rrVCaJze0uwN7zDDkjPVU=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:BwIjyKYGsK9dMCBOorzRri8MQwmi7mT9rGHsCEinZkA=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
|
||||||
|
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
|
||||||
|
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
|
||||||
|
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
|
||||||
|
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
|
gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4=
|
||||||
|
gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M=
|
||||||
|
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
|
||||||
|
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
k8s.io/api v0.31.0 h1:b9LiSjR2ym/SzTOlfMHm1tr7/21aD7fSkqgD/CVJBCo=
|
||||||
|
k8s.io/api v0.31.0/go.mod h1:0YiFF+JfFxMM6+1hQei8FY8M7s1Mth+z/q7eF1aJkTE=
|
||||||
|
k8s.io/apiextensions-apiserver v0.31.0 h1:fZgCVhGwsclj3qCw1buVXCV6khjRzKC5eCFt24kyLSk=
|
||||||
|
k8s.io/apiextensions-apiserver v0.31.0/go.mod h1:b9aMDEYaEe5sdK+1T0KU78ApR/5ZVp4i56VacZYEHxk=
|
||||||
|
k8s.io/apimachinery v0.31.0 h1:m9jOiSr3FoSSL5WO9bjm1n6B9KROYYgNZOb4tyZ1lBc=
|
||||||
|
k8s.io/apimachinery v0.31.0/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
|
||||||
|
k8s.io/apiserver v0.31.0 h1:p+2dgJjy+bk+B1Csz+mc2wl5gHwvNkC9QJV+w55LVrY=
|
||||||
|
k8s.io/apiserver v0.31.0/go.mod h1:KI9ox5Yu902iBnnyMmy7ajonhKnkeZYJhTZ/YI+WEMk=
|
||||||
|
k8s.io/client-go v0.31.0 h1:QqEJzNjbN2Yv1H79SsS+SWnXkBgVu4Pj3CJQgbx0gI8=
|
||||||
|
k8s.io/client-go v0.31.0/go.mod h1:Y9wvC76g4fLjmU0BA+rV+h2cncoadjvjjkkIGoTLcGU=
|
||||||
|
k8s.io/component-base v0.31.0 h1:/KIzGM5EvPNQcYgwq5NwoQBaOlVFrghoVGr8lG6vNRs=
|
||||||
|
k8s.io/component-base v0.31.0/go.mod h1:TYVuzI1QmN4L5ItVdMSXKvH7/DtvIuas5/mm8YT3rTo=
|
||||||
|
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
|
||||||
|
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
|
||||||
|
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
|
||||||
|
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98=
|
||||||
|
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A=
|
||||||
|
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
|
||||||
|
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 h1:2770sDpzrjjsAtVhSeUFseziht227YAWYHLGNM8QPwY=
|
||||||
|
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw=
|
||||||
|
sigs.k8s.io/controller-runtime v0.19.1 h1:Son+Q40+Be3QWb+niBXAg2vFiYWolDjjRfO8hn/cxOk=
|
||||||
|
sigs.k8s.io/controller-runtime v0.19.1/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4=
|
||||||
|
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
|
||||||
|
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
|
||||||
|
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
|
||||||
|
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
|
||||||
|
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
|
||||||
|
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
|
||||||
15
hack/boilerplate.go.txt
Normal file
15
hack/boilerplate.go.txt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
222
internal/controller/deployment.go
Normal file
222
internal/controller/deployment.go
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
gomaprojv1beta1 "github.com/jkaninda/goma-operator/api/v1beta1"
|
||||||
|
v1 "k8s.io/api/apps/v1"
|
||||||
|
av1 "k8s.io/api/autoscaling/v1"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// createDeployment creates Kubernetes deployment
|
||||||
|
func createDeployment(r GatewayReconciler, ctx context.Context, req ctrl.Request, gateway gomaprojv1beta1.Gateway, imageName string) error {
|
||||||
|
logger := log.FromContext(ctx)
|
||||||
|
// Define the desired Deployment
|
||||||
|
deployment := &v1.Deployment{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: req.Name,
|
||||||
|
Namespace: req.Namespace,
|
||||||
|
Labels: gateway.Labels,
|
||||||
|
},
|
||||||
|
Spec: v1.DeploymentSpec{
|
||||||
|
Replicas: int32Ptr(gateway.Spec.ReplicaCount), // Set desired replicas
|
||||||
|
Selector: &metav1.LabelSelector{
|
||||||
|
MatchLabels: map[string]string{
|
||||||
|
"app": req.Name,
|
||||||
|
"belongs-to": BelongsTo,
|
||||||
|
"managed-by": gateway.Name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Template: corev1.PodTemplateSpec{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Labels: map[string]string{
|
||||||
|
"app": req.Name,
|
||||||
|
"belongs-to": BelongsTo,
|
||||||
|
"managed-by": gateway.Name,
|
||||||
|
},
|
||||||
|
Annotations: map[string]string{
|
||||||
|
"updated-at": time.Now().Format(time.RFC3339),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Spec: corev1.PodSpec{
|
||||||
|
Affinity: gateway.Spec.Affinity,
|
||||||
|
Containers: []corev1.Container{
|
||||||
|
{
|
||||||
|
Name: "gateway",
|
||||||
|
Image: imageName,
|
||||||
|
ImagePullPolicy: corev1.PullIfNotPresent,
|
||||||
|
Command: []string{"/usr/local/bin/goma", "server"},
|
||||||
|
Ports: []corev1.ContainerPort{
|
||||||
|
{
|
||||||
|
ContainerPort: 8080,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ReadinessProbe: &corev1.Probe{
|
||||||
|
InitialDelaySeconds: 5,
|
||||||
|
PeriodSeconds: 10,
|
||||||
|
ProbeHandler: corev1.ProbeHandler{
|
||||||
|
HTTPGet: &corev1.HTTPGetAction{
|
||||||
|
Path: "/readyz",
|
||||||
|
Port: intstr.FromInt32(8080),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
LivenessProbe: &corev1.Probe{
|
||||||
|
InitialDelaySeconds: 15,
|
||||||
|
PeriodSeconds: 30,
|
||||||
|
ProbeHandler: corev1.ProbeHandler{
|
||||||
|
HTTPGet: &corev1.HTTPGetAction{
|
||||||
|
Path: "/healthz",
|
||||||
|
Port: intstr.FromInt32(8080),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Resources: gateway.Spec.Resources,
|
||||||
|
VolumeMounts: []corev1.VolumeMount{
|
||||||
|
{
|
||||||
|
Name: "config",
|
||||||
|
MountPath: "/etc/goma",
|
||||||
|
ReadOnly: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Volumes: []corev1.Volume{
|
||||||
|
{
|
||||||
|
Name: "config",
|
||||||
|
VolumeSource: corev1.VolumeSource{
|
||||||
|
ConfigMap: &corev1.ConfigMapVolumeSource{
|
||||||
|
LocalObjectReference: corev1.LocalObjectReference{
|
||||||
|
Name: req.Name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the Deployment already exists
|
||||||
|
var existingDeployment v1.Deployment
|
||||||
|
err := r.Get(ctx, types.NamespacedName{Name: deployment.Name, Namespace: deployment.Namespace}, &existingDeployment)
|
||||||
|
if err != nil && client.IgnoreNotFound(err) != nil {
|
||||||
|
logger.Error(err, "Failed to get Deployment")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err != nil && client.IgnoreNotFound(err) == nil {
|
||||||
|
logger.Info("Creating a new Deployment")
|
||||||
|
// Create the Deployment if it doesn't exist
|
||||||
|
if err = controllerutil.SetControllerReference(&gateway, deployment, r.Scheme); err != nil {
|
||||||
|
logger.Error(err, "Failed to set controller reference")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = r.Create(ctx, deployment); err != nil {
|
||||||
|
logger.Error(err, "Failed to create Deployment")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Info("Created Deployment", "Deployment.Name", deployment.Name)
|
||||||
|
} else {
|
||||||
|
logger.Info("Deployment already exists", "Deployment.Name", deployment.Name)
|
||||||
|
// Update the Deployment if the spec has changed
|
||||||
|
if !equalDeploymentSpec(existingDeployment.Spec, deployment.Spec, gateway.Spec.AutoScaling.Enabled) {
|
||||||
|
logger.Info("Updating Deployment", "Deployment.Name", deployment.Name)
|
||||||
|
existingDeployment.Spec = deployment.Spec
|
||||||
|
if err = r.Update(ctx, &existingDeployment); err != nil {
|
||||||
|
logger.Error(err, "Failed to update Deployment")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Info("Updated Deployment", "Deployment.Name", deployment.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if hpa is enabled
|
||||||
|
if gateway.Spec.AutoScaling.Enabled {
|
||||||
|
err = createHpa(r, ctx, req, &gateway)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err, "Failed to create HorizontalPodAutoscaler")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Check if the hpa already exists
|
||||||
|
var existHpa av1.HorizontalPodAutoscaler
|
||||||
|
err = r.Get(ctx, types.NamespacedName{Name: req.Name, Namespace: req.Namespace}, &existHpa)
|
||||||
|
if err != nil && client.IgnoreNotFound(err) != nil {
|
||||||
|
logger.Error(err, "Failed to get HorizontalPodAutoscaler")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
// Delete the HorizontalPodAutoscaler
|
||||||
|
if err = r.Delete(ctx, &existHpa); err != nil {
|
||||||
|
logger.Error(err, "Failed to delete HorizontalPodAutoscaler")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Info("Deleted HorizontalPodAutoscaler successfully", "HorizontalPodAutoscaler.Name", req.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to compare Deployment specs
|
||||||
|
func equalDeploymentSpec(existing, desired v1.DeploymentSpec, autoScalingEnabled bool) bool {
|
||||||
|
if existing.Template.Spec.Containers[0].Image != desired.Template.Spec.Containers[0].Image {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if !autoScalingEnabled {
|
||||||
|
if existing.Replicas == nil || *existing.Replicas != *desired.Replicas {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
func (r *RouteReconciler) RestartDeployment(ctx context.Context, req ctrl.Request, gateway gomaprojv1beta1.Gateway) error {
|
||||||
|
logger := log.FromContext(ctx)
|
||||||
|
// Fetch the Deployment
|
||||||
|
var deployment v1.Deployment
|
||||||
|
if err := r.Get(ctx, types.NamespacedName{Name: gateway.Name, Namespace: req.Namespace}, &deployment); err != nil {
|
||||||
|
logger.Error(err, "Failed to get Deployment", "name", gateway.Name, "namespace", req.Name)
|
||||||
|
return client.IgnoreNotFound(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add or update an annotation to trigger a rolling update
|
||||||
|
if deployment.Spec.Template.ObjectMeta.Annotations == nil {
|
||||||
|
deployment.Spec.Template.ObjectMeta.Annotations = make(map[string]string)
|
||||||
|
}
|
||||||
|
|
||||||
|
deployment.Spec.Template.ObjectMeta.Annotations["restarted-at"] = time.Now().Format(time.RFC3339)
|
||||||
|
deployment.Spec.Template.ObjectMeta.Annotations["updated-at"] = time.Now().Format(time.RFC3339)
|
||||||
|
// Update the Deployment
|
||||||
|
if err := r.Update(ctx, &deployment); err != nil {
|
||||||
|
logger.Error(err, "Failed to update Deployment for restart", "name", gateway.Name, "namespace", req.Name)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Info("Successfully restarted Deployment", "name", gateway.Name, "namespace", req.Name)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// currentReplicas returns current replicas
|
||||||
|
func currentReplicas(ctx context.Context, c client.Client, hpaName, namespace string) (int32, error) {
|
||||||
|
hpa := &av1.HorizontalPodAutoscaler{}
|
||||||
|
// Retrieve the HPA resource
|
||||||
|
err := c.Get(ctx, types.NamespacedName{Name: hpaName, Namespace: namespace}, hpa)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("failed to get HPA: %w", err)
|
||||||
|
}
|
||||||
|
// Access the current replicas in the status field
|
||||||
|
replicas := hpa.Status.CurrentReplicas
|
||||||
|
return replicas, nil
|
||||||
|
}
|
||||||
305
internal/controller/gateway_controller.go
Normal file
305
internal/controller/gateway_controller.go
Normal file
@@ -0,0 +1,305 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
v1 "k8s.io/api/apps/v1"
|
||||||
|
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
gomaprojv1beta1 "github.com/jkaninda/goma-operator/api/v1beta1"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GatewayReconciler reconciles a Gateway object
|
||||||
|
type GatewayReconciler struct {
|
||||||
|
client.Client
|
||||||
|
Scheme *runtime.Scheme
|
||||||
|
}
|
||||||
|
|
||||||
|
// +kubebuilder:rbac:groups=gomaproj.github.io,resources=gateways,verbs=get;list;watch;create;update;patch;delete
|
||||||
|
// +kubebuilder:rbac:groups=gomaproj.github.io,resources=gateways/status,verbs=get;update;patch
|
||||||
|
// +kubebuilder:rbac:groups=gomaproj.github.io,resources=gateways/finalizers,verbs=update
|
||||||
|
// +kubebuilder:rbac:groups=gomaproj.github.io,resources=middlewares,verbs=get;list;watch;create;update;patch;delete
|
||||||
|
// +kubebuilder:rbac:groups=gomaproj.github.io,resources=middlewares/status,verbs=get;update;patch
|
||||||
|
// +kubebuilder:rbac:groups=gomaproj.github.io,resources=middlewares/finalizers,verbs=update
|
||||||
|
// +kubebuilder:rbac:groups="",resources=configmaps,verbs=get;list;watch;create;update;patch;delete
|
||||||
|
// +kubebuilder:rbac:groups="",resources=events,verbs=create;update;patch;
|
||||||
|
// +kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch;create;update;patch;delete
|
||||||
|
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete
|
||||||
|
// +kubebuilder:rbac:groups=autoscaling,resources=horizontalpodautoscalers,verbs=get;list;watch;create;update;patch;delete
|
||||||
|
|
||||||
|
// Reconcile is part of the main kubernetes reconciliation loop which aims to
|
||||||
|
// move the current state of the cluster closer to the desired state.
|
||||||
|
// the Gateway object against the actual cluster state, and then
|
||||||
|
// perform operations to make the cluster state reflect the state specified by
|
||||||
|
// the user.
|
||||||
|
//
|
||||||
|
// For more details, check Reconcile and its Result here:
|
||||||
|
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.1/pkg/reconcile
|
||||||
|
func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
||||||
|
logger := log.FromContext(ctx)
|
||||||
|
imageName := AppImageName
|
||||||
|
// Fetch the custom resource
|
||||||
|
gateway := &gomaprojv1beta1.Gateway{}
|
||||||
|
if err := r.Get(ctx, req.NamespacedName, gateway); err != nil {
|
||||||
|
logger.Error(err, "Unable to fetch Gateway")
|
||||||
|
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the object is being deleted and if so, handle it
|
||||||
|
if gateway.ObjectMeta.DeletionTimestamp.IsZero() {
|
||||||
|
if !controllerutil.ContainsFinalizer(gateway, FinalizerName) {
|
||||||
|
controllerutil.AddFinalizer(gateway, FinalizerName)
|
||||||
|
err := r.Update(ctx, gateway)
|
||||||
|
if err != nil {
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if controllerutil.ContainsFinalizer(gateway, FinalizerName) {
|
||||||
|
// Once finalization is done, remove the finalizer
|
||||||
|
if err := r.finalize(ctx, gateway); err != nil {
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
controllerutil.RemoveFinalizer(gateway, FinalizerName)
|
||||||
|
err := r.Update(ctx, gateway)
|
||||||
|
if err != nil {
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ctrl.Result{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if gateway.Spec.GatewayVersion != "" {
|
||||||
|
imageName = fmt.Sprintf("%s:%s", AppImageName, gateway.Spec.GatewayVersion)
|
||||||
|
}
|
||||||
|
if gateway.Spec.ReplicaCount != 0 {
|
||||||
|
ReplicaCount = gateway.Spec.ReplicaCount
|
||||||
|
}
|
||||||
|
gomaConfig := gatewayConfig(*r, ctx, req, gateway)
|
||||||
|
yamlContent, err := yaml.Marshal(&gomaConfig)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err, "Unable to marshal YAML")
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
// Define the desired ConfigMap
|
||||||
|
configMap := &corev1.ConfigMap{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: req.Name,
|
||||||
|
Namespace: req.Namespace,
|
||||||
|
Labels: map[string]string{
|
||||||
|
"belongs-to": BelongsTo,
|
||||||
|
"gateway": gateway.Name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
Data: map[string]string{
|
||||||
|
ConfigName: strings.TrimSpace(string(yamlContent)),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// Check if the ConfigMap already exists
|
||||||
|
var existingConfigMap corev1.ConfigMap
|
||||||
|
err = r.Get(ctx, types.NamespacedName{Name: configMap.Name, Namespace: configMap.Namespace}, &existingConfigMap)
|
||||||
|
if err != nil && client.IgnoreNotFound(err) != nil {
|
||||||
|
logger.Error(err, "Failed to get ConfigMap")
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil && client.IgnoreNotFound(err) == nil {
|
||||||
|
// Create the ConfigMap if it doesn't exist
|
||||||
|
if err := controllerutil.SetControllerReference(gateway, configMap, r.Scheme); err != nil {
|
||||||
|
logger.Error(err, "Failed to set controller reference")
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
if err := r.Create(ctx, configMap); err != nil {
|
||||||
|
addCondition(&gateway.Status, "ConfigMapNotReady", metav1.ConditionFalse, "ConfigMapNotReady", "Failed to add configMap for Gateway")
|
||||||
|
logger.Error(err, "Failed to create ConfigMap")
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
logger.Info("Created ConfigMap", "ConfigMap.Name", configMap.Name)
|
||||||
|
} else {
|
||||||
|
// Optional: Update the ConfigMap if needed
|
||||||
|
if !equalConfigMapData(existingConfigMap.Data, configMap.Data) {
|
||||||
|
existingConfigMap.Data = configMap.Data
|
||||||
|
if err := r.Update(ctx, &existingConfigMap); err != nil {
|
||||||
|
logger.Error(err, "Failed to update ConfigMap")
|
||||||
|
addCondition(&gateway.Status, "ConfigMapReady", metav1.ConditionFalse, "ConfigMapReady", "Failed to update ConfigMap for Gateway")
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
logger.Info("Updated ConfigMap", "ConfigMap.Name", configMap.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
err = createDeployment(*r, ctx, req, *gateway, imageName)
|
||||||
|
if err != nil {
|
||||||
|
addCondition(&gateway.Status, "DeploymentNotReady", metav1.ConditionFalse, "DeploymentNotReady", "Failed to created deployment for Gateway")
|
||||||
|
logger.Error(err, "Failed to create Deployment")
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = createService(*r, ctx, req, gateway)
|
||||||
|
if err != nil {
|
||||||
|
addCondition(&gateway.Status, "ServiceNotReady", metav1.ConditionFalse, "ServiceNotReady", "Failed to create Service for Gateway")
|
||||||
|
logger.Error(err, "Failed to create Service")
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
addCondition(&gateway.Status, "GatewayReady", metav1.ConditionTrue, "AllSubresourcesReady", "All subresources are ready")
|
||||||
|
logger.Info("All Subresources ready")
|
||||||
|
|
||||||
|
// Update the Status
|
||||||
|
gateway.Status.Replicas = gateway.Spec.ReplicaCount
|
||||||
|
if gateway.Spec.AutoScaling.Enabled {
|
||||||
|
replicas, err := currentReplicas(ctx, r.Client, gateway.Name, gateway.Namespace)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err, "Failed to get current replicas")
|
||||||
|
}
|
||||||
|
gateway.Status.Replicas = replicas
|
||||||
|
|
||||||
|
}
|
||||||
|
gateway.Status.Routes = int32(len(gomaConfig.Gateway.Routes))
|
||||||
|
if err := r.updateStatus(ctx, gateway); err != nil {
|
||||||
|
logger.Error(err, "Failed to update resource status")
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Info("Successfully updated resource status")
|
||||||
|
return ctrl.Result{}, nil
|
||||||
|
}
|
||||||
|
func (r *GatewayReconciler) updateStatus(ctx context.Context, gateway *gomaprojv1beta1.Gateway) error {
|
||||||
|
return r.Client.Status().Update(ctx, gateway)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to return a pointer to an int32
|
||||||
|
func int32Ptr(i int32) *int32 {
|
||||||
|
return &i
|
||||||
|
}
|
||||||
|
|
||||||
|
func addCondition(status *gomaprojv1beta1.GatewayStatus, condType string, statusType metav1.ConditionStatus, reason, message string) {
|
||||||
|
for i, existingCondition := range status.Conditions {
|
||||||
|
if existingCondition.Type == condType {
|
||||||
|
// Condition already exists, update it
|
||||||
|
status.Conditions[i].Status = statusType
|
||||||
|
status.Conditions[i].Reason = reason
|
||||||
|
status.Conditions[i].Message = message
|
||||||
|
status.Conditions[i].LastTransitionTime = metav1.Now()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The Condition does not exist, add it
|
||||||
|
condition := metav1.Condition{
|
||||||
|
Type: condType,
|
||||||
|
Status: statusType,
|
||||||
|
Reason: reason,
|
||||||
|
Message: message,
|
||||||
|
LastTransitionTime: metav1.Now(),
|
||||||
|
}
|
||||||
|
status.Conditions = append(status.Conditions, condition)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *GatewayReconciler) finalize(ctx context.Context, gateway *gomaprojv1beta1.Gateway) error {
|
||||||
|
logger := log.FromContext(ctx)
|
||||||
|
logger.Info("Finalizing Gateway", "Name", gateway.Name, "Namespace", gateway.Namespace)
|
||||||
|
// Delete the ConfigMap
|
||||||
|
configMap := &corev1.ConfigMap{}
|
||||||
|
err := r.Get(ctx, client.ObjectKey{Namespace: gateway.Namespace, Name: gateway.Name}, configMap)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err, "Failed to get Deployment")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Info("Deleting ConfigMap...", "Name", configMap.Name)
|
||||||
|
err = r.Delete(ctx, configMap)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err, "Failed to delete Deployment")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the Deployment
|
||||||
|
deployment := &v1.Deployment{}
|
||||||
|
err = r.Get(ctx, client.ObjectKey{Namespace: gateway.Namespace, Name: gateway.Name}, deployment)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err, "Failed to get Deployment")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Info("Deleting Deployment...", "Name", deployment.Name)
|
||||||
|
err = r.Delete(ctx, deployment)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err, "Failed to delete Deployment")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if gateway.Spec.AutoScaling.Enabled {
|
||||||
|
// Delete the HorizontalPodAutoscaler
|
||||||
|
hpa := &autoscalingv1.HorizontalPodAutoscaler{}
|
||||||
|
err = r.Get(ctx, client.ObjectKey{Namespace: gateway.Namespace, Name: gateway.Name}, hpa)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err, "Failed to get HorizontalPodAutoscaler")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Info("Deleting HorizontalPodAutoscaler...", "Name", hpa.Name)
|
||||||
|
err = r.Delete(ctx, hpa)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err, "Failed to delete HorizontalPodAutoscaler")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
logger.Info("Deleted Deployment", "Name", deployment.Name, "Namespace", deployment.Namespace)
|
||||||
|
|
||||||
|
// Delete the Service
|
||||||
|
service := &corev1.Service{}
|
||||||
|
err = r.Get(ctx, client.ObjectKey{Namespace: gateway.Namespace, Name: gateway.Name}, service)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err, "Failed to get Service")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Info("Deleting Service...", "Name", service.Name)
|
||||||
|
err = r.Delete(ctx, service)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err, "Failed to delete Service")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Info("Deleted Service", "Name", service.Name, "Namespace", service.Namespace)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetupWithManager sets up the controller with the Manager.
|
||||||
|
func (r *GatewayReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
|
return ctrl.NewControllerManagedBy(mgr).
|
||||||
|
For(&gomaprojv1beta1.Gateway{}).
|
||||||
|
Owns(&corev1.ConfigMap{}). // Watch ConfigMaps created by the controller
|
||||||
|
Owns(&v1.Deployment{}). // Watch Deployments created by the controller
|
||||||
|
Owns(&corev1.Service{}). // Watch Services created by the controller
|
||||||
|
Owns(&autoscalingv1.HorizontalPodAutoscaler{}). // Watch HorizontalPodAutoscaler created by the controller
|
||||||
|
Named("gateway").
|
||||||
|
Complete(r)
|
||||||
|
}
|
||||||
89
internal/controller/gateway_controller_test.go
Normal file
89
internal/controller/gateway_controller_test.go
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
gomaprojv1beta1 "github.com/jkaninda/goma-operator/api/v1beta1"
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("Gateway Controller", func() {
|
||||||
|
Context("When reconciling a resource", func() {
|
||||||
|
const resourceName = "test-gateway"
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
typeNamespacedName := types.NamespacedName{
|
||||||
|
Name: resourceName,
|
||||||
|
Namespace: "default",
|
||||||
|
}
|
||||||
|
gateway := &gomaprojv1beta1.Gateway{}
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
By("creating the custom resource for the Kind Gateway")
|
||||||
|
err := k8sClient.Get(ctx, typeNamespacedName, gateway)
|
||||||
|
if err != nil && errors.IsNotFound(err) {
|
||||||
|
resource := &gomaprojv1beta1.Gateway{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: resourceName,
|
||||||
|
Namespace: "default",
|
||||||
|
},
|
||||||
|
Spec: gomaprojv1beta1.GatewaySpec{
|
||||||
|
GatewayVersion: "latest",
|
||||||
|
Server: gomaprojv1beta1.Server{},
|
||||||
|
ReplicaCount: 1,
|
||||||
|
AutoScaling: gomaprojv1beta1.AutoScaling{
|
||||||
|
Enabled: false,
|
||||||
|
MinReplicas: 2,
|
||||||
|
MaxReplicas: 5,
|
||||||
|
TargetCPUUtilizationPercentage: 80,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
Expect(k8sClient.Create(ctx, resource)).To(Succeed())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
AfterEach(func() {
|
||||||
|
resource := &gomaprojv1beta1.Gateway{}
|
||||||
|
err := k8sClient.Get(ctx, typeNamespacedName, resource)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
By("Cleanup the specific resource instance Gateway")
|
||||||
|
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
|
||||||
|
})
|
||||||
|
It("should successfully reconcile the resource", func() {
|
||||||
|
By("Reconciling the created resource")
|
||||||
|
controllerReconciler := &GatewayReconciler{
|
||||||
|
Client: k8sClient,
|
||||||
|
Scheme: k8sClient.Scheme(),
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := controllerReconciler.Reconcile(ctx, reconcile.Request{
|
||||||
|
NamespacedName: typeNamespacedName,
|
||||||
|
})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
210
internal/controller/helpers.go
Normal file
210
internal/controller/helpers.go
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
gomaprojv1beta1 "github.com/jkaninda/goma-operator/api/v1beta1"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func gatewayConfig(r GatewayReconciler, ctx context.Context, req ctrl.Request, gateway *gomaprojv1beta1.Gateway) GatewayConfig {
|
||||||
|
logger := log.FromContext(ctx)
|
||||||
|
gomaConfig := &GatewayConfig{}
|
||||||
|
gomaConfig.Version = GatewayConfigVersion
|
||||||
|
gomaConfig.Gateway = mapToGateway(gateway.Spec)
|
||||||
|
labelSelector := client.MatchingLabels{}
|
||||||
|
var middlewareNames []string
|
||||||
|
// List ConfigMaps in the namespace with the matching label
|
||||||
|
var routes gomaprojv1beta1.RouteList
|
||||||
|
if err := r.List(ctx, &routes, labelSelector, client.InNamespace(req.Namespace)); err != nil {
|
||||||
|
logger.Error(err, "Failed to list Routes")
|
||||||
|
return *gomaConfig
|
||||||
|
}
|
||||||
|
var middlewares gomaprojv1beta1.MiddlewareList
|
||||||
|
if err := r.List(ctx, &middlewares, labelSelector, client.InNamespace(req.Namespace)); err != nil {
|
||||||
|
logger.Error(err, "Failed to list Middlewares")
|
||||||
|
return *gomaConfig
|
||||||
|
}
|
||||||
|
logger.Info(fmt.Sprintf("Listing Routes: size: %d", len(routes.Items)))
|
||||||
|
|
||||||
|
for _, route := range routes.Items {
|
||||||
|
logger.Info("Found Route", "Name", route.Name)
|
||||||
|
if route.Spec.Gateway == gateway.Name {
|
||||||
|
gomaConfig.Gateway.Routes = append(gomaConfig.Gateway.Routes, route.Spec.Routes...)
|
||||||
|
for _, rt := range route.Spec.Routes {
|
||||||
|
middlewareNames = append(middlewareNames, rt.Middlewares...)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, mid := range middlewares.Items {
|
||||||
|
middleware := *mapMid(mid)
|
||||||
|
logger.Info("Adding Middleware", "Name", middleware.Name)
|
||||||
|
if slices.Contains(middlewareNames, middleware.Name) {
|
||||||
|
gomaConfig.Middlewares = append(gomaConfig.Middlewares, middleware)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return *gomaConfig
|
||||||
|
}
|
||||||
|
func updateGatewayConfig(r RouteReconciler, ctx context.Context, req ctrl.Request, gateway gomaprojv1beta1.Gateway) error {
|
||||||
|
logger := log.FromContext(ctx)
|
||||||
|
gomaConfig := &GatewayConfig{}
|
||||||
|
gomaConfig.Version = GatewayConfigVersion
|
||||||
|
gomaConfig.Gateway = mapToGateway(gateway.Spec)
|
||||||
|
labelSelector := client.MatchingLabels{}
|
||||||
|
var middlewareNames []string
|
||||||
|
// List ConfigMaps in the namespace with the matching label
|
||||||
|
var routes gomaprojv1beta1.RouteList
|
||||||
|
if err := r.List(ctx, &routes, labelSelector, client.InNamespace(req.Namespace)); err != nil {
|
||||||
|
logger.Error(err, "Failed to list Routes")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var middlewares gomaprojv1beta1.MiddlewareList
|
||||||
|
if err := r.List(ctx, &middlewares, labelSelector, client.InNamespace(req.Namespace)); err != nil {
|
||||||
|
logger.Error(err, "Failed to list Middlewares")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Info(fmt.Sprintf("Listing Routes: size: %d", len(routes.Items)))
|
||||||
|
|
||||||
|
for _, route := range routes.Items {
|
||||||
|
logger.Info("Found Route", "Name", route.Name)
|
||||||
|
if route.Spec.Gateway == gateway.Name {
|
||||||
|
gomaConfig.Gateway.Routes = append(gomaConfig.Gateway.Routes, route.Spec.Routes...)
|
||||||
|
for _, rt := range route.Spec.Routes {
|
||||||
|
middlewareNames = append(middlewareNames, rt.Middlewares...)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, mid := range middlewares.Items {
|
||||||
|
middleware := *mapMid(mid)
|
||||||
|
logger.Info("Adding Middleware", "Name", middleware.Name)
|
||||||
|
if slices.Contains(middlewareNames, middleware.Name) {
|
||||||
|
gomaConfig.Middlewares = append(gomaConfig.Middlewares, middleware)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
yamlContent, err := yaml.Marshal(&gomaConfig)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err, "Unable to marshal YAML")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Define the desired ConfigMap
|
||||||
|
configMap := &corev1.ConfigMap{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: gateway.Name,
|
||||||
|
Namespace: req.Namespace,
|
||||||
|
Labels: map[string]string{
|
||||||
|
"belongs-to": BelongsTo,
|
||||||
|
"gateway": gateway.Name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Data: map[string]string{
|
||||||
|
ConfigName: strings.TrimSpace(string(yamlContent)),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// Check if the ConfigMap already exists
|
||||||
|
var existingConfigMap corev1.ConfigMap
|
||||||
|
err = r.Get(ctx, types.NamespacedName{Name: configMap.Name, Namespace: configMap.Namespace}, &existingConfigMap)
|
||||||
|
if err != nil && client.IgnoreNotFound(err) != nil {
|
||||||
|
logger.Error(err, "Failed to get ConfigMap")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil && client.IgnoreNotFound(err) == nil {
|
||||||
|
// Create the ConfigMap if it doesn't exist
|
||||||
|
if err = controllerutil.SetControllerReference(&gateway, configMap, r.Scheme); err != nil {
|
||||||
|
logger.Error(err, "Failed to set controller reference")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = r.Create(ctx, configMap); err != nil {
|
||||||
|
logger.Error(err, "Failed to create ConfigMap")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Info("Created ConfigMap", "ConfigMap.Name", configMap.Name)
|
||||||
|
} else {
|
||||||
|
// Optional: Update the ConfigMap if needed
|
||||||
|
if !equalConfigMapData(existingConfigMap.Data, configMap.Data) {
|
||||||
|
existingConfigMap.Data = configMap.Data
|
||||||
|
if err = r.Update(ctx, &existingConfigMap); err != nil {
|
||||||
|
logger.Error(err, "Failed to update ConfigMap")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Info("Updated ConfigMap", "ConfigMap.Name", configMap.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to compare ConfigMap data
|
||||||
|
func equalConfigMapData(existing, desired map[string]string) bool {
|
||||||
|
if len(existing) != len(desired) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for key, value := range desired {
|
||||||
|
if existing[key] != value {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// mapMid converts RawExtensionT to struct
|
||||||
|
func mapMid(middleware gomaprojv1beta1.Middleware) *Middleware {
|
||||||
|
mid := &Middleware{
|
||||||
|
Name: middleware.Name,
|
||||||
|
Type: middleware.Spec.Type,
|
||||||
|
Paths: middleware.Spec.Paths,
|
||||||
|
}
|
||||||
|
switch middleware.Spec.Type {
|
||||||
|
case BasicAuth:
|
||||||
|
var basicAuth BasicRuleMiddleware
|
||||||
|
err := ConvertRawExtensionToStruct(middleware.Spec.Rule, &basicAuth)
|
||||||
|
if err != nil {
|
||||||
|
return mid
|
||||||
|
}
|
||||||
|
mid.Rule = basicAuth
|
||||||
|
return mid
|
||||||
|
case OAuth:
|
||||||
|
var oauthRulerMiddleware OauthRulerMiddleware
|
||||||
|
err := ConvertRawExtensionToStruct(middleware.Spec.Rule, &oauthRulerMiddleware)
|
||||||
|
if err != nil {
|
||||||
|
return mid
|
||||||
|
}
|
||||||
|
mid.Rule = oauthRulerMiddleware
|
||||||
|
return mid
|
||||||
|
case JWTAuth:
|
||||||
|
var jwtAuth JWTRuleMiddleware
|
||||||
|
err := ConvertRawExtensionToStruct(middleware.Spec.Rule, &jwtAuth)
|
||||||
|
if err != nil {
|
||||||
|
return mid
|
||||||
|
}
|
||||||
|
mid.Rule = jwtAuth
|
||||||
|
return mid
|
||||||
|
case ratelimit, RateLimit:
|
||||||
|
var rateLimitRuleMiddleware RateLimitRuleMiddleware
|
||||||
|
err := ConvertRawExtensionToStruct(middleware.Spec.Rule, &rateLimitRuleMiddleware)
|
||||||
|
if err != nil {
|
||||||
|
return mid
|
||||||
|
}
|
||||||
|
mid.Rule = rateLimitRuleMiddleware
|
||||||
|
return mid
|
||||||
|
}
|
||||||
|
return mid
|
||||||
|
}
|
||||||
122
internal/controller/hpa.go
Normal file
122
internal/controller/hpa.go
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
|
||||||
|
gomaprojv1beta1 "github.com/jkaninda/goma-operator/api/v1beta1"
|
||||||
|
autoscalingv2 "k8s.io/api/autoscaling/v2"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// createHpa creates HPA
|
||||||
|
func createHpa(r GatewayReconciler, ctx context.Context, req ctrl.Request, gateway *gomaprojv1beta1.Gateway) error {
|
||||||
|
logger := log.FromContext(ctx)
|
||||||
|
var metrics []autoscalingv2.MetricSpec
|
||||||
|
targetCPUUtilizationPercentage := gateway.Spec.AutoScaling.TargetCPUUtilizationPercentage
|
||||||
|
targetMemoryUtilizationPercentage := gateway.Spec.AutoScaling.TargetMemoryUtilizationPercentage
|
||||||
|
// Add CPU metric if targetCPUUtilizationPercentage is set
|
||||||
|
if targetCPUUtilizationPercentage != 0 {
|
||||||
|
metrics = append(metrics, autoscalingv2.MetricSpec{
|
||||||
|
Type: autoscalingv2.ResourceMetricSourceType,
|
||||||
|
Resource: &autoscalingv2.ResourceMetricSource{
|
||||||
|
Name: "cpu",
|
||||||
|
Target: autoscalingv2.MetricTarget{
|
||||||
|
Type: autoscalingv2.UtilizationMetricType,
|
||||||
|
AverageUtilization: int32Ptr(targetCPUUtilizationPercentage),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// Add Memory metric if targetMemoryUtilizationPercentage is set
|
||||||
|
if targetMemoryUtilizationPercentage != 0 {
|
||||||
|
metrics = append(metrics, autoscalingv2.MetricSpec{
|
||||||
|
Type: autoscalingv2.ResourceMetricSourceType,
|
||||||
|
Resource: &autoscalingv2.ResourceMetricSource{
|
||||||
|
Name: "memory",
|
||||||
|
Target: autoscalingv2.MetricTarget{
|
||||||
|
Type: autoscalingv2.UtilizationMetricType,
|
||||||
|
AverageUtilization: int32Ptr(targetMemoryUtilizationPercentage),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// Create HPA
|
||||||
|
hpa := &autoscalingv2.HorizontalPodAutoscaler{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: req.Name,
|
||||||
|
Namespace: req.Namespace,
|
||||||
|
},
|
||||||
|
Spec: autoscalingv2.HorizontalPodAutoscalerSpec{
|
||||||
|
MinReplicas: int32Ptr(gateway.Spec.AutoScaling.MinReplicas),
|
||||||
|
MaxReplicas: gateway.Spec.AutoScaling.MaxReplicas,
|
||||||
|
Metrics: metrics,
|
||||||
|
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
|
||||||
|
APIVersion: "apps/v1",
|
||||||
|
Kind: "Deployment",
|
||||||
|
Name: req.Name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// Check if the hpa already exists
|
||||||
|
var existHpa autoscalingv2.HorizontalPodAutoscaler
|
||||||
|
err := r.Get(ctx, types.NamespacedName{Name: req.Name, Namespace: req.Namespace}, &existHpa)
|
||||||
|
if err != nil && client.IgnoreNotFound(err) != nil {
|
||||||
|
logger.Error(err, "Failed to get HorizontalPodAutoscaler")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err != nil && client.IgnoreNotFound(err) == nil {
|
||||||
|
// Create the HPA if it doesn't exist
|
||||||
|
if err = controllerutil.SetControllerReference(gateway, hpa, r.Scheme); err != nil {
|
||||||
|
logger.Error(err, "Failed to set controller reference")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = r.Create(ctx, hpa); err != nil {
|
||||||
|
logger.Error(err, "Failed to create HorizontalPodAutoscaler")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Info("Created HorizontalPodAutoscaler", "HorizontalPodAutoscaler.Name", hpa.Name)
|
||||||
|
} else {
|
||||||
|
// Update the Deployment if the spec has changed
|
||||||
|
if !equalHpaSpec(existHpa, *hpa) {
|
||||||
|
existHpa.Spec = hpa.Spec
|
||||||
|
if err = r.Update(ctx, &existHpa); err != nil {
|
||||||
|
logger.Error(err, "Failed to update Deployment")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Info("Updated HorizontalPodAutoscaler", "HorizontalPodAutoscaler.Name", hpa.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to compare Deployment specs
|
||||||
|
func equalHpaSpec(existing, desired autoscalingv2.HorizontalPodAutoscaler) bool {
|
||||||
|
// A deep equality check or field-by-field comparison would be more accurate
|
||||||
|
if existing.Spec.MinReplicas != desired.Spec.MinReplicas {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if existing.Spec.MaxReplicas != desired.Spec.MaxReplicas {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if existing.Spec.Metrics[0].Resource.Target.AverageUtilization != desired.Spec.Metrics[0].Resource.Target.AverageUtilization {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if existing.Spec.Metrics[1].Resource.Target.AverageUtilization != desired.Spec.Metrics[1].Resource.Target.AverageUtilization {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
func ConvertRawExtensionToStruct(raw runtime.RawExtension, out interface{}) error {
|
||||||
|
// Unmarshal the raw JSON into the provided struct
|
||||||
|
if err := json.Unmarshal(raw.Raw, out); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
87
internal/controller/route_controller.go
Normal file
87
internal/controller/route_controller.go
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
gomaprojv1beta1 "github.com/jkaninda/goma-operator/api/v1beta1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RouteReconciler reconciles a Route object
|
||||||
|
type RouteReconciler struct {
|
||||||
|
client.Client
|
||||||
|
Scheme *runtime.Scheme
|
||||||
|
}
|
||||||
|
|
||||||
|
// +kubebuilder:rbac:groups=gomaproj.github.io,resources=routes,verbs=get;list;watch;create;update;patch;delete
|
||||||
|
// +kubebuilder:rbac:groups=gomaproj.github.io,resources=routes/status,verbs=get;update;patch
|
||||||
|
// +kubebuilder:rbac:groups=gomaproj.github.io,resources=routes/finalizers,verbs=update
|
||||||
|
// +kubebuilder:rbac:groups=gomaproj.github.io,resources=middlewares,verbs=get;list;watch;create;update;patch;delete
|
||||||
|
// +kubebuilder:rbac:groups=gomaproj.github.io,resources=middlewares/status,verbs=get;update;patch
|
||||||
|
// +kubebuilder:rbac:groups=gomaproj.github.io,resources=middlewares/finalizers,verbs=update
|
||||||
|
// +kubebuilder:rbac:groups="",resources=configmaps,verbs=get;list;watch;create;update;patch;delete
|
||||||
|
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete
|
||||||
|
|
||||||
|
// Reconcile is part of the main kubernetes reconciliation loop which aims to
|
||||||
|
// move the current state of the cluster closer to the desired state.
|
||||||
|
// TODO(user): Modify the Reconcile function to compare the state specified by
|
||||||
|
// the Route object against the actual cluster state, and then
|
||||||
|
// perform operations to make the cluster state reflect the state specified by
|
||||||
|
// the user.
|
||||||
|
//
|
||||||
|
// For more details, check Reconcile and its Result here:
|
||||||
|
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.1/pkg/reconcile
|
||||||
|
func (r *RouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
||||||
|
logger := log.FromContext(ctx)
|
||||||
|
// Fetch the custom resource
|
||||||
|
var route gomaprojv1beta1.Route
|
||||||
|
if err := r.Get(ctx, req.NamespacedName, &route); err != nil {
|
||||||
|
logger.Error(err, "Unable to fetch CustomResource")
|
||||||
|
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||||
|
}
|
||||||
|
var gateway gomaprojv1beta1.Gateway
|
||||||
|
if err := r.Get(ctx, types.NamespacedName{Name: route.Spec.Gateway, Namespace: route.Namespace}, &gateway); err != nil {
|
||||||
|
logger.Error(err, "Failed to fetch Gateway")
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
err := updateGatewayConfig(*r, ctx, req, gateway)
|
||||||
|
if err != nil {
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
//
|
||||||
|
if err = r.RestartDeployment(ctx, req, gateway); err != nil {
|
||||||
|
logger.Error(err, "Failed to restart Deployment")
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
|
||||||
|
}
|
||||||
|
return ctrl.Result{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetupWithManager sets up the controller with the Manager.
|
||||||
|
func (r *RouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
|
return ctrl.NewControllerManagedBy(mgr).
|
||||||
|
For(&gomaprojv1beta1.Route{}).
|
||||||
|
Named("route").
|
||||||
|
Complete(r)
|
||||||
|
}
|
||||||
119
internal/controller/route_controller_test.go
Normal file
119
internal/controller/route_controller_test.go
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||||
|
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
|
gomaprojv1beta1 "github.com/jkaninda/goma-operator/api/v1beta1"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("Route Controller", func() {
|
||||||
|
Context("When reconciling a resource", func() {
|
||||||
|
const resourceName = "test-resource"
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
typeNamespacedName := types.NamespacedName{
|
||||||
|
Name: resourceName,
|
||||||
|
Namespace: "default", // TODO(user):Modify as needed
|
||||||
|
}
|
||||||
|
gateway := &gomaprojv1beta1.Gateway{}
|
||||||
|
|
||||||
|
route := &gomaprojv1beta1.Route{}
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
By("creating the custom resource for the Kind Gateway")
|
||||||
|
err := k8sClient.Get(ctx, typeNamespacedName, gateway)
|
||||||
|
if err != nil && errors.IsNotFound(err) {
|
||||||
|
resource := &gomaprojv1beta1.Gateway{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: resourceName,
|
||||||
|
Namespace: "default",
|
||||||
|
},
|
||||||
|
Spec: gomaprojv1beta1.GatewaySpec{
|
||||||
|
GatewayVersion: "latest",
|
||||||
|
Server: gomaprojv1beta1.Server{},
|
||||||
|
ReplicaCount: 1,
|
||||||
|
AutoScaling: gomaprojv1beta1.AutoScaling{
|
||||||
|
Enabled: false,
|
||||||
|
MinReplicas: 2,
|
||||||
|
MaxReplicas: 5,
|
||||||
|
TargetCPUUtilizationPercentage: 80,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
Expect(k8sClient.Create(ctx, resource)).To(Succeed())
|
||||||
|
}
|
||||||
|
By("creating the custom resource for the Kind Route")
|
||||||
|
err = k8sClient.Get(ctx, typeNamespacedName, route)
|
||||||
|
if err != nil && errors.IsNotFound(err) {
|
||||||
|
resource := &gomaprojv1beta1.Route{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: resourceName,
|
||||||
|
Namespace: "default",
|
||||||
|
},
|
||||||
|
Spec: gomaprojv1beta1.RouteSpec{
|
||||||
|
Gateway: resourceName,
|
||||||
|
Routes: []gomaprojv1beta1.RouteConfig{
|
||||||
|
{
|
||||||
|
Path: "/",
|
||||||
|
Name: resourceName,
|
||||||
|
Rewrite: "/",
|
||||||
|
Destination: "https://example.com",
|
||||||
|
Methods: []string{"GET", "POST"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
Expect(k8sClient.Create(ctx, resource)).To(Succeed())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
AfterEach(func() {
|
||||||
|
// TODO(user): Cleanup logic after each test, like removing the resource instance.
|
||||||
|
resource := &gomaprojv1beta1.Route{}
|
||||||
|
err := k8sClient.Get(ctx, typeNamespacedName, resource)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
By("Cleanup the specific resource instance Route")
|
||||||
|
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
|
||||||
|
})
|
||||||
|
It("should successfully reconcile the resource", func() {
|
||||||
|
By("Reconciling the created resource")
|
||||||
|
controllerReconciler := &RouteReconciler{
|
||||||
|
Client: k8sClient,
|
||||||
|
Scheme: k8sClient.Scheme(),
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := controllerReconciler.Reconcile(ctx, reconcile.Request{
|
||||||
|
NamespacedName: typeNamespacedName,
|
||||||
|
})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
// TODO(user): Add more specific assertions depending on your controller's reconciliation logic.
|
||||||
|
// Example: If you expect a certain status condition after reconciliation, verify it here.
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
96
internal/controller/suite_test.go
Normal file
96
internal/controller/suite_test.go
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"k8s.io/client-go/kubernetes/scheme"
|
||||||
|
"k8s.io/client-go/rest"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/envtest"
|
||||||
|
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
||||||
|
|
||||||
|
gomaprojv1beta1 "github.com/jkaninda/goma-operator/api/v1beta1"
|
||||||
|
// +kubebuilder:scaffold:imports
|
||||||
|
)
|
||||||
|
|
||||||
|
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
|
||||||
|
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
|
||||||
|
|
||||||
|
var cfg *rest.Config
|
||||||
|
var k8sClient client.Client
|
||||||
|
var testEnv *envtest.Environment
|
||||||
|
var ctx context.Context
|
||||||
|
var cancel context.CancelFunc
|
||||||
|
|
||||||
|
func TestControllers(t *testing.T) {
|
||||||
|
RegisterFailHandler(Fail)
|
||||||
|
|
||||||
|
RunSpecs(t, "Controller Suite")
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = BeforeSuite(func() {
|
||||||
|
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
|
||||||
|
|
||||||
|
ctx, cancel = context.WithCancel(context.TODO())
|
||||||
|
|
||||||
|
By("bootstrapping test environment")
|
||||||
|
testEnv = &envtest.Environment{
|
||||||
|
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
|
||||||
|
ErrorIfCRDPathMissing: true,
|
||||||
|
|
||||||
|
// The BinaryAssetsDirectory is only required if you want to run the tests directly
|
||||||
|
// without call the makefile target test. If not informed it will look for the
|
||||||
|
// default path defined in controller-runtime which is /usr/local/kubebuilder/.
|
||||||
|
// Note that you must have the required binaries setup under the bin directory to perform
|
||||||
|
// the tests directly. When we run make test it will be setup and used automatically.
|
||||||
|
BinaryAssetsDirectory: filepath.Join("..", "..", "bin", "k8s",
|
||||||
|
fmt.Sprintf("1.31.0-%s-%s", runtime.GOOS, runtime.GOARCH)),
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
// cfg is defined in this file globally.
|
||||||
|
cfg, err = testEnv.Start()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(cfg).NotTo(BeNil())
|
||||||
|
|
||||||
|
err = gomaprojv1beta1.AddToScheme(scheme.Scheme)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
// +kubebuilder:scaffold:scheme
|
||||||
|
|
||||||
|
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(k8sClient).NotTo(BeNil())
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
var _ = AfterSuite(func() {
|
||||||
|
By("tearing down the test environment")
|
||||||
|
cancel()
|
||||||
|
err := testEnv.Stop()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
})
|
||||||
71
internal/controller/svc.go
Normal file
71
internal/controller/svc.go
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
gomaprojv1beta1 "github.com/jkaninda/goma-operator/api/v1beta1"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// createService create K8s service
|
||||||
|
func createService(r GatewayReconciler, ctx context.Context, req ctrl.Request, gateway *gomaprojv1beta1.Gateway) error {
|
||||||
|
l := log.FromContext(ctx)
|
||||||
|
k8sService := &corev1.Service{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: req.Name,
|
||||||
|
Namespace: req.Namespace,
|
||||||
|
Labels: map[string]string{
|
||||||
|
"app": req.Name,
|
||||||
|
"belongs-to": BelongsTo,
|
||||||
|
"managed-by": req.Name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Spec: corev1.ServiceSpec{
|
||||||
|
Selector: map[string]string{
|
||||||
|
"app": req.Name,
|
||||||
|
},
|
||||||
|
Ports: []corev1.ServicePort{
|
||||||
|
{
|
||||||
|
Name: "http",
|
||||||
|
Protocol: corev1.ProtocolTCP,
|
||||||
|
Port: 8080,
|
||||||
|
TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: 8080},
|
||||||
|
}, {
|
||||||
|
Name: "https",
|
||||||
|
Protocol: corev1.ProtocolTCP,
|
||||||
|
Port: 8443,
|
||||||
|
TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: 8443},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set Gateway instance as the owner and controller
|
||||||
|
if err := controllerutil.SetControllerReference(gateway, k8sService, r.Scheme); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
found := &corev1.Service{}
|
||||||
|
err := r.Get(ctx, client.ObjectKey{Namespace: req.Namespace, Name: req.Name}, found)
|
||||||
|
if err != nil {
|
||||||
|
if strings.Contains(err.Error(), "not found") {
|
||||||
|
l.Info("Creating a new Service", "Service.Namespace", k8sService.Namespace, "Service.Name", k8sService.Name)
|
||||||
|
err = r.Create(ctx, k8sService)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
l.Info("Failed to get Service", "Service.Namespace", k8sService.Namespace, "Service.Name", k8sService.Name)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
105
internal/controller/types.go
Normal file
105
internal/controller/types.go
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import gomaprojv1beta1 "github.com/jkaninda/goma-operator/api/v1beta1"
|
||||||
|
|
||||||
|
// Gateway contains Goma Proxy Gateway's configs
|
||||||
|
type Gateway struct {
|
||||||
|
// SSLCertFile SSL Certificate file
|
||||||
|
SSLCertFile string `yaml:"sslCertFile"`
|
||||||
|
// SSLKeyFile SSL Private key file
|
||||||
|
SSLKeyFile string `yaml:"sslKeyFile"`
|
||||||
|
// Redis contains redis database details
|
||||||
|
Redis Redis `yaml:"redis"`
|
||||||
|
// WriteTimeout defines proxy write timeout
|
||||||
|
WriteTimeout int `yaml:"writeTimeout"`
|
||||||
|
// ReadTimeout defines proxy read timeout
|
||||||
|
ReadTimeout int `yaml:"readTimeout"`
|
||||||
|
// IdleTimeout defines proxy idle timeout
|
||||||
|
IdleTimeout int `yaml:"idleTimeout"`
|
||||||
|
LogLevel string `yaml:"logLevel"`
|
||||||
|
Cors gomaprojv1beta1.Cors `yaml:"cors"`
|
||||||
|
// DisableHealthCheckStatus enable and disable routes health check
|
||||||
|
DisableHealthCheckStatus bool `yaml:"disableHealthCheckStatus"`
|
||||||
|
// DisableRouteHealthCheckError allows enabling and disabling backend healthcheck errors
|
||||||
|
DisableRouteHealthCheckError bool `yaml:"disableRouteHealthCheckError"`
|
||||||
|
// Disable allows enabling and disabling displaying routes on start
|
||||||
|
DisableDisplayRouteOnStart bool `yaml:"disableDisplayRouteOnStart"`
|
||||||
|
// DisableKeepAlive allows enabling and disabling KeepALive server
|
||||||
|
DisableKeepAlive bool `yaml:"disableKeepAlive"`
|
||||||
|
EnableMetrics bool `yaml:"enableMetrics"`
|
||||||
|
// InterceptErrors holds the status codes to intercept the error from backend
|
||||||
|
InterceptErrors []int `yaml:"interceptErrors,omitempty"`
|
||||||
|
Routes []gomaprojv1beta1.RouteConfig `json:"routes,omitempty" yaml:"routes,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Redis struct {
|
||||||
|
// Addr redis hostname and port number :
|
||||||
|
Addr string `yaml:"addr"`
|
||||||
|
// Password redis password
|
||||||
|
Password string `yaml:"password"`
|
||||||
|
}
|
||||||
|
type Middleware struct {
|
||||||
|
// Path contains the name of middlewares and must be unique
|
||||||
|
Name string `json:"name" yaml:"name"`
|
||||||
|
// Type contains authentication types
|
||||||
|
//
|
||||||
|
// basic, jwt, auth0, rateLimit, access
|
||||||
|
Type string `json:"type" yaml:"type"` // Middleware type [basic, jwt, auth0, rateLimit, access]
|
||||||
|
Paths []string `json:"paths" yaml:"paths"` // Protected paths
|
||||||
|
// Rule contains route middleware rule
|
||||||
|
Rule interface{} `json:"rule" yaml:"rule"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Middlewares struct {
|
||||||
|
Middlewares []Middleware `json:"middlewares,omitempty" yaml:"middlewares,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GatewayConfig struct {
|
||||||
|
Version string `json:"version" yaml:"version"`
|
||||||
|
Gateway Gateway `json:"gateway" yaml:"gateway"`
|
||||||
|
Middlewares []Middleware `json:"middlewares,omitempty" yaml:"middlewares,omitempty"`
|
||||||
|
}
|
||||||
|
type BasicRuleMiddleware struct {
|
||||||
|
Username string `yaml:"username" json:"username"`
|
||||||
|
Password string `yaml:"password" json:"password"`
|
||||||
|
}
|
||||||
|
type JWTRuleMiddleware struct {
|
||||||
|
URL string `yaml:"url" json:"url"`
|
||||||
|
RequiredHeaders []string `yaml:"requiredHeaders" json:"requiredHeaders"`
|
||||||
|
Headers map[string]string `yaml:"headers" json:"headers"`
|
||||||
|
Params map[string]string `yaml:"params" json:"params"`
|
||||||
|
}
|
||||||
|
type RateLimitRuleMiddleware struct {
|
||||||
|
Unit string `yaml:"unit" json:"unit"`
|
||||||
|
RequestsPerUnit int `yaml:"requestsPerUnit" json:"requestsPerUnit"`
|
||||||
|
}
|
||||||
|
type OauthRulerMiddleware struct {
|
||||||
|
// ClientID is the application's ID.
|
||||||
|
ClientID string `yaml:"clientId"`
|
||||||
|
|
||||||
|
// ClientSecret is the application's secret.
|
||||||
|
ClientSecret string `yaml:"clientSecret"`
|
||||||
|
// oauth provider google, gitlab, github, amazon, facebook, custom
|
||||||
|
Provider string `yaml:"provider"`
|
||||||
|
// Endpoint contains the resource server's token endpoint
|
||||||
|
Endpoint OauthEndpoint `yaml:"endpoint"`
|
||||||
|
|
||||||
|
// RedirectURL is the URL to redirect users going through
|
||||||
|
// the OAuth flow, after the resource owner's URLs.
|
||||||
|
RedirectURL string `yaml:"redirectUrl"`
|
||||||
|
// RedirectPath is the PATH to redirect users after authentication, e.g: /my-protected-path/dashboard
|
||||||
|
RedirectPath string `yaml:"redirectPath"`
|
||||||
|
// CookiePath e.g: /my-protected-path or / || by default is applied on a route path
|
||||||
|
CookiePath string `yaml:"cookiePath"`
|
||||||
|
|
||||||
|
// Scope specifies optional requested permissions.
|
||||||
|
Scopes []string `yaml:"scopes"`
|
||||||
|
// contains filtered or unexported fields
|
||||||
|
State string `yaml:"state"`
|
||||||
|
JWTSecret string `yaml:"jwtSecret"`
|
||||||
|
}
|
||||||
|
type OauthEndpoint struct {
|
||||||
|
AuthURL string `yaml:"authUrl"`
|
||||||
|
TokenURL string `yaml:"tokenUrl"`
|
||||||
|
UserInfoURL string `yaml:"userInfoUrl"`
|
||||||
|
}
|
||||||
22
internal/controller/util.go
Normal file
22
internal/controller/util.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import gomaprojv1beta1 "github.com/jkaninda/goma-operator/api/v1beta1"
|
||||||
|
|
||||||
|
func mapToGateway(g gomaprojv1beta1.GatewaySpec) Gateway {
|
||||||
|
return Gateway{
|
||||||
|
SSLKeyFile: "",
|
||||||
|
SSLCertFile: "",
|
||||||
|
Redis: Redis{},
|
||||||
|
WriteTimeout: g.Server.WriteTimeout,
|
||||||
|
ReadTimeout: g.Server.ReadTimeout,
|
||||||
|
IdleTimeout: g.Server.IdleTimeout,
|
||||||
|
LogLevel: g.Server.LogLevel,
|
||||||
|
Cors: g.Server.Cors,
|
||||||
|
DisableHealthCheckStatus: g.Server.DisableHealthCheckStatus,
|
||||||
|
DisableRouteHealthCheckError: g.Server.DisableHealthCheckStatus,
|
||||||
|
DisableKeepAlive: g.Server.DisableKeepAlive,
|
||||||
|
InterceptErrors: g.Server.InterceptErrors,
|
||||||
|
EnableMetrics: g.Server.EnableMetrics,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
19
internal/controller/var.go
Normal file
19
internal/controller/var.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
const (
|
||||||
|
AppImageName = "jkaninda/goma-gateway"
|
||||||
|
ExtraConfigPath = "/etc/goma/extra/"
|
||||||
|
BasicAuth = "basic" // basic authentication middlewares
|
||||||
|
JWTAuth = "jwt" // JWT authentication middlewares
|
||||||
|
OAuth = "oauth"
|
||||||
|
ratelimit = "ratelimit"
|
||||||
|
RateLimit = "rateLimit"
|
||||||
|
BelongsTo = "goma-gateway"
|
||||||
|
GatewayConfigVersion = "1.0"
|
||||||
|
FinalizerName = "finalizer.gomaproj.jonaskaninda.com"
|
||||||
|
ConfigName = "goma.yml"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ReplicaCount int32 = 1
|
||||||
|
)
|
||||||
120
test/e2e/e2e_suite_test.go
Normal file
120
test/e2e/e2e_suite_test.go
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package e2e
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"github.com/jkaninda/goma-operator/test/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Optional Environment Variables:
|
||||||
|
// - PROMETHEUS_INSTALL_SKIP=true: Skips Prometheus Operator installation during test setup.
|
||||||
|
// - CERT_MANAGER_INSTALL_SKIP=true: Skips CertManager installation during test setup.
|
||||||
|
// These variables are useful if Prometheus or CertManager is already installed, avoiding
|
||||||
|
// re-installation and conflicts.
|
||||||
|
skipPrometheusInstall = os.Getenv("PROMETHEUS_INSTALL_SKIP") == "true"
|
||||||
|
skipCertManagerInstall = os.Getenv("CERT_MANAGER_INSTALL_SKIP") == "true"
|
||||||
|
// isPrometheusOperatorAlreadyInstalled will be set true when prometheus CRDs be found on the cluster
|
||||||
|
isPrometheusOperatorAlreadyInstalled = false
|
||||||
|
// isCertManagerAlreadyInstalled will be set true when CertManager CRDs be found on the cluster
|
||||||
|
isCertManagerAlreadyInstalled = false
|
||||||
|
|
||||||
|
// projectImage is the name of the image which will be build and loaded
|
||||||
|
// with the code source changes to be tested.
|
||||||
|
projectImage = "example.com/goma-operator:v0.0.1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestE2E runs the end-to-end (e2e) test suite for the project. These tests execute in an isolated,
|
||||||
|
// temporary environment to validate project changes with the the purposed to be used in CI jobs.
|
||||||
|
// The default setup requires Kind, builds/loads the Manager Docker image locally, and installs
|
||||||
|
// CertManager and Prometheus.
|
||||||
|
func TestE2E(t *testing.T) {
|
||||||
|
RegisterFailHandler(Fail)
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, "Starting goma-operator integration test suite\n")
|
||||||
|
RunSpecs(t, "e2e suite")
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = BeforeSuite(func() {
|
||||||
|
By("Ensure that Prometheus is enabled")
|
||||||
|
_ = utils.UncommentCode("config/default/kustomization.yaml", "#- ../prometheus", "#")
|
||||||
|
|
||||||
|
By("generating files")
|
||||||
|
cmd := exec.Command("make", "generate")
|
||||||
|
_, err := utils.Run(cmd)
|
||||||
|
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to run make generate")
|
||||||
|
|
||||||
|
By("generating manifests")
|
||||||
|
cmd = exec.Command("make", "manifests")
|
||||||
|
_, err = utils.Run(cmd)
|
||||||
|
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to run make manifests")
|
||||||
|
|
||||||
|
By("building the manager(Operator) image")
|
||||||
|
cmd = exec.Command("make", "docker-build", fmt.Sprintf("IMG=%s", projectImage))
|
||||||
|
_, err = utils.Run(cmd)
|
||||||
|
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to build the manager(Operator) image")
|
||||||
|
|
||||||
|
// TODO(user): If you want to change the e2e test vendor from Kind, ensure the image is
|
||||||
|
// built and available before running the tests. Also, remove the following block.
|
||||||
|
By("loading the manager(Operator) image on Kind")
|
||||||
|
err = utils.LoadImageToKindClusterWithName(projectImage)
|
||||||
|
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to load the manager(Operator) image into Kind")
|
||||||
|
|
||||||
|
// The tests-e2e are intended to run on a temporary cluster that is created and destroyed for testing.
|
||||||
|
// To prevent errors when tests run in environments with Prometheus or CertManager already installed,
|
||||||
|
// we check for their presence before execution.
|
||||||
|
// Setup Prometheus and CertManager before the suite if not skipped and if not already installed
|
||||||
|
if !skipPrometheusInstall {
|
||||||
|
By("checking if prometheus is installed already")
|
||||||
|
isPrometheusOperatorAlreadyInstalled = utils.IsPrometheusCRDsInstalled()
|
||||||
|
if !isPrometheusOperatorAlreadyInstalled {
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, "Installing Prometheus Operator...\n")
|
||||||
|
Expect(utils.InstallPrometheusOperator()).To(Succeed(), "Failed to install Prometheus Operator")
|
||||||
|
} else {
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, "WARNING: Prometheus Operator is already installed. Skipping installation...\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !skipCertManagerInstall {
|
||||||
|
By("checking if cert manager is installed already")
|
||||||
|
isCertManagerAlreadyInstalled = utils.IsCertManagerCRDsInstalled()
|
||||||
|
if !isCertManagerAlreadyInstalled {
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, "Installing CertManager...\n")
|
||||||
|
Expect(utils.InstallCertManager()).To(Succeed(), "Failed to install CertManager")
|
||||||
|
} else {
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, "WARNING: CertManager is already installed. Skipping installation...\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
var _ = AfterSuite(func() {
|
||||||
|
// Teardown Prometheus and CertManager after the suite if not skipped and if they were not already installed
|
||||||
|
if !skipPrometheusInstall && !isPrometheusOperatorAlreadyInstalled {
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, "Uninstalling Prometheus Operator...\n")
|
||||||
|
utils.UninstallPrometheusOperator()
|
||||||
|
}
|
||||||
|
if !skipCertManagerInstall && !isCertManagerAlreadyInstalled {
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, "Uninstalling CertManager...\n")
|
||||||
|
utils.UninstallCertManager()
|
||||||
|
}
|
||||||
|
})
|
||||||
307
test/e2e/e2e_test.go
Normal file
307
test/e2e/e2e_test.go
Normal file
@@ -0,0 +1,307 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package e2e
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"github.com/jkaninda/goma-operator/test/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
// namespace where the project is deployed in
|
||||||
|
const namespace = "goma-operator-system"
|
||||||
|
|
||||||
|
// serviceAccountName created for the project
|
||||||
|
const serviceAccountName = "goma-operator-controller-manager"
|
||||||
|
|
||||||
|
// metricsServiceName is the name of the metrics service of the project
|
||||||
|
const metricsServiceName = "goma-operator-controller-manager-metrics-service"
|
||||||
|
|
||||||
|
// metricsRoleBindingName is the name of the RBAC that will be created to allow get the metrics data
|
||||||
|
const metricsRoleBindingName = "goma-operator-metrics-binding"
|
||||||
|
|
||||||
|
var _ = Describe("Manager", Ordered, func() {
|
||||||
|
var controllerPodName string
|
||||||
|
|
||||||
|
// Before running the tests, set up the environment by creating the namespace,
|
||||||
|
// installing CRDs, and deploying the controller.
|
||||||
|
BeforeAll(func() {
|
||||||
|
By("creating manager namespace")
|
||||||
|
cmd := exec.Command("kubectl", "create", "ns", namespace)
|
||||||
|
_, err := utils.Run(cmd)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "Failed to create namespace")
|
||||||
|
|
||||||
|
By("installing CRDs")
|
||||||
|
cmd = exec.Command("make", "install")
|
||||||
|
_, err = utils.Run(cmd)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "Failed to install CRDs")
|
||||||
|
|
||||||
|
By("deploying the controller-manager")
|
||||||
|
cmd = exec.Command("make", "deploy", fmt.Sprintf("IMG=%s", projectImage))
|
||||||
|
_, err = utils.Run(cmd)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "Failed to deploy the controller-manager")
|
||||||
|
})
|
||||||
|
|
||||||
|
// After all tests have been executed, clean up by undeploying the controller, uninstalling CRDs,
|
||||||
|
// and deleting the namespace.
|
||||||
|
AfterAll(func() {
|
||||||
|
By("cleaning up the curl pod for metrics")
|
||||||
|
cmd := exec.Command("kubectl", "delete", "pod", "curl-metrics", "-n", namespace)
|
||||||
|
_, _ = utils.Run(cmd)
|
||||||
|
|
||||||
|
By("undeploying the controller-manager")
|
||||||
|
cmd = exec.Command("make", "undeploy")
|
||||||
|
_, _ = utils.Run(cmd)
|
||||||
|
|
||||||
|
By("uninstalling CRDs")
|
||||||
|
cmd = exec.Command("make", "uninstall")
|
||||||
|
_, _ = utils.Run(cmd)
|
||||||
|
|
||||||
|
By("removing manager namespace")
|
||||||
|
cmd = exec.Command("kubectl", "delete", "ns", namespace)
|
||||||
|
_, _ = utils.Run(cmd)
|
||||||
|
})
|
||||||
|
|
||||||
|
// After each test, check for failures and collect logs, events,
|
||||||
|
// and pod descriptions for debugging.
|
||||||
|
AfterEach(func() {
|
||||||
|
specReport := CurrentSpecReport()
|
||||||
|
if specReport.Failed() {
|
||||||
|
By("Fetching controller manager pod logs")
|
||||||
|
cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace)
|
||||||
|
controllerLogs, err := utils.Run(cmd)
|
||||||
|
if err == nil {
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Controller logs:\n %s", controllerLogs))
|
||||||
|
} else {
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get Controller logs: %s", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
By("Fetching Kubernetes events")
|
||||||
|
cmd = exec.Command("kubectl", "get", "events", "-n", namespace, "--sort-by=.lastTimestamp")
|
||||||
|
eventsOutput, err := utils.Run(cmd)
|
||||||
|
if err == nil {
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Kubernetes events:\n%s", eventsOutput))
|
||||||
|
} else {
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get Kubernetes events: %s", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
By("Fetching curl-metrics logs")
|
||||||
|
cmd = exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
|
||||||
|
metricsOutput, err := utils.Run(cmd)
|
||||||
|
if err == nil {
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Metrics logs:\n %s", metricsOutput))
|
||||||
|
} else {
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get curl-metrics logs: %s", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
By("Fetching controller manager pod description")
|
||||||
|
cmd = exec.Command("kubectl", "describe", "pod", controllerPodName, "-n", namespace)
|
||||||
|
podDescription, err := utils.Run(cmd)
|
||||||
|
if err == nil {
|
||||||
|
fmt.Println("Pod description:\n", podDescription)
|
||||||
|
} else {
|
||||||
|
fmt.Println("Failed to describe controller pod")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
SetDefaultEventuallyTimeout(2 * time.Minute)
|
||||||
|
SetDefaultEventuallyPollingInterval(time.Second)
|
||||||
|
|
||||||
|
Context("Manager", func() {
|
||||||
|
It("should run successfully", func() {
|
||||||
|
By("validating that the controller-manager pod is running as expected")
|
||||||
|
verifyControllerUp := func(g Gomega) {
|
||||||
|
// Get the name of the controller-manager pod
|
||||||
|
cmd := exec.Command("kubectl", "get",
|
||||||
|
"pods", "-l", "control-plane=controller-manager",
|
||||||
|
"-o", "go-template={{ range .items }}"+
|
||||||
|
"{{ if not .metadata.deletionTimestamp }}"+
|
||||||
|
"{{ .metadata.name }}"+
|
||||||
|
"{{ \"\\n\" }}{{ end }}{{ end }}",
|
||||||
|
"-n", namespace,
|
||||||
|
)
|
||||||
|
|
||||||
|
podOutput, err := utils.Run(cmd)
|
||||||
|
g.Expect(err).NotTo(HaveOccurred(), "Failed to retrieve controller-manager pod information")
|
||||||
|
podNames := utils.GetNonEmptyLines(podOutput)
|
||||||
|
g.Expect(podNames).To(HaveLen(1), "expected 1 controller pod running")
|
||||||
|
controllerPodName = podNames[0]
|
||||||
|
g.Expect(controllerPodName).To(ContainSubstring("controller-manager"))
|
||||||
|
|
||||||
|
// Validate the pod's status
|
||||||
|
cmd = exec.Command("kubectl", "get",
|
||||||
|
"pods", controllerPodName, "-o", "jsonpath={.status.phase}",
|
||||||
|
"-n", namespace,
|
||||||
|
)
|
||||||
|
output, err := utils.Run(cmd)
|
||||||
|
g.Expect(err).NotTo(HaveOccurred())
|
||||||
|
g.Expect(output).To(Equal("Running"), "Incorrect controller-manager pod status")
|
||||||
|
}
|
||||||
|
Eventually(verifyControllerUp).Should(Succeed())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should ensure the metrics endpoint is serving metrics", func() {
|
||||||
|
By("creating a ClusterRoleBinding for the service account to allow access to metrics")
|
||||||
|
cmd := exec.Command("kubectl", "create", "clusterrolebinding", metricsRoleBindingName,
|
||||||
|
"--clusterrole=goma-operator-metrics-reader",
|
||||||
|
fmt.Sprintf("--serviceaccount=%s:%s", namespace, serviceAccountName),
|
||||||
|
)
|
||||||
|
_, err := utils.Run(cmd)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "Failed to create ClusterRoleBinding")
|
||||||
|
|
||||||
|
By("validating that the metrics service is available")
|
||||||
|
cmd = exec.Command("kubectl", "get", "service", metricsServiceName, "-n", namespace)
|
||||||
|
_, err = utils.Run(cmd)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "Metrics service should exist")
|
||||||
|
|
||||||
|
By("validating that the ServiceMonitor for Prometheus is applied in the namespace")
|
||||||
|
cmd = exec.Command("kubectl", "get", "ServiceMonitor", "-n", namespace)
|
||||||
|
_, err = utils.Run(cmd)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "ServiceMonitor should exist")
|
||||||
|
|
||||||
|
By("getting the service account token")
|
||||||
|
token, err := serviceAccountToken()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(token).NotTo(BeEmpty())
|
||||||
|
|
||||||
|
By("waiting for the metrics endpoint to be ready")
|
||||||
|
verifyMetricsEndpointReady := func(g Gomega) {
|
||||||
|
cmd := exec.Command("kubectl", "get", "endpoints", metricsServiceName, "-n", namespace)
|
||||||
|
output, err := utils.Run(cmd)
|
||||||
|
g.Expect(err).NotTo(HaveOccurred())
|
||||||
|
g.Expect(output).To(ContainSubstring("8443"), "Metrics endpoint is not ready")
|
||||||
|
}
|
||||||
|
Eventually(verifyMetricsEndpointReady).Should(Succeed())
|
||||||
|
|
||||||
|
By("verifying that the controller manager is serving the metrics server")
|
||||||
|
verifyMetricsServerStarted := func(g Gomega) {
|
||||||
|
cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace)
|
||||||
|
output, err := utils.Run(cmd)
|
||||||
|
g.Expect(err).NotTo(HaveOccurred())
|
||||||
|
g.Expect(output).To(ContainSubstring("controller-runtime.metrics\tServing metrics server"),
|
||||||
|
"Metrics server not yet started")
|
||||||
|
}
|
||||||
|
Eventually(verifyMetricsServerStarted).Should(Succeed())
|
||||||
|
|
||||||
|
By("creating the curl-metrics pod to access the metrics endpoint")
|
||||||
|
cmd = exec.Command("kubectl", "run", "curl-metrics", "--restart=Never",
|
||||||
|
"--namespace", namespace,
|
||||||
|
"--image=curlimages/curl:7.78.0",
|
||||||
|
"--", "/bin/sh", "-c", fmt.Sprintf(
|
||||||
|
"curl -v -k -H 'Authorization: Bearer %s' https://%s.%s.svc.cluster.local:8443/metrics",
|
||||||
|
token, metricsServiceName, namespace))
|
||||||
|
_, err = utils.Run(cmd)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "Failed to create curl-metrics pod")
|
||||||
|
|
||||||
|
By("waiting for the curl-metrics pod to complete.")
|
||||||
|
verifyCurlUp := func(g Gomega) {
|
||||||
|
cmd := exec.Command("kubectl", "get", "pods", "curl-metrics",
|
||||||
|
"-o", "jsonpath={.status.phase}",
|
||||||
|
"-n", namespace)
|
||||||
|
output, err := utils.Run(cmd)
|
||||||
|
g.Expect(err).NotTo(HaveOccurred())
|
||||||
|
g.Expect(output).To(Equal("Succeeded"), "curl pod in wrong status")
|
||||||
|
}
|
||||||
|
Eventually(verifyCurlUp, 5*time.Minute).Should(Succeed())
|
||||||
|
|
||||||
|
By("getting the metrics by checking curl-metrics logs")
|
||||||
|
metricsOutput := getMetricsOutput()
|
||||||
|
Expect(metricsOutput).To(ContainSubstring(
|
||||||
|
"controller_runtime_reconcile_total",
|
||||||
|
))
|
||||||
|
})
|
||||||
|
|
||||||
|
// +kubebuilder:scaffold:e2e-webhooks-checks
|
||||||
|
|
||||||
|
// TODO: Customize the e2e test suite with scenarios specific to your project.
|
||||||
|
// Consider applying sample/CR(s) and check their status and/or verifying
|
||||||
|
// the reconciliation by using the metrics, i.e.:
|
||||||
|
// metricsOutput := getMetricsOutput()
|
||||||
|
// Expect(metricsOutput).To(ContainSubstring(
|
||||||
|
// fmt.Sprintf(`controller_runtime_reconcile_total{controller="%s",result="success"} 1`,
|
||||||
|
// strings.ToLower(<Kind>),
|
||||||
|
// ))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// serviceAccountToken returns a token for the specified service account in the given namespace.
|
||||||
|
// It uses the Kubernetes TokenRequest API to generate a token by directly sending a request
|
||||||
|
// and parsing the resulting token from the API response.
|
||||||
|
func serviceAccountToken() (string, error) {
|
||||||
|
const tokenRequestRawString = `{
|
||||||
|
"apiVersion": "authentication.k8s.io/v1",
|
||||||
|
"kind": "TokenRequest"
|
||||||
|
}`
|
||||||
|
|
||||||
|
// Temporary file to store the token request
|
||||||
|
secretName := fmt.Sprintf("%s-token-request", serviceAccountName)
|
||||||
|
tokenRequestFile := filepath.Join("/tmp", secretName)
|
||||||
|
err := os.WriteFile(tokenRequestFile, []byte(tokenRequestRawString), os.FileMode(0o644))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var out string
|
||||||
|
verifyTokenCreation := func(g Gomega) {
|
||||||
|
// Execute kubectl command to create the token
|
||||||
|
cmd := exec.Command("kubectl", "create", "--raw", fmt.Sprintf(
|
||||||
|
"/api/v1/namespaces/%s/serviceaccounts/%s/token",
|
||||||
|
namespace,
|
||||||
|
serviceAccountName,
|
||||||
|
), "-f", tokenRequestFile)
|
||||||
|
|
||||||
|
output, err := cmd.CombinedOutput()
|
||||||
|
g.Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
// Parse the JSON output to extract the token
|
||||||
|
var token tokenRequest
|
||||||
|
err = json.Unmarshal([]byte(output), &token)
|
||||||
|
g.Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
out = token.Status.Token
|
||||||
|
}
|
||||||
|
Eventually(verifyTokenCreation).Should(Succeed())
|
||||||
|
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// getMetricsOutput retrieves and returns the logs from the curl pod used to access the metrics endpoint.
|
||||||
|
func getMetricsOutput() string {
|
||||||
|
By("getting the curl-metrics logs")
|
||||||
|
cmd := exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
|
||||||
|
metricsOutput, err := utils.Run(cmd)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
|
||||||
|
Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
|
||||||
|
return metricsOutput
|
||||||
|
}
|
||||||
|
|
||||||
|
// tokenRequest is a simplified representation of the Kubernetes TokenRequest API response,
|
||||||
|
// containing only the token field that we need to extract.
|
||||||
|
type tokenRequest struct {
|
||||||
|
Status struct {
|
||||||
|
Token string `json:"token"`
|
||||||
|
} `json:"status"`
|
||||||
|
}
|
||||||
251
test/utils/utils.go
Normal file
251
test/utils/utils.go
Normal file
@@ -0,0 +1,251 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2" //nolint:golint,revive
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
prometheusOperatorVersion = "v0.77.1"
|
||||||
|
prometheusOperatorURL = "https://github.com/prometheus-operator/prometheus-operator/" +
|
||||||
|
"releases/download/%s/bundle.yaml"
|
||||||
|
|
||||||
|
certmanagerVersion = "v1.16.0"
|
||||||
|
certmanagerURLTmpl = "https://github.com/jetstack/cert-manager/releases/download/%s/cert-manager.yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
func warnError(err error) {
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, "warning: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run executes the provided command within this context
|
||||||
|
func Run(cmd *exec.Cmd) (string, error) {
|
||||||
|
dir, _ := GetProjectDir()
|
||||||
|
cmd.Dir = dir
|
||||||
|
|
||||||
|
if err := os.Chdir(cmd.Dir); err != nil {
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %s\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Env = append(os.Environ(), "GO111MODULE=on")
|
||||||
|
command := strings.Join(cmd.Args, " ")
|
||||||
|
_, _ = fmt.Fprintf(GinkgoWriter, "running: %s\n", command)
|
||||||
|
output, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return string(output), fmt.Errorf("%s failed with error: (%v) %s", command, err, string(output))
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(output), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// InstallPrometheusOperator installs the prometheus Operator to be used to export the enabled metrics.
|
||||||
|
func InstallPrometheusOperator() error {
|
||||||
|
url := fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion)
|
||||||
|
cmd := exec.Command("kubectl", "create", "-f", url)
|
||||||
|
_, err := Run(cmd)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// UninstallPrometheusOperator uninstalls the prometheus
|
||||||
|
func UninstallPrometheusOperator() {
|
||||||
|
url := fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion)
|
||||||
|
cmd := exec.Command("kubectl", "delete", "-f", url)
|
||||||
|
if _, err := Run(cmd); err != nil {
|
||||||
|
warnError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsPrometheusCRDsInstalled checks if any Prometheus CRDs are installed
|
||||||
|
// by verifying the existence of key CRDs related to Prometheus.
|
||||||
|
func IsPrometheusCRDsInstalled() bool {
|
||||||
|
// List of common Prometheus CRDs
|
||||||
|
prometheusCRDs := []string{
|
||||||
|
"prometheuses.monitoring.coreos.com",
|
||||||
|
"prometheusrules.monitoring.coreos.com",
|
||||||
|
"prometheusagents.monitoring.coreos.com",
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command("kubectl", "get", "crds", "-o", "custom-columns=NAME:.metadata.name")
|
||||||
|
output, err := Run(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
crdList := GetNonEmptyLines(string(output))
|
||||||
|
for _, crd := range prometheusCRDs {
|
||||||
|
for _, line := range crdList {
|
||||||
|
if strings.Contains(line, crd) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// UninstallCertManager uninstalls the cert manager
|
||||||
|
func UninstallCertManager() {
|
||||||
|
url := fmt.Sprintf(certmanagerURLTmpl, certmanagerVersion)
|
||||||
|
cmd := exec.Command("kubectl", "delete", "-f", url)
|
||||||
|
if _, err := Run(cmd); err != nil {
|
||||||
|
warnError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// InstallCertManager installs the cert manager bundle.
|
||||||
|
func InstallCertManager() error {
|
||||||
|
url := fmt.Sprintf(certmanagerURLTmpl, certmanagerVersion)
|
||||||
|
cmd := exec.Command("kubectl", "apply", "-f", url)
|
||||||
|
if _, err := Run(cmd); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Wait for cert-manager-webhook to be ready, which can take time if cert-manager
|
||||||
|
// was re-installed after uninstalling on a cluster.
|
||||||
|
cmd = exec.Command("kubectl", "wait", "deployment.apps/cert-manager-webhook",
|
||||||
|
"--for", "condition=Available",
|
||||||
|
"--namespace", "cert-manager",
|
||||||
|
"--timeout", "5m",
|
||||||
|
)
|
||||||
|
|
||||||
|
_, err := Run(cmd)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsCertManagerCRDsInstalled checks if any Cert Manager CRDs are installed
|
||||||
|
// by verifying the existence of key CRDs related to Cert Manager.
|
||||||
|
func IsCertManagerCRDsInstalled() bool {
|
||||||
|
// List of common Cert Manager CRDs
|
||||||
|
certManagerCRDs := []string{
|
||||||
|
"certificates.cert-manager.io",
|
||||||
|
"issuers.cert-manager.io",
|
||||||
|
"clusterissuers.cert-manager.io",
|
||||||
|
"certificaterequests.cert-manager.io",
|
||||||
|
"orders.acme.cert-manager.io",
|
||||||
|
"challenges.acme.cert-manager.io",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute the kubectl command to get all CRDs
|
||||||
|
cmd := exec.Command("kubectl", "get", "crds")
|
||||||
|
output, err := Run(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if any of the Cert Manager CRDs are present
|
||||||
|
crdList := GetNonEmptyLines(string(output))
|
||||||
|
for _, crd := range certManagerCRDs {
|
||||||
|
for _, line := range crdList {
|
||||||
|
if strings.Contains(line, crd) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
|
||||||
|
func LoadImageToKindClusterWithName(name string) error {
|
||||||
|
cluster := "kind"
|
||||||
|
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
|
||||||
|
cluster = v
|
||||||
|
}
|
||||||
|
kindOptions := []string{"load", "docker-image", name, "--name", cluster}
|
||||||
|
cmd := exec.Command("kind", kindOptions...)
|
||||||
|
_, err := Run(cmd)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetNonEmptyLines converts given command output string into individual objects
|
||||||
|
// according to line breakers, and ignores the empty elements in it.
|
||||||
|
func GetNonEmptyLines(output string) []string {
|
||||||
|
var res []string
|
||||||
|
elements := strings.Split(output, "\n")
|
||||||
|
for _, element := range elements {
|
||||||
|
if element != "" {
|
||||||
|
res = append(res, element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetProjectDir will return the directory where the project is
|
||||||
|
func GetProjectDir() (string, error) {
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return wd, err
|
||||||
|
}
|
||||||
|
wd = strings.Replace(wd, "/test/e2e", "", -1)
|
||||||
|
return wd, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UncommentCode searches for target in the file and remove the comment prefix
|
||||||
|
// of the target content. The target content may span multiple lines.
|
||||||
|
func UncommentCode(filename, target, prefix string) error {
|
||||||
|
// false positive
|
||||||
|
// nolint:gosec
|
||||||
|
content, err := os.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
strContent := string(content)
|
||||||
|
|
||||||
|
idx := strings.Index(strContent, target)
|
||||||
|
if idx < 0 {
|
||||||
|
return fmt.Errorf("unable to find the code %s to be uncomment", target)
|
||||||
|
}
|
||||||
|
|
||||||
|
out := new(bytes.Buffer)
|
||||||
|
_, err = out.Write(content[:idx])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(bytes.NewBufferString(target))
|
||||||
|
if !scanner.Scan() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
_, err := out.WriteString(strings.TrimPrefix(scanner.Text(), prefix))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Avoid writing a newline in case the previous line was the last in target.
|
||||||
|
if !scanner.Scan() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if _, err := out.WriteString("\n"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = out.Write(content[idx+len(target):])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// false positive
|
||||||
|
// nolint:gosec
|
||||||
|
return os.WriteFile(filename, out.Bytes(), 0644)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user