From 8390bfd0213cc3b5987b8b6c62844df2bc6576e2 Mon Sep 17 00:00:00 2001 From: dumez-k Date: Tue, 16 Mar 2021 15:47:20 -0400 Subject: [PATCH 1/7] - Rebasing against main branch - Setting the environment variables to actually show the log messages - Fixing feedback from review Signed-off-by: Juan Bustamante --- cmd/build-init/main.go | 7 +++++++ hack/common.sh | 2 +- pkg/apis/build/v1alpha2/build_pod.go | 12 ++++++++++++ pkg/apis/build/v1alpha2/builder_resource.go | 1 + pkg/apis/build/v1alpha2/image_builds_test.go | 8 ++++++++ pkg/apis/core/v1alpha1/build_types.go | 2 ++ pkg/duckbuilder/duck_builder.go | 11 +++++++++++ pkg/reconciler/image/build_required_test.go | 6 ++++++ pkg/reconciler/image/image_test.go | 11 +++++++++++ test/execute_build_test.go | 3 +++ 10 files changed, 62 insertions(+), 1 deletion(-) diff --git a/cmd/build-init/main.go b/cmd/build-init/main.go index 5e35e7a57..68802430e 100644 --- a/cmd/build-init/main.go +++ b/cmd/build-init/main.go @@ -38,6 +38,10 @@ var ( buildChanges = flag.String("build-changes", os.Getenv("BUILD_CHANGES"), "JSON string of build changes and their reason") descriptorPath = flag.String("project-descriptor-path", os.Getenv("PROJECT_DESCRIPTOR_PATH"), "path to project descriptor file") + builderImage= flag.String("builder-image", os.Getenv("BUILDER_IMAGE"), "The builder image used to build the application") + builderName = flag.String("builder-name", os.Getenv("BUILD_NAME"), "The builder name provided during creation") + builderKind = flag.String("builder-kind", os.Getenv("BUILD_KIND"), "The builder kind") + basicGitCredentials flaghelpers.CredentialsFlags sshGitCredentials flaghelpers.CredentialsFlags dockerCredentials flaghelpers.CredentialsFlags @@ -138,6 +142,9 @@ func main() { logger.Fatalf("error while processing the project descriptor: %s", err) } + logger.Printf("Builder:\n Image:%s \n Name:%s \n Kind:%s ", *builderImage, + *builderName, *builderKind) + err = cnb.SetupPlatformEnvVars(platformDir, *platformEnvVars) if err != nil { logger.Fatalf("error setting up platform env vars %s", err) diff --git a/hack/common.sh b/hack/common.sh index 246917349..30828e0a4 100644 --- a/hack/common.sh +++ b/hack/common.sh @@ -60,4 +60,4 @@ function compile() { -v rebase_image=${rebase_image} \ -v completion_image=${completion_image} \ -v lifecycle_image=${lifecycle_image} > $output -} \ No newline at end of file +} diff --git a/pkg/apis/build/v1alpha2/build_pod.go b/pkg/apis/build/v1alpha2/build_pod.go index c1b1d8943..8196d654c 100644 --- a/pkg/apis/build/v1alpha2/build_pod.go +++ b/pkg/apis/build/v1alpha2/build_pod.go @@ -375,6 +375,18 @@ func (b *Build) BuildPod(images BuildPodImages, buildContext BuildContext) (*cor Name: "RUN_IMAGE", Value: buildContext.BuildPodBuilderConfig.RunImage, }, + corev1.EnvVar{ + Name: "BUILDER_IMAGE", + Value: b.Spec.Builder.Image, + }, + corev1.EnvVar{ + Name: "BUILD_NAME", + Value: b.Spec.Builder.Name, + }, + corev1.EnvVar{ + Name: "BUILD_KIND", + Value: b.Spec.Builder.Kind, + }, corev1.EnvVar{ Name: "DNS_PROBE_HOSTNAME", Value: dnsProbeHost, diff --git a/pkg/apis/build/v1alpha2/builder_resource.go b/pkg/apis/build/v1alpha2/builder_resource.go index 21e6a18be..a074b1ff4 100644 --- a/pkg/apis/build/v1alpha2/builder_resource.go +++ b/pkg/apis/build/v1alpha2/builder_resource.go @@ -8,4 +8,5 @@ type BuilderResource interface { Ready() bool BuildpackMetadata() corev1alpha1.BuildpackMetadataList RunImage() string + GetKind() string } diff --git a/pkg/apis/build/v1alpha2/image_builds_test.go b/pkg/apis/build/v1alpha2/image_builds_test.go index 95424ee6a..e49ed7b45 100644 --- a/pkg/apis/build/v1alpha2/image_builds_test.go +++ b/pkg/apis/build/v1alpha2/image_builds_test.go @@ -55,6 +55,7 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) { builder := &TestBuilderResource{ Name: "builder-Name", LatestImage: "some/builder@sha256:builder-digest", + Kind: "builder", BuilderReady: true, BuilderMetadata: []corev1alpha1.BuildpackMetadata{ {Id: "buildpack.matches", Version: "1"}, @@ -349,6 +350,7 @@ type TestBuilderResource struct { BuilderReady bool BuilderMetadata []corev1alpha1.BuildpackMetadata ImagePullSecrets []corev1.LocalObjectReference + Kind string LatestImage string LatestRunImage string Name string @@ -358,6 +360,8 @@ func (t TestBuilderResource) BuildBuilderSpec() corev1alpha1.BuildBuilderSpec { return corev1alpha1.BuildBuilderSpec{ Image: t.LatestImage, ImagePullSecrets: t.ImagePullSecrets, + Kind: t.Kind, + Name: t.Name, } } @@ -376,3 +380,7 @@ func (t TestBuilderResource) RunImage() string { func (t TestBuilderResource) GetName() string { return t.Name } + +func(t TestBuilderResource) GetKind() string{ + return t.Kind +} diff --git a/pkg/apis/core/v1alpha1/build_types.go b/pkg/apis/core/v1alpha1/build_types.go index 47df46d81..c8386df24 100644 --- a/pkg/apis/core/v1alpha1/build_types.go +++ b/pkg/apis/core/v1alpha1/build_types.go @@ -19,6 +19,8 @@ type BuildBuilderSpec struct { // +patchStrategy=merge // +listType ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,15,rep,name=imagePullSecrets"` + Kind string `json:"kind,omitempty"` + Name string `json:"name,omitempty"` } // +k8s:openapi-gen=true diff --git a/pkg/duckbuilder/duck_builder.go b/pkg/duckbuilder/duck_builder.go index b140db3f4..fed8de34a 100644 --- a/pkg/duckbuilder/duck_builder.go +++ b/pkg/duckbuilder/duck_builder.go @@ -15,6 +15,15 @@ type DuckBuilder struct { Spec DuckBuilderSpec `json:"spec"` Status buildapi.BuilderStatus `json:"status"` } + +func (b *DuckBuilder) GetName() string { + return b.Name +} + +func (b *DuckBuilder) GetKind() string { + return b.Kind +} + type DuckBuilderSpec struct { ImagePullSecrets []v1.LocalObjectReference } @@ -28,6 +37,8 @@ func (b *DuckBuilder) BuildBuilderSpec() corev1alpha1.BuildBuilderSpec { return corev1alpha1.BuildBuilderSpec{ Image: b.Status.LatestImage, ImagePullSecrets: b.Spec.ImagePullSecrets, + Name: b.Name, + Kind: b.Kind, } } diff --git a/pkg/reconciler/image/build_required_test.go b/pkg/reconciler/image/build_required_test.go index b10183055..e889604fa 100644 --- a/pkg/reconciler/image/build_required_test.go +++ b/pkg/reconciler/image/build_required_test.go @@ -63,6 +63,7 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) { {Id: "buildpack.matches", Version: "1"}, }, LatestRunImage: "some.registry.io/run-image@sha256:67e3de2af270bf09c02e9a644aeb7e87e6b3c049abe6766bf6b6c3728a83e7fb", + } latestBuild := &buildapi.Build{ @@ -803,6 +804,7 @@ type TestBuilderResource struct { LatestImage string LatestRunImage string Name string + Kind string } func (t TestBuilderResource) BuildBuilderSpec() corev1alpha1.BuildBuilderSpec { @@ -827,3 +829,7 @@ func (t TestBuilderResource) RunImage() string { func (t TestBuilderResource) GetName() string { return t.Name } + +func (t TestBuilderResource) GetKind() string { + return t.Kind +} diff --git a/pkg/reconciler/image/image_test.go b/pkg/reconciler/image/image_test.go index 7b96d74b8..05e43423e 100644 --- a/pkg/reconciler/image/image_test.go +++ b/pkg/reconciler/image/image_test.go @@ -715,6 +715,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: builder.Status.LatestImage, + Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Cache: &buildapi.BuildCacheConfig{}, @@ -805,6 +806,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: clusterBuilder.Status.LatestImage, + Name: clusterBuilderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Cache: &buildapi.BuildCacheConfig{}, @@ -895,6 +897,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: builder.Status.LatestImage, + Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Cache: &buildapi.BuildCacheConfig{}, @@ -986,6 +989,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: clusterBuilder.Status.LatestImage, + Name: clusterBuilderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Cache: &buildapi.BuildCacheConfig{}, @@ -1079,6 +1083,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: builder.Status.LatestImage, + Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Source: corev1alpha1.SourceConfig{ @@ -1225,6 +1230,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: builder.Status.LatestImage, + Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Source: corev1alpha1.SourceConfig{ @@ -1351,6 +1357,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: builder.Status.LatestImage, + Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Source: corev1alpha1.SourceConfig{ @@ -1511,6 +1518,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: updatedBuilderImage, + Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Source: corev1alpha1.SourceConfig{ @@ -1603,6 +1611,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: updatedBuilderImage, + Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Source: corev1alpha1.SourceConfig{ @@ -1666,6 +1675,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: updatedBuilderImage, + Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Source: corev1alpha1.SourceConfig{ @@ -1811,6 +1821,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: builder.Status.LatestImage, + Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Source: corev1alpha1.SourceConfig{ diff --git a/test/execute_build_test.go b/test/execute_build_test.go index 696553f58..bda8c328f 100644 --- a/test/execute_build_test.go +++ b/test/execute_build_test.go @@ -531,6 +531,9 @@ func validateImageCreate(t *testing.T, clients *clients, image *buildapi.Image, _, _, err = registryClient.Fetch(authn.DefaultKeychain, image.Spec.Tag) require.NoError(t, err) + //TODO: Delete me: + t.Logf("Build Log: %s", logTail.String()) + eventually(t, func() bool { return strings.Contains(logTail.String(), "Build successful") }, 1*time.Second, 10*time.Second) From 0d7477beea668a7cd8b2c579d8cd5a56d80dfb8e Mon Sep 17 00:00:00 2001 From: Juan Bustamante Date: Thu, 7 Apr 2022 18:00:05 -0500 Subject: [PATCH 2/7] Adding the getKind() method again because otherwise is not shown in the log Signed-off-by: Juan Bustamante --- cmd/build-init/main.go | 2 +- pkg/apis/build/v1alpha1/builder_resource.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/build-init/main.go b/cmd/build-init/main.go index 68802430e..63b216649 100644 --- a/cmd/build-init/main.go +++ b/cmd/build-init/main.go @@ -142,7 +142,7 @@ func main() { logger.Fatalf("error while processing the project descriptor: %s", err) } - logger.Printf("Builder:\n Image:%s \n Name:%s \n Kind:%s ", *builderImage, + logger.Printf("Builder:\n Image: %s \n Name: %s \n Kind: %s ", *builderImage, *builderName, *builderKind) err = cnb.SetupPlatformEnvVars(platformDir, *platformEnvVars) diff --git a/pkg/apis/build/v1alpha1/builder_resource.go b/pkg/apis/build/v1alpha1/builder_resource.go index 7646d633f..d59675394 100644 --- a/pkg/apis/build/v1alpha1/builder_resource.go +++ b/pkg/apis/build/v1alpha1/builder_resource.go @@ -8,4 +8,5 @@ type BuilderResource interface { Ready() bool BuildpackMetadata() corev1alpha1.BuildpackMetadataList RunImage() string + GetKind() string } From c83f8e508807052ea3d5bdf2e8ff799e85da1cad Mon Sep 17 00:00:00 2001 From: Juan Bustamante Date: Tue, 12 Apr 2022 16:08:23 -0500 Subject: [PATCH 3/7] Adding integration test Signed-off-by: Juan Bustamante --- cmd/build-init/main.go | 4 ++-- pkg/apis/build/v1alpha2/build_pod.go | 10 +++++----- test/execute_build_test.go | 17 +++++++++++++++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/cmd/build-init/main.go b/cmd/build-init/main.go index 63b216649..b16dbf260 100644 --- a/cmd/build-init/main.go +++ b/cmd/build-init/main.go @@ -39,8 +39,8 @@ var ( descriptorPath = flag.String("project-descriptor-path", os.Getenv("PROJECT_DESCRIPTOR_PATH"), "path to project descriptor file") builderImage= flag.String("builder-image", os.Getenv("BUILDER_IMAGE"), "The builder image used to build the application") - builderName = flag.String("builder-name", os.Getenv("BUILD_NAME"), "The builder name provided during creation") - builderKind = flag.String("builder-kind", os.Getenv("BUILD_KIND"), "The builder kind") + builderName = flag.String("builder-name", os.Getenv("BUILDER_NAME"), "The builder name provided during creation") + builderKind = flag.String("builder-kind", os.Getenv("BUILDER_KIND"), "The builder kind") basicGitCredentials flaghelpers.CredentialsFlags sshGitCredentials flaghelpers.CredentialsFlags diff --git a/pkg/apis/build/v1alpha2/build_pod.go b/pkg/apis/build/v1alpha2/build_pod.go index 8196d654c..7654b533a 100644 --- a/pkg/apis/build/v1alpha2/build_pod.go +++ b/pkg/apis/build/v1alpha2/build_pod.go @@ -377,15 +377,15 @@ func (b *Build) BuildPod(images BuildPodImages, buildContext BuildContext) (*cor }, corev1.EnvVar{ Name: "BUILDER_IMAGE", - Value: b.Spec.Builder.Image, + Value: b.BuilderSpec().Image, }, corev1.EnvVar{ - Name: "BUILD_NAME", - Value: b.Spec.Builder.Name, + Name: "BUILDER_NAME", + Value: b.BuilderSpec().Name, }, corev1.EnvVar{ - Name: "BUILD_KIND", - Value: b.Spec.Builder.Kind, + Name: "BUILDER_KIND", + Value: b.BuilderSpec().Kind, }, corev1.EnvVar{ Name: "DNS_PROBE_HOSTNAME", diff --git a/test/execute_build_test.go b/test/execute_build_test.go index bda8c328f..38b3ee768 100644 --- a/test/execute_build_test.go +++ b/test/execute_build_test.go @@ -531,8 +531,7 @@ func validateImageCreate(t *testing.T, clients *clients, image *buildapi.Image, _, _, err = registryClient.Fetch(authn.DefaultKeychain, image.Spec.Tag) require.NoError(t, err) - //TODO: Delete me: - t.Logf("Build Log: %s", logTail.String()) + validateBuildLog(t, clients, image, ctx, logTail.String()) eventually(t, func() bool { return strings.Contains(logTail.String(), "Build successful") @@ -550,6 +549,20 @@ func validateImageCreate(t *testing.T, clients *clients, image *buildapi.Image, assert.Equal(t, expectedResources, pod.Spec.Containers[0].Resources) } +func validateBuildLog(t *testing.T, clients *clients, image *buildapi.Image, ctx context.Context, output string) { + buildList, err := clients.client.KpackV1alpha2().Builds(image.Namespace).List(ctx, metav1.ListOptions{ + LabelSelector: fmt.Sprintf("image.kpack.io/image=%s", image.Name), + }) + require.NoError(t, err) + + require.Len(t, buildList.Items, 1) + buildSpec := buildList.Items[0].Spec.DeepCopy() + + assert.Contains(t, output, fmt.Sprintf("Name: %s", buildSpec.Builder.Name)) + assert.Contains(t, output, fmt.Sprintf("Image: %s", buildSpec.Builder.Image)) + assert.Contains(t, output, fmt.Sprintf("Kind: %s", buildSpec.Builder.Kind)) +} + func validateRebase(t *testing.T, ctx context.Context, clients *clients, imageName, testNamespace string) { var rebaseBuildName = imageName + "-rebase" From be25bc5ece26c1452d3e7aa71807f35744ade942 Mon Sep 17 00:00:00 2001 From: Juan Bustamante Date: Tue, 19 Apr 2022 15:59:08 -0500 Subject: [PATCH 4/7] Removing unused method Signed-off-by: Juan Bustamante --- pkg/apis/build/v1alpha1/builder_resource.go | 1 - pkg/apis/build/v1alpha2/builder_resource.go | 1 - pkg/apis/build/v1alpha2/image_builds_test.go | 4 ---- pkg/duckbuilder/duck_builder.go | 4 ---- pkg/reconciler/image/build_required_test.go | 4 ---- 5 files changed, 14 deletions(-) diff --git a/pkg/apis/build/v1alpha1/builder_resource.go b/pkg/apis/build/v1alpha1/builder_resource.go index d59675394..7646d633f 100644 --- a/pkg/apis/build/v1alpha1/builder_resource.go +++ b/pkg/apis/build/v1alpha1/builder_resource.go @@ -8,5 +8,4 @@ type BuilderResource interface { Ready() bool BuildpackMetadata() corev1alpha1.BuildpackMetadataList RunImage() string - GetKind() string } diff --git a/pkg/apis/build/v1alpha2/builder_resource.go b/pkg/apis/build/v1alpha2/builder_resource.go index a074b1ff4..21e6a18be 100644 --- a/pkg/apis/build/v1alpha2/builder_resource.go +++ b/pkg/apis/build/v1alpha2/builder_resource.go @@ -8,5 +8,4 @@ type BuilderResource interface { Ready() bool BuildpackMetadata() corev1alpha1.BuildpackMetadataList RunImage() string - GetKind() string } diff --git a/pkg/apis/build/v1alpha2/image_builds_test.go b/pkg/apis/build/v1alpha2/image_builds_test.go index e49ed7b45..1ce1efca3 100644 --- a/pkg/apis/build/v1alpha2/image_builds_test.go +++ b/pkg/apis/build/v1alpha2/image_builds_test.go @@ -380,7 +380,3 @@ func (t TestBuilderResource) RunImage() string { func (t TestBuilderResource) GetName() string { return t.Name } - -func(t TestBuilderResource) GetKind() string{ - return t.Kind -} diff --git a/pkg/duckbuilder/duck_builder.go b/pkg/duckbuilder/duck_builder.go index fed8de34a..40187ded9 100644 --- a/pkg/duckbuilder/duck_builder.go +++ b/pkg/duckbuilder/duck_builder.go @@ -20,10 +20,6 @@ func (b *DuckBuilder) GetName() string { return b.Name } -func (b *DuckBuilder) GetKind() string { - return b.Kind -} - type DuckBuilderSpec struct { ImagePullSecrets []v1.LocalObjectReference } diff --git a/pkg/reconciler/image/build_required_test.go b/pkg/reconciler/image/build_required_test.go index e889604fa..63ca33f8d 100644 --- a/pkg/reconciler/image/build_required_test.go +++ b/pkg/reconciler/image/build_required_test.go @@ -829,7 +829,3 @@ func (t TestBuilderResource) RunImage() string { func (t TestBuilderResource) GetName() string { return t.Name } - -func (t TestBuilderResource) GetKind() string { - return t.Kind -} From 6898af3e669b49932c4f624be8dd730c84396545 Mon Sep 17 00:00:00 2001 From: Juan Bustamante Date: Thu, 21 Apr 2022 17:24:17 -0500 Subject: [PATCH 5/7] WIP - using an annotation approach to save the data to be shown in the log Signed-off-by: Juan Bustamante --- pkg/apis/build/v1alpha2/build.go | 15 +++++++ pkg/apis/build/v1alpha2/build_pod.go | 4 +- pkg/apis/build/v1alpha2/builder_resource.go | 1 + pkg/apis/build/v1alpha2/image_builds.go | 5 +++ pkg/apis/build/v1alpha2/image_builds_test.go | 10 +++-- pkg/apis/core/v1alpha1/build_types.go | 2 - pkg/duckbuilder/duck_builder.go | 6 ++- pkg/reconciler/image/build_required_test.go | 6 ++- pkg/reconciler/image/image_test.go | 43 +++++++++++++++----- test/execute_build_test.go | 6 +-- 10 files changed, 73 insertions(+), 25 deletions(-) diff --git a/pkg/apis/build/v1alpha2/build.go b/pkg/apis/build/v1alpha2/build.go index 8f728a5dd..495b6367b 100644 --- a/pkg/apis/build/v1alpha2/build.go +++ b/pkg/apis/build/v1alpha2/build.go @@ -193,3 +193,18 @@ func (b *Build) additionalBuildNeeded() bool { _, ok := b.Annotations[BuildNeededAnnotation] return ok } + + +func (b *Build) builderName() string { + if b == nil { + return "" + } + return b.GetAnnotations()[BuilderNameAnnotation] +} + +func (b *Build) builderKind() string { + if b == nil { + return "" + } + return b.GetAnnotations()[BuilderKindAnnotation] +} diff --git a/pkg/apis/build/v1alpha2/build_pod.go b/pkg/apis/build/v1alpha2/build_pod.go index 7654b533a..e28288fc5 100644 --- a/pkg/apis/build/v1alpha2/build_pod.go +++ b/pkg/apis/build/v1alpha2/build_pod.go @@ -381,11 +381,11 @@ func (b *Build) BuildPod(images BuildPodImages, buildContext BuildContext) (*cor }, corev1.EnvVar{ Name: "BUILDER_NAME", - Value: b.BuilderSpec().Name, + Value: b.builderName(), }, corev1.EnvVar{ Name: "BUILDER_KIND", - Value: b.BuilderSpec().Kind, + Value: b.builderKind(), }, corev1.EnvVar{ Name: "DNS_PROBE_HOSTNAME", diff --git a/pkg/apis/build/v1alpha2/builder_resource.go b/pkg/apis/build/v1alpha2/builder_resource.go index 21e6a18be..a074b1ff4 100644 --- a/pkg/apis/build/v1alpha2/builder_resource.go +++ b/pkg/apis/build/v1alpha2/builder_resource.go @@ -8,4 +8,5 @@ type BuilderResource interface { Ready() bool BuildpackMetadata() corev1alpha1.BuildpackMetadataList RunImage() string + GetKind() string } diff --git a/pkg/apis/build/v1alpha2/image_builds.go b/pkg/apis/build/v1alpha2/image_builds.go index 506a00c4d..a57a360cd 100644 --- a/pkg/apis/build/v1alpha2/image_builds.go +++ b/pkg/apis/build/v1alpha2/image_builds.go @@ -22,6 +22,9 @@ const ( BuildChangesAnnotation = "image.kpack.io/buildChanges" BuildNeededAnnotation = "image.kpack.io/additionalBuildNeeded" + BuilderNameAnnotation = "image.kpack.io/builderName" + BuilderKindAnnotation = "image.kpack.io/builderKind" + BuildReasonConfig = "CONFIG" BuildReasonCommit = "COMMIT" BuildReasonBuildpack = "BUILDPACK" @@ -48,6 +51,8 @@ func (im *Image) Build(sourceResolver *SourceResolver, builder BuilderResource, Annotations: combine(im.Annotations, map[string]string{ BuildReasonAnnotation: reasons, BuildChangesAnnotation: changes, + BuilderNameAnnotation: builder.GetName(), + BuilderKindAnnotation: builder.GetKind(), }), }, Spec: BuildSpec{ diff --git a/pkg/apis/build/v1alpha2/image_builds_test.go b/pkg/apis/build/v1alpha2/image_builds_test.go index 1ce1efca3..647a01fc3 100644 --- a/pkg/apis/build/v1alpha2/image_builds_test.go +++ b/pkg/apis/build/v1alpha2/image_builds_test.go @@ -55,7 +55,7 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) { builder := &TestBuilderResource{ Name: "builder-Name", LatestImage: "some/builder@sha256:builder-digest", - Kind: "builder", + Kind: BuilderKind, BuilderReady: true, BuilderMetadata: []corev1alpha1.BuildpackMetadata{ {Id: "buildpack.matches", Version: "1"}, @@ -128,7 +128,7 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) { it("propagates image's annotations onto the build", func() { build := image.Build(sourceResolver, builder, latestBuild, "some-reasons", "some-changes", 27, "") - assert.Equal(t, map[string]string{"annotation-key": "annotation-value", "image.kpack.io/buildChanges": "some-changes", "image.kpack.io/reason": "some-reasons"}, build.Annotations) + assert.Equal(t, map[string]string{"annotation-key": "annotation-value", "image.kpack.io/buildChanges": "some-changes", "image.kpack.io/reason": "some-reasons", "image.kpack.io/builderKind": "Builder", "image.kpack.io/builderName": "builder-Name"}, build.Annotations) }) it("sets labels from image metadata and propagates image labels", func() { @@ -360,8 +360,6 @@ func (t TestBuilderResource) BuildBuilderSpec() corev1alpha1.BuildBuilderSpec { return corev1alpha1.BuildBuilderSpec{ Image: t.LatestImage, ImagePullSecrets: t.ImagePullSecrets, - Kind: t.Kind, - Name: t.Name, } } @@ -380,3 +378,7 @@ func (t TestBuilderResource) RunImage() string { func (t TestBuilderResource) GetName() string { return t.Name } + +func (t TestBuilderResource) GetKind() string { + return t.Kind +} diff --git a/pkg/apis/core/v1alpha1/build_types.go b/pkg/apis/core/v1alpha1/build_types.go index c8386df24..47df46d81 100644 --- a/pkg/apis/core/v1alpha1/build_types.go +++ b/pkg/apis/core/v1alpha1/build_types.go @@ -19,8 +19,6 @@ type BuildBuilderSpec struct { // +patchStrategy=merge // +listType ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,15,rep,name=imagePullSecrets"` - Kind string `json:"kind,omitempty"` - Name string `json:"name,omitempty"` } // +k8s:openapi-gen=true diff --git a/pkg/duckbuilder/duck_builder.go b/pkg/duckbuilder/duck_builder.go index 40187ded9..df0a3c9ab 100644 --- a/pkg/duckbuilder/duck_builder.go +++ b/pkg/duckbuilder/duck_builder.go @@ -20,6 +20,10 @@ func (b *DuckBuilder) GetName() string { return b.Name } +func (b *DuckBuilder) GetKind() string { + return b.Kind +} + type DuckBuilderSpec struct { ImagePullSecrets []v1.LocalObjectReference } @@ -33,8 +37,6 @@ func (b *DuckBuilder) BuildBuilderSpec() corev1alpha1.BuildBuilderSpec { return corev1alpha1.BuildBuilderSpec{ Image: b.Status.LatestImage, ImagePullSecrets: b.Spec.ImagePullSecrets, - Name: b.Name, - Kind: b.Kind, } } diff --git a/pkg/reconciler/image/build_required_test.go b/pkg/reconciler/image/build_required_test.go index 63ca33f8d..663e0fed4 100644 --- a/pkg/reconciler/image/build_required_test.go +++ b/pkg/reconciler/image/build_required_test.go @@ -63,7 +63,7 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) { {Id: "buildpack.matches", Version: "1"}, }, LatestRunImage: "some.registry.io/run-image@sha256:67e3de2af270bf09c02e9a644aeb7e87e6b3c049abe6766bf6b6c3728a83e7fb", - + Kind: buildapi.BuilderKind, } latestBuild := &buildapi.Build{ @@ -829,3 +829,7 @@ func (t TestBuilderResource) RunImage() string { func (t TestBuilderResource) GetName() string { return t.Name } + +func (t TestBuilderResource) GetKind() string { + return t.Kind +} diff --git a/pkg/reconciler/image/image_test.go b/pkg/reconciler/image/image_test.go index 05e43423e..b9ba62041 100644 --- a/pkg/reconciler/image/image_test.go +++ b/pkg/reconciler/image/image_test.go @@ -116,6 +116,9 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Name: builderName, Namespace: namespace, }, + TypeMeta: metav1.TypeMeta{ + Kind: buildapi.BuilderKind, + }, Status: buildapi.BuilderStatus{ LatestImage: "some/builder@sha256:acf123", BuilderMetadata: corev1alpha1.BuildpackMetadataList{ @@ -143,6 +146,9 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { ObjectMeta: metav1.ObjectMeta{ Name: clusterBuilderName, }, + TypeMeta: metav1.TypeMeta{ + Kind: buildapi.ClusterBuilderKind, + }, Status: buildapi.BuilderStatus{ LatestImage: "some/clusterbuilder@sha256:acf123", BuilderMetadata: corev1alpha1.BuildpackMetadataList{ @@ -689,6 +695,8 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { someLabelKey: someValueToPassThrough, }, Annotations: map[string]string{ + buildapi.BuilderNameAnnotation: builderName, + buildapi.BuilderKindAnnotation: buildapi.BuilderKind, buildapi.BuildReasonAnnotation: buildapi.BuildReasonConfig, buildapi.BuildChangesAnnotation: testhelpers.CompactJSON(` [ @@ -715,7 +723,6 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: builder.Status.LatestImage, - Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Cache: &buildapi.BuildCacheConfig{}, @@ -780,6 +787,8 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { someLabelKey: someValueToPassThrough, }, Annotations: map[string]string{ + buildapi.BuilderNameAnnotation: clusterBuilderName, + buildapi.BuilderKindAnnotation: buildapi.ClusterBuilderKind, buildapi.BuildReasonAnnotation: buildapi.BuildReasonConfig, buildapi.BuildChangesAnnotation: testhelpers.CompactJSON(` [ @@ -806,7 +815,6 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: clusterBuilder.Status.LatestImage, - Name: clusterBuilderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Cache: &buildapi.BuildCacheConfig{}, @@ -871,6 +879,8 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { someLabelKey: someValueToPassThrough, }, Annotations: map[string]string{ + buildapi.BuilderNameAnnotation: builderName, + buildapi.BuilderKindAnnotation: buildapi.BuilderKind, buildapi.BuildReasonAnnotation: buildapi.BuildReasonConfig, buildapi.BuildChangesAnnotation: testhelpers.CompactJSON(` [ @@ -897,7 +907,6 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: builder.Status.LatestImage, - Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Cache: &buildapi.BuildCacheConfig{}, @@ -963,6 +972,8 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { someLabelKey: someValueToPassThrough, }, Annotations: map[string]string{ + buildapi.BuilderNameAnnotation: clusterBuilderName, + buildapi.BuilderKindAnnotation: buildapi.ClusterBuilderKind, buildapi.BuildReasonAnnotation: buildapi.BuildReasonConfig, buildapi.BuildChangesAnnotation: testhelpers.CompactJSON(` [ @@ -989,7 +1000,6 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: clusterBuilder.Status.LatestImage, - Name: clusterBuilderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Cache: &buildapi.BuildCacheConfig{}, @@ -1057,6 +1067,8 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { someLabelKey: someValueToPassThrough, }, Annotations: map[string]string{ + buildapi.BuilderNameAnnotation: builderName, + buildapi.BuilderKindAnnotation: buildapi.BuilderKind, buildapi.BuildReasonAnnotation: buildapi.BuildReasonConfig, buildapi.BuildChangesAnnotation: testhelpers.CompactJSON(` [ @@ -1083,7 +1095,6 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: builder.Status.LatestImage, - Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Source: corev1alpha1.SourceConfig{ @@ -1191,6 +1202,8 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { buildapi.ImageGenerationLabel: generation(image), }, Annotations: map[string]string{ + buildapi.BuilderNameAnnotation: builderName, + buildapi.BuilderKindAnnotation: buildapi.BuilderKind, buildapi.BuildReasonAnnotation: strings.Join([]string{ buildapi.BuildReasonCommit, buildapi.BuildReasonConfig, @@ -1230,7 +1243,6 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: builder.Status.LatestImage, - Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Source: corev1alpha1.SourceConfig{ @@ -1349,6 +1361,8 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { someLabelKey: someValueToPassThrough, }, Annotations: map[string]string{ + buildapi.BuilderNameAnnotation: builderName, + buildapi.BuilderKindAnnotation: buildapi.BuilderKind, buildapi.BuildReasonAnnotation: buildapi.BuildReasonCommit, buildapi.BuildChangesAnnotation: `[{"reason":"COMMIT","old":"1234567","new":"new-commit"}]`, }, @@ -1357,7 +1371,6 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: builder.Status.LatestImage, - Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Source: corev1alpha1.SourceConfig{ @@ -1411,6 +1424,9 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Name: builderName, Namespace: namespace, }, + TypeMeta: metav1.TypeMeta{ + Kind: buildapi.BuilderKind, + }, Status: buildapi.BuilderStatus{ Status: corev1alpha1.Status{ Conditions: corev1alpha1.Conditions{ @@ -1498,6 +1514,8 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { someLabelKey: someValueToPassThrough, }, Annotations: map[string]string{ + buildapi.BuilderNameAnnotation: builderName, + buildapi.BuilderKindAnnotation: buildapi.BuilderKind, buildapi.BuildReasonAnnotation: buildapi.BuildReasonBuildpack, buildapi.BuildChangesAnnotation: testhelpers.CompactJSON(` [ @@ -1518,7 +1536,6 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: updatedBuilderImage, - Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Source: corev1alpha1.SourceConfig{ @@ -1572,6 +1589,9 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Name: builderName, Namespace: namespace, }, + TypeMeta: metav1.TypeMeta{ + Kind: buildapi.BuilderKind, + }, Status: buildapi.BuilderStatus{ Status: corev1alpha1.Status{ Conditions: corev1alpha1.Conditions{ @@ -1611,7 +1631,6 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: updatedBuilderImage, - Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Source: corev1alpha1.SourceConfig{ @@ -1660,6 +1679,8 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { someLabelKey: someValueToPassThrough, }, Annotations: map[string]string{ + buildapi.BuilderNameAnnotation: builderName, + buildapi.BuilderKindAnnotation: buildapi.BuilderKind, buildapi.BuildReasonAnnotation: buildapi.BuildReasonStack, buildapi.BuildChangesAnnotation: testhelpers.CompactJSON(` [ @@ -1675,7 +1696,6 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: updatedBuilderImage, - Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Source: corev1alpha1.SourceConfig{ @@ -1782,6 +1802,8 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { someLabelKey: someValueToPassThrough, }, Annotations: map[string]string{ + buildapi.BuilderNameAnnotation: builderName, + buildapi.BuilderKindAnnotation: buildapi.BuilderKind, buildapi.BuildReasonAnnotation: strings.Join([]string{ buildapi.BuildReasonCommit, buildapi.BuildReasonConfig, @@ -1821,7 +1843,6 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { Tags: []string{image.Spec.Tag}, Builder: corev1alpha1.BuildBuilderSpec{ Image: builder.Status.LatestImage, - Name: builderName, }, ServiceAccountName: image.Spec.ServiceAccountName, Source: corev1alpha1.SourceConfig{ diff --git a/test/execute_build_test.go b/test/execute_build_test.go index 38b3ee768..cb4e4caee 100644 --- a/test/execute_build_test.go +++ b/test/execute_build_test.go @@ -557,10 +557,10 @@ func validateBuildLog(t *testing.T, clients *clients, image *buildapi.Image, ctx require.Len(t, buildList.Items, 1) buildSpec := buildList.Items[0].Spec.DeepCopy() - - assert.Contains(t, output, fmt.Sprintf("Name: %s", buildSpec.Builder.Name)) + assert.Contains(t, output, fmt.Sprintf("Name: %s", image.Spec.Builder.Name)) assert.Contains(t, output, fmt.Sprintf("Image: %s", buildSpec.Builder.Image)) - assert.Contains(t, output, fmt.Sprintf("Kind: %s", buildSpec.Builder.Kind)) + // TODO Fix, for some reason the Kind annotation is empty during the test + assert.Contains(t, output, fmt.Sprintf("Kind: %s", image.Spec.Builder.Kind)) } func validateRebase(t *testing.T, ctx context.Context, clients *clients, imageName, testNamespace string) { From 919aaefda3349ed1a3e027a6c8074f4f3ee44d78 Mon Sep 17 00:00:00 2001 From: Juan Bustamante Date: Thu, 9 Jun 2022 17:30:03 -0500 Subject: [PATCH 6/7] Fixing suggestions from review Signed-off-by: Juan Bustamante --- cmd/build-init/main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/build-init/main.go b/cmd/build-init/main.go index f8dc50fcf..45b26b610 100644 --- a/cmd/build-init/main.go +++ b/cmd/build-init/main.go @@ -151,8 +151,10 @@ func main() { logger.Fatalf("error while processing the project descriptor: %s", err) } - logger.Printf("Builder:\n Image: %s \n Name: %s \n Kind: %s ", *builderImage, - *builderName, *builderKind) + if *builderImage != "" && *builderName != "" && *builderKind != "" { + logger.Printf("Builder:\n Image: %s \n Name: %s \n Kind: %s ", *builderImage, + *builderName, *builderKind) + } err = cnb.SetupPlatformEnvVars(platformDir, *platformEnvVars) if err != nil { From ea79b802b65319ebf1f6bd1311acacbaf287c9a1 Mon Sep 17 00:00:00 2001 From: Juan Bustamante Date: Thu, 9 Jun 2022 20:10:46 -0500 Subject: [PATCH 7/7] Removing integration tests Signed-off-by: Juan Bustamante --- test/execute_build_test.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/test/execute_build_test.go b/test/execute_build_test.go index cb4e4caee..696553f58 100644 --- a/test/execute_build_test.go +++ b/test/execute_build_test.go @@ -531,8 +531,6 @@ func validateImageCreate(t *testing.T, clients *clients, image *buildapi.Image, _, _, err = registryClient.Fetch(authn.DefaultKeychain, image.Spec.Tag) require.NoError(t, err) - validateBuildLog(t, clients, image, ctx, logTail.String()) - eventually(t, func() bool { return strings.Contains(logTail.String(), "Build successful") }, 1*time.Second, 10*time.Second) @@ -549,20 +547,6 @@ func validateImageCreate(t *testing.T, clients *clients, image *buildapi.Image, assert.Equal(t, expectedResources, pod.Spec.Containers[0].Resources) } -func validateBuildLog(t *testing.T, clients *clients, image *buildapi.Image, ctx context.Context, output string) { - buildList, err := clients.client.KpackV1alpha2().Builds(image.Namespace).List(ctx, metav1.ListOptions{ - LabelSelector: fmt.Sprintf("image.kpack.io/image=%s", image.Name), - }) - require.NoError(t, err) - - require.Len(t, buildList.Items, 1) - buildSpec := buildList.Items[0].Spec.DeepCopy() - assert.Contains(t, output, fmt.Sprintf("Name: %s", image.Spec.Builder.Name)) - assert.Contains(t, output, fmt.Sprintf("Image: %s", buildSpec.Builder.Image)) - // TODO Fix, for some reason the Kind annotation is empty during the test - assert.Contains(t, output, fmt.Sprintf("Kind: %s", image.Spec.Builder.Kind)) -} - func validateRebase(t *testing.T, ctx context.Context, clients *clients, imageName, testNamespace string) { var rebaseBuildName = imageName + "-rebase"