Skip to content

Commit 43a59a9

Browse files
Merge pull request cri-o#6425 from saschagrunert/cri-wrapper
Remove `cri` wrapper package
2 parents 3e342bf + 6c62954 commit 43a59a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+134
-547
lines changed

cmd/crio/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/cri-o/cri-o/internal/version"
2424
libconfig "github.com/cri-o/cri-o/pkg/config"
2525
"github.com/cri-o/cri-o/server"
26-
v1 "github.com/cri-o/cri-o/server/cri/v1"
2726
otel_collector "github.com/cri-o/cri-o/server/otel-collector"
2827
"github.com/cri-o/cri-o/utils"
2928
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
@@ -35,6 +34,7 @@ import (
3534
sdktrace "go.opentelemetry.io/otel/sdk/trace"
3635
"golang.org/x/sys/unix"
3736
"google.golang.org/grpc"
37+
v1 "k8s.io/cri-api/pkg/apis/runtime/v1"
3838
)
3939

4040
func writeCrioGoroutineStacks() {
@@ -341,7 +341,8 @@ func main() {
341341
}
342342
}
343343

344-
v1.Register(grpcServer, crioServer)
344+
v1.RegisterRuntimeServiceServer(grpcServer, crioServer)
345+
v1.RegisterImageServiceServer(grpcServer, crioServer)
345346

346347
// after the daemon is done setting up we can notify systemd api
347348
notifySystem()

server/container_checkpoint.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import (
1818
)
1919

