Skip to content

Commit

Permalink
Updates e2e tests for v1beta1
Browse files Browse the repository at this point in the history
initial changes to e2e & test/utils

enhanced & more structured changes to test samples

resolved import dependencies

add v1beta1 to API scheme & restructure test/data
  • Loading branch information
apoorvajagtap committed Oct 13, 2023
1 parent 7ab94f9 commit ee28e4a
Show file tree
Hide file tree
Showing 151 changed files with 7,586 additions and 330 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ test-integration: install-apis ginkgo
-trace \
test/integration/...

# .PHONY: test-e2e-alpha
# test-e2e:
# $(eval TEST_API := v1alpha1)
# $(MAKE) install-strategies test-e2e-plain

.PHONY: test-e2e
test-e2e: install-strategies test-e2e-plain

Expand All @@ -222,7 +227,7 @@ test-e2e-plain: ginkgo
TEST_E2E_SERVICEACCOUNT_NAME=${TEST_E2E_SERVICEACCOUNT_NAME} \
TEST_E2E_TIMEOUT_MULTIPLIER=${TEST_E2E_TIMEOUT_MULTIPLIER} \
TEST_E2E_VERIFY_TEKTONOBJECTS=${TEST_E2E_VERIFY_TEKTONOBJECTS} \
$(GINKGO) ${TEST_E2E_FLAGS} test/e2e
$(GINKGO) ${TEST_E2E_FLAGS} test/e2e/v1beta1

.PHONY: test-e2e-kind-with-prereq-install
test-e2e-kind-with-prereq-install: ginkgo install-controller-kind install-strategies test-e2e-plain
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
k8s.io/client-go v0.26.9
k8s.io/code-generator v0.26.9
k8s.io/kubectl v0.26.9
k8s.io/utils v0.0.0-20230209194617-a36077c30491
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
knative.dev/pkg v0.0.0-20230221145627-8efb3485adcf
sigs.k8s.io/controller-runtime v0.14.6
sigs.k8s.io/yaml v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,8 @@ k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a h1:gmovKNur38vgoWfGtP5QOG
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a/go.mod h1:y5VtZWM9sHHc2ZodIH/6SHzXj+TPU5USoA8lcIeKEKY=
k8s.io/kubectl v0.26.9 h1:0Z8wEFQoXqWbWfT7G9si5EKVjYf5KG4hocSB7B8Jkbc=
k8s.io/kubectl v0.26.9/go.mod h1:Rl9W561iyUZtzwgstHcKChzUo2xMaGqb7Za6jUDMKP4=
k8s.io/utils v0.0.0-20230209194617-a36077c30491 h1:r0BAOLElQnnFhE/ApUsg3iHdVYYPBjNSSOMowRZxxsY=
k8s.io/utils v0.0.0-20230209194617-a36077c30491/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
knative.dev/pkg v0.0.0-20230221145627-8efb3485adcf h1:TwvZFDpkyqpK2OCAwvNGV2Zjk14FzIh8X8Ci/du3jYI=
knative.dev/pkg v0.0.0-20230221145627-8efb3485adcf/go.mod h1:VO/fcEsq43seuONRQxZyftWHjpMabYzRHDtpSEQ/eoQ=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/addtoscheme_build_v1beta1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright The Shipwright Contributors
//
// SPDX-License-Identifier: Apache-2.0

package apis

import (
"github.com/shipwright-io/build/pkg/apis/build/v1beta1"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, v1beta1.SchemeBuilder.AddToScheme)
}
25 changes: 24 additions & 1 deletion pkg/apis/build/v1beta1/build_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ func (src *Build) ConvertTo(ctx context.Context, obj *unstructured.Unstructured)
alphaBuild.ObjectMeta.Annotations[v1alpha1.AnnotationBuildRunDeletion] = strconv.FormatBool(*src.Spec.Retention.AtBuildDeletion)
}

// convert OCIArtifact to Bundle
if src.Spec.Source.OCIArtifact != nil {
alphaBuild.Spec.Source.BundleContainer = &v1alpha1.BundleContainer{
Image: src.Spec.Source.OCIArtifact.Image,
Prune: (*v1alpha1.PruneOption)(src.Spec.Source.OCIArtifact.Prune),
}
}

