Skip to content

Commit

Permalink
Logs for the build cleaner
Browse files Browse the repository at this point in the history
Useful to troubleshoot situations when the app droplet is missing

Co-authored-by: Georgi Sabev <[email protected]>
  • Loading branch information
danail-branekov and georgethebeatle committed May 13, 2024
1 parent a03dc97 commit c353c9e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions controllers/cleanup/build_cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package cleanup

import (
"context"
"fmt"
"sort"

korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1"
"code.cloudfoundry.org/korifi/statefulset-runner/controllers"
"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -21,6 +23,8 @@ func NewBuildCleaner(k8sClient client.Client, retainedBuilds int) BuildCleaner {
}

func (c BuildCleaner) Clean(ctx context.Context, app types.NamespacedName) error {
log := logr.FromContextOrDiscard(ctx).WithName("BuildCleaner").WithValues("app", app)

var cfApp korifiv1alpha1.CFApp
err := c.k8sClient.Get(ctx, app, &cfApp)
if err != nil {
Expand All @@ -39,13 +43,18 @@ func (c BuildCleaner) Clean(ctx context.Context, app types.NamespacedName) error
}

var deletableBuilds []korifiv1alpha1.CFBuild
log.Info("processing builds", "count", len(cfBuilds.Items))
for _, cfBuild := range cfBuilds.Items {
if cfBuild.Name == cfApp.Spec.CurrentDropletRef.Name {
continue
}
if !meta.IsStatusConditionTrue(cfBuild.Status.Conditions, korifiv1alpha1.SucceededConditionType) {
continue
}
log.Info("found deletable build",
"buildGUID", cfBuild.Name,
"appCurrentDroplet", cfApp.Spec.CurrentDropletRef.Name,
"succeedCondition", fmt.Sprintf("%v", meta.FindStatusCondition(cfBuild.Status.Conditions, korifiv1alpha1.SucceededConditionType)))
deletableBuilds = append(deletableBuilds, cfBuild)
}

Expand All @@ -54,6 +63,7 @@ func (c BuildCleaner) Clean(ctx context.Context, app types.NamespacedName) error
})

for i := c.retainedBuilds; i < len(deletableBuilds); i++ {
log.Info("deleting deletable build", "buildGUID", deletableBuilds[i].Name)
err = c.k8sClient.Delete(ctx, &deletableBuilds[i])
if err != nil {
return err
Expand Down

0 comments on commit c353c9e

Please sign in to comment.