Skip to content

Commit

Permalink
add logs (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwinger233 authored Feb 24, 2022
1 parent b8a71b4 commit acd1169
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
22 changes: 17 additions & 5 deletions app/cnicmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,34 @@ import (
"github.com/projecteru2/docker-cni/cni"
"github.com/projecteru2/docker-cni/config"
"github.com/projecteru2/docker-cni/handler"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)

func runCNI(handler handler.Handler) func(*cli.Context) error {
return func(c *cli.Context) (err error) {
stateBuf, err := ioutil.ReadAll(os.Stdin)
defer func() {
if err != nil {
log.Errorf("[hook] failed to preceed: %+v", err)
}
}()

conf, err := config.LoadConfig(c.String("config"))
if err != nil {
return errors.WithStack(err)
}
var state specs.State
if err = json.Unmarshal(stateBuf, &state); err != nil {

if err = conf.SetupLog(); err != nil {
return errors.WithStack(err)
}

conf, err := config.LoadConfig(c.String("config"))
stateBuf, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return
return errors.WithStack(err)
}
var state specs.State
if err = json.Unmarshal(stateBuf, &state); err != nil {
return errors.WithStack(err)
}

cniFilename, cniConfigFilename, err := cni.FindCNI(conf.CNIConfDir, conf.CNIBinDir)
Expand Down Expand Up @@ -79,6 +90,7 @@ func runCNI(handler handler.Handler) func(*cli.Context) error {
return errors.WithStack(err)
}

log.Infof("[hook] cni running: %+v %s", strings.Join(env, " "), cniFilename)
return errors.WithStack(syscall.Exec(cniFilename, []string{cniFilename}, env))
}
}
13 changes: 7 additions & 6 deletions app/ocicmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ import (

func runOCI(handler handler.Handler) func(*cli.Context) error {
return func(c *cli.Context) (err error) {
defer func() {
if err != nil {
log.Errorf("[oci] failed to preceed: %+v", err)
}
}()

configPath, ociArgs := c.String("config"), c.Args().Slice()

conf, err := setup(configPath, ociArgs)
if err != nil {
log.Errorf("failed to setup: %+v", err)
return
}

log.Infof("docker-cni running: %+v", os.Args)
defer func() {
log.Infof("docker-cni finishing: %+v", err)
}()
log.Infof("[oci] docker-cni running: %+v", os.Args)

containerMeta, err := oci.LoadContainerMeta(conf.OCISpecFilename)
if err != nil {
Expand Down Expand Up @@ -72,6 +74,5 @@ func setup(configPath string, ociArgs []string) (conf config.Config, err error)
return
}

log.Debugf("config: %+v", conf)
return conf, conf.Validate()
}
4 changes: 3 additions & 1 deletion handler/cni/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ func (h *CNIHandler) AddCNIStartHook(conf config.Config, containerMeta *oci.Cont
if containerMeta.RequiresSpecificIP() {
cniArgs = append(cniArgs, "IP="+containerMeta.SpecificIP())
}
env = append(env, "CNI_ARGS="+strings.Join(cniArgs, ";"))
if len(cniArgs) != 0 {
env = append(env, "CNI_ARGS="+strings.Join(cniArgs, ";"))
}
containerMeta.AppendHook("prestart",
conf.BinPathname,
[]string{conf.BinPathname, "cni", "--config", conf.Filename, "--command", "add"}, // args
Expand Down

0 comments on commit acd1169

Please sign in to comment.