Skip to content

Commit 1ff2229

Browse files
Merge pull request #20008 from smarterclayton/builder
[3.11 pre-rebase] - Prepare to move pkg/build/builder out of openshift binary
2 parents 29484db + 70597de commit 1ff2229

File tree

13 files changed

+278
-309
lines changed

13 files changed

+278
-309
lines changed

hack/import-restrictions.json

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
"allowedImportPackageRoots": [
159159
"vendor/k8s.io/apimachinery",
160160
"github.com/openshift/origin/pkg/image/apis/image/internal",
161+
"github.com/openshift/origin/pkg/image/apis/image/reference",
161162
"vendor/k8s.io/api",
162163
"vendor/github.com/openshift/api",
163164
"github.com/openshift/origin/pkg/api/apihelpers"

pkg/apps/apis/apps/zz_generated.deepcopy.go

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/build/builder/common.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"github.com/openshift/origin/pkg/build/builder/util/dockerfile"
3535
buildutil "github.com/openshift/origin/pkg/build/util"
3636
"github.com/openshift/origin/pkg/git"
37-
imageapi "github.com/openshift/origin/pkg/image/apis/image"
37+
imagereference "github.com/openshift/origin/pkg/image/apis/image/reference"
3838
utilglog "github.com/openshift/origin/pkg/util/glog"
3939
)
4040

