Skip to content

Commit

Permalink
dogswatch: Update logging, climits, list update.
Browse files Browse the repository at this point in the history
* Add logging to command execution.
* Increase, temporarily, memory of running pod.
* Update ListUpdate logic.
  • Loading branch information
patraw committed Nov 14, 2019
1 parent 7e86d64 commit c8c4a0f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 9 deletions.
4 changes: 2 additions & 2 deletions extras/dogswatch/dev/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ spec:
privileged: true
resources:
limits:
memory: 200Mi
memory: 600Mi
requests:
cpu: 100m
memory: 200Mi
memory: 600Mi
volumeMounts:
- name: rootfs
mountPath: /.thar/rootfs
Expand Down
64 changes: 57 additions & 7 deletions extras/dogswatch/pkg/platform/updog/updog.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package updog

import (
"bufio"
"bytes"
"os"
"os/exec"
"path/filepath"

"github.com/amazonlinux/thar/dogswatch/pkg/logging"
"github.com/amazonlinux/thar/dogswatch/pkg/thar"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

var (
Expand All @@ -31,20 +35,56 @@ type executable struct{}

func (e *executable) runOk(cmd *exec.Cmd) (bool, error) {
cmd.SysProcAttr = thar.ProcessAttrs()
// TODO: pipe out the updog stderr to debug logger

var buf bytes.Buffer
writer := bufio.NewWriter(&buf)
cmd.Stdout = writer
cmd.Stderr = writer

if logging.Debuggable {
logging.New("updog").WithFields(logrus.Fields{
"cmd": cmd.String(),
}).Debug("Executing")
}

if err := cmd.Start(); err != nil {
if logging.Debuggable {
logging.New("updog").WithFields(logrus.Fields{
"cmd": cmd.String(),
"output": buf.String(),
}).WithError(err).Error("Failed to start command")
}
return false, err
}
err := cmd.Wait()
return err == nil, err
if err != nil {
if logging.Debuggable {
logging.New("updog").WithFields(logrus.Fields{
"cmd": cmd.String(),
"output": buf.String(),
}).WithError(err).Error("Command errored durring run")
}
return false, err
}
if logging.Debuggable {
logging.New("updog").WithFields(logrus.Fields{
"cmd": cmd.String(),
"output": buf.String(),
}).Debug("Command completed successfully")
}
// Boolean currently only used by ListUpdate. Returns true if the
// command yielded output, which indicates an update is available.
// TODO: Update this when an interface is defined between updog
// and dogswatch.
return len(buf.String()) > 0, err
}

func (e *executable) CheckUpdate() (bool, error) {
return e.runOk(exec.Command(updogBin, "check-update"))
}

func (e *executable) Update() error {
_, err := e.runOk(exec.Command(updogBin, "update"))
_, err := e.runOk(exec.Command(updogBin, "update-apply", "-r"))
return err
}

Expand Down Expand Up @@ -80,15 +120,25 @@ func (u *updog) Status() (*statusResponse, error) {
}

func (u *updog) ListAvailable() (*listAvailableResponse, error) {
if _, err := u.Bin.CheckUpdate(); err != nil {
if avail, err := u.Bin.CheckUpdate(); err != nil {
return nil, err
} else {
if avail {
return &listAvailableResponse{
// TODO: deserialize output from updog and plumb version IDs
ReportedUpdates: []*availableUpdate{&availableUpdate{ID: "POSITIVE_STUB_INDICATOR"}},
}, nil
} else {
return &listAvailableResponse{}, nil
}
}
return &listAvailableResponse{}, nil
}

func (u *updog) PrepareUpdate(id UpdateID) (*prepareUpdateResponse, error) {
// TODO: extend updog for prepare steps
return &prepareUpdateResponse{}, nil
// TODO: extend updog for prepare steps.
return &prepareUpdateResponse{
ID: "POSITIVE_STUB_INDICATOR",
}, nil
}

func (u *updog) ApplyUpdate(id UpdateID) (*applyUpdateResponse, error) {
Expand Down

0 comments on commit c8c4a0f

Please sign in to comment.