From dcb34ff78b0881ba4d252872e21901d372dfa126 Mon Sep 17 00:00:00 2001 From: yylt Date: Mon, 3 Mar 2025 16:02:04 +0800 Subject: [PATCH] setup environment GOMAXPROCS=2 Signed-off-by: yylt --- cni.go | 3 ++- exec.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 exec.go diff --git a/cni.go b/cni.go index 70ca382..6a4ecb5 100644 --- a/cni.go +++ b/cni.go @@ -98,9 +98,10 @@ func defaultCNIConfig() *libcni { []string{ DefaultCNIDir, }, - &invoke.DefaultExec{ + &Exec{ RawExec: &invoke.RawExec{Stderr: os.Stderr}, PluginDecoder: version.PluginDecoder{}, + Environ: []string{"GOMAXPROCS=2"}, }, ), networkCount: 1, diff --git a/exec.go b/exec.go new file mode 100644 index 0000000..a5748b5 --- /dev/null +++ b/exec.go @@ -0,0 +1,34 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package cni + +import ( + "context" + + "github.com/containernetworking/cni/pkg/invoke" + "github.com/containernetworking/cni/pkg/version" +) + +type Exec struct { + *invoke.RawExec + version.PluginDecoder + Environ []string +} + +func (e *Exec) ExecPlugin(ctx context.Context, pluginPath string, stdinData []byte, environ []string) ([]byte, error) { + return e.RawExec.ExecPlugin(ctx, pluginPath, stdinData, append(e.Environ, environ...)) +}