kubernetes

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 8 Imported by: 1 module, 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

Index

Constants

View Source
const (
	SessionStatusOpen   = "open"
	SessionStatusClosed = "closed"
)

Session statuses: a 'kube sessions' row shows one, and the list filter takes the same values.

View Source
const ClientTypeCLI = "cli"

ClientTypeCLI is the client_type a session opened from this CLI declares.

View Source
const SurfaceNotEnabledMessage = "Kubernetes support is not enabled on this workspace. If it was enabled recently, run 'alpacon login' again to refresh."

SurfaceNotEnabledMessage is what the CLI prints when the workspace does not expose the Kubernetes surface.

Variables

This section is empty.

Functions

func CloseSession added in v1.16.0

func CloseSession(ac *client.AlpaconClient, sessionID string) error

CloseSession ends a proxy session.

func ExternalGrantCounts added in v1.20.0

func ExternalGrantCounts(w *RBACDriftWarning) string

ExternalGrantCounts names the warning's counts by reach, such as "2 cluster-wide, 1 namespaced", leaving out a zero count. It is "" for a nil warning or one with no count above zero, since then there is nothing to name.

func GetClusterDetailRaw

func GetClusterDetailRaw(ac *client.AlpaconClient, clusterID string) ([]byte, error)

GetClusterDetailRaw fetches one cluster by ID and returns the body as the server sent it.

func GetClusterIDByName

func GetClusterIDByName(ac *client.AlpaconClient, clusterName string) (string, error)

GetClusterIDByName resolves a cluster name to its ID through the server's exact-match name filter.

func GetClusterNames added in v1.19.0

func GetClusterNames(ac *client.AlpaconClient) (map[string]string, error)

GetClusterNames maps the IDs of the clusters the caller can see to their names.

func IsSurfaceOff added in v1.18.0

func IsSurfaceOff(err error) bool

IsSurfaceOff reports whether err carries a 404, which the server answers for every path under /api/kubernetes/ when the Kubernetes surface is off.

func ResolveGroupNames

func ResolveGroupNames(ac *client.AlpaconClient, groupIDs []string) []string

ResolveGroupNames maps group UUIDs to names in one batched lookup. A UUID with no match, or every UUID when the lookup fails, is shown as-is so the caller's output is never blocked on the group list.

Types

type ClusterAttributes

type ClusterAttributes struct {
	Name         string           `json:"name"`
	Provider     string           `json:"provider"`
	KubeVersion  Optional[string] `json:"kube_version" table:"Kube Version"`
	NodeCount    Optional[int]    `json:"node_count" table:"Nodes"`
	Connected    bool             `json:"connected"`
	Enabled      bool             `json:"enabled"`
	RBACDrift    Optional[string] `json:"rbac_drift" table:"RBAC drift"`
	AgentVersion string           `json:"agent_version" table:"Agent Version"`
}

ClusterAttributes is the 'kube ls' row. Its version and node count keep the server's names and types, so a script reading --output json sees node_count as a number and a value the agent has not reported yet as null; the table shows that as blank. Connected follows ServerAttributes, not is_connected.

func GetClusterList

func GetClusterList(ac *client.AlpaconClient) ([]ClusterAttributes, error)

GetClusterList returns every cluster the caller can see, projected for 'kube ls'. A service token sees none: the server answers it with an empty list.

type ClusterDetail

type ClusterDetail struct {
	ID               string          `json:"id"`
	Name             string          `json:"name"`
	Provider         string          `json:"provider"`
	KubeVersion      *string         `json:"kube_version"`
	AgentVersion     string          `json:"agent_version"`
	NodeCount        *int            `json:"node_count"`
	Status           json.RawMessage `json:"status"`
	Enabled          bool            `json:"enabled"`
	Groups           []string        `json:"groups"`
	Tags             json.RawMessage `json:"tags"`
	IsConnected      bool            `json:"is_connected"`
	RBACDrift        *string         `json:"rbac_drift"`
	LastConnectivity *time.Time      `json:"last_connectivity"`
	LastSyncedAt     *time.Time      `json:"last_synced_at"`
	AddedAt          time.Time       `json:"added_at"`
	UpdatedAt        time.Time       `json:"updated_at"`
}

ClusterDetail decodes one entry of /api/kubernetes/clusters/. Status and Tags stay raw: the server stores both as free-form JSON, and status has no enum. KubeVersion and NodeCount are nil until the agent has measured them, which is not the same as an empty version or zero nodes.

func GetClusterDetail

func GetClusterDetail(ac *client.AlpaconClient, clusterID string) (*ClusterDetail, error)

GetClusterDetail fetches one cluster by ID.

type KubeSessionAttributes added in v1.19.0

type KubeSessionAttributes struct {
	ID               string          `json:"id" table:"ID"`
	Cluster          string          `json:"cluster" table:"Cluster"`
	ClusterID        string          `json:"cluster_id" table:"-"`
	User             string          `json:"user" table:"User"`
	Status           string          `json:"status" table:"Status"`
	Kind             string          `json:"kind" table:"Kind"`
	ExpiresAt        utils.Timestamp `json:"expires_at" table:"Expires At"`
	TokenExpiredAt   utils.Timestamp `json:"token_expired_at" table:"-"`
	ClosedAt         utils.Timestamp `json:"closed_at" table:"-"`
	RBACDriftWarning json.RawMessage `json:"rbac_drift_warning" table:"-"`
	ExternalGrants   string          `json:"-" table:"External grants"`
}

KubeSessionAttributes is the 'kube sessions' row. The table shows the expiry in local time; --output json carries it, both raw times and the cluster's ID, all times in UTC. Kind is api, unknown, or the kind of the session's newest stream (see sessionKind). A session that opened with an RBAC drift warning shows its external grants in the table; --output json carries the server's warning object as it came, or null.

