Documentation
¶
Index ¶
- Constants
- func CloseSession(ac *client.AlpaconClient, sessionID string) error
- func GetClusterDetailRaw(ac *client.AlpaconClient, clusterID string) ([]byte, error)
- func GetClusterIDByName(ac *client.AlpaconClient, clusterName string) (string, error)
- func GetClusterNames(ac *client.AlpaconClient) (map[string]string, error)
- func IsSurfaceOff(err error) bool
- func ResolveGroupNames(ac *client.AlpaconClient, groupIDs []string) []string
- type ClusterAttributes
- type ClusterDetail
- type KubeSessionAttributes
- type KubeSessionCreateRequest
- type KubeSessionDetail
- type KubeSessionListItem
- type KubeSessionResponse
- type KubeSessionUser
- type Optional
Constants ¶
const ( SessionStatusOpen = "open" SessionStatusClosed = "closed" )
Session statuses: a 'kube sessions' row shows one, and the list filter takes the same values.
const ClientTypeCLI = "cli"
ClientTypeCLI is the client_type a session opened from this CLI declares.
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 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
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"`
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"`
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"`
ExpiresAt string `json:"expires_at" table:"Expires At"`
TokenExpiredAt *time.Time `json:"token_expired_at" table:"-"`
ClosedAt *time.Time `json:"closed_at" table:"-"`
}
KubeSessionAttributes is the 'kube sessions' row. The table shows the expiry in local time; --output json also carries the cluster's ID and both times as the server sent them.
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.
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"`
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.
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"`
}
KubeSessionResponse is the session the server opened. ChannelToken is the credential kubectl presents to ProxyURL until TokenExpiredAt.
func CreateSession ¶ added in v1.16.0
func CreateSession(ac *client.AlpaconClient, req KubeSessionCreateRequest) (*KubeSessionResponse, error)
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.
type KubeSessionUser ¶ added in v1.19.0
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.