-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add delete and finalizer to ragengine
Signed-off-by: Bangqi Zhu <[email protected]>
- Loading branch information
Bangqi Zhu
committed
Oct 23, 2024
1 parent
788c32c
commit bc8e411
Showing
7 changed files
with
120 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
package controllers | ||
|
||
import ( | ||
"context" | ||
|
||
kaitov1alpha1 "github.com/azure/kaito/api/v1alpha1" | ||
"github.com/azure/kaito/pkg/featuregates" | ||
"github.com/azure/kaito/pkg/machine" | ||
"github.com/azure/kaito/pkg/nodeclaim" | ||
"github.com/azure/kaito/pkg/utils/consts" | ||
"k8s.io/klog/v2" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
) | ||
|
||
// garbageCollectRAGEngine remove finalizer associated with ragengine object. | ||
func (c *RAGEngineReconciler) garbageCollectRAGEngine(ctx context.Context, ragEngineObj *kaitov1alpha1.RAGEngine) (ctrl.Result, error) { | ||
klog.InfoS("garbageCollectRAGEngine", "ragengine", klog.KObj(ragEngineObj)) | ||
|
||
// Check if there are any machines associated with this ragengine. | ||
mList, err := machine.ListMachines(ctx, ragEngineObj, c.Client) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
// We should delete all the machines that are created by this ragengine | ||
for i := range mList.Items { | ||
if deleteErr := c.Delete(ctx, &mList.Items[i], &client.DeleteOptions{}); deleteErr != nil { | ||
klog.ErrorS(deleteErr, "failed to delete the machine", "machine", klog.KObj(&mList.Items[i])) | ||
return ctrl.Result{}, deleteErr | ||
} | ||
} | ||
|
||
if featuregates.FeatureGates[consts.FeatureFlagKarpenter] { | ||
// Check if there are any nodeClaims associated with this ragengine. | ||
ncList, err := nodeclaim.ListNodeClaim(ctx, ragEngineObj, c.Client) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
// We should delete all the nodeClaims that are created by this ragengine | ||
for i := range ncList.Items { | ||
if deleteErr := c.Delete(ctx, &ncList.Items[i], &client.DeleteOptions{}); deleteErr != nil { | ||
klog.ErrorS(deleteErr, "failed to delete the nodeClaim", "nodeClaim", klog.KObj(&ncList.Items[i])) | ||
return ctrl.Result{}, deleteErr | ||
} | ||
} | ||
} | ||
|
||
staleWObj := ragEngineObj.DeepCopy() | ||
staleWObj.SetFinalizers(nil) | ||
if updateErr := c.Update(ctx, staleWObj, &client.UpdateOptions{}); updateErr != nil { | ||
klog.ErrorS(updateErr, "failed to remove the finalizer from the ragengine", | ||
"ragengine", klog.KObj(ragEngineObj), "ragengine", klog.KObj(staleWObj)) | ||
return ctrl.Result{}, updateErr | ||
} | ||
klog.InfoS("successfully removed the ragengine finalizers", | ||
"ragengine", klog.KObj(ragEngineObj)) | ||
controllerutil.RemoveFinalizer(ragEngineObj, consts.RAGEngineFinalizer) | ||
return ctrl.Result{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters