diff --git a/slice/internal/controller/admissioncheck_controller.go b/slice/internal/controller/admissioncheck_controller.go index 996d78143..17da44b82 100644 --- a/slice/internal/controller/admissioncheck_controller.go +++ b/slice/internal/controller/admissioncheck_controller.go @@ -19,6 +19,8 @@ package controller import ( "context" + "tpu-slice-controller/internal/core" + apimeta "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/ptr" @@ -62,8 +64,9 @@ func (r *AdmissionCheckReconciler) Reconcile(ctx context.Context, req ctrl.Reque } if currentCondition.Status != newCondition.Status { - apimeta.SetStatusCondition(&ac.Status.Conditions, newCondition) - return reconcile.Result{}, client.IgnoreNotFound(r.client.Status().Update(ctx, ac)) + acPatch := core.BaseSSAAdmissionCheck(ac) + apimeta.SetStatusCondition(&acPatch.Status.Conditions, newCondition) + return reconcile.Result{}, client.IgnoreNotFound(r.client.Status().Patch(ctx, acPatch, client.Apply, client.FieldOwner(SliceControllerName), client.ForceOwnership)) } return reconcile.Result{}, nil diff --git a/slice/internal/core/admissioncheck.go b/slice/internal/core/admissioncheck.go new file mode 100644 index 000000000..a78984c4e --- /dev/null +++ b/slice/internal/core/admissioncheck.go @@ -0,0 +1,36 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package core + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kueue "sigs.k8s.io/kueue/apis/kueue/v1beta2" +) + +func BaseSSAAdmissionCheck(ac *kueue.AdmissionCheck) *kueue.AdmissionCheck { + return &kueue.AdmissionCheck{ + TypeMeta: metav1.TypeMeta{ + APIVersion: kueue.GroupVersion.String(), + Kind: "AdmissionCheck", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: ac.Name, + Namespace: ac.Namespace, + UID: ac.UID, + }, + } +}