Skip to content

Commit

Permalink
Updates e2e tests for v1beta1
Browse files Browse the repository at this point in the history
removes deprecated pointer references
  • Loading branch information
apoorvajagtap committed Oct 15, 2023
1 parent a381f9d commit ee55ef2
Show file tree
Hide file tree
Showing 173 changed files with 7,765 additions and 507 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)
}
35 changes: 30 additions & 5 deletions pkg/apis/build/v1beta1/build_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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/pointer"
"k8s.io/utils/ptr"
)

const (
Expand Down 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 @@ -82,7 +90,7 @@ func (src *Build) ConvertFrom(ctx context.Context, obj *unstructured.Unstructure
if src.Spec.Retention == nil {
src.Spec.Retention = &BuildRetention{}
}
src.Spec.Retention.AtBuildDeletion = pointer.Bool(value == "true")
src.Spec.Retention.AtBuildDeletion = ptr.To[bool](value == "true")
delete(src.ObjectMeta.Annotations, v1alpha1.AnnotationBuildRunDeletion)
}

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,11 +301,15 @@ func (p ParamValue) convertToAlpha(dest *v1alpha1.ParamValue) {
}

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

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

dest.Name = p.Name
Expand Down Expand Up @@ -323,9 +346,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
4 changes: 2 additions & 2 deletions pkg/apis/build/v1beta1/buildstrategy_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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/pointer"
"k8s.io/utils/ptr"
)

// ensure v1beta1 implements the Conversion interface
Expand Down Expand Up @@ -213,7 +213,7 @@ func (src *BuildStrategySpec) ConvertFrom(bs v1alpha1.BuildStrategySpec) {
Name: "dockerfile",
Description: "The Dockerfile to be built.",
Type: ParameterTypeString,
Default: pointer.String("Dockerfile"),
Default: ptr.To[string]("Dockerfile"),
})
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

const (
Expand Down Expand Up @@ -85,8 +85,8 @@ var (
metricBuildRunEstablishDurationBuckets = []float64{0, 1, 2, 3, 5, 7, 10, 15, 20, 30}
metricBuildRunRampUpDurationBuckets = prometheus.LinearBuckets(0, 1, 10)

root = pointer.Int64(0)
nonRoot = pointer.Int64(1000)
root = ptr.To[int64](0)
nonRoot = ptr.To[int64](1000)
)

// Config hosts different parameters that
Expand Down Expand Up @@ -162,7 +162,7 @@ func NewDefaultConfig() *Config {
},
},
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: pointer.Bool(false),
AllowPrivilegeEscalation: ptr.To[bool](false),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{
"ALL",
Expand All @@ -186,7 +186,7 @@ func NewDefaultConfig() *Config {
},
},
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: pointer.Bool(false),
AllowPrivilegeEscalation: ptr.To[bool](false),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{
"ALL",
Expand Down Expand Up @@ -214,7 +214,7 @@ func NewDefaultConfig() *Config {
// in all possible scenarios, we run this step as root with DAC_OVERRIDE
// capability.
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: pointer.Bool(false),
AllowPrivilegeEscalation: ptr.To[bool](false),
RunAsUser: root,
RunAsGroup: root,
Capabilities: &corev1.Capabilities{
Expand Down Expand Up @@ -244,7 +244,7 @@ func NewDefaultConfig() *Config {
},
},
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: pointer.Bool(false),
AllowPrivilegeEscalation: ptr.To[bool](false),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{
"ALL",
Expand Down
10 changes: 5 additions & 5 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

. "github.com/shipwright-io/build/pkg/config"
)
Expand Down Expand Up @@ -126,15 +126,15 @@ var _ = Describe("Config", func() {
}

configWithEnvVariableOverrides(overrides, func(config *Config) {
nonRoot := pointer.Int64(1000)
nonRoot := ptr.To[int64](1000)
Expect(config.GitContainerTemplate).To(Equal(pipeline.Step{
Image: "myregistry/custom/git-image",
Command: []string{
"/ko-app/git",
},
Env: []corev1.EnvVar{{Name: "HOME", Value: "/shared-home"}},
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: pointer.Bool(false),
AllowPrivilegeEscalation: ptr.To[bool](false),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{
"ALL",
Expand Down Expand Up @@ -228,14 +228,14 @@ var _ = Describe("Config", func() {
}

configWithEnvVariableOverrides(overrides, func(config *Config) {
nonRoot := pointer.Int64(1000)
nonRoot := ptr.To[int64](1000)
Expect(config.WaiterContainerTemplate).To(Equal(pipeline.Step{
Image: "myregistry/custom/image",
Command: []string{"/ko-app/waiter"},
Args: []string{"start"},
Env: []corev1.EnvVar{{Name: "HOME", Value: "/shared-home"}},
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: pointer.Bool(false),
AllowPrivilegeEscalation: ptr.To[bool](false),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{
"ALL",
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
4 changes: 2 additions & 2 deletions pkg/reconciler/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -113,7 +113,7 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques
}

b.Status.Registered = build.ConditionStatusPtr(corev1.ConditionTrue)
b.Status.Message = pointer.String(build.AllValidationsSucceeded)
b.Status.Message = ptr.To[string](build.AllValidationsSucceeded)
if err := r.client.Status().Update(ctx, b); err != nil {
return reconcile.Result{}, err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/reconciler/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
crc "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand All @@ -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 Expand Up @@ -371,7 +371,7 @@ var _ = Describe("Reconcile Build", func() {
Context("when source URL is specified", func() {
// validate file protocol
It("fails when source URL is invalid", func() {
buildSample.Spec.Source.URL = pointer.String("foobar")
buildSample.Spec.Source.URL = ptr.To[string]("foobar")
buildSample.SetAnnotations(map[string]string{
build.AnnotationBuildVerifyRepository: "true",
})
Expand All @@ -385,7 +385,7 @@ var _ = Describe("Reconcile Build", func() {

// validate https protocol
It("fails when public source URL is unreachable", func() {
buildSample.Spec.Source.URL = pointer.String("https://github.com/shipwright-io/sample-go-fake")
buildSample.Spec.Source.URL = ptr.To[string]("https://github.com/shipwright-io/sample-go-fake")
buildSample.SetAnnotations(map[string]string{
build.AnnotationBuildVerifyRepository: "true",
})
Expand All @@ -400,7 +400,7 @@ var _ = Describe("Reconcile Build", func() {

// skip validation because of empty sourceURL annotation
It("succeed when source URL is invalid because source annotation is empty", func() {
buildSample.Spec.Source.URL = pointer.String("foobar")
buildSample.Spec.Source.URL = ptr.To[string]("foobar")

// Fake some client Get calls and ensure we populate all
// different resources we could get during reconciliation
Expand Down Expand Up @@ -451,7 +451,7 @@ var _ = Describe("Reconcile Build", func() {
// skip validation because build references a sourceURL secret
It("succeed when source URL is fake private URL because build reference a sourceURL secret", func() {
buildSample := ctl.BuildWithClusterBuildStrategyAndSourceSecret(buildName, namespace, buildStrategyName)
buildSample.Spec.Source.URL = pointer.String("https://github.yourco.com/org/build-fake")
buildSample.Spec.Source.URL = ptr.To[string]("https://github.yourco.com/org/build-fake")
buildSample.Spec.Source.Credentials.Name = registrySecret

// Fake some client Get calls and ensure we populate all
Expand Down
Loading

0 comments on commit ee55ef2

Please sign in to comment.