Skip to content

Commit

Permalink
fix build, and make ip address dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
KnicKnic committed Jul 28, 2020
1 parent 8d7a486 commit 09dce8c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
8 changes: 7 additions & 1 deletion instructions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ nameserver 8.8.8.8
""" > /etc/resolv.conf

#add paths, #note k3s is where my host-local files are
$env:KUBECONFIG="C:\tmp\k3s\server\cred\admin.kubeconfig"
# $env:KUBECONFIG="C:\tmp\k3s\server\cred\admin.kubeconfig"
$env:KUBECONFIG="C:\Users\Administrator\.kube\k3s.yaml"
$env:Path +=";C:\Users\Administrator\go\src\github.com\rancher\k3s"
$env:Path +=";C:\tmp"

#optional resolve-conf --resolv-conf C:\etc\resolv.conf

$hostNetwork = get-NetIPAddress -InterfaceAlias "vEthernet (Ethernet)"| ?{$_.AddressFamily -eq "IPv4"}
$env:hostIp = $hostNetwork.IpAddress
$env:hostCidr = "{0}/{1}" -f $hostNetwork.IpAddress, $hostNetwork.PrefixLength

#for host-gw
#eventually need to get rid of KUBE_NETWORK
$env:KUBE_NETWORK="cbr0"
Expand Down Expand Up @@ -54,4 +59,5 @@ ipmo C:\etc\rancher\node\hns.psm1
Get-HNSEndpoint | Remove-HNSEndpoint
Get-HNSNetwork | ? Name -Like "cbr0" | Remove-HNSNetwork
Get-HNSNetwork | ? Name -Like "vxlan0" | Remove-HNSNetwork
# Get-HnsNetwork |?{$_.name -eq "External"} |Remove-HnsNetwork
Get-HnsPolicyList | Remove-HnsPolicyList
5 changes: 0 additions & 5 deletions pkg/agent/flannel/hns_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,11 +607,6 @@ func resetHnsNetwork(scriptDirectory string) {
_ = run("ipmo " + hnsLocation + `; Reset-HNSNetwork`)
}

func resetHnsNetwork(scriptDirectory string) {
hnsLocation := saveHnsScript(scriptDirectory)
_ = run("ipmo " + hnsLocation + `; Reset-HNSNetwork`)
}

func run(command string) string {
logrus.Info(command)
cmd := exec.Command("powershell", "-Command", command)
Expand Down
28 changes: 26 additions & 2 deletions pkg/agent/flannel/setup_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package flannel
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -171,10 +172,33 @@ func createCNIConf(nodeConfig *config.Node) error {
return fmt.Errorf("Cannot configure unknown flannel backend '%s'", nodeConfig.FlannelBackend)
}
confJSON := strings.Replace(cniConf, "%CLUSTERCIDR%", nodeConfig.AgentConfig.ClusterCIDR.String(), -1)

// ideally I should not be lazy and query hostCidr & ip
// flannelIface := "Ethernet"
// if nodeConfig.FlannelIface != nil {
// if nodeConfig.FlannelIface.Name != "" {
// flannelIface = nodeConfig.FlannelIface.Name
// }
// }
// hostCidr := getHostCidr(nodeConfig.AgentConfig.NodeConfigPath, flannelIface)
// hostIp := getHostIp(nodeConfig.AgentConfig.NodeConfigPath, flannelIface)

// lets default them to some random computer, and load them with environment variables
hostCidr := "10.231.120.177/24"
if os.Getenv("hostCidr") != "" {
hostCidr = os.Getenv("hostCidr")
}

hostIp := "10.231.120.177"
if os.Getenv("hostIp") != "" {
hostIp = os.Getenv("hostIp")
}
// ideally I should write this function, lets be lazy ...

// TODO: figure out how to fetch service cidr
confJSON = strings.Replace(confJSON, "%SERVICECIDR%", "10.43.0.0/16", -1)
confJSON = strings.Replace(confJSON, "%HOSTCIDR%", "10.231.120.177/24", -1)
confJSON = strings.Replace(confJSON, "%HOSTIPCIDR%", "10.231.120.177/32", -1)
confJSON = strings.Replace(confJSON, "%HOSTCIDR%", hostCidr, -1)
confJSON = strings.Replace(confJSON, "%HOSTIPCIDR%", hostIp+"/32", -1)

return util.WriteFile(p, confJSON)
}
Expand Down

0 comments on commit 09dce8c

Please sign in to comment.