package resources import ( "context" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" v1etcd "edge-infra.dev/pkg/sds/etcd/operator/apis/etcdmember/v1" kubeclienttypes "edge-infra.dev/pkg/sds/lib/k8s/retryclient/types" ) type SecretHandler struct { *corev1.Secret Client kubeclienttypes.Retrier Key types.NamespacedName Found bool } // Validate will validate the Secret using a DryRun create func (h *SecretHandler) Validate(ctx context.Context) error { opts := &client.CreateOptions{} client.DryRunAll.ApplyToCreate(opts) return client.IgnoreAlreadyExists(h.Client.SafeCreate(ctx, h.Secret, opts)) } // ReconcileLocal updates the local copy of the Secret with the latest // version from the API server func (h *SecretHandler) ReconcileLocal(ctx context.Context) error { return h.Client.SafeGet(ctx, h.Key, h.Secret) } // CreateRemote creates the Secret in the API server func (h *SecretHandler) CreateRemote(ctx context.Context) error { return h.Client.SafeCreate(ctx, h.Secret) } // DeleteRemote deletes the Secret from the API server func (h *SecretHandler) DeleteRemote(ctx context.Context) error { return h.Client.SafeDelete(ctx, h.Secret) } // DeepCopyFrom copies the contents of the provided Secret into the local // copy of the Secret func (h *SecretHandler) DeepCopyFrom(from *corev1.Secret) { from.DeepCopyInto(h.Secret) } func (h *SecretHandler) OwnedByEtcdMember() bool { for _, ownerRef := range h.OwnerReferences { if ownerRef.Kind == v1etcd.Kind { return true } } return false }