chickenzord / kube-annotate Goto Github PK
View Code? Open in Web Editor NEWKubernetes mutating admission webhook to automatically annotate pods
License: MIT License
Kubernetes mutating admission webhook to automatically annotate pods
License: MIT License
kube-annotate/annotator/handler.go
Line 13 in d034d81
kube-annotate/annotator/handler.go
Line 15 in d034d81
Only the first read works, the second one returns empty as the stream has already been processed. See this post on Reddit:
https://www.reddit.com/r/golang/comments/8mfex0/why_requestbody_is_empty_after_decoding_or_reading/
Hello.
I'm looking for something like this project to annotate arbitrary objects, using label selectors and jsonpath matchers.
My first use-case is to add some annotations to Ingress objects only if they match a specific host.
I believe the config would be something like this:
# config.yaml
- apiVersion: networking.k8s.io/v1
kind: Ingress
namespaceSelector:
team: web
selector:
app: frontend
annotations:
haproxy.router.openshift.io/response-header.X-Robots-Tag: "noindex, nofollow"
matches:
- '$.spec.rules[?(@.host=="www.example.com")]'
- ...
Is it something you are willing to accept a PR? If not, please let me known and I'll fork it to (try) to implement it myself (not a golang programer though).
Best,
Mateus
I trying to add a annotation when a pod is created to allow cluster autoscaler delete an instance manager, but looks like I'm missing something.
webhook:
apiVersion: admissionregistration.k8s.io/v1beta1
kind: MutatingWebhookConfiguration
metadata:
name: kube-annotate
labels:
app: kube-annotate
webhooks:
- name: kube-annotate.example.com
clientConfig:
service:
name: kube-annotate
namespace: kube-annotate # NOTE: replace this with namespace where you deploy `kube-annotate`
path: "/mutate"
caBundle: <removed>
rules:
- operations: [ "CREATE" ]
apiGroups: [""]
apiVersions: ["v1"]
resources: ["pods"]
namespaceSelector:
matchLabels:
kube-annotate: 'enabled'
deployment:
` - name: kube-annotate
image: docker.io/chickenzord/kube-annotate:latest
imagePullPolicy: Always
env:
- name: TLS_ENABLED
value: 'true'
- name: TLS_CRT
value: /var/run/secrets/tls/tlscert
- name: TLS_KEY
value: /var/run/secrets/tls/tlskey
- name: RULES_FILE
value: /etc/kube-annotate/rules.yaml
- name: LOG_FORMAT
value: json
- name: LOG_LEVEL
value: debug
`
config map:
`cat configmap.yaml
apiVersion: v1
data:
rules.yaml: |
- selector:
longhorn.io/component: instance-manager
annotations:
cluster-autoscaler.kubernetes.io/safe-to-evict: true
kind: ConfigMap
metadata:
labels:
app: kube-annotate
name: kube-annotate-config
namespace: kube-annotate
`
Error:
`kubectl logs -lapp=kube-annotate -n kube-annotate -f
github.com/chickenzord/kube-annotate/vendor/github.com/urfave/negroni.middleware.ServeHTTP(0xe0bd80, 0xc00024ac60, 0xc0002554e0, 0x7fbed03e2020, 0xc00014e058, 0xc000332600)
/go/src/github.com/chickenzord/kube-annotate/vendor/github.com/urfave/negroni/negroni.go:38 +0x9c
github.com/chickenzord/kube-annotate/vendor/github.com/urfave/negroni.(*Negroni).ServeHTTP(0xc00024da10, 0xe18ea0, 0xc00031c380, 0xc000332600)
/go/src/github.com/chickenzord/kube-annotate/vendor/github.com/urfave/negroni/negroni.go:96 +0xee
net/http.serverHandler.ServeHTTP(0xc00026ab60, 0xe18ea0, 0xc00031c380, 0xc000332600)
/usr/local/go/src/net/http/server.go:2741 +0xab
net/http.(*conn).serve(0xc00032c140, 0xe19ba0, 0xc000262680)
/usr/local/go/src/net/http/server.go:1847 +0x646
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2851 +0x2f5
{"level":"info","msg":"starting kube-annotate version 0.3.4 (7291937)","time":"2021-04-09T18:42:48Z"}
{"level":"info","msg":"loaded 1 rule(s) from /etc/kube-annotate/rules.yaml","time":"2021-04-09T18:42:48Z"}
{"level":"info","msg":"internal server is listening on :8081","time":"2021-04-09T18:42:48Z"}
{"level":"info","msg":"API server is listening on :8443","time":"2021-04-09T18:42:48Z"}
{"level":"debug","msg":"API server TLS is enabled","time":"2021-04-09T18:42:48Z"}
{"level":"info","msg":"starting kube-annotate version 0.3.4 (7291937)","time":"2021-04-09T18:42:48Z"}
{"level":"info","msg":"loaded 1 rule(s) from /etc/kube-annotate/rules.yaml","time":"2021-04-09T18:42:48Z"}
{"level":"info","msg":"internal server is listening on :8081","time":"2021-04-09T18:42:48Z"}
{"level":"info","msg":"API server is listening on :8443","time":"2021-04-09T18:42:48Z"}
{"level":"debug","msg":"API server TLS is enabled","time":"2021-04-09T18:42:48Z"}
`
Any ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.