Skip to content

Commit

Permalink
Updated containerd1.7; google.golang.org/protobuf
Browse files Browse the repository at this point in the history
Update to containerd 1.7 and move to `google.golang.org/protobuf`
from `github.com/gogo/protobuf/gogoproto`.

These two changes are intertwined, since containerd 1.7 changes its
ttrpc task server definitions and protobuff generation (as well as some
other API changes).
Upgrading to `google.golang.org/protobuf` also requires updating
the `containerd/cgroups` dependency to v3
(`github.com/containerd/cgroups/v3/cgroup1/stats/`).

The new `protoc-gen-go-grpc` generators do not allow directives such as
`gogoproto.customname`, so the `go-fix-acronym` command is used to
update acronym customization (similar to what containerd does).

Added an `Update-Proto.ps1` script to re-gerenate protobuf files locally
and in GitHub CI.

Add `protobuild` and protobuff `grpc` and `ttrpc` generators to
`tools.go` so they are tracked and vendored, and can be trivially
installed via `go install`.

Add empty `after` section to Protobuild to suppress errors about missing
directories `usr/local/include` and `/usr/include`, which are defaults.

Add protobuf file to gitignore so it does not affect `git diff` results.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
  • Loading branch information
helsaawy committed May 4, 2023
1 parent 4c7925c commit 274836c
Show file tree
Hide file tree
Showing 540 changed files with 54,373 additions and 84,520 deletions.
52 changes: 28 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,44 +53,47 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

# protobuild requires the code to be in $GOPATH to translate from github.com/Microsoft/hcsshim
# to the correct path on disk
- uses: actions/checkout@v3
with:
path: "go/src/github.com/Microsoft/hcsshim"
# Install protoc-gen-gogoctrd in D:\bin
- uses: actions/checkout@v3
with:
repository: containerd/containerd
ref: v1.6.2
path: "containerd"
- name: Install protoc-gen-gogoctrd
shell: powershell
run: |
cd containerd
go build ./cmd/protoc-gen-gogoctrd
mkdir D:\bin
mv protoc-gen-gogoctrd.exe D:\bin
path: "${{ github.workspace }}/go/src/github.com/Microsoft/hcsshim"