func ProjectSessions added in v1.19.0

func ProjectSessions(sessions []KubeSessionListItem, names map[string]string, loc *time.Location) []KubeSessionAttributes

ProjectSessions builds the 'kube sessions' rows, with the expiry shown in loc. A cluster missing from names shows its ID, and the status reads closed_at alone: a session whose token has expired stays open until the server's sweep closes it. The kind comes from sessionKind and the external grants cell from externalGrantsCell.

type KubeSessionCreateRequest added in v1.16.0

type KubeSessionCreateRequest struct {
	Cluster     string `json:"cluster"`
	WorkSession string `json:"work_session,omitempty"`
	ClientType  string `json:"client_type"`
}

KubeSessionCreateRequest opens a proxy session to one cluster. Cluster and WorkSession are UUIDs; WorkSession is left out when neither --work-session nor ALPACON_WORK_SESSION names a session.

type KubeSessionDetail added in v1.18.0

type KubeSessionDetail struct {
	ID             string     `json:"id"`
	TokenExpiredAt *time.Time `json:"token_expired_at"`
	ClosedAt       *time.Time `json:"closed_at"`
}

KubeSessionDetail is a kube session as it is read back. It never carries the channel token. TokenExpiredAt follows an extended work session, and ClosedAt is set once the session has ended for any reason.

func GetSession added in v1.18.0

func GetSession(ac *client.AlpaconClient, sessionID string) (*KubeSessionDetail, error)

GetSession reads a proxy session back, to learn whether it is still open and when its token expires now.

type KubeSessionListItem added in v1.19.0

type KubeSessionListItem struct {
	ID               string           `json:"id"`
	Cluster          string           `json:"cluster"`
	User             *KubeSessionUser `json:"user"`
	TokenExpiredAt   *time.Time       `json:"token_expired_at"`
	LatestExec       json.RawMessage  `json:"latest_exec"`
	RBACDriftWarning json.RawMessage  `json:"rbac_drift_warning"`
	ClosedAt         *time.Time       `json:"closed_at"`
}

KubeSessionListItem is one entry of the session list. It is apart from KubeSessionDetail so a change in these fields cannot fail the read 'kube credentials' makes on every kubectl call.

LatestExec is the newest exec, attach or port-forward stream the session opened, {id, kind}, or null when it opened none. RBACDriftWarning is null unless the session opened with a warning. An older server leaves either out. Both stay raw so a shape this build does not expect cannot fail the list.

func GetSessionList added in v1.19.0

func GetSessionList(ac *client.AlpaconClient, clusterID, status string) ([]KubeSessionListItem, error)

GetSessionList returns the kube sessions the caller can see, newest first: its own and those of clusters it manages. An empty clusterID or status leaves that filter off; clusterID is an ID, not a name.

type KubeSessionResponse added in v1.16.0

type KubeSessionResponse struct {
	ID               string          `json:"id"`
	Cluster          string          `json:"cluster"`
	ChannelID        string          `json:"channel_id"`
	ChannelToken     string          `json:"channel_token"`
	TokenExpiredAt   time.Time       `json:"token_expired_at"`
	ProxyURL         string          `json:"proxy_url"`
	RBACDriftWarning json.RawMessage `json:"rbac_drift_warning"`
}

KubeSessionResponse is the session the server opened. ChannelToken is the credential kubectl presents to ProxyURL until TokenExpiredAt. RBACDriftWarning is set when the session opened despite cluster RBAC bindings outside Alpacon. It stays raw so --output json carries it as the server sent it and a shape this build does not expect cannot fail the open.

func CreateSession added in v1.16.0

CreateSession opens a proxy session to a cluster. The channel token appears only in this response—the server never returns it again—so the caller must persist it at once. The POST's own error is tagged with utils.MarkSubmission, so an MFA wait may send a refused create again; a failure to read or use the answer is not, since the session exists by then.

type KubeSessionUser added in v1.19.0

type KubeSessionUser struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

KubeSessionUser is the person a listed kube session belongs to.

type Optional

type Optional[T any] struct {
	Value *T
}

Optional is a value the server may send as null. PrintTable formats a cell with %v, which would print a bare pointer's address, so the pointer is wrapped: String renders null as blank and MarshalJSON keeps it null.

func (Optional[T]) MarshalJSON

func (o Optional[T]) MarshalJSON() ([]byte, error)

func (Optional[T]) String

func (o Optional[T]) String() string

type RBACDriftWarning added in v1.20.0

type RBACDriftWarning struct {
	ClusterExternalGrants    int  `json:"cluster_external_grants"`
	NamespacedExternalGrants int  `json:"namespaced_external_grants"`
	Incomplete               bool `json:"incomplete"`
}

RBACDriftWarning is the part of the server's rbac_drift_warning the CLI shows: its cluster's RBAC check at the open, a snapshot that a later cleanup of the cluster does not change. The two counts are permissions beyond Alpacon's baseline that bindings Alpacon did not make grant the session identity, through ClusterRoleBindings (in every namespace) and through RoleBindings (once per namespace). Incomplete means the check did not finish, so the counts are a lower bound. The other fields stay out, so a value the CLI never reads cannot make the counts unreadable; --output json carries the whole object.

func ParseRBACDriftWarning added in v1.20.0

func ParseRBACDriftWarning(raw json.RawMessage) (warning *RBACDriftWarning, present bool)

ParseRBACDriftWarning reads a session's rbac_drift_warning. present is false when the field is null or absent, as from a server older than it. A value that is there but does not decode still means the session opened with a warning: present is true and the warning is nil.

Jump to

Keyboard shortcuts

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