Skip to content

Commit

Permalink
added flag to operator to enable default telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
xadhatter committed May 21, 2024
1 parent 382060d commit e5966f3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```

Expand Down
16 changes: 10 additions & 6 deletions components/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand Down Expand Up @@ -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{
Expand Down
11 changes: 11 additions & 0 deletions components/operator/webhook/platform_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e5966f3

Please sign in to comment.