Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions internal/controller/appwrapper/appwrapper_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,17 @@ func (r *AppWrapperReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}
}

if err := awstatus.EnsureComponentStatusInitialized(ctx, aw); err != nil {
return ctrl.Result{}, err
}

return r.updateStatus(ctx, aw, workloadv1beta2.AppWrapperSuspended)

case workloadv1beta2.AppWrapperSuspended: // no components deployed
if aw.Spec.Suspend {
return ctrl.Result{}, nil // remain suspended
}

// Normally already done as a side-effect of Kueue calling PodSets(), but be absolutely certain before we start using it.
if err := awstatus.EnsureComponentStatusInitialized(ctx, aw); err != nil {
return ctrl.Result{}, err
}

// begin deployment
meta.SetStatusCondition(&aw.Status.Conditions, metav1.Condition{
Type: string(workloadv1beta2.QuotaReserved),
Expand Down
2 changes: 0 additions & 2 deletions internal/controller/appwrapper/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"

workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
"github.com/project-codeflare/appwrapper/internal/controller/awstatus"
kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1"
)

Expand Down Expand Up @@ -101,7 +100,6 @@ var _ = BeforeSuite(func() {
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
awstatus.CacheClient(k8sClient)
})

var _ = AfterSuite(func() {
Expand Down
36 changes: 1 addition & 35 deletions internal/controller/awstatus/status_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,9 @@ import (

workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
"github.com/project-codeflare/appwrapper/pkg/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var (
cachedClient client.Client
)

const controllerName = "workload.codeflare.dev-appwrapper"

// CacheClient initializes cachedClient; must be called during startup
func CacheClient(k8sclient client.Client) {
cachedClient = k8sclient
}

// BaseSSAAppWrapper creates a new object based on the input AppWrapper that
// only contains the fields necessary to identify the original object.
// The object can be used as a base for Server-Side-Apply.
func BaseSSAAppWrapper(aw *workloadv1beta2.AppWrapper) *workloadv1beta2.AppWrapper {
patch := &workloadv1beta2.AppWrapper{
ObjectMeta: metav1.ObjectMeta{
UID: aw.UID,
Name: aw.Name,
Namespace: aw.Namespace,
},
TypeMeta: metav1.TypeMeta{
APIVersion: workloadv1beta2.GroupVersion.String(),
Kind: "AppWrapper",
},
}
return patch
}

// EnsureComponentStatusInitialized initializes aw.Status.ComponenetStatus, including performing PodSet inference for known GVKs
func EnsureComponentStatusInitialized(ctx context.Context, aw *workloadv1beta2.AppWrapper) error {
if len(aw.Status.ComponentStatus) == len(aw.Spec.Components) {
Expand All @@ -81,8 +50,5 @@ func EnsureComponentStatusInitialized(ctx context.Context, aw *workloadv1beta2.A
}
}
aw.Status.ComponentStatus = compStatus

patch := BaseSSAAppWrapper(aw)
patch.Status.ComponentStatus = compStatus
return cachedClient.Status().Patch(ctx, patch, client.Apply, client.FieldOwner(controllerName), client.ForceOwnership)
return nil
}
2 changes: 0 additions & 2 deletions pkg/controller/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
cert "github.com/open-policy-agent/cert-controller/pkg/rotator"

"github.com/project-codeflare/appwrapper/internal/controller/appwrapper"
"github.com/project-codeflare/appwrapper/internal/controller/awstatus"
"github.com/project-codeflare/appwrapper/internal/controller/workload"
"github.com/project-codeflare/appwrapper/internal/webhook"
"github.com/project-codeflare/appwrapper/pkg/config"
Expand All @@ -39,7 +38,6 @@ import (

// SetupControllers creates and configures all components of the AppWrapper controller
func SetupControllers(mgr ctrl.Manager, awConfig *config.AppWrapperConfig) error {
awstatus.CacheClient(mgr.GetClient())
if awConfig.EnableKueueIntegrations {
if err := workload.WorkloadReconciler(
mgr.GetClient(),
Expand Down