feat: to unstructured
This commit is contained in:
@@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -19,6 +20,7 @@ import (
|
||||
kwhmodel "github.com/slok/kubewebhook/v2/pkg/model"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
type wrapLogger struct {
|
||||
@@ -35,20 +37,13 @@ func (n *wrapLogger) Warningf(template string, args ...interface{}) {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
WebhookListenAddr string
|
||||
TLSCertFilePath string
|
||||
TLSKeyFilePath string
|
||||
EnableIngressSingleHost bool
|
||||
IngressHostRegexes []string
|
||||
MinSMScrapeInterval time.Duration
|
||||
|
||||
LabelMarks map[string]string
|
||||
WebhookListenAddr string
|
||||
TLSCertFilePath string
|
||||
TLSKeyFilePath string
|
||||
}
|
||||
|
||||
var (
|
||||
cmdConfig = &Config{
|
||||
LabelMarks: map[string]string{},
|
||||
}
|
||||
cmdConfig = &Config{}
|
||||
serverCmd = &cobra.Command{
|
||||
Use: "server",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
@@ -83,7 +78,16 @@ var (
|
||||
{
|
||||
logger := logger.With(zap.String("addr", cmdConfig.WebhookListenAddr), zap.String("http-server", "webhooks"))
|
||||
mt := kwhmutating.MutatorFunc(func(_ context.Context, _ *kwhmodel.AdmissionReview, obj metav1.Object) (*kwhmutating.MutatorResult, error) {
|
||||
logger.Info("mutating webhook called", zap.Any("object", obj))
|
||||
o, err := obj.(runtime.Unstructured)
|
||||
if !err {
|
||||
return nil, fmt.Errorf("could not type assert to unstructured")
|
||||
}
|
||||
|
||||
m := o.UnstructuredContent()
|
||||
|
||||
o.SetUnstructuredContent(m)
|
||||
|
||||
logger.Info("mutating webhook called", zap.Any("object", m))
|
||||
return &kwhmutating.MutatorResult{MutatedObject: obj}, nil
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user