-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.go
136 lines (107 loc) · 4.91 KB
/
registry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package registry
import (
"time"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
dockerClient "github.com/fsouza/go-dockerclient"
"k8s.io/kubernetes/pkg/util/wait"
regclient "github.com/openshift/origin/pkg/dockerregistry"
imageapi "github.com/openshift/origin/pkg/image/api"
imagesutil "github.com/openshift/origin/test/extended/images"
registryutil "github.com/openshift/origin/test/extended/registry/util"
exutil "github.com/openshift/origin/test/extended/util"
testutil "github.com/openshift/origin/test/util"
)
const (
repoName = "app"
tagName = "latest"
imageSize = 1024
)
var _ = g.Describe("[registry][migration] manifest migration from etcd to registry storage", func() {
defer g.GinkgoRecover()
var oc = exutil.NewCLI("registry-migration", exutil.KubeConfigPath())
g.It("registry can get access to manifest [local]", func() {
oc.SetOutputDir(exutil.TestContext.OutputDir)
cleanUp := imagesutil.NewCleanUpContainer(oc)
defer cleanUp.Run()
g.By("set up policy for registry to have anonymous access to images")
err := oc.Run("policy").Args("add-role-to-user", "registry-viewer", "system:anonymous").Execute()
o.Expect(err).NotTo(o.HaveOccurred())
dClient, err := testutil.NewDockerClient()
o.Expect(err).NotTo(o.HaveOccurred())
registryURL, err := registryutil.GetDockerRegistryURL(oc)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("pushing image...")
imageDigest, _, err := imagesutil.BuildAndPushImageOfSizeWithDocker(oc, dClient, repoName, tagName, imageSize, 1, g.GinkgoWriter, true, true)
o.Expect(err).NotTo(o.HaveOccurred())
cleanUp.AddImage(imageDigest, "", "")
g.By("checking that the image converted...")
image, err := oc.AsAdmin().REST().Images().Get(imageDigest)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(len(image.DockerImageManifest)).Should(o.Equal(0))
imageMetadataNotEmpty(image)
g.By("getting image manifest from docker-registry...")
conn, err := regclient.NewClient(10*time.Second, true).Connect(registryURL, true)
o.Expect(err).NotTo(o.HaveOccurred())
_, manifest, err := conn.ImageManifest(oc.Namespace(), repoName, tagName)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(len(manifest)).Should(o.BeNumerically(">", 0))
g.By("restoring manifest...")
image, err = oc.AsAdmin().REST().Images().Get(imageDigest)
o.Expect(err).NotTo(o.HaveOccurred())
imageMetadataNotEmpty(image)
image.DockerImageManifest = string(manifest)
newImage, err := oc.AsAdmin().REST().Images().Update(image)
o.Expect(err).NotTo(o.HaveOccurred())
imageMetadataNotEmpty(newImage)
g.By("checking that the manifest is present in the image...")
image, err = oc.AsAdmin().REST().Images().Get(imageDigest)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(len(image.DockerImageManifest)).Should(o.BeNumerically(">", 0))
o.Expect(image.DockerImageManifest).Should(o.Equal(string(manifest)))
imageMetadataNotEmpty(image)
g.By("getting image manifest from docker-registry one more time...")
_, manifest, err = conn.ImageManifest(oc.Namespace(), repoName, tagName)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(len(manifest)).Should(o.BeNumerically(">", 0))
g.By("waiting until image is updated...")
err = waitForImageUpdate(oc, image)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("checking that the manifest was removed from the image...")
image, err = oc.AsAdmin().REST().Images().Get(imageDigest)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(len(image.DockerImageManifest)).Should(o.Equal(0))
imageMetadataNotEmpty(image)
g.By("getting image manifest from docker-registry to check if he's available...")
_, manifest, err = conn.ImageManifest(oc.Namespace(), repoName, tagName)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(len(manifest)).Should(o.BeNumerically(">", 0))
g.By("pulling image...")
authCfg, err := exutil.BuildAuthConfiguration(registryURL, oc)
o.Expect(err).NotTo(o.HaveOccurred())
opts := dockerClient.PullImageOptions{
Repository: authCfg.ServerAddress + "/" + oc.Namespace() + "/" + repoName,
Tag: tagName,
}
err = dClient.PullImage(opts, *authCfg)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("removing image...")
err = dClient.RemoveImage(opts.Repository)
o.Expect(err).NotTo(o.HaveOccurred())
})
})
func imageMetadataNotEmpty(image *imageapi.Image) {
o.Expect(len(image.DockerImageMetadata.ID)).Should(o.BeNumerically(">", 0))
o.Expect(len(image.DockerImageMetadata.Container)).Should(o.BeNumerically(">", 0))
o.Expect(len(image.DockerImageMetadata.DockerVersion)).Should(o.BeNumerically(">", 0))
o.Expect(len(image.DockerImageMetadata.Architecture)).Should(o.BeNumerically(">", 0))
}
func waitForImageUpdate(oc *exutil.CLI, image *imageapi.Image) error {
return wait.Poll(200*time.Millisecond, 2*time.Minute, func() (bool, error) {
newImage, err := oc.AsAdmin().REST().Images().Get(image.Name)
if err != nil {
return false, err
}
return (image.ResourceVersion < newImage.ResourceVersion), nil
})
}