mirror of
https://github.com/clearlinux/rkt.git
synced 2026-11-25 05:22:53 +00:00
*: move rktpath/metadata into single "common" pkg
This commit is contained in:
@@ -12,14 +12,12 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package path
|
||||
|
||||
//
|
||||
// Functions defining paths that are shared by different parts of rkt
|
||||
// (e.g. stage0 and stage1)
|
||||
//
|
||||
// Package common defines values shared by different parts
|
||||
// of rkt (e.g. stage0 and stage1)
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/appc/spec/aci"
|
||||
@@ -29,6 +27,10 @@ import (
|
||||
const (
|
||||
Stage1Dir = "/stage1"
|
||||
stage2Dir = "/opt/stage2"
|
||||
|
||||
MetadataSvcIP = "169.254.169.255"
|
||||
MetadataSvcPubPort = 80
|
||||
MetadataSvcPrvPort = 2375
|
||||
)
|
||||
|
||||
// Stage1RootfsPath returns the directory in root containing the rootfs for stage1
|
||||
@@ -70,3 +72,13 @@ func RelAppRootfsPath(imageID types.Hash) string {
|
||||
func ImageManifestPath(root string, imageID types.Hash) string {
|
||||
return filepath.Join(AppImagePath(root, imageID), aci.ManifestFile)
|
||||
}
|
||||
|
||||
// MetadataSvcPrivateURL returns the private URL used to host the metadata service
|
||||
func MetadataSvcPrivateURL() string {
|
||||
return fmt.Sprintf("http://127.0.0.1:%v", MetadataSvcPrvPort)
|
||||
}
|
||||
|
||||
// MetadataSvcPublicURL returns the public URL used to host the metadata service
|
||||
func MetadataSvcPublicURL() string {
|
||||
return fmt.Sprintf("http://%v:%v", MetadataSvcIP, MetadataSvcPubPort)
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package metadata
|
||||
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
SvcIP = "169.254.169.255"
|
||||
SvcPubPort = 80
|
||||
SvcPrvPort = 2375
|
||||
)
|
||||
|
||||
func SvcPrvURL() string {
|
||||
return fmt.Sprintf("http://127.0.0.1:%v", SvcPrvPort)
|
||||
}
|
||||
|
||||
func SvcPubURL() string {
|
||||
return fmt.Sprintf("http://%v:%v", SvcIP, SvcPubPort)
|
||||
}
|
||||
@@ -23,8 +23,8 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/rocket/common"
|
||||
"github.com/coreos/rocket/networking/util"
|
||||
rktpath "github.com/coreos/rocket/path"
|
||||
)
|
||||
|
||||
// TODO(eyakubovich): make this configurable in rkt.conf
|
||||
@@ -49,7 +49,7 @@ func (e *containerEnv) findNetPlugin(plugin string) string {
|
||||
// try 3rd-party path first
|
||||
paths := []string{
|
||||
UserNetPluginsPath,
|
||||
filepath.Join(rktpath.Stage1RootfsPath(e.rktRoot), BuiltinNetPluginsPath),
|
||||
filepath.Join(common.Stage1RootfsPath(e.rktRoot), BuiltinNetPluginsPath),
|
||||
}
|
||||
|
||||
for _, p := range paths {
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ import (
|
||||
"path"
|
||||
"sort"
|
||||
|
||||
"github.com/coreos/rocket/common"
|
||||
"github.com/coreos/rocket/networking/util"
|
||||
rktpath "github.com/coreos/rocket/path"
|
||||
)
|
||||
|
||||
// Net encodes a network plugin.
|
||||
@@ -89,7 +89,7 @@ func (e *containerEnv) loadNets() ([]Net, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defPath := path.Join(rktpath.Stage1RootfsPath(e.rktRoot), DefaultNetPath)
|
||||
defPath := path.Join(common.Stage1RootfsPath(e.rktRoot), DefaultNetPath)
|
||||
defNet := Net{}
|
||||
if err := util.LoadNet(defPath, &defNet); err != nil {
|
||||
return nil, fmt.Errorf("error loading net: %v", err)
|
||||
|
||||
+4
-4
@@ -25,7 +25,7 @@ import (
|
||||
|
||||
"github.com/appc/spec/schema"
|
||||
"github.com/appc/spec/schema/types"
|
||||
rktpath "github.com/coreos/rocket/path"
|
||||
"github.com/coreos/rocket/common"
|
||||
"github.com/coreos/rocket/pkg/lock"
|
||||
"github.com/coreos/rocket/stage0"
|
||||
)
|
||||
@@ -77,7 +77,7 @@ func runEnter(args []string) (exit int) {
|
||||
return 1
|
||||
}
|
||||
|
||||
_, err = os.Stat(filepath.Join(rktpath.AppRootfsPath(cdir, *imageID)))
|
||||
_, err = os.Stat(filepath.Join(common.AppRootfsPath(cdir, *imageID)))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Unable to access app rootfs: %v\n", err)
|
||||
return 1
|
||||
@@ -108,7 +108,7 @@ func getAppImageID(cdir string) (*types.Hash, error) {
|
||||
}
|
||||
|
||||
// figure out the image id, or show a list if multiple are present
|
||||
b, err := ioutil.ReadFile(rktpath.ContainerManifestPath(cdir))
|
||||
b, err := ioutil.ReadFile(common.ContainerManifestPath(cdir))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading container manifest: %v", err)
|
||||
}
|
||||
@@ -165,7 +165,7 @@ func getEnterArgv(cdir string, imageID *types.Hash, cmdArgs []string) ([]string,
|
||||
}
|
||||
|
||||
// TODO(vc): LookPath() uses os.Stat() internally so symlinks can defeat this check
|
||||
_, err := exec.LookPath(filepath.Join(rktpath.AppRootfsPath(cdir, *imageID), argv[0]))
|
||||
_, err := exec.LookPath(filepath.Join(common.AppRootfsPath(cdir, *imageID), argv[0]))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("command %q missing, giving up: %v", argv[0], err)
|
||||
}
|
||||
|
||||
+4
-5
@@ -34,8 +34,7 @@ import (
|
||||
"github.com/appc/spec/schema"
|
||||
"github.com/appc/spec/schema/types"
|
||||
"github.com/coreos/rocket/Godeps/_workspace/src/github.com/gorilla/mux"
|
||||
|
||||
"github.com/coreos/rocket/metadata"
|
||||
"github.com/coreos/rocket/common"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -72,7 +71,7 @@ const (
|
||||
func init() {
|
||||
commands = append(commands, cmdMetadataSvc)
|
||||
cmdMetadataSvc.Flags.StringVar(&flagSrcAddrs, "src-addr", "0.0.0.0/0", "source address/range for iptables")
|
||||
cmdMetadataSvc.Flags.IntVar(&flagListenPort, "listen-port", metadata.SvcPrvPort, "listen port")
|
||||
cmdMetadataSvc.Flags.IntVar(&flagListenPort, "listen-port", common.MetadataSvcPrvPort, "listen port")
|
||||
cmdMetadataSvc.Flags.BoolVar(&flagNoIdle, "no-idle", false, "exit when last container is unregistered")
|
||||
}
|
||||
|
||||
@@ -82,8 +81,8 @@ func modifyIPTables(action, port string) error {
|
||||
"-t", "nat",
|
||||
action, "PREROUTING",
|
||||
"-p", "tcp",
|
||||
"-d", metadata.SvcIP,
|
||||
"--dport", strconv.Itoa(metadata.SvcPubPort),
|
||||
"-d", common.MetadataSvcIP,
|
||||
"--dport", strconv.Itoa(common.MetadataSvcPubPort),
|
||||
"-j", "REDIRECT",
|
||||
"--to-port", port,
|
||||
).Run()
|
||||
|
||||
+6
-6
@@ -43,7 +43,7 @@ import (
|
||||
"github.com/appc/spec/schema/types"
|
||||
"github.com/coreos/rocket/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid"
|
||||
"github.com/coreos/rocket/cas"
|
||||
rktpath "github.com/coreos/rocket/path"
|
||||
"github.com/coreos/rocket/common"
|
||||
"github.com/coreos/rocket/pkg/lock"
|
||||
ptar "github.com/coreos/rocket/pkg/tar"
|
||||
"github.com/coreos/rocket/version"
|
||||
@@ -98,9 +98,9 @@ func Setup(cfg Config) (string, error) {
|
||||
|
||||
log.Printf("Unpacking stage1 rootfs")
|
||||
if cfg.Stage1Rootfs != "" {
|
||||
err = unpackRootfs(cfg.Stage1Rootfs, rktpath.Stage1RootfsPath(dir))
|
||||
err = unpackRootfs(cfg.Stage1Rootfs, common.Stage1RootfsPath(dir))
|
||||
} else {
|
||||
err = unpackBuiltinRootfs(rktpath.Stage1RootfsPath(dir))
|
||||
err = unpackBuiltinRootfs(common.Stage1RootfsPath(dir))
|
||||
}
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error unpacking rootfs: %v", err)
|
||||
@@ -185,7 +185,7 @@ func Setup(cfg Config) (string, error) {
|
||||
}
|
||||
|
||||
log.Printf("Writing container manifest")
|
||||
fn = rktpath.ContainerManifestPath(dir)
|
||||
fn = common.ContainerManifestPath(dir)
|
||||
if err := ioutil.WriteFile(fn, cdoc, 0700); err != nil {
|
||||
return "", fmt.Errorf("error writing container manifest: %v", err)
|
||||
}
|
||||
@@ -336,7 +336,7 @@ func setupImage(cfg Config, img types.Hash, dir string) (*schema.ImageManifest,
|
||||
return nil, fmt.Errorf("error reading stream: %v", err)
|
||||
}
|
||||
|
||||
ad := rktpath.AppImagePath(dir, img)
|
||||
ad := common.AppImagePath(dir, img)
|
||||
err = os.MkdirAll(ad, 0776)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating image directory: %v", err)
|
||||
@@ -367,7 +367,7 @@ func setupImage(cfg Config, img types.Hash, dir string) (*schema.ImageManifest,
|
||||
return nil, fmt.Errorf("error creating tmp directory: %v", err)
|
||||
}
|
||||
|
||||
mpath := rktpath.ImageManifestPath(dir, img)
|
||||
mpath := common.ImageManifestPath(dir, img)
|
||||
f, err := os.Open(mpath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error opening app manifest: %v", err)
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
"github.com/appc/spec/schema"
|
||||
"github.com/appc/spec/schema/types"
|
||||
"github.com/coreos/rocket/Godeps/_workspace/src/github.com/coreos/go-systemd/unit"
|
||||
rktpath "github.com/coreos/rocket/path"
|
||||
"github.com/coreos/rocket/common"
|
||||
)
|
||||
|
||||
// Container encapsulates a ContainerRuntimeManifest and ImageManifests
|
||||
@@ -49,7 +49,7 @@ func LoadContainer(root string) (*Container, error) {
|
||||
Apps: make(map[string]*schema.ImageManifest),
|
||||
}
|
||||
|
||||
buf, err := ioutil.ReadFile(rktpath.ContainerManifestPath(c.Root))
|
||||
buf, err := ioutil.ReadFile(common.ContainerManifestPath(c.Root))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed reading container runtime manifest: %v", err)
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func LoadContainer(root string) (*Container, error) {
|
||||
c.Manifest = cm
|
||||
|
||||
for _, app := range c.Manifest.Apps {
|
||||
ampath := rktpath.ImageManifestPath(c.Root, app.ImageID)
|
||||
ampath := common.ImageManifestPath(c.Root, app.ImageID)
|
||||
buf, err := ioutil.ReadFile(ampath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed reading app manifest %q: %v", ampath, err)
|
||||
@@ -119,7 +119,7 @@ func (c *Container) appToSystemd(am *schema.ImageManifest, id types.Hash) error
|
||||
workDir = app.WorkingDirectory
|
||||
}
|
||||
|
||||
execWrap := []string{"/diagexec", rktpath.RelAppRootfsPath(id), workDir}
|
||||
execWrap := []string{"/diagexec", common.RelAppRootfsPath(id), workDir}
|
||||
execStart := quoteExec(append(execWrap, app.Exec...))
|
||||
opts := []*unit.UnitOption{
|
||||
newUnitOption("Unit", "Description", name),
|
||||
@@ -264,7 +264,7 @@ func (c *Container) appToNspawnArgs(am *schema.ImageManifest, id types.Hash) ([]
|
||||
|
||||
opt[1] = vol.Source
|
||||
opt[2] = ":"
|
||||
opt[3] = filepath.Join(rktpath.RelAppRootfsPath(id), mp.Path)
|
||||
opt[3] = filepath.Join(common.RelAppRootfsPath(id), mp.Path)
|
||||
|
||||
args = append(args, strings.Join(opt, ""))
|
||||
}
|
||||
@@ -285,7 +285,7 @@ func (c *Container) appToNspawnArgs(am *schema.ImageManifest, id types.Hash) ([]
|
||||
func (c *Container) ContainerToNspawnArgs() ([]string, error) {
|
||||
args := []string{
|
||||
"--uuid=" + c.Manifest.UUID.String(),
|
||||
"--directory=" + rktpath.Stage1RootfsPath(c.Root),
|
||||
"--directory=" + common.Stage1RootfsPath(c.Root),
|
||||
}
|
||||
|
||||
for _, am := range c.Apps {
|
||||
|
||||
+8
-9
@@ -31,9 +31,8 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/coreos/rocket/metadata"
|
||||
"github.com/coreos/rocket/common"
|
||||
"github.com/coreos/rocket/networking"
|
||||
"github.com/coreos/rocket/path"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -64,7 +63,7 @@ func mirrorLocalZoneInfo(root string) {
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
destp := filepath.Join(path.Stage1RootfsPath(root), zif)
|
||||
destp := filepath.Join(common.Stage1RootfsPath(root), zif)
|
||||
|
||||
if err = os.MkdirAll(filepath.Dir(destp), 0755); err != nil {
|
||||
return
|
||||
@@ -105,7 +104,7 @@ func stage1() int {
|
||||
}
|
||||
|
||||
mirrorLocalZoneInfo(c.Root)
|
||||
c.MetadataSvcURL = metadata.SvcPubURL()
|
||||
c.MetadataSvcURL = common.MetadataSvcPublicURL()
|
||||
|
||||
if err = c.ContainerToSystemd(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to configure systemd: %v\n", err)
|
||||
@@ -113,8 +112,8 @@ func stage1() int {
|
||||
}
|
||||
|
||||
args := []string{
|
||||
filepath.Join(path.Stage1RootfsPath(c.Root), interpBin),
|
||||
filepath.Join(path.Stage1RootfsPath(c.Root), nspawnBin),
|
||||
filepath.Join(common.Stage1RootfsPath(c.Root), interpBin),
|
||||
filepath.Join(common.Stage1RootfsPath(c.Root), nspawnBin),
|
||||
"--boot", // Launch systemd in the container
|
||||
"--register", "false", // We cannot assume the host system is running systemd
|
||||
}
|
||||
@@ -139,8 +138,8 @@ func stage1() int {
|
||||
}
|
||||
|
||||
env := os.Environ()
|
||||
env = append(env, "LD_PRELOAD="+filepath.Join(path.Stage1RootfsPath(c.Root), "fakesdboot.so"))
|
||||
env = append(env, "LD_LIBRARY_PATH="+filepath.Join(path.Stage1RootfsPath(c.Root), "usr/lib"))
|
||||
env = append(env, "LD_PRELOAD="+filepath.Join(common.Stage1RootfsPath(c.Root), "fakesdboot.so"))
|
||||
env = append(env, "LD_LIBRARY_PATH="+filepath.Join(common.Stage1RootfsPath(c.Root), "usr/lib"))
|
||||
|
||||
if metadataSvc != "" {
|
||||
if err = launchMetadataSvc(); err != nil {
|
||||
@@ -198,7 +197,7 @@ func launchMetadataSvc() error {
|
||||
// use socket activation protocol to avoid race-condition of
|
||||
// service becoming ready
|
||||
// TODO(eyakubovich): remove hard-coded port
|
||||
l, err := net.ListenTCP("tcp4", &net.TCPAddr{Port: metadata.SvcPrvPort})
|
||||
l, err := net.ListenTCP("tcp4", &net.TCPAddr{Port: common.MetadataSvcPrvPort})
|
||||
if err != nil {
|
||||
if err.(*net.OpError).Err.(*os.SyscallError).Err == syscall.EADDRINUSE {
|
||||
// assume metadatasvc is already running
|
||||
|
||||
+2
-2
@@ -20,11 +20,11 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/appc/spec/schema/types"
|
||||
"github.com/coreos/rocket/path"
|
||||
"github.com/coreos/rocket/common"
|
||||
)
|
||||
|
||||
const (
|
||||
unitsDir = path.Stage1Dir + "/usr/lib/systemd/system"
|
||||
unitsDir = common.Stage1Dir + "/usr/lib/systemd/system"
|
||||
defaultWantsDir = unitsDir + "/default.target.wants"
|
||||
socketsWantsDir = unitsDir + "/sockets.target.wants"
|
||||
)
|
||||
|
||||
@@ -22,12 +22,11 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/coreos/rocket/metadata"
|
||||
rktpath "github.com/coreos/rocket/path"
|
||||
"github.com/coreos/rocket/common"
|
||||
)
|
||||
|
||||
func registerContainer(c *Container, ip net.IP) error {
|
||||
cmf, err := os.Open(rktpath.ContainerManifestPath(c.Root))
|
||||
cmf, err := os.Open(common.ContainerManifestPath(c.Root))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed opening runtime manifest: %v", err)
|
||||
}
|
||||
@@ -40,7 +39,7 @@ func registerContainer(c *Container, ip net.IP) error {
|
||||
|
||||
uid := c.Manifest.UUID.String()
|
||||
for _, app := range c.Manifest.Apps {
|
||||
ampath := rktpath.ImageManifestPath(c.Root, app.ImageID)
|
||||
ampath := common.ImageManifestPath(c.Root, app.ImageID)
|
||||
amf, err := os.Open(ampath)
|
||||
if err != nil {
|
||||
fmt.Errorf("failed reading app manifest %q: %v", ampath, err)
|
||||
@@ -66,7 +65,7 @@ func registerApp(uuid, app string, r io.Reader) error {
|
||||
}
|
||||
|
||||
func httpRequest(method, pth string, body io.Reader) error {
|
||||
uri := metadata.SvcPrvURL() + pth
|
||||
uri := common.MetadataSvcPrivateURL() + pth
|
||||
req, err := http.NewRequest(method, uri, body)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -15,7 +15,7 @@ COVER=${COVER:-"-cover"}
|
||||
source ./build
|
||||
|
||||
TESTABLE_AND_FORMATTABLE="cas pkg/keystore pkg/lock pkg/tar rkt stage1/init"
|
||||
FORMATTABLE="$TESTABLE_AND_FORMATTABLE networking path stage0/run.go version"
|
||||
FORMATTABLE="$TESTABLE_AND_FORMATTABLE common networking stage0/run.go version"
|
||||
|
||||
# user has not provided PKG override
|
||||
if [ -z "$PKG" ]; then
|
||||
|
||||
Reference in New Issue
Block a user