Move ResourceLabels and NodeSelectorTerms fields into TapConfig

This commit is contained in:
M. Mert Yildiran 2023-04-11 22:37:29 +03:00
parent 0aedc023aa
commit 02990912b7
No known key found for this signature in database
GPG Key ID: DA5D6DCBB758A461
4 changed files with 34 additions and 33 deletions

View File

@ -28,17 +28,15 @@ type ManifestsConfig struct {
} }
type ConfigStruct struct { type ConfigStruct struct {
Tap configStructs.TapConfig `yaml:"tap"` Tap configStructs.TapConfig `yaml:"tap"`
Logs configStructs.LogsConfig `yaml:"logs"` Logs configStructs.LogsConfig `yaml:"logs"`
Config configStructs.ConfigConfig `yaml:"config,omitempty"` Config configStructs.ConfigConfig `yaml:"config,omitempty"`
Kube KubeConfig `yaml:"kube"` Kube KubeConfig `yaml:"kube"`
DumpLogs bool `yaml:"dumplogs" default:"false"` DumpLogs bool `yaml:"dumplogs" default:"false"`
HeadlessMode bool `yaml:"headless" default:"false"` HeadlessMode bool `yaml:"headless" default:"false"`
License string `yaml:"license" default:""` License string `yaml:"license" default:""`
Scripting configStructs.ScriptingConfig `yaml:"scripting"` Scripting configStructs.ScriptingConfig `yaml:"scripting"`
ResourceLabels map[string]string `yaml:"resourceLabels" default:"{}"` Manifests ManifestsConfig `yaml:"manifests,omitempty"`
NodeSelectorTerms []v1.NodeSelectorTerm `yaml:"nodeSelectorTerms" default:"[]"`
Manifests ManifestsConfig `yaml:"manifests,omitempty"`
} }
func (config *ConfigStruct) ImagePullPolicy() v1.PullPolicy { func (config *ConfigStruct) ImagePullPolicy() v1.PullPolicy {

View File

@ -6,6 +6,7 @@ import (
"github.com/kubeshark/kubeshark/utils" "github.com/kubeshark/kubeshark/utils"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
v1 "k8s.io/api/core/v1"
) )
const ( const (
@ -70,21 +71,23 @@ type ResourcesConfig struct {
} }
type TapConfig struct { type TapConfig struct {
Docker DockerConfig `yaml:"docker"` Docker DockerConfig `yaml:"docker"`
Proxy ProxyConfig `yaml:"proxy"` Proxy ProxyConfig `yaml:"proxy"`
PodRegexStr string `yaml:"regex" default:".*"` PodRegexStr string `yaml:"regex" default:".*"`
Namespaces []string `yaml:"namespaces"` Namespaces []string `yaml:"namespaces"`
AllNamespaces bool `yaml:"allnamespaces" default:"true"` AllNamespaces bool `yaml:"allnamespaces" default:"true"`
SelfNamespace string `yaml:"selfnamespace" default:"kubeshark"` SelfNamespace string `yaml:"selfnamespace" default:"kubeshark"`
StorageLimit string `yaml:"storagelimit" default:"200MB"` StorageLimit string `yaml:"storagelimit" default:"200MB"`
DryRun bool `yaml:"dryrun" default:"false"` DryRun bool `yaml:"dryrun" default:"false"`
Pcap string `yaml:"pcap" default:""` Pcap string `yaml:"pcap" default:""`
Resources ResourcesConfig `yaml:"resources"` Resources ResourcesConfig `yaml:"resources"`
ServiceMesh bool `yaml:"servicemesh" default:"true"` ServiceMesh bool `yaml:"servicemesh" default:"true"`
Tls bool `yaml:"tls" default:"true"` Tls bool `yaml:"tls" default:"true"`
PacketCapture string `yaml:"packetcapture" default:"libpcap"` PacketCapture string `yaml:"packetcapture" default:"libpcap"`
IgnoreTainted bool `yaml:"ignoreTainted" default:"false"` IgnoreTainted bool `yaml:"ignoreTainted" default:"false"`
Debug bool `yaml:"debug" default:"false"` ResourceLabels map[string]string `yaml:"resourceLabels" default:"{}"`
NodeSelectorTerms []v1.NodeSelectorTerm `yaml:"nodeSelectorTerms" default:"[]"`
Debug bool `yaml:"debug" default:"false"`
} }
func (config *TapConfig) PodRegex() *regexp.Regexp { func (config *TapConfig) PodRegex() *regexp.Regexp {

View File

@ -280,11 +280,11 @@ func (provider *Provider) BuildHubPod(opts *PodOptions) (*core.Pod, error) {
}, },
} }
if len(config.Config.NodeSelectorTerms) > 0 { if len(config.Config.Tap.NodeSelectorTerms) > 0 {
pod.Spec.Affinity = &core.Affinity{ pod.Spec.Affinity = &core.Affinity{
NodeAffinity: &core.NodeAffinity{ NodeAffinity: &core.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{ RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
NodeSelectorTerms: config.Config.NodeSelectorTerms, NodeSelectorTerms: config.Config.Tap.NodeSelectorTerms,
}, },
}, },
} }
@ -390,11 +390,11 @@ func (provider *Provider) BuildFrontPod(opts *PodOptions, hubHost string, hubPor
}, },
} }
if len(config.Config.NodeSelectorTerms) > 0 { if len(config.Config.Tap.NodeSelectorTerms) > 0 {
pod.Spec.Affinity = &core.Affinity{ pod.Spec.Affinity = &core.Affinity{
NodeAffinity: &core.NodeAffinity{ NodeAffinity: &core.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{ RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
NodeSelectorTerms: config.Config.NodeSelectorTerms, NodeSelectorTerms: config.Config.Tap.NodeSelectorTerms,
}, },
}, },
} }
@ -849,11 +849,11 @@ func (provider *Provider) BuildWorkerDaemonSet(
}, },
} }
if len(config.Config.NodeSelectorTerms) > 0 { if len(config.Config.Tap.NodeSelectorTerms) > 0 {
pod.Spec.Affinity = &core.Affinity{ pod.Spec.Affinity = &core.Affinity{
NodeAffinity: &core.NodeAffinity{ NodeAffinity: &core.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{ RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
NodeSelectorTerms: config.Config.NodeSelectorTerms, NodeSelectorTerms: config.Config.Tap.NodeSelectorTerms,
}, },
}, },
} }

View File

@ -8,7 +8,7 @@ func buildWithDefaultLabels(labels map[string]string, provider *Provider) map[st
labels[LabelManagedBy] = provider.managedBy labels[LabelManagedBy] = provider.managedBy
labels[LabelCreatedBy] = provider.createdBy labels[LabelCreatedBy] = provider.createdBy
for k, v := range config.Config.ResourceLabels { for k, v := range config.Config.Tap.ResourceLabels {
labels[k] = v labels[k] = v
} }