mapito, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&alphaBuild)
if err != nil {
ctxlog.Error(ctx, err, "failed structuring the newObject")
Expand Down Expand Up @@ -154,6 +162,17 @@ func (dest *BuildSpec) ConvertFrom(orig *v1alpha1.BuildSpec) error {
dest.ParamValues = append(dest.ParamValues, dockerfileParam)
}

// handle spec.Builder migration
if orig.Builder != nil {
builderParam := ParamValue{
Name: "builder-image",
SingleValue: &SingleValue{
Value: &orig.Builder.Image,
},
}
dest.ParamValues = append(dest.ParamValues, builderParam)
}

// Handle BuildSpec Output
dest.Output.Image = orig.Output.Image
dest.Output.Insecure = orig.Output.Insecure
Expand Down Expand Up @@ -282,10 +301,12 @@ func (p ParamValue) convertToAlpha(dest *v1alpha1.ParamValue) {
}

if p.ConfigMapValue != nil {
dest.ConfigMapValue = &v1alpha1.ObjectKeyRef{}
dest.SingleValue = &v1alpha1.SingleValue{}
dest.ConfigMapValue = (*v1alpha1.ObjectKeyRef)(p.ConfigMapValue)
}

if p.SecretValue != nil {
dest.SingleValue = &v1alpha1.SingleValue{}
dest.SecretValue = (*v1alpha1.ObjectKeyRef)(p.SecretValue)
}

Expand Down Expand Up @@ -323,9 +344,11 @@ func convertBetaParamValue(orig v1alpha1.ParamValue) ParamValue {
}

if orig.ConfigMapValue != nil {
p.SingleValue = &SingleValue{}
p.ConfigMapValue = (*ObjectKeyRef)(orig.ConfigMapValue)
}
if orig.SecretValue != nil {
p.SingleValue = &SingleValue{}
p.SecretValue = (*ObjectKeyRef)(orig.SecretValue)
}

Expand Down
21 changes: 19 additions & 2 deletions pkg/apis/build/v1beta1/buildrun_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
runtime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/ptr"
)

// ensure v1beta1 implements the Conversion interface
Expand Down Expand Up @@ -42,8 +43,16 @@ func (src *BuildRun) ConvertTo(ctx context.Context, obj *unstructured.Unstructur
}

