本文整理汇总了Golang中github.com/coreos/rkt/Godeps/_workspace/src/github.com/appc/spec/schema/types.MustACIdentifier函数的典型用法代码示例。如果您正苦于以下问题:Golang MustACIdentifier函数的具体用法?Golang MustACIdentifier怎么用?Golang MustACIdentifier使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustACIdentifier函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: mergeManifests
func mergeManifests(manifests []schema.ImageManifest) schema.ImageManifest {
// FIXME(iaguis) we take app layer's manifest as the final manifest for now
manifest := manifests[0]
manifest.Dependencies = nil
layerIndex := -1
for i, l := range manifest.Labels {
if l.Name.String() == "layer" {
layerIndex = i
}
}
if layerIndex != -1 {
manifest.Labels = append(manifest.Labels[:layerIndex], manifest.Labels[layerIndex+1:]...)
}
nameWithoutLayerID := appctypes.MustACIdentifier(stripLayerID(manifest.Name.String()))
manifest.Name = *nameWithoutLayerID
// once the image is squashed, we don't need a pathWhitelist
manifest.PathWhitelist = nil
return manifest
}
开发者ID:matomesc,项目名称:rkt,代码行数:26,代码来源:docker2aci.go
示例2: TestPodManifest
//.........这里部分代码省略.........
},
true,
"host:zaz",
},
{
// Simple read after write with read-only volume mounted, no apps in pod manifest.
// This should fail as the volume is read-only.
"rkt-test-run-pod-manifest-vol-ro-no-app.aci",
[]string{
"--exec=/inspect --write-file --read-file --file-name=/dir1/file --content=baz",
"--mounts=dir1,path=/dir1,readOnly=false",
},
&schema.PodManifest{
Apps: []schema.RuntimeApp{
{Name: baseAppName},
},
Volumes: []types.Volume{
{"dir1", "host", tmpdir, &boolTrue},
},
},
false,
`Cannot write to file "/dir1/file": open /dir1/file: read-only file system`,
},
}
for i, tt := range tests {
patchTestACI(tt.imageName, tt.imagePatches...)
hash := importImageAndFetchHash(t, ctx, tt.imageName)
defer os.Remove(tt.imageName)
tt.podManifest.ACKind = schema.PodManifestKind
tt.podManifest.ACVersion = schema.AppContainerVersion
imgName := types.MustACIdentifier(tt.imageName)
imgID, err := types.NewHash(hash)
if err != nil {
t.Fatalf("Cannot generate types.Hash from %v: %v", hash, err)
}
for i := range tt.podManifest.Apps {
ra := &tt.podManifest.Apps[i]
ra.Image.Name = imgName
ra.Image.ID = *imgID
}
manifestFile := generatePodManifestFile(t, tt.podManifest)
defer os.Remove(manifestFile)
// 1. Test 'rkt run'.
runCmd := fmt.Sprintf("%s run --pod-manifest=%s", ctx.cmd(), manifestFile)
t.Logf("Running 'run' test #%v: %v", i, runCmd)
child, err := gexpect.Spawn(runCmd)
if err != nil {
t.Fatalf("Cannot exec rkt #%v: %v", i, err)
}
if tt.expectedResult != "" {
if err := child.Expect(tt.expectedResult); err != nil {
t.Fatalf("Expected %q but not found: %v", tt.expectedResult, err)
}
}
if err := child.Wait(); err != nil {
if tt.shouldSuccess {
t.Fatalf("rkt didn't terminate correctly: %v", err)
}
}
verifyHostFile(t, tmpdir, "file", i, tt.expectedResult)
开发者ID:danieltaborda,项目名称:rkt,代码行数:67,代码来源:rkt_run_pod_manifest_test.go
示例3: TestPodManifest
//.........这里部分代码省略.........
&schema.PodManifest{
Apps: []schema.RuntimeApp{
{
Name: baseAppName,
App: &types.App{
Exec: []string{"/inspect", "--print-caps-pid=0"},
User: "0",
Group: "0",
Environment: []types.EnvironmentVariable{
{"CAPABILITY", strconv.Itoa(int(capability.CAP_NET_ADMIN))},
},
Isolators: []types.Isolator{
{
Name: "os/linux/capabilities-retain-set",
ValueRaw: rawValue(fmt.Sprintf(`{"set":["CAP_NET_ADMIN"]}`)),
},
},
},
},
},
},
true,
fmt.Sprintf("%v=enabled", capability.CAP_NET_ADMIN.String()),
"",
},
}
for i, tt := range tests {
if tt.cgroup != "" && !cgroup.IsIsolatorSupported(tt.cgroup) {
t.Logf("Skip test #%v: cgroup %s not supported", i, tt.cgroup)
continue
}
var hashesToRemove []string
for j, v := range tt.images {
hash := patchImportAndFetchHash(v.name, v.patches, t, ctx)
hashesToRemove = append(hashesToRemove, hash)
imgName := types.MustACIdentifier(v.name)
imgID, err := types.NewHash(hash)
if err != nil {
t.Fatalf("Cannot generate types.Hash from %v: %v", hash, err)
}
ra := &tt.podManifest.Apps[j]
ra.Image.Name = imgName
ra.Image.ID = *imgID
}
tt.podManifest.ACKind = schema.PodManifestKind
tt.podManifest.ACVersion = schema.AppContainerVersion
manifestFile := generatePodManifestFile(t, tt.podManifest)
defer os.Remove(manifestFile)
// 1. Test 'rkt run'.
runCmd := fmt.Sprintf("%s run --mds-register=false --pod-manifest=%s", ctx.Cmd(), manifestFile)
t.Logf("Running 'run' test #%v", i)
child := spawnOrFail(t, runCmd)
if tt.expectedResult != "" {
if err := expectWithOutput(child, tt.expectedResult); err != nil {
t.Fatalf("Expected %q but not found: %v", tt.expectedResult, err)
}
}
if err := child.Wait(); err != nil {
if tt.shouldSucceed {
t.Fatalf("rkt didn't terminate correctly: %v", err)
}
}
verifyHostFile(t, tmpdir, "file", i, tt.expectedResult)
// 2. Test 'rkt prepare' + 'rkt run-prepared'.
rktCmd := fmt.Sprintf("%s --insecure-skip-verify prepare --pod-manifest=%s",
ctx.Cmd(), manifestFile)
uuid := runRktAndGetUUID(t, rktCmd)
runPreparedCmd := fmt.Sprintf("%s run-prepared --mds-register=false %s", ctx.Cmd(), uuid)
t.Logf("Running 'run-prepared' test #%v", i)
child = spawnOrFail(t, runPreparedCmd)
if tt.expectedResult != "" {
if err := expectWithOutput(child, tt.expectedResult); err != nil {
t.Fatalf("Expected %q but not found: %v", tt.expectedResult, err)
}
}
if err := child.Wait(); err != nil {
if tt.shouldSucceed {
t.Fatalf("rkt didn't terminate correctly: %v", err)
}
}
verifyHostFile(t, tmpdir, "file", i, tt.expectedResult)
// we run the garbage collector and remove the imported images to save
// space
runGC(t, ctx)
for _, h := range hashesToRemove {
removeFromCas(t, ctx, h)
}
}
}
开发者ID:kinpro,项目名称:rkt,代码行数:101,代码来源:rkt_run_pod_manifest_test.go
示例4: GenerateManifest
func GenerateManifest(layerData types.DockerImageData, dockerURL *types.ParsedDockerURL) (*schema.ImageManifest, error) {
dockerConfig := layerData.Config
genManifest := &schema.ImageManifest{}
appURL := ""
// omit docker hub index URL in app name
if dockerURL.IndexURL != defaultIndex {
appURL = dockerURL.IndexURL + "/"
}
appURL += dockerURL.ImageName + "-" + layerData.ID
appURL, err := appctypes.SanitizeACIdentifier(appURL)
if err != nil {
return nil, err
}
name := appctypes.MustACIdentifier(appURL)
genManifest.Name = *name
acVersion, err := appctypes.NewSemVer(schemaVersion)
if err != nil {
panic("invalid appc spec version")
}
genManifest.ACVersion = *acVersion
genManifest.ACKind = appctypes.ACKind(schema.ImageManifestKind)
var (
labels appctypes.Labels
parentLabels appctypes.Labels
annotations appctypes.Annotations
)
layer := appctypes.MustACIdentifier("layer")
labels = append(labels, appctypes.Label{Name: *layer, Value: layerData.ID})
tag := dockerURL.Tag
version := appctypes.MustACIdentifier("version")
labels = append(labels, appctypes.Label{Name: *version, Value: tag})
if layerData.OS != "" {
os := appctypes.MustACIdentifier("os")
labels = append(labels, appctypes.Label{Name: *os, Value: layerData.OS})
parentLabels = append(parentLabels, appctypes.Label{Name: *os, Value: layerData.OS})
if layerData.Architecture != "" {
arch := appctypes.MustACIdentifier("arch")
parentLabels = append(parentLabels, appctypes.Label{Name: *arch, Value: layerData.Architecture})
}
}
if layerData.Author != "" {
authorsKey := appctypes.MustACIdentifier("authors")
annotations = append(annotations, appctypes.Annotation{Name: *authorsKey, Value: layerData.Author})
}
epoch := time.Unix(0, 0)
if !layerData.Created.Equal(epoch) {
createdKey := appctypes.MustACIdentifier("created")
annotations = append(annotations, appctypes.Annotation{Name: *createdKey, Value: layerData.Created.Format(time.RFC3339)})
}
if layerData.Comment != "" {
commentKey := appctypes.MustACIdentifier("docker-comment")
annotations = append(annotations, appctypes.Annotation{Name: *commentKey, Value: layerData.Comment})
}
genManifest.Labels = labels
genManifest.Annotations = annotations
if dockerConfig != nil {
exec := getExecCommand(dockerConfig.Entrypoint, dockerConfig.Cmd)
if exec != nil {
user, group := parseDockerUser(dockerConfig.User)
var env appctypes.Environment
for _, v := range dockerConfig.Env {
parts := strings.SplitN(v, "=", 2)
env.Set(parts[0], parts[1])
}
app := &appctypes.App{
Exec: exec,
User: user,
Group: group,
Environment: env,
WorkingDirectory: dockerConfig.WorkingDir,
}
app.MountPoints, err = convertVolumesToMPs(dockerConfig.Volumes)
if err != nil {
return nil, err
}
app.Ports, err = convertPorts(dockerConfig.ExposedPorts, dockerConfig.PortSpecs)
if err != nil {
return nil, err
}
genManifest.App = app
}
}
if layerData.Parent != "" {
parentImageNameString := dockerURL.IndexURL + "/" + dockerURL.ImageName + "-" + layerData.Parent
parentImageNameString, err := appctypes.SanitizeACIdentifier(parentImageNameString)
//.........这里部分代码省略.........
开发者ID:danieltaborda,项目名称:rkt,代码行数:101,代码来源:common.go
示例5: TestAPIServiceListInspectPods
func TestAPIServiceListInspectPods(t *testing.T) {
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
svc := startAPIService(t, ctx)
defer stopAPIService(t, svc)
c, conn := newAPIClientOrFail(t, "localhost:15441")
defer conn.Close()
resp, err := c.ListPods(context.Background(), &v1alpha.ListPodsRequest{})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if len(resp.Pods) != 0 {
t.Errorf("Unexpected result: %v, should see zero pods", resp.Pods)
}
patches := []string{"--exec=/inspect --print-msg=HELLO_API --exit-code=42"}
patchImportAndFetchHash("rkt-inspect-print.aci", patches, t, ctx)
// TODO(derekparker) There is a bug where `patchImportAndFetchHash` does not
// return the full hash, which causes `InspectPod` to fail later in this test.
// So instead we list images to get the full, correct hash.
iresp, err := c.ListImages(context.Background(), &v1alpha.ListImagesRequest{})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if len(iresp.Images) == 0 {
t.Fatal("Expected non-zero images")
}
imgID, err := types.NewHash(iresp.Images[0].Id)
if err != nil {
t.Fatalf("Cannot generate types.Hash from %v: %v", iresp.Images[0].Id, err)
}
pm := schema.BlankPodManifest()
pm.Apps = []schema.RuntimeApp{
schema.RuntimeApp{
Name: types.ACName("rkt-inspect"),
Image: schema.RuntimeImage{
Name: types.MustACIdentifier("coreos.com/rkt-inspect"),
ID: *imgID,
},
Annotations: []types.Annotation{types.Annotation{Name: types.ACIdentifier("app-test"), Value: "app-test"}},
},
}
pm.Annotations = []types.Annotation{types.Annotation{Name: types.ACIdentifier("test"), Value: "test"}}
manifestFile := generatePodManifestFile(t, pm)
defer os.Remove(manifestFile)
runCmd := fmt.Sprintf("%s run --pod-manifest=%s", ctx.Cmd(), manifestFile)
esp := spawnOrFail(t, runCmd)
waitOrFail(t, esp, true)
// ListPods(detail=false).
resp, err = c.ListPods(context.Background(), &v1alpha.ListPodsRequest{})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if len(resp.Pods) == 0 {
t.Errorf("Unexpected result: %v, should see non-zero pods", resp.Pods)
}
for _, p := range resp.Pods {
checkPodBasics(t, ctx, p)
// Test InspectPod().
inspectResp, err := c.InspectPod(context.Background(), &v1alpha.InspectPodRequest{Id: p.Id})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
checkPodDetails(t, ctx, inspectResp.Pod)
// Test Apps.
for i, app := range p.Apps {
checkAnnotations(t, pm.Apps[i].Annotations, app.Annotations)
}
}
// ListPods(detail=true).
resp, err = c.ListPods(context.Background(), &v1alpha.ListPodsRequest{Detail: true})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if len(resp.Pods) == 0 {
t.Errorf("Unexpected result: %v, should see non-zero pods", resp.Pods)
}
for _, p := range resp.Pods {
checkPodDetails(t, ctx, p)
}
}
开发者ID:tomdee,项目名称:rkt,代码行数:94,代码来源:rkt_api_service_test.go
示例6: TestPodManifest
//.........这里部分代码省略.........
User: "0",
Group: "0",
Environment: []types.EnvironmentVariable{
{"CAPABILITY", strconv.Itoa(int(capability.CAP_NET_BIND_SERVICE))},
},
Isolators: []types.Isolator{
{
Name: "os/linux/capabilities-retain-set",
ValueRaw: rawValue(fmt.Sprintf(`{"set":["CAP_NET_BIND_SERVICE"]}`)),
},
},
},
},
},
},
true,
fmt.Sprintf("%v=enabled", capability.CAP_NET_BIND_SERVICE.String()),
"",
},
}
for i, tt := range tests {
if tt.cgroup != "" && !cgroup.IsIsolatorSupported(tt.cgroup) {
t.Logf("Skip test #%v: cgroup %s not supported", i, tt.cgroup)
continue
}
j := 0
for name, patches := range tt.images {
imageFile := patchTestACI(name, patches...)
hash := importImageAndFetchHash(t, ctx, imageFile)
defer os.Remove(imageFile)
imgName := types.MustACIdentifier(name)
imgID, err := types.NewHash(hash)
if err != nil {
t.Fatalf("Cannot generate types.Hash from %v: %v", hash, err)
}
ra := &tt.podManifest.Apps[j]
ra.Image.Name = imgName
ra.Image.ID = *imgID
j++
}
tt.podManifest.ACKind = schema.PodManifestKind
tt.podManifest.ACVersion = schema.AppContainerVersion
manifestFile := generatePodManifestFile(t, tt.podManifest)
defer os.Remove(manifestFile)
// 1. Test 'rkt run'.
runCmd := fmt.Sprintf("%s run --mds-register=false --pod-manifest=%s", ctx.cmd(), manifestFile)
t.Logf("Running 'run' test #%v: %v", i, runCmd)
child, err := gexpect.Spawn(runCmd)
if err != nil {
t.Fatalf("Cannot exec rkt #%v: %v", i, err)
}
if tt.expectedResult != "" {
if err := expectWithOutput(child, tt.expectedResult); err != nil {
t.Fatalf("Expected %q but not found: %v", tt.expectedResult, err)
}
}
if err := child.Wait(); err != nil {
开发者ID:squaremo,项目名称:rkt,代码行数:67,代码来源:rkt_run_pod_manifest_test.go
注:本文中的github.com/coreos/rkt/Godeps/_workspace/src/github.com/appc/spec/schema/types.MustACIdentifier函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论