Revert CNI auto-download (#6095)

Revert CNI auto-download
This commit is contained in:
Nick Ethier
2019-08-08 15:26:49 -04:00
committed by GitHub
5 changed files with 0 additions and 116 deletions

View File

@@ -354,18 +354,6 @@ func NewClient(cfg *config.Config, consulCatalog consul.CatalogAPI, consulServic
c.configCopy = c.config.Copy()
c.configLock.Unlock()
// Auto download CNI binaries and configure CNI_PATH if requested.
if c.config.AutoFetchCNI {
if cniPath := FetchCNIPlugins(c.logger, c.config.AutoFetchCNIURL, c.config.AutoFetchCNIDir); cniPath != "" {
if c.config.CNIPath == "" {
c.config.CNIPath = cniPath
} else {
c.config.CNIPath = c.config.CNIPath + ":" + cniPath
}
c.logger.Debug("using new CNI Path", "cni_path", c.config.CNIPath)
}
}
fingerprintManager := NewFingerprintManager(
c.configCopy.PluginSingletonLoader, c.GetConfig, c.configCopy.Node,
c.shutdownCh, c.updateNodeFromFingerprint, c.logger)
@@ -568,35 +556,6 @@ func (c *Client) init() error {
}
c.logger.Info("using alloc directory", "alloc_dir", c.config.AllocDir)
// Ensure the cnibin dir exists if we have one
if c.config.AutoFetchCNIDir != "" {
if err := os.MkdirAll(c.config.AutoFetchCNIDir, 0755); err != nil {
return fmt.Errorf("failed to create directory for AutoFetchCNIDir: %s", err)
}
} else {
// Otherwise make a temp directory to use.
p, err := ioutil.TempDir("", "NomadClient")
if err != nil {
return fmt.Errorf("failed creating temporary directory for the AutoFetchCNIDir: %v", err)
}
p, err = filepath.EvalSymlinks(p)
if err != nil {
return fmt.Errorf("failed to find temporary directory for the AutoFetchCNIDir: %v", err)
}
// Change the permissions to have the execute bit
if err := os.Chmod(p, 0755); err != nil {
return fmt.Errorf("failed to change directory permissions for the AutoFetchCNIdir: %v", err)
}
c.config.AutoFetchCNIDir = p
}
if c.config.AutoFetchCNI {
c.logger.Info("using cni directory for plugin downloads", "cni_dir", c.config.AutoFetchCNIDir)
}
return nil
}

View File

@@ -1,48 +0,0 @@
package client
import (
"fmt"
"path/filepath"
"runtime"
getter "github.com/hashicorp/go-getter"
hclog "github.com/hashicorp/go-hclog"
)
const (
nomadCNIBinDir = "cnibin"
)
var (
// checksums are copied from https://github.com/containernetworking/plugins/releases
defaultCNIGetterChecksums = map[string]string{
"linux-amd64": "sha256:e9bfc78acd3ae71be77eb8f3e890cc9078a33cc3797703b8ff2fc3077a232252",
"linux-arm": "sha256:ae6ddbd87c05a79aceb92e1c8c32d11e302f6fc55045f87f6a3ea7e0268b2fda",
"linux-arm64": "sha256:acde854e3def3c776c532ae521c19d8784534918cc56449ff16945a2909bff6d",
"windows-amd64": "sha256:a8a24e9cf93f4db92321afca3fe53bd3ccdf2b7117c403c55a5bac162d8d79cc",
}
defaultCNIPluginVersion = "0.8.1"
defaultCNIGetterSrc = fmt.Sprintf("https://github.com/containernetworking/plugins/releases/download/v%s/cni-plugins-%s-%s-v%s.tgz?checksum=%s",
defaultCNIPluginVersion, runtime.GOOS, runtime.GOARCH, defaultCNIPluginVersion,
defaultCNIGetterChecksums[runtime.GOOS+"-"+runtime.GOARCH])
)
// FetchCNIPlugins downloads the standard set of CNI plugins to the client's
// data directory and returns the path to be used when setting up the CNI_PATH
// environment variable. If an error occures during download, it is logged and
// an empty path is returned
func FetchCNIPlugins(logger hclog.Logger, src string, dataDir string) string {
if src == "" {
src = defaultCNIGetterSrc
}
logger.Info("downloading CNI plugins", "url", src)
dst := filepath.Join(dataDir, nomadCNIBinDir)
if err := getter.Get(dst, src); err != nil {
logger.Warn("failed to fetch CNI plugins", "url", src, "error", err)
return ""
}
return dst
}

View File

@@ -234,18 +234,6 @@ type Config struct {
// for allocations in bridge networking mode. Subnet must be in CIDR
// notation
BridgeNetworkAllocSubnet string
// AutoFetchCNI is a toggle to enable auto downloading of the CNI standard
// plugins managed by the CNI team. This defaults to false
AutoFetchCNI bool
// AutoFetchCNIURL is the go-getter URL to use when auto downloading CNI
// plugins
AutoFetchCNIURL string
// AutoFetchCNIDir is the destination dir to use when auto doanloading CNI plugins.
// This directory will be appended to the CNIPath so it is searched last
AutoFetchCNIDir string
}
func (c *Config) Copy() *Config {
@@ -280,7 +268,6 @@ func DefaultConfig() *Config {
DisableRemoteExec: false,
BackwardsCompatibleMetrics: false,
RPCHoldTimeout: 5 * time.Second,
AutoFetchCNI: false,
}
}

View File

@@ -437,7 +437,6 @@ func convertClientConfig(agentConfig *Config) (*clientconfig.Config, error) {
if agentConfig.DataDir != "" {
conf.StateDir = filepath.Join(agentConfig.DataDir, "client")
conf.AllocDir = filepath.Join(agentConfig.DataDir, "alloc")
conf.AutoFetchCNIDir = filepath.Join(agentConfig.DataDir, "cnibin")
}
if agentConfig.Client.StateDir != "" {
conf.StateDir = agentConfig.Client.StateDir
@@ -543,8 +542,6 @@ func convertClientConfig(agentConfig *Config) (*clientconfig.Config, error) {
conf.CNIPath = agentConfig.Client.CNIPath
conf.BridgeNetworkName = agentConfig.Client.BridgeNetworkName
conf.BridgeNetworkAllocSubnet = agentConfig.Client.BridgeNetworkSubnet
conf.AutoFetchCNI = agentConfig.Client.AutoFetchCNIPlugins
conf.AutoFetchCNIURL = agentConfig.Client.AutoFetchCNIPluginsURL
return conf, nil
}

View File

@@ -260,16 +260,6 @@ type ClientConfig struct {
// creating allocations with bridge networking mode. This range is local to
// the host
BridgeNetworkSubnet string `hcl:"bridge_network_subnet"`
// AutoFetchCNIPlugins toggles if the Nomad client should attempt to
// automatically download a standard set of CNI plugins, typically from
// the community repo https://github.com/containernetworking/plugins/releases
AutoFetchCNIPlugins bool `hcl:"auto_fetch_cni_plugins"`
// AutoFetchCNIPluginsURL sets the source URL to be used if automatically
// downloading CNI plugins. If not set will use a known working version from
// the community repo https://github.com/containernetworking/plugins/releases
AutoFetchCNIPluginsURL string `hcl:"auto_fetch_cni_plugins_url"`
}
// ACLConfig is configuration specific to the ACL system
@@ -684,7 +674,6 @@ func DevConfig() *Config {
conf.Telemetry.PrometheusMetrics = true
conf.Telemetry.PublishAllocationMetrics = true
conf.Telemetry.PublishNodeMetrics = true
conf.Client.AutoFetchCNIPlugins = true
return conf
}