Skip to content

Commit

Permalink
cilium: Fix agent configuration API
Browse files Browse the repository at this point in the history
Fixes two issues:
 - Multiple PATCH /config API calls were issued
 - CLI was not checking response for disabled/false

Signed-off-by:  <thomas@cilium.io>
  • Loading branch information
tgraf committed Mar 17, 2017
1 parent e4fab2c commit dc53ba4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
24 changes: 11 additions & 13 deletions cilium/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"fmt"
"os"
"sort"
"strings"

"github.com/cilium/cilium/api/v1/models"
"github.com/cilium/cilium/common"
"github.com/cilium/cilium/daemon/options"
"github.com/cilium/cilium/pkg/option"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -56,22 +56,21 @@ func dumpConfig(Opts map[string]string) {
sort.Strings(opts)

for _, k := range opts {
text := common.Green("Enabled")

if Opts[k] == "" || strings.ToLower(Opts[k]) == "disabled" {
text = common.Red("Disabled")
if enabled, err := option.NormalizeBool(Opts[k]); err != nil {
Fatalf("Invalid option answer %s: %s", Opts[k], err)
} else if enabled {
fmt.Printf("%-24s %s\n", k, common.Green("Enabled"))
} else {
fmt.Printf("%-24s %s\n", k, common.Red("Disabled"))
}

fmt.Printf("%-24s %s\n", k, text)
}
}

func configDaemon(cmd *cobra.Command, opts []string) {
if len(opts) == 0 {
resp, err := client.ConfigGet()
if err != nil {
fmt.Fprintf(os.Stderr, "Error while retrieving configuration: %s", err)
os.Exit(1)
Fatalf("Error while retrieving configuration: %s", err)
}

dumpConfig(resp.Configuration.Immutable)
Expand All @@ -93,10 +92,9 @@ func configDaemon(cmd *cobra.Command, opts []string) {
} else {
dOpts[name] = "Disabled"
}
}

if err = client.ConfigPatch(dOpts); err != nil {
fmt.Fprintf(os.Stderr, "Unable to set daemon configuration: %s\n", err)
os.Exit(1)
}
if err := client.ConfigPatch(dOpts); err != nil {
Fatalf("Unable to change agent configuration: %s\n", err)
}
}
6 changes: 5 additions & 1 deletion daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,9 @@ func NewPatchConfigHandler(d *Daemon) PatchConfigHandler {
}

func (h *patchConfig) Handle(params PatchConfigParams) middleware.Responder {
d := h.daemon
log.Debugf("PATCH /config request: %+v", params)

d := h.daemon
d.conf.OptsMU.Lock()
defer d.conf.OptsMU.Unlock()

Expand All @@ -586,6 +587,7 @@ func (h *patchConfig) Handle(params PatchConfigParams) middleware.Responder {
}

changes := d.conf.Opts.Apply(params.Configuration, changedOption, d)
log.Debugf("Applied %d changes", changes)
if changes > 0 {
if err := d.compileBase(); err != nil {
msg := fmt.Errorf("Unable to recompile base programs: %s\n", err)
Expand Down Expand Up @@ -623,6 +625,8 @@ func NewGetConfigHandler(d *Daemon) GetConfigHandler {
}

func (h *getConfig) Handle(params GetConfigParams) middleware.Responder {
log.Debugf("GET /config request: %+v", params)

d := h.daemon
d.conf.OptsMU.RLock()
defer d.conf.OptsMU.RUnlock()
Expand Down

0 comments on commit dc53ba4

Please sign in to comment.