kubernetes

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Kubernetes workloads in discovery: the EKS clusters of an account and region, and a target group traced to the one Deployment or StatefulSet behind it.

Ports manager packages/discovery/src/kubernetes.ts (clustersOf, kubernetesBackend).

Package kubernetes is the Kubernetes API of an EKS cluster, without a Kubernetes library: plain HTTPS trusting the cluster's certificate authority, with an EKS token signed here by hand.

Token ports the router's lambda/src/lib/k8s.mjs (presignUrl, eksToken).

Index

Constants

View Source
const ClusterTTL = 15 * time.Minute

ClusterTTL is how long a cluster's view is kept (15 minutes).

Variables

View Source
var DefaultTimeouts = Timeouts{Connect: 3 * time.Second, Idle: 10 * time.Second}

DefaultTimeouts are the AWS calls' bounds (the router's TIMEOUTS): 3 seconds to connect, 10 seconds idle.

Functions

func LabelSelector

func LabelSelector(s Selector) (string, error)

LabelSelector writes an owner's selector as the API's labelSelector parameter takes it.

func OwnerPath

func OwnerPath(ref Ref) string

OwnerPath is the owner's path in the API.

func Token

func Token(cluster, region string, creds aws.Credentials, now time.Time) string

Token is the bearer token EKS accepts (what `aws eks get-token` prints): an STS GetCallerIdentity URL presigned for 60 seconds with the cluster's name signed; EKS takes it for 15 minutes from its date.

Types

type AccessConfig

type AccessConfig struct {
	AuthenticationMode string `json:"authenticationMode,omitempty"`
}

AccessConfig is the cluster's authentication mode.

type Autoscaler

type Autoscaler string

Autoscaler is the node autoscaler of a cluster: karpenter, cluster-autoscaler or none (empty, null in JSON).

func (Autoscaler) MarshalJSON

func (a Autoscaler) MarshalJSON() ([]byte, error)

MarshalJSON writes none as null.

func (*Autoscaler) UnmarshalJSON

func (a *Autoscaler) UnmarshalJSON(b []byte) error

UnmarshalJSON reads null as none.

type Candidate

type Candidate struct {
	Cluster    string     `json:"cluster"`
	Namespace  string     `json:"namespace"`
	Owner      Owner      `json:"owner"`
	Switch     string     `json:"switch"`
	Ingress    *Ingress   `json:"ingress,omitempty"`
	GitOps     string     `json:"gitops,omitempty"`
	HPA        bool       `json:"hpa"`
	Keda       *bool      `json:"keda"`
	Capacity   string     `json:"capacity"`
	Autoscaler Autoscaler `json:"autoscaler"`
}

Candidate is the Kubernetes workload behind a target group, with how the waker is switched in. Switch is rule, ingress or patched-ingress; GitOps argocd or flux (empty: none); Keda nil when the cluster refuses to show its ScaledObjects; Capacity fargate or nodes.

type CertificateAuthority

type CertificateAuthority struct {
	Data string `json:"data,omitempty"`
}

CertificateAuthority holds the cluster's CA, PEM in base64.

type Client

type Client interface {
	// Get returns the object at path (nil for an empty answer).
	Get(ctx context.Context, path string) (json.RawMessage, error)
	// List returns every item at path, following the API's continue tokens.
	List(ctx context.Context, path string, query map[string]string) ([]json.RawMessage, error)
}

Client reads one cluster's API (GET only).

func New

func New(endpoint string, ca []byte, token string) Client

New makes the client of a cluster: endpoint and ca (PEM) from the cluster, token from Token. An empty ca trusts the system roots.

type Cluster

type Cluster struct {
	Name       string
	VPCID      string
	Reason     string // empty when read
	Client     Client
	Pods       []Pod
	Autoscaler Autoscaler
	// contains filtered or unexported fields
}

Cluster is a cluster of the region with what discovery can read of it: its pods (by IP) and whether a node autoscaler runs. A cluster it cannot reach or read keeps the Reason (its target groups are ineligible with it, the account goes on).

func ClustersOf

func ClustersOf(ctx context.Context, ports Ports) ([]Cluster, error)

ClustersOf reads every cluster of the region.

func (Cluster) MarshalJSON

func (c Cluster) MarshalJSON() ([]byte, error)

MarshalJSON writes the cluster as the scan reports it: its name and its reason (null when read).

type ClusterView

type ClusterView struct {
	Endpoint     string
	CA           []byte // PEM, decoded
	PublicAccess bool
	PublicCidrs  []string
	PrivateOnly  bool
	AuthMode     string // CONFIG_MAP for a cluster without accessConfig
	Version      string
}

ClusterView is a cluster's endpoint, certificate authority, reach and authentication mode (the router's clusterOf).

func ClusterOf

func ClusterOf(ctx context.Context, eks EKSPort, name string, now time.Time) (ClusterView, error)

ClusterOf reads a cluster once per 15 minutes per EKS port and name (a concurrent caller shares the call in flight); a failure is not kept. A port that cannot be a map key (not comparable) is not cached.

type Condition

type Condition struct {
	Type   string `json:"type"`
	Status string `json:"status"`
}

Condition is a pod's status condition.

type Container

type Container struct {
	Resources struct {
		Requests map[string]string `json:"requests,omitempty"`
	} `json:"resources"`
}

Container is a pod's container (its requests only).

type DescribeClusterInput

type DescribeClusterInput struct {
	Name string `json:"name"`
}

DescribeClusterInput is EKS DescribeCluster's input.

type DescribeClusterOutput

type DescribeClusterOutput struct {
	Cluster *EKSCluster `json:"cluster,omitempty"`
}

DescribeClusterOutput is its answer.

type EKSCluster

type EKSCluster struct {
	Name                 string                `json:"name,omitempty"`
	Version              string                `json:"version,omitempty"`
	Endpoint             string                `json:"endpoint,omitempty"`
	CertificateAuthority *CertificateAuthority `json:"certificateAuthority,omitempty"`
	ResourcesVpcConfig   *VPCConfig            `json:"resourcesVpcConfig,omitempty"`
	AccessConfig         *AccessConfig         `json:"accessConfig,omitempty"`
}

EKSCluster is the part of an EKS cluster the estimate reads.

type EKSPort

type EKSPort interface {
	ListClusters(ctx context.Context, in ListClustersInput) (ListClustersOutput, error)
	DescribeCluster(ctx context.Context, in DescribeClusterInput) (DescribeClusterOutput, error)
}

EKSPort is the EKS API (ListClusters, DescribeCluster).

type Error

type Error struct {
	Status  int
	Reason  string
	Message string
}

Error is a failed Kubernetes call. Status is the HTTP status, 0 when no answer came; Reason the API's (Forbidden, NotFound, Conflict...), the HTTP status's text, Timeout, or the network error's code.

func (*Error) Error

func (e *Error) Error() string

Error is the message.

func (*Error) ErrorName

func (e *Error) ErrorName() string

ErrorName is the error's name as the router's KubernetesError has it (awserr.Name reads it).

type Expression

type Expression struct {
	Key      string   `json:"key"`
	Operator string   `json:"operator"`
	Values   []string `json:"values,omitempty"`
}

Expression is a selector's matchExpressions entry.

type Group

type Group struct {
	ARN     string            `json:"arn"`
	Type    string            `json:"type,omitempty"`
	VPCID   string            `json:"vpcId,omitempty"`
	Tags    map[string]string `json:"tags"`
	Targets []string          `json:"targets"`
}

Group is a target group to trace.

type Ingress

type Ingress struct {
	Name       string  `json:"name"`
	RuleIndex  int     `json:"ruleIndex"`
	GroupOrder *int    `json:"groupOrder,omitempty"`
	Service    Service `json:"service"`
}

Ingress is the Ingress rule the target group was made for.

type K8sBackend

type K8sBackend struct {
	Kind       string    `json:"kind"`
	ID         string    `json:"id"`
	Kubernetes Candidate `json:"kubernetes"`
}

K8sBackend is the backend discovery reports for a Kubernetes workload.

type Label

type Label struct{ Key, Value string }

Label is one matchLabels entry.

type Labels

type Labels []Label

Labels are a selector's matchLabels, in the order the API wrote them (the label selector keeps it).

func (Labels) MarshalJSON

func (l Labels) MarshalJSON() ([]byte, error)

MarshalJSON writes the object back.

func (*Labels) UnmarshalJSON

func (l *Labels) UnmarshalJSON(b []byte) error

UnmarshalJSON reads an object keeping its keys' order.

type ListClustersInput

type ListClustersInput struct {
	NextToken string `json:"nextToken,omitempty"`
}

ListClustersInput is EKS ListClusters' input (a page).

type ListClustersOutput

type ListClustersOutput struct {
	Clusters  []string `json:"clusters,omitempty"`
	NextToken string   `json:"nextToken,omitempty"`
}

ListClustersOutput is its answer.

type Metadata

type Metadata struct {
	Name              string            `json:"name"`
	Namespace         string            `json:"namespace,omitempty"`
	Labels            map[string]string `json:"labels,omitempty"`
	Annotations       map[string]string `json:"annotations,omitempty"`
	OwnerReferences   []OwnerReference  `json:"ownerReferences,omitempty"`
	DeletionTimestamp string            `json:"deletionTimestamp,omitempty"`
}

Metadata is an object's metadata.

func (Metadata) Controller

func (m Metadata) Controller() (OwnerReference, bool)

Controller is the reference that controls the object, if any.

type Owner

type Owner struct {
	Kind string `json:"kind"`
	Name string `json:"name"`
}

Owner is a Deployment or a StatefulSet.

func ServiceOwner added in v0.8.0

func ServiceOwner(ctx context.Context, k Client, namespace, service string) (owner *Owner, reason string, err error)

ServiceOwner traces a Service to the one Deployment or StatefulSet behind it: its selector, the pods it selects, then their owner. reason says why it cannot be told, with no owner; err is a refused or failed call.

