mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-05-08 10:17:49 +00:00
* Rename `mizu` to `kubeshark` * Rename `up9inc` to `kubeshark` * Change the logo, title, motto and the main color * Replace the favicon * Update the docs link * Change the copyright text in C files * Remove a comment * Rewrite the `README.md` and update the logo and screenshots used in it * Add a `TODO` * Fix the grammar * Fix the bottom text in the filtering guide * Change the Docker Hub username of cross-compilation intermediate images * Add an install script * Fix `docker/login-action` in the CI * Delete `build-custom-branch.yml` GitHub workflow * Update `README.md` * Remove `install.sh` * Change the motto back to "Traffic viewer for Kubernetes"
83 lines
3.2 KiB
Go
83 lines
3.2 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
|
|
"github.com/kubeshark/kubeshark/cli/config/configStructs"
|
|
"github.com/kubeshark/kubeshark/cli/kubeshark"
|
|
"github.com/kubeshark/kubeshark/shared"
|
|
"github.com/op/go-logging"
|
|
v1 "k8s.io/api/core/v1"
|
|
"k8s.io/client-go/util/homedir"
|
|
)
|
|
|
|
const (
|
|
KubesharkResourcesNamespaceConfigName = "kubeshark-resources-namespace"
|
|
ConfigFilePathCommandName = "config-path"
|
|
KubeConfigPathConfigName = "kube-config-path"
|
|
)
|
|
|
|
type ConfigStruct struct {
|
|
Tap configStructs.TapConfig `yaml:"tap"`
|
|
Check configStructs.CheckConfig `yaml:"check"`
|
|
Install configStructs.InstallConfig `yaml:"install"`
|
|
Version configStructs.VersionConfig `yaml:"version"`
|
|
View configStructs.ViewConfig `yaml:"view"`
|
|
Logs configStructs.LogsConfig `yaml:"logs"`
|
|
Config configStructs.ConfigConfig `yaml:"config,omitempty"`
|
|
AgentImage string `yaml:"agent-image,omitempty" readonly:""`
|
|
ImagePullPolicyStr string `yaml:"image-pull-policy" default:"Always"`
|
|
KubesharkResourcesNamespace string `yaml:"kubeshark-resources-namespace" default:"kubeshark"`
|
|
DumpLogs bool `yaml:"dump-logs" default:"false"`
|
|
KubeConfigPathStr string `yaml:"kube-config-path"`
|
|
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:""`
|
|
ServiceMap bool `yaml:"service-map" default:"true"`
|
|
OAS shared.OASConfig `yaml:"oas"`
|
|
}
|
|
|
|
func (config *ConfigStruct) validate() error {
|
|
if _, err := logging.LogLevel(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() {
|
|
config.AgentImage = fmt.Sprintf("%s:%s", shared.KubesharkAgentImageRepo, kubeshark.Ver)
|
|
config.ConfigFilePath = path.Join(kubeshark.GetKubesharkFolderPath(), "config.yaml")
|
|
}
|
|
|
|
func (config *ConfigStruct) ImagePullPolicy() v1.PullPolicy {
|
|
return v1.PullPolicy(config.ImagePullPolicyStr)
|
|
}
|
|
|
|
func (config *ConfigStruct) IsNsRestrictedMode() bool {
|
|
return config.KubesharkResourcesNamespace != "kubeshark" // Notice "kubeshark" string must match the default KubesharkResourcesNamespace
|
|
}
|
|
|
|
func (config *ConfigStruct) KubeConfigPath() string {
|
|
if config.KubeConfigPathStr != "" {
|
|
return config.KubeConfigPathStr
|
|
}
|
|
|
|
envKubeConfigPath := os.Getenv("KUBECONFIG")
|
|
if envKubeConfigPath != "" {
|
|
return envKubeConfigPath
|
|
}
|
|
|
|
home := homedir.HomeDir()
|
|
return filepath.Join(home, ".kube", "config")
|
|
}
|
|
|
|
func (config *ConfigStruct) LogLevel() logging.Level {
|
|
logLevel, _ := logging.LogLevel(config.LogLevelStr)
|
|
return logLevel
|
|
}
|