-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathplugin.go
More file actions
184 lines (154 loc) · 6.01 KB
/
plugin.go
File metadata and controls
184 lines (154 loc) · 6.01 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
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:
_, err := p.RunPodSandbox(ctx, &api.RunPodSandboxRequest{
Pod: req.GetPod(),
})
return &api.Empty{}, err
case api.Event_POST_UPDATE_POD_SANDBOX:
_, err := p.PostUpdatePodSandbox(ctx, &api.PostUpdatePodSandboxRequest{
Pod: req.GetPod(),
})
return &api.Empty{}, err
case api.Event_STOP_POD_SANDBOX:
_, err := p.StopPodSandbox(ctx, &api.StopPodSandboxRequest{
Pod: req.GetPod(),
})
return &api.Empty{}, err
case api.Event_REMOVE_POD_SANDBOX:
_, err := p.RemovePodSandbox(ctx, &api.RemovePodSandboxRequest{
Pod: req.GetPod(),
})
return &api.Empty{}, err
case api.Event_POST_CREATE_CONTAINER:
_, err := p.PostCreateContainer(ctx, &api.PostCreateContainerRequest{
Pod: req.GetPod(),
Container: req.GetContainer(),
})
return &api.Empty{}, err
case api.Event_START_CONTAINER:
_, err := p.StartContainer(ctx, &api.StartContainerRequest{
Pod: req.GetPod(),
Container: req.GetContainer(),
})
return &api.Empty{}, err
case api.Event_POST_START_CONTAINER:
_, err := p.PostStartContainer(ctx, &api.PostStartContainerRequest{
Pod: req.GetPod(),
Container: req.GetContainer(),
})
return &api.Empty{}, err
case api.Event_POST_UPDATE_CONTAINER:
_, err := p.PostUpdateContainer(ctx, &api.PostUpdateContainerRequest{
Pod: req.GetPod(),
Container: req.GetContainer(),
})
return &api.Empty{}, err
case api.Event_REMOVE_CONTAINER:
_, err := p.RemoveContainer(ctx, &api.RemoveContainerRequest{
Pod: req.GetPod(),
Container: req.GetContainer(),
})
return &api.Empty{}, err
}
return &api.Empty{}, nil
}
func (p *plugin) RunPodSandbox(ctx context.Context, req *api.RunPodSandboxRequest) (*api.RunPodSandboxResponse, 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, req *api.PostUpdatePodSandboxRequest) (*api.PostUpdatePodSandboxResponse, error) {
log(ctx, "Got post update pod sandbox request")
return nil, nil
}
func (p *plugin) StopPodSandbox(ctx context.Context, req *api.StopPodSandboxRequest) (*api.StopPodSandboxResponse, error) {
log(ctx, "Got stop pod sandbox request")
return nil, nil
}
func (p *plugin) RemovePodSandbox(ctx context.Context, req *api.RemovePodSandboxRequest) (*api.RemovePodSandboxResponse, 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, req *api.PostCreateContainerRequest) (*api.PostCreateContainerResponse, error) {
log(ctx, "Got post create container request")
return nil, nil
}
func (p *plugin) StartContainer(ctx context.Context, req *api.StartContainerRequest) (*api.StartContainerResponse, error) {
log(ctx, "Got start container request")
return nil, nil
}
func (p *plugin) PostStartContainer(ctx context.Context, req *api.PostStartContainerRequest) (*api.PostStartContainerResponse, 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, req *api.PostUpdateContainerRequest) (*api.PostUpdateContainerResponse, 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, req *api.RemoveContainerRequest) (*api.RemoveContainerResponse, 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
}