Skip to content

Commit

Permalink
Merge pull request #1831 from wenwutang1/master
Browse files Browse the repository at this point in the history
support Configure the default bridge network
  • Loading branch information
ks-ci-bot committed May 9, 2023
2 parents f02d7a6 + 8faafb7 commit 62c40eb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/kk/apis/kubekey/v1alpha2/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type RegistryConfig struct {
PrivateRegistry string `yaml:"privateRegistry" json:"privateRegistry,omitempty"`
DataRoot string `yaml:"dataRoot" json:"dataRoot,omitempty"`
NamespaceOverride string `yaml:"namespaceOverride" json:"namespaceOverride,omitempty"`
BridgeIP string `yaml:"bridgeIP" json:"bridgeIP,omitempty"`
Auths runtime.RawExtension `yaml:"auths" json:"auths,omitempty"`
}

Expand Down
1 change: 1 addition & 0 deletions cmd/kk/pkg/container/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func InstallDocker(m *InstallContainerModule) []task.Interface {
"Mirrors": templates.Mirrors(m.KubeConf),
"InsecureRegistries": templates.InsecureRegistries(m.KubeConf),
"DataRoot": templates.DataRoot(m.KubeConf),
"BridgeIP": templates.BridgeIP(m.KubeConf),
},
},
Parallel: true,
Expand Down
28 changes: 28 additions & 0 deletions cmd/kk/pkg/container/templates/docker_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package templates

import (
"fmt"
"net"
"strings"
"text/template"

Expand All @@ -41,6 +42,9 @@ var DockerConfig = template.Must(template.New("daemon.json").Parse(
{{- if .InsecureRegistries }}
"insecure-registries": [{{ .InsecureRegistries }}],
{{- end}}
{{- if .BridgeIP }}
"bip": {{ .BridgeIP }},
{{- end}}
"exec-opts": ["native.cgroupdriver=systemd"]
}
`)))
Expand Down Expand Up @@ -76,3 +80,27 @@ func DataRoot(kubeConf *common.KubeConf) string {
}
return dataRoot
}

func BridgeIP(kubeConf *common.KubeConf) string {
var bip string
if kubeConf.Cluster.Registry.BridgeIP != "" {
bip = "172.17.0.1/16"
_, cidr, err := net.ParseCIDR(kubeConf.Cluster.Registry.BridgeIP)
if err != nil {
return bip
}
ip4 := cidr.IP.To4()
if ip4 == nil {
return bip
}
bridge0 := net.IPv4(ip4[0], ip4[1], ip4[2], ip4[3]+1)
if !cidr.Contains(bridge0) {
return bip
}
ones, _ := cidr.Mask.Size()

bip = fmt.Sprintf("\"%s/%d\"", bridge0.String(), ones)
}

return bip
}

0 comments on commit 62c40eb

Please sign in to comment.