-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit eaf7965
Showing
3,188 changed files
with
1,149,436 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
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,22 @@ | ||
name: Lint | ||
|
||
on: | ||
push | ||
|
||
jobs: | ||
lint: | ||
name: 📋 Lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: ⬇️ Git clone the repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: 📦 Install Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: '1.23' | ||
|
||
- name: 🧪 Revive | ||
run: | | ||
go install github.com/mgechev/revive@latest | ||
make lint |
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,50 @@ | ||
name: Release Github Package | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
platforms: linux/amd64,linux/arm64 |
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 @@ | ||
/.idea |
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,9 @@ | ||
FROM golang:1.23 AS builder | ||
COPY . /go/src/github.com/skpr/k8s-mutate-nodeselector | ||
WORKDIR /go/src/github.com/skpr/k8s-mutate-nodeselector | ||
RUN CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o skpr-k8s-mutate-nodeselector github.com/skpr/k8s-mutate-nodeselector/cmd/skpr-k8s-mutate-nodeselector | ||
|
||
FROM alpine:3.20 | ||
COPY --from=builder /go/src/github.com/skpr/k8s-mutate-nodeselector/skpr-k8s-mutate-nodeselector /usr/local/bin/skpr-k8s-mutate-nodeselector | ||
RUN chmod +x /usr/local/bin/skpr-k8s-mutate-nodeselector | ||
CMD ["/usr/local/bin/skpr-k8s-mutate-nodeselector"] |
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,6 @@ | ||
#!/usr/bin/make -f | ||
|
||
lint: | ||
revive -set_exit_status -exclude=./vendor/... ./... | ||
|
||
.PHONY: * |
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,96 @@ | ||
package main | ||
|
||
import ( | ||
"log/slog" | ||
"net/http" | ||
"os" | ||
"time" | ||
|
||
"github.com/christgf/env" | ||
"github.com/spf13/cobra" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/tools/clientcmd" | ||
|
||
"github.com/skpr/k8s-mutate-nodeselector/internal/mutator" | ||
) | ||
|
||
var ( | ||
cmdLong = ` | ||
Run the mutating webhook server` | ||
|
||
cmdExample = ` | ||
# Using flags. | ||
k8s-mutate-nodeselector --cert=/path/to/my/certificate --key=/path/to/my/key | ||
# Using environment variables | ||
export K8S_MUTATE_NODESELECTOR_CERT=/path/to/my/certificate | ||
export K8S_MUTATE_NODESELECTOR_KEY=/path/to/my/key | ||
k8s-mutate-nodeselector` | ||
) | ||
|
||
// Options for this application. | ||
type Options struct { | ||
Port string | ||
KubeConfig string | ||
CertFilePath string | ||
KeyFilePath string | ||
} | ||
|
||
func main() { | ||
o := Options{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "k8s-mutate-nodeselector", | ||
Short: "Run the mutating webhook server", | ||
Long: cmdLong, | ||
Example: cmdExample, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{})) | ||
|
||
logger.Info("Starting server") | ||
|
||
config, err := clientcmd.BuildConfigFromFlags("", o.KubeConfig) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientset, err := kubernetes.NewForConfig(config) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientset.CoreV1().Namespaces() | ||
|
||
mux := http.NewServeMux() | ||
|
||
handler := mutator.NewHandler(logger, clientset.CoreV1().Namespaces()) | ||
|
||
mux.HandleFunc("/mutate", handler.Handle) | ||
|
||
s := &http.Server{ | ||
Addr: o.Port, | ||
Handler: mux, | ||
ReadTimeout: 10 * time.Second, | ||
WriteTimeout: 10 * time.Second, | ||
MaxHeaderBytes: 1 << 20, // 1048576 | ||
} | ||
|
||
err = s.ListenAndServeTLS(o.CertFilePath, o.KeyFilePath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
cmd.PersistentFlags().StringVar(&o.Port, "port", env.String("K8S_MUTATE_NODESELECTOR_PORT", ":8443"), "Port which this webserver will receive requests") | ||
cmd.PersistentFlags().StringVar(&o.KubeConfig, "kubeconfig", env.String("K8S_MUTATE_NODESELECTOR_KUBECONFIG", ""), "Path to the kubeconfig file") | ||
cmd.PersistentFlags().StringVar(&o.CertFilePath, "cert", env.String("K8S_MUTATE_NODESELECTOR_CERT", ""), "Path to the certificate file") | ||
cmd.PersistentFlags().StringVar(&o.KeyFilePath, "key", env.String("K8S_MUTATE_NODESELECTOR_KEY", ""), "Path to the key file") | ||
|
||
err := cmd.Execute() | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
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,55 @@ | ||
module github.com/skpr/k8s-mutate-nodeselector | ||
|
||
go 1.22.6 | ||
|
||
require ( | ||
github.com/christgf/env v0.0.0-20230511114549-ccdc1a7b5961 | ||
github.com/spf13/cobra v1.8.1 | ||
github.com/stretchr/testify v1.9.0 | ||
k8s.io/api v0.31.3 | ||
k8s.io/apimachinery v0.31.3 | ||
k8s.io/client-go v0.31.3 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect | ||
github.com/emicklei/go-restful/v3 v3.11.0 // indirect | ||
github.com/fxamacker/cbor/v2 v2.7.0 // indirect | ||
github.com/go-logr/logr v1.4.2 // 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/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.4 // 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/uuid v1.6.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/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/x448/float16 v0.8.4 // indirect | ||
golang.org/x/net v0.26.0 // indirect | ||
golang.org/x/oauth2 v0.21.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 | ||
google.golang.org/protobuf v1.34.2 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // 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/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 | ||
) |
Oops, something went wrong.