mirror of
https://github.com/storytold/irsa-manager.git
synced 2026-10-16 00:13:23 +00:00
no update (secret)
This commit is contained in:
@@ -4,11 +4,14 @@ import (
|
||||
"context"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
type KubernetesClient interface {
|
||||
Apply(ctx context.Context, obj client.Object) error
|
||||
Create(ctx context.Context, obj client.Object) error
|
||||
Get(ctx context.Context, obj client.Object) (*unstructured.Unstructured, error)
|
||||
Delete(ctx context.Context, obj client.Object, opts DeleteOptions) error
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
@@ -23,6 +25,20 @@ func (k *KubernetesHandler) Append(obj client.Object) {
|
||||
k.objs = append(k.objs, obj)
|
||||
}
|
||||
|
||||
// CreateAll creates the given objects (AlreadyExists errors are ignored)
|
||||
func (k *KubernetesHandler) CreateAll(ctx context.Context) error {
|
||||
for _, obj := range k.objs {
|
||||
err := k.client.Create(ctx, obj)
|
||||
if err != nil {
|
||||
if !errors.IsAlreadyExists(err) {
|
||||
return err
|
||||
}
|
||||
log.Printf("resource %s/%s already exists. skipped to create \n", obj.GetNamespace(), obj.GetName())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k *KubernetesHandler) ApplyAll(ctx context.Context) error {
|
||||
for _, obj := range k.objs {
|
||||
err := k.client.Apply(ctx, obj)
|
||||
|
||||
Reference in New Issue
Block a user