type OwnerReference

type OwnerReference struct {
	Kind       string `json:"kind"`
	Name       string `json:"name"`
	Controller bool   `json:"controller,omitempty"`
}

OwnerReference is a metadata.ownerReferences entry.

type Pod

type Pod struct {
	Metadata Metadata `json:"metadata"`
	Spec     struct {
		NodeName       string            `json:"nodeName,omitempty"`
		SchedulerName  string            `json:"schedulerName,omitempty"`
		Containers     []Container       `json:"containers,omitempty"`
		InitContainers []Container       `json:"initContainers,omitempty"`
		Overhead       map[string]string `json:"overhead,omitempty"`
	} `json:"spec"`
	Status struct {
		Phase      string      `json:"phase,omitempty"`
		PodIP      string      `json:"podIP,omitempty"`
		Conditions []Condition `json:"conditions,omitempty"`
	} `json:"status"`
}

Pod is a pod with the fields the estimate reads.

func LivePods

func LivePods(ctx context.Context, k Client, ref Ref, w Workload) ([]Pod, error)

LivePods are the owner's pods still there (finished ones are gone for good): those it controls, a Deployment's through its ReplicaSets. The selector may match another owner's pods (a canary selecting the same labels): never the owner's, foreign behind the target group.

func OwnerPods

func OwnerPods(ctx context.Context, k Client, ref Ref) ([]Pod, error)

OwnerPods are the owner's pods still there; none when the owner is gone.

type Port

type Port struct {
	Number int    `json:"number,omitempty"`
	Name   string `json:"name,omitempty"`
}

Port is an Ingress backend's service port.

type Ports

type Ports struct {
	EKS     EKSPort
	Of      func(ctx context.Context, cluster string) (Client, error)
	Reader  string
	Account string
	Region  string
}

Ports are what discovery reads clusters through. Of gives the client of a cluster by name (for real: its endpoint and certificate authority from DescribeCluster, an EKS token). Reader names who reads the clusters, in the reason of one refused (DmtDiscoveryRole when empty). Account and Region name the router to install, in the reason of a private cluster.

type Ref

type Ref struct {
	Namespace string
	Owner     Owner
}

Ref is where an owner lives in its cluster.

type Result

type Result struct {
	Backend *K8sBackend
	Reason  string
}

Result is the answer of Backend: the owner (Backend), why the target group cannot be napped (Reason), or neither when it is not a Kubernetes target group. It marshals to the Node value: the backend, the reason or null.

func Backend

func Backend(ctx context.Context, clusters []Cluster, g Group) Result

Backend finds the target group's Kubernetes owner, why it cannot be napped, or neither when it is not a Kubernetes target group (no cluster's tag, and no target among a reachable cluster's pods).

func (Result) MarshalJSON

func (r Result) MarshalJSON() ([]byte, error)

MarshalJSON writes the backend, the reason, or null.

type Selector

type Selector struct {
	MatchLabels      Labels       `json:"matchLabels,omitempty"`
	MatchExpressions []Expression `json:"matchExpressions,omitempty"`
}

Selector is a label selector (matchLabels and matchExpressions).

type Service

type Service struct {
	Name string `json:"name"`
	Port Port   `json:"port"`
}

Service is an Ingress backend's service.

type Timeouts

type Timeouts struct{ Connect, Idle time.Duration }

Timeouts are the calls' bounds: connected (TLS included) within Connect, failed after Idle of silence (no byte read).

type VPCConfig

type VPCConfig struct {
	VPCID                 string   `json:"vpcId,omitempty"`
	EndpointPublicAccess  bool     `json:"endpointPublicAccess,omitempty"`
	EndpointPrivateAccess bool     `json:"endpointPrivateAccess,omitempty"`
	PublicAccessCidrs     []string `json:"publicAccessCidrs,omitempty"`
}

VPCConfig is the cluster's VPC and endpoint access.

type Workload

type Workload struct {
	Kind     string   `json:"kind,omitempty"`
	Metadata Metadata `json:"metadata"`
	Spec     struct {
		Replicas *int      `json:"replicas,omitempty"`
		Selector *Selector `json:"selector,omitempty"`
	} `json:"spec"`
}

Workload is a Deployment or a StatefulSet (or a ReplicaSet: its metadata).

func GetWorkload

func GetWorkload(ctx context.Context, k Client, ref Ref) (Workload, error)

GetWorkload reads the owner; a missing one is the API's 404.

func OwnerOf

func OwnerOf(ctx context.Context, k Client, ref Ref) (*Workload, error)

OwnerOf reads the owner, nil when it does not exist.

Directories

Path Synopsis
Package kubernetestest holds the fakes of the Kubernetes ports for tests: the recorded answers of the shared cases, as the ports of internal/kubernetes.
Package kubernetestest holds the fakes of the Kubernetes ports for tests: the recorded answers of the shared cases, as the ports of internal/kubernetes.

Jump to

Keyboard shortcuts

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