🔥 Remove log-level and ignored-user-agents options

This commit is contained in:
M. Mert Yildiran
2022-12-26 09:05:05 +03:00
parent a501e0e409
commit 1c72262cc7
8 changed files with 22 additions and 83 deletions

View File

@@ -16,7 +16,6 @@ import (
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/kubeshark/base/pkg/api"
"github.com/kubeshark/base/pkg/models"
"github.com/kubeshark/kubeshark/cmd/goUtils"
"github.com/kubeshark/kubeshark/config"
@@ -82,7 +81,7 @@ func tap() {
}
log.Info().Msg("Waiting for the creation of Kubeshark resources...")
if state.kubesharkServiceAccountExists, err = resources.CreateHubResources(ctx, kubernetesProvider, serializedKubesharkConfig, config.Config.IsNsRestrictedMode(), config.Config.ResourcesNamespace, config.Config.Tap.MaxEntriesDBSizeBytes(), config.Config.Tap.HubResources, config.Config.ImagePullPolicy(), config.Config.LogLevel(), config.Config.Tap.Debug); err != nil {
if state.kubesharkServiceAccountExists, err = resources.CreateHubResources(ctx, kubernetesProvider, serializedKubesharkConfig, config.Config.IsNsRestrictedMode(), config.Config.ResourcesNamespace, config.Config.Tap.MaxEntriesDBSizeBytes(), config.Config.Tap.HubResources, config.Config.ImagePullPolicy(), config.Config.Tap.Debug); err != nil {
var statusError *k8serrors.StatusError
if errors.As(err, &statusError) && (statusError.ErrStatus.Reason == metav1.StatusReasonAlreadyExists) {
log.Info().Msg("Kubeshark is already running in this namespace, change the `kubeshark-resources-namespace` configuration or run `kubeshark clean` to remove the currently running Kubeshark instance")
@@ -141,15 +140,11 @@ func printTargettedPodsPreview(ctx context.Context, kubernetesProvider *kubernet
func startWorkerSyncer(ctx context.Context, cancel context.CancelFunc, provider *kubernetes.Provider, targetNamespaces []string, startTime time.Time) error {
workerSyncer, err := kubernetes.CreateAndStartWorkerSyncer(ctx, provider, kubernetes.WorkerSyncerConfig{
TargetNamespaces: targetNamespaces,
PodFilterRegex: *config.Config.Tap.PodRegex(),
KubesharkResourcesNamespace: config.Config.ResourcesNamespace,
WorkerResources: config.Config.Tap.WorkerResources,
ImagePullPolicy: config.Config.ImagePullPolicy(),
LogLevel: config.Config.LogLevel(),
KubesharkApiFilteringOptions: api.TrafficFilteringOptions{
IgnoredUserAgents: config.Config.Tap.IgnoredUserAgents,
},
TargetNamespaces: targetNamespaces,
PodFilterRegex: *config.Config.Tap.PodRegex(),
KubesharkResourcesNamespace: config.Config.ResourcesNamespace,
WorkerResources: config.Config.Tap.WorkerResources,
ImagePullPolicy: config.Config.ImagePullPolicy(),
KubesharkServiceAccountExists: state.kubesharkServiceAccountExists,
ServiceMesh: config.Config.Tap.ServiceMesh,
Tls: config.Config.Tap.Tls,

View File

@@ -68,10 +68,6 @@ func InitConfig(cmd *cobra.Command) error {
cmd.Flags().Visit(initFlag)
if err := Config.validate(); err != nil {
return fmt.Errorf("config validation failed, err: %v", err)
}
log.Debug().Interface("config", Config).Msg("Init config is finished.")
return nil

View File

@@ -1,15 +1,12 @@
package config
import (
"fmt"
"os"
"path"
"path/filepath"
"github.com/kubeshark/kubeshark/config/configStructs"
"github.com/kubeshark/kubeshark/kubeshark"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/util/homedir"
)
@@ -47,15 +44,6 @@ type ConfigStruct struct {
KubeContext string `yaml:"kube-context"`
ConfigFilePath string `yaml:"config-path,omitempty" readonly:""`
HeadlessMode bool `yaml:"headless" default:"false"`
LogLevelStr string `yaml:"log-level,omitempty" default:"info" readonly:""`
}
func (config *ConfigStruct) validate() error {
if _, err := zerolog.ParseLevel(config.LogLevelStr); err != nil {
return fmt.Errorf("%s is not a valid log level, err: %v", config.LogLevelStr, err)
}
return nil
}
func (config *ConfigStruct) SetDefaults() {
@@ -83,11 +71,3 @@ func (config *ConfigStruct) KubeConfigPath() string {
home := homedir.HomeDir()
return filepath.Join(home, ".kube", "config")
}
func (config *ConfigStruct) LogLevel() zerolog.Level {
logLevel, err := zerolog.ParseLevel(config.LogLevelStr)
if err != nil {
log.Error().Err(err).Str("log-level", config.LogLevelStr).Msg("Invalid log level")
}
return logLevel
}

View File

@@ -42,7 +42,6 @@ type TapConfig struct {
ProxyHost string `yaml:"proxy-host" default:"127.0.0.1"`
Namespaces []string `yaml:"namespaces"`
AllNamespaces bool `yaml:"all-namespaces" default:"false"`
IgnoredUserAgents []string `yaml:"ignored-user-agents"`
HumanMaxEntriesDBSize string `yaml:"max-entries-db-size" default:"200MB"`
DryRun bool `yaml:"dry-run" default:"false"`
HubResources models.Resources `yaml:"hub-resources"`

View File

@@ -3,7 +3,6 @@ package kubernetes
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
@@ -11,12 +10,9 @@ import (
"path/filepath"
"regexp"
"github.com/kubeshark/base/pkg/api"
"github.com/kubeshark/base/pkg/models"
"github.com/kubeshark/kubeshark/docker"
"github.com/kubeshark/kubeshark/semver"
"github.com/kubeshark/kubeshark/utils"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
auth "k8s.io/api/authorization/v1"
core "k8s.io/api/core/v1"
@@ -182,7 +178,6 @@ type PodOptions struct {
MaxEntriesDBSizeBytes int64
Resources models.Resources
ImagePullPolicy core.PullPolicy
LogLevel zerolog.Level
Debug bool
}
@@ -252,12 +247,6 @@ func (provider *Provider) BuildHubPod(opts *PodOptions, mountVolumeClaim bool, v
ImagePullPolicy: opts.ImagePullPolicy,
VolumeMounts: volumeMounts,
Command: command,
Env: []core.EnvVar{
{
Name: utils.LogLevelEnvVar,
Value: opts.LogLevel.String(),
},
},
Resources: core.ResourceRequirements{
Limits: core.ResourceList{
"cpu": cpuLimit,
@@ -711,7 +700,20 @@ func (provider *Provider) CreateConfigMap(ctx context.Context, namespace string,
return nil
}
func (provider *Provider) ApplyWorkerDaemonSet(ctx context.Context, namespace string, daemonSetName string, podImage string, workerPodName string, nodeNames []string, serviceAccountName string, resources models.Resources, imagePullPolicy core.PullPolicy, kubesharkApiFilteringOptions api.TrafficFilteringOptions, logLevel zerolog.Level, serviceMesh bool, tls bool, debug bool) error {
func (provider *Provider) ApplyWorkerDaemonSet(
ctx context.Context,
namespace string,
daemonSetName string,
podImage string,
workerPodName string,
nodeNames []string,
serviceAccountName string,
resources models.Resources,
imagePullPolicy core.PullPolicy,
serviceMesh bool,
tls bool,
debug bool,
) error {
log.Debug().
Int("node-count", len(nodeNames)).
Str("namespace", namespace).
@@ -724,11 +726,6 @@ func (provider *Provider) ApplyWorkerDaemonSet(ctx context.Context, namespace st
return fmt.Errorf("DaemonSet %s must target at least 1 pod", daemonSetName)
}
kubesharkApiFilteringOptionsJsonStr, err := json.Marshal(kubesharkApiFilteringOptions)
if err != nil {
return err
}
command := []string{"./worker", "-i", "any", "-port", "8897"}
if debug {
@@ -772,18 +769,7 @@ func (provider *Provider) ApplyWorkerDaemonSet(ctx context.Context, namespace st
workerContainer.WithSecurityContext(applyconfcore.SecurityContext().WithCapabilities(caps))
workerContainer.WithCommand(command...)
workerContainer.WithEnv(
applyconfcore.EnvVar().WithName(utils.LogLevelEnvVar).WithValue(logLevel.String()),
applyconfcore.EnvVar().WithName(utils.HostModeEnvVar).WithValue("1"),
applyconfcore.EnvVar().WithName(utils.KubesharkFilteringOptionsEnvVar).WithValue(string(kubesharkApiFilteringOptionsJsonStr)),
)
workerContainer.WithEnv(
applyconfcore.EnvVar().WithName(utils.NodeNameEnvVar).WithValueFrom(
applyconfcore.EnvVarSource().WithFieldRef(
applyconfcore.ObjectFieldSelector().WithAPIVersion("v1").WithFieldPath("spec.nodeName"),
),
),
)
cpuLimit, err := resource.ParseQuantity(resources.CpuLimit)
if err != nil {
return fmt.Errorf("invalid cpu limit for %s container", workerPodName)

View File

@@ -6,12 +6,10 @@ import (
"regexp"
"time"
"github.com/kubeshark/base/pkg/api"
"github.com/kubeshark/base/pkg/models"
"github.com/kubeshark/kubeshark/debounce"
"github.com/kubeshark/kubeshark/docker"
"github.com/kubeshark/kubeshark/utils"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
v1 "k8s.io/api/core/v1"
)
@@ -43,8 +41,6 @@ type WorkerSyncerConfig struct {
KubesharkResourcesNamespace string
WorkerResources models.Resources
ImagePullPolicy v1.PullPolicy
LogLevel zerolog.Level
KubesharkApiFilteringOptions api.TrafficFilteringOptions
KubesharkServiceAccountExists bool
ServiceMesh bool
Tls bool
@@ -366,8 +362,6 @@ func (workerSyncer *WorkerSyncer) updateWorkers() error {
serviceAccountName,
workerSyncer.config.WorkerResources,
workerSyncer.config.ImagePullPolicy,
workerSyncer.config.KubesharkApiFilteringOptions,
workerSyncer.config.LogLevel,
workerSyncer.config.ServiceMesh,
workerSyncer.config.Tls,
workerSyncer.config.Debug); err != nil {

View File

@@ -9,12 +9,11 @@ import (
"github.com/kubeshark/kubeshark/errormessage"
"github.com/kubeshark/kubeshark/kubernetes"
"github.com/kubeshark/kubeshark/kubeshark"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
core "k8s.io/api/core/v1"
)
func CreateHubResources(ctx context.Context, kubernetesProvider *kubernetes.Provider, serializedKubesharkConfig string, isNsRestrictedMode bool, kubesharkResourcesNamespace string, maxEntriesDBSizeBytes int64, hubResources models.Resources, imagePullPolicy core.PullPolicy, logLevel zerolog.Level, debug bool) (bool, error) {
func CreateHubResources(ctx context.Context, kubernetesProvider *kubernetes.Provider, serializedKubesharkConfig string, isNsRestrictedMode bool, kubesharkResourcesNamespace string, maxEntriesDBSizeBytes int64, hubResources models.Resources, imagePullPolicy core.PullPolicy, debug bool) (bool, error) {
if !isNsRestrictedMode {
if err := createKubesharkNamespace(ctx, kubernetesProvider, kubesharkResourcesNamespace); err != nil {
return false, err
@@ -45,7 +44,6 @@ func CreateHubResources(ctx context.Context, kubernetesProvider *kubernetes.Prov
MaxEntriesDBSizeBytes: maxEntriesDBSizeBytes,
Resources: hubResources,
ImagePullPolicy: imagePullPolicy,
LogLevel: logLevel,
Debug: debug,
}
@@ -57,7 +55,6 @@ func CreateHubResources(ctx context.Context, kubernetesProvider *kubernetes.Prov
MaxEntriesDBSizeBytes: maxEntriesDBSizeBytes,
Resources: hubResources,
ImagePullPolicy: imagePullPolicy,
LogLevel: logLevel,
Debug: debug,
}

View File

@@ -1,8 +0,0 @@
package utils
const (
KubesharkFilteringOptionsEnvVar = "SENSITIVE_DATA_FILTERING_OPTIONS"
LogLevelEnvVar = "LOG_LEVEL"
HostModeEnvVar = "HOST_MODE"
NodeNameEnvVar = "NODE_NAME"
)