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

Code before:
   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"
	v3 "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, *v3.StateRequest) (*v3.StateResponse, error)
	Create(context.Context, *v3.CreateTaskRequest) (*v3.CreateTaskResponse, error)
	Start(context.Context, *v3.StartRequest) (*v3.StartResponse, error)
	Delete(context.Context, *v3.DeleteRequest) (*v3.DeleteResponse, error)
	Pids(context.Context, *v3.PidsRequest) (*v3.PidsResponse, error)
	Pause(context.Context, *v3.PauseRequest) (*emptypb.Empty, error)
	Resume(context.Context, *v3.ResumeRequest) (*emptypb.Empty, error)
	Checkpoint(context.Context, *v3.CheckpointTaskRequest) (*emptypb.Empty, error)
	Kill(context.Context, *v3.KillRequest) (*emptypb.Empty, error)
	Exec(context.Context, *v3.ExecProcessRequest) (*emptypb.Empty, error)
	ResizePty(context.Context, *v3.ResizePtyRequest) (*emptypb.Empty, error)
	CloseIO(context.Context, *v3.CloseIORequest) (*emptypb.Empty, error)
	Update(context.Context, *v3.UpdateTaskRequest) (*emptypb.Empty, error)
	Wait(context.Context, *v3.WaitRequest) (*v3.WaitResponse, error)
	Stats(context.Context, *v3.StatsRequest) (*v3.StatsResponse, error)
	Connect(context.Context, *v3.ConnectRequest) (*v3.ConnectResponse, error)
	Shutdown(context.Context, *v3.ShutdownRequest) (*emptypb.Empty, error)
}

// NewTaskClient returns a new task client interface which handles both GRPC and TTRPC servers depending on the
// client object type passed in.
//

Review comment (suggestion):
I had a quick peek at the file in `main`, and it looks like there's 4 uses of `v3`, but 82 uses of the `api` alias.

Perhaps instead we should remove the `v3` alias; it would result in less code-churn, and also because the `api` alias describes why that version is picked.




Code after:
   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)
}

// NewTaskClient returns a new task client interface which handles both GRPC and TTRPC servers depending on the
// client object type passed in.