apply keypair secret

This commit is contained in:
kkb0318
2024-04-10 23:08:23 +09:00
parent 0a81afa3f1
commit 720bc912b9
11 changed files with 149 additions and 59 deletions
+6 -14
View File
@@ -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,
+11
View File
@@ -0,0 +1,11 @@
package kubernetes
import (
"sigs.k8s.io/controller-runtime/pkg/client"
)
type KubernetesClient struct {
client client.Client
owner Owner
cleanup bool
}
+3 -13
View File
@@ -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
}