From 1566b979e3b27f6f6fece4c114c2d6c4f6d301c8 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Thu, 13 Oct 2016 13:22:12 -0700 Subject: [PATCH] Disable lxc by default --- client/driver/lxc.go | 7 +++++++ client/driver/lxc_test.go | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/client/driver/lxc.go b/client/driver/lxc.go index 41045992e54..e95e379f4f3 100644 --- a/client/driver/lxc.go +++ b/client/driver/lxc.go @@ -26,6 +26,9 @@ import ( ) const ( + // The option that enables this driver in the Config.Options map. + lxcConfigOption = "driver.lxc.enable" + // containerMonitorIntv is the interval at which the driver checks if the // container is still alive containerMonitorIntv = 2 * time.Second @@ -143,6 +146,10 @@ func (d *LxcDriver) Validate(config map[string]interface{}) error { // Fingerprint fingerprints the lxc driver configuration func (d *LxcDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) { + enabled := cfg.ReadBoolDefault(lxcConfigOption, false) + if !enabled { + return false, nil + } version := lxc.Version() if version == "" { return false, nil diff --git a/client/driver/lxc_test.go b/client/driver/lxc_test.go index 519e975305e..a50640c75ac 100644 --- a/client/driver/lxc_test.go +++ b/client/driver/lxc_test.go @@ -33,8 +33,16 @@ func TestLxcDriver_Fingerprint(t *testing.T) { if err != nil { t.Fatalf("err: %v", err) } + if apply { + t.Fatalf("should not apply by default") + } + + apply, err = d.Fingerprint(&config.Config{Options: map[string]string{lxcConfigOption: "1"}}, node) + if err != nil { + t.Fatalf("err: %v", err) + } if !apply { - t.Fatalf("should apply") + t.Fatalf("should apply with config") } if node.Attributes["driver.lxc"] == "" { t.Fatalf("missing driver")