...

Source file src/edge-infra.dev/pkg/k8s/meta/resource_refs.go

Documentation: edge-infra.dev/pkg/k8s/meta

     1  package meta
     2  
     3  import "fmt"
     4  
     5  // Much of this file was originally forked from github.com/fluxcd/pkg/meta to
     6  // avoid the dependency tangle-ups that can occur in a large K8s Golang repository,
     7  // in the view that it is better to fork and iterate on a small bit of code to
     8  // avoid depending on a large bit of code.
     9  
    10  // LocalObjectReference contains enough information to locate the referenced
    11  // Kubernetes resource object.
    12  type LocalObjectReference struct {
    13  	// Name of the referent.
    14  	// +kubebuilder:validation:MinLength=1
    15  	// +kubebuilder:validation:MaxLength=253
    16  	// +required
    17  	Name string `json:"name"`
    18  }
    19  
    20  // NamespacedObjectReference contains enough information to locate the referenced
    21  // Kubernetes resource object in any namespace.
    22  type NamespacedObjectReference struct {
    23  	// Name of the referent.
    24  	// +kubebuilder:validation:MinLength=1
    25  	// +kubebuilder:validation:MaxLength=253
    26  	// +required
    27  	Name string `json:"name"`
    28  
    29  	// Namespace of the referent, when not specified it acts as LocalObjectReference.
    30  	// +kubebuilder:validation:MinLength=1
    31  	// +kubebuilder:validation:MaxLength=253
    32  	// +optional
    33  	Namespace string `json:"namespace,omitempty"`
    34  }
    35  
    36  // String implements Stringer for NamespacedObjectReference so it can be passed
    37  // directly to string templates
    38  func (nor NamespacedObjectReference) String() string {
    39  	if nor.Namespace == "" {
    40  		return nor.Name
    41  	}
    42  	return fmt.Sprintf("%s/%s", nor.Namespace, nor.Name)
    43  }
    44  
    45  // NamespacedObjectKindReference contains enough information to locate the typed
    46  // referenced Kubernetes resource object in any namespace.
    47  type NamespacedObjectKindReference struct {
    48  	// API version of the referent, if not specified the Kubernetes preferred version will be used.
    49  	// +optional
    50  	APIVersion string `json:"apiVersion,omitempty"`
    51  
    52  	// Kind of the referent.
    53  	// +required
    54  	Kind string `json:"kind"`
    55  
    56  	// Name of the referent.
    57  	// +kubebuilder:validation:MinLength=1
    58  	// +kubebuilder:validation:MaxLength=253
    59  	// +required
    60  	Name string `json:"name"`
    61  
    62  	// Namespace of the referent, when not specified it acts as LocalObjectReference.
    63  	// +kubebuilder:validation:MinLength=1
    64  	// +kubebuilder:validation:MaxLength=253
    65  	// +optional
    66  	Namespace string `json:"namespace,omitempty"`
    67  }
    68  

View as plain text