mirror of
https://github.com/storytold/irsa-manager.git
synced 2026-10-18 07:33:15 +00:00
apply keypair secret
This commit is contained in:
@@ -10,22 +10,14 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
cleanup bool
|
||||
client client.Client
|
||||
owner Owner
|
||||
}
|
||||
|
||||
// NewHelper returns an initialized Helper.
|
||||
func NewHandler(c client.Client, owner Owner, cleanup bool) (*Handler, error) {
|
||||
return &Handler{
|
||||
cleanup: cleanup,
|
||||
client: c,
|
||||
owner: owner,
|
||||
func NewKubernetesClient(c client.Client, owner Owner) (*KubernetesClient, error) {
|
||||
return &KubernetesClient{
|
||||
client: c,
|
||||
owner: owner,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (h Handler) Apply(ctx context.Context, obj client.Object) error {
|
||||
func (h KubernetesClient) Apply(ctx context.Context, obj client.Object) error {
|
||||
opts := []client.PatchOption{
|
||||
client.ForceOwnership,
|
||||
client.FieldOwner(h.owner.Field),
|
||||
@@ -50,7 +42,7 @@ func (h Handler) Apply(ctx context.Context, obj client.Object) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h Handler) PatchStatus(ctx context.Context, obj client.Object) error {
|
||||
func (h KubernetesClient) PatchStatus(ctx context.Context, obj client.Object) error {
|
||||
opts := &client.SubResourcePatchOptions{
|
||||
PatchOptions: client.PatchOptions{
|
||||
FieldManager: h.owner.Field,
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package kubernetes
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
type KubernetesClient struct {
|
||||
client client.Client
|
||||
owner Owner
|
||||
cleanup bool
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/kkb0318/irsa-manager/internal/handler"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
@@ -13,18 +14,7 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
// DeleteOptions contains options for delete requests.
|
||||
type DeleteOptions struct {
|
||||
// DeletionPropagation decides how the garbage collector will handle the propagation.
|
||||
DeletionPropagation metav1.DeletionPropagation
|
||||
|
||||
// Inclusions determines which in-cluster objects are subject to deletion
|
||||
// based on the labels.
|
||||
// A nil Inclusions map means all objects are subject to deletion
|
||||
Inclusions map[string]string
|
||||
}
|
||||
|
||||
func (h *Handler) DeleteAll(ctx context.Context, resources []*unstructured.Unstructured, opts DeleteOptions) error {
|
||||
func (h *KubernetesClient) DeleteAll(ctx context.Context, resources []*unstructured.Unstructured, opts handler.DeleteOptions) error {
|
||||
if !h.cleanup {
|
||||
return nil
|
||||
}
|
||||
@@ -38,7 +28,7 @@ func (h *Handler) DeleteAll(ctx context.Context, resources []*unstructured.Unstr
|
||||
}
|
||||
|
||||
// Delete deletes the given object (not found errors are ignored).
|
||||
func (h *Handler) Delete(ctx context.Context, object *unstructured.Unstructured, opts DeleteOptions) error {
|
||||
func (h *KubernetesClient) Delete(ctx context.Context, object *unstructured.Unstructured, opts handler.DeleteOptions) error {
|
||||
if !h.cleanup {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user