// BuildRunSpec ServiceAccount
alphaBuildRun.Spec.ServiceAccount = &v1alpha1.ServiceAccount{
Name: src.Spec.ServiceAccount,
// With the deprecation of serviceAccount.Generate, serviceAccount is set to ".generate" to have the SA created on fly.
if src.Spec.ServiceAccount != nil && *src.Spec.ServiceAccount == ".generate" {
alphaBuildRun.Spec.ServiceAccount = &v1alpha1.ServiceAccount{
Name: &src.ObjectMeta.Name,
Generate: ptr.To[bool](true),
}
} else {
alphaBuildRun.Spec.ServiceAccount = &v1alpha1.ServiceAccount{
Name: src.Spec.ServiceAccount,
}
}

// BuildRunSpec Timeout
Expand Down Expand Up @@ -142,6 +151,14 @@ func (src *BuildRun) ConvertFrom(ctx context.Context, obj *unstructured.Unstruct
conditions = append(conditions, ct)
}

if alphaBuildRun.Status.FailureDetails != nil {
src.Status.FailureDetails = &FailureDetails{
Reason: alphaBuildRun.Status.FailureDetails.Reason,
Message: alphaBuildRun.Status.FailureDetails.Message,
Location: (*Location)(alphaBuildRun.Status.FailureDetails.Location),
}
}

src.Status = BuildRunStatus{
Sources: sources,
Output: (*Output)(alphaBuildRun.Status.Output),
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/google/go-containerregistry/pkg/v1/random"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/shipwright-io/build/pkg/image"
"github.com/shipwright-io/build/test/utils"
utils "github.com/shipwright-io/build/test/utils/v1alpha1"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/shipwright-io/build/pkg/config"
"github.com/shipwright-io/build/pkg/controller/fakes"
buildController "github.com/shipwright-io/build/pkg/reconciler/build"
"github.com/shipwright-io/build/test"
test "github.com/shipwright-io/build/test/v1alpha1_samples"
)

var _ = Describe("Reconcile Build", func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/buildrun/buildrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/shipwright-io/build/pkg/controller/fakes"
buildrunctl "github.com/shipwright-io/build/pkg/reconciler/buildrun"
"github.com/shipwright-io/build/pkg/reconciler/buildrun/resources"
"github.com/shipwright-io/build/test"
test "github.com/shipwright-io/build/test/v1alpha1_samples"
)

var _ = Describe("Reconcile BuildRun", func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/buildrun/resources/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
"github.com/shipwright-io/build/pkg/controller/fakes"
"github.com/shipwright-io/build/pkg/reconciler/buildrun/resources"
"github.com/shipwright-io/build/test"
test "github.com/shipwright-io/build/test/v1alpha1_samples"
)

var _ = Describe("Build Resource", func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/buildrun/resources/conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
"github.com/shipwright-io/build/pkg/controller/fakes"
"github.com/shipwright-io/build/pkg/reconciler/buildrun/resources"
"github.com/shipwright-io/build/test"
test "github.com/shipwright-io/build/test/v1alpha1_samples"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/buildrun/resources/image_processing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
"github.com/shipwright-io/build/pkg/config"
"github.com/shipwright-io/build/pkg/reconciler/buildrun/resources"
"github.com/shipwright-io/build/test/utils"
utils "github.com/shipwright-io/build/test/utils/v1alpha1"
pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/buildrun/resources/results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
"github.com/shipwright-io/build/pkg/reconciler/buildrun/resources"
"github.com/shipwright-io/build/test"
test "github.com/shipwright-io/build/test/v1alpha1_samples"

pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"k8s.io/apimachinery/pkg/types"
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/buildrun/resources/service_accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
"github.com/shipwright-io/build/pkg/controller/fakes"
"github.com/shipwright-io/build/pkg/reconciler/buildrun/resources"
"github.com/shipwright-io/build/test"
test "github.com/shipwright-io/build/test/v1alpha1_samples"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/buildrun/resources/strategies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
"github.com/shipwright-io/build/pkg/controller/fakes"
"github.com/shipwright-io/build/pkg/reconciler/buildrun/resources"
"github.com/shipwright-io/build/test"
test "github.com/shipwright-io/build/test/v1alpha1_samples"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/buildrun/resources/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"github.com/shipwright-io/build/pkg/config"
"github.com/shipwright-io/build/pkg/env"
"github.com/shipwright-io/build/pkg/reconciler/buildrun/resources"
"github.com/shipwright-io/build/test"
"github.com/shipwright-io/build/test/utils"
utils "github.com/shipwright-io/build/test/utils/v1alpha1"
test "github.com/shipwright-io/build/test/v1alpha1_samples"
)

var _ = Describe("GenerateTaskrun", func() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions test/data/v1beta1/build_buildah_cr_custom_context+dockerfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-custom-context-dockerfile
spec:
source:
git:
url: https://github.com/shipwright-io/sample-nodejs
contextDir: docker-build-renamed
strategy:
name: buildah-shipwright-managed-push
kind: ClusterBuildStrategy
paramValues:
- name: dockerfile
value: RenamedDockerfile
output:
image: image-registry.openshift-image-registry.svc:5000/build-examples/renamed-dockerfile
18 changes: 18 additions & 0 deletions test/data/v1beta1/build_buildah_cr_local_source_upload.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-golang-build-local-source-upload
spec:
source:
git:
url: https://github.com/shipwright-io/sample-go
contextDir: docker-build
strategy:
name: buildah-shipwright-managed-push
kind: ClusterBuildStrategy
paramValues:
- name: dockerfile
value: Dockerfile
output:
image: image-registry.openshift-image-registry.svc:5000/build-examples/taxi-app
22 changes: 22 additions & 0 deletions test/data/v1beta1/build_buildah_cr_mutate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-golang-build-mutate
spec:
source:
git:
url: https://github.com/shipwright-io/sample-go
contextDir: docker-build
strategy:
name: buildah-shipwright-managed-push
kind: ClusterBuildStrategy
paramValues:
- name: dockerfile
value: Dockerfile
output:
image: image-registry.openshift-image-registry.svc:5000/build-examples/taxi-app
annotations:
"org.opencontainers.image.url": "https://my-company.com/images"
labels:
"maintainer": "[email protected]"
18 changes: 18 additions & 0 deletions test/data/v1beta1/build_buildah_cr_private_github.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-golang-build
spec:
source:
git:
url: [email protected]:qu1queee/newtaxi.git
cloneSecret: github-ssh-all
strategy:
name: buildah-shipwright-managed-push
kind: ClusterBuildStrategy
paramValues:
- name: dockerfile
value: Dockerfile
output:
image: image-registry.openshift-image-registry.svc:5000/build-examples/taxi-app
17 changes: 17 additions & 0 deletions test/data/v1beta1/build_buildah_cr_private_gitlab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-golang-build
spec:
source:
git:
url: [email protected]:eduardooli/newtaxi.git
strategy:
name: buildah-shipwright-managed-push
kind: ClusterBuildStrategy
paramValues:
- name: dockerfile
value: Dockerfile
output:
image: image-registry.openshift-image-registry.svc:5000/build-examples/taxi-app
24 changes: 24 additions & 0 deletions test/data/v1beta1/build_buildkit_cr_insecure_registry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildkit-build
spec:
source:
git:
url: https://github.com/shipwright-io/sample-go
contextDir: docker-build
paramValues:
- name: insecure-registry
value: "true"
- name: platforms
values:
- value: linux/amd64
- value: linux/arm64
strategy:
name: buildkit
kind: ClusterBuildStrategy
retention:
atBuildDeletion: true
output:
image: image-registry.openshift-image-registry.svc:5000/build-examples/taxi-app
15 changes: 15 additions & 0 deletions test/data/v1beta1/build_buildpacks-v3_golang_cr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildpack-golang-build
spec:
source:
git:
url: https://github.com/shipwright-io/sample-go
contextDir: source-build
strategy:
name: buildpacks-v3
kind: ClusterBuildStrategy
output:
image: image-registry.openshift-image-registry.svc:5000/build-examples/taxi-app
Loading

0 comments on commit ee28e4a

Please sign in to comment.