diff --git a/.github/workflows/static-checks.yaml b/.github/workflows/static-checks.yaml index 0bcefcc0a1..9b8af9c53b 100644 --- a/.github/workflows/static-checks.yaml +++ b/.github/workflows/static-checks.yaml @@ -8,13 +8,11 @@ jobs: os: [ubuntu-20.04] runs-on: ${{ matrix.os }} env: - GO111MODULE: off TRAVIS: "true" TRAVIS_BRANCH: ${{ github.base_ref }} TRAVIS_PULL_REQUEST_BRANCH: ${{ github.head_ref }} TRAVIS_PULL_REQUEST_SHA : ${{ github.event.pull_request.head.sha }} RUST_BACKTRACE: "1" - RUST_AGENT: "yes" target_branch: ${TRAVIS_BRANCH} steps: - name: Install Go @@ -25,9 +23,6 @@ jobs: GOPATH: ${{ runner.workspace }}/kata-containers - name: Setup GOPATH run: | - gopath_org=$(go env GOPATH)/src/github.com/kata-containers/ - mkdir -p ${gopath_org} - ln -s ${PWD} ${gopath_org} echo "TRAVIS_BRANCH: ${TRAVIS_BRANCH}" echo "TRAVIS_PULL_REQUEST_BRANCH: ${TRAVIS_PULL_REQUEST_BRANCH}" echo "TRAVIS_PULL_REQUEST_SHA: ${TRAVIS_PULL_REQUEST_SHA}" @@ -43,29 +38,29 @@ jobs: path: ./src/github.com/${{ github.repository }} - name: Setup travis references run: | - echo "TRAVIS_BRANCH=${TRAVIS_BRANCH:-$(echo $GITHUB_REF | awk 'BEGIN { FS = \"/\" } ; { print $3 }')}" + echo "TRAVIS_BRANCH=${TRAVIS_BRANCH:-$(echo $GITHUB_REF | awk 'BEGIN { FS = \"/\" } ; { print $3 }')}" target_branch=${TRAVIS_BRANCH} - name: Setup run: | - cd ${GOPATH}/src/github.com/kata-containers/kata-containers && ./ci/setup.sh + cd ${GOPATH}/src/github.com/${{ github.repository }} && ./ci/setup.sh env: GOPATH: ${{ runner.workspace }}/kata-containers - name: Building rust run: | - cd ${GOPATH}/src/github.com/kata-containers/kata-containers && ./ci/install_rust.sh + cd ${GOPATH}/src/github.com/${{ github.repository }} && ./ci/install_rust.sh PATH=$PATH:"$HOME/.cargo/bin" - - name: Make clippy + rustup target add x86_64-unknown-linux-musl + rustup component add rustfmt clippy + # Must build before static checks as we depend on some generated code in runtime and agent + - name: Build run: | - cd ${GOPATH}/src/github.com/kata-containers/kata-containers/src/agent && rustup target add x86_64-unknown-linux-musl && rustup component add rustfmt && rustup component add clippy && make clippy - - name: Static checks + cd ${GOPATH}/src/github.com/${{ github.repository }} && make + - name: Static Checks run: | - cd ${GOPATH}/src/github.com/kata-containers/kata-containers && ./ci/static-checks.sh - - name: Build agent + cd ${GOPATH}/src/github.com/${{ github.repository }} && ./ci/static-checks.sh + - name: Run Compiler Checks run: | - cd ${GOPATH}/src/github.com/kata-containers/kata-containers/src/agent && make - - name: Run agent unit tests + cd ${GOPATH}/src/github.com/${{ github.repository }} && make check + - name: Run Unit Tests run: | - cd ${GOPATH}/src/github.com/kata-containers/kata-containers/src/agent && make check - - name: Build agent-ctl tool (must be buildable against current agent) - run: | - cd ${GOPATH}/src/github.com/kata-containers/kata-containers/tools/agent-ctl && make + cd ${GOPATH}/src/github.com/${{ github.repository }} && make test diff --git a/src/agent/Makefile b/src/agent/Makefile index a968784da0..1659fe0460 100644 --- a/src/agent/Makefile +++ b/src/agent/Makefile @@ -141,6 +141,9 @@ clippy: $(GENERATED_CODE) -Aclippy::redundant_allocation \ -D warnings +format: + cargo fmt -- --check + ##TARGET install: install agent install: install-services @@ -157,7 +160,7 @@ test: @cargo test --all --target $(TRIPLE) ##TARGET check: run test -check: test +check: clippy format ##TARGET run: build and run agent run: diff --git a/src/runtime/Makefile b/src/runtime/Makefile index 685b715801..fc78df01f5 100644 --- a/src/runtime/Makefile +++ b/src/runtime/Makefile @@ -642,7 +642,6 @@ go-test: $(GENERATED_FILES) go test -v -mod=vendor ./... check-go-static: - $(QUIET_CHECK)../../ci/static-checks.sh $(QUIET_CHECK)../../ci/go-no-os-exit.sh ./cli $(QUIET_CHECK)../../ci/go-no-os-exit.sh ./virtcontainers diff --git a/src/runtime/cli/kata-check.go b/src/runtime/cli/kata-check.go index e2008c1bec..1a0b130d6b 100644 --- a/src/runtime/cli/kata-check.go +++ b/src/runtime/cli/kata-check.go @@ -63,7 +63,6 @@ const ( moduleParamDir = "parameters" successMessageCapable = "System is capable of running " + project successMessageCreate = "System can currently create " + project - successMessageVersion = "Version consistency of " + project + " is verified" failMessage = "System is not capable of running " + project kernelPropertyCorrect = "Kernel property value correct" @@ -398,7 +397,7 @@ EXAMPLES: span, _ := katautils.Trace(ctx, "check") defer span.End() - if context.Bool("no-network-checks") == false && os.Getenv(noNetworkEnvVar) == "" { + if !context.Bool("no-network-checks") && os.Getenv(noNetworkEnvVar) == "" { cmd := RelCmdCheck if context.Bool("only-list-releases") { diff --git a/src/runtime/cli/kata-monitor/main.go b/src/runtime/cli/kata-monitor/main.go index accd211945..c3565bcaf4 100644 --- a/src/runtime/cli/kata-monitor/main.go +++ b/src/runtime/cli/kata-monitor/main.go @@ -48,9 +48,9 @@ var versionTemplate = `{{.AppName}} ` func printVersion(ver versionInfo) { - t, err := template.New("version").Parse(versionTemplate) + t, _ := template.New("version").Parse(versionTemplate) - if err = t.Execute(os.Stdout, ver); err != nil { + if err := t.Execute(os.Stdout, ver); err != nil { panic(err) } } diff --git a/src/runtime/cli/main.go b/src/runtime/cli/main.go index e5da0a1f07..0c454f6608 100644 --- a/src/runtime/cli/main.go +++ b/src/runtime/cli/main.go @@ -64,9 +64,6 @@ var originalLoggerLevel = logrus.WarnLevel var debug = false -// if true, coredump when an internal error occurs or a fatal signal is received -var crashOnError = false - // concrete virtcontainer implementation var virtcontainersImpl = &vc.VCImpl{} @@ -86,8 +83,8 @@ var defaultErrorFile = os.Stderr // runtimeFlags is the list of supported global command-line flags var runtimeFlags = []cli.Flag{ cli.StringFlag{ - Name: "config, kata-config", - Usage: project + " config file path", + Name: "config, kata-config", + Usage: project + " config file path", }, cli.StringFlag{ Name: "log", @@ -110,8 +107,8 @@ var runtimeFlags = []cli.Flag{ Usage: "ignore cgroup permission errors ('true', 'false', or 'auto')", }, cli.BoolFlag{ - Name: "show-default-config-paths, kata-show-default-config-paths", - Usage: "show config file paths that will be checked for (in order)", + Name: "show-default-config-paths, kata-show-default-config-paths", + Usage: "show config file paths that will be checked for (in order)", }, cli.BoolFlag{ Name: "systemd-cgroup", @@ -322,13 +319,12 @@ func beforeSubcommands(c *cli.Context) error { } } - configFile, runtimeConfig, err = katautils.LoadConfiguration(c.GlobalString("config"), ignoreConfigLogs, false) + configFile, runtimeConfig, err = katautils.LoadConfiguration(c.GlobalString("kata-config"), ignoreConfigLogs, false) if err != nil { fatal(err) } if !subCmdIsCheckCmd { debug = runtimeConfig.Debug - crashOnError = runtimeConfig.Debug if traceRootSpan != "" { // Create the tracer. diff --git a/src/runtime/cli/main_test.go b/src/runtime/cli/main_test.go index d27052ae73..d47a016560 100644 --- a/src/runtime/cli/main_test.go +++ b/src/runtime/cli/main_test.go @@ -8,7 +8,6 @@ package main import ( "bytes" "context" - "encoding/json" "errors" "flag" "fmt" @@ -29,7 +28,6 @@ import ( "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/compatoci" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/oci" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/vcmock" - "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/stretchr/testify/assert" @@ -44,10 +42,8 @@ const ( // small docker image used to create root filesystems from testDockerImage = "busybox" - testSandboxID = "99999999-9999-9999-99999999999999999" - testContainerID = "1" - testBundle = "bundle" - testConsole = "/dev/pts/999" + testBundle = "bundle" + testConsole = "/dev/pts/999" ) var ( @@ -387,44 +383,6 @@ func makeOCIBundle(bundleDir string) error { return nil } -func writeOCIConfigFile(spec specs.Spec, configPath string) error { - if configPath == "" { - return errors.New("BUG: need config file path") - } - - bytes, err := json.MarshalIndent(spec, "", "\t") - if err != nil { - return err - } - - return ioutil.WriteFile(configPath, bytes, testFileMode) -} - -func newSingleContainerStatus(containerID string, containerState types.ContainerState, annotations map[string]string, spec *specs.Spec) vc.ContainerStatus { - return vc.ContainerStatus{ - ID: containerID, - State: containerState, - Annotations: annotations, - Spec: spec, - } -} - -func execCLICommandFunc(assertHandler *assert.Assertions, cliCommand cli.Command, set *flag.FlagSet, expectedErr bool) { - ctx := createCLIContext(set) - ctx.App.Name = "foo" - - fn, ok := cliCommand.Action.(func(context *cli.Context) error) - assertHandler.True(ok) - - err := fn(ctx) - - if expectedErr { - assertHandler.Error(err) - } else { - assertHandler.Nil(err) - } -} - func createCLIContextWithApp(flagSet *flag.FlagSet, app *cli.App) *cli.Context { ctx := cli.NewContext(app, flagSet, nil) diff --git a/src/runtime/cli/release_test.go b/src/runtime/cli/release_test.go index b6d94ac0f5..fc5b46cbad 100644 --- a/src/runtime/cli/release_test.go +++ b/src/runtime/cli/release_test.go @@ -458,7 +458,7 @@ func TestGetNewReleaseType(t *testing.T) { } data := []testData{ - // Check build metadata (ignored for version comparisions) + // Check build metadata (ignored for version comparisons) {"2.0.0+build", "2.0.0", true, ""}, {"2.0.0+build-1", "2.0.0+build-2", true, ""}, {"1.12.0+build", "1.12.0", true, ""}, diff --git a/src/runtime/cli/utils.go b/src/runtime/cli/utils.go index 4d982e8cb6..be2b9e5d7b 100644 --- a/src/runtime/cli/utils.go +++ b/src/runtime/cli/utils.go @@ -189,21 +189,3 @@ func constructVersionInfo(version string) VersionInfo { } } - -func versionEqual(a VersionInfo, b VersionInfo) bool { - av, err := semver.Make(a.Semver) - if err != nil { - return false - } - - bv, err := semver.Make(b.Semver) - if err != nil { - return false - } - - if av.Major == bv.Major && av.Minor == bv.Minor && av.Patch == bv.Patch { - return true - } - - return false -} diff --git a/src/runtime/cli/utils_arch_base.go b/src/runtime/cli/utils_arch_base.go deleted file mode 100644 index a0c6a5e71f..0000000000 --- a/src/runtime/cli/utils_arch_base.go +++ /dev/null @@ -1,10 +0,0 @@ -// +build !s390x -// -// SPDX-License-Identifier: Apache-2.0 -// - -package main - -func archConvertStatFs(cgroupFsType int) int64 { - return int64(cgroupFsType) -} diff --git a/src/runtime/cli/utils_s390x.go b/src/runtime/cli/utils_s390x.go deleted file mode 100644 index 6acd5627ef..0000000000 --- a/src/runtime/cli/utils_s390x.go +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) 2018 IBM -// -// SPDX-License-Identifier: Apache-2.0 -// - -package main - -func archConvertStatFs(cgroupFsType int) uint32 { - return uint32(cgroupFsType) -} diff --git a/src/runtime/containerd-shim-v2/metrics_test.go b/src/runtime/containerd-shim-v2/metrics_test.go index a2ff047d9a..d40ba6347e 100644 --- a/src/runtime/containerd-shim-v2/metrics_test.go +++ b/src/runtime/containerd-shim-v2/metrics_test.go @@ -7,6 +7,7 @@ package containerdshim import ( + "context" "testing" "github.com/containerd/cgroups" @@ -50,7 +51,7 @@ func TestStatNetworkMetric(t *testing.T) { sandbox.StatsContainerFunc = nil }() - resp, err := sandbox.StatsContainer(testContainerID) + resp, err := sandbox.StatsContainer(context.Background(), testContainerID) assert.NoError(err) metrics := statsToMetrics(&resp) diff --git a/src/runtime/containerd-shim-v2/service.go b/src/runtime/containerd-shim-v2/service.go index 329c1982b0..7c1ff89022 100644 --- a/src/runtime/containerd-shim-v2/service.go +++ b/src/runtime/containerd-shim-v2/service.go @@ -301,7 +301,7 @@ func trace(ctx context.Context, name string) (otelTrace.Span, context.Context) { } func (s *service) Cleanup(ctx context.Context) (_ *taskAPI.DeleteResponse, err error) { - span, ctx := trace(s.rootCtx, "Cleanup") + span, _ := trace(s.rootCtx, "Cleanup") defer span.End() //Since the binary cleanup will return the DeleteResponse from stdout to @@ -416,7 +416,7 @@ func (s *service) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (_ * // Start a process func (s *service) Start(ctx context.Context, r *taskAPI.StartRequest) (_ *taskAPI.StartResponse, err error) { - span, ctx := trace(s.rootCtx, "Start") + span, _ := trace(s.rootCtx, "Start") defer span.End() start := time.Now() @@ -467,7 +467,7 @@ func (s *service) Start(ctx context.Context, r *taskAPI.StartRequest) (_ *taskAP // Delete the initial process and container func (s *service) Delete(ctx context.Context, r *taskAPI.DeleteRequest) (_ *taskAPI.DeleteResponse, err error) { - span, ctx := trace(s.rootCtx, "Delete") + span, _ := trace(s.rootCtx, "Delete") defer span.End() start := time.Now() @@ -519,7 +519,7 @@ func (s *service) Delete(ctx context.Context, r *taskAPI.DeleteRequest) (_ *task // Exec an additional process inside the container func (s *service) Exec(ctx context.Context, r *taskAPI.ExecProcessRequest) (_ *ptypes.Empty, err error) { - span, ctx := trace(s.rootCtx, "Exec") + span, _ := trace(s.rootCtx, "Exec") defer span.End() start := time.Now() @@ -557,7 +557,7 @@ func (s *service) Exec(ctx context.Context, r *taskAPI.ExecProcessRequest) (_ *p // ResizePty of a process func (s *service) ResizePty(ctx context.Context, r *taskAPI.ResizePtyRequest) (_ *ptypes.Empty, err error) { - span, ctx := trace(s.rootCtx, "ResizePty") + span, _ := trace(s.rootCtx, "ResizePty") defer span.End() start := time.Now() @@ -596,7 +596,7 @@ func (s *service) ResizePty(ctx context.Context, r *taskAPI.ResizePtyRequest) (_ // State returns runtime state information for a process func (s *service) State(ctx context.Context, r *taskAPI.StateRequest) (_ *taskAPI.StateResponse, err error) { - span, ctx := trace(s.rootCtx, "State") + span, _ := trace(s.rootCtx, "State") defer span.End() start := time.Now() @@ -648,7 +648,7 @@ func (s *service) State(ctx context.Context, r *taskAPI.StateRequest) (_ *taskAP // Pause the container func (s *service) Pause(ctx context.Context, r *taskAPI.PauseRequest) (_ *ptypes.Empty, err error) { - span, ctx := trace(s.rootCtx, "Pause") + span, _ := trace(s.rootCtx, "Pause") defer span.End() start := time.Now() @@ -687,7 +687,7 @@ func (s *service) Pause(ctx context.Context, r *taskAPI.PauseRequest) (_ *ptypes // Resume the container func (s *service) Resume(ctx context.Context, r *taskAPI.ResumeRequest) (_ *ptypes.Empty, err error) { - span, ctx := trace(s.rootCtx, "Resume") + span, _ := trace(s.rootCtx, "Resume") defer span.End() start := time.Now() @@ -724,7 +724,7 @@ func (s *service) Resume(ctx context.Context, r *taskAPI.ResumeRequest) (_ *ptyp // Kill a process with the provided signal func (s *service) Kill(ctx context.Context, r *taskAPI.KillRequest) (_ *ptypes.Empty, err error) { - span, ctx := trace(s.rootCtx, "Kill") + span, _ := trace(s.rootCtx, "Kill") defer span.End() start := time.Now() @@ -785,7 +785,7 @@ func (s *service) Kill(ctx context.Context, r *taskAPI.KillRequest) (_ *ptypes.E // Since for kata, it cannot get the process's pid from VM, // thus only return the Shim's pid directly. func (s *service) Pids(ctx context.Context, r *taskAPI.PidsRequest) (_ *taskAPI.PidsResponse, err error) { - span, ctx := trace(s.rootCtx, "Pids") + span, _ := trace(s.rootCtx, "Pids") defer span.End() var processes []*task.ProcessInfo @@ -808,7 +808,7 @@ func (s *service) Pids(ctx context.Context, r *taskAPI.PidsRequest) (_ *taskAPI. // CloseIO of a process func (s *service) CloseIO(ctx context.Context, r *taskAPI.CloseIORequest) (_ *ptypes.Empty, err error) { - span, ctx := trace(s.rootCtx, "CloseIO") + span, _ := trace(s.rootCtx, "CloseIO") defer span.End() start := time.Now() @@ -849,7 +849,7 @@ func (s *service) CloseIO(ctx context.Context, r *taskAPI.CloseIORequest) (_ *pt // Checkpoint the container func (s *service) Checkpoint(ctx context.Context, r *taskAPI.CheckpointTaskRequest) (_ *ptypes.Empty, err error) { - span, ctx := trace(s.rootCtx, "Checkpoint") + span, _ := trace(s.rootCtx, "Checkpoint") defer span.End() start := time.Now() @@ -863,7 +863,7 @@ func (s *service) Checkpoint(ctx context.Context, r *taskAPI.CheckpointTaskReque // Connect returns shim information such as the shim's pid func (s *service) Connect(ctx context.Context, r *taskAPI.ConnectRequest) (_ *taskAPI.ConnectResponse, err error) { - span, ctx := trace(s.rootCtx, "Connect") + span, _ := trace(s.rootCtx, "Connect") defer span.End() start := time.Now() @@ -883,7 +883,7 @@ func (s *service) Connect(ctx context.Context, r *taskAPI.ConnectRequest) (_ *ta } func (s *service) Shutdown(ctx context.Context, r *taskAPI.ShutdownRequest) (_ *ptypes.Empty, err error) { - span, ctx := trace(s.rootCtx, "Shutdown") + span, _ := trace(s.rootCtx, "Shutdown") start := time.Now() defer func() { @@ -911,7 +911,7 @@ func (s *service) Shutdown(ctx context.Context, r *taskAPI.ShutdownRequest) (_ * } func (s *service) Stats(ctx context.Context, r *taskAPI.StatsRequest) (_ *taskAPI.StatsResponse, err error) { - span, ctx := trace(s.rootCtx, "Stats") + span, _ := trace(s.rootCtx, "Stats") defer span.End() start := time.Now() @@ -940,7 +940,7 @@ func (s *service) Stats(ctx context.Context, r *taskAPI.StatsRequest) (_ *taskAP // Update a running container func (s *service) Update(ctx context.Context, r *taskAPI.UpdateTaskRequest) (_ *ptypes.Empty, err error) { - span, ctx := trace(s.rootCtx, "Update") + span, _ := trace(s.rootCtx, "Update") defer span.End() start := time.Now() @@ -972,7 +972,7 @@ func (s *service) Update(ctx context.Context, r *taskAPI.UpdateTaskRequest) (_ * // Wait for a process to exit func (s *service) Wait(ctx context.Context, r *taskAPI.WaitRequest) (_ *taskAPI.WaitResponse, err error) { - span, ctx := trace(s.rootCtx, "Wait") + span, _ := trace(s.rootCtx, "Wait") defer span.End() var ret uint32 diff --git a/src/runtime/containerd-shim-v2/shim_management.go b/src/runtime/containerd-shim-v2/shim_management.go index 2f08a88fcc..e03224f072 100644 --- a/src/runtime/containerd-shim-v2/shim_management.go +++ b/src/runtime/containerd-shim-v2/shim_management.go @@ -65,8 +65,7 @@ func (s *service) serveMetrics(w http.ResponseWriter, r *http.Request) { // encode the metrics encoder := expfmt.NewEncoder(w, expfmt.FmtText) for _, mf := range mfs { - if err := encoder.Encode(mf); err != nil { - } + encoder.Encode(mf) } // if using an old agent, only collect shim/sandbox metrics. @@ -150,7 +149,7 @@ func (s *service) startManagementServer(ctx context.Context, ociSpec *specs.Spec shimMgtLog.Info("kata management inited") - // bind hanlder + // bind handler m := http.NewServeMux() m.Handle("/metrics", http.HandlerFunc(s.serveMetrics)) m.Handle("/agent-url", http.HandlerFunc(s.agentURL)) diff --git a/src/runtime/containerd-shim-v2/shim_metrics.go b/src/runtime/containerd-shim-v2/shim_metrics.go index e9f3655ae1..d946665e18 100644 --- a/src/runtime/containerd-shim-v2/shim_metrics.go +++ b/src/runtime/containerd-shim-v2/shim_metrics.go @@ -177,7 +177,7 @@ func calcOverhead(initialSandboxStats, finishSandboxStats vc.SandboxStats, initi cpuUsageGuest := float64(guestFinalCPU-guestInitCPU) / deltaTime * 100 cpuUsageHost := float64(hostFinalCPU-hostInitCPU) / deltaTime * 100 - return float64(hostMemoryUsage - guestMemoryUsage), float64(cpuUsageHost - cpuUsageGuest) + return float64(hostMemoryUsage - guestMemoryUsage), cpuUsageHost - cpuUsageGuest } func (s *service) getPodOverhead(ctx context.Context) (float64, float64, error) { diff --git a/src/runtime/containerd-shim-v2/shim_metrics_test.go b/src/runtime/containerd-shim-v2/shim_metrics_test.go index 03b09ee991..255c0ccfed 100644 --- a/src/runtime/containerd-shim-v2/shim_metrics_test.go +++ b/src/runtime/containerd-shim-v2/shim_metrics_test.go @@ -6,6 +6,7 @@ package containerdshim import ( + "context" "testing" vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers" @@ -83,7 +84,7 @@ func TestStatsSandbox(t *testing.T) { containers: make(map[string]*container), } - initialSandboxStats, initialContainerStats, err := s.statsSandbox() + initialSandboxStats, initialContainerStats, err := s.statsSandbox(context.Background()) assert.Nil(err) assert.Equal(uint64(1000*1e9), initialSandboxStats.CgroupStats.CPUStats.CPUUsage.TotalUsage) assert.Equal(2, len(initialContainerStats)) @@ -96,7 +97,7 @@ func TestStatsSandbox(t *testing.T) { sandbox.StatsFunc = getSandboxCPUFunc(2000, 110000) sandbox.StatsContainerFunc = getStatsContainerCPUFunc(200, 400, 20000, 40000) - finishSandboxStats, finishContainersStats, err := s.statsSandbox() + finishSandboxStats, finishContainersStats, _ := s.statsSandbox(context.Background()) // calc overhead mem, cpu := calcOverhead(initialSandboxStats, finishSandboxStats, initialContainerStats, finishContainersStats, 1e9) diff --git a/src/runtime/pkg/kata-monitor/metrics_test.go b/src/runtime/pkg/kata-monitor/metrics_test.go index 8ea63b1d72..5263d2a932 100644 --- a/src/runtime/pkg/kata-monitor/metrics_test.go +++ b/src/runtime/pkg/kata-monitor/metrics_test.go @@ -107,14 +107,14 @@ func TestEncodeMetricFamily(t *testing.T) { scrapeCount.Inc() scrapeCount.Inc() - mfs, err := prometheus.DefaultGatherer.Gather() + mfs, _ := prometheus.DefaultGatherer.Gather() // create encoder buf := bytes.NewBufferString("") encoder := expfmt.NewEncoder(buf, expfmt.FmtText) // encode metrics to text format - err = encodeMetricFamily(mfs, encoder) + err := encodeMetricFamily(mfs, encoder) assert.Nil(err, "encodeMetricFamily should not return error") // here will be to many metrics, diff --git a/src/runtime/pkg/kata-monitor/monitor.go b/src/runtime/pkg/kata-monitor/monitor.go index 3254b52021..64266fdb7d 100644 --- a/src/runtime/pkg/kata-monitor/monitor.go +++ b/src/runtime/pkg/kata-monitor/monitor.go @@ -38,7 +38,7 @@ type KataMonitor struct { // NewKataMonitor create and return a new KataMonitor instance func NewKataMonitor(containerdAddr, containerdConfigFile string) (*KataMonitor, error) { if containerdAddr == "" { - return nil, fmt.Errorf("Containerd serve address missing.") + return nil, fmt.Errorf("containerd serve address missing") } containerdConf := &srvconfig.Config{ @@ -82,7 +82,7 @@ func (km *KataMonitor) initSandboxCache() error { // GetAgentURL returns agent URL func (km *KataMonitor) GetAgentURL(w http.ResponseWriter, r *http.Request) { - sandboxID, err := getSandboxIdFromReq(r) + sandboxID, err := getSandboxIDFromReq(r) if err != nil { commonServeError(w, http.StatusBadRequest, err) return diff --git a/src/runtime/pkg/kata-monitor/pprof.go b/src/runtime/pkg/kata-monitor/pprof.go index 9e54315a42..86f39c4667 100644 --- a/src/runtime/pkg/kata-monitor/pprof.go +++ b/src/runtime/pkg/kata-monitor/pprof.go @@ -21,7 +21,7 @@ func serveError(w http.ResponseWriter, status int, txt string) { } func (km *KataMonitor) composeSocketAddress(r *http.Request) (string, error) { - sandbox, err := getSandboxIdFromReq(r) + sandbox, err := getSandboxIDFromReq(r) if err != nil { return "", err } diff --git a/src/runtime/pkg/kata-monitor/sandbox_cache.go b/src/runtime/pkg/kata-monitor/sandbox_cache.go index 8d3b579751..f749ef4641 100644 --- a/src/runtime/pkg/kata-monitor/sandbox_cache.go +++ b/src/runtime/pkg/kata-monitor/sandbox_cache.go @@ -157,7 +157,7 @@ func (sc *sandboxCache) startEventsListener(addr string) error { // if the container is a sandbox container, // means the VM is started, and can start to collect metrics from the VM. if isSandboxContainer(&c) { - // we can simply put the contaienrid in sandboxes list if the conatiner is a sandbox container + // we can simply put the contaienrid in sandboxes list if the container is a sandbox container sc.putIfNotExists(cc.ID, e.Namespace) monitorLog.WithField("container", cc.ID).Info("add sandbox to cache") } diff --git a/src/runtime/pkg/kata-monitor/shim_client.go b/src/runtime/pkg/kata-monitor/shim_client.go index f711f88f99..b2c462e8fa 100644 --- a/src/runtime/pkg/kata-monitor/shim_client.go +++ b/src/runtime/pkg/kata-monitor/shim_client.go @@ -25,7 +25,7 @@ func commonServeError(w http.ResponseWriter, status int, err error) { } } -func getSandboxIdFromReq(r *http.Request) (string, error) { +func getSandboxIDFromReq(r *http.Request) (string, error) { sandbox := r.URL.Query().Get("sandbox") if sandbox != "" { return sandbox, nil diff --git a/src/runtime/pkg/katautils/config-settings.go.in b/src/runtime/pkg/katautils/config-settings.go.in index 730b0c8bb8..7cd9138baa 100644 --- a/src/runtime/pkg/katautils/config-settings.go.in +++ b/src/runtime/pkg/katautils/config-settings.go.in @@ -17,7 +17,6 @@ var defaultInitrdPath = "/usr/share/kata-containers/kata-containers-initrd.img" var defaultFirmwarePath = "" var defaultMachineAccelerators = "" var defaultCPUFeatures = "" -var defaultShimPath = "/usr/libexec/kata-containers/kata-shim" var systemdUnitName = "kata-containers.target" const defaultKernelParams = "" diff --git a/src/runtime/pkg/katautils/config.go b/src/runtime/pkg/katautils/config.go index d10037501f..d3dce569dc 100644 --- a/src/runtime/pkg/katautils/config.go +++ b/src/runtime/pkg/katautils/config.go @@ -72,12 +72,9 @@ type factory struct { type hypervisor struct { Path string `toml:"path"` - HypervisorPathList []string `toml:"valid_hypervisor_paths"` JailerPath string `toml:"jailer_path"` - JailerPathList []string `toml:"valid_jailer_paths"` Kernel string `toml:"kernel"` CtlPath string `toml:"ctlpath"` - CtlPathList []string `toml:"valid_ctlpaths"` Initrd string `toml:"initrd"` Image string `toml:"image"` Firmware string `toml:"firmware"` @@ -89,17 +86,23 @@ type hypervisor struct { EntropySource string `toml:"entropy_source"` SharedFS string `toml:"shared_fs"` VirtioFSDaemon string `toml:"virtio_fs_daemon"` - VirtioFSDaemonList []string `toml:"valid_virtio_fs_daemon_paths"` VirtioFSCache string `toml:"virtio_fs_cache"` + VhostUserStorePath string `toml:"vhost_user_store_path"` + FileBackedMemRootDir string `toml:"file_mem_backend"` + GuestHookPath string `toml:"guest_hook_path"` + GuestMemoryDumpPath string `toml:"guest_memory_dump_path"` + HypervisorPathList []string `toml:"valid_hypervisor_paths"` + JailerPathList []string `toml:"valid_jailer_paths"` + CtlPathList []string `toml:"valid_ctlpaths"` + VirtioFSDaemonList []string `toml:"valid_virtio_fs_daemon_paths"` VirtioFSExtraArgs []string `toml:"virtio_fs_extra_args"` PFlashList []string `toml:"pflashes"` - VirtioFSCacheSize uint32 `toml:"virtio_fs_cache_size"` - BlockDeviceCacheSet bool `toml:"block_device_cache_set"` - BlockDeviceCacheDirect bool `toml:"block_device_cache_direct"` - BlockDeviceCacheNoflush bool `toml:"block_device_cache_noflush"` - EnableVhostUserStore bool `toml:"enable_vhost_user_store"` - VhostUserStorePath string `toml:"vhost_user_store_path"` VhostUserStorePathList []string `toml:"valid_vhost_user_store_paths"` + FileBackedMemRootList []string `toml:"valid_file_mem_backends"` + EnableAnnotations []string `toml:"enable_annotations"` + RxRateLimiterMaxRate uint64 `toml:"rx_rate_limiter_max_rate"` + TxRateLimiterMaxRate uint64 `toml:"tx_rate_limiter_max_rate"` + VirtioFSCacheSize uint32 `toml:"virtio_fs_cache_size"` NumVCPUs int32 `toml:"default_vcpus"` DefaultMaxVCPUs uint32 `toml:"default_maxvcpus"` MemorySize uint32 `toml:"default_memory"` @@ -108,14 +111,16 @@ type hypervisor struct { DefaultBridges uint32 `toml:"default_bridges"` Msize9p uint32 `toml:"msize_9p"` PCIeRootPort uint32 `toml:"pcie_root_port"` + BlockDeviceCacheSet bool `toml:"block_device_cache_set"` + BlockDeviceCacheDirect bool `toml:"block_device_cache_direct"` + BlockDeviceCacheNoflush bool `toml:"block_device_cache_noflush"` + EnableVhostUserStore bool `toml:"enable_vhost_user_store"` DisableBlockDeviceUse bool `toml:"disable_block_device_use"` MemPrealloc bool `toml:"enable_mem_prealloc"` HugePages bool `toml:"enable_hugepages"` VirtioMem bool `toml:"enable_virtio_mem"` IOMMU bool `toml:"enable_iommu"` IOMMUPlatform bool `toml:"enable_iommu_platform"` - FileBackedMemRootDir string `toml:"file_mem_backend"` - FileBackedMemRootList []string `toml:"valid_file_mem_backends"` Swap bool `toml:"enable_swap"` Debug bool `toml:"enable_debug"` DisableNestingChecks bool `toml:"disable_nesting_checks"` @@ -123,35 +128,30 @@ type hypervisor struct { DisableImageNvdimm bool `toml:"disable_image_nvdimm"` HotplugVFIOOnRootBus bool `toml:"hotplug_vfio_on_root_bus"` DisableVhostNet bool `toml:"disable_vhost_net"` - GuestHookPath string `toml:"guest_hook_path"` - RxRateLimiterMaxRate uint64 `toml:"rx_rate_limiter_max_rate"` - TxRateLimiterMaxRate uint64 `toml:"tx_rate_limiter_max_rate"` - EnableAnnotations []string `toml:"enable_annotations"` - GuestMemoryDumpPath string `toml:"guest_memory_dump_path"` GuestMemoryDumpPaging bool `toml:"guest_memory_dump_paging"` } type runtime struct { + InterNetworkModel string `toml:"internetworking_model"` + JaegerEndpoint string `toml:"jaeger_endpoint"` + JaegerUser string `toml:"jaeger_user"` + JaegerPassword string `toml:"jaeger_password"` + SandboxBindMounts []string `toml:"sandbox_bind_mounts"` + Experimental []string `toml:"experimental"` Debug bool `toml:"enable_debug"` Tracing bool `toml:"enable_tracing"` DisableNewNetNs bool `toml:"disable_new_netns"` DisableGuestSeccomp bool `toml:"disable_guest_seccomp"` SandboxCgroupOnly bool `toml:"sandbox_cgroup_only"` - SandboxBindMounts []string `toml:"sandbox_bind_mounts"` - Experimental []string `toml:"experimental"` - InterNetworkModel string `toml:"internetworking_model"` EnablePprof bool `toml:"enable_pprof"` - JaegerEndpoint string `toml:"jaeger_endpoint"` - JaegerUser string `toml:"jaeger_user"` - JaegerPassword string `toml:"jaeger_password"` } type agent struct { - Debug bool `toml:"enable_debug"` - Tracing bool `toml:"enable_tracing"` TraceMode string `toml:"trace_mode"` TraceType string `toml:"trace_type"` KernelModules []string `toml:"kernel_modules"` + Debug bool `toml:"enable_debug"` + Tracing bool `toml:"enable_tracing"` DebugConsoleEnabled bool `toml:"debug_console_enabled"` } @@ -449,20 +449,12 @@ func (h hypervisor) getInitrdAndImage() (initrd string, image string, err error) return } -func (h hypervisor) getRxRateLimiterCfg() (uint64, error) { - if h.RxRateLimiterMaxRate < 0 { - return 0, fmt.Errorf("rx Rate Limiter configuration must be greater than or equal to 0, max_rate %v", h.RxRateLimiterMaxRate) - } - - return h.RxRateLimiterMaxRate, nil +func (h hypervisor) getRxRateLimiterCfg() uint64 { + return h.RxRateLimiterMaxRate } -func (h hypervisor) getTxRateLimiterCfg() (uint64, error) { - if h.TxRateLimiterMaxRate < 0 { - return 0, fmt.Errorf("tx Rate Limiter configuration must be greater than or equal to 0, max_rate %v", h.TxRateLimiterMaxRate) - } - - return h.TxRateLimiterMaxRate, nil +func (h hypervisor) getTxRateLimiterCfg() uint64 { + return h.TxRateLimiterMaxRate } func (h hypervisor) getIOMMUPlatform() bool { @@ -547,15 +539,8 @@ func newFirecrackerHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { return vc.HypervisorConfig{}, err } - rxRateLimiterMaxRate, err := h.getRxRateLimiterCfg() - if err != nil { - return vc.HypervisorConfig{}, err - } - - txRateLimiterMaxRate, err := h.getTxRateLimiterCfg() - if err != nil { - return vc.HypervisorConfig{}, err - } + rxRateLimiterMaxRate := h.getRxRateLimiterCfg() + txRateLimiterMaxRate := h.getTxRateLimiterCfg() return vc.HypervisorConfig{ HypervisorPath: hypervisor, @@ -656,15 +641,8 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { return vc.HypervisorConfig{}, err } - rxRateLimiterMaxRate, err := h.getRxRateLimiterCfg() - if err != nil { - return vc.HypervisorConfig{}, err - } - - txRateLimiterMaxRate, err := h.getTxRateLimiterCfg() - if err != nil { - return vc.HypervisorConfig{}, err - } + rxRateLimiterMaxRate := h.getRxRateLimiterCfg() + txRateLimiterMaxRate := h.getTxRateLimiterCfg() return vc.HypervisorConfig{ HypervisorPath: hypervisor, diff --git a/src/runtime/pkg/katautils/config_test.go b/src/runtime/pkg/katautils/config_test.go index eb6b7d6a39..32be51ff68 100644 --- a/src/runtime/pkg/katautils/config_test.go +++ b/src/runtime/pkg/katautils/config_test.go @@ -172,6 +172,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf SharedFS: sharedFS, VirtioFSDaemon: virtioFSdaemon, VirtioFSCache: defaultVirtioFSCacheMode, + PFlash: []string{}, SGXEPCSize: epcSize, } diff --git a/src/runtime/virtcontainers/acrn.go b/src/runtime/virtcontainers/acrn.go index 8103d5e8fe..f04ebd6e53 100644 --- a/src/runtime/virtcontainers/acrn.go +++ b/src/runtime/virtcontainers/acrn.go @@ -25,10 +25,10 @@ import ( "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api" + vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/uuid" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils" - vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" ) // Since ACRN is using the store in a quite abnormal way, let's first draw it back from store to here @@ -420,7 +420,7 @@ func (a *Acrn) createSandbox(ctx context.Context, id string, networkNS NetworkNa // startSandbox will start the Sandbox's VM. func (a *Acrn) startSandbox(ctx context.Context, timeoutSecs int) error { - span, ctx := a.trace(ctx, "startSandbox") + span, _ := a.trace(ctx, "startSandbox") defer span.End() if a.config.Debug { @@ -570,7 +570,7 @@ func (a *Acrn) updateBlockDevice(drive *config.BlockDrive) error { } func (a *Acrn) hotplugAddDevice(ctx context.Context, devInfo interface{}, devType deviceType) (interface{}, error) { - span, ctx := a.trace(ctx, "hotplugAddDevice") + span, _ := a.trace(ctx, "hotplugAddDevice") defer span.End() switch devType { @@ -584,7 +584,7 @@ func (a *Acrn) hotplugAddDevice(ctx context.Context, devInfo interface{}, devTyp } func (a *Acrn) hotplugRemoveDevice(ctx context.Context, devInfo interface{}, devType deviceType) (interface{}, error) { - span, ctx := a.trace(ctx, "hotplugRemoveDevice") + span, _ := a.trace(ctx, "hotplugRemoveDevice") defer span.End() // Not supported. return success diff --git a/src/runtime/virtcontainers/agent.go b/src/runtime/virtcontainers/agent.go index 426413c58b..87e061204d 100644 --- a/src/runtime/virtcontainers/agent.go +++ b/src/runtime/virtcontainers/agent.go @@ -206,7 +206,7 @@ type agent interface { // getOOMEvent will wait on OOM events that occur in the sandbox. // Will return the ID of the container where the event occurred. - getOOMEvent(ctx context.Context, ) (string, error) + getOOMEvent(ctx context.Context) (string, error) // getAgentMetrics get metrics of agent and guest through agent getAgentMetrics(context.Context, *grpc.GetMetricsRequest) (*grpc.Metrics, error) diff --git a/src/runtime/virtcontainers/api.go b/src/runtime/virtcontainers/api.go index 3cb6fe66c3..22e0634730 100644 --- a/src/runtime/virtcontainers/api.go +++ b/src/runtime/virtcontainers/api.go @@ -53,7 +53,7 @@ func SetLogger(ctx context.Context, logger *logrus.Entry) { // CreateSandbox is the virtcontainers sandbox creation entry point. // CreateSandbox creates a sandbox and its containers. It does not start them. func CreateSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factory) (VCSandbox, error) { - span, ctx := trace(ctx, "CreateSandbox") + span, _ := trace(ctx, "CreateSandbox") defer span.End() s, err := createSandboxFromConfig(ctx, sandboxConfig, factory) @@ -62,7 +62,7 @@ func CreateSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Fac } func createSandboxFromConfig(ctx context.Context, sandboxConfig SandboxConfig, factory Factory) (_ *Sandbox, err error) { - span, ctx := trace(ctx, "createSandboxFromConfig") + span, _ := trace(ctx, "createSandboxFromConfig") defer span.End() // Create the sandbox. @@ -136,7 +136,7 @@ func createSandboxFromConfig(ctx context.Context, sandboxConfig SandboxConfig, f // in the sandbox left, do stop the sandbox and delete it. Those serial operations will be done exclusively by // locking the sandbox. func CleanupContainer(ctx context.Context, sandboxID, containerID string, force bool) error { - span, ctx := trace(ctx, "CleanupContainer") + span, _ := trace(ctx, "CleanupContainer") defer span.End() if sandboxID == "" { diff --git a/src/runtime/virtcontainers/api_test.go b/src/runtime/virtcontainers/api_test.go index 741db3b033..b2aa32833f 100644 --- a/src/runtime/virtcontainers/api_test.go +++ b/src/runtime/virtcontainers/api_test.go @@ -15,7 +15,6 @@ import ( "testing" ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils" - "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations" vccgroups "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/mock" @@ -74,16 +73,6 @@ func newBasicTestCmd() types.Cmd { return cmd } -func rmSandboxDir(sid string) error { - store, err := persist.GetDriver() - if err != nil { - return fmt.Errorf("failed to get fs persist driver: %v", err) - } - - store.Destroy(sid) - return nil -} - func newTestSandboxConfigNoop() SandboxConfig { bundlePath := filepath.Join(testDir, testBundle) containerAnnotations[annotations.BundlePathKey] = bundlePath @@ -170,8 +159,12 @@ func TestCreateSandboxKataAgentSuccessful(t *testing.T) { config := newTestSandboxConfigKataAgent() + url, err := mock.GenerateKataMockHybridVSock() + assert.NoError(err) + MockHybridVSockPath = url + hybridVSockTTRPCMock := mock.HybridVSockTTRPCMock{} - err := hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", MockHybridVSockPath)) + err = hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", url)) assert.NoError(err) defer hybridVSockTTRPCMock.Stop() @@ -203,26 +196,6 @@ func TestCreateSandboxFailing(t *testing.T) { * Benchmarks */ -func createNewSandboxConfig(hType HypervisorType) SandboxConfig { - hypervisorConfig := HypervisorConfig{ - KernelPath: "/usr/share/kata-containers/vmlinux.container", - ImagePath: "/usr/share/kata-containers/kata-containers.img", - HypervisorPath: "/usr/bin/qemu-system-x86_64", - } - - netConfig := NetworkConfig{} - - return SandboxConfig{ - ID: testSandboxID, - HypervisorType: hType, - HypervisorConfig: hypervisorConfig, - - AgentConfig: KataAgentConfig{}, - - NetworkConfig: netConfig, - } -} - func newTestContainerConfigNoop(contID string) ContainerConfig { // Define the container command and bundle. container := ContainerConfig{ diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index e5de04afe0..fcf346808f 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -30,9 +30,9 @@ import ( otelTrace "go.opentelemetry.io/otel/trace" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" + vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils" - vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" ) // @@ -339,7 +339,7 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ // startSandbox will start the VMM and boot the virtual machine for the given sandbox. func (clh *cloudHypervisor) startSandbox(ctx context.Context, timeout int) error { - span, ctx := clh.trace(ctx, "startSandbox") + span, _ := clh.trace(ctx, "startSandbox") defer span.End() ctx, cancel := context.WithTimeout(context.Background(), clhAPITimeout*time.Second) @@ -492,7 +492,7 @@ func (clh *cloudHypervisor) hotplugAddDevice(ctx context.Context, devInfo interf } func (clh *cloudHypervisor) hotplugRemoveDevice(ctx context.Context, devInfo interface{}, devType deviceType) (interface{}, error) { - span, ctx := clh.trace(ctx, "hotplugRemoveDevice") + span, _ := clh.trace(ctx, "hotplugRemoveDevice") defer span.End() var deviceID string @@ -576,7 +576,7 @@ func (clh *cloudHypervisor) resizeMemory(ctx context.Context, reqMemMB uint32, m } cl := clh.client() - ctx, cancelResize := context.WithTimeout(context.Background(), clhAPITimeout*time.Second) + ctx, cancelResize := context.WithTimeout(ctx, clhAPITimeout*time.Second) defer cancelResize() // OpenApi does not support uint64, convert to int64 @@ -620,7 +620,7 @@ func (clh *cloudHypervisor) resizeVCPUs(ctx context.Context, reqVCPUs uint32) (c } // Resize (hot-plug) vCPUs via HTTP API - ctx, cancel := context.WithTimeout(context.Background(), clhAPITimeout*time.Second) + ctx, cancel := context.WithTimeout(ctx, clhAPITimeout*time.Second) defer cancel() if _, err = cl.VmResizePut(ctx, chclient.VmResize{DesiredVcpus: int32(reqVCPUs)}); err != nil { return currentVCPUs, newVCPUs, errors.Wrap(err, "[clh] VmResizePut failed") @@ -653,7 +653,7 @@ func (clh *cloudHypervisor) resumeSandbox(ctx context.Context) error { // stopSandbox will stop the Sandbox's VM. func (clh *cloudHypervisor) stopSandbox(ctx context.Context) (err error) { - span, ctx := clh.trace(ctx, "stopSandbox") + span, _ := clh.trace(ctx, "stopSandbox") defer span.End() clh.Logger().WithField("function", "stopSandbox").Info("Stop Sandbox") return clh.terminate(ctx) @@ -757,7 +757,7 @@ func (clh *cloudHypervisor) trace(parent context.Context, name string) (otelTrac } func (clh *cloudHypervisor) terminate(ctx context.Context) (err error) { - span, ctx := clh.trace(ctx, "terminate") + span, _ := clh.trace(ctx, "terminate") defer span.End() pid := clh.state.PID diff --git a/src/runtime/virtcontainers/container.go b/src/runtime/virtcontainers/container.go index 18a5f7f8e0..13f2f8f6cd 100644 --- a/src/runtime/virtcontainers/container.go +++ b/src/runtime/virtcontainers/container.go @@ -700,7 +700,7 @@ func (c *Container) createBlockDevices(ctx context.Context) error { // newContainer creates a Container structure from a sandbox and a container configuration. func newContainer(ctx context.Context, sandbox *Sandbox, contConfig *ContainerConfig) (*Container, error) { - span, ctx := sandbox.trace(ctx, "newContainer") + span, _ := sandbox.trace(ctx, "newContainer") defer span.End() if !contConfig.valid() { diff --git a/src/runtime/virtcontainers/device/config/config.go b/src/runtime/virtcontainers/device/config/config.go index 4faf24d7f9..5c866623de 100644 --- a/src/runtime/virtcontainers/device/config/config.go +++ b/src/runtime/virtcontainers/device/config/config.go @@ -15,8 +15,8 @@ import ( "strings" "github.com/go-ini/ini" - "golang.org/x/sys/unix" vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" + "golang.org/x/sys/unix" ) // DeviceType indicates device type diff --git a/src/runtime/virtcontainers/factory/factory.go b/src/runtime/virtcontainers/factory/factory.go index c677fd16ae..34dabdc536 100644 --- a/src/runtime/virtcontainers/factory/factory.go +++ b/src/runtime/virtcontainers/factory/factory.go @@ -141,7 +141,7 @@ func (f *factory) checkConfig(config vc.VMConfig) error { // GetVM returns a working blank VM created by the factory. func (f *factory) GetVM(ctx context.Context, config vc.VMConfig) (*vc.VM, error) { - span, ctx := trace(ctx, "GetVM") + span, _ := trace(ctx, "GetVM") defer span.End() hypervisorConfig := config.HypervisorConfig @@ -191,7 +191,7 @@ func (f *factory) GetVM(ctx context.Context, config vc.VMConfig) (*vc.VM, error) online := false baseConfig := f.base.Config().HypervisorConfig if baseConfig.NumVCPUs < hypervisorConfig.NumVCPUs { - err = vm.AddCPUs(ctx, hypervisorConfig.NumVCPUs - baseConfig.NumVCPUs) + err = vm.AddCPUs(ctx, hypervisorConfig.NumVCPUs-baseConfig.NumVCPUs) if err != nil { return nil, err } @@ -199,7 +199,7 @@ func (f *factory) GetVM(ctx context.Context, config vc.VMConfig) (*vc.VM, error) } if baseConfig.MemorySize < hypervisorConfig.MemorySize { - err = vm.AddMemory(ctx, hypervisorConfig.MemorySize - baseConfig.MemorySize) + err = vm.AddMemory(ctx, hypervisorConfig.MemorySize-baseConfig.MemorySize) if err != nil { return nil, err } diff --git a/src/runtime/virtcontainers/factory/factory_test.go b/src/runtime/virtcontainers/factory/factory_test.go index 9ff9abcf49..91b47cf52c 100644 --- a/src/runtime/virtcontainers/factory/factory_test.go +++ b/src/runtime/virtcontainers/factory/factory_test.go @@ -59,8 +59,12 @@ func TestNewFactory(t *testing.T) { t.Skip(testDisabledAsNonRoot) } + url, err := mock.GenerateKataMockHybridVSock() + assert.NoError(err) + vc.MockHybridVSockPath = url + hybridVSockTTRPCMock := mock.HybridVSockTTRPCMock{} - err = hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", vc.MockHybridVSockPath)) + err = hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", url)) assert.NoError(err) defer hybridVSockTTRPCMock.Stop() @@ -173,8 +177,12 @@ func TestFactoryGetVM(t *testing.T) { t.Skip(testDisabledAsNonRoot) } + url, err := mock.GenerateKataMockHybridVSock() + assert.NoError(err) + vc.MockHybridVSockPath = url + hybridVSockTTRPCMock := mock.HybridVSockTTRPCMock{} - err = hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", vc.MockHybridVSockPath)) + err = hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", url)) assert.NoError(err) defer hybridVSockTTRPCMock.Stop() diff --git a/src/runtime/virtcontainers/factory/template/template_test.go b/src/runtime/virtcontainers/factory/template/template_test.go index 4eedc1655e..c7256218ca 100644 --- a/src/runtime/virtcontainers/factory/template/template_test.go +++ b/src/runtime/virtcontainers/factory/template/template_test.go @@ -47,8 +47,12 @@ func TestTemplateFactory(t *testing.T) { ctx := context.Background() + url, err := mock.GenerateKataMockHybridVSock() + assert.NoError(err) + vc.MockHybridVSockPath = url + hybridVSockTTRPCMock := mock.HybridVSockTTRPCMock{} - err = hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", vc.MockHybridVSockPath)) + err = hybridVSockTTRPCMock.Start(fmt.Sprintf("mock://%s", url)) assert.NoError(err) defer hybridVSockTTRPCMock.Stop() diff --git a/src/runtime/virtcontainers/fc.go b/src/runtime/virtcontainers/fc.go index 25aebd1d8f..3d2ae97f2d 100644 --- a/src/runtime/virtcontainers/fc.go +++ b/src/runtime/virtcontainers/fc.go @@ -200,7 +200,7 @@ func (fc *firecracker) createSandbox(ctx context.Context, id string, networkNS N fc.ctx = ctx var span otelTrace.Span - span, ctx = fc.trace(ctx, "createSandbox") + span, _ = fc.trace(ctx, "createSandbox") defer span.End() //TODO: check validity of the hypervisor config provided @@ -325,7 +325,7 @@ func (fc *firecracker) checkVersion(version string) error { // waitVMMRunning will wait for timeout seconds for the VMM to be up and running. func (fc *firecracker) waitVMMRunning(ctx context.Context, timeout int) error { - span, ctx := fc.trace(ctx, "wait VMM to be running") + span, _ := fc.trace(ctx, "wait VMM to be running") defer span.End() if timeout < 0 { @@ -347,7 +347,7 @@ func (fc *firecracker) waitVMMRunning(ctx context.Context, timeout int) error { } func (fc *firecracker) fcInit(ctx context.Context, timeout int) error { - span, ctx := fc.trace(ctx, "fcInit") + span, _ := fc.trace(ctx, "fcInit") defer span.End() var err error @@ -467,7 +467,7 @@ func (fc *firecracker) fcEnd(ctx context.Context) (err error) { } func (fc *firecracker) client(ctx context.Context) *client.Firecracker { - span, ctx := fc.trace(ctx, "client") + span, _ := fc.trace(ctx, "client") defer span.End() if fc.connection == nil { @@ -762,7 +762,7 @@ func (fc *firecracker) fcInitConfiguration(ctx context.Context) error { // In the context of firecracker, this will start the hypervisor, // for configuration, but not yet start the actual virtual machine func (fc *firecracker) startSandbox(ctx context.Context, timeout int) error { - span, ctx := fc.trace(ctx, "startSandbox") + span, _ := fc.trace(ctx, "startSandbox") defer span.End() if err := fc.fcInitConfiguration(ctx); err != nil { @@ -875,7 +875,7 @@ func (fc *firecracker) cleanupJail(ctx context.Context) { // stopSandbox will stop the Sandbox's VM. func (fc *firecracker) stopSandbox(ctx context.Context) (err error) { - span, ctx := fc.trace(ctx, "stopSandbox") + span, _ := fc.trace(ctx, "stopSandbox") defer span.End() return fc.fcEnd(ctx) @@ -996,7 +996,7 @@ func (fc *firecracker) fcAddBlockDrive(ctx context.Context, drive config.BlockDr // Firecracker supports replacing the host drive used once the VM has booted up func (fc *firecracker) fcUpdateBlockDrive(ctx context.Context, path, id string) error { - span, ctx := fc.trace(ctx, "fcUpdateBlockDrive") + span, _ := fc.trace(ctx, "fcUpdateBlockDrive") defer span.End() // Use the global block index as an index into the pool of the devices @@ -1020,7 +1020,7 @@ func (fc *firecracker) fcUpdateBlockDrive(ctx context.Context, path, id string) // addDevice will add extra devices to firecracker. Limited to configure before the // virtual machine starts. Devices include drivers and network interfaces only. func (fc *firecracker) addDevice(ctx context.Context, devInfo interface{}, devType deviceType) error { - span, ctx := fc.trace(ctx, "addDevice") + span, _ := fc.trace(ctx, "addDevice") defer span.End() fc.state.RLock() @@ -1081,7 +1081,7 @@ func (fc *firecracker) hotplugBlockDevice(ctx context.Context, drive config.Bloc // hotplugAddDevice supported in Firecracker VMM func (fc *firecracker) hotplugAddDevice(ctx context.Context, devInfo interface{}, devType deviceType) (interface{}, error) { - span, ctx := fc.trace(ctx, "hotplugAddDevice") + span, _ := fc.trace(ctx, "hotplugAddDevice") defer span.End() switch devType { @@ -1097,7 +1097,7 @@ func (fc *firecracker) hotplugAddDevice(ctx context.Context, devInfo interface{} // hotplugRemoveDevice supported in Firecracker VMM func (fc *firecracker) hotplugRemoveDevice(ctx context.Context, devInfo interface{}, devType deviceType) (interface{}, error) { - span, ctx := fc.trace(ctx, "hotplugRemoveDevice") + span, _ := fc.trace(ctx, "hotplugRemoveDevice") defer span.End() switch devType { @@ -1245,9 +1245,8 @@ func revertBytes(num uint64) uint64 { b := num % 1000 if a == 0 { return num - } else { - return 1024*revertBytes(a) + b } + return 1024*revertBytes(a) + b } func (fc *firecracker) setSandbox(sandbox *Sandbox) { diff --git a/src/runtime/virtcontainers/fc_metrics.go b/src/runtime/virtcontainers/fc_metrics.go index 2a608508bb..bb0d423e58 100644 --- a/src/runtime/virtcontainers/fc_metrics.go +++ b/src/runtime/virtcontainers/fc_metrics.go @@ -174,11 +174,11 @@ func registerFirecrackerMetrics() { // updateFirecrackerMetrics update all metrics to the latest values. func updateFirecrackerMetrics(fm *FirecrackerMetrics) { - // set metrics for ApiServerMetrics - apiServerMetrics.WithLabelValues("process_startup_time_us").Set(float64(fm.ApiServer.ProcessStartupTimeUs)) - apiServerMetrics.WithLabelValues("process_startup_time_cpu_us").Set(float64(fm.ApiServer.ProcessStartupTimeCpuUs)) - apiServerMetrics.WithLabelValues("sync_response_fails").Set(float64(fm.ApiServer.SyncResponseFails)) - apiServerMetrics.WithLabelValues("sync_vmm_send_timeout_count").Set(float64(fm.ApiServer.SyncVmmSendTimeoutCount)) + // set metrics for APIServerMetrics + apiServerMetrics.WithLabelValues("process_startup_time_us").Set(float64(fm.APIServer.ProcessStartupTimeUs)) + apiServerMetrics.WithLabelValues("process_startup_time_cpu_us").Set(float64(fm.APIServer.ProcessStartupTimeCPUUs)) + apiServerMetrics.WithLabelValues("sync_response_fails").Set(float64(fm.APIServer.SyncResponseFails)) + apiServerMetrics.WithLabelValues("sync_vmm_send_timeout_count").Set(float64(fm.APIServer.SyncVmmSendTimeoutCount)) // set metrics for BlockDeviceMetrics blockDeviceMetrics.WithLabelValues("activate_fails").Set(float64(fm.Block.ActivateFails)) @@ -199,10 +199,10 @@ func updateFirecrackerMetrics(fm *FirecrackerMetrics) { blockDeviceMetrics.WithLabelValues("rate_limiter_throttled_events").Set(float64(fm.Block.RateLimiterThrottledEvents)) // set metrics for GetRequestsMetrics - getRequestsMetrics.WithLabelValues("instance_info_count").Set(float64(fm.GetApiRequests.InstanceInfoCount)) - getRequestsMetrics.WithLabelValues("instance_info_fails").Set(float64(fm.GetApiRequests.InstanceInfoFails)) - getRequestsMetrics.WithLabelValues("machine_cfg_count").Set(float64(fm.GetApiRequests.MachineCfgCount)) - getRequestsMetrics.WithLabelValues("machine_cfg_fails").Set(float64(fm.GetApiRequests.MachineCfgFails)) + getRequestsMetrics.WithLabelValues("instance_info_count").Set(float64(fm.GetAPIRequests.InstanceInfoCount)) + getRequestsMetrics.WithLabelValues("instance_info_fails").Set(float64(fm.GetAPIRequests.InstanceInfoFails)) + getRequestsMetrics.WithLabelValues("machine_cfg_count").Set(float64(fm.GetAPIRequests.MachineCfgCount)) + getRequestsMetrics.WithLabelValues("machine_cfg_fails").Set(float64(fm.GetAPIRequests.MachineCfgFails)) // set metrics for I8042DeviceMetrics i8042DeviceMetrics.WithLabelValues("error_count").Set(float64(fm.I8042.ErrorCount)) @@ -216,13 +216,13 @@ func updateFirecrackerMetrics(fm *FirecrackerMetrics) { performanceMetrics.WithLabelValues("full_create_snapshot").Set(float64(fm.LatenciesUs.FullCreateSnapshot)) performanceMetrics.WithLabelValues("diff_create_snapshot").Set(float64(fm.LatenciesUs.DiffCreateSnapshot)) performanceMetrics.WithLabelValues("load_snapshot").Set(float64(fm.LatenciesUs.LoadSnapshot)) - performanceMetrics.WithLabelValues("pause_vm").Set(float64(fm.LatenciesUs.PauseVm)) - performanceMetrics.WithLabelValues("resume_vm").Set(float64(fm.LatenciesUs.ResumeVm)) + performanceMetrics.WithLabelValues("pause_vm").Set(float64(fm.LatenciesUs.PauseVM)) + performanceMetrics.WithLabelValues("resume_vm").Set(float64(fm.LatenciesUs.ResumeVM)) performanceMetrics.WithLabelValues("vmm_full_create_snapshot").Set(float64(fm.LatenciesUs.VmmFullCreateSnapshot)) performanceMetrics.WithLabelValues("vmm_diff_create_snapshot").Set(float64(fm.LatenciesUs.VmmDiffCreateSnapshot)) performanceMetrics.WithLabelValues("vmm_load_snapshot").Set(float64(fm.LatenciesUs.VmmLoadSnapshot)) - performanceMetrics.WithLabelValues("vmm_pause_vm").Set(float64(fm.LatenciesUs.VmmPauseVm)) - performanceMetrics.WithLabelValues("vmm_resume_vm").Set(float64(fm.LatenciesUs.VmmResumeVm)) + performanceMetrics.WithLabelValues("vmm_pause_vm").Set(float64(fm.LatenciesUs.VmmPauseVM)) + performanceMetrics.WithLabelValues("vmm_resume_vm").Set(float64(fm.LatenciesUs.VmmResumeVM)) // set metrics for LoggerSystemMetrics loggerSystemMetrics.WithLabelValues("missed_metrics_count").Set(float64(fm.Logger.MissedMetricsCount)) @@ -273,28 +273,28 @@ func updateFirecrackerMetrics(fm *FirecrackerMetrics) { netDeviceMetrics.WithLabelValues("tx_spoofed_mac_count").Set(float64(fm.Net.TxSpoofedMacCount)) // set metrics for PatchRequestsMetrics - patchRequestsMetrics.WithLabelValues("drive_count").Set(float64(fm.PatchApiRequests.DriveCount)) - patchRequestsMetrics.WithLabelValues("drive_fails").Set(float64(fm.PatchApiRequests.DriveFails)) - patchRequestsMetrics.WithLabelValues("network_count").Set(float64(fm.PatchApiRequests.NetworkCount)) - patchRequestsMetrics.WithLabelValues("network_fails").Set(float64(fm.PatchApiRequests.NetworkFails)) - patchRequestsMetrics.WithLabelValues("machine_cfg_count").Set(float64(fm.PatchApiRequests.MachineCfgCount)) - patchRequestsMetrics.WithLabelValues("machine_cfg_fails").Set(float64(fm.PatchApiRequests.MachineCfgFails)) + patchRequestsMetrics.WithLabelValues("drive_count").Set(float64(fm.PatchAPIRequests.DriveCount)) + patchRequestsMetrics.WithLabelValues("drive_fails").Set(float64(fm.PatchAPIRequests.DriveFails)) + patchRequestsMetrics.WithLabelValues("network_count").Set(float64(fm.PatchAPIRequests.NetworkCount)) + patchRequestsMetrics.WithLabelValues("network_fails").Set(float64(fm.PatchAPIRequests.NetworkFails)) + patchRequestsMetrics.WithLabelValues("machine_cfg_count").Set(float64(fm.PatchAPIRequests.MachineCfgCount)) + patchRequestsMetrics.WithLabelValues("machine_cfg_fails").Set(float64(fm.PatchAPIRequests.MachineCfgFails)) // set metrics for PutRequestsMetrics - putRequestsMetrics.WithLabelValues("actions_count").Set(float64(fm.PutApiRequests.ActionsCount)) - putRequestsMetrics.WithLabelValues("actions_fails").Set(float64(fm.PutApiRequests.ActionsFails)) - putRequestsMetrics.WithLabelValues("boot_source_count").Set(float64(fm.PutApiRequests.BootSourceCount)) - putRequestsMetrics.WithLabelValues("boot_source_fails").Set(float64(fm.PutApiRequests.BootSourceFails)) - putRequestsMetrics.WithLabelValues("drive_count").Set(float64(fm.PutApiRequests.DriveCount)) - putRequestsMetrics.WithLabelValues("drive_fails").Set(float64(fm.PutApiRequests.DriveFails)) - putRequestsMetrics.WithLabelValues("logger_count").Set(float64(fm.PutApiRequests.LoggerCount)) - putRequestsMetrics.WithLabelValues("logger_fails").Set(float64(fm.PutApiRequests.LoggerFails)) - putRequestsMetrics.WithLabelValues("machine_cfg_count").Set(float64(fm.PutApiRequests.MachineCfgCount)) - putRequestsMetrics.WithLabelValues("machine_cfg_fails").Set(float64(fm.PutApiRequests.MachineCfgFails)) - putRequestsMetrics.WithLabelValues("metrics_count").Set(float64(fm.PutApiRequests.MetricsCount)) - putRequestsMetrics.WithLabelValues("metrics_fails").Set(float64(fm.PutApiRequests.MetricsFails)) - putRequestsMetrics.WithLabelValues("network_count").Set(float64(fm.PutApiRequests.NetworkCount)) - putRequestsMetrics.WithLabelValues("network_fails").Set(float64(fm.PutApiRequests.NetworkFails)) + putRequestsMetrics.WithLabelValues("actions_count").Set(float64(fm.PutAPIRequests.ActionsCount)) + putRequestsMetrics.WithLabelValues("actions_fails").Set(float64(fm.PutAPIRequests.ActionsFails)) + putRequestsMetrics.WithLabelValues("boot_source_count").Set(float64(fm.PutAPIRequests.BootSourceCount)) + putRequestsMetrics.WithLabelValues("boot_source_fails").Set(float64(fm.PutAPIRequests.BootSourceFails)) + putRequestsMetrics.WithLabelValues("drive_count").Set(float64(fm.PutAPIRequests.DriveCount)) + putRequestsMetrics.WithLabelValues("drive_fails").Set(float64(fm.PutAPIRequests.DriveFails)) + putRequestsMetrics.WithLabelValues("logger_count").Set(float64(fm.PutAPIRequests.LoggerCount)) + putRequestsMetrics.WithLabelValues("logger_fails").Set(float64(fm.PutAPIRequests.LoggerFails)) + putRequestsMetrics.WithLabelValues("machine_cfg_count").Set(float64(fm.PutAPIRequests.MachineCfgCount)) + putRequestsMetrics.WithLabelValues("machine_cfg_fails").Set(float64(fm.PutAPIRequests.MachineCfgFails)) + putRequestsMetrics.WithLabelValues("metrics_count").Set(float64(fm.PutAPIRequests.MetricsCount)) + putRequestsMetrics.WithLabelValues("metrics_fails").Set(float64(fm.PutAPIRequests.MetricsFails)) + putRequestsMetrics.WithLabelValues("network_count").Set(float64(fm.PutAPIRequests.NetworkCount)) + putRequestsMetrics.WithLabelValues("network_fails").Set(float64(fm.PutAPIRequests.NetworkFails)) // set metrics for RTCDeviceMetrics rTCDeviceMetrics.WithLabelValues("error_count").Set(float64(fm.Rtc.ErrorCount)) @@ -310,7 +310,7 @@ func updateFirecrackerMetrics(fm *FirecrackerMetrics) { vcpuMetrics.WithLabelValues("exit_mmio_read").Set(float64(fm.Vcpu.ExitMmioRead)) vcpuMetrics.WithLabelValues("exit_mmio_write").Set(float64(fm.Vcpu.ExitMmioWrite)) vcpuMetrics.WithLabelValues("failures").Set(float64(fm.Vcpu.Failures)) - vcpuMetrics.WithLabelValues("filter_cpuid").Set(float64(fm.Vcpu.FilterCpuid)) + vcpuMetrics.WithLabelValues("filter_cpuid").Set(float64(fm.Vcpu.FilterCPUid)) // set metrics for VmmMetrics vmmMetrics.WithLabelValues("device_events").Set(float64(fm.Vmm.DeviceEvents)) @@ -355,11 +355,11 @@ func updateFirecrackerMetrics(fm *FirecrackerMetrics) { // Structure storing all metrics while enforcing serialization support on them. type FirecrackerMetrics struct { // API Server related metrics. - ApiServer ApiServerMetrics `json:"api_server"` + APIServer APIServerMetrics `json:"api_server"` // A block device's related metrics. Block BlockDeviceMetrics `json:"block"` // Metrics related to API GET requests. - GetApiRequests GetRequestsMetrics `json:"get_api_requests"` + GetAPIRequests GetRequestsMetrics `json:"get_api_requests"` // Metrics related to the i8042 device. I8042 I8042DeviceMetrics `json:"i8042"` // Metrics related to performance measurements. @@ -371,9 +371,9 @@ type FirecrackerMetrics struct { // A network device's related metrics. Net NetDeviceMetrics `json:"net"` // Metrics related to API PATCH requests. - PatchApiRequests PatchRequestsMetrics `json:"patch_api_requests"` + PatchAPIRequests PatchRequestsMetrics `json:"patch_api_requests"` // Metrics related to API PUT requests. - PutApiRequests PutRequestsMetrics `json:"put_api_requests"` + PutAPIRequests PutRequestsMetrics `json:"put_api_requests"` // Metrics related to the RTC device. Rtc RTCDeviceMetrics `json:"rtc"` // Metrics related to seccomp filtering. @@ -391,11 +391,11 @@ type FirecrackerMetrics struct { } // API Server related metrics. -type ApiServerMetrics struct { +type APIServerMetrics struct { // Measures the process's startup time in microseconds. ProcessStartupTimeUs uint64 `json:"process_startup_time_us"` // Measures the cpu's startup time in microseconds. - ProcessStartupTimeCpuUs uint64 `json:"process_startup_time_cpu_us"` + ProcessStartupTimeCPUUs uint64 `json:"process_startup_time_cpu_us"` // Number of failures on API requests triggered by internal errors. SyncResponseFails uint64 `json:"sync_response_fails"` // Number of timeouts during communication with the VMM. @@ -475,9 +475,9 @@ type PerformanceMetrics struct { // Measures the snapshot load time, at the API (user) level, in microseconds. LoadSnapshot uint64 `json:"load_snapshot"` // Measures the microVM pausing duration, at the API (user) level, in microseconds. - PauseVm uint64 `json:"pause_vm"` + PauseVM uint64 `json:"pause_vm"` // Measures the microVM resuming duration, at the API (user) level, in microseconds. - ResumeVm uint64 `json:"resume_vm"` + ResumeVM uint64 `json:"resume_vm"` // Measures the snapshot full create time, at the VMM level, in microseconds. VmmFullCreateSnapshot uint64 `json:"vmm_full_create_snapshot"` // Measures the snapshot diff create time, at the VMM level, in microseconds. @@ -485,9 +485,9 @@ type PerformanceMetrics struct { // Measures the snapshot load time, at the VMM level, in microseconds. VmmLoadSnapshot uint64 `json:"vmm_load_snapshot"` // Measures the microVM pausing duration, at the VMM level, in microseconds. - VmmPauseVm uint64 `json:"vmm_pause_vm"` + VmmPauseVM uint64 `json:"vmm_pause_vm"` // Measures the microVM resuming duration, at the VMM level, in microseconds. - VmmResumeVm uint64 `json:"vmm_resume_vm"` + VmmResumeVM uint64 `json:"vmm_resume_vm"` } // Logging related metrics. @@ -662,7 +662,7 @@ type VcpuMetrics struct { // Number of errors during this VCPU's run. Failures uint64 `json:"failures"` // Failures in configuring the CPUID. - FilterCpuid uint64 `json:"filter_cpuid"` + FilterCPUid uint64 `json:"filter_cpuid"` } // Metrics related to the virtual machine manager. diff --git a/src/runtime/virtcontainers/kata_agent.go b/src/runtime/virtcontainers/kata_agent.go index 4b3ed16085..a288288ee0 100644 --- a/src/runtime/virtcontainers/kata_agent.go +++ b/src/runtime/virtcontainers/kata_agent.go @@ -26,7 +26,6 @@ import ( "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc" vcAnnotations "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations" vccgroups "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups" - ns "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/nsenter" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless" vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/uuid" @@ -411,7 +410,7 @@ func setupSandboxBindMounts(sandbox *Sandbox) error { } func cleanupSandboxBindMounts(sandbox *Sandbox) error { - if len(sandbox.config.SandboxBindMounts) == 0 { + if sandbox.config == nil || len(sandbox.config.SandboxBindMounts) == 0 { return nil } @@ -496,7 +495,7 @@ func (k *kataAgent) setupSharedPath(ctx context.Context, sandbox *Sandbox) error } func (k *kataAgent) createSandbox(ctx context.Context, sandbox *Sandbox) error { - span, ctx := k.trace(ctx, "createSandbox") + span, _ := k.trace(ctx, "createSandbox") defer span.End() if err := k.setupSharedPath(ctx, sandbox); err != nil { @@ -583,7 +582,7 @@ func cmdEnvsToStringSlice(ev []types.EnvVar) []string { } func (k *kataAgent) exec(ctx context.Context, sandbox *Sandbox, c Container, cmd types.Cmd) (*Process, error) { - span, ctx := k.trace(ctx, "exec") + span, _ := k.trace(ctx, "exec") defer span.End() var kataProcess *grpc.Process @@ -755,7 +754,7 @@ func (k *kataAgent) getDNS(sandbox *Sandbox) ([]string, error) { } func (k *kataAgent) startSandbox(ctx context.Context, sandbox *Sandbox) error { - span, ctx := k.trace(ctx, "startSandbox") + span, _ := k.trace(ctx, "startSandbox") defer span.End() if err := k.setAgentURL(); err != nil { @@ -910,7 +909,7 @@ func setupStorages(ctx context.Context, sandbox *Sandbox) []*grpc.Storage { } func (k *kataAgent) stopSandbox(ctx context.Context, sandbox *Sandbox) error { - span, ctx := k.trace(ctx, "stopSandbox") + span, _ := k.trace(ctx, "stopSandbox") defer span.End() req := &grpc.DestroySandboxRequest{} @@ -1272,7 +1271,7 @@ func (k *kataAgent) buildContainerRootfs(ctx context.Context, sandbox *Sandbox, } func (k *kataAgent) createContainer(ctx context.Context, sandbox *Sandbox, c *Container) (p *Process, err error) { - span, ctx := k.trace(ctx, "createContainer") + span, _ := k.trace(ctx, "createContainer") defer span.End() var ctrStorages []*grpc.Storage @@ -1384,14 +1383,6 @@ func (k *kataAgent) createContainer(ctx context.Context, sandbox *Sandbox, c *Co return nil, err } - enterNSList := []ns.Namespace{} - if sandbox.networkNS.NetNsPath != "" { - enterNSList = append(enterNSList, ns.Namespace{ - Path: sandbox.networkNS.NetNsPath, - Type: ns.NSTypeNet, - }) - } - return buildProcessFromExecID(req.ExecId) } @@ -1602,7 +1593,7 @@ func (k *kataAgent) handlePidNamespace(grpcSpec *grpc.Spec, sandbox *Sandbox) bo } func (k *kataAgent) startContainer(ctx context.Context, sandbox *Sandbox, c *Container) error { - span, ctx := k.trace(ctx, "startContainer") + span, _ := k.trace(ctx, "startContainer") defer span.End() req := &grpc.StartContainerRequest{ @@ -1614,7 +1605,7 @@ func (k *kataAgent) startContainer(ctx context.Context, sandbox *Sandbox, c *Con } func (k *kataAgent) stopContainer(ctx context.Context, sandbox *Sandbox, c Container) error { - span, ctx := k.trace(ctx, "stopContainer") + span, _ := k.trace(ctx, "stopContainer") defer span.End() _, err := k.sendReq(ctx, &grpc.RemoveContainerRequest{ContainerId: c.id}) @@ -1778,7 +1769,7 @@ func (k *kataAgent) connect(ctx context.Context) error { return nil } - span, ctx := k.trace(ctx, "connect") + span, _ := k.trace(ctx, "connect") defer span.End() // This is for the first connection only, to prevent race @@ -1824,7 +1815,7 @@ func (k *kataAgent) disconnect(ctx context.Context) error { // check grpc server is serving func (k *kataAgent) check(ctx context.Context) error { - span, ctx := k.trace(ctx, "check") + span, _ := k.trace(ctx, "check") defer span.End() _, err := k.sendReq(ctx, &grpc.CheckRequest{}) @@ -1835,7 +1826,7 @@ func (k *kataAgent) check(ctx context.Context) error { } func (k *kataAgent) waitProcess(ctx context.Context, c *Container, processID string) (int32, error) { - span, ctx := k.trace(ctx, "waitProcess") + span, _ := k.trace(ctx, "waitProcess") defer span.End() resp, err := k.sendReq(ctx, &grpc.WaitProcessRequest{ @@ -2022,7 +2013,7 @@ func (k *kataAgent) sendReq(spanCtx context.Context, request interface{}) (inter k.Logger().WithField("name", msgName).WithField("req", message.String()).Debug("sending request") defer func() { - agentRpcDurationsHistogram.WithLabelValues(msgName).Observe(float64(time.Since(start).Nanoseconds() / int64(time.Millisecond))) + agentRPCDurationsHistogram.WithLabelValues(msgName).Observe(float64(time.Since(start).Nanoseconds() / int64(time.Millisecond))) }() return handler(ctx, request) } diff --git a/src/runtime/virtcontainers/kata_agent_test.go b/src/runtime/virtcontainers/kata_agent_test.go index 5bbfbd0b89..cafc1c45a8 100644 --- a/src/runtime/virtcontainers/kata_agent_test.go +++ b/src/runtime/virtcontainers/kata_agent_test.go @@ -31,8 +31,8 @@ import ( vcAnnotations "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/mock" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless" - "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" + "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" ) var ( @@ -360,6 +360,7 @@ func TestHandleBlockVolume(t *testing.T) { bPCIPath, err := vcTypes.PciPathFromString("03/04") assert.NoError(t, err) dPCIPath, err := vcTypes.PciPathFromString("04/05") + assert.NoError(t, err) vDev := drivers.NewVhostUserBlkDevice(&config.DeviceInfo{ID: vDevID}) bDev := drivers.NewBlockDevice(&config.DeviceInfo{ID: bDevID}) diff --git a/src/runtime/virtcontainers/mock_agent.go b/src/runtime/virtcontainers/mock_agent.go index 8aac06d872..6807ac72a5 100644 --- a/src/runtime/virtcontainers/mock_agent.go +++ b/src/runtime/virtcontainers/mock_agent.go @@ -22,6 +22,7 @@ import ( type mockAgent struct { } +// nolint:golint func NewMockAgent() agent { return &mockAgent{} } @@ -237,6 +238,6 @@ func (n *mockAgent) getOOMEvent(ctx context.Context) (string, error) { return "", nil } -func (k *mockAgent) getAgentMetrics(ctx context.Context, req *grpc.GetMetricsRequest) (*grpc.Metrics, error) { +func (n *mockAgent) getAgentMetrics(ctx context.Context, req *grpc.GetMetricsRequest) (*grpc.Metrics, error) { return nil, nil } diff --git a/src/runtime/virtcontainers/mount.go b/src/runtime/virtcontainers/mount.go index a562ee3a6f..16234ac1e8 100644 --- a/src/runtime/virtcontainers/mount.go +++ b/src/runtime/virtcontainers/mount.go @@ -219,7 +219,7 @@ const mountPerm = os.FileMode(0755) // * recursively create the destination // pgtypes stands for propagation types, which are shared, private, slave, and ubind. func bindMount(ctx context.Context, source, destination string, readonly bool, pgtypes string) error { - span, ctx := trace(ctx, "bindMount") + span, _ := trace(ctx, "bindMount") defer span.End() if source == "" { @@ -347,7 +347,7 @@ func bindUnmountContainerRootfs(ctx context.Context, sharedDir, cID string) erro } func bindUnmountAllRootfs(ctx context.Context, sharedDir string, sandbox *Sandbox) error { - span, ctx := trace(ctx, "bindUnmountAllRootfs") + span, _ := trace(ctx, "bindUnmountAllRootfs") defer span.End() var errors *merr.Error diff --git a/src/runtime/virtcontainers/network.go b/src/runtime/virtcontainers/network.go index 42739118d8..3c51c0fb58 100644 --- a/src/runtime/virtcontainers/network.go +++ b/src/runtime/virtcontainers/network.go @@ -1273,7 +1273,7 @@ func (n *Network) Run(ctx context.Context, networkNSPath string, cb func() error // Add adds all needed interfaces inside the network namespace. func (n *Network) Add(ctx context.Context, config *NetworkConfig, s *Sandbox, hotplug bool) ([]Endpoint, error) { - span, ctx := n.trace(ctx, "Add") + span, _ := n.trace(ctx, "Add") defer span.End() endpoints, err := createEndpointsFromScan(config.NetNSPath, config) @@ -1354,7 +1354,7 @@ func (n *Network) PostAdd(ctx context.Context, ns *NetworkNamespace, hotplug boo // Remove network endpoints in the network namespace. It also deletes the network // namespace in case the namespace has been created by us. func (n *Network) Remove(ctx context.Context, ns *NetworkNamespace, hypervisor hypervisor) error { - span, ctx := n.trace(ctx, "Remove") + span, _ := n.trace(ctx, "Remove") defer span.End() for _, endpoint := range ns.Endpoints { diff --git a/src/runtime/virtcontainers/persist/api/device.go b/src/runtime/virtcontainers/persist/api/device.go index 204ea7cfa7..5e6c6e6f73 100644 --- a/src/runtime/virtcontainers/persist/api/device.go +++ b/src/runtime/virtcontainers/persist/api/device.go @@ -6,7 +6,7 @@ package persistapi -import vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" +import vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" // ============= sandbox level resources ============= diff --git a/src/runtime/virtcontainers/physical_endpoint.go b/src/runtime/virtcontainers/physical_endpoint.go index 8ec1401bf8..cdc57910e7 100644 --- a/src/runtime/virtcontainers/physical_endpoint.go +++ b/src/runtime/virtcontainers/physical_endpoint.go @@ -17,8 +17,8 @@ import ( "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/drivers" persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups" - "github.com/safchain/ethtool" vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" + "github.com/safchain/ethtool" ) // PhysicalEndpoint gathers a physical network interface and its properties diff --git a/src/runtime/virtcontainers/pkg/agent/protocols/client/client.go b/src/runtime/virtcontainers/pkg/agent/protocols/client/client.go index 961fc959c7..2e21779334 100644 --- a/src/runtime/virtcontainers/pkg/agent/protocols/client/client.go +++ b/src/runtime/virtcontainers/pkg/agent/protocols/client/client.go @@ -34,7 +34,6 @@ const ( ) var defaultDialTimeout = 15 * time.Second -var defaultCloseTimeout = 5 * time.Second var hybridVSockPort uint32 @@ -70,8 +69,7 @@ func NewAgentClient(ctx context.Context, sock string) (*AgentClient, error) { } var conn net.Conn - var d dialer - d = agentDialer(parsedAddr) + var d = agentDialer(parsedAddr) conn, err = d(grpcAddr, defaultDialTimeout) if err != nil { return nil, err diff --git a/src/runtime/virtcontainers/pkg/agent/protocols/grpc/agent.pb.go b/src/runtime/virtcontainers/pkg/agent/protocols/grpc/agent.pb.go index ac1a0ded7f..b277d40d9d 100644 --- a/src/runtime/virtcontainers/pkg/agent/protocols/grpc/agent.pb.go +++ b/src/runtime/virtcontainers/pkg/agent/protocols/grpc/agent.pb.go @@ -7248,7 +7248,7 @@ func (this *MemoryStats) String() string { return "nil" } keysForStats := make([]string, 0, len(this.Stats)) - for k, _ := range this.Stats { + for k := range this.Stats { keysForStats = append(keysForStats, k) } github_com_gogo_protobuf_sortkeys.Strings(keysForStats) @@ -7359,7 +7359,7 @@ func (this *CgroupStats) String() string { return "nil" } keysForHugetlbStats := make([]string, 0, len(this.HugetlbStats)) - for k, _ := range this.HugetlbStats { + for k := range this.HugetlbStats { keysForHugetlbStats = append(keysForHugetlbStats, k) } github_com_gogo_protobuf_sortkeys.Strings(keysForHugetlbStats) diff --git a/src/runtime/virtcontainers/pkg/agent/protocols/grpc/oci.pb.go b/src/runtime/virtcontainers/pkg/agent/protocols/grpc/oci.pb.go index 851a1ac0b8..f14e7d49ae 100644 --- a/src/runtime/virtcontainers/pkg/agent/protocols/grpc/oci.pb.go +++ b/src/runtime/virtcontainers/pkg/agent/protocols/grpc/oci.pb.go @@ -6653,7 +6653,7 @@ func (this *Spec) String() string { } repeatedStringForMounts += "}" keysForAnnotations := make([]string, 0, len(this.Annotations)) - for k, _ := range this.Annotations { + for k := range this.Annotations { keysForAnnotations = append(keysForAnnotations, k) } github_com_gogo_protobuf_sortkeys.Strings(keysForAnnotations) @@ -6852,7 +6852,7 @@ func (this *Linux) String() string { } repeatedStringForDevices += "}" keysForSysctl := make([]string, 0, len(this.Sysctl)) - for k, _ := range this.Sysctl { + for k := range this.Sysctl { keysForSysctl = append(keysForSysctl, k) } github_com_gogo_protobuf_sortkeys.Strings(keysForSysctl) diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/client.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/client.go index b435e963f2..ece0784d89 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/client.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/client.go @@ -157,13 +157,12 @@ func parameterToJson(obj interface{}) (string, error) { return string(jsonBuf), err } - // callAPI do the request. func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { if c.cfg.Debug { - dump, err := httputil.DumpRequestOut(request, true) + dump, err := httputil.DumpRequestOut(request, true) if err != nil { - return nil, err + return nil, err } log.Printf("\n%s\n", string(dump)) } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/configuration.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/configuration.go index 57ccf85697..4dd597fcc5 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/configuration.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/configuration.go @@ -37,7 +37,6 @@ var ( // ContextAPIKey takes an APIKey as authentication for the request ContextAPIKey = contextKey("apikey") - ) // BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth @@ -52,7 +51,6 @@ type APIKey struct { Prefix string } - // ServerVariable stores the information about a server variable type ServerVariable struct { Description string @@ -62,9 +60,9 @@ type ServerVariable struct { // ServerConfiguration stores the information about a server type ServerConfiguration struct { - Url string + Url string Description string - Variables map[string]ServerVariable + Variables map[string]ServerVariable } // Configuration stores the configuration of the API client @@ -86,9 +84,9 @@ func NewConfiguration() *Configuration { DefaultHeader: make(map[string]string), UserAgent: "OpenAPI-Generator/1.0.0/go", Debug: false, - Servers: []ServerConfiguration{ + Servers: []ServerConfiguration{ { - Url: "http://localhost/api/v1", + Url: "http://localhost/api/v1", Description: "No description provided", }, }, @@ -104,7 +102,7 @@ func (c *Configuration) AddDefaultHeader(key string, value string) { // ServerUrl returns URL based on server settings func (c *Configuration) ServerUrl(index int, variables map[string]string) (string, error) { if index < 0 || len(c.Servers) <= index { - return "", fmt.Errorf("Index %v out of range %v", index, len(c.Servers) - 1) + return "", fmt.Errorf("Index %v out of range %v", index, len(c.Servers)-1) } server := c.Servers[index] url := server.Url diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_balloon_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_balloon_config.go index 999f669de4..96de345d35 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_balloon_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_balloon_config.go @@ -8,6 +8,7 @@ */ package openapi + // BalloonConfig struct for BalloonConfig type BalloonConfig struct { Size int64 `json:"size"` diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_cmd_line_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_cmd_line_config.go index 62d23ce3fb..e924de7118 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_cmd_line_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_cmd_line_config.go @@ -8,6 +8,7 @@ */ package openapi + // CmdLineConfig struct for CmdLineConfig type CmdLineConfig struct { Args string `json:"args"` diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_console_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_console_config.go index af23bcf48e..6de0c247a3 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_console_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_console_config.go @@ -8,9 +8,10 @@ */ package openapi + // ConsoleConfig struct for ConsoleConfig type ConsoleConfig struct { - File string `json:"file,omitempty"` - Mode string `json:"mode"` - Iommu bool `json:"iommu,omitempty"` + File string `json:"file,omitempty"` + Mode string `json:"mode"` + Iommu bool `json:"iommu,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_cpu_topology.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_cpu_topology.go index 3c8bf4b0d3..110801dbdc 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_cpu_topology.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_cpu_topology.go @@ -8,10 +8,11 @@ */ package openapi + // CpuTopology struct for CpuTopology type CpuTopology struct { ThreadsPerCore int32 `json:"threads_per_core,omitempty"` - CoresPerDie int32 `json:"cores_per_die,omitempty"` + CoresPerDie int32 `json:"cores_per_die,omitempty"` DiesPerPackage int32 `json:"dies_per_package,omitempty"` - Packages int32 `json:"packages,omitempty"` + Packages int32 `json:"packages,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_cpus_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_cpus_config.go index 6bf2245cf7..b67daeec04 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_cpus_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_cpus_config.go @@ -8,10 +8,11 @@ */ package openapi + // CpusConfig struct for CpusConfig type CpusConfig struct { - BootVcpus int32 `json:"boot_vcpus"` - MaxVcpus int32 `json:"max_vcpus"` - Topology CpuTopology `json:"topology,omitempty"` - MaxPhysBits int32 `json:"max_phys_bits,omitempty"` + BootVcpus int32 `json:"boot_vcpus"` + MaxVcpus int32 `json:"max_vcpus"` + Topology CpuTopology `json:"topology,omitempty"` + MaxPhysBits int32 `json:"max_phys_bits,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_device_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_device_config.go index d0fa7d6e1a..a1e2836331 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_device_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_device_config.go @@ -8,9 +8,10 @@ */ package openapi + // DeviceConfig struct for DeviceConfig type DeviceConfig struct { - Path string `json:"path"` - Iommu bool `json:"iommu,omitempty"` - Id string `json:"id,omitempty"` + Path string `json:"path"` + Iommu bool `json:"iommu,omitempty"` + Id string `json:"id,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_device_node.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_device_node.go index f584d9a3f9..bb49a9fcc0 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_device_node.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_device_node.go @@ -8,10 +8,11 @@ */ package openapi + // DeviceNode struct for DeviceNode type DeviceNode struct { - Id string `json:"id,omitempty"` + Id string `json:"id,omitempty"` Resources []map[string]interface{} `json:"resources,omitempty"` - Children []string `json:"children,omitempty"` - PciBdf int32 `json:"pci_bdf,omitempty"` + Children []string `json:"children,omitempty"` + PciBdf int32 `json:"pci_bdf,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_disk_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_disk_config.go index 24bf8c11e7..7c1da3ce54 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_disk_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_disk_config.go @@ -8,16 +8,17 @@ */ package openapi + // DiskConfig struct for DiskConfig type DiskConfig struct { - Path string `json:"path"` - Readonly bool `json:"readonly,omitempty"` - Direct bool `json:"direct,omitempty"` - Iommu bool `json:"iommu,omitempty"` - NumQueues int32 `json:"num_queues,omitempty"` - QueueSize int32 `json:"queue_size,omitempty"` - VhostUser bool `json:"vhost_user,omitempty"` + Path string `json:"path"` + Readonly bool `json:"readonly,omitempty"` + Direct bool `json:"direct,omitempty"` + Iommu bool `json:"iommu,omitempty"` + NumQueues int32 `json:"num_queues,omitempty"` + QueueSize int32 `json:"queue_size,omitempty"` + VhostUser bool `json:"vhost_user,omitempty"` VhostSocket string `json:"vhost_socket,omitempty"` - PollQueue bool `json:"poll_queue,omitempty"` - Id string `json:"id,omitempty"` + PollQueue bool `json:"poll_queue,omitempty"` + Id string `json:"id,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_fs_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_fs_config.go index 6b1ccb8644..a5ea4f446d 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_fs_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_fs_config.go @@ -8,13 +8,14 @@ */ package openapi + // FsConfig struct for FsConfig type FsConfig struct { - Tag string `json:"tag"` - Socket string `json:"socket"` - NumQueues int32 `json:"num_queues"` - QueueSize int32 `json:"queue_size"` - Dax bool `json:"dax"` - CacheSize int64 `json:"cache_size"` - Id string `json:"id,omitempty"` + Tag string `json:"tag"` + Socket string `json:"socket"` + NumQueues int32 `json:"num_queues"` + QueueSize int32 `json:"queue_size"` + Dax bool `json:"dax"` + CacheSize int64 `json:"cache_size"` + Id string `json:"id,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_initramfs_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_initramfs_config.go index 3b361c1268..9b335569ba 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_initramfs_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_initramfs_config.go @@ -8,6 +8,7 @@ */ package openapi + // InitramfsConfig struct for InitramfsConfig type InitramfsConfig struct { Path string `json:"path"` diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_kernel_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_kernel_config.go index ce35f47f6b..fe12852142 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_kernel_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_kernel_config.go @@ -8,6 +8,7 @@ */ package openapi + // KernelConfig struct for KernelConfig type KernelConfig struct { Path string `json:"path"` diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_memory_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_memory_config.go index 126a8ea6a4..86408200b8 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_memory_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_memory_config.go @@ -8,14 +8,15 @@ */ package openapi + // MemoryConfig struct for MemoryConfig type MemoryConfig struct { - Size int64 `json:"size"` - HotplugSize int64 `json:"hotplug_size,omitempty"` - HotpluggedSize int64 `json:"hotplugged_size,omitempty"` - Mergeable bool `json:"mergeable,omitempty"` - HotplugMethod string `json:"hotplug_method,omitempty"` - Shared bool `json:"shared,omitempty"` - Hugepages bool `json:"hugepages,omitempty"` - Zones []MemoryZoneConfig `json:"zones,omitempty"` + Size int64 `json:"size"` + HotplugSize int64 `json:"hotplug_size,omitempty"` + HotpluggedSize int64 `json:"hotplugged_size,omitempty"` + Mergeable bool `json:"mergeable,omitempty"` + HotplugMethod string `json:"hotplug_method,omitempty"` + Shared bool `json:"shared,omitempty"` + Hugepages bool `json:"hugepages,omitempty"` + Zones []MemoryZoneConfig `json:"zones,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_memory_zone_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_memory_zone_config.go index aacd718330..8ded3360be 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_memory_zone_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_memory_zone_config.go @@ -8,15 +8,16 @@ */ package openapi + // MemoryZoneConfig struct for MemoryZoneConfig type MemoryZoneConfig struct { - Id string `json:"id"` - Size int64 `json:"size"` - File string `json:"file,omitempty"` - Mergeable bool `json:"mergeable,omitempty"` - Shared bool `json:"shared,omitempty"` - Hugepages bool `json:"hugepages,omitempty"` - HostNumaNode int32 `json:"host_numa_node,omitempty"` - HotplugSize int64 `json:"hotplug_size,omitempty"` - HotpluggedSize int64 `json:"hotplugged_size,omitempty"` + Id string `json:"id"` + Size int64 `json:"size"` + File string `json:"file,omitempty"` + Mergeable bool `json:"mergeable,omitempty"` + Shared bool `json:"shared,omitempty"` + Hugepages bool `json:"hugepages,omitempty"` + HostNumaNode int32 `json:"host_numa_node,omitempty"` + HotplugSize int64 `json:"hotplug_size,omitempty"` + HotpluggedSize int64 `json:"hotplugged_size,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_net_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_net_config.go index aea3efe7f8..c9d2da688c 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_net_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_net_config.go @@ -8,16 +8,17 @@ */ package openapi + // NetConfig struct for NetConfig type NetConfig struct { - Tap string `json:"tap,omitempty"` - Ip string `json:"ip,omitempty"` - Mask string `json:"mask,omitempty"` - Mac string `json:"mac,omitempty"` - Iommu bool `json:"iommu,omitempty"` - NumQueues int32 `json:"num_queues,omitempty"` - QueueSize int32 `json:"queue_size,omitempty"` - VhostUser bool `json:"vhost_user,omitempty"` + Tap string `json:"tap,omitempty"` + Ip string `json:"ip,omitempty"` + Mask string `json:"mask,omitempty"` + Mac string `json:"mac,omitempty"` + Iommu bool `json:"iommu,omitempty"` + NumQueues int32 `json:"num_queues,omitempty"` + QueueSize int32 `json:"queue_size,omitempty"` + VhostUser bool `json:"vhost_user,omitempty"` VhostSocket string `json:"vhost_socket,omitempty"` - Id string `json:"id,omitempty"` + Id string `json:"id,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_numa_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_numa_config.go index 378b92fd44..e4e247d629 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_numa_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_numa_config.go @@ -8,10 +8,11 @@ */ package openapi + // NumaConfig struct for NumaConfig type NumaConfig struct { - GuestNumaId int32 `json:"guest_numa_id"` - Cpus []int32 `json:"cpus,omitempty"` - Distances []NumaDistance `json:"distances,omitempty"` - MemoryZones []string `json:"memory_zones,omitempty"` + GuestNumaId int32 `json:"guest_numa_id"` + Cpus []int32 `json:"cpus,omitempty"` + Distances []NumaDistance `json:"distances,omitempty"` + MemoryZones []string `json:"memory_zones,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_numa_distance.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_numa_distance.go index 4b96816970..1f4f3560ce 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_numa_distance.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_numa_distance.go @@ -8,8 +8,9 @@ */ package openapi + // NumaDistance struct for NumaDistance type NumaDistance struct { Destination int32 `json:"destination"` - Distance int32 `json:"distance"` + Distance int32 `json:"distance"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_pci_device_info.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_pci_device_info.go index 308386207d..47b3302e63 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_pci_device_info.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_pci_device_info.go @@ -8,8 +8,9 @@ */ package openapi + // PciDeviceInfo Information about a PCI device type PciDeviceInfo struct { - Id string `json:"id"` + Id string `json:"id"` Bdf string `json:"bdf"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_pmem_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_pmem_config.go index 600238f836..85cac5564f 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_pmem_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_pmem_config.go @@ -8,12 +8,13 @@ */ package openapi + // PmemConfig struct for PmemConfig type PmemConfig struct { - File string `json:"file"` - Size int64 `json:"size,omitempty"` - Iommu bool `json:"iommu,omitempty"` - Mergeable bool `json:"mergeable,omitempty"` - DiscardWrites bool `json:"discard_writes,omitempty"` - Id string `json:"id,omitempty"` + File string `json:"file"` + Size int64 `json:"size,omitempty"` + Iommu bool `json:"iommu,omitempty"` + Mergeable bool `json:"mergeable,omitempty"` + DiscardWrites bool `json:"discard_writes,omitempty"` + Id string `json:"id,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_restore_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_restore_config.go index 713cf1b3c3..490a34d60f 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_restore_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_restore_config.go @@ -8,8 +8,9 @@ */ package openapi + // RestoreConfig struct for RestoreConfig type RestoreConfig struct { SourceUrl string `json:"source_url"` - Prefault bool `json:"prefault,omitempty"` + Prefault bool `json:"prefault,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_rng_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_rng_config.go index 3a928cd2a8..2bd1c15875 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_rng_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_rng_config.go @@ -8,8 +8,9 @@ */ package openapi + // RngConfig struct for RngConfig type RngConfig struct { - Src string `json:"src"` - Iommu bool `json:"iommu,omitempty"` + Src string `json:"src"` + Iommu bool `json:"iommu,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_sgx_epc_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_sgx_epc_config.go index 692122c387..a0562558f9 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_sgx_epc_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_sgx_epc_config.go @@ -8,8 +8,9 @@ */ package openapi + // SgxEpcConfig struct for SgxEpcConfig type SgxEpcConfig struct { - Size int64 `json:"size"` - Prefault bool `json:"prefault,omitempty"` + Size int64 `json:"size"` + Prefault bool `json:"prefault,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_add_device.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_add_device.go index f644fa60a2..749bbf139c 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_add_device.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_add_device.go @@ -8,9 +8,10 @@ */ package openapi + // VmAddDevice struct for VmAddDevice type VmAddDevice struct { - Path string `json:"path,omitempty"` - Iommu bool `json:"iommu,omitempty"` - Id string `json:"id,omitempty"` + Path string `json:"path,omitempty"` + Iommu bool `json:"iommu,omitempty"` + Id string `json:"id,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_config.go index 158ef3b2fe..7c8f09b396 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_config.go @@ -8,25 +8,26 @@ */ package openapi + // VmConfig Virtual machine configuration type VmConfig struct { - Cpus CpusConfig `json:"cpus,omitempty"` - Memory MemoryConfig `json:"memory,omitempty"` - Kernel KernelConfig `json:"kernel"` + Cpus CpusConfig `json:"cpus,omitempty"` + Memory MemoryConfig `json:"memory,omitempty"` + Kernel KernelConfig `json:"kernel"` Initramfs *InitramfsConfig `json:"initramfs,omitempty"` - Cmdline CmdLineConfig `json:"cmdline,omitempty"` - Disks []DiskConfig `json:"disks,omitempty"` - Net []NetConfig `json:"net,omitempty"` - Rng RngConfig `json:"rng,omitempty"` - Balloon BalloonConfig `json:"balloon,omitempty"` - Fs []FsConfig `json:"fs,omitempty"` - Pmem []PmemConfig `json:"pmem,omitempty"` - Serial ConsoleConfig `json:"serial,omitempty"` - Console ConsoleConfig `json:"console,omitempty"` - Devices []DeviceConfig `json:"devices,omitempty"` - Vsock VsockConfig `json:"vsock,omitempty"` - SgxEpc []SgxEpcConfig `json:"sgx_epc,omitempty"` - Numa []NumaConfig `json:"numa,omitempty"` - Iommu bool `json:"iommu,omitempty"` - Watchdog bool `json:"watchdog,omitempty"` + Cmdline CmdLineConfig `json:"cmdline,omitempty"` + Disks []DiskConfig `json:"disks,omitempty"` + Net []NetConfig `json:"net,omitempty"` + Rng RngConfig `json:"rng,omitempty"` + Balloon BalloonConfig `json:"balloon,omitempty"` + Fs []FsConfig `json:"fs,omitempty"` + Pmem []PmemConfig `json:"pmem,omitempty"` + Serial ConsoleConfig `json:"serial,omitempty"` + Console ConsoleConfig `json:"console,omitempty"` + Devices []DeviceConfig `json:"devices,omitempty"` + Vsock VsockConfig `json:"vsock,omitempty"` + SgxEpc []SgxEpcConfig `json:"sgx_epc,omitempty"` + Numa []NumaConfig `json:"numa,omitempty"` + Iommu bool `json:"iommu,omitempty"` + Watchdog bool `json:"watchdog,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_info.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_info.go index 0f1597286b..83a0159c87 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_info.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_info.go @@ -8,10 +8,11 @@ */ package openapi + // VmInfo Virtual Machine information type VmInfo struct { - Config VmConfig `json:"config"` - State string `json:"state"` - MemoryActualSize int64 `json:"memory_actual_size,omitempty"` - DeviceTree map[string]DeviceNode `json:"device_tree,omitempty"` + Config VmConfig `json:"config"` + State string `json:"state"` + MemoryActualSize int64 `json:"memory_actual_size,omitempty"` + DeviceTree map[string]DeviceNode `json:"device_tree,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_remove_device.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_remove_device.go index 4a0cb6cf2c..65bab16fc3 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_remove_device.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_remove_device.go @@ -8,6 +8,7 @@ */ package openapi + // VmRemoveDevice struct for VmRemoveDevice type VmRemoveDevice struct { Id string `json:"id,omitempty"` diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_resize.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_resize.go index 492b00a500..4e60fbfa4a 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_resize.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_resize.go @@ -8,6 +8,7 @@ */ package openapi + // VmResize struct for VmResize type VmResize struct { DesiredVcpus int32 `json:"desired_vcpus,omitempty"` diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_resize_zone.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_resize_zone.go index c86e02f0ff..aac1207604 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_resize_zone.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_resize_zone.go @@ -8,6 +8,7 @@ */ package openapi + // VmResizeZone struct for VmResizeZone type VmResizeZone struct { Id string `json:"id,omitempty"` diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_snapshot_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_snapshot_config.go index b029fff392..58d848792c 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_snapshot_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vm_snapshot_config.go @@ -8,6 +8,7 @@ */ package openapi + // VmSnapshotConfig struct for VmSnapshotConfig type VmSnapshotConfig struct { DestinationUrl string `json:"destination_url,omitempty"` diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vmm_ping_response.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vmm_ping_response.go index 4ab8cf1c1b..abbcf03464 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vmm_ping_response.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vmm_ping_response.go @@ -8,6 +8,7 @@ */ package openapi + // VmmPingResponse Virtual Machine Monitor information type VmmPingResponse struct { Version string `json:"version"` diff --git a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vsock_config.go b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vsock_config.go index 2fed17461a..98745fa77b 100644 --- a/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vsock_config.go +++ b/src/runtime/virtcontainers/pkg/cloud-hypervisor/client/model_vsock_config.go @@ -8,12 +8,13 @@ */ package openapi + // VsockConfig struct for VsockConfig type VsockConfig struct { // Guest Vsock CID Cid int64 `json:"cid"` // Path to UNIX domain socket, used to proxy vsock connections. Socket string `json:"socket"` - Iommu bool `json:"iommu,omitempty"` - Id string `json:"id,omitempty"` + Iommu bool `json:"iommu,omitempty"` + Id string `json:"id,omitempty"` } diff --git a/src/runtime/virtcontainers/pkg/oci/utils.go b/src/runtime/virtcontainers/pkg/oci/utils.go index 1fa885bb80..0663318046 100644 --- a/src/runtime/virtcontainers/pkg/oci/utils.go +++ b/src/runtime/virtcontainers/pkg/oci/utils.go @@ -100,19 +100,25 @@ type RuntimeConfig struct { AgentConfig vc.KataAgentConfig - Console string - //Determines how the VM should be connected to the //the container network interface InterNetworkModel vc.NetInterworkingModel FactoryConfig FactoryConfig - Debug bool - Trace bool + Console string JaegerEndpoint string JaegerUser string JaegerPassword string + //Paths to be bindmounted RO into the guest. + SandboxBindMounts []string + + //Experimental features enabled + Experimental []exp.Feature + + Debug bool + Trace bool + //Determines if seccomp should be applied inside guest DisableGuestSeccomp bool @@ -122,12 +128,6 @@ type RuntimeConfig struct { //Determines kata processes are managed only in sandbox cgroup SandboxCgroupOnly bool - //Paths to be bindmounted RO into the guest. - SandboxBindMounts []string - - //Experimental features enabled - Experimental []exp.Feature - // Determines if enable pprof EnablePprof bool } @@ -819,7 +819,7 @@ func addHypervisporNetworkOverrides(ocispec specs.Spec, sbConfig *vc.SandboxConf if value, ok := ocispec.Annotations[vcAnnotations.RxRateLimiterMaxRate]; ok { rxRateLimiterMaxRate, err := strconv.ParseUint(value, 10, 64) - if err != nil || rxRateLimiterMaxRate < 0 { + if err != nil { return fmt.Errorf("Error parsing annotation for rx_rate_limiter_max_rate: %v, Please specify an integer greater than or equal to 0", err) } sbConfig.HypervisorConfig.RxRateLimiterMaxRate = rxRateLimiterMaxRate @@ -827,7 +827,7 @@ func addHypervisporNetworkOverrides(ocispec specs.Spec, sbConfig *vc.SandboxConf if value, ok := ocispec.Annotations[vcAnnotations.TxRateLimiterMaxRate]; ok { txRateLimiterMaxRate, err := strconv.ParseUint(value, 10, 64) - if err != nil || txRateLimiterMaxRate < 0 { + if err != nil { return fmt.Errorf("Error parsing annotation for tx_rate_limiter_max_rate: %v, Please specify an integer greater than or equal to 0", err) } sbConfig.HypervisorConfig.TxRateLimiterMaxRate = txRateLimiterMaxRate diff --git a/src/runtime/virtcontainers/pkg/vcmock/sandbox.go b/src/runtime/virtcontainers/pkg/vcmock/sandbox.go index 168bb51e33..0eee87ef15 100644 --- a/src/runtime/virtcontainers/pkg/vcmock/sandbox.go +++ b/src/runtime/virtcontainers/pkg/vcmock/sandbox.go @@ -71,12 +71,12 @@ func (s *Sandbox) Release(ctx context.Context) error { } // Start implements the VCSandbox function of the same name. -func (s *Sandbox) Start() error { +func (s *Sandbox) Start(ctx context.Context) error { return nil } // Stop implements the VCSandbox function of the same name. -func (s *Sandbox) Stop(force bool) error { +func (s *Sandbox) Stop(ctx context.Context, force bool) error { return nil } @@ -114,7 +114,7 @@ func (s *Sandbox) StartContainer(ctx context.Context, contID string) (vc.VCConta } // StopContainer implements the VCSandbox function of the same name. -func (s *Sandbox) StopContainer(contID string, force bool) (vc.VCContainer, error) { +func (s *Sandbox) StopContainer(ctx context.Context, contID string, force bool) (vc.VCContainer, error) { return &Container{}, nil } diff --git a/src/runtime/virtcontainers/qemu.go b/src/runtime/virtcontainers/qemu.go index 9c67bd805b..0c070bf99c 100644 --- a/src/runtime/virtcontainers/qemu.go +++ b/src/runtime/virtcontainers/qemu.go @@ -36,10 +36,10 @@ import ( pkgUtils "github.com/kata-containers/kata-containers/src/runtime/pkg/utils" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api" + vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/uuid" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils" - vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" ) // romFile is the file name of the ROM that can be used for virtio-pci devices. @@ -121,13 +121,9 @@ const ( scsiControllerID = "scsi0" rngID = "rng0" - vsockKernelOption = "agent.use_vsock" fallbackFileBackedMemDir = "/dev/shm" ) -var qemuMajorVersion int -var qemuMinorVersion int - // agnostic list of kernel parameters var defaultKernelParameters = []Param{ {"panic", "1"}, @@ -472,7 +468,7 @@ func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNa // Save the tracing context q.ctx = ctx - span, ctx := q.trace(ctx, "createSandbox") + span, _ := q.trace(ctx, "createSandbox") defer span.End() if err := q.setup(ctx, id, hypervisorConfig); err != nil { @@ -776,7 +772,7 @@ func (q *qemu) setupVirtioMem() error { // startSandbox will start the Sandbox's VM. func (q *qemu) startSandbox(ctx context.Context, timeout int) error { - span, ctx := q.trace(ctx, "startSandbox") + span, _ := q.trace(ctx, "startSandbox") defer span.End() if q.config.Debug { @@ -921,9 +917,6 @@ func (q *qemu) waitSandbox(ctx context.Context, timeout int) error { q.qmpMonitorCh.disconn = disconnectCh defer q.qmpShutdown() - qemuMajorVersion = ver.Major - qemuMinorVersion = ver.Minor - q.Logger().WithFields(logrus.Fields{ "qmp-major-version": ver.Major, "qmp-minor-version": ver.Minor, @@ -1024,9 +1017,8 @@ func (q *qemu) togglePauseSandbox(ctx context.Context, pause bool) error { if pause { return q.qmpMonitorCh.qmp.ExecuteStop(q.qmpMonitorCh.ctx) - } else { - return q.qmpMonitorCh.qmp.ExecuteCont(q.qmpMonitorCh.ctx) } + return q.qmpMonitorCh.qmp.ExecuteCont(q.qmpMonitorCh.ctx) } func (q *qemu) qmpSetup() error { @@ -1067,19 +1059,13 @@ func (q *qemu) qmpSetup() error { } func (q *qemu) loopQMPEvent(event chan govmmQemu.QMPEvent) { - for { - select { - case e, open := <-event: - if !open { - q.Logger().Infof("QMP event channel closed") - return - } - q.Logger().WithField("event", e).Debug("got QMP event") - if e.Name == "GUEST_PANICKED" { - go q.handleGuestPanic() - } + for e := range event { + q.Logger().WithField("event", e).Debug("got QMP event") + if e.Name == "GUEST_PANICKED" { + go q.handleGuestPanic() } } + q.Logger().Infof("QMP event channel closed") } func (q *qemu) handleGuestPanic() { @@ -1116,13 +1102,12 @@ func (q *qemu) canDumpGuestMemory(dumpSavePath string) error { exceptMemorySize := guestMemorySizeInBytes * 2 if availSpaceInBytes >= exceptMemorySize { return nil - } else { - return fmt.Errorf("there are not enough free space to store memory dump file. Except %d bytes, but only %d bytes available", exceptMemorySize, availSpaceInBytes) } + return fmt.Errorf("there are not enough free space to store memory dump file. Except %d bytes, but only %d bytes available", exceptMemorySize, availSpaceInBytes) } // dumpSandboxMetaInfo save meta information for debug purpose, includes: -// hypervisor verison, sandbox/container state, hypervisor config +// hypervisor version, sandbox/container state, hypervisor config func (q *qemu) dumpSandboxMetaInfo(dumpSavePath string) { dumpStatePath := filepath.Join(dumpSavePath, "state") @@ -1377,19 +1362,18 @@ func (q *qemu) hotplugBlockDevice(ctx context.Context, drive *config.BlockDrive, if op == addDevice { return q.hotplugAddBlockDevice(ctx, drive, op, devID) - } else { - if q.config.BlockDeviceDriver == config.VirtioBlock { - if err := q.arch.removeDeviceFromBridge(drive.ID); err != nil { - return err - } - } - - if err := q.qmpMonitorCh.qmp.ExecuteDeviceDel(q.qmpMonitorCh.ctx, devID); err != nil { + } + if q.config.BlockDeviceDriver == config.VirtioBlock { + if err := q.arch.removeDeviceFromBridge(drive.ID); err != nil { return err } - - return q.qmpMonitorCh.qmp.ExecuteBlockdevDel(q.qmpMonitorCh.ctx, drive.ID) } + + if err := q.qmpMonitorCh.qmp.ExecuteDeviceDel(q.qmpMonitorCh.ctx, devID); err != nil { + return err + } + + return q.qmpMonitorCh.qmp.ExecuteBlockdevDel(q.qmpMonitorCh.ctx, drive.ID) } func (q *qemu) hotplugVhostUserDevice(ctx context.Context, vAttr *config.VhostUserDeviceAttrs, op operation) error { @@ -1625,7 +1609,7 @@ func (q *qemu) hotplugDevice(ctx context.Context, devInfo interface{}, devType d } func (q *qemu) hotplugAddDevice(ctx context.Context, devInfo interface{}, devType deviceType) (interface{}, error) { - span, ctx := q.trace(ctx, "hotplugAddDevice") + span, _ := q.trace(ctx, "hotplugAddDevice") defer span.End() data, err := q.hotplugDevice(ctx, devInfo, devType, addDevice) @@ -1637,7 +1621,7 @@ func (q *qemu) hotplugAddDevice(ctx context.Context, devInfo interface{}, devTyp } func (q *qemu) hotplugRemoveDevice(ctx context.Context, devInfo interface{}, devType deviceType) (interface{}, error) { - span, ctx := q.trace(ctx, "hotplugRemoveDevice") + span, _ := q.trace(ctx, "hotplugRemoveDevice") defer span.End() data, err := q.hotplugDevice(ctx, devInfo, devType, removeDevice) @@ -1849,14 +1833,14 @@ func (q *qemu) hotplugAddMemory(memDev *memoryDevice) (int, error) { } func (q *qemu) pauseSandbox(ctx context.Context) error { - span, ctx := q.trace(ctx, "pauseSandbox") + span, _ := q.trace(ctx, "pauseSandbox") defer span.End() return q.togglePauseSandbox(ctx, true) } func (q *qemu) resumeSandbox(ctx context.Context) error { - span, ctx := q.trace(ctx, "resumeSandbox") + span, _ := q.trace(ctx, "resumeSandbox") defer span.End() return q.togglePauseSandbox(ctx, false) diff --git a/src/runtime/virtcontainers/qemu_arch_base.go b/src/runtime/virtcontainers/qemu_arch_base.go index 8770164e1c..303b4b5880 100644 --- a/src/runtime/virtcontainers/qemu_arch_base.go +++ b/src/runtime/virtcontainers/qemu_arch_base.go @@ -157,7 +157,7 @@ type qemuArchBase struct { kernelParamsDebug []Param kernelParams []Param Bridges []types.Bridge - PFlash []string + PFlash []string } const ( diff --git a/src/runtime/virtcontainers/sandbox.go b/src/runtime/virtcontainers/sandbox.go index ec831913a1..66a77a31a5 100644 --- a/src/runtime/virtcontainers/sandbox.go +++ b/src/runtime/virtcontainers/sandbox.go @@ -445,7 +445,7 @@ func (s *Sandbox) getAndStoreGuestDetails(ctx context.Context) error { // to physically create that sandbox i.e. starts a VM for that sandbox to eventually // be started. func createSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factory) (*Sandbox, error) { - span, ctx := trace(ctx, "createSandbox") + span, _ := trace(ctx, "createSandbox") defer span.End() if err := createAssets(ctx, &sandboxConfig); err != nil { @@ -483,7 +483,7 @@ func createSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Fac } func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factory) (sb *Sandbox, retErr error) { - span, ctx := trace(ctx, "newSandbox") + span, _ := trace(ctx, "newSandbox") defer span.End() if !sandboxConfig.valid() { @@ -618,7 +618,7 @@ func (s *Sandbox) createCgroupManager() error { // storeSandbox stores a sandbox config. func (s *Sandbox) storeSandbox(ctx context.Context) error { - span, ctx := s.trace(ctx, "storeSandbox") + span, _ := s.trace(ctx, "storeSandbox") defer span.End() // flush data to storage @@ -628,15 +628,6 @@ func (s *Sandbox) storeSandbox(ctx context.Context) error { return nil } -func rLockSandbox(sandboxID string) (func() error, error) { - store, err := persist.GetDriver() - if err != nil { - return nil, fmt.Errorf("failed to get fs persist driver: %v", err) - } - - return store.Lock(sandboxID, false) -} - func rwLockSandbox(sandboxID string) (func() error, error) { store, err := persist.GetDriver() if err != nil { @@ -761,7 +752,7 @@ func (s *Sandbox) createNetwork(ctx context.Context) error { return nil } - span, ctx := s.trace(ctx, "createNetwork") + span, _ := s.trace(ctx, "createNetwork") defer span.End() s.networkNS = NetworkNamespace{ @@ -951,7 +942,7 @@ func (cw *consoleWatcher) start(s *Sandbox) (err error) { scanner = bufio.NewScanner(cw.conn) case consoleProtoPty: // read-only - cw.ptyConsole, err = os.Open(cw.consoleURL) + cw.ptyConsole, _ = os.Open(cw.consoleURL) scanner = bufio.NewScanner(cw.ptyConsole) default: return fmt.Errorf("unknown console proto %s", cw.proto) @@ -1003,7 +994,7 @@ func (cw *consoleWatcher) stop() { // startVM starts the VM. func (s *Sandbox) startVM(ctx context.Context) (err error) { - span, ctx := s.trace(ctx, "startVM") + span, _ := s.trace(ctx, "startVM") defer span.End() s.Logger().Info("Starting VM") @@ -1084,7 +1075,7 @@ func (s *Sandbox) startVM(ctx context.Context) (err error) { // stopVM: stop the sandbox's VM func (s *Sandbox) stopVM(ctx context.Context) error { - span, ctx := s.trace(ctx, "stopVM") + span, _ := s.trace(ctx, "stopVM") defer span.End() s.Logger().Info("Stopping sandbox in the VM") @@ -1460,7 +1451,7 @@ func (s *Sandbox) ResumeContainer(ctx context.Context, containerID string) error // createContainers registers all containers, create the // containers in the guest and starts one shim per container. func (s *Sandbox) createContainers(ctx context.Context) error { - span, ctx := s.trace(ctx, "createContainers") + span, _ := s.trace(ctx, "createContainers") defer span.End() for _, contConfig := range s.config.Containers { @@ -1532,7 +1523,7 @@ func (s *Sandbox) Start(ctx context.Context) error { // will be destroyed. // When force is true, ignore guest related stop failures. func (s *Sandbox) Stop(ctx context.Context, force bool) error { - span, ctx := s.trace(ctx, "Stop") + span, _ := s.trace(ctx, "Stop") defer span.End() if s.state.State == types.StateStopped { @@ -1643,7 +1634,7 @@ func (s *Sandbox) unsetSandboxBlockIndex(index int) error { // HotplugAddDevice is used for add a device to sandbox // Sandbox implement DeviceReceiver interface from device/api/interface.go func (s *Sandbox) HotplugAddDevice(ctx context.Context, device api.Device, devType config.DeviceType) error { - span, ctx := s.trace(ctx, "HotplugAddDevice") + span, _ := s.trace(ctx, "HotplugAddDevice") defer span.End() if s.config.SandboxCgroupOnly { diff --git a/src/runtime/virtcontainers/sandbox_metrics.go b/src/runtime/virtcontainers/sandbox_metrics.go index 51e94c0ca4..49e115cfcb 100644 --- a/src/runtime/virtcontainers/sandbox_metrics.go +++ b/src/runtime/virtcontainers/sandbox_metrics.go @@ -62,7 +62,7 @@ var ( Help: "Open FDs for hypervisor.", }) - agentRpcDurationsHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{ + agentRPCDurationsHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{ Namespace: namespaceKatashim, Name: "agent_rpc_durations_histogram_milliseconds", Help: "RPC latency distributions.", @@ -79,7 +79,7 @@ func RegisterMetrics() { prometheus.MustRegister(hypervisorNetdev) prometheus.MustRegister(hypervisorIOStat) prometheus.MustRegister(hypervisorOpenFDs) - prometheus.MustRegister(agentRpcDurationsHistogram) + prometheus.MustRegister(agentRPCDurationsHistogram) } // UpdateRuntimeMetrics update shim/hypervisor's metrics diff --git a/src/runtime/virtcontainers/tap_endpoint.go b/src/runtime/virtcontainers/tap_endpoint.go index 344652b2f3..9617945814 100644 --- a/src/runtime/virtcontainers/tap_endpoint.go +++ b/src/runtime/virtcontainers/tap_endpoint.go @@ -13,8 +13,8 @@ import ( "github.com/vishvananda/netlink" persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api" - "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/uuid" vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" + "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/uuid" ) // TapEndpoint represents just a tap endpoint diff --git a/src/runtime/virtcontainers/vhostuser_endpoint.go b/src/runtime/virtcontainers/vhostuser_endpoint.go index 7c8a1f9f8b..7f3c9efe43 100644 --- a/src/runtime/virtcontainers/vhostuser_endpoint.go +++ b/src/runtime/virtcontainers/vhostuser_endpoint.go @@ -13,8 +13,8 @@ import ( "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api" - "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils" vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" + "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils" ) // Long term, this should be made more configurable. For now matching path diff --git a/tools/agent-ctl/Cargo.lock b/tools/agent-ctl/Cargo.lock index ce45a2c11e..9c61b93bd4 100644 --- a/tools/agent-ctl/Cargo.lock +++ b/tools/agent-ctl/Cargo.lock @@ -45,18 +45,6 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034" -[[package]] -name = "arrayref" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" - -[[package]] -name = "arrayvec" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" - [[package]] name = "async-trait" version = "0.1.42" @@ -99,29 +87,12 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base64" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" - [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -[[package]] -name = "blake2b_simd" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a" -dependencies = [ - "arrayref", - "arrayvec", - "constant_time_eq", -] - [[package]] name = "byteorder" version = "1.3.4" @@ -212,12 +183,6 @@ dependencies = [ "vec_map", ] -[[package]] -name = "constant_time_eq" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" - [[package]] name = "crossbeam-channel" version = "0.4.2" @@ -250,26 +215,6 @@ dependencies = [ "syn 1.0.58", ] -[[package]] -name = "dirs" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "142995ed02755914747cc6ca76fc7e4583cd18578746716d0508ea6ed558b9ff" -dependencies = [ - "dirs-sys", -] - -[[package]] -name = "dirs-sys" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - [[package]] name = "either" version = "1.6.1" @@ -990,17 +935,6 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" -[[package]] -name = "redox_users" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b23093265f8d200fa7b4c2c76297f47e681c655f6f1285a8780d6a022f7431" -dependencies = [ - "getrandom", - "redox_syscall", - "rust-argon2", -] - [[package]] name = "regex" version = "1.3.9" @@ -1037,18 +971,6 @@ dependencies = [ "libc", ] -[[package]] -name = "rust-argon2" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc8af4bda8e1ff4932523b94d3dd20ee30a87232323eda55903ffd71d2fb017" -dependencies = [ - "base64", - "blake2b_simd", - "constant_time_eq", - "crossbeam-utils", -] - [[package]] name = "rustc-demangle" version = "0.1.18" @@ -1072,7 +994,6 @@ dependencies = [ "async-trait", "caps", "cgroups-rs", - "dirs", "futures", "inotify", "lazy_static",