Skip to content

Commit 7f6b5bd

Browse files
abstract vmnet's default domain name
Signed-off-by: António Meireles <antonio.meireles@reformi.st>
1 parent 941b0cb commit 7f6b5bd

4 files changed

Lines changed: 40 additions & 31 deletions

File tree

‎components/server/httpservices.go‎

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package server
1717

1818
import (
1919
"encoding/json"
20+
"fmt"
2021
"io/ioutil"
2122
"net"
2223
"net/http"
@@ -93,33 +94,38 @@ func httpInstanceCloudConfig(w http.ResponseWriter, r *http.Request) {
9394

9495
func reversedIPaddress(ip string) string {
9596
const IPv4prefix = "in-addr.arpa"
96-
var d string
97-
addr := net.ParseIP(ip)
9897

99-
ip4addr := addr.To4()
98+
ip4addr := net.ParseIP(ip).To4()
10099
domain := make([]byte, 0, len(ip4addr)*4+len(IPv4prefix))
100+
101101
for x := len(ip4addr) - 1; x >= 0; x-- {
102102
domain = strconv.AppendUint(domain, uint64(ip4addr[x]), 10)
103103
domain = append(domain, '.')
104104
}
105105
domain = append(domain, IPv4prefix...)
106-
y := strings.Split(string(domain), ".")
107-
for x := len(y) - 1; x >= 0; x-- {
108-
d += y[x] + "/"
106+
107+
return invertDomain(string(domain))
108+
}
109+
110+
func invertDomain(in string) (out string) {
111+
s := strings.Split(in, ".")
112+
for x := len(s) - 1; x >= 0; x-- {
113+
out += s[x] + "/"
109114
}
110-
d = strings.TrimSuffix(d, "/")
111-
return string(d)
115+
out = strings.TrimSuffix(out, "/")
116+
return
112117
}
113118

114119
func skyWrite(hostName string, ip string) (err error) {
115-
path := "/skydns/local/coreos/" + strings.Replace(hostName, ".", "/", -1)
120+
path := fmt.Sprintf("/skydns/%s/%s", invertDomain(coreos.LocalDomainName),
121+
strings.Replace(hostName, ".", "/", -1))
116122

117123
if _, err = Daemon.DataStore.Set(context.Background(), path,
118124
"{\"host\":\""+ip+"\"}", nil); err != nil {
119125
return
120126
}
121127
// reverse
122-
hostName = hostName + ".coreos.local"
128+
hostName = hostName + "." + coreos.LocalDomainName
123129
_, err = Daemon.DataStore.Set(context.Background(),
124130
"/skydns/"+reversedIPaddress(ip), "{\"host\":\""+hostName+"\"}", nil)
125131
return
@@ -135,13 +141,14 @@ func isPortOpen(t string, target string) bool {
135141
}
136142

137143
func skyWipe(hostName string, ip string) (err error) {
138-
path := "/skydns/local/coreos/" + strings.Replace(hostName, ".", "/", -1)
144+
path := fmt.Sprintf("/skydns/%s/%s", invertDomain(coreos.LocalDomainName),
145+
strings.Replace(hostName, ".", "/", -1))
139146
if _, err =
140147
Daemon.DataStore.Delete(context.Background(), path, nil); err != nil {
141148
return
142149
}
143150
// reverse
144-
hostName = hostName + ".coreos.local"
151+
hostName = hostName + "." + coreos.LocalDomainName
145152
_, err = Daemon.DataStore.Delete(context.Background(),
146153
"/skydns/"+reversedIPaddress(ip), nil)
147154
return

‎components/server/rpcservices.go‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,6 @@ func (s *RPCservice) Run(r *http.Request,
245245
vm.exec.Wait()
246246
vm.deregister()
247247
os.Remove(vm.TTY())
248-
// give it time to flush logs
249-
time.Sleep(3 * time.Second)
250248
}()
251249

252250
select {
@@ -301,7 +299,7 @@ func (s *RPCservice) StopVMs(r *http.Request,
301299
Daemon.Active[v].halt()
302300
for {
303301
Daemon.Lock()
304-
_, stillAlive := Daemon.Active[v]
302+
stillAlive := Daemon.Active[v].exec.ProcessState.Exited()
305303
Daemon.Unlock()
306304
if !stillAlive {
307305
break

‎components/server/server.go‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"golang.org/x/net/context"
3030

3131
"github.com/TheNewNormal/corectl/components/host/session"
32+
"github.com/TheNewNormal/corectl/components/target/coreos"
3233
"github.com/TheNewNormal/corectl/release"
3334
"github.com/blang/semver"
3435
"github.com/braintree/manners"
@@ -78,7 +79,7 @@ func Start() (err error) {
7879

7980
etcd := exec.Command(path.Join(session.ExecutableFolder(), "corectld.store"),
8081
"-data-dir="+session.Caller.EtcDir(),
81-
"-name=corectld.coreos.local",
82+
"-name=corectld."+coreos.LocalDomainName,
8283
"--listen-client-urls=http://0.0.0.0:2379,http://0.0.0.0:4001",
8384
"--advertise-client-urls=http://0.0.0.0:2379,http://0.0.0.0:4001")
8485
if log.IsDebugging {
@@ -107,7 +108,7 @@ func Start() (err error) {
107108
}
108109

109110
defer func() {
110-
if err = etcd.Process.Signal(syscall.SIGINT); err != nil {
111+
if err = etcd.Process.Signal(syscall.SIGTERM); err != nil {
111112
log.Err(err.Error())
112113
}
113114
}()
@@ -126,7 +127,7 @@ func Start() (err error) {
126127
&client.DeleteOptions{Dir: true, Recursive: true})
127128

128129
dnsArgs := []string{"-nameservers=8.8.8.8:53,8.8.4.4:53",
129-
"-domain=coreos.local",
130+
"-domain=" + coreos.LocalDomainName,
130131
"-addr=0.0.0.0:53"}
131132
if log.IsDebugging {
132133
dnsArgs = append(dnsArgs, "-verbose")
@@ -143,7 +144,7 @@ func Start() (err error) {
143144
skyWrite("corectld", session.Caller.Network.Address)
144145
defer func() {
145146
skyWipe("corectld", session.Caller.Network.Address)
146-
if err = skydns.Process.Signal(syscall.SIGINT); err != nil {
147+
if err = skydns.Process.Signal(syscall.SIGTERM); err != nil {
147148
log.Err(err.Error())
148149
}
149150
}()

‎components/target/coreos/coreos.go‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,25 @@ import (
2121
"github.com/TheNewNormal/corectl/components/common/assets"
2222
)
2323

24-
const latestImageBreackage = "2016-07-06T00:00:00WET"
25-
26-
func LatestImageBreackage() (t time.Time) {
27-
t, _ = time.Parse("2006-01-02T15:04:05MST", latestImageBreackage)
28-
return
29-
}
30-
31-
// CoreOS default Channels
32-
var Channels = []string{"alpha", "beta", "stable"}
33-
34-
const defaultChannel = "alpha"
35-
const defaultVersion = "latest"
24+
const (
25+
latestImageBreackage = "2016-07-06T00:00:00WET"
26+
defaultChannel = "alpha"
27+
defaultVersion = "latest"
28+
)
3629

3730
var (
31+
// CoreOS default Channels
32+
Channels = []string{"alpha", "beta", "stable"}
33+
3834
GPGLongID = "50E0885593D2DCB4"
3935
GPGKey = assets.Contents("target/coreos/CoreOSkey.public")
4036
CoreOEMsharedHomedir = assets.Contents("target/coreos/homedir.yml.tmpl")
4137
CoreOSIgnitionTmpl = assets.Contents("target/coreos/corectl.ignition.yml.tmpl")
38+
39+
LocalDomainName = "coreos.local"
4240
)
41+
42+
func LatestImageBreackage() (t time.Time) {
43+
t, _ = time.Parse("2006-01-02T15:04:05MST", latestImageBreackage)
44+
return
45+
}

0 commit comments

Comments
 (0)
⌂ 换网址