Skip to content

Commit

Permalink
Add ignore namespace option as a flag (#59)
Browse files Browse the repository at this point in the history
Roadmap:

- [x] Add namespace ignoring for controller
- [x] Add namespace option in `values.yaml` on
https://github.com/keyval-dev/odigos-charts
- [x] Test Cases
  - [x] Default namespaces from the code (moved to helm)
  - [x] Single namespace is given
  - [x] No namespace is given
  - [x] Multiple namespace is given
  - [x] Single non-existing namespace is given
  - [x] Multiple namespaces given but one is not existing
  - [x] Multiple namespaces given but more than one are not existing
  • Loading branch information
eugercek authored Feb 4, 2023
1 parent 3b8a462 commit d889c8b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
5 changes: 5 additions & 0 deletions cli/cmd/resources/instrumentor.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ func NewInstrumentorDeployment(version string, telemetryEnabled bool) *appsv1.De
"--health-probe-bind-address=:8081",
"--metrics-bind-address=127.0.0.1:8080",
"--leader-elect",
"--ignore-namespace=odigos-system",
"--ignore-namespace=kube-system",
"--ignore-namespace=local-path-storage",
"--ignore-namespace=istio-system",
"--ignore-namespace=linkerd",
fmt.Sprintf("--lang-detector-tag=%s", version),
fmt.Sprintf("--lang-detector-image=%s", langDetectorImage),
}
Expand Down
16 changes: 6 additions & 10 deletions instrumentor/controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,22 @@ import (
)

var (
IgnoredNamespaces = []string{"kube-system", "local-path-storage", "istio-system", "linkerd", consts.DefaultNamespace}
// IgnoredNamespaces have [odigos-system kube-system local-path-storage istio-system linkerd] by default
IgnoredNamespaces map[string]bool
SkipAnnotation = "odigos.io/skip"

DeploymentPrefix = "deployment-"
StatefulSetPrefix = "statefulset-"
)

func shouldSkip(annotations map[string]string, namespace string) bool {
for k, v := range annotations {
if k == SkipAnnotation && v == "true" {
return true
}
if val, ok := annotations[SkipAnnotation]; ok && val == "true" {
return true
}

for _, ns := range IgnoredNamespaces {
if namespace == ns {
return true
}
if _, ok := IgnoredNamespaces[namespace]; ok {
return true
}

return false
}

Expand Down
28 changes: 27 additions & 1 deletion instrumentor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ package main

import (
"flag"
"github.com/keyval-dev/odigos/instrumentor/report"
"os"
"strings"

v1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1"
"github.com/keyval-dev/odigos/instrumentor/report"

"github.com/keyval-dev/odigos/instrumentor/controllers"

Expand Down Expand Up @@ -57,6 +58,7 @@ func main() {
var langDetectorTag string
var langDetectorImage string
var deleteLangDetectionPods bool
var ignoredNameSpaces stringslice
var telemetryDisabled bool

flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
Expand All @@ -67,6 +69,7 @@ func main() {
flag.StringVar(&langDetectorTag, "lang-detector-tag", "latest", "container tag to use for lang detection")
flag.StringVar(&langDetectorImage, "lang-detector-image", "ghcr.io/keyval-dev/odigos/lang-detector", "container image to use for lang detection")
flag.BoolVar(&deleteLangDetectionPods, "delete-detection-pods", true, "Automatic termination of detection pods")
flag.Var(&ignoredNameSpaces, "ignore-namespace", "The ignored namespaces")
flag.BoolVar(&telemetryDisabled, "telemetry-disabled", false, "Disable telemetry")

opts := zap.Options{
Expand All @@ -77,6 +80,9 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

controllers.IgnoredNamespaces = generateIgnoredNamesSpacesMap(ignoredNameSpaces)
setupLog.Info("ignored namespaces from flags", "namespaces", ignoredNameSpaces)

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Expand Down Expand Up @@ -142,3 +148,23 @@ func main() {
os.Exit(1)
}
}

type stringslice []string

func (s *stringslice) Set(val string) error {
*s = append(*s, val)
return nil
}

func (s *stringslice) String() string {
return strings.Join(*s, " ")
}

func generateIgnoredNamesSpacesMap(nss []string) map[string]bool {
m := make(map[string]bool)
for _, v := range nss {
m[v] = true
}

return m
}

0 comments on commit d889c8b

Please sign in to comment.