...

Source file src/edge-infra.dev/pkg/sds/etcd/operator/internal/resources/secret.go

Documentation: edge-infra.dev/pkg/sds/etcd/operator/internal/resources

     1  package resources
     2  
     3  import (
     4  	"context"
     5  
     6  	corev1 "k8s.io/api/core/v1"
     7  	"k8s.io/apimachinery/pkg/types"
     8  	"sigs.k8s.io/controller-runtime/pkg/client"
     9  
    10  	v1etcd "edge-infra.dev/pkg/sds/etcd/operator/apis/etcdmember/v1"
    11  	kubeclienttypes "edge-infra.dev/pkg/sds/lib/k8s/retryclient/types"
    12  )
    13  
    14  type SecretHandler struct {
    15  	*corev1.Secret
    16  
    17  	Client kubeclienttypes.Retrier
    18  	Key    types.NamespacedName
    19  	Found  bool
    20  }
    21  
    22  // Validate will validate the Secret using a DryRun create
    23  func (h *SecretHandler) Validate(ctx context.Context) error {
    24  	opts := &client.CreateOptions{}
    25  	client.DryRunAll.ApplyToCreate(opts)
    26  	return client.IgnoreAlreadyExists(h.Client.SafeCreate(ctx, h.Secret, opts))
    27  }
    28  
    29  // ReconcileLocal updates the local copy of the Secret with the latest
    30  // version from the API server
    31  func (h *SecretHandler) ReconcileLocal(ctx context.Context) error {
    32  	return h.Client.SafeGet(ctx, h.Key, h.Secret)
    33  }
    34  
    35  // CreateRemote creates the Secret in the API server
    36  func (h *SecretHandler) CreateRemote(ctx context.Context) error {
    37  	return h.Client.SafeCreate(ctx, h.Secret)
    38  }
    39  
    40  // DeleteRemote deletes the Secret from the API server
    41  func (h *SecretHandler) DeleteRemote(ctx context.Context) error {
    42  	return h.Client.SafeDelete(ctx, h.Secret)
    43  }
    44  
    45  // DeepCopyFrom copies the contents of the provided Secret into the local
    46  // copy of the Secret
    47  func (h *SecretHandler) DeepCopyFrom(from *corev1.Secret) {
    48  	from.DeepCopyInto(h.Secret)
    49  }
    50  
    51  func (h *SecretHandler) OwnedByEtcdMember() bool {
    52  	for _, ownerRef := range h.OwnerReferences {
    53  		if ownerRef.Kind == v1etcd.Kind {
    54  			return true
    55  		}
    56  	}
    57  	return false
    58  }
    59  

View as plain text