Skip to content

Commit

Permalink
feat(deploy): add --kube-qps-limit and --kube-burst-limit flags, incr…
Browse files Browse the repository at this point in the history
…ease default QPS/Burst

Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
  • Loading branch information
ilya-lesikov committed Jan 22, 2025
1 parent c3ab1aa commit 71f79ef
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 10 deletions.
4 changes: 4 additions & 0 deletions cmd/werf/bundle/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ func NewCmd(ctx context.Context) *cobra.Command {
common.SetupReleasesHistoryMax(&commonCmdData, cmd)

common.SetupNetworkParallelism(&commonCmdData, cmd)
common.SetupKubeQpsLimit(&commonCmdData, cmd)
common.SetupKubeBurstLimit(&commonCmdData, cmd)
common.SetupDeployGraphPath(&commonCmdData, cmd)
common.SetupRollbackGraphPath(&commonCmdData, cmd)

Expand Down Expand Up @@ -219,6 +221,8 @@ func runApply(ctx context.Context) error {
},
ReleasesHistoryMax: *commonCmdData.ReleasesHistoryMax,
RegistryClient: helmRegistryClient,
QPSLimit: *commonCmdData.KubeQpsLimit,
BurstLimit: *commonCmdData.KubeBurstLimit,
}); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/werf/bundle/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ func NewCmd(ctx context.Context) *cobra.Command {
common.SetupKubeVersion(&commonCmdData, cmd)

common.SetupNetworkParallelism(&commonCmdData, cmd)
common.SetupKubeQpsLimit(&commonCmdData, cmd)
common.SetupKubeBurstLimit(&commonCmdData, cmd)

defaultTag := os.Getenv("WERF_TAG")
if defaultTag == "" {
Expand Down Expand Up @@ -197,6 +199,8 @@ func runRender(ctx context.Context) error {
ConfigDataBase64: *commonCmdData.KubeConfigBase64,
ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList,
},
QPSLimit: *commonCmdData.KubeQpsLimit,
BurstLimit: *commonCmdData.KubeBurstLimit,
},
); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions cmd/werf/common/cmd_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type CmdData struct {
Parallel *bool
ParallelTasksLimit *int64
NetworkParallelism *int
KubeQpsLimit *int
KubeBurstLimit *int

DockerConfig *string
InsecureRegistry *bool
Expand Down
49 changes: 45 additions & 4 deletions cmd/werf/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/werf/logboek/pkg/level"
"github.com/werf/logboek/pkg/style"
"github.com/werf/logboek/pkg/types"
"github.com/werf/nelm/pkg/action"
"github.com/werf/werf/v2/pkg/build"
"github.com/werf/werf/v2/pkg/build/stage"
"github.com/werf/werf/v2/pkg/buildah"
Expand Down Expand Up @@ -239,23 +240,63 @@ func GetUseDeployReport(cmdData *CmdData) bool {
func SetupNetworkParallelism(cmdData *CmdData, cmd *cobra.Command) {
cmdData.NetworkParallelism = new(int)

fallbackVal := 30

var defVal int
if val, err := util.GetIntEnvVar("WERF_NETWORK_PARALLELISM"); err != nil {
TerminateWithError(fmt.Sprintf("bad WERF_NETWORK_PARALLELISM value: %s", err), 1)
} else if val != nil {
defVal = int(*val)
} else {
defVal = fallbackVal
defVal = action.DefaultNetworkParallelism
}

cmd.Flags().IntVarP(
cmdData.NetworkParallelism,
"network-parallelism",
"",
defVal,
fmt.Sprintf("Parallelize some network operations (default $WERF_NETWORK_PARALLELISM or %d)", fallbackVal),
fmt.Sprintf("Parallelize some network operations (default $WERF_NETWORK_PARALLELISM or %d)", action.DefaultNetworkParallelism),
)
}

func SetupKubeQpsLimit(cmdData *CmdData, cmd *cobra.Command) {
cmdData.KubeQpsLimit = new(int)

var defVal int
if val, err := util.GetIntEnvVar("WERF_KUBE_QPS_LIMIT"); err != nil {
TerminateWithError(fmt.Sprintf("bad WERF_KUBE_QPS_LIMIT value: %s", err), 1)
} else if val != nil {
defVal = int(*val)
} else {
defVal = action.DefaultQPSLimit
}

cmd.Flags().IntVarP(
cmdData.KubeQpsLimit,
"kube-qps-limit",
"",
defVal,
fmt.Sprintf("Kubernetes client QPS limit (default $WERF_KUBE_QPS_LIMIT or %d)", action.DefaultQPSLimit),
)
}

func SetupKubeBurstLimit(cmdData *CmdData, cmd *cobra.Command) {
cmdData.KubeBurstLimit = new(int)

var defVal int
if val, err := util.GetIntEnvVar("WERF_KUBE_BURST_LIMIT"); err != nil {
TerminateWithError(fmt.Sprintf("bad WERF_KUBE_BURST_LIMIT value: %s", err), 1)
} else if val != nil {
defVal = int(*val)
} else {
defVal = action.DefaultBurstLimit
}

cmd.Flags().IntVarP(
cmdData.KubeBurstLimit,
"kube-burst-limit",
"",
defVal,
fmt.Sprintf("Kubernetes client burst limit (default $WERF_KUBE_BURST_LIMIT or %d)", action.DefaultBurstLimit),
)
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/werf/converge/converge.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ werf converge --repo registry.mydomain.com/web --env production`,
common.SetupDockerServerStoragePath(&commonCmdData, cmd)

common.SetupNetworkParallelism(&commonCmdData, cmd)
common.SetupKubeQpsLimit(&commonCmdData, cmd)
common.SetupKubeBurstLimit(&commonCmdData, cmd)
common.SetupDeployGraphPath(&commonCmdData, cmd)
common.SetupRollbackGraphPath(&commonCmdData, cmd)

Expand Down Expand Up @@ -424,10 +426,12 @@ func run(
ExtraLabels: extraLabels,
ExtraRuntimeAnnotations: serviceAnnotations,
KubeAPIServerName: *commonCmdData.KubeApiServer,
KubeBurstLimit: *commonCmdData.KubeBurstLimit,
KubeCAPath: *commonCmdData.KubeCaPath,
KubeConfigBase64: *commonCmdData.KubeConfigBase64,
KubeConfigPaths: append([]string{*commonCmdData.KubeConfig}, *commonCmdData.KubeConfigPathMergeList...),
KubeContext: *commonCmdData.KubeContext,
KubeQPSLimit: *commonCmdData.KubeQpsLimit,
KubeSkipTLSVerify: *commonCmdData.SkipTlsVerifyKube,
KubeTLSServerName: *commonCmdData.KubeTlsServer,
KubeToken: *commonCmdData.KubeToken,
Expand Down
5 changes: 5 additions & 0 deletions cmd/werf/dismiss/dismiss.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ func NewCmd(ctx context.Context) *cobra.Command {
common.SetupSkipTlsVerifyRegistry(&commonCmdData, cmd)
common.SetupContainerRegistryMirror(&commonCmdData, cmd)

common.SetupKubeQpsLimit(&commonCmdData, cmd)
common.SetupKubeBurstLimit(&commonCmdData, cmd)

commonCmdData.SetupPlatform(cmd)

cmd.Flags().BoolVarP(&cmdData.WithNamespace, "with-namespace", "", util.GetBoolEnvironmentDefaultFalse("WERF_WITH_NAMESPACE"), "Delete Kubernetes Namespace after purging Helm Release (default $WERF_WITH_NAMESPACE)")
Expand Down Expand Up @@ -171,10 +174,12 @@ func runDismiss(ctx context.Context) error {
DeleteHooks: cmdData.WithHooks,
DeleteReleaseNamespace: cmdData.WithNamespace,
KubeAPIServerName: *commonCmdData.KubeApiServer,
KubeBurstLimit: *commonCmdData.KubeBurstLimit,
KubeCAPath: *commonCmdData.KubeCaPath,
KubeConfigBase64: *commonCmdData.KubeConfigBase64,
KubeConfigPaths: append([]string{*commonCmdData.KubeConfig}, *commonCmdData.KubeConfigPathMergeList...),
KubeContext: *commonCmdData.KubeContext,
KubeQPSLimit: *commonCmdData.KubeQpsLimit,
KubeSkipTLSVerify: *commonCmdData.SkipTlsVerifyKube,
KubeTLSServerName: *commonCmdData.KubeTlsServer,
KubeToken: *commonCmdData.KubeToken,
Expand Down
4 changes: 4 additions & 0 deletions cmd/werf/plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ werf plan --repo registry.mydomain.com/web --env production`,
common.SetupDockerServerStoragePath(&commonCmdData, cmd)

common.SetupNetworkParallelism(&commonCmdData, cmd)
common.SetupKubeQpsLimit(&commonCmdData, cmd)
common.SetupKubeBurstLimit(&commonCmdData, cmd)

defaultTimeout, err := util.GetIntEnvVar("WERF_TIMEOUT")
if err != nil || defaultTimeout == nil {
Expand Down Expand Up @@ -415,10 +417,12 @@ func run(
ExtraLabels: extraLabels,
ExtraRuntimeAnnotations: serviceAnnotations,
KubeAPIServerName: *commonCmdData.KubeApiServer,
KubeBurstLimit: *commonCmdData.KubeBurstLimit,
KubeCAPath: *commonCmdData.KubeCaPath,
KubeConfigBase64: *commonCmdData.KubeConfigBase64,
KubeConfigPaths: append([]string{*commonCmdData.KubeConfig}, *commonCmdData.KubeConfigPathMergeList...),
KubeContext: *commonCmdData.KubeContext,
KubeQPSLimit: *commonCmdData.KubeQpsLimit,
KubeSkipTLSVerify: *commonCmdData.SkipTlsVerifyKube,
KubeTLSServerName: *commonCmdData.KubeTlsServer,
KubeToken: *commonCmdData.KubeToken,
Expand Down
4 changes: 4 additions & 0 deletions cmd/werf/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ func NewCmd(ctx context.Context) *cobra.Command {
common.SetupKubeVersion(&commonCmdData, cmd)

common.SetupNetworkParallelism(&commonCmdData, cmd)
common.SetupKubeQpsLimit(&commonCmdData, cmd)
common.SetupKubeBurstLimit(&commonCmdData, cmd)

cmd.Flags().BoolVarP(&cmdData.Validate, "validate", "", util.GetBoolEnvironmentDefaultFalse("WERF_VALIDATE"), "Validate your manifests against the Kubernetes cluster you are currently pointing at (default $WERF_VALIDATE)")
cmd.Flags().BoolVarP(&cmdData.IncludeCRDs, "include-crds", "", util.GetBoolEnvironmentDefaultTrue("WERF_INCLUDE_CRDS"), "Include CRDs in the templated output (default $WERF_INCLUDE_CRDS)")
Expand Down Expand Up @@ -372,10 +374,12 @@ func runRender(ctx context.Context, imageNameListFromArgs []string) error {
ExtraLabels: extraLabels,
ExtraRuntimeAnnotations: serviceAnnotations,
KubeAPIServerName: *commonCmdData.KubeApiServer,
KubeBurstLimit: *commonCmdData.KubeBurstLimit,
KubeCAPath: *commonCmdData.KubeCaPath,
KubeConfigBase64: *commonCmdData.KubeConfigBase64,
KubeConfigPaths: append([]string{*commonCmdData.KubeConfig}, *commonCmdData.KubeConfigPathMergeList...),
KubeContext: *commonCmdData.KubeContext,
KubeQPSLimit: *commonCmdData.KubeQpsLimit,
KubeSkipTLSVerify: *commonCmdData.SkipTlsVerifyKube,
KubeTLSServerName: *commonCmdData.KubeTlsServer,
KubeToken: *commonCmdData.KubeToken,
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ require (
github.com/werf/3p-helm-for-werf-helm v0.0.0-20241217155820-089f92cd5c9d
github.com/werf/common-go v0.0.0-20250115100423-863829c6587b
github.com/werf/copy-recurse v0.2.7
github.com/werf/kubedog v0.12.4-0.20250120134236-d21f7c460eb1
github.com/werf/kubedog v0.12.4-0.20250122091205-68c31637c845
github.com/werf/kubedog-for-werf-helm v0.0.0-20241217155728-9d45c48b82b6
github.com/werf/lockgate v0.1.1
github.com/werf/logboek v0.6.1
github.com/werf/nelm v0.0.0-20250120134421-7ab5abc19727
github.com/werf/nelm v0.0.0-20250122091325-1344f24210bc
github.com/werf/nelm-for-werf-helm v0.0.0-20241217155925-b0e6734d1dbf
go.opentelemetry.io/otel v1.24.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1435,16 +1435,16 @@ github.com/werf/common-go v0.0.0-20250115100423-863829c6587b h1:ft7Yse9RtV2SJTVb
github.com/werf/common-go v0.0.0-20250115100423-863829c6587b/go.mod h1:7pkHNfgZ2wvdwcMWCuDjdkY7iR3mIX5snYwbd1Iu7T4=
github.com/werf/copy-recurse v0.2.7 h1:3FTOarbJ9uhFLi75oeUCioK9zxZwuV7o28kuUBPDZPM=
github.com/werf/copy-recurse v0.2.7/go.mod h1:6Ypb+qN+hRBJgoCgEkX1vpbqcQ+8q69BQ3hi8s8Y6Qc=
github.com/werf/kubedog v0.12.4-0.20250120134236-d21f7c460eb1 h1:YYtKuJv7EszFF8SCjOJcfUdjOdbIURLRXSVu1VeWhmE=
github.com/werf/kubedog v0.12.4-0.20250120134236-d21f7c460eb1/go.mod h1:Y6pesrIN5uhFKqmHnHSoeW4jmVyZlWPFWv5SjB0rUPg=
github.com/werf/kubedog v0.12.4-0.20250122091205-68c31637c845 h1:LG5HPq5vDABdq6hPFIjUb9RX1IP2pNZLjRQlfzMQ/yQ=
github.com/werf/kubedog v0.12.4-0.20250122091205-68c31637c845/go.mod h1:Y6pesrIN5uhFKqmHnHSoeW4jmVyZlWPFWv5SjB0rUPg=
github.com/werf/kubedog-for-werf-helm v0.0.0-20241217155728-9d45c48b82b6 h1:lpgQPTCp+wNJfTqJWtR6A5gRA4e4m/eRJFV7V18XCoA=
github.com/werf/kubedog-for-werf-helm v0.0.0-20241217155728-9d45c48b82b6/go.mod h1:PA9xGVKX9Il6sCgvPrcB3/FahRme3bXRz4BuylvAssc=
github.com/werf/lockgate v0.1.1 h1:S400JFYjtWfE4i4LY9FA8zx0fMdfui9DPrBiTciCrx4=
github.com/werf/lockgate v0.1.1/go.mod h1:0yIFSLq9ausy6ejNxF5uUBf/Ib6daMAfXuCaTMZJzIE=
github.com/werf/logboek v0.6.1 h1:oEe6FkmlKg0z0n80oZjLplj6sXcBeLleCkjfOOZEL2g=
github.com/werf/logboek v0.6.1/go.mod h1:Gez5J4bxekyr6MxTmIJyId1F61rpO+0/V4vjCIEIZmk=
github.com/werf/nelm v0.0.0-20250120134421-7ab5abc19727 h1:O6XOlPJuVPG17/emc73r5KyGD9fAt8ISgliuhjl7coU=
github.com/werf/nelm v0.0.0-20250120134421-7ab5abc19727/go.mod h1:fHdXNhAcVcBldKmppUk7UpV0YInBmpBby4F1d+ay5UQ=
github.com/werf/nelm v0.0.0-20250122091325-1344f24210bc h1:UM0K2WNKgq/LDpkn5N3LSIlsfYM6MK2lImI662zvL2g=
github.com/werf/nelm v0.0.0-20250122091325-1344f24210bc/go.mod h1:hYBiw/t1UF+7EHutiIBCIk4yAEAWvOjg8DCMel6iXxs=
github.com/werf/nelm-for-werf-helm v0.0.0-20241217155925-b0e6734d1dbf h1:K51qz209c1yJgKzPw8AeS72T21F/ACp0VI3RJvT4THA=
github.com/werf/nelm-for-werf-helm v0.0.0-20241217155925-b0e6734d1dbf/go.mod h1:7RJXSGPKKPEvfPqrTwNA8jT7y52O0ebwhSbSn29ESMA=
github.com/xanzy/go-gitlab v0.31.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug=
Expand Down
4 changes: 4 additions & 0 deletions pkg/deploy/helm/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ type InitActionConfigOptions struct {
KubeConfigOptions kube.KubeConfigOptions
ReleasesHistoryMax int
RegistryClient *registry.Client
QPSLimit int
BurstLimit int
}

func InitActionConfig(ctx context.Context, kubeInitializer KubeInitializer, namespace string, envSettings *cli.EnvSettings, actionConfig *action.Configuration, opts InitActionConfigOptions) error {
configGetter, err := kube.NewKubeConfigGetter(kube.KubeConfigGetterOptions{
KubeConfigOptions: opts.KubeConfigOptions,
Namespace: namespace,
QPSLimit: opts.QPSLimit,
BurstLimit: opts.BurstLimit,
})
if err != nil {
return fmt.Errorf("error creating kube config getter: %w", err)
Expand Down

0 comments on commit 71f79ef

Please sign in to comment.