Skip to content

Commit

Permalink
using buildapi for github.com/shipwright-io/build/pkg/apis/build/v1be…
Browse files Browse the repository at this point in the history
…ta package
  • Loading branch information
karanibm6 committed Mar 12, 2024
1 parent fd40dd5 commit f81c6f1
Show file tree
Hide file tree
Showing 82 changed files with 1,510 additions and 1,514 deletions.
2 changes: 1 addition & 1 deletion pkg/image/vulnerability_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func RunVulnerabilityScan(ctx context.Context, imagePath string, settings builda
return nil, err
}

// Get the vulnerabilites from the trivy scan
// Get the vulnerabilities from the trivy scan
vulnerabilities := parseTrivyResult(trivyResult, settings.Ignore)

// Sort the vulnerabilities by severity
Expand Down
14 changes: 7 additions & 7 deletions pkg/reconciler/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

build "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
"github.com/shipwright-io/build/pkg/config"
"github.com/shipwright-io/build/pkg/ctxlog"
buildmetrics "github.com/shipwright-io/build/pkg/metrics"
Expand Down Expand Up @@ -64,7 +64,7 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques

ctxlog.Debug(ctx, "start reconciling Build", namespace, request.Namespace, name, request.Name)

b := &build.Build{}
b := &buildapi.Build{}
if err := r.client.Get(ctx, request.NamespacedName, b); err != nil {
if apierrors.IsNotFound(err) {
ctxlog.Debug(ctx, "finish reconciling build. build was not found", namespace, request.Namespace, name, request.Name)
Expand All @@ -75,8 +75,8 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques
}

// Populate the status struct with default values
b.Status.Registered = build.ConditionStatusPtr(corev1.ConditionFalse)
b.Status.Reason = build.BuildReasonPtr(build.SucceedStatus)
b.Status.Registered = buildapi.ConditionStatusPtr(corev1.ConditionFalse)
b.Status.Reason = buildapi.BuildReasonPtr(buildapi.SucceedStatus)

// trigger all current validations
for _, validationType := range validationTypes {
Expand Down Expand Up @@ -104,7 +104,7 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques
}
}

if b.Status.Reason == nil || *b.Status.Reason != build.SucceedStatus {
if b.Status.Reason == nil || *b.Status.Reason != buildapi.SucceedStatus {
if err := r.client.Status().Update(ctx, b); err != nil {
return reconcile.Result{}, err
}
Expand All @@ -113,8 +113,8 @@ 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.Registered = buildapi.ConditionStatusPtr(corev1.ConditionTrue)
b.Status.Message = pointer.String(buildapi.AllValidationsSucceeded)
if err := r.client.Status().Update(ctx, b); err != nil {
return reconcile.Result{}, err
}
Expand Down
114 changes: 57 additions & 57 deletions pkg/reconciler/build/build_test.go

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions pkg/reconciler/build/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

build "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
"github.com/shipwright-io/build/pkg/config"
"github.com/shipwright-io/build/pkg/ctxlog"
)
Expand Down Expand Up @@ -60,8 +60,8 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo

pred := predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
o := e.ObjectOld.(*build.Build)
n := e.ObjectNew.(*build.Build)
o := e.ObjectOld.(*buildapi.Build)
n := e.ObjectNew.(*buildapi.Build)

buildAtBuildDeletion := false

Expand Down Expand Up @@ -119,7 +119,7 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo
}

// Watch for changes to primary resource Build
if err = c.Watch(source.Kind(mgr.GetCache(), &build.Build{}), &handler.EnqueueRequestForObject{}, pred); err != nil {
if err = c.Watch(source.Kind(mgr.GetCache(), &buildapi.Build{}), &handler.EnqueueRequestForObject{}, pred); err != nil {
return err
}

Expand Down Expand Up @@ -160,7 +160,7 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo
return c.Watch(source.Kind(mgr.GetCache(), &corev1.Secret{}), handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, o client.Object) []reconcile.Request {
secret := o.(*corev1.Secret)

buildList := &build.BuildList{}
buildList := &buildapi.BuildList{}

// List all builds in the namespace of the current secret
if err := mgr.GetClient().List(ctx, buildList, &client.ListOptions{Namespace: secret.Namespace}); err != nil {
Expand Down Expand Up @@ -205,7 +205,7 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo
}

func buildCredentialsAnnotationExist(annotation map[string]string) (string, bool) {
if val, ok := annotation[build.AnnotationBuildRefSecret]; ok {
if val, ok := annotation[buildapi.AnnotationBuildRefSecret]; ok {
return val, true
}
return "", false
Expand Down
14 changes: 7 additions & 7 deletions 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/v1beta1"
buildapi "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 @@ -43,7 +43,7 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques

ctxlog.Debug(ctx, "Start reconciling build-limit-cleanup", namespace, request.Namespace, name, request.Name)

b := &build.Build{}
b := &buildapi.Build{}
err := r.client.Get(ctx, request.NamespacedName, b)

if err != nil {
Expand All @@ -65,13 +65,13 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques
}

lbls := map[string]string{
build.LabelBuild: b.Name,
buildapi.LabelBuild: b.Name,
}
opts := client.ListOptions{
Namespace: b.Namespace,
LabelSelector: labels.SelectorFromSet(lbls),
}
allBuildRuns := &build.BuildRunList{}
allBuildRuns := &buildapi.BuildRunList{}

err = r.client.List(ctx, allBuildRuns, &opts)
if err != nil {
Expand All @@ -82,12 +82,12 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques
return reconcile.Result{}, nil
}

var buildRunFailed []build.BuildRun
var buildRunSucceeded []build.BuildRun
var buildRunFailed []buildapi.BuildRun
var buildRunSucceeded []buildapi.BuildRun

// Sort buildruns into successful ones and failed ones
for _, br := range allBuildRuns.Items {
condition := br.Status.GetCondition(build.Succeeded)
condition := br.Status.GetCondition(buildapi.Succeeded)
if condition != nil {
if condition.Status == corev1.ConditionFalse {
buildRunFailed = append(buildRunFailed, br)
Expand Down
22 changes: 11 additions & 11 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"

buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
buildapi "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.(*buildv1beta1.Build)
o := e.Object.(*buildapi.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.(*buildv1beta1.Build)
o := e.ObjectOld.(*buildv1beta1.Build)
n := e.ObjectNew.(*buildapi.Build)
o := e.ObjectOld.(*buildapi.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.(*buildv1beta1.BuildRun)
n := e.ObjectNew.(*buildapi.BuildRun)

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

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

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

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

return []reconcile.Request{
{
Expand Down
Loading

0 comments on commit f81c6f1

Please sign in to comment.