func (b *Builder) getStage1Manifest() (*schema.ImageManifest, error) { content, err := ioutil.ReadFile(rktcommon.Stage1ManifestPath(b.pod.Root)) if err != nil { return nil, errs.WithEF(err, b.fields.WithField("file", rktcommon.Stage1ManifestPath(b.pod.Root)), "Failed to read stage1 manifest") } im := &schema.ImageManifest{} err = im.UnmarshalJSON(content) if err != nil { return nil, errs.WithEF(err, b.fields.WithField("content", string(content)). WithField("file", rktcommon.Stage1ManifestPath(b.pod.Root)), "Cannot unmarshall json content from file") } return im, nil }
// getStage1Entrypoint retrieves the named entrypoint from the stage1 manifest for a given pod func getStage1Entrypoint(cdir string, entrypoint string) (string, error) { b, err := ioutil.ReadFile(common.Stage1ManifestPath(cdir)) if err != nil { return "", errwrap.Wrap(errors.New("error reading pod manifest"), err) } s1m := schema.ImageManifest{} if err := json.Unmarshal(b, &s1m); err != nil { return "", errwrap.Wrap(errors.New("error unmarshaling stage1 manifest"), err) } if ep, ok := s1m.Annotations.Get(entrypoint); ok { return ep, nil } return "", fmt.Errorf("entrypoint %q not found", entrypoint) }
// supportsMutableEnvironment returns whether the given stage1 image supports mutable pod operations. // It introspects the stage1 manifest and checks the presence of app* entrypoints. func supportsMutableEnvironment(cdir string) (bool, error) { b, err := ioutil.ReadFile(common.Stage1ManifestPath(cdir)) if err != nil { return false, errwrap.Wrap(errors.New("error reading pod manifest"), err) } s1m := schema.ImageManifest{} if err := json.Unmarshal(b, &s1m); err != nil { return false, errwrap.Wrap(errors.New("error unmarshaling stage1 manifest"), err) } _, appRmOk := s1m.Annotations.Get(appRmEntrypoint) _, appStartOk := s1m.Annotations.Get(appStartEntrypoint) _, appStopOk := s1m.Annotations.Get(appStopEntrypoint) return appRmOk && appStartOk && appStopOk, nil }
// getStage1InterfaceVersion retrieves the interface version from the stage1 // manifest for a given pod func getStage1InterfaceVersion(cdir string) (int, error) { b, err := ioutil.ReadFile(common.Stage1ManifestPath(cdir)) if err != nil { return -1, errwrap.Wrap(errors.New("error reading pod manifest"), err) } s1m := schema.ImageManifest{} if err := json.Unmarshal(b, &s1m); err != nil { return -1, errwrap.Wrap(errors.New("error unmarshaling stage1 manifest"), err) } if iv, ok := s1m.Annotations.Get(interfaceVersion); ok { v, err := strconv.Atoi(iv) if err != nil { return -1, errwrap.Wrap(errors.New("error parsing interface version"), err) } return v, nil } // "interface-version" annotation not found, assume version 1 return 1, nil }