Skip to content

Commit

Permalink
Rename image.spec.image to image.spec.tag
Browse files Browse the repository at this point in the history
+ It is not an actual image but the tag the built images will be tagged with
+ It is common for the “tag” to refer to a fully-qualified tag
   aka `docker build -t reg.com/name`
+ Resolves #59, #40
  • Loading branch information
matthewmcnew committed Aug 2, 2019
1 parent 99cff3f commit e8846bf
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ kubectl cluster-info # ensure you have access to a cluster
metadata:
name: sample-image
spec:
tag: gcr.io/project-name/app
serviceAccount: service-account
builderRef: sample-builder
image: gcr.io/project-name/app
cacheSize: "1.5Gi"
failedBuildHistoryLimit: 5
successBuildHistoryLimit: 5
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/build/v1alpha1/build_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (b *Build) BuildPod(config BuildPodConfig, secrets []corev1.Secret) (*corev
"-helpers=false",
"-group=/layers/group.toml",
"-analyzed=/layers/analyzed.toml",
b.Spec.Image,
b.Spec.Tag,
},
VolumeMounts: []corev1.VolumeMount{
layersVolume,
Expand Down Expand Up @@ -277,7 +277,7 @@ func buildExporterArgs(build *Build) []string {
"-app=/workspace",
"-group=/layers/group.toml",
"-analyzed=/layers/analyzed.toml",
build.Spec.Image}
build.Spec.Tag}
args = append(args, build.Spec.AdditionalImageNames...)
return args
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/build/v1alpha1/build_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
},
},
Spec: v1alpha1.BuildSpec{
Image: "someimage/name",
Tag: "someimage/name",
ServiceAccount: serviceAccount,
Builder: builderImage,
Env: []corev1.EnvVar{
Expand Down Expand Up @@ -254,7 +254,7 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
"-helpers=false",
"-group=/layers/group.toml",
"-analyzed=/layers/analyzed.toml",
build.Spec.Image,
build.Spec.Tag,
}, pod.Spec.InitContainers[5].Args)
})

Expand Down Expand Up @@ -288,7 +288,7 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
"-app=/workspace",
"-group=/layers/group.toml",
"-analyzed=/layers/analyzed.toml",
build.Spec.Image,
build.Spec.Tag,
"someimage/name:tag2",
"someimage/name:tag3",
}, pod.Spec.InitContainers[7].Args)
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/build/v1alpha1/build_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (
)

