Skip to content

Commit

Permalink
integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qu1queee committed Jan 12, 2024
1 parent 3c23b25 commit 67f6ebd
Show file tree
Hide file tree
Showing 22 changed files with 403 additions and 435 deletions.
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"
utils "github.com/shipwright-io/build/test/utils/v1alpha1"
utils "github.com/shipwright-io/build/test/utils/v1beta1"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/buildlimitcleanup/build_limit_cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"context"
"sort"

build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
build "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
"github.com/shipwright-io/build/pkg/config"
"github.com/shipwright-io/build/pkg/ctxlog"
corev1 "k8s.io/api/core/v1"
Expand Down
26 changes: 13 additions & 13 deletions pkg/reconciler/buildlimitcleanup/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package buildlimitcleanup
import (
"context"

buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
"github.com/shipwright-io/build/pkg/config"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -49,12 +49,12 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in

pred := predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
o := e.Object.(*buildv1alpha1.Build)
o := e.Object.(*buildv1beta1.Build)
return o.Spec.Retention != nil && (o.Spec.Retention.FailedLimit != nil || o.Spec.Retention.SucceededLimit != nil)
},
UpdateFunc: func(e event.UpdateEvent) bool {
n := e.ObjectNew.(*buildv1alpha1.Build)
o := e.ObjectOld.(*buildv1alpha1.Build)
n := e.ObjectNew.(*buildv1beta1.Build)
o := e.ObjectOld.(*buildv1beta1.Build)

// Check to see if there are new retention parameters or whether the
// limit values have decreased
Expand Down Expand Up @@ -88,16 +88,16 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in
},
// Reconcile the build the related buildrun has just completed
UpdateFunc: func(e event.UpdateEvent) bool {
n := e.ObjectNew.(*buildv1alpha1.BuildRun)
n := e.ObjectNew.(*buildv1beta1.BuildRun)

// check if Buildrun is related to a build
if n.Spec.BuildRef == nil {
if n.Spec.Build.Name == nil {
return false
}

o := e.ObjectOld.(*buildv1alpha1.BuildRun)
oldCondition := o.Status.GetCondition(buildv1alpha1.Succeeded)
newCondition := n.Status.GetCondition(buildv1alpha1.Succeeded)
o := e.ObjectOld.(*buildv1beta1.BuildRun)
oldCondition := o.Status.GetCondition(buildv1beta1.Succeeded)
newCondition := n.Status.GetCondition(buildv1beta1.Succeeded)
if newCondition != nil {
if (oldCondition == nil || oldCondition.Status == corev1.ConditionUnknown) &&
(newCondition.Status == corev1.ConditionFalse || newCondition.Status == corev1.ConditionTrue) {
Expand All @@ -113,18 +113,18 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in
}

// Watch for changes to primary resource Build
if err = c.Watch(&source.Kind{Type: &buildv1alpha1.Build{}}, &handler.EnqueueRequestForObject{}, pred); err != nil {
if err = c.Watch(&source.Kind{Type: &buildv1beta1.Build{}}, &handler.EnqueueRequestForObject{}, pred); err != nil {
return err
}

// Watch for changes to resource BuildRun
return c.Watch(&source.Kind{Type: &buildv1alpha1.BuildRun{}}, handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request {
buildRun := o.(*buildv1alpha1.BuildRun)
return c.Watch(&source.Kind{Type: &buildv1beta1.BuildRun{}}, handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request {
buildRun := o.(*buildv1beta1.BuildRun)

return []reconcile.Request{
{
NamespacedName: types.NamespacedName{
Name: buildRun.Spec.BuildRef.Name,
Name: *buildRun.Spec.Build.Name,
Namespace: buildRun.Namespace,
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/buildrun/buildrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ var _ = Describe("Reconcile BuildRun", func() {
)

// Ensure the BuildRun gets an ownershipReference when
// the buildv1alpha1.AnnotationBuildRunDeletion is set to true
// the buildv1beta1.AnnotationBuildRunDeletion is set to true
// in the build
clientUpdateCalls := ctl.StubBuildUpdateOwnerReferences("Build",
buildName,
Expand Down Expand Up @@ -1446,7 +1446,7 @@ var _ = Describe("Reconcile BuildRun", func() {
},
},
},
ServiceAccount: pointer.String(".generated"),
ServiceAccount: pointer.String(".generate"),
},
}

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 @@ -11,7 +11,7 @@ import (
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
"github.com/shipwright-io/build/pkg/config"
"github.com/shipwright-io/build/pkg/reconciler/buildrun/resources"
utils "github.com/shipwright-io/build/test/utils/v1alpha1"
utils "github.com/shipwright-io/build/test/utils/v1beta1"
pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/buildrun/resources/service_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func GetGeneratedServiceAccountName(buildRun *buildv1beta1.BuildRun) string {

// IsGeneratedServiceAccountUsed checks if a build run uses a generated service account
func IsGeneratedServiceAccountUsed(buildRun *buildv1beta1.BuildRun) bool {
return buildRun.Spec.ServiceAccount != nil && *buildRun.Spec.ServiceAccount == ".generated"
return buildRun.Spec.ServiceAccount != nil && *buildRun.Spec.ServiceAccount == ".generate"
}

// GenerateSA generates a new service account on the fly
Expand Down
6 changes: 3 additions & 3 deletions pkg/reconciler/buildrun/resources/sources/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"

"github.com/shipwright-io/build/pkg/apis/build/v1beta1"
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
"github.com/shipwright-io/build/pkg/config"
pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -25,7 +25,7 @@ const (
func AppendGitStep(
cfg *config.Config,
taskSpec *pipelineapi.TaskSpec,
git buildv1alpha1.Git,
git buildv1beta1.Git,
name string,
) {
// append the result
Expand Down Expand Up @@ -109,7 +109,7 @@ func AppendGitStep(
}

// AppendGitResult append git source result to build run
func AppendGitResult(buildRun *buildv1alpha1.BuildRun, name string, results []pipelineapi.TaskRunResult) {
func AppendGitResult(buildRun *buildv1beta1.BuildRun, name string, results []pipelineapi.TaskRunResult) {
commitAuthor := findResultValue(results, fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, commitAuthorResult))
commitSha := findResultValue(results, fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, commitSHAResult))
branchName := findResultValue(results, fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, branchName))
Expand Down
6 changes: 3 additions & 3 deletions pkg/reconciler/buildrunttlcleanup/buildrun_ttl_cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"context"
"time"

buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
"github.com/shipwright-io/build/pkg/config"
"github.com/shipwright-io/build/pkg/ctxlog"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -44,7 +44,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req

ctxlog.Debug(ctx, "Start reconciling Buildrun-ttl", namespace, request.Namespace, name, request.Name)

br := &buildv1alpha1.BuildRun{}
br := &buildv1beta1.BuildRun{}
err := r.client.Get(ctx, types.NamespacedName{Name: request.Name, Namespace: request.Namespace}, br)
if err != nil {
if apierrors.IsNotFound(err) {
Expand All @@ -54,7 +54,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req
return reconcile.Result{}, err
}

condition := br.Status.GetCondition(buildv1alpha1.Succeeded)
condition := br.Status.GetCondition(buildv1beta1.Succeeded)
if condition == nil || condition.Status == corev1.ConditionUnknown {
return reconcile.Result{}, nil
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/reconciler/buildrunttlcleanup/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package buildrunttlcleanup
import (
"context"

buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
"github.com/shipwright-io/build/pkg/config"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand All @@ -31,7 +31,7 @@ func Add(_ context.Context, c *config.Config, mgr manager.Manager) error {
}

// reconcileCompletedBuildRun returns true if the object has the required TTL parameters
func reconcileCompletedBuildRun(condition *buildv1alpha1.Condition, o *buildv1alpha1.BuildRun) bool {
func reconcileCompletedBuildRun(condition *buildv1beta1.Condition, o *buildv1beta1.BuildRun) bool {
if condition.Status == corev1.ConditionTrue {
// check if a successful BuildRun has a TTL after succeeded value set
if o.Spec.Retention != nil && o.Spec.Retention.TTLAfterSucceeded != nil {
Expand All @@ -56,7 +56,7 @@ func reconcileCompletedBuildRun(condition *buildv1alpha1.Condition, o *buildv1al

// reconcileAlreadyCompletedBuildRun returns true only if the TTL limit was introduced
// or if it was lowered as the object was completed before the update
func reconcileAlreadyCompletedBuildRun(newCondition *buildv1alpha1.Condition, n *buildv1alpha1.BuildRun, o *buildv1alpha1.BuildRun) bool {
func reconcileAlreadyCompletedBuildRun(newCondition *buildv1beta1.Condition, n *buildv1beta1.BuildRun, o *buildv1beta1.BuildRun) bool {
if newCondition.Status == corev1.ConditionTrue {
// check if a successful BuildRun has a TTL that was lowered or introduced
if (o.Spec.Retention == nil || o.Spec.Retention.TTLAfterSucceeded == nil) && n.Spec.Retention != nil && n.Spec.Retention.TTLAfterSucceeded != nil {
Expand Down Expand Up @@ -98,10 +98,10 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in
predBuildRun := predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
// Reconcile if TTL values are set
o := e.Object.(*buildv1alpha1.BuildRun)
o := e.Object.(*buildv1beta1.BuildRun)

// ignore a running BuildRun
condition := o.Status.GetCondition(buildv1alpha1.Succeeded)
condition := o.Status.GetCondition(buildv1beta1.Succeeded)
if condition == nil || condition.Status == corev1.ConditionUnknown {
return false
}
Expand All @@ -110,14 +110,14 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in
},
UpdateFunc: func(e event.UpdateEvent) bool {
// check if the updated object is completed
n := e.ObjectNew.(*buildv1alpha1.BuildRun)
newCondition := n.Status.GetCondition(buildv1alpha1.Succeeded)
n := e.ObjectNew.(*buildv1beta1.BuildRun)
newCondition := n.Status.GetCondition(buildv1beta1.Succeeded)
if newCondition == nil || newCondition.Status == corev1.ConditionUnknown {
return false
}

o := e.ObjectOld.(*buildv1alpha1.BuildRun)
oldCondition := o.Status.GetCondition(buildv1alpha1.Succeeded)
o := e.ObjectOld.(*buildv1beta1.BuildRun)
oldCondition := o.Status.GetCondition(buildv1beta1.Succeeded)

// for objects that failed or just completed, check if a matching TTL is set
if oldCondition == nil || oldCondition.Status == corev1.ConditionUnknown {
Expand All @@ -137,5 +137,5 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in
},
}
// Watch for changes to primary resource BuildRun
return c.Watch(&source.Kind{Type: &buildv1alpha1.BuildRun{}}, &handler.EnqueueRequestForObject{}, predBuildRun)
return c.Watch(&source.Kind{Type: &buildv1beta1.BuildRun{}}, &handler.EnqueueRequestForObject{}, predBuildRun)
}
4 changes: 2 additions & 2 deletions pkg/reconciler/buildstrategy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
"github.com/shipwright-io/build/pkg/config"
)

Expand All @@ -40,5 +40,5 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in
}

// Watch for changes to primary resource BuildStrategy
return c.Watch(&source.Kind{Type: &buildv1alpha1.BuildStrategy{}}, &handler.EnqueueRequestForObject{})
return c.Watch(&source.Kind{Type: &buildv1beta1.BuildStrategy{}}, &handler.EnqueueRequestForObject{})
}
4 changes: 2 additions & 2 deletions pkg/reconciler/clusterbuildstrategy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
"github.com/shipwright-io/build/pkg/config"
)

Expand All @@ -40,5 +40,5 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in
}

// Watch for changes to primary resource ClusterBuildStrategy
return c.Watch(&source.Kind{Type: &buildv1alpha1.ClusterBuildStrategy{}}, &handler.EnqueueRequestForObject{})
return c.Watch(&source.Kind{Type: &buildv1beta1.ClusterBuildStrategy{}}, &handler.EnqueueRequestForObject{})
}
Loading

0 comments on commit 67f6ebd

Please sign in to comment.