2020
// CheckpointContainer checkpoints a container
21-
func (s *Server) CheckpointContainer(ctx context.Context, req *types.CheckpointContainerRequest) error {
21+
func (s *Server) CheckpointContainer(ctx context.Context, req *types.CheckpointContainerRequest) (*types.CheckpointContainerResponse, error) {
2222
if !s.config.RuntimeConfig.CheckpointRestore() {
23-
return fmt.Errorf("checkpoint/restore support not available")
23+
return nil, fmt.Errorf("checkpoint/restore support not available")
2424
}
2525

2626
var opts []*lib.ContainerCheckpointRestoreOptions
@@ -32,17 +32,17 @@ func (s *Server) CheckpointContainer(ctx context.Context, req *types.CheckpointC
3232
// Maybe the user specified a Pod
3333
sb, err := s.LookupSandbox(req.ContainerId)
3434
if err != nil {
35-
return status.Errorf(codes.NotFound, "could not find container or pod %q: %v", req.ContainerId, err)
35+
return nil, status.Errorf(codes.NotFound, "could not find container or pod %q: %v", req.ContainerId, err)
3636
}
3737
if req.Location == "" {
38-
return status.Errorf(codes.NotFound, "Pod checkpointing requires a destination file")
38+
return nil, status.Errorf(codes.NotFound, "Pod checkpointing requires a destination file")
3939
}
4040

4141
log.Infof(ctx, "Checkpointing pod: %s", req.ContainerId)
4242
// Create a temporary directory
4343
podCheckpointDirectory, err = os.MkdirTemp("", "checkpoint")
4444
if err != nil {
45-
return err
45+
return nil, err
4646
}
4747
sandboxConfig := types.PodSandboxConfig{
4848
Metadata: &types.PodSandboxMetadata{
@@ -83,7 +83,7 @@ func (s *Server) CheckpointContainer(ctx context.Context, req *types.CheckpointC
8383
sandboxConfig.DnsConfig = dnsConfig
8484
}
8585
if _, err := metadata.WriteJSONFile(sandboxConfig, podCheckpointDirectory, metadata.PodDumpFile); err != nil {
86-
return err
86+
return nil, err
8787
}
8888
defer func() {
8989
if err := os.RemoveAll(podCheckpointDirectory); err != nil {
@@ -104,7 +104,7 @@ func (s *Server) CheckpointContainer(ctx context.Context, req *types.CheckpointC
104104
checkpointedPodOptions.Containers = append(checkpointedPodOptions.Containers, ctr.Name())
105105
}
106106
if len(opts) == 0 {
107-
return status.Errorf(codes.NotFound, "No containers found in Pod %q", req.ContainerId)
107+
return nil, status.Errorf(codes.NotFound, "No containers found in Pod %q", req.ContainerId)
108108
}
109109
checkpointedPodOptions.Version = 1
110110
checkpointedPodOptions.MountLabel = sb.MountLabel()
@@ -126,36 +126,36 @@ func (s *Server) CheckpointContainer(ctx context.Context, req *types.CheckpointC
126126
for _, opt := range opts {
127127
_, err = s.ContainerServer.ContainerCheckpoint(ctx, opt)
128128
if err != nil {
129-
return err
129+
return nil, err
130130
}
131131
}
132132

133133
if podCheckpointDirectory != "" {
134134
if podOptions, err := metadata.WriteJSONFile(checkpointedPodOptions, podCheckpointDirectory, metadata.PodOptionsFile); err != nil {
135-
return fmt.Errorf("error creating checkpointedContainers list file %q: %w", podOptions, err)
135+
return nil, fmt.Errorf("error creating checkpointedContainers list file %q: %w", podOptions, err)
136136
}
137137
// It is a Pod checkpoint. Create the archive
138138
podTar, err := archive.TarWithOptions(podCheckpointDirectory, &archive.TarOptions{
139139
IncludeSourceDir: true,
140140
})
141141
if err != nil {
142-
return err
142+
return nil, err
143143
}
144144
// The resulting tar archive should not readable by everyone as it contains
145145
// every memory page of the checkpointed processes.
146146
podTarFile, err := os.OpenFile(req.Location, os.O_RDWR|os.O_CREATE, 0o600)
147147
if err != nil {
148-
return fmt.Errorf("error creating pod checkpoint archive %q: %w", req.Location, err)
148+
return nil, fmt.Errorf("error creating pod checkpoint archive %q: %w", req.Location, err)
149149
}
150150
defer podTarFile.Close()
151151
_, err = io.Copy(podTarFile, podTar)
152152
if err != nil {
153-
return fmt.Errorf("failed writing to pod tar archive %q: %w", req.Location, err)
153+
return nil, fmt.Errorf("failed writing to pod tar archive %q: %w", req.Location, err)
154154
}
155155
log.Infof(ctx, "Checkpointed pod: %s", req.ContainerId)
156156
} else {
157157
log.Infof(ctx, "Checkpointed container: %s", req.ContainerId)
158158
}
159159

160-
return nil
160+
return &types.CheckpointContainerResponse{}, nil
161161
}

server/container_checkpoint_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var _ = t.Describe("ContainerCheckpoint", func() {
5454
)
5555

5656
// When
57-
err := sut.CheckpointContainer(context.Background(),
57+
_, err := sut.CheckpointContainer(context.Background(),
5858
&types.CheckpointContainerRequest{
5959
ContainerId: testContainer.ID(),
6060
})
@@ -66,7 +66,7 @@ var _ = t.Describe("ContainerCheckpoint", func() {
6666
It("should fail with invalid container id", func() {
6767
// Given
6868
// When
69-
err := sut.CheckpointContainer(context.Background(),
69+
_, err := sut.CheckpointContainer(context.Background(),
7070
&types.CheckpointContainerRequest{
7171
ContainerId: testContainer.ID(),
7272
})
@@ -78,7 +78,7 @@ var _ = t.Describe("ContainerCheckpoint", func() {
7878
// Given
7979
addContainerAndSandbox()
8080
// When
81-
err := sut.CheckpointContainer(context.Background(),
81+
_, err := sut.CheckpointContainer(context.Background(),
8282
&types.CheckpointContainerRequest{
8383
ContainerId: testSandbox.ID(),
8484
})
@@ -103,7 +103,7 @@ var _ = t.Describe("ContainerCheckpoint", func() {
103103
runtimeServerMock.EXPECT().StopContainer(gomock.Any(), gomock.Any()).Return(nil),
104104
)
105105
// When
106-
err := sut.CheckpointContainer(context.Background(),
106+
_, err := sut.CheckpointContainer(context.Background(),
107107
&types.CheckpointContainerRequest{
108108
ContainerId: testSandbox.ID(),
109109
Location: "cp.tar",
@@ -152,7 +152,7 @@ var _ = t.Describe("ContainerCheckpoint", func() {
152152
runtimeServerMock.EXPECT().StopContainer(gomock.Any(), gomock.Any()).Return(nil),
153153
)
154154
// When
155-
err := sut.CheckpointContainer(context.Background(),
155+
_, err := sut.CheckpointContainer(context.Background(),
156156
&types.CheckpointContainerRequest{
157157
ContainerId: testSandbox.ID(),
158158
Location: "cp.tar",
@@ -174,7 +174,7 @@ var _ = t.Describe("ContainerCheckpoint", func() {
174174
storeMock.EXPECT().Container(gomock.Any()).Return(nil, t.TestError),
175175
)
176176
// When
177-
err := sut.CheckpointContainer(context.Background(),
177+
_, err := sut.CheckpointContainer(context.Background(),
178178
&types.CheckpointContainerRequest{
179179
ContainerId: testSandbox.ID(),
180180
Location: "cp.tar",
@@ -202,7 +202,7 @@ var _ = t.Describe("ContainerCheckpoint with CheckpointRestore set to false", fu
202202
It("should fail with checkpoint/restore support not available", func() {
203203
// Given
204204
// When
205-
err := sut.CheckpointContainer(context.Background(),
205+
_, err := sut.CheckpointContainer(context.Background(),
206206
&types.CheckpointContainerRequest{
207207
ContainerId: testContainer.ID(),
208208
})

server/container_events.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package server
2+
3+
import (
4+
types "k8s.io/cri-api/pkg/apis/runtime/v1"
5+
)
6+
7+
func (s *Server) GetContainerEvents(req *types.GetEventsRequest, res types.RuntimeService_GetContainerEventsServer) error {
8+
// Spoofing the GetContainerEvents method to return nil response until actual support code is added.
9+
return nil
10+
}

server/container_remove.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ import (
1818

1919
// RemoveContainer removes the container. If the container is running, the container
2020
// should be force removed.
21-
func (s *Server) RemoveContainer(ctx context.Context, req *types.RemoveContainerRequest) error {
21+
func (s *Server) RemoveContainer(ctx context.Context, req *types.RemoveContainerRequest) (*types.RemoveContainerResponse, error) {
2222
ctx, span := log.StartSpan(ctx)
2323
defer span.End()
2424
log.Infof(ctx, "Removing container: %s", req.ContainerId)
2525
// save container description to print
2626
c, err := s.GetContainerFromShortID(ctx, req.ContainerId)
2727
if err != nil {
28-
return status.Errorf(codes.NotFound, "could not find container %q: %v", req.ContainerId, err)
28+
return nil, status.Errorf(codes.NotFound, "could not find container %q: %v", req.ContainerId, err)
2929
}
3030

3131
sb := s.getSandbox(ctx, c.Sandbox())
3232

3333
if err := s.removeContainerInPod(ctx, sb, c); err != nil {
34-
return err
34+
return nil, err
3535
}
3636

3737
if notifier, ok := s.seccompNotifiers.Load(c.ID()); ok {
@@ -44,7 +44,7 @@ func (s *Server) RemoveContainer(ctx context.Context, req *types.RemoveContainer
4444
}
4545

4646
log.Infof(ctx, "Removed container %s: %s", c.ID(), c.Description())
47-
return nil
47+
return &types.RemoveContainerResponse{}, nil
4848
}
4949

5050
func (s *Server) removeContainerInPod(ctx context.Context, sb *sandbox.Sandbox, c *oci.Container) error {

server/container_remove_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var _ = t.Describe("ContainerRemove", func() {
3737
)
3838

3939
// When
40-
err := sut.RemoveContainer(context.Background(),
40+
_, err := sut.RemoveContainer(context.Background(),
4141
&types.RemoveContainerRequest{
4242
ContainerId: testContainer.ID(),
4343
})
@@ -49,7 +49,7 @@ var _ = t.Describe("ContainerRemove", func() {
4949
It("should fail on container remove error", func() {
5050
// Given
5151
// When
52-
err := sut.RemoveContainer(context.Background(),
52+
_, err := sut.RemoveContainer(context.Background(),
5353
&types.RemoveContainerRequest{})
5454

5555
// Then

server/container_reopen_log.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,26 @@ import (
1010
)
1111

1212
// ReopenContainerLog reopens the containers log file
13-
func (s *Server) ReopenContainerLog(ctx context.Context, req *types.ReopenContainerLogRequest) error {
13+
func (s *Server) ReopenContainerLog(ctx context.Context, req *types.ReopenContainerLogRequest) (*types.ReopenContainerLogResponse, error) {
1414
ctx, span := log.StartSpan(ctx)
1515
defer span.End()
1616
c, err := s.GetContainerFromShortID(ctx, req.ContainerId)
1717
if err != nil {
18-
return fmt.Errorf("could not find container %s: %w", req.ContainerId, err)
18+
return nil, fmt.Errorf("could not find container %s: %w", req.ContainerId, err)
1919
}
2020

2121
if err := s.ContainerServer.Runtime().UpdateContainerStatus(ctx, c); err != nil {
22-
return err
22+
return nil, err
2323
}
2424

2525
cState := c.State()
2626
if !(cState.Status == oci.ContainerStateRunning || cState.Status == oci.ContainerStateCreated) {
27-
return fmt.Errorf("container is not created or running")
27+
return nil, fmt.Errorf("container is not created or running")
2828
}
2929

3030
if err := s.ContainerServer.Runtime().ReopenContainerLog(ctx, c); err != nil {
31-
return err
31+
return nil, err
3232
}
33-
return nil
33+
34+
return &types.ReopenContainerLogResponse{}, nil
3435
}

server/container_reopen_log_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var _ = t.Describe("ReopenContainerLog", func() {
2222
It("should fail on invalid container ID", func() {
2323
// Given
2424
// When
25-
err := sut.ReopenContainerLog(
25+
_, err := sut.ReopenContainerLog(
2626
context.Background(),
2727
&types.ReopenContainerLogRequest{},
2828
)

server/container_start.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import (
1515
)
1616

1717
// StartContainer starts the container.
18-
func (s *Server) StartContainer(ctx context.Context, req *types.StartContainerRequest) (retErr error) {
18+
func (s *Server) StartContainer(ctx context.Context, req *types.StartContainerRequest) (res *types.StartContainerResponse, retErr error) {
1919
ctx, span := log.StartSpan(ctx)
2020
defer span.End()
2121
log.Infof(ctx, "Starting container: %s", req.ContainerId)
2222
c, err := s.GetContainerFromShortID(ctx, req.ContainerId)
2323
if err != nil {
24-
return status.Errorf(codes.NotFound, "could not find container %q: %v", req.ContainerId, err)
24+
return nil, status.Errorf(codes.NotFound, "could not find container %q: %v", req.ContainerId, err)
2525
}
2626

2727
if c.Restore() {
@@ -43,30 +43,30 @@ func (s *Server) StartContainer(ctx context.Context, req *types.StartContainerRe
4343
if err != nil {
4444
ociContainer, err1 := s.GetContainerFromShortID(ctx, c.ID())
4545
if err1 != nil {
46-
return fmt.Errorf("failed to find container %s: %v", c.ID(), err1)
46+
return nil, fmt.Errorf("failed to find container %s: %v", c.ID(), err1)
4747
}
4848
s.ReleaseContainerName(ctx, ociContainer.Name())
4949
err2 := s.StorageRuntimeServer().DeleteContainer(ctx, c.ID())
5050
if err2 != nil {
5151
log.Warnf(ctx, "Failed to cleanup container directory: %v", err2)
5252
}
5353
s.removeContainer(ctx, ociContainer)
54-
return err
54+
return nil, err
5555
}
5656

5757
log.Infof(ctx, "Restored container: %s", ctr)
58-
return nil
58+
return &types.StartContainerResponse{}, nil
5959
}
6060

6161
state := c.State()
6262
if state.Status != oci.ContainerStateCreated {
63-
return fmt.Errorf("container %s is not in created state: %s", c.ID(), state.Status)
63+
return nil, fmt.Errorf("container %s is not in created state: %s", c.ID(), state.Status)
6464
}
6565

6666
sandbox := s.getSandbox(ctx, c.Sandbox())
6767
hooks, err := runtimehandlerhooks.GetRuntimeHandlerHooks(ctx, &s.config, sandbox.RuntimeHandler(), sandbox.Annotations())
6868
if err != nil {
69-
return fmt.Errorf("failed to get runtime handler %q hooks", sandbox.RuntimeHandler())
69+
return nil, fmt.Errorf("failed to get runtime handler %q hooks", sandbox.RuntimeHandler())
7070
}
7171

7272
defer func() {
@@ -89,12 +89,12 @@ func (s *Server) StartContainer(ctx context.Context, req *types.StartContainerRe
8989

9090
if hooks != nil {
9191
if err := hooks.PreStart(ctx, c, sandbox); err != nil {
92-
return fmt.Errorf("failed to run pre-start hook for container %q: %w", c.ID(), err)
92+
return nil, fmt.Errorf("failed to run pre-start hook for container %q: %w", c.ID(), err)
9393
}
9494
}
9595

9696
if err := s.Runtime().StartContainer(ctx, c); err != nil {
97-
return fmt.Errorf("failed to start container %s: %w", c.ID(), err)
97+
return nil, fmt.Errorf("failed to start container %s: %w", c.ID(), err)
9898
}
9999

100100
log.WithFields(ctx, map[string]interface{}{
@@ -103,5 +103,6 @@ func (s *Server) StartContainer(ctx context.Context, req *types.StartContainerRe
103103
"sandboxID": sandbox.ID(),
104104
"PID": state.Pid,
105105
}).Infof("Started container")
106-
return nil
106+
107+
return &types.StartContainerResponse{}, nil
107108
}

server/container_start_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var _ = t.Describe("ContainerStart", func() {
2424
addContainerAndSandbox()
2525

2626
// When
27-
err := sut.StartContainer(context.Background(),
27+
_, err := sut.StartContainer(context.Background(),
2828
&types.StartContainerRequest{
2929
ContainerId: testContainer.ID(),
3030
})
@@ -36,7 +36,7 @@ var _ = t.Describe("ContainerStart", func() {
3636
It("should fail with invalid container ID", func() {
3737
// Given
3838
// When
39-
err := sut.StartContainer(context.Background(),
39+
_, err := sut.StartContainer(context.Background(),
4040
&types.StartContainerRequest{})
4141

4242
// Then
@@ -48,7 +48,7 @@ var _ = t.Describe("ContainerStart", func() {
4848
addContainerAndSandbox()
4949

5050
// When
51-
err := sut.StartContainer(context.Background(),
51+
_, err := sut.StartContainer(context.Background(),
5252
&types.StartContainerRequest{
5353
ContainerId: testContainer.ID(),
5454
},

0 commit comments

Comments
 (0)