Skip to content

Commit

Permalink
⚙️ Setup DNS with cloud init
Browse files Browse the repository at this point in the history
  • Loading branch information
mudler committed May 6, 2022
1 parent 034de60 commit 9ac5efa
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 15 deletions.
11 changes: 11 additions & 0 deletions cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package config

import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"

yip "github.com/mudler/yip/pkg/schema"

"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -140,3 +143,11 @@ func ReplaceToken(dir []string, token string) (err error) {

return ioutil.WriteFile(configFile, d, perms)
}

func SaveCloudConfig(name string, yc yip.YipConfig) error {
dnsYAML, err := yaml.Marshal(yc)
if err != nil {
return err
}
return ioutil.WriteFile(filepath.Join("oem", fmt.Sprintf("100_%s.yaml", name)), dnsYAML, 0700)
}
10 changes: 8 additions & 2 deletions cli/vpn/setup.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vpn

import (
"fmt"
"os"
"path/filepath"
"strings"
Expand All @@ -9,6 +10,7 @@ import (
"github.com/c3os-io/c3os/cli/machine"
"github.com/c3os-io/c3os/cli/machine/systemd"
"github.com/c3os-io/c3os/cli/utils"
yip "github.com/mudler/yip/pkg/schema"
)

func Setup(instance, apiAddress, rootDir string, start bool, c *config.Config) error {
Expand Down Expand Up @@ -36,8 +38,6 @@ func Setup(instance, apiAddress, rootDir string, start bool, c *config.Config) e
if c.C3OS.DNS {
vpnOpts["DNSADDRESS"] = "127.0.0.1:53"
vpnOpts["DNSFORWARD"] = "true"
// TODO: Currently DNS set up is supported only on opensuse,
// Extend this to other flavors too.
if !utils.IsOpenRCBased() {
if _, err := os.Stat("/etc/sysconfig/network/config"); err == nil {
utils.WriteEnv("/etc/sysconfig/network/config", map[string]string{
Expand All @@ -52,6 +52,12 @@ func Setup(instance, apiAddress, rootDir string, start bool, c *config.Config) e
}
}
}
if err := config.SaveCloudConfig("dns", yip.YipConfig{
Name: "DNS Configuration",
Stages: map[string][]yip.Stage{"network": {{Dns: yip.DNS{Nameservers: []string{"127.0.0.1"}}}}},
}); err != nil {
fmt.Println("Failed installing DNS")
}
}

os.MkdirAll("/etc/systemd/system.conf.d/", 0600)
Expand Down
12 changes: 9 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ require (
github.com/bramvdbogaerde/go-scp v1.2.0
github.com/creack/pty v1.1.19-0.20220421211855-0d412c9fbeb1
github.com/denisbrodbeck/machineid v1.0.1
github.com/gliderlabs/ssh v0.1.1
github.com/gliderlabs/ssh v0.2.2
github.com/google/go-github/v40 v40.0.0
github.com/ipfs/go-log v1.0.5
github.com/joho/godotenv v1.4.0
github.com/mudler/edgevpn v0.14.3
github.com/mudler/go-nodepair v0.0.0-20220223175428-76dad7d611c6
github.com/mudler/yip v0.0.0-20220321143540-2617d71ea02a
github.com/onsi/ginkgo/v2 v2.1.3
github.com/onsi/gomega v1.17.0
github.com/onsi/gomega v1.18.0
github.com/pterm/pterm v0.12.36
github.com/qeesung/image2ascii v1.0.1
github.com/urfave/cli v1.22.5
Expand All @@ -35,6 +36,7 @@ require (
github.com/cheekybits/genny v1.0.0 // indirect
github.com/containerd/cgroups v1.0.3 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/coreos/yaml v0.0.0-20141224210557-6b16a5714269 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/disintegration/imaging v1.6.2 // indirect
Expand All @@ -52,12 +54,12 @@ require (
github.com/google/btree v1.0.1 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gookit/color v1.5.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-version v1.4.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/ipfs/go-cid v0.1.0 // indirect
Expand All @@ -66,6 +68,8 @@ require (
github.com/ipfs/go-ipns v0.1.2 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/ipld/go-ipld-prime v0.14.4 // indirect
github.com/itchyny/gojq v0.12.2 // indirect
github.com/itchyny/timefmt-go v0.1.2 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
Expand Down Expand Up @@ -157,6 +161,7 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.33.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rancher-sandbox/cloud-init v1.14.3-0.20210913085759-bf90bf5eb77e // indirect
github.com/raulk/clock v1.1.0 // indirect
github.com/raulk/go-watchdog v1.2.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
Expand All @@ -166,6 +171,7 @@ require (
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 // indirect
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/twpayne/go-vfs v1.5.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
github.com/vishvananda/netlink v1.1.0 // indirect
Expand Down
Loading

0 comments on commit 9ac5efa

Please sign in to comment.