Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
dont use helper pkg for now
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Mar 3, 2020
1 parent b878a02 commit 215309a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 52 deletions.
50 changes: 44 additions & 6 deletions controllers/routemigrate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ import (
routev1 "github.com/openshift/api/route/v1"
corev1 "k8s.io/api/core/v1"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/amazeeio/dioscuri/pkg/helper"
)

// RouteMigrateReconciler reconciles a RouteMigrate object
Expand Down Expand Up @@ -60,7 +59,7 @@ func (r *RouteMigrateReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error
// your logic here
var dioscuri dioscuriv1.RouteMigrate
if err := r.Get(ctx, req.NamespacedName, &dioscuri); err != nil {
return ctrl.Result{}, helper.IgnoreNotFound(err)
return ctrl.Result{}, IgnoreNotFound(err)
}
// your logic here
finalizerName := "finalizer.dioscuri.amazee.io/v1"
Expand Down Expand Up @@ -140,23 +139,23 @@ func (r *RouteMigrateReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error
// The object is not being deleted, so if it does not have our finalizer,
// then lets add the finalizer and update the object. This is equivalent
// registering our finalizer.
if !helper.ContainsString(dioscuri.ObjectMeta.Finalizers, finalizerName) {
if !ContainsString(dioscuri.ObjectMeta.Finalizers, finalizerName) {
dioscuri.ObjectMeta.Finalizers = append(dioscuri.ObjectMeta.Finalizers, finalizerName)
if err := r.Update(context.Background(), &dioscuri); err != nil {
return ctrl.Result{}, err
}
}
} else {
// The object is being deleted
if helper.ContainsString(dioscuri.ObjectMeta.Finalizers, finalizerName) {
if ContainsString(dioscuri.ObjectMeta.Finalizers, finalizerName) {
// our finalizer is present, so lets handle any external dependency
if err := r.deleteExternalResources(&dioscuri, req.NamespacedName.Namespace); err != nil {
// if fail to delete the external dependency here, return with error
// so that it can be retried
return ctrl.Result{}, err
}
// remove our finalizer from the list and update it.
dioscuri.ObjectMeta.Finalizers = helper.RemoveString(dioscuri.ObjectMeta.Finalizers, finalizerName)
dioscuri.ObjectMeta.Finalizers = RemoveString(dioscuri.ObjectMeta.Finalizers, finalizerName)
if err := r.Update(context.Background(), &dioscuri); err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -285,3 +284,42 @@ func (r *RouteMigrateReconciler) removeRoute(route *routev1.Route) error {
}
return nil
}

// IgnoreNotFound will ignore not found errors
func IgnoreNotFound(err error) error {
if apierrors.IsNotFound(err) {
return nil
}
return err
}

// ContainsString check if a slice contains a string
func ContainsString(slice []string, s string) bool {
for _, item := range slice {
if item == s {
return true
}
}
return false
}

// RemoveString remove string from a sliced
func RemoveString(slice []string, s string) (result []string) {
for _, item := range slice {
if item == s {
continue
}
result = append(result, item)
}
return
}

// ContainsStatus check if conditions contains a condition
func ContainsStatus(slice []interface{}, s interface{}) bool {
for _, item := range slice {
if item == s {
return true
}
}
return false
}
46 changes: 0 additions & 46 deletions pkg/helper/helper.go

This file was deleted.

0 comments on commit 215309a

Please sign in to comment.