Documentation ¶
Overview ¶
Package secret contains useful functionality for select secret
Index ¶
- Variables
- func GetSecretByRefOrLabel(ctx context.Context, clt client.Client, ref *corev1.ObjectReference) (obj *corev1.Secret, err error)
- func HasAnnotationsKey(annotations, expectedAnnotaions map[string]string, matchValue bool) bool
- func SelectToolSecret(logger *zap.SugaredLogger, clientI interface{}, resourceURL string, ...) (secret *corev1.Secret, err error)
- func SelectToolSecretByRefOrLabelOrURL(ctx context.Context, currentNamespace string, url string, ...) (*corev1.Secret, error)
- func SelectToolSecretFrom(logger *zap.SugaredLogger, secretList []corev1.Secret, isGlobal bool, ...) []corev1.Secret
- func WithMutator(ctx context.Context, mutator Mutator) context.Context
- type MutateFunc
- type Mutator
- type MutatorList
- type NoOpMutator
- type ResourcePathFormat
- type SecretTypeList
- type SelectSecretOption
- type SortedSecretList
Constants ¶
This section is empty.
Variables ¶
var DefaultMutator = &NoOpMutator{}
DefaultMutator is a no-operation implementation of the Mutator interface. It is used as a default option when there is no Mutator associated with the context.
Functions ¶
func GetSecretByRefOrLabel ¶
func GetSecretByRefOrLabel(ctx context.Context, clt client.Client, ref *corev1.ObjectReference) (obj *corev1.Secret, err error)
GetSecretByRefOrLabel retrieves an secret If the ref.namespace is empty, it will use the namespace from the ctx. If the resource does not exist, it will try to match according to the label.
func HasAnnotationsKey ¶
HasAnnotationsKey whether to include the expected annotation key, returns true when the expected annotation is empty.
func SelectToolSecret ¶
func SelectToolSecret(logger *zap.SugaredLogger, clientI interface{}, resourceURL string, option SelectSecretOption) (secret *corev1.Secret, err error)
SelectToolSecret will select secret according to tool address and resource scope on secret
clientI could be sigs.k8s.io/controller-runtime/pkg/client.Client or k8s.io/client-go/kubernetes.Interface or "k8s.io/client-go/informers".SharedInformerFactory resourceURL refers resource url lik git http url or harbor http url. eg. https://github.com/example or build.harbor.com/example namespaces refers to all namespaces where the secret may exist
if no secret was found, secret will be nil and err is nil if any errors occurred, err will not be nil The meaning of preferred is that if there is a secret with this name, it will be selected first, and preferredNs means the namespace where the secret is located
func SelectToolSecretByRefOrLabelOrURL ¶
func SelectToolSecretByRefOrLabelOrURL(ctx context.Context, currentNamespace string, url string, secretRef *corev1.ObjectReference) (*corev1.Secret, error)
SelectToolSecretByRefOrLabelOrURL will select secret by secretRef first, if not found, will select by label, if not found, will select by url
func SelectToolSecretFrom ¶ added in v0.9.0
func SelectToolSecretFrom(logger *zap.SugaredLogger, secretList []corev1.Secret, isGlobal bool, resourceURL *neturl.URL, option SelectSecretOption) []corev1.Secret
SelectToolSecretFrom selects the secret that matches the resource url from the secret list
Types ¶
type MutateFunc ¶ added in v0.9.0
MutateFunc is a function type that implements the Mutator interface.
type Mutator ¶ added in v0.9.0
Mutator interface defines a method for modifying Secret objects.
func MutatorFromCtx ¶ added in v0.9.0
MutatorFromCtx retrieves a Mutator from the given context. If no Mutator is found, it returns the noOpMutator.
type NoOpMutator ¶ added in v0.9.0
type NoOpMutator struct { }
NoOpMutator struct implements the Mutator interface but performs no actions.
type ResourcePathFormat ¶
type ResourcePathFormat struct {
// contains filtered or unexported fields
}
ResourcePathFormat manage the resource path format
func NewResourcePathFormat ¶
func NewResourcePathFormat(pathJson, subPathJson string) *ResourcePathFormat
NewResourcePathFormat construct a ResourcePathFormat from json string
func (*ResourcePathFormat) FormatPathAllScene ¶
func (p *ResourcePathFormat) FormatPathAllScene(scope string) (list []string)
FormatPathAllScene get the formatted strings of all scenes
func (*ResourcePathFormat) FormatPathByScene ¶
func (p *ResourcePathFormat) FormatPathByScene(scene metav1alpha1.ResourcePathScene, scope string) string
FormatPathByScene get the formatted string of special scene
type SecretTypeList ¶
type SecretTypeList []corev1.SecretType
func (SecretTypeList) Contains ¶
func (s SecretTypeList) Contains(e corev1.SecretType) bool
type SelectSecretOption ¶
type SelectSecretOption struct { // Scene indicates resource url format in different scenario Scene string // PerferredSecret will return the secret if it is be selected PerferredSecret types.NamespacedName // ExcludedSecretTypes exclude some secret types when do selecting ExcludedSecretTypes SecretTypeList // SecretTypes means only secret which type exist in this list will be selected // if it is empty means there is no limit for secret type when selecting SecretTypes SecretTypeList // Namespace indicates current namespace that current resource belongs. // the secret will be searched in this namespace // as a default action, secret in the same namespace could be used by other resources in same namespace Namespace string // GlobalCredentialsNamespace is the namespace that we save global credentials. // it is not public to all namespace only until it is bind to one project(namespace) // the secret will be searched in this namespace GlobalCredentialsNamespace string // LabelSelector is label selector when select secret, default will be everything LabelSelector labels.Selector // IncludeAnnotaion if specified, it needs to be filtered base IncludeAnnotaion. Currently only key value filtering is used. IncludeAnnotaion map[string]string }
SelectSecretOption encapsulate the configuration related to selecting secrets
func NewSecretSelectOption ¶
func NewSecretSelectOption(preferredSecret types.NamespacedName, namespace string, globalCredentialsNamespace string) (option SelectSecretOption)
NewSecretSelectOption just construct SecretSelectOption
type SortedSecretList ¶
func (SortedSecretList) Len ¶
func (s SortedSecretList) Len() int
func (SortedSecretList) Less ¶
func (s SortedSecretList) Less(i, j int) bool
func (SortedSecretList) Swap ¶
func (s SortedSecretList) Swap(i, j int)