This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
9,135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: Traefik Hub Static Analyzer | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
checks: write | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: azure/setup-kubectl@v3 | ||
- run: | | ||
kubectl kustomize apps/base/ -o /tmp/kubecon/data.yaml | ||
- name: Split | ||
uses: mikefarah/yq@master | ||
working-directory: /tmp/kubecon | ||
with: | ||
cmd: yq --split-exp '.metadata.name + ".yaml"' --no-doc /tmp/kubecon/data.yaml | ||
|
||
- run: | | ||
rm /tmp/kubecon/data.yaml | ||
- name: Lint Traefik Hub CRDs with hub-static-analyzer | ||
uses: traefik/hub-static-analyzer-action@main | ||
with: | ||
token: ${{ secrets.GH_TOKEN }} | ||
lint: true | ||
path: "/tmp/kubecon" | ||
lint-format: checkstyle | ||
lint-output-file: ./output.xml | ||
|
||
- name: Annotate code | ||
if: ${{ !cancelled() }} | ||
uses: Juuxel/publish-checkstyle-report@v1 | ||
with: | ||
reports: | | ||
./output.xml | ||
diff: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
checks: write | ||
contents: write | ||
pull-requests: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Lint Traefik Hub CRDs with hub-static-analyzer | ||
uses: traefik/hub-static-analyzer-action@main | ||
with: | ||
token: ${{ secrets.GH_TOKEN }} | ||
diff: true | ||
diff-range: "origin/${GITHUB_BASE_REF}...origin/${GITHUB_HEAD_REF}" | ||
diff-output-file: ./output.md | ||
|
||
- name: Prepare report | ||
shell: bash | ||
run: | | ||
set -u | ||
echo "# Traefik Hub Report:" > header.md | ||
echo "" >> header.md | ||
echo "The following changes have been detected." >> header.md | ||
echo "" >> header.md | ||
- name: Write report | ||
if: ${{ hashFiles('./output.md') != ''}} | ||
uses: mshick/add-pr-comment@v2 | ||
with: | ||
message-path: | | ||
header.md | ||
output.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# syntax=docker/dockerfile:1.2 | ||
# Alpine | ||
FROM alpine | ||
|
||
RUN apk --no-cache --no-progress add ca-certificates tzdata git \ | ||
&& rm -rf /var/cache/apk/* | ||
|
||
ARG TARGETPLATFORM | ||
COPY ./dist/$TARGETPLATFORM/api-server / | ||
|
||
ENTRYPOINT ["/api-server"] | ||
EXPOSE 3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.PHONY: default check test build image | ||
|
||
# Default build target | ||
GOOS := $(shell go env GOOS) | ||
GOARCH := $(shell go env GOARCH) | ||
DOCKER_BUILD_PLATFORMS ?= linux/amd64,linux/arm64 | ||
|
||
default: check test build | ||
|
||
dist: | ||
mkdir dist | ||
|
||
build: dist | ||
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -v -trimpath -ldflags '-s' -o "./dist/${GOOS}/${GOARCH}/api-server" . | ||
|
||
test: | ||
go test -v -cover ./... | ||
|
||
check: | ||
golangci-lint run | ||
|
||
build-linux-arm64: export GOOS := linux | ||
build-linux-arm64: export GOARCH := arm64 | ||
build-linux-arm64: | ||
make build | ||
|
||
build-linux-amd64: export GOOS := linux | ||
build-linux-amd64: export GOARCH := amd64 | ||
build-linux-amd64: | ||
make build | ||
|
||
## Build Multi archs Docker image | ||
multi-arch-image-%: build-linux-amd64 build-linux-arm64 | ||
docker buildx build $(DOCKER_BUILDX_ARGS) -t mmatur/traefik-hub:$* --platform=$(DOCKER_BUILD_PLATFORMS) . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module api-server | ||
|
||
go 1.21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"math/rand" | ||
"net/http" | ||
"os" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
func main() { | ||
openapispec := flag.String("openapi", "", "openapispec") | ||
datafile := flag.String("data", "", "file to put data in") | ||
latency := flag.Duration("latency", 0, "latency to add") | ||
errorrate := flag.Int("errorrate", 0, "latency to add") | ||
flag.Parse() | ||
|
||
var openapi []byte | ||
|
||
if openapispec != nil && *openapispec != "" { | ||
var err error | ||
openapi, err = os.ReadFile(*openapispec) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
var data []byte | ||
if datafile != nil && *datafile != "" { | ||
var err error | ||
data, err = os.ReadFile(*datafile) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
log.Fatal(http.ListenAndServe(":3000", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { | ||
if req.URL.Path == "/openapi.yaml" { | ||
_, _ = rw.Write(openapi) | ||
return | ||
} | ||
|
||
if latency != nil && *latency > 0 { | ||
time.Sleep(*latency) | ||
} | ||
|
||
status := req.URL.Query().Get("status") | ||
if status == "" { | ||
if errorrate != nil && *errorrate > 0 { | ||
if rand.Int()%100 < *errorrate { | ||
rw.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
} | ||
switch req.Method { | ||
case http.MethodGet, http.MethodPut: | ||
rw.WriteHeader(http.StatusOK) | ||
_, _ = rw.Write(data) | ||
case http.MethodPost: | ||
rw.WriteHeader(http.StatusCreated) | ||
_, _ = rw.Write([]byte(`{"id":4}`)) | ||
case http.MethodDelete: | ||
rw.WriteHeader(http.StatusNoContent) | ||
} | ||
|
||
return | ||
} | ||
|
||
atoi, err := strconv.Atoi(status) | ||
if err != nil { | ||
http.Error(rw, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
rw.WriteHeader(atoi) | ||
}))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
apiVersion: hub.traefik.io/v1alpha1 | ||
kind: APIAccess | ||
metadata: | ||
name: crm-internal | ||
spec: | ||
groups: | ||
- internal | ||
apiSelector: | ||
matchLabels: | ||
module: crm | ||
area: employee | ||
|
||
--- | ||
apiVersion: hub.traefik.io/v1alpha1 | ||
kind: APIAccess | ||
metadata: | ||
name: crm-all | ||
spec: | ||
groups: | ||
- crm-user | ||
apiCollectionSelector: | ||
matchLabels: | ||
module: crm | ||
|
||
--- | ||
apiVersion: hub.traefik.io/v1alpha1 | ||
kind: APIAccess | ||
metadata: | ||
name: custom-pick | ||
spec: | ||
groups: | ||
- support | ||
apis: | ||
- name: world-time-api-external-name | ||
namespace: apps | ||
apiSelector: | ||
matchExpressions: | ||
- key: area | ||
operator: In | ||
values: | ||
- flights | ||
- tickets | ||
|
||
--- | ||
apiVersion: hub.traefik.io/v1alpha1 | ||
kind: APIAccess | ||
metadata: | ||
name: admins | ||
spec: | ||
groups: | ||
- admin | ||
apiSelector: | ||
matchExpressions: | ||
- key: area | ||
operator: Exists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: hub.traefik.io/v1alpha1 | ||
kind: APICollection | ||
metadata: | ||
name: crm-all | ||
labels: | ||
module: crm | ||
spec: | ||
pathPrefix: "/crm" | ||
apiSelector: | ||
matchLabels: | ||
module: crm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
apiVersion: hub.traefik.io/v1alpha1 | ||
kind: APIGateway | ||
metadata: | ||
name: my-gateway | ||
labels: | ||
area: crm | ||
spec: | ||
apiAccesses: | ||
- crm-all | ||
- crm-internal | ||
- admins | ||
- custom-pick | ||
# customDomains: | ||
# - gateway.YOUR_ENV_NAME.demo.traefiklabs.tech |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
apiVersion: hub.traefik.io/v1alpha1 | ||
kind: APIPortal | ||
metadata: | ||
name: my-kubecon-portal | ||
spec: | ||
title: "Traefik Kubecon" | ||
description: "API Portal for Kubecon" | ||
apiGateway: my-gateway | ||
# ui: | ||
# logoUrl: https://traefik.io/favicon.png | ||
# ui: | ||
# service: | ||
# name: hub-apiportal-ui | ||
# namespace: portal-ui | ||
# port: | ||
# number: 80 | ||
# customDomains: | ||
# - portal.YOUR_ENV_NAME.demo.traefiklabs.tech |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
apiVersion: hub.traefik.io/v1alpha1 | ||
kind: APIRateLimit | ||
metadata: | ||
name: crm-user-ratelimit | ||
spec: | ||
limit: 2 # 2 requests | ||
period: 5s # 5 seconds | ||
groups: | ||
- crm-user | ||
apiSelector: | ||
matchLabels: | ||
module: crm | ||
apis: | ||
- name: employee-api | ||
namespace: apps | ||
--- | ||
apiVersion: hub.traefik.io/v1alpha1 | ||
kind: APIRateLimit | ||
metadata: | ||
name: support-ratelimit | ||
spec: | ||
limit: 15 | ||
period: 1m | ||
groups: | ||
- support | ||
apiSelector: | ||
matchExpressions: | ||
- key: area | ||
operator: In | ||
values: | ||
- flights | ||
- tickets | ||
--- | ||
apiVersion: hub.traefik.io/v1alpha1 | ||
kind: APIRateLimit | ||
metadata: | ||
name: fallback-ratelimit | ||
spec: | ||
limit: 2000 | ||
period: 65s | ||
anyGroups: true | ||
apiSelector: {} |
Oops, something went wrong.