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 16, 2023
1 parent 92e7a0b commit f4f6eaa
Show file tree
Hide file tree
Showing 255 changed files with 11,055 additions and 540 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TEST_NAMESPACE ?= default
TEKTON_VERSION ?= v0.44.0

# E2E test flags
TEST_E2E_FLAGS ?= -p --randomize-all -timeout=1h -trace -v
TEST_E2E_FLAGS ?= -r -p --randomize-all -timeout=1h -trace -v

# E2E test service account name to be used for the build runs, can be set to generated to use the generated service account feature
TEST_E2E_SERVICEACCOUNT_NAME ?= pipeline
Expand Down Expand Up @@ -222,7 +222,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/

.PHONY: test-e2e-kind-with-prereq-install
test-e2e-kind-with-prereq-install: ginkgo install-controller-kind install-strategies test-e2e-plain
Expand Down Expand Up @@ -270,7 +270,7 @@ install-controller-kind: install-apis

.PHONY: install-strategies
install-strategies: install-apis
kubectl apply -R -f samples/buildstrategy/
kubectl apply -R -f samples/v1beta1/buildstrategy/

.PHONY: local
local: install-strategies
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)
}
42 changes: 37 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 @@ -227,6 +246,12 @@ func (dest *BuildSpec) ConvertTo(bs *v1alpha1.BuildSpec) error {
continue
}

if p.Name == "builder-image" && p.SingleValue != nil {
bs.Builder = &v1alpha1.Image{
Image: *p.SingleValue.Value,
}
continue
}
param := v1alpha1.ParamValue{}
p.convertToAlpha(&param)
bs.ParamValues = append(bs.ParamValues, param)
Expand Down Expand Up @@ -271,6 +296,7 @@ func (dest *BuildSpec) ConvertTo(bs *v1alpha1.BuildSpec) error {
}
bs.Volumes = append(bs.Volumes, aux)
}

return nil
}

Expand All @@ -282,11 +308,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 +353,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
55 changes: 51 additions & 4 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 All @@ -41,7 +41,7 @@ func (src *BuildStrategy) ConvertTo(ctx context.Context, obj *unstructured.Unstr
}

func (src *BuildStrategySpec) ConvertTo(bs *v1alpha1.BuildStrategySpec) {
usesMigratedDockerfileArg := false
usesMigratedDockerfileArg, usesMigratedBuilderArg := false, false

bs.Parameters = []v1alpha1.Parameter{}
for _, param := range src.Parameters {
Expand All @@ -50,6 +50,11 @@ func (src *BuildStrategySpec) ConvertTo(bs *v1alpha1.BuildStrategySpec) {
continue
}

if param.Name == "builder-image" && param.Type == ParameterTypeString && param.Default == nil {
usesMigratedBuilderArg = true
continue
}

bs.Parameters = append(bs.Parameters, v1alpha1.Parameter{
Name: param.Name,
Description: param.Description,
Expand Down Expand Up @@ -99,6 +104,28 @@ func (src *BuildStrategySpec) ConvertTo(bs *v1alpha1.BuildStrategySpec) {
}
}

if usesMigratedBuilderArg {
// Migrate to legacy argument

for commandIndex, command := range buildStep.Command {
if strings.Contains(command, "$(params.builder-image)") {
buildStep.Command[commandIndex] = strings.ReplaceAll(command, "$(params.builder-image)", "$(build.builder.image)")
}
}

for argIndex, arg := range buildStep.Args {
if strings.Contains(arg, "$(params.dockerfile)") {
buildStep.Args[argIndex] = strings.ReplaceAll(arg, "$(params.builder-image)", "$(build.builder.image)")
}
}

for envIndex, env := range buildStep.Env {
if strings.Contains(env.Value, "$(params.dockerfile)") {
buildStep.Env[envIndex].Value = strings.ReplaceAll(env.Value, "$(params.builder-image)", "$(build.builder.image)")
}
}
}

bs.BuildSteps = append(bs.BuildSteps, buildStep)
}

Expand Down Expand Up @@ -141,7 +168,7 @@ func (src *BuildStrategy) ConvertFrom(ctx context.Context, obj *unstructured.Uns
func (src *BuildStrategySpec) ConvertFrom(bs v1alpha1.BuildStrategySpec) {
src.Steps = []Step{}

usesDockerfile := false
usesDockerfile, usesBuilderImage := false, false

for _, brStep := range bs.BuildSteps {
step := Step{
Expand All @@ -168,6 +195,10 @@ func (src *BuildStrategySpec) ConvertFrom(bs v1alpha1.BuildStrategySpec) {
usesDockerfile = true
step.Command[commandIndex] = strings.ReplaceAll(command, "$(build.dockerfile)", "$(params.dockerfile)")
}
if strings.Contains(command, "$(build.builder.image)") {
usesBuilderImage = true
step.Command[commandIndex] = strings.ReplaceAll(command, "$(build.builder.image)", "$(params.builder-image)")
}
}

for argIndex, arg := range step.Args {
Expand All @@ -179,6 +210,10 @@ func (src *BuildStrategySpec) ConvertFrom(bs v1alpha1.BuildStrategySpec) {
usesDockerfile = true
step.Args[argIndex] = strings.ReplaceAll(arg, "$(build.dockerfile)", "$(params.dockerfile)")
}
if strings.Contains(arg, "$(build.builder.image)") {
usesBuilderImage = true
step.Command[argIndex] = strings.ReplaceAll(arg, "$(build.builder.image)", "$(params.builder-image)")
}
}

for envIndex, env := range step.Env {
Expand All @@ -190,6 +225,10 @@ func (src *BuildStrategySpec) ConvertFrom(bs v1alpha1.BuildStrategySpec) {
usesDockerfile = true
step.Env[envIndex].Value = strings.ReplaceAll(env.Value, "$(build.dockerfile)", "$(params.dockerfile)")
}
if strings.Contains(env.Value, "$(build.builder.image)") {
usesBuilderImage = true
step.Command[envIndex] = strings.ReplaceAll(env.Value, "$(build.builder.image)", "$(params.builder-image)")
}
}

src.Steps = append(src.Steps, step)
Expand All @@ -213,7 +252,15 @@ 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"),
})
}

if usesBuilderImage {
src.Parameters = append(src.Parameters, Parameter{
Name: "builder-image",
Description: "The builder image.",
Type: ParameterTypeString,
})
}

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
Loading

0 comments on commit f4f6eaa

Please sign in to comment.