# Install protoc in D:\bin
- name: Install protoc
shell: powershell
run: |
Invoke-WebRequest -OutFile protoc.zip -Uri https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protoc-3.19.4-win32.zip
$VerbosePreference = 'Continue'
$ErrorActionPreference = 'Stop'
$protocVersion = '3.19.4'
$url = "https://github.com/protocolbuffers/protobuf/releases/download/v${protocVersion}/protoc-${protocVersion}-win32.zip"
curl.exe -L --no-progress-meter -o protoc.zip $url
Expand-Archive -Path protoc.zip -DestinationPath .
mv include go/src/github.com/Microsoft/hcsshim/protobuf
mkdir -f ${{ github.workspace }}/go/src/github.com/Microsoft/hcsshim/protobuf
mv include/* ${{ github.workspace }}/go/src/github.com/Microsoft/hcsshim/protobuf
mkdir -f D:\bin
mv bin\protoc.exe D:\bin
- name: Run Protobuild
- name: Run protobuild
shell: powershell
run: |
go install github.com/containerd/protobuild@v0.2.0
cd go\src\github.com\Microsoft\hcsshim
$Env:Path += ";D:\bin;" + $Env:GOPATH + "\bin"
protobuild $(go list ./... | grep -v /vendor/)
$env:Path += ";D:\bin;$env:GOPATH\bin"
Write-Output "::group::protobuild"
.\scripts\Update-Proto.ps1
Write-Output "::endgroup::"
git add --all --intent-to-add .
Write-Output "::group::git diff"
git diff --exit-code
Write-Output "::endgroup::"
working-directory: "${{ github.workspace }}/go/src/github.com/Microsoft/hcsshim"
env:
GOPATH: '${{ github.workspace }}\go'
GOFLAGS: ""
GOPROXY: ""

verify-vendor:
runs-on: "windows-2019"
Expand Down Expand Up @@ -262,6 +265,7 @@ jobs:
with:
path: src/github.com/containerd/containerd
repository: "containerd/containerd"
ref: "release/1.7"

- uses: actions/checkout@v3
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ rootfs-conv/*
deps/*
out/*

# protobuf files
/protobuf/*

# test results
test/results

Expand Down
57 changes: 17 additions & 40 deletions Protobuild.toml
Original file line number Diff line number Diff line change
@@ -1,48 +1,25 @@
version = "1"
generator = "gogoctrd"
plugins = ["grpc", "fieldpath"]
version = "2"
generators = ["go", "go-grpc"]

# Control protoc include paths. Below are usually some good defaults, but feel
# free to try it without them if it works for your project.
# Control protoc include paths.
[includes]
# Include paths that will be added before all others. Typically, you want to
# treat the root of the project as an include, but this may not be necessary.
before = ["./protobuf"]

# Paths that should be treated as include roots in relation to the vendor
# directory. These will be calculated with the vendor directory nearest the
# target package.
packages = ["github.com/gogo/protobuf"]
# defaults are "/usr/local/include" and "/usr/include", which don't exist on Windows.
# override defaults to supress errors about non-existant directories.
after = []

# This section maps protobuf imports to Go packages. These will become
# `-M` directives in the call to the go protobuf generator.
# This section maps protobuf imports to Go packages.
[packages]
"gogoproto/gogo.proto" = "github.com/gogo/protobuf/gogoproto"
"google/protobuf/any.proto" = "github.com/gogo/protobuf/types"
"google/protobuf/empty.proto" = "github.com/gogo/protobuf/types"
"google/protobuf/struct.proto" = "github.com/gogo/protobuf/types"
"google/protobuf/descriptor.proto" = "github.com/gogo/protobuf/protoc-gen-gogo/descriptor"
"google/protobuf/field_mask.proto" = "github.com/gogo/protobuf/types"
"google/protobuf/timestamp.proto" = "github.com/gogo/protobuf/types"
"google/protobuf/duration.proto" = "github.com/gogo/protobuf/types"
"github/containerd/cgroups/stats/v1/metrics.proto" = "github.com/containerd/cgroups/stats/v1"
# github.com/containerd/cgroups protofiles still list their go path as "github.com/containerd/cgroups/cgroup1/stats"
"github.com/containerd/cgroups/v3/cgroup1/stats/metrics.proto" = "github.com/containerd/cgroups/v3/cgroup1/stats"

[[overrides]]
prefixes = ["github.com/Microsoft/hcsshim/internal/shimdiag"]
plugins = ["ttrpc"]

[[overrides]]
prefixes = ["github.com/Microsoft/hcsshim/internal/extendedtask"]
plugins = ["ttrpc"]

[[overrides]]
prefixes = ["github.com/Microsoft/hcsshim/internal/computeagent"]
plugins = ["ttrpc"]

[[overrides]]
prefixes = ["github.com/Microsoft/hcsshim/internal/ncproxyttrpc"]
plugins = ["ttrpc"]

[[overrides]]
prefixes = ["github.com/Microsoft/hcsshim/internal/vmservice"]
plugins = ["ttrpc"]
prefixes = [
"github.com/Microsoft/hcsshim/internal/shimdiag",
"github.com/Microsoft/hcsshim/internal/extendedtask",
"github.com/Microsoft/hcsshim/internal/computeagent",
"github.com/Microsoft/hcsshim/internal/ncproxyttrpc",
"github.com/Microsoft/hcsshim/internal/vmservice",
]
generators = ["go", "go-ttrpc"]
14 changes: 8 additions & 6 deletions cmd/containerd-shim-runhcs-v1/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ import (
"path/filepath"
"time"

task "github.com/containerd/containerd/api/runtime/task/v2"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/Microsoft/hcsshim/internal/hcs"
"github.com/Microsoft/hcsshim/internal/memory"
"github.com/Microsoft/hcsshim/internal/oc"
"github.com/Microsoft/hcsshim/internal/winapi"
"github.com/containerd/containerd/runtime/v2/task"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

// LimitedRead reads at max `readLimitBytes` bytes from the file at path `filePath`. If the file has
Expand Down Expand Up @@ -119,7 +121,7 @@ The delete command will be executed in the container's bundle as its cwd.
}

if data, err := proto.Marshal(&task.DeleteResponse{
ExitedAt: time.Now(),
ExitedAt: timestamppb.New(time.Now()),
ExitStatus: 255,
}); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/containerd-shim-runhcs-v1/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package main
import (
"context"

task "github.com/containerd/containerd/api/runtime/task/v2"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/runtime/v2/task"
"github.com/pkg/errors"
)

Expand Down
13 changes: 7 additions & 6 deletions cmd/containerd-shim-runhcs-v1/exec_hcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
"time"

eventstypes "github.com/containerd/containerd/api/events"
task "github.com/containerd/containerd/api/runtime/task/v2"
containerd_v1_types "github.com/containerd/containerd/api/types/task"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/runtime"
"github.com/containerd/containerd/runtime/v2/task"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"go.opencensus.io/trace"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/Microsoft/hcsshim/internal/cmd"
"github.com/Microsoft/hcsshim/internal/cow"
Expand Down Expand Up @@ -151,11 +152,11 @@ func (he *hcsExec) Status() *task.StateResponse {
var s containerd_v1_types.Status
switch he.state {
case shimExecStateCreated:
s = containerd_v1_types.StatusCreated
s = containerd_v1_types.Status_CREATED
case shimExecStateRunning:
s = containerd_v1_types.StatusRunning
s = containerd_v1_types.Status_RUNNING
case shimExecStateExited:
s = containerd_v1_types.StatusStopped
s = containerd_v1_types.Status_STOPPED
}

return &task.StateResponse{
Expand All @@ -169,7 +170,7 @@ func (he *hcsExec) Status() *task.StateResponse {
Stderr: he.io.StderrPath(),
Terminal: he.io.Terminal(),
ExitStatus: he.exitStatus,
ExitedAt: he.exitedAt,
ExitedAt: timestamppb.New(he.exitedAt),
}
}

Expand Down Expand Up @@ -492,7 +493,7 @@ func (he *hcsExec) waitForExit() {
ID: he.id,
Pid: uint32(he.pid),
ExitStatus: he.exitStatus,
ExitedAt: he.exitedAt,
ExitedAt: timestamppb.New(he.exitedAt),
}); err != nil {
log.G(ctx).WithError(err).Error("failed to publish TaskExitEvent")
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/containerd-shim-runhcs-v1/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"context"
"time"

"github.com/containerd/containerd/runtime/v2/task"
task "github.com/containerd/containerd/api/runtime/task/v2"
"google.golang.org/protobuf/types/known/timestamppb"
)

// newTestShimExec creates a test exec. If you are intending to make an init
Expand Down Expand Up @@ -47,7 +48,7 @@ func (tse *testShimExec) Status() *task.StateResponse {
ExecID: tse.id,
Pid: uint32(tse.pid),
ExitStatus: tse.status,
ExitedAt: tse.at,
ExitedAt: timestamppb.New(tse.at),
}
}
func (tse *testShimExec) Start(ctx context.Context) error {
Expand Down
11 changes: 6 additions & 5 deletions cmd/containerd-shim-runhcs-v1/exec_wcow_podsandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (

"github.com/Microsoft/hcsshim/internal/log"
eventstypes "github.com/containerd/containerd/api/events"
task "github.com/containerd/containerd/api/runtime/task/v2"
containerd_v1_types "github.com/containerd/containerd/api/types/task"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/runtime"
"github.com/containerd/containerd/runtime/v2/task"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"google.golang.org/protobuf/types/known/timestamppb"
)

func newWcowPodSandboxExec(ctx context.Context, events publisher, tid, bundle string) *wcowPodSandboxExec {
Expand Down Expand Up @@ -100,11 +101,11 @@ func (wpse *wcowPodSandboxExec) Status() *task.StateResponse {
var s containerd_v1_types.Status
switch wpse.state {
case shimExecStateCreated:
s = containerd_v1_types.StatusCreated
s = containerd_v1_types.Status_CREATED
case shimExecStateRunning:
s = containerd_v1_types.StatusRunning
s = containerd_v1_types.Status_RUNNING
case shimExecStateExited:
s = containerd_v1_types.StatusStopped
s = containerd_v1_types.Status_STOPPED
}

return &task.StateResponse{
Expand All @@ -118,7 +119,7 @@ func (wpse *wcowPodSandboxExec) Status() *task.StateResponse {
Stderr: "", // NilIO
Terminal: false,
ExitStatus: wpse.exitStatus,
ExitedAt: wpse.exitedAt,
ExitedAt: timestamppb.New(wpse.exitedAt),
}
}

Expand Down
Loading

0 comments on commit 274836c

Please sign in to comment.