re-vendor appc/spec; fixup pod related changes

* UUID is no longer part of manifest
* Metadata URLs changed
This commit is contained in:
Eugene Yakubovich
2015-03-25 16:47:55 -07:00
parent 05b512cb67
commit 554ab1a270
11 changed files with 66 additions and 43 deletions
+12 -12
View File
@@ -25,33 +25,33 @@
},
{
"ImportPath": "github.com/appc/spec/aci",
"Comment": "v0.5.0",
"Rev": "cffea391f209199b873af3f8a71a98ac658f073e"
"Comment": "v0.5.0-10-g3fa4247",
"Rev": "3fa4247af87697784d812b8b68efd809fcbee33e"
},
{
"ImportPath": "github.com/appc/spec/actool",
"Comment": "v0.5.0",
"Rev": "cffea391f209199b873af3f8a71a98ac658f073e"
"Comment": "v0.5.0-10-g3fa4247",
"Rev": "3fa4247af87697784d812b8b68efd809fcbee33e"
},
{
"ImportPath": "github.com/appc/spec/discovery",
"Comment": "v0.5.0",
"Rev": "cffea391f209199b873af3f8a71a98ac658f073e"
"Comment": "v0.5.0-10-g3fa4247",
"Rev": "3fa4247af87697784d812b8b68efd809fcbee33e"
},
{
"ImportPath": "github.com/appc/spec/pkg/acirenderer",
"Comment": "v0.5.0",
"Rev": "cffea391f209199b873af3f8a71a98ac658f073e"
"Comment": "v0.5.0-10-g3fa4247",
"Rev": "3fa4247af87697784d812b8b68efd809fcbee33e"
},
{
"ImportPath": "github.com/appc/spec/pkg/tarheader",
"Comment": "v0.5.0",
"Rev": "cffea391f209199b873af3f8a71a98ac658f073e"
"Comment": "v0.5.0-10-g3fa4247",
"Rev": "3fa4247af87697784d812b8b68efd809fcbee33e"
},
{
"ImportPath": "github.com/appc/spec/schema",
"Comment": "v0.5.0",
"Rev": "cffea391f209199b873af3f8a71a98ac658f073e"
"Comment": "v0.5.0-10-g3fa4247",
"Rev": "3fa4247af87697784d812b8b68efd809fcbee33e"
},
{
"ImportPath": "github.com/camlistore/lock",
-1
View File
@@ -13,7 +13,6 @@ const PodManifestKind = types.ACKind("PodManifest")
type PodManifest struct {
ACVersion types.SemVer `json:"acVersion"`
ACKind types.ACKind `json:"acKind"`
UUID types.UUID `json:"uuid"`
Apps AppList `json:"apps"`
Volumes []types.Volume `json:"volumes"`
Isolators []types.Isolator `json:"isolators"`
+1 -1
View File
@@ -8,7 +8,7 @@ const (
// version represents the canonical version of the appc spec and tooling.
// For now, the schema and tooling is coupled with the spec itself, so
// this must be kept in sync with the VERSION file in the root of the repo.
version string = "0.5.0"
version string = "0.5.0+git"
)
var (
+27 -19
View File
@@ -46,6 +46,7 @@ var (
)
type mdsContainer struct {
uuid types.UUID
manifest schema.PodManifest
apps map[string]*schema.ImageManifest
ip string
@@ -105,6 +106,13 @@ func handleRegisterContainer(w http.ResponseWriter, r *http.Request) {
return
}
uuid, err := types.NewUUID(mux.Vars(r)["uuid"])
if err != nil {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "UUID is missing or malformed: %v", err)
return
}
containerIP := queryValue(r.URL, "ip")
if containerIP == "" {
w.WriteHeader(http.StatusBadRequest)
@@ -124,7 +132,7 @@ func handleRegisterContainer(w http.ResponseWriter, r *http.Request) {
}
containerByIP[containerIP] = c
containerByUID[c.manifest.UUID] = c
containerByUID[*uuid] = c
w.WriteHeader(http.StatusOK)
}
@@ -132,21 +140,21 @@ func handleRegisterContainer(w http.ResponseWriter, r *http.Request) {
func handleUnregisterContainer(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
uid, err := types.NewUUID(mux.Vars(r)["uid"])
uuid, err := types.NewUUID(mux.Vars(r)["uuid"])
if err != nil {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "UUID is missing or malformed: %v", err)
return
}
c, ok := containerByUID[*uid]
c, ok := containerByUID[*uuid]
if !ok {
w.WriteHeader(http.StatusNotFound)
fmt.Fprint(w, "Container with given UUID not found")
return
}
delete(containerByUID, *uid)
delete(containerByUID, *uuid)
delete(containerByIP, c.ip)
w.WriteHeader(http.StatusOK)
@@ -165,14 +173,14 @@ func handleRegisterApp(w http.ResponseWriter, r *http.Request) {
return
}
uid, err := types.NewUUID(mux.Vars(r)["uid"])
uuid, err := types.NewUUID(mux.Vars(r)["uuid"])
if err != nil {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "UUID is missing or mulformed: %v", err)
return
}
c, ok := containerByUID[*uid]
c, ok := containerByUID[*uuid]
if !ok {
w.WriteHeader(http.StatusNotFound)
fmt.Fprint(w, "Container with given UUID not found")
@@ -264,14 +272,14 @@ func handlePodManifest(w http.ResponseWriter, r *http.Request, c *mdsContainer)
}
}
func handleContainerUID(w http.ResponseWriter, r *http.Request, c *mdsContainer) {
func handleContainerUUID(w http.ResponseWriter, r *http.Request, c *mdsContainer) {
defer r.Body.Close()
uid := c.manifest.UUID.String()
uuid := c.uuid.String()
w.Header().Add("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
w.Write([]byte(uid))
w.Write([]byte(uuid))
}
func mergeAppAnnotations(im *schema.ImageManifest, cm *schema.PodManifest) types.Annotations {
@@ -375,7 +383,7 @@ func handleContainerSign(w http.ResponseWriter, r *http.Request) {
// HMAC(UID:content)
h := hmac.New(sha512.New, hmacKey[:])
h.Write(c.manifest.UUID[:])
h.Write(c.uuid[:])
h.Write([]byte(content))
// Send back HMAC as the signature
@@ -449,27 +457,27 @@ func logReq(h func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc {
func makeHandlers() http.Handler {
r := mux.NewRouter()
r.HandleFunc("/pods/", logReq(handleRegisterContainer)).Methods("POST")
r.HandleFunc("/pods/{uid}", logReq(handleUnregisterContainer)).Methods("DELETE")
r.HandleFunc("/pods/{uid}/{app:.*}", logReq(handleRegisterApp)).Methods("PUT")
r.HandleFunc("/pods/{uuid}", logReq(handleRegisterContainer)).Methods("PUT")
r.HandleFunc("/pods/{uuid}", logReq(handleUnregisterContainer)).Methods("DELETE")
r.HandleFunc("/pods/{uuid}/{app:.*}", logReq(handleRegisterApp)).Methods("PUT")
acRtr := r.Headers("Metadata-Flavor", "AppContainer").
PathPrefix("/acMetadata/v1").Subrouter()
mr := acRtr.Methods("GET").Subrouter()
mr.HandleFunc("/container/annotations/", logReq(containerGet(handleContainerAnnotations)))
mr.HandleFunc("/container/annotations/{name}", logReq(containerGet(handleContainerAnnotation)))
mr.HandleFunc("/container/manifest", logReq(containerGet(handlePodManifest)))
mr.HandleFunc("/container/uid", logReq(containerGet(handleContainerUID)))
mr.HandleFunc("/pod/annotations/", logReq(containerGet(handleContainerAnnotations)))
mr.HandleFunc("/pod/annotations/{name}", logReq(containerGet(handleContainerAnnotation)))
mr.HandleFunc("/pod/manifest", logReq(containerGet(handlePodManifest)))
mr.HandleFunc("/pod/uuid", logReq(containerGet(handleContainerUUID)))
mr.HandleFunc("/apps/{app:.*}/annotations/", logReq(appGet(handleAppAnnotations)))
mr.HandleFunc("/apps/{app:.*}/annotations/{name}", logReq(appGet(handleAppAnnotation)))
mr.HandleFunc("/apps/{app:.*}/image/manifest", logReq(appGet(handleImageManifest)))
mr.HandleFunc("/apps/{app:.*}/image/id", logReq(appGet(handleAppID)))
acRtr.HandleFunc("/container/hmac/sign", logReq(handleContainerSign)).Methods("POST")
acRtr.HandleFunc("/container/hmac/verify", logReq(handleContainerVerify)).Methods("POST")
acRtr.HandleFunc("/pod/hmac/sign", logReq(handleContainerSign)).Methods("POST")
acRtr.HandleFunc("/pod/hmac/verify", logReq(handleContainerVerify)).Methods("POST")
return r
}
+1
View File
@@ -115,6 +115,7 @@ func runPrepare(args []string) (exit int) {
Store: ds,
Debug: globalFlags.Debug,
Stage1Image: *s1img,
UUID: c.uuid,
Images: imgs,
},
ExecAppends: appArgs,
+1
View File
@@ -234,6 +234,7 @@ func runRun(args []string) (exit int) {
cfg := stage0.CommonConfig{
Store: ds,
Stage1Image: *s1img,
UUID: c.uuid,
Images: imgs,
Debug: globalFlags.Debug,
}
+1
View File
@@ -123,6 +123,7 @@ func runRunPrepared(args []string) (exit int) {
CommonConfig: stage0.CommonConfig{
Store: ds,
Stage1Image: *s1img,
UUID: c.uuid,
Images: imgs,
Debug: globalFlags.Debug,
},
+2
View File
@@ -74,6 +74,7 @@ type RunConfig struct {
type CommonConfig struct {
Store *cas.Store // store containing all of the configured application images
Stage1Image types.Hash // stage1 image containing usable /init and /enter entrypoints
UUID *types.UUID // UUID of the pod
Images []types.Hash // application images
PodsDir string // root directory for rocket pods
Debug bool
@@ -304,6 +305,7 @@ func Run(cfg RunConfig, dir string) {
if cfg.Interactive {
args = append(args, "--interactive")
}
args = append(args, cfg.UUID.String())
// make sure the lock fd stays open across exec
if err := sys.CloseOnExec(cfg.LockFd, false); err != nil {
+4 -2
View File
@@ -36,6 +36,7 @@ import (
// Container encapsulates a PodManifest and ImageManifests
type Container struct {
Root string // root directory where the container will be located
UUID types.UUID
Manifest *schema.PodManifest
Apps map[string]*schema.ImageManifest
MetadataServiceURL string
@@ -44,9 +45,10 @@ type Container struct {
// LoadContainer loads a Pod Manifest (as prepared by stage0) and
// its associated Application Manifests, under $root/stage1/opt/stage1/$apphash
func LoadContainer(root string) (*Container, error) {
func LoadContainer(root string, uuid *types.UUID) (*Container, error) {
c := &Container{
Root: root,
UUID: *uuid,
Apps: make(map[string]*schema.ImageManifest),
}
@@ -323,7 +325,7 @@ func (c *Container) appToNspawnArgs(ra *schema.RuntimeApp, am *schema.ImageManif
// argument list ready to be executed
func (c *Container) ContainerToNspawnArgs() ([]string, error) {
args := []string{
"--uuid=" + c.Manifest.UUID.String(),
"--uuid=" + c.UUID.String(),
"--directory=" + common.Stage1RootfsPath(c.Root),
}
+10 -2
View File
@@ -28,6 +28,8 @@ import (
"runtime"
"syscall"
"github.com/coreos/rocket/Godeps/_workspace/src/github.com/appc/spec/schema/types"
"github.com/coreos/rocket/common"
"github.com/coreos/rocket/networking"
"github.com/coreos/rocket/pkg/sys"
@@ -156,8 +158,14 @@ func withClearedCloExec(lfd int, f func() error) error {
}
func stage1() int {
uuid, err := types.NewUUID(flag.Arg(0))
if err != nil {
fmt.Fprintln(os.Stderr, "UUID is missing or malformed")
return 1
}
root := "."
c, err := LoadContainer(root)
c, err := LoadContainer(root, uuid)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to load container: %v\n", err)
return 1
@@ -194,7 +202,7 @@ func stage1() int {
// careful not to make another local err variable.
// cmd.Run sets the one from parent scope
var n *networking.Networking
n, err = networking.Setup(root, c.Manifest.UUID)
n, err = networking.Setup(root, c.UUID)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to setup network: %v\n", err)
return 6
+7 -6
View File
@@ -26,18 +26,19 @@ import (
)
func registerContainer(c *Container, ip net.IP) error {
uuid := c.UUID.String()
cmf, err := os.Open(common.PodManifestPath(c.Root))
if err != nil {
return fmt.Errorf("failed opening runtime manifest: %v", err)
}
defer cmf.Close()
pth := fmt.Sprintf("/pods/?ip=%v", ip.To4().String())
if err := httpRequest("POST", pth, cmf); err != nil {
pth := fmt.Sprintf("/pods/%v?ip=%v", uuid, ip.To4().String())
if err := httpRequest("PUT", pth, cmf); err != nil {
return fmt.Errorf("failed to register container with metadata svc: %v", err)
}
uid := c.Manifest.UUID.String()
for _, app := range c.Manifest.Apps {
ampath := common.ImageManifestPath(c.Root, app.Image.ID)
amf, err := os.Open(ampath)
@@ -46,7 +47,7 @@ func registerContainer(c *Container, ip net.IP) error {
}
defer amf.Close()
if err := registerApp(uid, app.Name.String(), amf); err != nil {
if err := registerApp(uuid, app.Name.String(), amf); err != nil {
fmt.Errorf("failed to register app with metadata svc: %v", err)
}
}
@@ -55,12 +56,12 @@ func registerContainer(c *Container, ip net.IP) error {
}
func unregisterContainer(c *Container) error {
pth := path.Join("/containers", c.Manifest.UUID.String())
pth := path.Join("/pods", c.UUID.String())
return httpRequest("DELETE", pth, nil)
}
func registerApp(uuid, app string, r io.Reader) error {
pth := path.Join("/containers", uuid, app)
pth := path.Join("/pods", uuid, app)
return httpRequest("PUT", pth, r)
}