From 686dd5fba12ef3d72caac1244fc255729b6da7d5 Mon Sep 17 00:00:00 2001 From: "M. Mert Yildiran" Date: Wed, 19 Apr 2023 20:52:28 +0300 Subject: [PATCH] :fire: Remove the `-A` flag and `allnamespaces` field from `config.yaml` --- cmd/helmChart.go | 2 +- cmd/tap.go | 1 - config/configStructs/tapConfig.go | 2 -- helm-chart/templates/04-hub-pod.yaml | 2 +- helm-chart/values.yaml | 1 - kubernetes/provider.go | 19 ++----------------- 6 files changed, 4 insertions(+), 23 deletions(-) diff --git a/cmd/helmChart.go b/cmd/helmChart.go index 1f74ed981..ee8b12119 100644 --- a/cmd/helmChart.go +++ b/cmd/helmChart.go @@ -128,7 +128,7 @@ var hubPodMappings = map[string]interface{}{ }, { "name": "NAMESPACES", - "value": "{{ .Values.tap.allnamespaces | ternary \"\" .Values.tap.namespaces }}", + "value": "{{ gt (len .Values.tap.namespaces) 0 | ternary (join \",\" .Values.tap.namespaces) \"\" }}", }, { "name": "STORAGE_LIMIT", diff --git a/cmd/tap.go b/cmd/tap.go index da263e123..056613618 100644 --- a/cmd/tap.go +++ b/cmd/tap.go @@ -51,7 +51,6 @@ func init() { tapCmd.Flags().Uint16(configStructs.ProxyHubPortLabel, defaultTapConfig.Proxy.Hub.SrcPort, "Provide a custom port for the Hub proxy/port-forward") tapCmd.Flags().String(configStructs.ProxyHostLabel, defaultTapConfig.Proxy.Host, "Provide a custom host for the proxy/port-forward") tapCmd.Flags().StringSliceP(configStructs.NamespacesLabel, "n", defaultTapConfig.Namespaces, "Namespaces selector") - tapCmd.Flags().BoolP(configStructs.AllNamespacesLabel, "A", defaultTapConfig.AllNamespaces, "Tap all namespaces") tapCmd.Flags().StringP(configStructs.SelfNamespaceLabel, "s", defaultTapConfig.SelfNamespace, "Self-namespace of Kubeshark") tapCmd.Flags().String(configStructs.StorageLimitLabel, defaultTapConfig.StorageLimit, "Override the default storage limit. (per node)") tapCmd.Flags().Bool(configStructs.DryRunLabel, defaultTapConfig.DryRun, "Preview of all pods matching the regex, without tapping them") diff --git a/config/configStructs/tapConfig.go b/config/configStructs/tapConfig.go index 88457d94e..bc07e01e1 100644 --- a/config/configStructs/tapConfig.go +++ b/config/configStructs/tapConfig.go @@ -18,7 +18,6 @@ const ( ProxyHubPortLabel = "proxy-hub-port" ProxyHostLabel = "proxy-host" NamespacesLabel = "namespaces" - AllNamespacesLabel = "allnamespaces" SelfNamespaceLabel = "selfnamespace" StorageLimitLabel = "storagelimit" DryRunLabel = "dryrun" @@ -83,7 +82,6 @@ type TapConfig struct { Proxy ProxyConfig `yaml:"proxy"` PodRegexStr string `yaml:"regex" default:".*"` Namespaces []string `yaml:"namespaces"` - AllNamespaces bool `yaml:"allnamespaces" default:"true"` SelfNamespace string `yaml:"selfnamespace" default:"kubeshark"` StorageLimit string `yaml:"storagelimit" default:"200MB"` DryRun bool `yaml:"dryrun" default:"false"` diff --git a/helm-chart/templates/04-hub-pod.yaml b/helm-chart/templates/04-hub-pod.yaml index 59db0a8c5..d0d3cb938 100644 --- a/helm-chart/templates/04-hub-pod.yaml +++ b/helm-chart/templates/04-hub-pod.yaml @@ -18,7 +18,7 @@ spec: - name: POD_REGEX value: '{{ .Values.tap.regex }}' - name: NAMESPACES - value: '{{ .Values.tap.allnamespaces | ternary "" .Values.tap.namespaces }}' + value: '{{ gt (len .Values.tap.namespaces) 0 | ternary (join "," .Values.tap.namespaces) "" }}' - name: STORAGE_LIMIT value: '{{ .Values.tap.storagelimit }}' - name: LICENSE diff --git a/helm-chart/values.yaml b/helm-chart/values.yaml index cd4b28214..e1c6bab34 100644 --- a/helm-chart/values.yaml +++ b/helm-chart/values.yaml @@ -17,7 +17,6 @@ tap: host: 127.0.0.1 regex: .* namespaces: [] - allnamespaces: true selfnamespace: kubeshark storagelimit: 200MB dryrun: false diff --git a/kubernetes/provider.go b/kubernetes/provider.go index 08926671a..7c4ad29ac 100644 --- a/kubernetes/provider.go +++ b/kubernetes/provider.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "encoding/json" - "errors" "fmt" "io" "net/url" @@ -111,14 +110,6 @@ func NewProviderInCluster() (*Provider, error) { }, nil } -func (provider *Provider) CurrentNamespace() (string, error) { - if provider.kubernetesConfig == nil { - return "", errors.New("kubernetesConfig is nil, The CLI will not work with in-cluster kubernetes config, use a kubeconfig file when initializing the Provider") - } - ns, _, err := provider.kubernetesConfig.Namespace() - return ns, err -} - func (provider *Provider) WaitUtilNamespaceDeleted(ctx context.Context, name string) error { fieldSelector := fmt.Sprintf("metadata.name=%s", name) var limit int64 = 1 @@ -1133,16 +1124,10 @@ func (provider *Provider) GetKubernetesVersion() (*semver.SemVersion, error) { } func (provider *Provider) GetNamespaces() []string { - if config.Config.Tap.AllNamespaces { - return []string{K8sAllNamespaces} - } else if len(config.Config.Tap.Namespaces) > 0 { + if len(config.Config.Tap.Namespaces) > 0 { return utils.Unique(config.Config.Tap.Namespaces) } else { - currentNamespace, err := provider.CurrentNamespace() - if err != nil { - log.Fatal().Err(err).Msg("Error getting current namespace!") - } - return []string{currentNamespace} + return []string{K8sAllNamespaces} } }