type BuildSpec struct {
Image string `json:"image"`
Tag string `json:"tag"`
Builder string `json:"builder"`
ServiceAccount string `json:"serviceAccount"`
Source Source `json:"source"`
Expand Down Expand Up @@ -79,8 +79,8 @@ func (b *Build) ServiceAccount() string {
return b.Spec.ServiceAccount
}

func (b *Build) RepoName() string {
return b.Spec.Image
func (b *Build) Tag() string {
return b.Spec.Tag
}

func (b *Build) Namespace() string {
Expand Down Expand Up @@ -111,7 +111,7 @@ func (b *Build) BuiltImage() string {
return ""
}

return b.Spec.Image + "@" + b.Status.SHA
return b.Spec.Tag + "@" + b.Status.SHA
}

func (b *Build) IsSuccess() bool {
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/build/v1alpha1/image_builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (im *Image) buildNeeded(lastBuild *Build, sourceResolver *SourceResolver, b
return []string{BuildReasonConfig}, true
}

if im.Spec.Image != lastBuild.Spec.Image {
if im.Spec.Tag != lastBuild.Spec.Tag {
return []string{BuildReasonConfig}, true
}

Expand Down Expand Up @@ -82,7 +82,7 @@ func (im *Image) build(sourceResolver *SourceResolver, builder *Builder, reasons
},
},
Spec: BuildSpec{
Image: im.Spec.Image,
Tag: im.Spec.Tag,
Builder: builder.Spec.Image,
Env: im.Spec.Build.Env,
Resources: im.Spec.Build.Resources,
Expand Down Expand Up @@ -163,7 +163,7 @@ func (im *Image) generateImageNames(buildNumber string) []string {
}
now := time.Now()

tag, err := name.NewTag(im.Spec.Image, name.WeakValidation)
tag, err := name.NewTag(im.Spec.Tag, name.WeakValidation)
if err != nil {
// We assume that if the Image Name cannot be parsed the image will not be successfully built
// in this case we can just ignore any additional image names
Expand Down
14 changes: 7 additions & 7 deletions pkg/apis/build/v1alpha1/image_builds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) {
Name: "image-name",
},
Spec: ImageSpec{
Image: "some/image",
Tag: "some/image",
ServiceAccount: "some/service-account",
BuilderRef: "some/builder",
Build: ImageBuild{
Expand Down Expand Up @@ -66,7 +66,7 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) {
Name: "image-name",
},
Spec: BuildSpec{
Image: "some/image",
Tag: "some/image",
Builder: "some/builder",
ServiceAccount: "some/serviceaccount",
Source: Source{
Expand Down Expand Up @@ -112,7 +112,7 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) {
})

it("true for different image", func() {
image.Spec.Image = "different"
image.Spec.Tag = "different"

reasons, needed := image.buildNeeded(build, sourceResolver, builder)
assert.True(t, needed)
Expand Down Expand Up @@ -303,30 +303,30 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) {
})

it("with excludes additional images names when explicitly disabled", func() {
image.Spec.Image = "imagename/foo:test"
image.Spec.Tag = "imagename/foo:test"
image.Spec.DisableAdditionalImageNames = true
build := image.build(sourceResolver, builder, []string{BuildReasonConfig}, 1)
require.Len(t, build.Spec.AdditionalImageNames, 0)
})

when("generates additional image names for a provided build number", func() {
it("with tag prefix if image name has a tag", func() {
image.Spec.Image = "gcr.io/imagename/foo:test"
image.Spec.Tag = "gcr.io/imagename/foo:test"
build := image.build(sourceResolver, builder, []string{BuildReasonConfig}, 45)
require.Len(t, build.Spec.AdditionalImageNames, 1)
require.Regexp(t, "gcr.io/imagename/foo:test-b45\\.\\d{8}\\.\\d{6}", build.Spec.AdditionalImageNames[0])
})

it("without tag prefix if image name has no provided tag", func() {
image.Spec.Image = "gcr.io/imagename/notags"
image.Spec.Tag = "gcr.io/imagename/notags"
build := image.build(sourceResolver, builder, []string{BuildReasonConfig}, 1)

require.Len(t, build.Spec.AdditionalImageNames, 1)
require.Regexp(t, "gcr.io/imagename/notags:b1\\.\\d{8}\\.\\d{6}", build.Spec.AdditionalImageNames[0])
})

it("without tag prefix if image name has the tag 'latest' provided", func() {
image.Spec.Image = "gcr.io/imagename/tagged:latest"
image.Spec.Tag = "gcr.io/imagename/tagged:latest"
build := image.build(sourceResolver, builder, []string{BuildReasonConfig}, 1)

require.Len(t, build.Spec.AdditionalImageNames, 1)
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/build/v1alpha1/image_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Image struct {
}

type ImageSpec struct {
Image string `json:"image"`
Tag string `json:"tag"`
BuilderRef string `json:"builderRef"`
ServiceAccount string `json:"serviceAccount"`
Source Source `json:"source"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/buildpod/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func testGenerator(t *testing.T, when spec.G, it spec.S) {
Name: "simple-build",
},
Spec: v1alpha1.BuildSpec{
Image: "image/name",
Tag: "image/name",
Builder: "builder/name",
ServiceAccount: serviceAccountName,
Source: v1alpha1.Source{
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/v1alpha1/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func testBuildReconciler(t *testing.T, when spec.G, it spec.S) {
Generation: originalGeneration,
},
Spec: v1alpha1.BuildSpec{
Image: "someimage/name",
Tag: "someimage/name",
ServiceAccount: serviceAccountName,
Builder: "somebuilder/123",
Env: []corev1.EnvVar{
Expand Down
24 changes: 12 additions & 12 deletions pkg/reconciler/v1alpha1/image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
},
},
Spec: v1alpha1.ImageSpec{
Image: "some/image",
Tag: "some/image",
ServiceAccount: serviceAccount,
BuilderRef: builderName,
Source: v1alpha1.Source{
Expand Down Expand Up @@ -569,7 +569,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
},
},
Spec: v1alpha1.BuildSpec{
Image: image.Spec.Image,
Tag: image.Spec.Tag,
Builder: builder.Spec.Image,
ServiceAccount: image.Spec.ServiceAccount,
Source: v1alpha1.Source{
Expand Down Expand Up @@ -633,7 +633,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
},
},
Spec: v1alpha1.BuildSpec{
Image: image.Spec.Image,
Tag: image.Spec.Tag,
Builder: builder.Spec.Image,
ServiceAccount: image.Spec.ServiceAccount,
Source: v1alpha1.Source{
Expand Down Expand Up @@ -689,7 +689,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
},
},
Spec: v1alpha1.BuildSpec{
Image: image.Spec.Image,
Tag: image.Spec.Tag,
Builder: builder.Spec.Image,
ServiceAccount: "old-service-account",
Source: v1alpha1.Source{
Expand Down Expand Up @@ -731,7 +731,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
},
},
Spec: v1alpha1.BuildSpec{
Image: image.Spec.Image,
Tag: image.Spec.Tag,
Builder: builder.Spec.Image,
ServiceAccount: image.Spec.ServiceAccount,
Source: v1alpha1.Source{
Expand Down Expand Up @@ -796,7 +796,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
},
},
Spec: v1alpha1.BuildSpec{
Image: image.Spec.Image,
Tag: image.Spec.Tag,
Builder: builder.Spec.Image,
ServiceAccount: image.Spec.ServiceAccount,
Source: v1alpha1.Source{
Expand Down Expand Up @@ -838,7 +838,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
},
},
Spec: v1alpha1.BuildSpec{
Image: image.Spec.Image,
Tag: image.Spec.Tag,
Builder: builder.Spec.Image,
ServiceAccount: image.Spec.ServiceAccount,
Source: v1alpha1.Source{
Expand Down Expand Up @@ -910,7 +910,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
},
},
Spec: v1alpha1.BuildSpec{
Image: image.Spec.Image,
Tag: image.Spec.Tag,
Builder: builder.Spec.Image,
ServiceAccount: image.Spec.ServiceAccount,
Source: v1alpha1.Source{
Expand Down Expand Up @@ -958,7 +958,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
},
},
Spec: v1alpha1.BuildSpec{
Image: image.Spec.Image,
Tag: image.Spec.Tag,
Builder: builder.Spec.Image,
ServiceAccount: image.Spec.ServiceAccount,
Source: v1alpha1.Source{
Expand Down Expand Up @@ -1015,7 +1015,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
},
},
Spec: v1alpha1.BuildSpec{
Image: image.Spec.Image,
Tag: image.Spec.Tag,
Builder: builder.Spec.Image,
ServiceAccount: "old-service-account",
Source: v1alpha1.Source{
Expand Down Expand Up @@ -1066,7 +1066,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
},
},
Spec: v1alpha1.BuildSpec{
Image: image.Spec.Image,
Tag: image.Spec.Tag,
Builder: builder.Spec.Image,
ServiceAccount: image.Spec.ServiceAccount,
Source: v1alpha1.Source{
Expand Down Expand Up @@ -1239,7 +1239,7 @@ func builds(image *v1alpha1.Image, sourceResolver *v1alpha1.SourceResolver, coun
CreationTimestamp: metav1.NewTime(time.Now().Add(time.Duration(i) * time.Minute)),
},
Spec: v1alpha1.BuildSpec{
Image: image.Spec.Image,
Tag: image.Spec.Tag,
Builder: "some/builder",
ServiceAccount: image.Spec.ServiceAccount,
Source: v1alpha1.Source{
Expand Down
8 changes: 4 additions & 4 deletions pkg/registry/image_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type ImageFactory struct {
}

func (f *ImageFactory) NewRemote(imageRef ImageRef) (RemoteImage, error) {
remote, err := imgutil.NewRemoteImage(imageRef.RepoName(), f.KeychainFactory.KeychainForImageRef(imageRef))
return remote, errors.Wrapf(err, "could not create remote image from ref %s", imageRef.RepoName())
remote, err := imgutil.NewRemoteImage(imageRef.Tag(), f.KeychainFactory.KeychainForImageRef(imageRef))
return remote, errors.Wrapf(err, "could not create remote image from ref %s", imageRef.Tag())
}

type KeychainFactory interface {
Expand All @@ -24,7 +24,7 @@ type KeychainFactory interface {
type ImageRef interface {
ServiceAccount() string
Namespace() string
RepoName() string
Tag() string
}

type noAuthImageRef struct {
Expand All @@ -35,7 +35,7 @@ func NewNoAuthImageRef(repoName string) *noAuthImageRef {
return &noAuthImageRef{repoName: repoName}
}

func (na *noAuthImageRef) RepoName() string {
func (na *noAuthImageRef) Tag() string {
return na.repoName
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/secrets_keychain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (f *fakeImageRef) Namespace() string {
return f.namespace
}

func (f *fakeImageRef) RepoName() string {
func (f *fakeImageRef) Tag() string {
return "NOT-NEEDED"
}

Expand Down
2 changes: 1 addition & 1 deletion samples/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
spec:
serviceAccount: serviceaccount
builder: cloudfoundry/cnb
image: sample/image
tag: sample/image
source:
git:
url: https://github.com/buildpack/sample-java-app.git
Expand Down
2 changes: 1 addition & 1 deletion samples/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: sample
spec:
builderRef: sample-builder
image: registry.default.svc.cluster.local:5000/sample/image
tag: registry.default.svc.cluster.local:5000/sample/image
source:
git:
url: https://github.com/buildpack/sample-java-app.git
Expand Down
2 changes: 1 addition & 1 deletion test/execute_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func testCreateImage(t *testing.T, when spec.G, it spec.S) {
Name: imageName,
},
Spec: v1alpha1.ImageSpec{
Image: cfg.imageTag,
Tag: cfg.imageTag,
BuilderRef: builderName,
ServiceAccount: serviceAccountName,
Source: v1alpha1.Source{
Expand Down

0 comments on commit e8846bf

Please sign in to comment.