Skip to content

Commit

Permalink
refactor: add default values to effective config in reconciler (#2180)
Browse files Browse the repository at this point in the history
This adds the default values of `ignoredNamesapces` and
`ignoreContainers` with the effective config reconcile, so it behaves
the same way helm-vs-cli and also updated correctly on `odigos-config`
changes.
  • Loading branch information
blumamir authored Jan 10, 2025
1 parent 04e3894 commit b8eedeb
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 68 deletions.
14 changes: 5 additions & 9 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/odigos-io/odigos/cli/pkg/autodetect"
"github.com/odigos-io/odigos/common/consts"

"github.com/odigos-io/odigos/cli/pkg/labels"

Expand All @@ -17,8 +18,6 @@ import (
"github.com/odigos-io/odigos/cli/pkg/kube"
"github.com/odigos-io/odigos/cli/pkg/log"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/common/consts"
"github.com/odigos-io/odigos/common/utils"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -205,11 +204,8 @@ func validateUserInputProfiles(tier common.OdigosTier) {
}

func createOdigosConfig(odigosTier common.OdigosTier) common.OdigosConfiguration {
fullIgnoredNamespaces := utils.MergeDefaultIgnoreWithUserInput(userInputIgnoredNamespaces, consts.SystemNamespaces)
fullIgnoredContainers := utils.MergeDefaultIgnoreWithUserInput(userInputIgnoredContainers, consts.IgnoredContainers)

selectedProfiles := []common.ProfileName{}

for _, profile := range userInputInstallProfiles {
selectedProfiles = append(selectedProfiles, common.ProfileName(profile))
}
Expand All @@ -218,8 +214,8 @@ func createOdigosConfig(odigosTier common.OdigosTier) common.OdigosConfiguration
ConfigVersion: 1, // config version starts at 1 and incremented on every config change
TelemetryEnabled: telemetryEnabled,
OpenshiftEnabled: openshiftEnabled,
IgnoredNamespaces: fullIgnoredNamespaces,
IgnoredContainers: fullIgnoredContainers,
IgnoredNamespaces: userInputIgnoredNamespaces,
IgnoredContainers: userInputIgnoredContainers,
SkipWebhookIssuerCreation: skipWebhookIssuerCreation,
Psp: psp,
ImagePrefix: imagePrefix,
Expand Down Expand Up @@ -254,8 +250,8 @@ func init() {
installCmd.Flags().StringVar(&autoScalerImage, "autoscaler-image", "keyval/odigos-autoscaler", "autoscaler container image name")
installCmd.Flags().StringVar(&imagePrefix, "image-prefix", "", "prefix for all container images. used when your cluster doesn't have access to docker hub")
installCmd.Flags().BoolVar(&psp, "psp", false, "enable pod security policy")
installCmd.Flags().StringSliceVar(&userInputIgnoredNamespaces, "ignore-namespace", consts.SystemNamespaces, "namespaces not to show in odigos ui")
installCmd.Flags().StringSliceVar(&userInputIgnoredContainers, "ignore-container", consts.IgnoredContainers, "container names to exclude from instrumentation (useful for sidecar container)")
installCmd.Flags().StringSliceVar(&userInputIgnoredNamespaces, "ignore-namespace", k8sconsts.DefaultIgnoredNamespaces, "namespaces not to show in odigos ui")
installCmd.Flags().StringSliceVar(&userInputIgnoredContainers, "ignore-container", k8sconsts.DefaultIgnoredContainers, "container names to exclude from instrumentation (useful for sidecar container)")
installCmd.Flags().StringSliceVar(&userInputInstallProfiles, "profile", []string{}, "install preset profiles with a specific configuration")

if OdigosVersion != "" {
Expand Down
5 changes: 0 additions & 5 deletions cli/cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"github.com/odigos-io/odigos/cli/cmd/resources/odigospro"
cmdcontext "github.com/odigos-io/odigos/cli/pkg/cmd_context"
"github.com/odigos-io/odigos/cli/pkg/confirm"
"github.com/odigos-io/odigos/common/consts"
"github.com/odigos-io/odigos/common/utils"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -107,9 +105,6 @@ and apply any required migrations and adaptations.`,
// update the config on upgrade
config.ConfigVersion += 1

// make sure the current system namespaces is in the ignored in config
config.IgnoredNamespaces = utils.MergeDefaultIgnoreWithUserInput(config.IgnoredNamespaces, consts.SystemNamespaces)

currentTier, err := odigospro.GetCurrentOdigosTier(ctx, client, ns)
if err != nil {
fmt.Println("Odigos cloud login failed - unable to read the current Odigos tier.")
Expand Down
5 changes: 0 additions & 5 deletions common/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,3 @@ const (
var (
ErrorPodsNotFound = errors.New("could not find a ready pod")
)

var (
SystemNamespaces = []string{DefaultOdigosNamespace, "kube-system", "local-path-storage", "istio-system", "linkerd", "kube-node-lease"}
IgnoredContainers = []string{"istio-proxy", "vault-agent", "filebeat", "linkerd-proxy", "fluentd", "akeyless-init"}
)
33 changes: 0 additions & 33 deletions common/utils/ignoredns.go

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/services/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (

"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/k8sutils/pkg/client"
"github.com/odigos-io/odigos/k8sutils/pkg/utils"
"sigs.k8s.io/yaml"

"k8s.io/apimachinery/pkg/runtime/schema"

"golang.org/x/sync/errgroup"

"github.com/odigos-io/odigos/common/consts"
"github.com/odigos-io/odigos/common/utils"

"github.com/odigos-io/odigos/frontend/graph/model"
"github.com/odigos-io/odigos/frontend/kube"
Expand Down
20 changes: 7 additions & 13 deletions helm/odigos/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@ image:
tag: ""
imagePullSecrets: []

# namespaces not to show in odigos ui
# namespaces list not to show in odigos ui
# set by default: odigos-system, kube-system, local-path-storage, istio-system, linkerd, kube-node-lease, odigos-system
# you can add additional namespaces to ignore by adding them to the list
ignoredNamespaces:
- odigos-system
- kube-system
- local-path-storage
- istio-system
- linkerd
- kube-node-lease

# container names to never instrument
# useful for sidecars which are not interesting to be instrumented
# set by default: istio-proxy, vault-agent, filebeat, linkerd-proxy, fluentd, akeyless-init
# you can add additional container names to ignore by adding them to the list
ignoredContainers:
- istio-proxy
- vault-agent
- filebeat
- linkerd-proxy
- fluentd
- akeyless-init

collectorGateway:
# the memory request for the cluster gateway collector deployment.
Expand Down
7 changes: 6 additions & 1 deletion k8sutils/pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package consts

import "k8s.io/apimachinery/pkg/util/version"

var (
DefaultIgnoredNamespaces = []string{"kube-system", "local-path-storage", "istio-system", "linkerd", "kube-node-lease"}
DefaultIgnoredContainers = []string{"istio-proxy", "vault-agent", "filebeat", "linkerd-proxy", "fluentd", "akeyless-init"}
)

type CollectorRole string

const (
Expand Down Expand Up @@ -69,4 +74,4 @@ var (
const (
OdigosCloudApiKeySecretKey = "odigos-cloud-api-key"
OdigosOnpremTokenSecretKey = "odigos-onprem-token"
)
)
10 changes: 10 additions & 0 deletions k8sutils/pkg/utils/config_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package utils

func IsItemIgnored(item string, ignoredItems []string) bool {
for _, ignoredItem := range ignoredItems {
if item == ignoredItem {
return true
}
}
return false
}
2 changes: 1 addition & 1 deletion odiglet/pkg/kube/runtime_details/inspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/common/envOverwrite"
"github.com/odigos-io/odigos/common/utils"
criwrapper "github.com/odigos-io/odigos/k8sutils/pkg/cri"
"github.com/odigos-io/odigos/k8sutils/pkg/utils"
"github.com/odigos-io/odigos/k8sutils/pkg/workload"
kubeutils "github.com/odigos-io/odigos/odiglet/pkg/kube/utils"
"github.com/odigos-io/odigos/odiglet/pkg/log"
Expand Down
8 changes: 8 additions & 0 deletions scheduler/controllers/odigosconfig/odigosconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/common/consts"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/env"
"github.com/odigos-io/odigos/k8sutils/pkg/profiles"
corev1 "k8s.io/api/core/v1"
Expand All @@ -28,6 +29,13 @@ func (r *odigosConfigController) Reconcile(ctx context.Context, _ ctrl.Request)
return ctrl.Result{}, err
}

// make sure the default ignored namespaces are always present
odigosConfig.IgnoredNamespaces = mergeIgnoredItemLists(odigosConfig.IgnoredNamespaces, k8sconsts.DefaultIgnoredNamespaces)
odigosConfig.IgnoredNamespaces = append(odigosConfig.IgnoredNamespaces, env.GetCurrentNamespace())

// make sure the default ignored containers are always present
odigosConfig.IgnoredContainers = mergeIgnoredItemLists(odigosConfig.IgnoredContainers, k8sconsts.DefaultIgnoredContainers)

applyProfilesToOdigosConfig(odigosConfig)

err = r.persistEffectiveConfig(ctx, odigosConfig)
Expand Down
20 changes: 20 additions & 0 deletions scheduler/controllers/odigosconfig/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package odigosconfig

func mergeIgnoredItemLists(l1 []string, l2 []string) []string {

merged := map[string]struct{}{}

for _, i := range l1 {
merged[i] = struct{}{}
}
for _, i := range l2 {
merged[i] = struct{}{}
}

mergedList := make([]string, 0, len(merged))
for i := range merged {
mergedList = append(mergedList, i)
}

return mergedList
}

0 comments on commit b8eedeb

Please sign in to comment.