forked from containerd/nri
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.go
More file actions
152 lines (122 loc) · 5.1 KB
/
Copy pathplugin.go
File metadata and controls
152 lines (122 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
Copyright The containerd Authors.
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 main
import (
"context"
api "github.com/containerd/nri/pkg/api"
)
type plugin struct{}
func init() {
api.RegisterPlugin(&plugin{})
}
func main() {}
func log(ctx context.Context, msg string) {
api.NewHostFunctions().Log(ctx, &api.LogRequest{
Msg: "WASM: " + msg,
Level: api.LogRequest_LEVEL_INFO,
})
}
func (p *plugin) Configure(ctx context.Context, req *api.ConfigureRequest) (*api.ConfigureResponse, error) {
log(ctx, "Got configure request")
return nil, nil
}
func (p *plugin) Synchronize(ctx context.Context, req *api.SynchronizeRequest) (*api.SynchronizeResponse, error) {
log(ctx, "Got synchronize request")
return nil, nil
}
func (p *plugin) Shutdown(ctx context.Context, req *api.Empty) (*api.Empty, error) {
log(ctx, "Got shutdown request")
return nil, nil
}
func (p *plugin) StateChange(ctx context.Context, req *api.StateChangeEvent) (*api.Empty, error) {
log(ctx, "Got state change request with event: "+req.GetEvent().String())
// Event_CREATE_CONTAINER, Event_UPDATE_CONTAINER and Event_STOP_CONTAINER
// are defined within the service protocol definition and therefore being
// called directly.
switch req.GetEvent() {
case api.Event_RUN_POD_SANDBOX:
return p.RunPodSandbox(ctx, req.GetPod())
case api.Event_POST_UPDATE_POD_SANDBOX:
return p.PostUpdatePodSandbox(ctx, req.GetPod())
case api.Event_STOP_POD_SANDBOX:
return p.StopPodSandbox(ctx, req.GetPod())
case api.Event_REMOVE_POD_SANDBOX:
return p.RemovePodSandbox(ctx, req.GetPod())
case api.Event_POST_CREATE_CONTAINER:
return p.PostCreateContainer(ctx, req.GetPod(), req.GetContainer())
case api.Event_START_CONTAINER:
return p.StartContainer(ctx, req.GetPod(), req.GetContainer())
case api.Event_POST_START_CONTAINER:
return p.PostStartContainer(ctx, req.GetPod(), req.GetContainer())
case api.Event_POST_UPDATE_CONTAINER:
return p.PostUpdateContainer(ctx, req.GetPod(), req.GetContainer())
case api.Event_REMOVE_CONTAINER:
return p.RemoveContainer(ctx, req.GetPod(), req.GetContainer())
}
return &api.Empty{}, nil
}
func (p *plugin) RunPodSandbox(ctx context.Context, pod *api.PodSandbox) (*api.Empty, error) {
log(ctx, "Got run pod sandbox request")
return nil, nil
}
func (p *plugin) UpdatePodSandbox(ctx context.Context, req *api.UpdatePodSandboxRequest) (*api.UpdatePodSandboxResponse, error) {
log(ctx, "Got update pod sandbox request")
return nil, nil
}
func (p *plugin) PostUpdatePodSandbox(ctx context.Context, pod *api.PodSandbox) (*api.Empty, error) {
log(ctx, "Got post update pod sandbox request")
return nil, nil
}
func (p *plugin) StopPodSandbox(ctx context.Context, pod *api.PodSandbox) (*api.Empty, error) {
log(ctx, "Got stop pod sandbox request")
return nil, nil
}
func (p *plugin) RemovePodSandbox(ctx context.Context, pod *api.PodSandbox) (*api.Empty, error) {
log(ctx, "Got remove pod sandbox request")
return nil, nil
}
func (p *plugin) CreateContainer(ctx context.Context, req *api.CreateContainerRequest) (*api.CreateContainerResponse, error) {
log(ctx, "Got create container request")
return nil, nil
}
func (p *plugin) PostCreateContainer(ctx context.Context, pod *api.PodSandbox, container *api.Container) (*api.Empty, error) {
log(ctx, "Got post create container request")
return nil, nil
}
func (p *plugin) StartContainer(ctx context.Context, pod *api.PodSandbox, container *api.Container) (*api.Empty, error) {
log(ctx, "Got start container request")
return nil, nil
}
func (p *plugin) PostStartContainer(ctx context.Context, pod *api.PodSandbox, container *api.Container) (*api.Empty, error) {
log(ctx, "Got post start container request")
return nil, nil
}
func (p *plugin) UpdateContainer(ctx context.Context, req *api.UpdateContainerRequest) (*api.UpdateContainerResponse, error) {
log(ctx, "Got update container request")
return nil, nil
}
func (p *plugin) PostUpdateContainer(ctx context.Context, pod *api.PodSandbox, container *api.Container) (*api.Empty, error) {
log(ctx, "Got post update container request")
return nil, nil
}
func (p *plugin) StopContainer(ctx context.Context, req *api.StopContainerRequest) (*api.StopContainerResponse, error) {
log(ctx, "Got stop container request")
return nil, nil
}
func (p *plugin) RemoveContainer(ctx context.Context, pod *api.PodSandbox, container *api.Container) (*api.Empty, error) {
log(ctx, "Got remove container request")
return nil, nil
}
func (p *plugin) ValidateContainerAdjustment(ctx context.Context, req *api.ValidateContainerAdjustmentRequest) (*api.ValidateContainerAdjustmentResponse, error) {
return &api.ValidateContainerAdjustmentResponse{}, nil
}