cb75ecd0e5dcb63eb9ecd330f13bcb2b7016b769
[ovn4nfv-k8s-plugin.git] / ovn4nfvk8s-cni.go
1 package main
2
3 import (
4         "os"
5
6         "github.com/sirupsen/logrus"
7         "github.com/urfave/cli"
8
9         cni "ovn4nfv-k8s-plugin/internal/pkg/cnishim"
10         "ovn4nfv-k8s-plugin/internal/pkg/config"
11
12         "github.com/containernetworking/cni/pkg/skel"
13         "github.com/containernetworking/cni/pkg/types"
14         "github.com/containernetworking/cni/pkg/version"
15         "github.com/containernetworking/plugins/pkg/utils/buildversion"
16 )
17
18 func main() {
19         logrus.Infof("ovn4nfvk8s-cni shim cni")
20         c := cli.NewApp()
21         c.Name = "ovn4nfvk8s-cni"
22         c.Usage = "a CNI plugin to set up or tear down a additional interfaces with OVN"
23         c.Version = "0.1.0"
24         c.Flags = config.Flags
25
26         ep := cni.CNIEndpoint("")
27         c.Action = func(ctx *cli.Context) error {
28                 if _, err := config.InitConfig(ctx); err != nil {
29                         return err
30                 }
31                 skel.PluginMain(
32                         ep.CmdAdd,
33                         ep.CmdCheck,
34                         ep.CmdDel,
35                         version.All,
36                         buildversion.BuildString("ovn4nfv-k8s shim cni"))
37
38                 return nil
39         }
40
41         if err := c.Run(os.Args); err != nil {
42                 // Print the error to stdout in conformance with the CNI spec
43                 e, ok := err.(*types.Error)
44                 if !ok {
45                         e = &types.Error{Code: 100, Msg: err.Error()}
46                 }
47                 e.Print()
48         }
49 }