From e5966f38ab61267452ceb04514fd1d5b18d7ba0b Mon Sep 17 00:00:00 2001 From: John Long Date: Tue, 21 May 2024 12:33:20 -0400 Subject: [PATCH] added flag to operator to enable default telemetry --- README.md | 5 +++-- components/operator/main.go | 16 ++++++++++------ components/operator/webhook/platform_webhook.go | 11 +++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index fca2a1c..8009665 100644 --- a/README.md +++ b/README.md @@ -91,13 +91,14 @@ create a new kind cluster. ```shell kind create cluster --wait 5m +export BRANCH=$(git rev-parse --abbrev-ref HEAD) ``` Then, build all the components and load their container images into the kind cluster. ```shell -make all KIND_LOAD=true +make all KIND_LOAD=true VERSION="${BRANCH}" ``` Now, install the KubeFox Operator using the current branch name as the image @@ -107,7 +108,7 @@ tag. helm install kubefox kubefox \ --repo https://xigxog.github.io/helm-charts \ --create-namespace --namespace kubefox-system \ - --set log.format=console --set log.level=debug --set image.tag=$(git rev-parse --abbrev-ref HEAD) \ + --set log.format=console --set log.level=debug --set image.tag="${BRANCH}" \ --wait ``` diff --git a/components/operator/main.go b/components/operator/main.go index 7b7e3be..5427f35 100644 --- a/components/operator/main.go +++ b/components/operator/main.go @@ -59,11 +59,12 @@ func init() { kutil.Must(apiv1.AddToScheme(scheme)) } +// TODO move to config struct var ( - instance, namespace string - vaultURL, healthAddr string - logFormat, logLevel string - leaderElection bool + instance, namespace string + vaultURL, healthAddr string + logFormat, logLevel string + leaderElection, defTelemetry bool ) func main() { @@ -74,6 +75,7 @@ func main() { flag.BoolVar(&leaderElection, "leader-elect", true, "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.") flag.StringVar(&logFormat, "log-format", "console", `Log format; one of ["json", "console"].`) flag.StringVar(&logLevel, "log-level", "debug", `Log level; one of ["debug", "info", "warn", "error"].`) + flag.BoolVar(&defTelemetry, "default-telemetry", false, `Enables use of default telemetry configuration from Helm chart.`) flag.Parse() utils.CheckRequiredFlag("instance", instance) @@ -191,8 +193,10 @@ func main() { }) mgr.GetWebhookServer().Register("/v1alpha1/platforms/mutate", &kwebhook.Admission{ Handler: &webhook.PlatformWebhook{ - Client: &ctrlClient.Client, - Decoder: admission.NewDecoder(scheme), + Client: &ctrlClient.Client, + Decoder: admission.NewDecoder(scheme), + Namespace: namespace, + DefTelemetry: defTelemetry, }, }) mgr.GetWebhookServer().Register("/secrets/mutate", &kwebhook.Admission{ diff --git a/components/operator/webhook/platform_webhook.go b/components/operator/webhook/platform_webhook.go index f6c0568..cb3e476 100644 --- a/components/operator/webhook/platform_webhook.go +++ b/components/operator/webhook/platform_webhook.go @@ -24,6 +24,9 @@ import ( type PlatformWebhook struct { *k8s.Client admission.Decoder + + Namespace string + DefTelemetry bool } func (r *PlatformWebhook) Handle(ctx context.Context, req admission.Request) admission.Response { @@ -67,6 +70,14 @@ func (r *PlatformWebhook) Handle(ctx context.Context, req admission.Request) adm defaults.Set(&platform.Spec.Broker.ContainerSpec, &defaults.Broker) defaults.Set(&platform.Spec.HTTPSrv.ContainerSpec, &defaults.HTTPSrv) + if r.DefTelemetry && + !platform.Spec.Telemetry.Collector.Enabled && + platform.Spec.Telemetry.Collector.Address == "" { + + platform.Spec.Telemetry.Collector.Enabled = true + platform.Spec.Telemetry.Collector.Address = fmt.Sprintf("jaeger-agent.%s:4317", r.Namespace) + } + current, err := json.Marshal(platform) if err != nil { return admission.Errored(http.StatusInternalServerError, err)