mirror of
https://github.com/ngrok/ngrok-operator.git
synced 2026-05-17 16:50:44 +00:00
92b135c9c2
* refactor(service-controller): Move to own directory Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com> * feat: Add TCP Addresses mock client Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com> * chore: Update boilerplate.go.txt Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com> * chore: Add helper function in common types Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com> * test: Add kginkgo helpers Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com> * test: Add more tests for LB services In doing so, migrate to envtest to test the controller. Also fix a bug while we are at it Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com> * docs: Add a spec for the service controller Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com> --------- Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com>
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
|
)
|
|
|
|
const (
|
|
FinalizerName = "k8s.ngrok.com/finalizer"
|
|
)
|
|
|
|
func IsUpsert(o client.Object) bool {
|
|
return o.GetDeletionTimestamp().IsZero()
|
|
}
|
|
|
|
func IsDelete(o client.Object) bool {
|
|
return !o.GetDeletionTimestamp().IsZero()
|
|
}
|
|
|
|
func HasFinalizer(o client.Object) bool {
|
|
return controllerutil.ContainsFinalizer(o, FinalizerName)
|
|
}
|
|
|
|
func AddFinalizer(o client.Object) bool {
|
|
return controllerutil.AddFinalizer(o, FinalizerName)
|
|
}
|
|
|
|
func RemoveFinalizer(o client.Object) bool {
|
|
return controllerutil.RemoveFinalizer(o, FinalizerName)
|
|
}
|
|
|
|
func RegisterAndSyncFinalizer(ctx context.Context, c client.Writer, o client.Object) error {
|
|
if !HasFinalizer(o) {
|
|
AddFinalizer(o)
|
|
return c.Update(ctx, o)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func RemoveAndSyncFinalizer(ctx context.Context, c client.Writer, o client.Object) error {
|
|
RemoveFinalizer(o)
|
|
return c.Update(ctx, o)
|
|
}
|
|
|
|
func AddAnnotations(o client.Object, annotations map[string]string) {
|
|
if o == nil || annotations == nil {
|
|
return
|
|
}
|
|
|
|
existing := o.GetAnnotations()
|
|
if existing == nil {
|
|
existing = make(map[string]string)
|
|
}
|
|
|
|
for k, v := range annotations {
|
|
existing[k] = v
|
|
}
|
|
|
|
o.SetAnnotations(existing)
|
|
}
|