diff --git a/cli/cmd/install.go b/cli/cmd/install.go index ad64e8225..a2fe8e455 100644 --- a/cli/cmd/install.go +++ b/cli/cmd/install.go @@ -13,6 +13,7 @@ import ( odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1" "github.com/odigos-io/odigos/common" "github.com/odigos-io/odigos/common/consts" + "github.com/odigos-io/odigos/common/utils" "github.com/odigos-io/odigos/cli/cmd/resources" "github.com/odigos-io/odigos/cli/pkg/kube" @@ -24,15 +25,14 @@ import ( ) var ( - odigosCloudApiKeyFlag string - odigosOnPremToken string - namespaceFlag string - versionFlag string - skipWait bool - telemetryEnabled bool - psp bool - ignoredNamespaces []string - DefaultIgnoredNamespaces = []string{"odigos-system", "kube-system", "local-path-storage", "istio-system", "linkerd", "kube-node-lease"} + odigosCloudApiKeyFlag string + odigosOnPremToken string + namespaceFlag string + versionFlag string + skipWait bool + telemetryEnabled bool + psp bool + userInputIgnoredNamespaces []string instrumentorImage string odigletImage string @@ -56,7 +56,6 @@ This command will install k8s components that will auto-instrument your applicat } ctx := cmd.Context() ns := cmd.Flag("namespace").Value.String() - cmd.Flags().StringSliceVar(&ignoredNamespaces, "ignore-namespace", DefaultIgnoredNamespaces, "--ignore-namespace foo logging") // Check if Odigos already installed cm, err := client.CoreV1().ConfigMaps(ns).Get(ctx, resources.OdigosDeploymentConfigMapName, metav1.GetOptions{}) @@ -165,11 +164,13 @@ func createNamespace(ctx context.Context, cmd *cobra.Command, client *kube.Clien func createOdigosConfigSpec() odigosv1.OdigosConfigurationSpec { + fullIgnoredNamespaces := utils.AddSystemNamespacesToIgnored(userInputIgnoredNamespaces, consts.SystemNamespaces) + return odigosv1.OdigosConfigurationSpec{ OdigosVersion: versionFlag, ConfigVersion: 1, // config version starts at 1 and incremented on every config change TelemetryEnabled: telemetryEnabled, - IgnoredNamespaces: ignoredNamespaces, + IgnoredNamespaces: fullIgnoredNamespaces, Psp: psp, ImagePrefix: imagePrefix, OdigletImage: odigletImage, @@ -200,6 +201,7 @@ 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") if OdigosVersion != "" { versionFlag = OdigosVersion diff --git a/cli/cmd/upgrade.go b/cli/cmd/upgrade.go index 5219e082f..ebb14c3c8 100644 --- a/cli/cmd/upgrade.go +++ b/cli/cmd/upgrade.go @@ -13,6 +13,8 @@ import ( "github.com/odigos-io/odigos/cli/cmd/resources/odigospro" "github.com/odigos-io/odigos/cli/pkg/confirm" "github.com/odigos-io/odigos/cli/pkg/kube" + "github.com/odigos-io/odigos/common/consts" + "github.com/odigos-io/odigos/common/utils" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -99,6 +101,9 @@ and apply any required migrations and adaptations.`, config.Spec.OdigosVersion = versionFlag config.Spec.ConfigVersion += 1 + // make sure the current system namespaces is in the ignored in config + config.Spec.IgnoredNamespaces = utils.AddSystemNamespacesToIgnored(config.Spec.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.") diff --git a/common/consts/consts.go b/common/consts/consts.go index 56ed11e64..4f3097ca9 100644 --- a/common/consts/consts.go +++ b/common/consts/consts.go @@ -1,6 +1,8 @@ package consts -import "errors" +import ( + "errors" +) const ( CurrentNamespaceEnvVar = "CURRENT_NS" @@ -23,3 +25,7 @@ const ( var ( PodsNotFoundErr = errors.New("could not find a ready pod") ) + +var ( + SystemNamespaces = []string{DefaultNamespace, "kube-system", "local-path-storage", "istio-system", "linkerd", "kube-node-lease"} +) diff --git a/common/utils/ignoredns.go b/common/utils/ignoredns.go new file mode 100644 index 000000000..06ce1f3ff --- /dev/null +++ b/common/utils/ignoredns.go @@ -0,0 +1,33 @@ +package utils + +func arrayContainsString(arr []string, str string) bool { + for _, elem := range arr { + if elem == str { + return true + } + } + return false +} + +func AddSystemNamespacesToIgnored(userIgnoredNamespaces []string, systemNamespaces []string) []string { + + mergedList := make([]string, len(userIgnoredNamespaces)) + copy(mergedList, userIgnoredNamespaces) + + for _, ns := range systemNamespaces { + if !arrayContainsString(mergedList, ns) { + mergedList = append(mergedList, ns) + } + } + + return mergedList +} + +func IsNamespaceIgnored(namespace string, ignoredNamespaces []string) bool { + for _, ignoredNamespace := range ignoredNamespaces { + if namespace == ignoredNamespace { + return true + } + } + return false +} diff --git a/docs/cli/odigos_install.mdx b/docs/cli/odigos_install.mdx index 9eb715aca..1db64a96e 100644 --- a/docs/cli/odigos_install.mdx +++ b/docs/cli/odigos_install.mdx @@ -42,6 +42,7 @@ odigos install [flags] --autoscaler-image autoscaler container image name --image-prefix prefix for collector images. Used when your cluster doesn't have access to docker hub. --psp enable pod security policy + --ignore-namespace namespaces not to show in odigos ui ``` The `--api-key` is required if you use Odigos Cloud. diff --git a/frontend/endpoints/applications.go b/frontend/endpoints/applications.go index 2c6a69786..2130499f1 100644 --- a/frontend/endpoints/applications.go +++ b/frontend/endpoints/applications.go @@ -42,12 +42,6 @@ func GetApplicationsInNamespace(c *gin.Context) { return } - if IsSystemNamespace(request.Namespace) { - // skip system namespaces which should not be instrumented - c.JSON(http.StatusOK, GetApplicationsInNamespaceResponse{}) - return - } - ctx := c.Request.Context() deps, err := getDeployments(request.Namespace, ctx) if err != nil { diff --git a/frontend/endpoints/namespaces.go b/frontend/endpoints/namespaces.go index 377729765..2c1d9dda9 100644 --- a/frontend/endpoints/namespaces.go +++ b/frontend/endpoints/namespaces.go @@ -8,6 +8,7 @@ import ( "go.uber.org/multierr" "github.com/odigos-io/odigos/common/consts" + "github.com/odigos-io/odigos/common/utils" "github.com/odigos-io/odigos/frontend/kube" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -26,7 +27,14 @@ type GetNamespaceItem struct { TotalApps int `json:"totalApps"` } -func GetNamespaces(c *gin.Context) { +func GetNamespaces(c *gin.Context, odigosns string) { + + odigosConfig, err := kube.DefaultClient.OdigosClient.OdigosConfigurations(odigosns).Get(c.Request.Context(), "odigos-config", metav1.GetOptions{}) + if err != nil { + returnError(c, err) + return + } + list, err := kube.DefaultClient.CoreV1().Namespaces().List(c.Request.Context(), metav1.ListOptions{}) if err != nil { returnError(c, err) @@ -41,9 +49,7 @@ func GetNamespaces(c *gin.Context) { var response GetNamespacesResponse for _, namespace := range list.Items { - - if IsSystemNamespace(namespace.Name) { - // skip system namespaces which should not be instrumented + if utils.IsNamespaceIgnored(namespace.Name, odigosConfig.Spec.IgnoredNamespaces) { continue } @@ -81,10 +87,6 @@ func PersistNamespaces(c *gin.Context) { } for nsName, nsItem := range request { - if IsSystemNamespace(nsName) { - // skip system namespaces which should not be instrumented - continue - } jsonMergePayload := getJsonMergePatchForInstrumentationLabel(nsItem.FutureSelected) _, err := kube.DefaultClient.CoreV1().Namespaces().Patch(c.Request.Context(), nsName, types.MergePatchType, jsonMergePayload, metav1.PatchOptions{}) diff --git a/frontend/endpoints/utils.go b/frontend/endpoints/utils.go index 911800375..525dbcee4 100644 --- a/frontend/endpoints/utils.go +++ b/frontend/endpoints/utils.go @@ -5,7 +5,6 @@ import ( "errors" "path" - "github.com/odigos-io/odigos/common/consts" "github.com/odigos-io/odigos/frontend/kube" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -17,16 +16,6 @@ func GetImageURL(image string) string { return path.Join(cdnUrl, image) } -// TODO: read this from the odigosconfig CRD -func IsSystemNamespace(namespace string) bool { - return namespace == "kube-system" || - namespace == consts.DefaultNamespace || - namespace == "local-path-storage" || - namespace == "istio-system" || - namespace == "linkerd" || - namespace == "kube-node-lease" -} - func setWorkloadInstrumentationLabel(ctx context.Context, nsName string, workloadName string, workloadKind WorkloadKind, enabled *bool) error { jsonMergePatchData := getJsonMergePatchForInstrumentationLabel(enabled) diff --git a/frontend/main.go b/frontend/main.go index 58163c66f..b977e3ff4 100644 --- a/frontend/main.go +++ b/frontend/main.go @@ -88,7 +88,7 @@ func startHTTPServer(flags *Flags) (*gin.Engine, error) { // Serve API apis := r.Group("/api") { - apis.GET("/namespaces", endpoints.GetNamespaces) + apis.GET("/namespaces", func(c *gin.Context) { endpoints.GetNamespaces(c, flags.Namespace) }) apis.POST("/namespaces", endpoints.PersistNamespaces) apis.GET("/sources", endpoints.GetSources) diff --git a/frontend/webapp/components/setup/sources/sources.option.menu/filter.sources.options.tsx b/frontend/webapp/components/setup/sources/sources.option.menu/filter.sources.options.tsx index 8363a75f7..7d34b8dee 100644 --- a/frontend/webapp/components/setup/sources/sources.option.menu/filter.sources.options.tsx +++ b/frontend/webapp/components/setup/sources/sources.option.menu/filter.sources.options.tsx @@ -3,13 +3,12 @@ import { DropdownWrapper } from './sources.option.menu.styled'; import { KeyvalDropDown, KeyvalSearchInput, KeyvalText } from '@/design.system'; import { SETUP } from '@/utils/constants'; -const DEFAULT_DROPDOWN_VALUE = { id: 0, label: 'default' }; - export function FilterSourcesOptions({ setCurrentItem, data, searchFilter, setSearchFilter, + currentNamespace, }: any) { function handleDropDownChange(item: any) { setCurrentItem({ id: item?.id, name: item.label }); @@ -24,7 +23,7 @@ export function FilterSourcesOptions({ {SETUP.MENU.NAMESPACES} diff --git a/frontend/webapp/components/setup/sources/sources.option.menu/sources.option.menu.tsx b/frontend/webapp/components/setup/sources/sources.option.menu/sources.option.menu.tsx index 1037e2515..75f5cdf26 100644 --- a/frontend/webapp/components/setup/sources/sources.option.menu/sources.option.menu.tsx +++ b/frontend/webapp/components/setup/sources/sources.option.menu/sources.option.menu.tsx @@ -16,6 +16,7 @@ export function SourcesOptionMenu({ return ( item.name === DEFAULT - ); + ) ?? data?.namespaces[0]; setCurrentNamespace(currentNamespace); } }, [data]);