seaweedfs-operator/controllers/objectstore/master_controller_ensure.go

33 lines
1.1 KiB
Go
Raw Normal View History

2020-07-29 06:21:01 +00:00
package controllers
import (
"context"
"time"
"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime"
"github.com/seaweedfs/seaweedfs-operator/apis/objectstore/v100"
)
func (r *MasterReconciler) findMasterInstance(req controllerruntime.Request, ctx context.Context, log logr.Logger) (*v100.Master, bool, controllerruntime.Result, error) {
// fetch the master instance
master := &v100.Master{}
err := r.Get(ctx, req.NamespacedName, master)
if err != nil {
if errors.IsNotFound(err) {
// Request object not found, could have been deleted after reconcile request.
// Owned objects are automatically garbage collected. For additional cleanup logic use finalizers.
// Return and don't requeue
log.Info("Master resource not found. Ignoring since object must be deleted")
return nil, true, controllerruntime.Result{RequeueAfter: time.Second * 5}, nil
}
// Error reading the object - requeue the request.
log.Error(err, "Failed to get Master")
return nil, true, controllerruntime.Result{}, err
}
log.Info("Get master " + master.Name)
return master, false, controllerruntime.Result{}, nil
}