Skip to content

Commit

Permalink
feat(STONEINTG-883): set OwnerRef to ALL snapshots
Browse files Browse the repository at this point in the history
Signed-off-by: Dheeraj<[email protected]>
  • Loading branch information
dheerajodha committed Dec 6, 2024
1 parent b547faa commit 8273098
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
13 changes: 1 addition & 12 deletions internal/controller/snapshot/snapshot_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
clienterrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

applicationapiv1alpha1 "github.com/konflux-ci/application-api/api/v1alpha1"
"github.com/konflux-ci/integration-service/api/v1beta2"
Expand Down Expand Up @@ -522,18 +521,8 @@ func (a *Adapter) EnsureOverrideSnapshotValid() (controller.OperationResult, err
return controller.ContinueProcessing()
}

var err error
if !controllerutil.HasControllerReference(a.snapshot) {
a.snapshot, err = gitops.SetOwnerReference(a.context, a.client, a.snapshot, a.application)
if err != nil {
a.logger.Error(err, fmt.Sprintf("Failed to set owner reference for snapshot %s/%s", a.snapshot.Namespace, a.snapshot.Name))
return controller.RequeueWithError(err)
}
a.logger.Info("Owner reference has been set to snapshot")
}

// validate all snapshotComponents' containerImages/source in snapshot, make all errors joined
var errsForSnapshot error
var err, errsForSnapshot error
for _, snapshotComponent := range a.snapshot.Spec.Components {
snapshotComponent := snapshotComponent //G601
_, err := a.loader.GetComponent(a.context, a.client, snapshotComponent.Name, a.snapshot.Namespace)
Expand Down
11 changes: 11 additions & 0 deletions internal/controller/snapshot/snapshot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"k8s.io/client-go/util/retry"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/predicate"
)

Expand Down Expand Up @@ -112,6 +113,16 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
return helpers.HandleLoaderError(logger, err, "Application", "Snapshot")
}

if !controllerutil.HasControllerReference(snapshot) {
snapshot, err = gitops.SetOwnerReference(ctx, r.Client, snapshot, application)
if err != nil {
logger.Error(err, fmt.Sprintf("Failed to set owner reference for snapshot %s/%s", snapshot.Namespace, snapshot.Name))
return ctrl.Result{}, err
}
logger.LogAuditEvent(fmt.Sprintf("Application %s has been set as a Controller OwnerReference on Snapshot %s", application.Name, snapshot.Name),
snapshot, helpers.LogActionUpdate)
}

logger = logger.WithApp(*application)

adapter := NewAdapter(ctx, snapshot, application, logger, loader, r.Client)
Expand Down

0 comments on commit 8273098

Please sign in to comment.