util

package
v1.16.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 12 Imported by: 22

README

pkg/util

Intention

pkg/util is a legacy miscellaneous bucket. It does not represent one coherent abstraction. It contains a small set of cross-cutting helpers and tiny shared types that historically did not get better homes.

The main things still living here are:

  • GenerateResourceID() for generating Kubernetes-safe random resource IDs
  • ServiceDescriptor for passing common service/controller identity metadata such as name, version, and revision
  • GetNATPrefix() for discovering the process's internet-facing address and expressing it as a /32 so managed cluster firewall rules can allow control-plane access
  • K8SAPITester and DefaultK8SAPITester for a narrow kubeconfig connectivity check seam used by CD-layer code
  • Keys() as a small map-key helper that is now effectively obsolete

Invariants And Guard Rails

  • This package should stay small. New code should not treat pkg/util as the default home for unrelated helper functions just because they feel broadly reusable.
  • GenerateResourceID() is the shared helper for generating random Kubernetes resource IDs that satisfy the repository's naming expectations.
  • ServiceDescriptor is the shared identity payload used where services, controllers, or cross-service clients need a common name/version/revision description.
  • GetNATPrefix() is a pragmatic helper for the managed-cluster access model. Its job is to discover the control plane's egress address so firewall rules can allow access back into managed clusters.
  • K8SAPITester is a very limited integration seam for testing whether a kubeconfig can actually reach a Kubernetes API. It is not a broad connectivity abstraction and is mainly relevant to the CD-layer reachability check path.

Caveats

  • The package boundary is weak. These helpers live together mostly because of history, not because they belong to one design.
  • Keys() is effectively superseded by maps.Keys and should be treated as a cleanup candidate rather than something new code should continue to spread. It can be removed once the remaining live call sites are migrated.
  • GetNATPrefix() depends on an external internet service, memoizes the result globally, and assumes one observed egress address is the right process-wide answer. That is pragmatic operational baggage, not a cleanly modeled networking contract.
  • K8SAPITester and its default implementation are specific enough that they would make more architectural sense closer to the code that owns kubeconfig validation.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrK8SConnectionError = errors.New("unable to connection the kubernetes API")
)

Functions

func GenerateResourceID added in v0.1.71

func GenerateResourceID() string

GenerateResourceID creates a valid Kubernetes name from a UUID.

func GetNATPrefix

func GetNATPrefix(ctx context.Context) (string, error)

GetNATPrefix returns the IP address of the SNAT that the control plane and by extension we, sit behind.

func Keys

func Keys[T any](m map[string]T) []string

Keys returns the keys from a string map.

Types

type DefaultK8SAPITester

type DefaultK8SAPITester struct{}

func (*DefaultK8SAPITester) Connect

func (t *DefaultK8SAPITester) Connect(ctx context.Context, config *clientcmdapi.Config) error

type K8SAPITester

type K8SAPITester interface {
	Connect(ctx context.Context, config *clientcmdapi.Config) error
}

type ServiceDescriptor added in v1.9.0

type ServiceDescriptor struct {
	// Name is the name of the service.
	Name string
	// Version is the version of the service.
	Version string
	// Revision is the revision of the service (typically a Git SHA).
	Revision string
}

ServiceDescriptor is used to define a common format for application information. This is typically used to initialize logging and IPC so we can see who instigated a request.

Directories

Path Synopsis
Code generated by MockGen.
Code generated by MockGen.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL