Adding delettion and creation call. 66/12166/2
authornaman.gupta <naman.gupta@samsung.com>
Fri, 1 Dec 2023 18:37:08 +0000 (00:07 +0530)
committerThoralf Czichy <thoralf.czichy@nokia.com>
Thu, 7 Dec 2023 09:37:26 +0000 (09:37 +0000)
Adding delettion and creation call for deploy and undeploy.

Change-Id: Icf6d91f48f2a0ca5f46a481fdc7bd6d22c907e95
Signed-off-by: naman.gupta <naman.gupta@samsung.com>
depRicKubernetesOperator/internal/controller/ricplatform_controller.go

index 314b92e..34e044b 100644 (file)
@@ -41,6 +41,15 @@ type RicPlatformReconciler struct {
        Scheme *runtime.Scheme
 }
 
+func (r *RicPlatformReconciler) handle_deploy_using_generated_go_code(usage string) {
+       // return
+       if usage == "create" {
+               r.CreateAll()
+       } else {
+               r.DeleteAll()
+       }
+}
+
 //+kubebuilder:rbac:groups=ricdeploy.ricplt.com,resources=ricplatforms,verbs=get;list;watch;create;update;patch;delete
 //+kubebuilder:rbac:groups=ricdeploy.ricplt.com,resources=ricplatforms/status,verbs=get;update;patch
 //+kubebuilder:rbac:groups=ricdeploy.ricplt.com,resources=ricplatforms/finalizers,verbs=update
@@ -75,6 +84,10 @@ func (r *RicPlatformReconciler) Reconcile(ctx context.Context, req ctrl.Request)
        if instance.ObjectMeta.DeletionTimestamp.IsZero() {
                // Adding a Finaliser also adds the DeletionTimestamp while deleting
                if !controllerutil.ContainsFinalizer(instance, myFinalizerName) {
+                       logger.Info("--- Job is in Creation state")
+                       //r.get_replicas(logger, "intent-config", instance)
+                       r.handle_deploy_using_generated_go_code("create")
+                       logger.Info("--- Job has been Created")
                        controllerutil.AddFinalizer(instance, myFinalizerName)
                        if err := r.Update(ctx, instance); err != nil {
                                return ctrl.Result{}, err
@@ -83,6 +96,9 @@ func (r *RicPlatformReconciler) Reconcile(ctx context.Context, req ctrl.Request)
        } else {
                // The object is being deleted
                if controllerutil.ContainsFinalizer(instance, myFinalizerName) {
+                       logger.Info("--- Job is in Deletion state")
+                       r.handle_deploy_using_generated_go_code("delete")
+                       logger.Info("--- Job has been Delete")
                        // remove our finalizer from the list and update it.
                        controllerutil.RemoveFinalizer(instance, myFinalizerName)
                        if err := r.Update(ctx, instance); err != nil {