Repository: containerd/containerd
File: core/runtime/v2/bridge.go (Go)

Code before:

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package v2

import (
	"context"
	"fmt"

	"github.com/containerd/ttrpc"
	"google.golang.org/grpc"
	"google.golang.org/protobuf/types/known/emptypb"

	v2 "github.com/containerd/containerd/api/runtime/task/v2"
	api "github.com/containerd/containerd/api/runtime/task/v3"
)

// TaskServiceClient exposes a client interface to shims, which aims to hide
// the underlying complexity and backward compatibility (v2 task service vs v3, TTRPC vs GRPC, etc).
type TaskServiceClient interface {
	State(context.Context, *api.StateRequest) (*api.StateResponse, error)
	Create(context.Context, *api.CreateTaskRequest) (*api.CreateTaskResponse, error)
	Start(context.Context, *api.StartRequest) (*api.StartResponse, error)
	Delete(context.Context, *api.DeleteRequest) (*api.DeleteResponse, error)
	Pids(context.Context, *api.PidsRequest) (*api.PidsResponse, error)
	Pause(context.Context, *api.PauseRequest) (*emptypb.Empty, error)
	Resume(context.Context, *api.ResumeRequest) (*emptypb.Empty, error)
	Checkpoint(context.Context, *api.CheckpointTaskRequest) (*emptypb.Empty, error)
	Kill(context.Context, *api.KillRequest) (*emptypb.Empty, error)
	Exec(context.Context, *api.ExecProcessRequest) (*emptypb.Empty, error)
	ResizePty(context.Context, *api.ResizePtyRequest) (*emptypb.Empty, error)
	CloseIO(context.Context, *api.CloseIORequest) (*emptypb.Empty, error)
	Update(context.Context, *api.UpdateTaskRequest) (*emptypb.Empty, error)
	Wait(context.Context, *api.WaitRequest) (*api.WaitResponse, error)
	Stats(context.Context, *api.StatsRequest) (*api.StatsResponse, error)
	Connect(context.Context, *api.ConnectRequest) (*api.ConnectResponse, error)
	Shutdown(context.Context, *api.ShutdownRequest) (*emptypb.Empty, error)
}

// NewTaskClient returns a new task client interface which handles both GRPC and TTRPC servers depending on the

Review comment (suggestion):
Same for this one; also the first commit removed a `// Comment` that (from the looks of it) was informational, so probably should be kept.

Code after:

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package v2

import (
	"context"
	"fmt"

	"github.com/containerd/ttrpc"
	"google.golang.org/grpc"
	"google.golang.org/protobuf/types/known/emptypb"

	v2 "github.com/containerd/containerd/api/runtime/task/v2"

	api "github.com/containerd/containerd/api/runtime/task/v3" // Current version used by TaskServiceClient
)

// TaskServiceClient exposes a client interface to shims, which aims to hide
// the underlying complexity and backward compatibility (v2 task service vs v3, TTRPC vs GRPC, etc).
type TaskServiceClient interface {
	State(context.Context, *api.StateRequest) (*api.StateResponse, error)
	Create(context.Context, *api.CreateTaskRequest) (*api.CreateTaskResponse, error)
	Start(context.Context, *api.StartRequest) (*api.StartResponse, error)
	Delete(context.Context, *api.DeleteRequest) (*api.DeleteResponse, error)
	Pids(context.Context, *api.PidsRequest) (*api.PidsResponse, error)
	Pause(context.Context, *api.PauseRequest) (*emptypb.Empty, error)
	Resume(context.Context, *api.ResumeRequest) (*emptypb.Empty, error)
	Checkpoint(context.Context, *api.CheckpointTaskRequest) (*emptypb.Empty, error)
	Kill(context.Context, *api.KillRequest) (*emptypb.Empty, error)
	Exec(context.Context, *api.ExecProcessRequest) (*emptypb.Empty, error)
	ResizePty(context.Context, *api.ResizePtyRequest) (*emptypb.Empty, error)
	CloseIO(context.Context, *api.CloseIORequest) (*emptypb.Empty, error)
	Update(context.Context, *api.UpdateTaskRequest) (*emptypb.Empty, error)
	Wait(context.Context, *api.WaitRequest) (*api.WaitResponse, error)
	Stats(context.Context, *api.StatsRequest) (*api.StatsResponse, error)
	Connect(context.Context, *api.ConnectRequest) (*api.ConnectResponse, error)
	Shutdown(context.Context, *api.ShutdownRequest) (*emptypb.Empty, error)
}