Skip to content

Instantly share code, notes, and snippets.

@stijndehaes
stijndehaes / hash.go
Created April 14, 2022 12:42
Calculate has of object via json
func HashEvent(event interface{}) (string, error) {
eventJson, err := json.Marshal(event)
if err != nil {
return "", err
}
h := sha256.New()
h.Write(eventJson)
return fmt.Sprintf("%x", h.Sum(nil)), nil
}
@stijndehaes
stijndehaes / record.go
Last active October 29, 2021 08:36
record.go
func (r *NotebookReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
... Your reconcilitaion
if err != nil {
r.Recorder.Event(&notebook, "Warning", "ErrorOccurred", err.Error())
}
return result, err
}
@stijndehaes
stijndehaes / retry.go
Last active October 29, 2021 08:35
Retry mechanism for kubebuilder
import (
"context"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)