From f9677dbaa1193edff5642fc8eb1eae9728388076 Mon Sep 17 00:00:00 2001 From: RoyUP9 <87927115+RoyUP9@users.noreply.github.com> Date: Thu, 12 Aug 2021 16:33:32 +0300 Subject: [PATCH] added resources to config (#208) --- cli/cmd/tapRunner.go | 3 ++- cli/config/configStructs/tapConfig.go | 37 +++++++++++++++++---------- cli/kubernetes/provider.go | 21 +++++++-------- 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/cli/cmd/tapRunner.go b/cli/cmd/tapRunner.go index 6255bea18..c3c8713a7 100644 --- a/cli/cmd/tapRunner.go +++ b/cli/cmd/tapRunner.go @@ -182,7 +182,7 @@ func createMizuApiServer(ctx context.Context, kubernetesProvider *kubernetes.Pro MizuApiFilteringOptions: mizuApiFilteringOptions, MaxEntriesDBSizeBytes: config.Config.Tap.MaxEntriesDBSizeBytes(), } - _, err = kubernetesProvider.CreateMizuApiServerPod(ctx, opts) + _, err = kubernetesProvider.CreateMizuApiServerPod(ctx, opts, config.Config.Tap.ApiServerResources) if err != nil { return err } @@ -237,6 +237,7 @@ func updateMizuTappers(ctx context.Context, kubernetesProvider *kubernetes.Provi nodeToTappedPodIPMap, serviceAccountName, config.Config.Tap.TapOutgoing(), + config.Config.Tap.TapperResources, ); err != nil { return err } diff --git a/cli/config/configStructs/tapConfig.go b/cli/config/configStructs/tapConfig.go index 5f7a68eae..d80163b27 100644 --- a/cli/config/configStructs/tapConfig.go +++ b/cli/config/configStructs/tapConfig.go @@ -23,20 +23,29 @@ const ( ) type TapConfig struct { - AnalysisDestination string `yaml:"dest" default:"up9.app"` - SleepIntervalSec int `yaml:"upload-interval" default:"10"` - PodRegexStr string `yaml:"regex" default:".*"` - GuiPort uint16 `yaml:"gui-port" default:"8899"` - Namespaces []string `yaml:"namespaces"` - Analysis bool `yaml:"analysis" default:"false"` - AllNamespaces bool `yaml:"all-namespaces" default:"false"` - PlainTextFilterRegexes []string `yaml:"regex-masking"` - HealthChecksUserAgentHeaders []string `yaml:"ignored-user-agents"` - DisableRedaction bool `yaml:"no-redact" default:"false"` - HumanMaxEntriesDBSize string `yaml:"max-entries-db-size" default:"200MB"` - Direction string `yaml:"direction" default:"in"` - DryRun bool `yaml:"dry-run" default:"false"` - EnforcePolicyFile string `yaml:"test-rules"` + AnalysisDestination string `yaml:"dest" default:"up9.app"` + SleepIntervalSec int `yaml:"upload-interval" default:"10"` + PodRegexStr string `yaml:"regex" default:".*"` + GuiPort uint16 `yaml:"gui-port" default:"8899"` + Namespaces []string `yaml:"namespaces"` + Analysis bool `yaml:"analysis" default:"false"` + AllNamespaces bool `yaml:"all-namespaces" default:"false"` + PlainTextFilterRegexes []string `yaml:"regex-masking"` + HealthChecksUserAgentHeaders []string `yaml:"ignored-user-agents"` + DisableRedaction bool `yaml:"no-redact" default:"false"` + HumanMaxEntriesDBSize string `yaml:"max-entries-db-size" default:"200MB"` + Direction string `yaml:"direction" default:"in"` + DryRun bool `yaml:"dry-run" default:"false"` + EnforcePolicyFile string `yaml:"test-rules"` + ApiServerResources Resources `yaml:"api-server-resources"` + TapperResources Resources `yaml:"tapper-resources"` +} + +type Resources struct { + CpuLimit string `yaml:"cpu-limit" default:"750m"` + MemoryLimit string `yaml:"memory-limit" default:"1Gi"` + CpuRequests string `yaml:"cpu-requests" default:"50m"` + MemoryRequests string `yaml:"memory-requests" default:"50Mi"` } func (config *TapConfig) PodRegex() *regexp.Regexp { diff --git a/cli/kubernetes/provider.go b/cli/kubernetes/provider.go index 91f745b98..5559b0685 100644 --- a/cli/kubernetes/provider.go +++ b/cli/kubernetes/provider.go @@ -7,6 +7,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/up9inc/mizu/cli/config/configStructs" "github.com/up9inc/mizu/cli/logger" "os" "path/filepath" @@ -143,7 +144,7 @@ type ApiServerOptions struct { MaxEntriesDBSizeBytes int64 } -func (provider *Provider) CreateMizuApiServerPod(ctx context.Context, opts *ApiServerOptions) (*core.Pod, error) { +func (provider *Provider) CreateMizuApiServerPod(ctx context.Context, opts *ApiServerOptions, resources configStructs.Resources) (*core.Pod, error) { marshaledFilteringOptions, err := json.Marshal(opts.MizuApiFilteringOptions) if err != nil { return nil, err @@ -153,19 +154,19 @@ func (provider *Provider) CreateMizuApiServerPod(ctx context.Context, opts *ApiS configMapOptional := true configMapVolumeName.Optional = &configMapOptional - cpuLimit, err := resource.ParseQuantity("750m") + cpuLimit, err := resource.ParseQuantity(resources.CpuLimit) if err != nil { return nil, errors.New(fmt.Sprintf("invalid cpu limit for %s container", opts.PodName)) } - memLimit, err := resource.ParseQuantity("512Mi") + memLimit, err := resource.ParseQuantity(resources.MemoryLimit) if err != nil { return nil, errors.New(fmt.Sprintf("invalid memory limit for %s container", opts.PodName)) } - cpuRequests, err := resource.ParseQuantity("50m") + cpuRequests, err := resource.ParseQuantity(resources.CpuRequests) if err != nil { return nil, errors.New(fmt.Sprintf("invalid cpu request for %s container", opts.PodName)) } - memRequests, err := resource.ParseQuantity("50Mi") + memRequests, err := resource.ParseQuantity(resources.MemoryRequests) if err != nil { return nil, errors.New(fmt.Sprintf("invalid memory request for %s container", opts.PodName)) } @@ -562,7 +563,7 @@ func (provider *Provider) CreateConfigMap(ctx context.Context, namespace string, return nil } -func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespace string, daemonSetName string, podImage string, tapperPodName string, apiServerPodIp string, nodeToTappedPodIPMap map[string][]string, serviceAccountName string, tapOutgoing bool) error { +func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespace string, daemonSetName string, podImage string, tapperPodName string, apiServerPodIp string, nodeToTappedPodIPMap map[string][]string, serviceAccountName string, tapOutgoing bool, resources configStructs.Resources) error { logger.Log.Debugf("Applying %d tapper deamonsets, ns: %s, daemonSetName: %s, podImage: %s, tapperPodName: %s", len(nodeToTappedPodIPMap), namespace, daemonSetName, podImage, tapperPodName) if len(nodeToTappedPodIPMap) == 0 { @@ -601,19 +602,19 @@ func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespac ), ), ) - cpuLimit, err := resource.ParseQuantity("500m") + cpuLimit, err := resource.ParseQuantity(resources.CpuLimit) if err != nil { return errors.New(fmt.Sprintf("invalid cpu limit for %s container", tapperPodName)) } - memLimit, err := resource.ParseQuantity("1Gi") + memLimit, err := resource.ParseQuantity(resources.MemoryLimit) if err != nil { return errors.New(fmt.Sprintf("invalid memory limit for %s container", tapperPodName)) } - cpuRequests, err := resource.ParseQuantity("50m") + cpuRequests, err := resource.ParseQuantity(resources.CpuRequests) if err != nil { return errors.New(fmt.Sprintf("invalid cpu request for %s container", tapperPodName)) } - memRequests, err := resource.ParseQuantity("50Mi") + memRequests, err := resource.ParseQuantity(resources.MemoryRequests) if err != nil { return errors.New(fmt.Sprintf("invalid memory request for %s container", tapperPodName)) }