From ba388b6bc6a8d5f822f3a271b7e7b07269d8295a Mon Sep 17 00:00:00 2001 From: niusmallnan Date: Mon, 16 Apr 2018 14:16:08 +0800 Subject: [PATCH] Build docker-sys bridge via system-docker args and remove cni-glue --- assets/docker/cni/bridge.d/bridge.conf | 12 ------ assets/docker/cni/default.d | 1 - assets/docker/hooks/poststop.d/network.json | 7 ---- assets/docker/hooks/prestart.d/network.json | 6 --- .../metadata/cloudstack/metadata.go | 7 +--- config/schema.go | 1 + config/types.go | 1 + main.go | 6 --- netconf/netconf_linux.go | 40 +++++++++++++------ os-config.tpl.yml | 2 +- 10 files changed, 31 insertions(+), 52 deletions(-) delete mode 100644 assets/docker/cni/bridge.d/bridge.conf delete mode 120000 assets/docker/cni/default.d delete mode 100644 assets/docker/hooks/poststop.d/network.json delete mode 100644 assets/docker/hooks/prestart.d/network.json diff --git a/assets/docker/cni/bridge.d/bridge.conf b/assets/docker/cni/bridge.d/bridge.conf deleted file mode 100644 index a090c5e8..00000000 --- a/assets/docker/cni/bridge.d/bridge.conf +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "bridge", - "type": "bridge", - "bridge": "docker-sys", - "isDefaultGateway": true, - "ipMasq": true, - "hairpinMode": true, - "ipam": { - "type": "host-local", - "subnet": "172.18.42.1/16" - } -} diff --git a/assets/docker/cni/default.d b/assets/docker/cni/default.d deleted file mode 120000 index 505083cd..00000000 --- a/assets/docker/cni/default.d +++ /dev/null @@ -1 +0,0 @@ -bridge.d/ \ No newline at end of file diff --git a/assets/docker/hooks/poststop.d/network.json b/assets/docker/hooks/poststop.d/network.json deleted file mode 100644 index b2eae3cf..00000000 --- a/assets/docker/hooks/poststop.d/network.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "path": "/usr/bin/ros", - "args": [ - "cni-glue", - "poststop" - ] -} diff --git a/assets/docker/hooks/prestart.d/network.json b/assets/docker/hooks/prestart.d/network.json deleted file mode 100644 index a38ada87..00000000 --- a/assets/docker/hooks/prestart.d/network.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "path": "/usr/bin/ros", - "args": [ - "cni-glue" - ] -} diff --git a/config/cloudinit/datasource/metadata/cloudstack/metadata.go b/config/cloudinit/datasource/metadata/cloudstack/metadata.go index 3cb38188..d8261ef7 100644 --- a/config/cloudinit/datasource/metadata/cloudstack/metadata.go +++ b/config/cloudinit/datasource/metadata/cloudstack/metadata.go @@ -25,7 +25,6 @@ import ( "github.com/rancher/os/config/cloudinit/datasource/metadata" "github.com/rancher/os/config/cloudinit/pkg" "github.com/rancher/os/log" - "github.com/vishvananda/netlink" ) const ( @@ -44,14 +43,10 @@ func NewDatasource(root string) []*MetadataService { roots := make([]string, 0, 5) if root == "" { - if links, err := netlink.LinkList(); err == nil { + if links, err := netconf.GetValidLinkList(); err == nil { log.Infof("Checking to see if a cloudstack server-identifier is available") for _, link := range links { linkName := link.Attrs().Name - if linkName == "lo" { - continue - } - log.Infof("searching for cloudstack server %s on %s", serverIdentifier, linkName) lease := netconf.GetDhcpLease(linkName) if server, ok := lease[serverIdentifier]; ok { diff --git a/config/schema.go b/config/schema.go index a147fd4d..12a9aa2d 100644 --- a/config/schema.go +++ b/config/schema.go @@ -122,6 +122,7 @@ var schema = `{ "storage_context": {"type": "string"}, "exec": {"type": ["boolean", "null"]}, "bridge": {"type": "string"}, + "bip": {"type": "string"}, "config_file": {"type": "string"}, "containerd": {"type": "string"}, "debug": {"type": ["boolean", "null"]}, diff --git a/config/types.go b/config/types.go index 1b1fc8f6..64c7bb95 100644 --- a/config/types.go +++ b/config/types.go @@ -148,6 +148,7 @@ type UpgradeConfig struct { type EngineOpts struct { Bridge string `yaml:"bridge,omitempty" opt:"bridge"` + BIP string `yaml:"bip,omitempty" opt:"bip"` ConfigFile string `yaml:"config_file,omitempty" opt:"config-file"` Containerd string `yaml:"containerd,omitempty" opt:"containerd"` Debug *bool `yaml:"debug,omitempty" opt:"debug"` diff --git a/main.go b/main.go index bb6496d9..b554de85 100644 --- a/main.go +++ b/main.go @@ -4,11 +4,8 @@ import ( "fmt" "os" - "github.com/containernetworking/cni/plugins/ipam/host-local" - "github.com/containernetworking/cni/plugins/main/bridge" "github.com/docker/docker/docker" "github.com/docker/docker/pkg/reexec" - "github.com/rancher/cniglue" "github.com/rancher/os/cmd/cloudinitexecute" "github.com/rancher/os/cmd/cloudinitsave" "github.com/rancher/os/cmd/control" @@ -35,9 +32,6 @@ var entrypoints = map[string]func(){ "ros-bootstrap": control.BootstrapMain, "ros-sysinit": sysinit.Main, "wait-for-docker": wait.Main, - "cni-glue": glue.Main, - "bridge": bridge.Main, - "host-local": hostlocal.Main, "respawn": respawn.Main, // Power commands diff --git a/netconf/netconf_linux.go b/netconf/netconf_linux.go index 4f240922..651abf22 100644 --- a/netconf/netconf_linux.go +++ b/netconf/netconf_linux.go @@ -66,7 +66,7 @@ func createInterfaces(netCfg *NetworkConfig) { } func createSlaveInterfaces(netCfg *NetworkConfig) { - links, err := netlink.LinkList() + links, err := GetValidLinkList() if err != nil { log.Errorf("Failed to list links: %v", err) return @@ -167,7 +167,7 @@ func ApplyNetworkConfigs(netCfg *NetworkConfig, userSetHostname, userSetDNS bool createInterfaces(netCfg) createSlaveInterfaces(netCfg) - links, err := netlink.LinkList() + links, err := GetValidLinkList() if err != nil { log.Errorf("error getting LinkList: %s", err) return false, err @@ -177,10 +177,7 @@ func ApplyNetworkConfigs(netCfg *NetworkConfig, userSetHostname, userSetDNS bool //apply network config for _, link := range links { - linkName := link.Attrs().Name - if linkName != "lo" { - applyOuter(link, netCfg, &wg, userSetHostname, userSetDNS) - } + applyOuter(link, netCfg, &wg, userSetHostname, userSetDNS) } wg.Wait() @@ -189,13 +186,11 @@ func ApplyNetworkConfigs(netCfg *NetworkConfig, userSetHostname, userSetDNS bool dnsSet := false for _, link := range links { linkName := link.Attrs().Name - if linkName != "lo" { - log.Infof("dns testing %s", linkName) - lease := GetDhcpLease(linkName) - if _, ok := lease["domain_name_servers"]; ok { - log.Infof("dns was dhcp set for %s", linkName) - dnsSet = true - } + log.Infof("dns testing %s", linkName) + lease := GetDhcpLease(linkName) + if _, ok := lease["domain_name_servers"]; ok { + log.Infof("dns was dhcp set for %s", linkName) + dnsSet = true } } @@ -510,3 +505,22 @@ func runCmds(cmds []string, iface string) { } } } + +func GetValidLinkList() ([]netlink.Link, error) { + var validLinkList []netlink.Link + links, err := netlink.LinkList() + if err != nil { + return validLinkList, err + } + + for _, l := range links { + linkName := l.Attrs().Name + if linkName == "lo" || linkName == "docker-sys" { + continue + } + validLinkList = append(validLinkList, l) + } + + return validLinkList, nil + +} diff --git a/os-config.tpl.yml b/os-config.tpl.yml index f6f42ac9..1f7b5018 100644 --- a/os-config.tpl.yml +++ b/os-config.tpl.yml @@ -368,7 +368,7 @@ rancher: system_docker: exec: true storage_driver: overlay2 - bridge: none + bip: 172.18.42.1/16 restart: false graph: /var/lib/system-docker group: root