Skip to content

Commit

Permalink
Revert fg status configmap to default on KataConfig deletion
Browse files Browse the repository at this point in the history
Since fg status configmap is must and created during operator
initialisation, we need to ensure on KataConfig deletion it's reverted
back to default values.

Signed-off-by: Pradipta Banerjee <pradipta.banerjee@gmail.com>
  • Loading branch information
bpradipt committed Apr 25, 2024
1 parent 3d029f3 commit 501082f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions controllers/openshift_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,13 @@ func (r *KataConfigOpenShiftReconciler) processKataConfigDeleteRequest() (ctrl.R
return ctrl.Result{Requeue: true}, nil
}

// Revert the feature gate status configmap to default
err = r.FeatureGates.RevertFeatureGateStatusConfigMapToDefault(context.TODO())
if err != nil {
r.Log.Info("Error reverting feature gate status configmap to default", "err", err)
return ctrl.Result{Requeue: true}, err
}

r.Log.Info("Uninstallation completed. Proceeding with the KataConfig deletion")
if err = r.removeFinalizer(); err != nil {
return ctrl.Result{Requeue: true}, nil
Expand Down
27 changes: 27 additions & 0 deletions internal/featuregates/featuregates.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package featuregates

import (
"context"
"fmt"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -95,3 +97,28 @@ func (fg *FeatureGates) IsFeatureConfigMapPresent(ctx context.Context, feature s
}
return true
}

// Method to revert the feature gate status configmap to default values
func (fg *FeatureGates) RevertFeatureGateStatusConfigMapToDefault(ctx context.Context) error {
data := make(map[string]string)
for key, value := range DefaultFeatureGatesStatus {
data[key] = fmt.Sprintf("%t", value)
}

configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: fg.ConfigMapName,
Namespace: fg.Namespace,
},

Data: data,
}

err := fg.Client.Update(ctx, configMap)
if err != nil {
fgLogger.Info("Error reverting feature gate status configmap", "err", err)
return err
}
fgLogger.Info("Feature gate status configmap reverted to default values")
return nil
}

0 comments on commit 501082f

Please sign in to comment.