@@ -24,6 +24,7 @@ import (
24
24
"github.com/containernetworking/cni/pkg/types"
25
25
current "github.com/containernetworking/cni/pkg/types/100"
26
26
"github.com/containernetworking/cni/pkg/version"
27
+ "github.com/containernetworking/plugins/pkg/ipam"
27
28
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
28
29
)
29
30
@@ -150,10 +151,65 @@ func cmdDel(args *skel.CmdArgs) error {
150
151
151
152
func main () {
152
153
// replace TODO with your plugin name
153
- skel .PluginMain (cmdAdd , cmdCheck , cmdDel , version .All , bv .BuildString ("TODO" ))
154
+ skel .PluginMainFuncs (skel.CNIFuncs {
155
+ Add : cmdAdd ,
156
+ Del : cmdDel ,
157
+ Check : cmdCheck ,
158
+ Status : cmdStatus ,
159
+ GC : cmdGc ,
160
+ }, version .All , bv .BuildString ("a sample plugin" ))
154
161
}
155
162
156
163
func cmdCheck (_ * skel.CmdArgs ) error {
157
164
// TODO: implement
158
165
return fmt .Errorf ("not implemented" )
159
166
}
167
+
168
+ // cmdStatus implements the STATUS command, which indicates whether or not
169
+ // this plugin is able to accept ADD requests.
170
+ //
171
+ // If the plugin has external dependencies, such as a daemon
172
+ // or chained ipam plugin, it should determine their status. If all is well,
173
+ // and an ADD can be successfully processed, return nil
174
+ func cmdStatus (args * skel.CmdArgs ) error {
175
+ conf , err := parseConfig (args .StdinData )
176
+ if err != nil {
177
+ return err
178
+ }
179
+ _ = conf
180
+
181
+ // If this plugins delegates IPAM, ensure that IPAM is also running
182
+ if err := ipam .ExecStatus (conf .IPAM .Type , args .StdinData ); err != nil {
183
+ return err
184
+ }
185
+
186
+ // TODO: implement STATUS here
187
+ // e.g. querying an external deamon, or delegating STATUS to an IPAM plugin
188
+
189
+ return nil
190
+ }
191
+
192
+ // cmdGc implements the GC command, which the runtime uses to indicate
193
+ // the currently valid set of attachments for a given configuration; any
194
+ // resources not owned by these containers may be deleted.
195
+ //
196
+ // The set of valid attachments is provided in the variable 'cni.dev/valid-attachments'.
197
+ // All other attachments should be considered invalid.
198
+ func cmdGc (args * skel.CmdArgs ) error {
199
+ conf , err := parseConfig (args .StdinData )
200
+ if err != nil {
201
+ return err
202
+ }
203
+ _ = conf
204
+
205
+ // If this plugin delegates IPAM, then GC must be passed
206
+ if err := ipam .ExecGC (conf .IPAM .Type , args .StdinData ); err != nil {
207
+ return err
208
+ }
209
+
210
+ // TODO: implement GC here
211
+ // e.g clean up any stale resources, such as iptables rules.
212
+ // You can assume that anything attached to a network namespace is gone.
213
+
214
+ return nil
215
+ }
0 commit comments