diff --git a/cmd/clean.go b/cmd/clean.go index d5813646d..69020f489 100644 --- a/cmd/clean.go +++ b/cmd/clean.go @@ -33,5 +33,5 @@ func init() { log.Debug().Err(err).Send() } - cleanCmd.Flags().StringP(configStructs.SelfNamespaceLabel, "s", defaultTapConfig.SelfNamespace, "Self-namespace of Kubeshark") + cleanCmd.Flags().StringP(configStructs.ReleaseNamespaceLabel, "s", defaultTapConfig.ReleaseNamespace, "Self-namespace of Kubeshark") } diff --git a/cmd/common.go b/cmd/common.go index b48dbbd49..3a8f513d1 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -18,7 +18,7 @@ import ( ) func startProxyReportErrorIfAny(kubernetesProvider *kubernetes.Provider, ctx context.Context, serviceName string, podName string, proxyPortLabel string, srcPort uint16, dstPort uint16, healthCheck string) { - httpServer, err := kubernetes.StartProxy(kubernetesProvider, config.Config.Tap.Proxy.Host, srcPort, config.Config.Tap.SelfNamespace, serviceName) + httpServer, err := kubernetes.StartProxy(kubernetesProvider, config.Config.Tap.Proxy.Host, srcPort, config.Config.Tap.ReleaseNamespace, serviceName) if err != nil { log.Error(). Err(errormessage.FormatError(err)). @@ -38,7 +38,7 @@ func startProxyReportErrorIfAny(kubernetesProvider *kubernetes.Provider, ctx con } podRegex, _ := regexp.Compile(podName) - if _, err := kubernetes.NewPortForward(kubernetesProvider, config.Config.Tap.SelfNamespace, podRegex, srcPort, dstPort, ctx); err != nil { + if _, err := kubernetes.NewPortForward(kubernetesProvider, config.Config.Tap.ReleaseNamespace, podRegex, srcPort, dstPort, ctx); err != nil { log.Error(). Str("pod-regex", podRegex.String()). Err(errormessage.FormatError(err)). diff --git a/cmd/proxyRunner.go b/cmd/proxyRunner.go index 640514c3d..d126908dd 100644 --- a/cmd/proxyRunner.go +++ b/cmd/proxyRunner.go @@ -23,7 +23,7 @@ func runProxy(block bool, noBrowser bool) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - exists, err := kubernetesProvider.DoesServiceExist(ctx, config.Config.Tap.SelfNamespace, kubernetes.FrontServiceName) + exists, err := kubernetesProvider.DoesServiceExist(ctx, config.Config.Tap.ReleaseNamespace, kubernetes.FrontServiceName) if err != nil { log.Error(). Str("service", kubernetes.FrontServiceName). @@ -42,7 +42,7 @@ func runProxy(block bool, noBrowser bool) { return } - exists, err = kubernetesProvider.DoesServiceExist(ctx, config.Config.Tap.SelfNamespace, kubernetes.HubServiceName) + exists, err = kubernetesProvider.DoesServiceExist(ctx, config.Config.Tap.ReleaseNamespace, kubernetes.HubServiceName) if err != nil { log.Error(). Str("service", kubernetes.HubServiceName). diff --git a/cmd/tap.go b/cmd/tap.go index 51d2844ac..5191deec0 100644 --- a/cmd/tap.go +++ b/cmd/tap.go @@ -51,7 +51,7 @@ func init() { tapCmd.Flags().Uint16(configStructs.ProxyHubPortLabel, defaultTapConfig.Proxy.Hub.Port, "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().StringP(configStructs.SelfNamespaceLabel, "s", defaultTapConfig.SelfNamespace, "Self-namespace of Kubeshark") + tapCmd.Flags().StringP(configStructs.ReleaseNamespaceLabel, "s", defaultTapConfig.ReleaseNamespace, "Self-namespace of Kubeshark") tapCmd.Flags().Bool(configStructs.PersistentStorageLabel, defaultTapConfig.PersistentStorage, "Enable persistent storage (PersistentVolumeClaim)") tapCmd.Flags().String(configStructs.StorageLimitLabel, defaultTapConfig.StorageLimit, "Override the default storage limit (per node)") tapCmd.Flags().String(configStructs.StorageClassLabel, defaultTapConfig.StorageClass, "Override the default storage class of the PersistentVolumeClaim (per node)") diff --git a/cmd/tapRunner.go b/cmd/tapRunner.go index e17f3fe91..467f3cc33 100644 --- a/cmd/tapRunner.go +++ b/cmd/tapRunner.go @@ -78,8 +78,8 @@ func tap() { state.targetNamespaces = kubernetesProvider.GetNamespaces() if config.Config.IsNsRestrictedMode() { - if len(state.targetNamespaces) != 1 || !utils.Contains(state.targetNamespaces, config.Config.Tap.SelfNamespace) { - log.Error().Msg(fmt.Sprintf("%s can't resolve IPs in other namespaces when running in namespace restricted mode. You can use the same namespace for --%s and --%s", misc.Software, configStructs.NamespacesLabel, configStructs.SelfNamespaceLabel)) + if len(state.targetNamespaces) != 1 || !utils.Contains(state.targetNamespaces, config.Config.Tap.ReleaseNamespace) { + log.Error().Msg(fmt.Sprintf("%s can't resolve IPs in other namespaces when running in namespace restricted mode. You can use the same namespace for --%s and --%s", misc.Software, configStructs.NamespacesLabel, configStructs.ReleaseNamespaceLabel)) return } } @@ -125,7 +125,7 @@ func printProxyCommandSuggestion() { } func finishTapExecution(kubernetesProvider *kubernetes.Provider) { - finishSelfExecution(kubernetesProvider, config.Config.IsNsRestrictedMode(), config.Config.Tap.SelfNamespace) + finishSelfExecution(kubernetesProvider, config.Config.IsNsRestrictedMode(), config.Config.Tap.ReleaseNamespace) } /* @@ -158,7 +158,7 @@ func printNoPodsFoundSuggestion(targetNamespaces []string) { func watchHubPod(ctx context.Context, kubernetesProvider *kubernetes.Provider, cancel context.CancelFunc) { podExactRegex := regexp.MustCompile(fmt.Sprintf("^%s$", kubernetes.HubPodName)) podWatchHelper := kubernetes.NewPodWatchHelper(kubernetesProvider, podExactRegex) - eventChan, errorChan := kubernetes.FilteredWatch(ctx, podWatchHelper, []string{config.Config.Tap.SelfNamespace}, podWatchHelper) + eventChan, errorChan := kubernetes.FilteredWatch(ctx, podWatchHelper, []string{config.Config.Tap.ReleaseNamespace}, podWatchHelper) isPodReady := false timeAfter := time.After(120 * time.Second) @@ -225,7 +225,7 @@ func watchHubPod(ctx context.Context, kubernetesProvider *kubernetes.Provider, c log.Error(). Str("pod", kubernetes.HubPodName). - Str("namespace", config.Config.Tap.SelfNamespace). + Str("namespace", config.Config.Tap.ReleaseNamespace). Err(err). Msg("Failed creating pod.") cancel() @@ -249,7 +249,7 @@ func watchHubPod(ctx context.Context, kubernetesProvider *kubernetes.Provider, c func watchFrontPod(ctx context.Context, kubernetesProvider *kubernetes.Provider, cancel context.CancelFunc) { podExactRegex := regexp.MustCompile(fmt.Sprintf("^%s$", kubernetes.FrontPodName)) podWatchHelper := kubernetes.NewPodWatchHelper(kubernetesProvider, podExactRegex) - eventChan, errorChan := kubernetes.FilteredWatch(ctx, podWatchHelper, []string{config.Config.Tap.SelfNamespace}, podWatchHelper) + eventChan, errorChan := kubernetes.FilteredWatch(ctx, podWatchHelper, []string{config.Config.Tap.ReleaseNamespace}, podWatchHelper) isPodReady := false timeAfter := time.After(120 * time.Second) @@ -314,7 +314,7 @@ func watchFrontPod(ctx context.Context, kubernetesProvider *kubernetes.Provider, log.Error(). Str("pod", kubernetes.FrontPodName). - Str("namespace", config.Config.Tap.SelfNamespace). + Str("namespace", config.Config.Tap.ReleaseNamespace). Err(err). Msg("Failed creating pod.") @@ -337,7 +337,7 @@ func watchFrontPod(ctx context.Context, kubernetesProvider *kubernetes.Provider, func watchHubEvents(ctx context.Context, kubernetesProvider *kubernetes.Provider, cancel context.CancelFunc) { podExactRegex := regexp.MustCompile(fmt.Sprintf("^%s", kubernetes.HubPodName)) eventWatchHelper := kubernetes.NewEventWatchHelper(kubernetesProvider, podExactRegex, "pod") - eventChan, errorChan := kubernetes.FilteredWatch(ctx, eventWatchHelper, []string{config.Config.Tap.SelfNamespace}, eventWatchHelper) + eventChan, errorChan := kubernetes.FilteredWatch(ctx, eventWatchHelper, []string{config.Config.Tap.ReleaseNamespace}, eventWatchHelper) for { select { case wEvent, ok := <-eventChan: diff --git a/config/configStruct.go b/config/configStruct.go index b15d2a4ee..c80329fd7 100644 --- a/config/configStruct.go +++ b/config/configStruct.go @@ -53,7 +53,7 @@ func (config *ConfigStruct) ImagePullSecrets() []v1.LocalObjectReference { } func (config *ConfigStruct) IsNsRestrictedMode() bool { - return config.Tap.SelfNamespace != misc.Program // Notice "kubeshark" string must match the default SelfNamespace + return config.Tap.ReleaseNamespace != misc.Program // Notice "kubeshark" string must match the default ReleaseNamespace } func (config *ConfigStruct) KubeConfigPath() string { diff --git a/config/configStructs/tapConfig.go b/config/configStructs/tapConfig.go index 85339f55f..2a5e23940 100644 --- a/config/configStructs/tapConfig.go +++ b/config/configStructs/tapConfig.go @@ -17,7 +17,7 @@ const ( ProxyHubPortLabel = "proxy-hub-port" ProxyHostLabel = "proxy-host" NamespacesLabel = "namespaces" - SelfNamespaceLabel = "selfnamespace" + ReleaseNamespaceLabel = "releasenamespace" PersistentStorageLabel = "persistentstorage" StorageLimitLabel = "storagelimit" StorageClassLabel = "storageclass" @@ -99,7 +99,7 @@ type TapConfig struct { Proxy ProxyConfig `yaml:"proxy" json:"proxy"` PodRegexStr string `yaml:"regex" json:"regex" default:".*"` Namespaces []string `yaml:"namespaces" json:"namespaces" default:"[]"` - SelfNamespace string `yaml:"selfnamespace" json:"selfnamespace" default:"kubeshark"` + ReleaseNamespace string `yaml:"releasenamespace" json:"releasenamespace" default:"default"` PersistentStorage bool `yaml:"persistentstorage" json:"persistentstorage" default:"false"` StorageLimit string `yaml:"storagelimit" json:"storagelimit" default:"200Mi"` StorageClass string `yaml:"storageclass" json:"storageclass" default:"standard"` diff --git a/errormessage/errormessage.go b/errormessage/errormessage.go index de4f4650e..4d1ee539f 100644 --- a/errormessage/errormessage.go +++ b/errormessage/errormessage.go @@ -22,9 +22,9 @@ func FormatError(err error) error { "in the config file or setting the targeted namespace with --%s %s=", err, misc.Software, - configStructs.SelfNamespaceLabel, + configStructs.ReleaseNamespaceLabel, config.SetCommandName, - configStructs.SelfNamespaceLabel) + configStructs.ReleaseNamespaceLabel) } else if syntaxError, isSyntaxError := asRegexSyntaxError(err); isSyntaxError { errorNew = fmt.Errorf("regex %s is invalid: %w", syntaxError.Expr, err) } else { diff --git a/helm-chart/templates/00-namespace.yaml b/helm-chart/templates/00-namespace.yaml deleted file mode 100644 index 3456fba20..000000000 --- a/helm-chart/templates/00-namespace.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -apiVersion: v1 -kind: Namespace -metadata: - creationTimestamp: null - labels: - {{- if .Values.tap.labels }} - {{- toYaml .Values.tap.labels | nindent 4 }} - {{- end }} - annotations: - {{- if .Values.tap.annotations }} - {{- toYaml .Values.tap.annotations | nindent 4 }} - {{- end }} - name: {{ .Values.tap.selfnamespace }} -spec: {} -status: {} diff --git a/helm-chart/templates/01-service-account.yaml b/helm-chart/templates/01-service-account.yaml index a2979f61d..19527b65a 100644 --- a/helm-chart/templates/01-service-account.yaml +++ b/helm-chart/templates/01-service-account.yaml @@ -12,4 +12,4 @@ metadata: {{- toYaml .Values.tap.annotations | nindent 4 }} {{- end }} name: kubeshark-service-account - namespace: {{ .Values.tap.selfnamespace }} + namespace: {{ .Release.Namespace }} diff --git a/helm-chart/templates/02-cluster-role.yaml b/helm-chart/templates/02-cluster-role.yaml index c1d97b604..c8bc89d73 100644 --- a/helm-chart/templates/02-cluster-role.yaml +++ b/helm-chart/templates/02-cluster-role.yaml @@ -12,7 +12,7 @@ metadata: {{- toYaml .Values.tap.annotations | nindent 4 }} {{- end }} name: kubeshark-cluster-role - namespace: {{ .Values.tap.selfnamespace }} + namespace: {{ .Release.Namespace }} rules: - apiGroups: - "" diff --git a/helm-chart/templates/03-cluster-role-binding.yaml b/helm-chart/templates/03-cluster-role-binding.yaml index 58cdc81d5..8f32f6a75 100644 --- a/helm-chart/templates/03-cluster-role-binding.yaml +++ b/helm-chart/templates/03-cluster-role-binding.yaml @@ -12,7 +12,7 @@ metadata: {{- toYaml .Values.tap.annotations | nindent 4 }} {{- end }} name: kubeshark-cluster-role-binding - namespace: {{ .Values.tap.selfnamespace }} + namespace: {{ .Release.Namespace }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole @@ -20,4 +20,4 @@ roleRef: subjects: - kind: ServiceAccount name: kubeshark-service-account - namespace: {{ .Values.tap.selfnamespace }} + namespace: {{ .Release.Namespace }} diff --git a/helm-chart/templates/04-hub-pod.yaml b/helm-chart/templates/04-hub-pod.yaml index f6d8edecb..ca1c9bbfb 100644 --- a/helm-chart/templates/04-hub-pod.yaml +++ b/helm-chart/templates/04-hub-pod.yaml @@ -13,7 +13,7 @@ metadata: {{- toYaml .Values.tap.annotations | nindent 4 }} {{- end }} name: kubeshark-hub - namespace: {{ .Values.tap.selfnamespace }} + namespace: {{ .Release.Namespace }} spec: containers: - command: diff --git a/helm-chart/templates/05-hub-service.yaml b/helm-chart/templates/05-hub-service.yaml index 31c2e11a1..98798683d 100644 --- a/helm-chart/templates/05-hub-service.yaml +++ b/helm-chart/templates/05-hub-service.yaml @@ -12,7 +12,7 @@ metadata: {{- toYaml .Values.tap.annotations | nindent 4 }} {{- end }} name: kubeshark-hub - namespace: {{ .Values.tap.selfnamespace }} + namespace: {{ .Release.Namespace }} spec: ports: - name: kubeshark-hub diff --git a/helm-chart/templates/06-front-pod.yaml b/helm-chart/templates/06-front-pod.yaml index c537bdcfe..ef5e284f9 100644 --- a/helm-chart/templates/06-front-pod.yaml +++ b/helm-chart/templates/06-front-pod.yaml @@ -13,7 +13,7 @@ metadata: {{- toYaml .Values.tap.annotations | nindent 4 }} {{- end }} name: kubeshark-front - namespace: {{ .Values.tap.selfnamespace }} + namespace: {{ .Release.Namespace }} spec: containers: - env: diff --git a/helm-chart/templates/07-front-service.yaml b/helm-chart/templates/07-front-service.yaml index b5de960cf..b79557739 100644 --- a/helm-chart/templates/07-front-service.yaml +++ b/helm-chart/templates/07-front-service.yaml @@ -12,7 +12,7 @@ metadata: {{- toYaml .Values.tap.annotations | nindent 4 }} {{- end }} name: kubeshark-front - namespace: {{ .Values.tap.selfnamespace }} + namespace: {{ .Release.Namespace }} spec: ports: - name: kubeshark-front diff --git a/helm-chart/templates/08-persistent-volume-claim.yaml b/helm-chart/templates/08-persistent-volume-claim.yaml index acdcd384d..9e164fd8b 100644 --- a/helm-chart/templates/08-persistent-volume-claim.yaml +++ b/helm-chart/templates/08-persistent-volume-claim.yaml @@ -13,7 +13,7 @@ metadata: {{- toYaml .Values.tap.annotations | nindent 4 }} {{- end }} name: kubeshark-persistent-volume-claim - namespace: {{ .Values.tap.selfnamespace }} + namespace: {{ .Release.Namespace }} spec: accessModes: - ReadWriteMany diff --git a/helm-chart/templates/09-worker-daemon-set.yaml b/helm-chart/templates/09-worker-daemon-set.yaml index 90cf8fea8..1c972d038 100644 --- a/helm-chart/templates/09-worker-daemon-set.yaml +++ b/helm-chart/templates/09-worker-daemon-set.yaml @@ -13,7 +13,7 @@ metadata: {{- toYaml .Values.tap.annotations | nindent 4 }} {{- end }} name: kubeshark-worker-daemon-set - namespace: {{ .Values.tap.selfnamespace }} + namespace: {{ .Release.Namespace }} spec: selector: matchLabels: diff --git a/helm-chart/templates/10-ingress-class.yaml b/helm-chart/templates/10-ingress-class.yaml index e591d8ca5..6180ef604 100644 --- a/helm-chart/templates/10-ingress-class.yaml +++ b/helm-chart/templates/10-ingress-class.yaml @@ -13,7 +13,7 @@ metadata: {{- toYaml .Values.tap.annotations | nindent 4 }} {{- end }} name: kubeshark-ingress-class - namespace: {{ .Values.tap.selfnamespace }} + namespace: {{ .Release.Namespace }} spec: controller: {{ .Values.tap.ingress.controller }} {{- end }} diff --git a/helm-chart/templates/11-ingress.yaml b/helm-chart/templates/11-ingress.yaml index 91c7adb47..644ca9323 100644 --- a/helm-chart/templates/11-ingress.yaml +++ b/helm-chart/templates/11-ingress.yaml @@ -15,7 +15,7 @@ metadata: {{- toYaml .Values.tap.labels | nindent 4 }} {{- end }} name: kubeshark-ingress - namespace: {{ .Values.tap.selfnamespace }} + namespace: {{ .Release.Namespace }} spec: ingressClassName: {{ .Values.tap.ingress.classname }} rules: diff --git a/helm-chart/values.yaml b/helm-chart/values.yaml index 82878c585..7d999adf2 100644 --- a/helm-chart/values.yaml +++ b/helm-chart/values.yaml @@ -16,7 +16,7 @@ tap: host: 127.0.0.1 regex: .* namespaces: [] - selfnamespace: kubeshark + releasenamespace: default persistentstorage: false storagelimit: 200Mi storageclass: standard diff --git a/misc/fsUtils/kubesharkLogsUtils.go b/misc/fsUtils/kubesharkLogsUtils.go index ec517ddcf..52944a1ae 100644 --- a/misc/fsUtils/kubesharkLogsUtils.go +++ b/misc/fsUtils/kubesharkLogsUtils.go @@ -15,13 +15,13 @@ import ( func DumpLogs(ctx context.Context, provider *kubernetes.Provider, filePath string) error { podExactRegex := regexp.MustCompile("^" + kubernetes.SelfResourcesPrefix) - pods, err := provider.ListAllPodsMatchingRegex(ctx, podExactRegex, []string{config.Config.Tap.SelfNamespace}) + pods, err := provider.ListAllPodsMatchingRegex(ctx, podExactRegex, []string{config.Config.Tap.ReleaseNamespace}) if err != nil { return err } if len(pods) == 0 { - return fmt.Errorf("No %s pods found in namespace %s", misc.Software, config.Config.Tap.SelfNamespace) + return fmt.Errorf("No %s pods found in namespace %s", misc.Software, config.Config.Tap.ReleaseNamespace) } newZipFile, err := os.Create(filePath) @@ -60,17 +60,17 @@ func DumpLogs(ctx context.Context, provider *kubernetes.Provider, filePath strin } } - events, err := provider.GetNamespaceEvents(ctx, config.Config.Tap.SelfNamespace) + events, err := provider.GetNamespaceEvents(ctx, config.Config.Tap.ReleaseNamespace) if err != nil { log.Error().Err(err).Msg("Failed to get k8b events!") } else { - log.Debug().Str("namespace", config.Config.Tap.SelfNamespace).Msg("Successfully read events.") + log.Debug().Str("namespace", config.Config.Tap.ReleaseNamespace).Msg("Successfully read events.") } - if err := AddStrToZip(zipWriter, events, fmt.Sprintf("%s_events.log", config.Config.Tap.SelfNamespace)); err != nil { + if err := AddStrToZip(zipWriter, events, fmt.Sprintf("%s_events.log", config.Config.Tap.ReleaseNamespace)); err != nil { log.Error().Err(err).Msg("Failed write logs!") } else { - log.Debug().Str("namespace", config.Config.Tap.SelfNamespace).Msg("Successfully added events.") + log.Debug().Str("namespace", config.Config.Tap.ReleaseNamespace).Msg("Successfully added events.") } if err := AddFileToZip(zipWriter, config.ConfigFilePath); err != nil {