@@ -363,7 +363,7 @@ func addBuildParameters(dir string, build *buildapiv1.Build, sourceInfo *git.Sou
363363
if build.Spec.Strategy.DockerStrategy != nil && build.Spec.Strategy.DockerStrategy.From != nil && build.Spec.Strategy.DockerStrategy.From.Kind == "DockerImage" {
364364
// Reduce the name to a minimal canonical form for the daemon
365365
name := build.Spec.Strategy.DockerStrategy.From.Name
366-
if ref, err := imageapi.ParseDockerImageReference(name); err == nil {
366+
if ref, err := imagereference.Parse(name); err == nil {
367367
name = ref.DaemonMinimal().Exact()
368368
}
369369
err := replaceLastFrom(node, name)

pkg/build/builder/dockerutil.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/openshift/source-to-image/pkg/tar"
2828
s2iutil "github.com/openshift/source-to-image/pkg/util"
2929

30-
imageapi "github.com/openshift/origin/pkg/image/apis/image"
30+
"github.com/openshift/origin/pkg/image/apis/image/reference"
3131
)
3232

3333
var (
@@ -114,13 +114,13 @@ func pullImage(client DockerClient, name string, authConfig docker.AuthConfigura
114114
glog.V(0).Infof("%s", s)
115115
}
116116

117-
ref, err := imageapi.ParseDockerImageReference(name)
117+
ref, err := reference.Parse(name)
118118
if err != nil {
119119
return err
120120
}
121121
tag := ref.ID
122122
if len(ref.ID) == 0 {
123-
tag = imageapi.DefaultImageTag
123+
tag = "latest"
124124
if len(ref.Tag) != 0 {
125125
tag = ref.Tag
126126
}

pkg/build/controller/strategy/util.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
buildapiv1 "github.com/openshift/api/build/v1"
1818
"github.com/openshift/origin/pkg/api/apihelpers"
1919
buildapi "github.com/openshift/origin/pkg/build/apis/build"
20-
imageapi "github.com/openshift/origin/pkg/image/apis/image"
20+
"github.com/openshift/origin/pkg/image/apis/image/reference"
2121
)
2222

2323
const (
@@ -242,7 +242,7 @@ func addOutputEnvVars(buildOutput *kapi.ObjectReference, output *[]v1.EnvVar) er
242242
if buildOutput.Kind != "DockerImage" {
243243
return fmt.Errorf("invalid build output kind %s, must be DockerImage", buildOutput.Kind)
244244
}
245-
ref, err := imageapi.ParseDockerImageReference(buildOutput.Name)
245+
ref, err := reference.Parse(buildOutput.Name)
246246
if err != nil {
247247
return err
248248
}

pkg/image/apis/image/helper.go

+4-179
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7-
"net"
87
"net/url"
98
"regexp"
109
"sort"
@@ -18,6 +17,7 @@ import (
1817
"github.com/golang/glog"
1918

2019
"github.com/openshift/origin/pkg/image/apis/image/internal/digest"
20+
"github.com/openshift/origin/pkg/image/apis/image/reference"
2121
)
2222

2323
const (
@@ -145,191 +145,16 @@ func ParseImageStreamTagName(istag string) (name string, tag string, err error)
145145
return
146146
}
147147

148-
// IsRegistryDockerHub returns true if the given registry name belongs to
149-
// Docker hub.
150-
func IsRegistryDockerHub(registry string) bool {
151-
switch registry {
152-
case DockerDefaultRegistry, DockerDefaultV1Registry, DockerDefaultV2Registry:
153-
return true
154-
default:
155-
return false
156-
}
157-
}
158-
159148
// ParseDockerImageReference parses a Docker pull spec string into a
160149
// DockerImageReference.
161-
func ParseDockerImageReference(spec string) (DockerImageReference, error) {
162-
var ref DockerImageReference
163-
164-
namedRef, err := parseNamedDockerImageReference(spec)
150+
func ParseDockerImageReference(spec string) (reference.DockerImageReference, error) {
151+
ref, err := reference.Parse(spec)
165152
if err != nil {
166153
return ref, err
167154
}
168-
169-
ref.Registry = namedRef.Registry
170-
ref.Namespace = namedRef.Namespace
171-
ref.Name = namedRef.Name
172-
ref.Tag = namedRef.Tag
173-
ref.ID = namedRef.ID
174-
175155
return ref, nil
176156
}
177157

178-
// Equal returns true if the other DockerImageReference is equivalent to the
179-
// reference r. The comparison applies defaults to the Docker image reference,
180-
// so that e.g., "foobar" equals "docker.io/library/foobar:latest".
181-
func (r DockerImageReference) Equal(other DockerImageReference) bool {
182-
defaultedRef := r.DockerClientDefaults()
183-
otherDefaultedRef := other.DockerClientDefaults()
184-
return defaultedRef == otherDefaultedRef
185-
}
186-
187-
// DockerClientDefaults sets the default values used by the Docker client.
188-
func (r DockerImageReference) DockerClientDefaults() DockerImageReference {
189-
if len(r.Registry) == 0 {
190-
r.Registry = DockerDefaultRegistry
191-
}
192-
if len(r.Namespace) == 0 && IsRegistryDockerHub(r.Registry) {
193-
r.Namespace = DockerDefaultNamespace
194-
}
195-
if len(r.Tag) == 0 {
196-
r.Tag = DefaultImageTag
197-
}
198-
return r
199-
}
200-
201-
// Minimal reduces a DockerImageReference to its minimalist form.
202-
func (r DockerImageReference) Minimal() DockerImageReference {
203-
if r.Tag == DefaultImageTag {
204-
r.Tag = ""
205-
}
206-
return r
207-
}
208-
209-
// AsRepository returns the reference without tags or IDs.
210-
func (r DockerImageReference) AsRepository() DockerImageReference {
211-
r.Tag = ""
212-
r.ID = ""
213-
return r
214-
}
215-
216-
// RepositoryName returns the registry relative name
217-
func (r DockerImageReference) RepositoryName() string {
218-
r.Tag = ""
219-
r.ID = ""
220-
r.Registry = ""
221-
return r.Exact()
222-
}
223-
224-
// RegistryHostPort returns the registry hostname and the port.
225-
// If the port is not specified in the registry hostname we default to 443.
226-
// This will also default to Docker client defaults if the registry hostname is empty.
227-
func (r DockerImageReference) RegistryHostPort(insecure bool) (string, string) {
228-
registryHost := r.AsV2().DockerClientDefaults().Registry
229-
if strings.Contains(registryHost, ":") {
230-
hostname, port, _ := net.SplitHostPort(registryHost)
231-
return hostname, port
232-
}
233-
if insecure {
234-
return registryHost, "80"
235-
}
236-
return registryHost, "443"
237-
}
238-
239-
// RepositoryName returns the registry relative name
240-
func (r DockerImageReference) RegistryURL() *url.URL {
241-
return &url.URL{
242-
Scheme: "https",
243-
Host: r.AsV2().Registry,
244-
}
245-
}
246-
247-
// DaemonMinimal clears defaults that Docker assumes.
248-
func (r DockerImageReference) DaemonMinimal() DockerImageReference {
249-
switch r.Registry {
250-
case DockerDefaultV1Registry, DockerDefaultV2Registry:
251-
r.Registry = DockerDefaultRegistry
252-
}
253-
if IsRegistryDockerHub(r.Registry) && r.Namespace == DockerDefaultNamespace {
254-
r.Namespace = ""
255-
}
256-
return r.Minimal()
257-
}
258-
259-
func (r DockerImageReference) AsV2() DockerImageReference {
260-
switch r.Registry {
261-
case DockerDefaultV1Registry, DockerDefaultRegistry:
262-
r.Registry = DockerDefaultV2Registry
263-
}
264-
return r
265-
}
266-
267-
// MostSpecific returns the most specific image reference that can be constructed from the
268-
// current ref, preferring an ID over a Tag. Allows client code dealing with both tags and IDs
269-
// to get the most specific reference easily.
270-
func (r DockerImageReference) MostSpecific() DockerImageReference {
271-
if len(r.ID) == 0 {
272-
return r
273-
}
274-
if _, err := digest.ParseDigest(r.ID); err == nil {
275-
r.Tag = ""
276-
return r
277-
}
278-
if len(r.Tag) == 0 {
279-
r.Tag, r.ID = r.ID, ""
280-
return r
281-
}
282-
return r
283-
}
284-
285-
// NameString returns the name of the reference with its tag or ID.
286-
func (r DockerImageReference) NameString() string {
287-
switch {
288-
case len(r.Name) == 0:
289-
return ""
290-
case len(r.Tag) > 0:
291-
return r.Name + ":" + r.Tag
292-
case len(r.ID) > 0:
293-
var ref string
294-
if _, err := digest.ParseDigest(r.ID); err == nil {
295-
// if it parses as a digest, its v2 pull by id
296-
ref = "@" + r.ID
297-
} else {
298-
// if it doesn't parse as a digest, it's presumably a v1 registry by-id tag
299-
ref = ":" + r.ID
300-
}
301-
return r.Name + ref
302-
default:
303-
return r.Name
304-
}
305-
}
306-
307-
// Exact returns a string representation of the set fields on the DockerImageReference
308-
func (r DockerImageReference) Exact() string {
309-
name := r.NameString()
310-
if len(name) == 0 {
311-
return name
312-
}
313-
s := r.Registry
314-
if len(s) > 0 {
315-
s += "/"
316-
}
317-
318-
if len(r.Namespace) != 0 {
319-
s += r.Namespace + "/"
320-
}
321-
return s + name
322-
}
323-
324-
// String converts a DockerImageReference to a Docker pull spec (which implies a default namespace
325-
// according to V1 Docker registry rules). Use Exact() if you want no defaulting.
326-
func (r DockerImageReference) String() string {
327-
if len(r.Namespace) == 0 && IsRegistryDockerHub(r.Registry) {
328-
r.Namespace = DockerDefaultNamespace
329-
}
330-
return r.Exact()
331-
}
332-
333158
// SplitImageStreamTag turns the name of an ImageStreamTag into Name and Tag.
334159
// It returns false if the tag was not properly specified in the name.
335160
func SplitImageStreamTag(nameAndTag string) (name string, tag string, ok bool) {
@@ -790,7 +615,7 @@ func ResolveImageID(stream *ImageStream, imageID string) (*TagEvent, error) {
790615
// MostAccuratePullSpec returns a docker image reference that uses the current ID if possible, the current tag otherwise, and
791616
// returns false if the reference if the spec could not be parsed. The returned spec has all client defaults applied.
792617
func MostAccuratePullSpec(pullSpec string, id, tag string) (string, bool) {
793-
ref, err := ParseDockerImageReference(pullSpec)
618+
ref, err := reference.Parse(pullSpec)
794619
if err != nil {
795620
return pullSpec, false
796621
}

pkg/image/apis/image/reference.go

-51
This file was deleted.

0 commit comments

Comments
 (0)