Skip to content

Commit

Permalink
Merge pull request #376 from Revolyssup/fix
Browse files Browse the repository at this point in the history
Perform correct cleanup using ownerReferences
  • Loading branch information
leecalcote authored Sep 28, 2022
2 parents 0db958c + 5a65008 commit 579c41c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion controllers/broker_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ func (r *BrokerReconciler) reconcileBroker(ctx context.Context, enable bool, bas
object,
)
if err != nil && kubeerror.IsNotFound(err) && enable {
_ = ctrl.SetControllerReference(baseResource, object, r.Scheme)
er := r.Create(ctx, object)
if er != nil {
return ctrl.Result{}, ErrCreateMeshsync(er)
}
_ = ctrl.SetControllerReference(baseResource, object, r.Scheme)
return ctrl.Result{Requeue: true}, nil
} else if err != nil && enable {
return ctrl.Result{}, ErrGetMeshsync(err)
Expand Down
3 changes: 2 additions & 1 deletion controllers/meshsync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
util "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

mesheryv1alpha1 "github.com/layer5io/meshery-operator/api/v1alpha1"
brokerpackage "github.com/layer5io/meshery-operator/pkg/broker"
Expand Down Expand Up @@ -140,11 +141,11 @@ func (r *MeshSyncReconciler) reconcileMeshsync(ctx context.Context, enable bool,
object,
)
if err != nil && kubeerror.IsNotFound(err) && enable {
_ = util.SetControllerReference(baseResource, object, r.Scheme)
er := r.Create(ctx, object)
if er != nil {
return ctrl.Result{}, ErrCreateMeshsync(er)
}
_ = ctrl.SetControllerReference(baseResource, object, r.Scheme)
return ctrl.Result{Requeue: true}, nil
} else if err != nil && enable {
return ctrl.Result{}, ErrGetMeshsync(err)
Expand Down
12 changes: 0 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,4 @@ func main() {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}

// Cleanup residual controllers
setupLog.Info("cleaning up residual controllers")
err = mReconciler.Cleanup()
if err != nil {
ctrl.Log.Error(err, "unable to delete controller", "MeshSync")
}

err = bReconciler.Cleanup()
if err != nil {
ctrl.Log.Error(err, "unable to delete controller", "Broker")
}
}
13 changes: 9 additions & 4 deletions pkg/broker/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ var (

NatsConfigMap = &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "meshery-nats-config",
Labels: BrokerLabel,
Namespace: "meshery",
Name: "meshery-nats-config",
Labels: BrokerLabel,
},
Data: map[string]string{
"nats.conf": `
Expand All @@ -59,8 +60,9 @@ include "accounts/resolver.conf"`,

AccountsConfigMap = &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "meshery-nats-accounts",
Labels: BrokerLabel,
Namespace: "meshery",
Name: "meshery-nats-accounts",
Labels: BrokerLabel,
},
Data: map[string]string{
"resolver.conf": `
Expand All @@ -73,6 +75,7 @@ ACSU3Q6LTLBVLGAQUONAGXJHVNWGSKKAUA7IY5TB4Z7PLEKSR5O6JTGR: eyJ0eXAiOiJqd3QiLCJhbG

Service = &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: "meshery",
Name: "meshery-nats",
Labels: BrokerLabel,
Annotations: MesheryAnnotation,
Expand Down Expand Up @@ -111,6 +114,7 @@ ACSU3Q6LTLBVLGAQUONAGXJHVNWGSKKAUA7IY5TB4Z7PLEKSR5O6JTGR: eyJ0eXAiOiJqd3QiLCJhbG

StatefulSet = &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Namespace: "meshery",
Name: "meshery-nats",
Labels: BrokerLabel,
Annotations: MesheryAnnotation,
Expand All @@ -127,6 +131,7 @@ ACSU3Q6LTLBVLGAQUONAGXJHVNWGSKKAUA7IY5TB4Z7PLEKSR5O6JTGR: eyJ0eXAiOiJqd3QiLCJhbG

PodTemplate = corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Namespace: "meshery",
Name: "meshery-nats",
Labels: BrokerLabel,
Annotations: PrometheusAnnotation,
Expand Down

0 comments on commit 579c41c

Please sign in to comment.