tbclient

package
v0.5.11 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Index

Constants

View Source
const (
	// VeryShortDuration is a duration for very short-term cache
	VeryShortDuration = 1 * time.Second
	// ShortDuration is a duration for short-term cache
	ShortDuration = 2 * time.Second
	// MediumDuration is a duration for medium-term cache
	MediumDuration = 5 * time.Second
	// LongDuration is a duration for long-term cache
	LongDuration = 10 * time.Second
)
View Source
const (
	// MaxDebugBodyLength is the maximum length of response body for debug logs
	MaxDebugBodyLength = 50000
)

Variables

This section is empty.

Functions

func GetCacheDuration added in v0.5.1

func GetCacheDuration(ctx context.Context) (time.Duration, bool)

GetCacheDuration retrieves cache duration from the context

func Init added in v0.5.1

func Init(cfg ApiConfig)

Init initializes the global Tumblebug client.

func SetCacheDuration added in v0.5.1

func SetCacheDuration(ctx context.Context, d time.Duration) context.Context

SetCacheDuration adds cache duration to the context

Types

type ApiConfig

type ApiConfig struct {
	RestUrl       string
	Username      string
	Password      string
	Timeout       time.Duration
	CacheDuration time.Duration
	HttpTransport http.RoundTripper
}

ApiConfig holds the configuration for the Tumblebug client.

type CacheItem added in v0.5.1

type CacheItem struct {
	ResponseBytes []byte
	StatusCode    int
	Header        http.Header
	ExpiresAt     time.Time
}

CacheItem is a struct to store cached item

type CircuitBreakerState added in v0.5.1

type CircuitBreakerState struct {
	FailureCount int
	LastFailure  time.Time
	IsOpen       bool
}

CircuitBreakerState represents the state of a circuit breaker for a specific request

type K8sClusterList added in v0.5.10

type K8sClusterList struct {
	K8sClusters []tbmodel.K8sClusterInfo `json:"K8sClusterInfo"`
}

K8sClusterList wraps the list response for K8s clusters from Tumblebug.

type NLBListResponse added in v0.5.3

type NLBListResponse struct {
	NLB []tbmodel.NLBInfo `json:"nlb"`
}

NLBListResponse is the response body for GET /ns/{nsId}/infra/{infraId}/nlb.

type Session added in v0.5.1

type Session struct {
	// contains filtered or unexported fields
}

Session represents a single request scope. It holds the request-specific configuration (headers, context, etc.).

func NewSession added in v0.5.1

func NewSession() *Session

NewSession creates a new Session using the global client.

func (*Session) AddFirewallRules added in v0.5.10

func (s *Session) AddFirewallRules(nsId, securityGroupId string, rules []tbmodel.FirewallRuleReq) (tbmodel.SecurityGroupInfo, error)

AddFirewallRules adds firewall rules to an existing Security Group. Used to apply rules that cannot be included in the create request for some CSPs (e.g., Tencent rejects ingress+egress in a single create call).

func (*Session) AddK8sNodeGroup added in v0.5.10

func (s *Session) AddK8sNodeGroup(nsId, clusterId string, reqBody tbmodel.K8sNodeGroupReq) (tbmodel.K8sClusterInfo, error)

AddK8sNodeGroup adds a worker node group to an existing K8s cluster. Required for AWS (nodeGroupsOnCreation=false); universally compatible with other CSPs.

func (*Session) CheckK8sNodeGroupsOnCreation added in v0.5.10

func (s *Session) CheckK8sNodeGroupsOnCreation(providerName string) (bool, error)

CheckK8sNodeGroupsOnCreation checks whether the given CSP requires NodeGroups to be included in the K8s cluster creation request (nodeGroupsOnCreation=true), or allows them to be added separately after cluster creation (nodeGroupsOnCreation=false).

func (*Session) CreateInfra added in v0.5.1

func (s *Session) CreateInfra(nsId string, reqBody tbmodel.InfraReq) (tbmodel.InfraInfo, error)

CreateInfra creates a new Infra (Infrastructure) in the specified namespace

func (*Session) CreateInfraDynamic added in v0.5.1

func (s *Session) CreateInfraDynamic(nsId string, reqBody tbmodel.InfraDynamicReq) (tbmodel.InfraInfo, error)

CreateInfraDynamic creates a new Infra (Infrastructure) with defaults in the specified namespace

func (*Session) CreateK8sCluster added in v0.5.10

func (s *Session) CreateK8sCluster(nsId string, reqBody tbmodel.K8sClusterReq) (tbmodel.K8sClusterInfo, error)

CreateK8sCluster creates a K8s cluster using pre-created VNet, SshKey, and SecurityGroup resources.

func (*Session) CreateNamespace added in v0.5.1

func (s *Session) CreateNamespace(nsReq tbmodel.NsReq) (tbmodel.NsInfo, error)

CreateNamespace creates a new namespace in Tumblebug

func (*Session) CreateNlb added in v0.5.3

func (s *Session) CreateNlb(nsId, infraId string, req tbmodel.NLBReq) (tbmodel.NLBInfo, error)

CreateNlb creates a new NLB in the specified namespace and infra.

func (*Session) CreateObjectStorage added in v0.5.1

func (s *Session) CreateObjectStorage(nsId string, req tbmodel.ObjectStorageCreateRequest) (tbmodel.ObjectStorageInfo, error)

CreateObjectStorage creates a new object storage (bucket)

func (*Session) CreateSecurityGroup added in v0.5.1

func (s *Session) CreateSecurityGroup(nsId string, reqBody tbmodel.SecurityGroupReq, option string) (tbmodel.SecurityGroupInfo, error)

CreateSecurityGroup creates a new Security Group in the specified namespace

func (*Session) CreateSshKey added in v0.5.1

func (s *Session) CreateSshKey(nsId string, reqBody tbmodel.SshKeyReq) (tbmodel.SshKeyInfo, error)

CreateSshKey creates a new SSH Key in the specified namespace

func (*Session) CreateVNet added in v0.5.1

func (s *Session) CreateVNet(nsId string, reqBody tbmodel.VNetReq) (tbmodel.VNetInfo, error)

CreateVNet creates a new Virtual Network (VNet) in the specified namespace

func (*Session) Delete added in v0.5.1

func (s *Session) Delete(url string) (*resty.Response, error)

Delete executes a DELETE request.

func (*Session) DeleteInfra added in v0.5.1

func (s *Session) DeleteInfra(nsId, infraId, option string) (tbmodel.IdList, error)

DeleteInfra deletes a specific Infra (Infrastructure) in the specified namespace

func (*Session) DeleteK8sCluster added in v0.5.10

func (s *Session) DeleteK8sCluster(nsId, clusterId string) error

DeleteK8sCluster deletes a K8s cluster and all its node groups.

func (*Session) DeleteK8sNodeGroup added in v0.5.10

func (s *Session) DeleteK8sNodeGroup(nsId, clusterId, nodeGroupId string) error

DeleteK8sNodeGroup deletes a specific node group from a K8s cluster.

func (*Session) DeleteNlb added in v0.5.3

func (s *Session) DeleteNlb(nsId, infraId, nlbId string) error

DeleteNlb deletes a specific NLB.

func (*Session) DeleteObjectStorage added in v0.5.1

func (s *Session) DeleteObjectStorage(nsId string, osId string, option string) error

DeleteObjectStorage deletes an object storage (bucket). option controls the deletion behavior (mutually exclusive):

  • "" : Standard delete — fails if the bucket is not empty.
  • "empty" : Empty the bucket first, then delete.
  • "force" : Force-delete with all contents (passed to Spider as force=true).
  • "reconcile": Remove only Tumblebug metadata without calling the CSP delete API.

func (*Session) DeleteObjectStorageCORS added in v0.5.1

func (s *Session) DeleteObjectStorageCORS(nsId string, osId string) error

DeleteObjectStorageCORS deletes the CORS configuration of an object storage (bucket)

func (*Session) DeleteSecurityGroup added in v0.5.1

func (s *Session) DeleteSecurityGroup(nsId, securityGroupId string) (tbmodel.SimpleMsg, error)

DeleteSecurityGroup deletes a specific Security Group in the specified namespace

func (*Session) DeleteSharedResources added in v0.5.1

func (s *Session) DeleteSharedResources(nsId string) (tbmodel.IdList, error)

func (*Session) DeleteSshKey added in v0.5.1

func (s *Session) DeleteSshKey(nsId, sshKeyId string) (tbmodel.SimpleMsg, error)

func (*Session) DeleteStorageObject added in v0.5.1

func (s *Session) DeleteStorageObject(nsId, osId, objectKey string) error

DeleteStorageObject deletes a specific object from an object storage bucket.

func (*Session) DeleteVNet added in v0.5.1

func (s *Session) DeleteVNet(nsId, vNetId, action string) (tbmodel.SimpleMsg, error)

func (*Session) Execute added in v0.5.1

func (s *Session) Execute(method, url string) (*resty.Response, error)

Execute executes the request with the given method and URL.

func (*Session) ExistObjectStorage added in v0.5.1

func (s *Session) ExistObjectStorage(nsId string, osId string) (bool, error)

ExistObjectStorage checks the existence of an object storage (bucket)

func (*Session) Get added in v0.5.1

func (s *Session) Get(url string) (*resty.Response, error)

Get executes a GET request.

func (*Session) GetAvailableK8sVersions added in v0.5.10

func (s *Session) GetAvailableK8sVersions(providerName, regionName string) ([]tbmodel.K8sClusterVersionDetailAvailable, error)

GetAvailableK8sVersions returns the K8s versions supported by the CSP and region.

func (*Session) GetConnConfig added in v0.5.1

func (s *Session) GetConnConfig(connectionConfigName string) (tbmodel.ConnConfig, error)

func (*Session) GetK8sNodeGroupNamingRule added in v0.5.10

func (s *Session) GetK8sNodeGroupNamingRule(providerName string) (string, error)

GetK8sNodeGroupNamingRule returns the CSP-specific node group naming rule (a regex) from Tumblebug's k8sClusterInfo asset data. Returns an empty string when the CSP defines no rule. The regex does not always encode length limits (e.g. Azure omits its 12-char cap), so callers must apply their own safe upper bound in addition.

func (*Session) GetK8sNodeImages added in v0.5.10

func (s *Session) GetK8sNodeImages(providerName, regionName string) (bool, []tbmodel.K8sClusterNodeImageDetailAvailable, error)

GetK8sNodeImages returns whether the CSP requires node image designation and the curated node image list resolved for the region (preferring an exact region match, falling back to the "common" region entry). Data comes from the same k8sClusterInfo asset used for naming rules and subnet counts, so no extra (still under-development) node-image endpoint is needed.

func (*Session) GetK8sRequiredSubnetCount added in v0.5.10

func (s *Session) GetK8sRequiredSubnetCount(providerName string) (int, error)

GetK8sRequiredSubnetCount returns the number of subnets the CSP requires to create a K8s cluster (e.g. AWS EKS needs 2 across distinct AZs; most CSPs need 1), from Tumblebug's k8sClusterInfo asset data. The value is a required minimum, not an exact/maximum.

func (*Session) GetNlb added in v0.5.3

func (s *Session) GetNlb(nsId, infraId, nlbId string) (tbmodel.NLBInfo, error)

GetNlb retrieves a specific NLB.

func (*Session) GetNlbHealth added in v0.5.4

func (s *Session) GetNlbHealth(nsId, infraId, nlbId string) (tbmodel.NLBInfo, error)

GetNlbHealth performs a live health check on NLB targets via CSP and returns the updated NLB info.

func (*Session) GetObjectStorage added in v0.5.1

func (s *Session) GetObjectStorage(nsId string, osId string) (tbmodel.ObjectStorageInfo, error)

GetObjectStorage retrieves details of an object storage (bucket)

func (*Session) GetObjectStorageCORS added in v0.5.1

func (s *Session) GetObjectStorageCORS(nsId string, osId string) (tbmodel.ObjectStorageGetCorsResponse, error)

GetObjectStorageCORS retrieves the CORS configuration of an object storage (bucket)

func (*Session) GetObjectStorageLocation added in v0.5.1

func (s *Session) GetObjectStorageLocation(nsId string, osId string) (tbmodel.ObjectStorageLocationResponse, error)

GetObjectStorageLocation retrieves the location of an object storage (bucket)

func (*Session) GetObjectStorageSupport added in v0.5.1

func (s *Session) GetObjectStorageSupport(cspType string) (tbmodel.ObjectStorageSupportResponse, error)

GetObjectStorageSupport retrieves CSP support information for object storage features If cspType is empty, returns support information for all CSPs

func (*Session) GetObjectStorageVersioning added in v0.5.1

func (s *Session) GetObjectStorageVersioning(nsId string, osId string) (tbmodel.ObjectStorageGetVersioningResponse, error)

GetObjectStorageVersioning retrieves the versioning configuration of an object storage (bucket)

func (*Session) GetStorageObject added in v0.5.1

func (s *Session) GetStorageObject(nsId, osId, objectKey string) (tbmodel.Object, error)

GetStorageObject retrieves metadata of a specific object in an object storage bucket.

func (*Session) Head added in v0.5.1

func (s *Session) Head(url string) (*resty.Response, error)

Head executes a HEAD request.

func (*Session) InfraRecommendSpec added in v0.5.1

func (s *Session) InfraRecommendSpec(planToSearchProperVm string) ([]tbmodel.SpecInfo, error)

InfraRecommendSpec finds appropriate VM specs by filtering and prioritzing.

func (*Session) IsReady added in v0.5.1

func (s *Session) IsReady() (bool, *string, error)

IsReady checks if Tumblebug is ready

func (*Session) K8sClusterRecommendNode added in v0.5.10

func (s *Session) K8sClusterRecommendNode(req tbmodel.RecommendSpecReq) ([]tbmodel.SpecInfo, error)

K8sClusterRecommendNode finds appropriate K8s worker node specs by filtering and prioritizing.

This is the K8s counterpart of InfraRecommendSpec. Tumblebug wraps the shared spec search with validateK8sMinimumRequirements, which rejects filter conditions below the K8s node minimums and injects those minimums when the request omits them.

The request is passed as a struct rather than a JSON string: InfraRecommendSpec accepts a string only to json.Unmarshal it straight back into this same type. nsId is fixed to the system common namespace on the Tumblebug side, so it is not a parameter here.

func (*Session) ListNlbs added in v0.5.3

func (s *Session) ListNlbs(nsId, infraId string) (NLBListResponse, error)

ListNlbs retrieves all NLBs in the specified namespace and infra.

func (*Session) ListObjectStorageIDs added in v0.5.7

func (s *Session) ListObjectStorageIDs(nsId string) (tbmodel.IdList, error)

ListObjectStorageIDs retrieves the list of all object storage IDs in a namespace

func (*Session) ListObjectStorageObjects added in v0.5.1

func (s *Session) ListObjectStorageObjects(nsId string, osId string) (tbmodel.ObjectStorageListObjectsResponse, error)

ListObjectStorageObjects lists objects in a specific object storage bucket.

func (*Session) ListObjectStorages added in v0.5.1

func (s *Session) ListObjectStorages(nsId string, option string, filterKey string, filterVal string) (tbmodel.ObjectStorageListResponse, error)

ListObjectStorages retrieves the list of all object storages (buckets) in a namespace

func (*Session) NoCache added in v0.5.1

func (s *Session) NoCache() *Session

NoCache disables caching for the request.

func (*Session) Post added in v0.5.1

func (s *Session) Post(url string) (*resty.Response, error)

Post executes a POST request.

func (*Session) Put added in v0.5.1

func (s *Session) Put(url string) (*resty.Response, error)

Put executes a PUT request.

func (*Session) ReadAllInfra added in v0.5.1

func (s *Session) ReadAllInfra(nsId string) (TbInfraInfoList, error)

ReadAllInfra retrieves all Infras (Infrastructure) in the specified namespace. This call is paced against TB's 2 req/s limit; set a deadline via Session.SetContext to bound how long it waits for a slot.

func (*Session) ReadAllK8sClusters added in v0.5.10

func (s *Session) ReadAllK8sClusters(nsId string) (K8sClusterList, error)

ReadAllK8sClusters retrieves all K8s clusters in the specified namespace.

func (*Session) ReadInfra added in v0.5.1

func (s *Session) ReadInfra(nsId, infraId string) (tbmodel.InfraInfo, error)

ReadInfra retrieves information about a specific Infra (Infrastructure) in the specified namespace. This call is paced against TB's 2 req/s limit; set a deadline via Session.SetContext to bound how long it waits for a slot.

func (*Session) ReadInfraAccessInfo added in v0.5.1

func (s *Session) ReadInfraAccessInfo(nsId, infraId, option, accessInfoOption string) (tbmodel.InfraAccessInfo, error)

func (*Session) ReadInfraIDs added in v0.5.1

func (s *Session) ReadInfraIDs(nsId string) (tbmodel.IdList, error)

ReadInfraIDs retrieves all Infra IDs in the specified namespace. This call is paced against TB's 2 req/s limit; set a deadline via Session.SetContext to bound how long it waits for a slot.

func (*Session) ReadK8sCluster added in v0.5.10

func (s *Session) ReadK8sCluster(nsId, clusterId string) (tbmodel.K8sClusterInfo, error)

ReadK8sCluster retrieves information about a specific K8s cluster.

func (*Session) ReadNamespace added in v0.5.1

func (s *Session) ReadNamespace(nsId string) (tbmodel.NsInfo, error)

ReadNamespace retrieves information about a specific namespace

func (*Session) ReadRegionInfo added in v0.5.1

func (s *Session) ReadRegionInfo(providerName string, regionName string) (tbmodel.RegionDetail, error)

ReadRegionInfo reads region information in a specific provider

func (*Session) ReadSecurityGroup added in v0.5.1

func (s *Session) ReadSecurityGroup(nsId, securityGroupId string) (tbmodel.SecurityGroupInfo, error)

ReadSecurityGroup retrieves information about a specific Security Group in the specified namespace

func (*Session) ReadSshKey added in v0.5.1

func (s *Session) ReadSshKey(nsId, sshKeyId string) (tbmodel.SshKeyInfo, error)

ReadSshKey retrieves information about a specific SSH Key in the specified namespace

func (*Session) ReadVNet added in v0.5.1

func (s *Session) ReadVNet(nsId, vNetId string) (tbmodel.VNetInfo, error)

ReadVNet retrieves information about a specific Virtual Network (VNet) in the specified namespace

func (*Session) ReadVmOsImage added in v0.5.1

func (s *Session) ReadVmOsImage(nsId, vmOsImageId string) (tbmodel.ImageInfo, error)

ReadVmOsImage retrieves information about a specific VM OS Image in the specified namespace

func (*Session) ReadVmSpec added in v0.5.1

func (s *Session) ReadVmSpec(nsId, vmSpecId string) (tbmodel.SpecInfo, error)

ReadVmSpec retrieves information about a specific VM Spec in the specified namespace

func (*Session) RemoteCommandToInfra added in v0.5.7

func (s *Session) RemoteCommandToInfra(nsId, infraId, nodeGroupId, nodeId string, reqBody tbmodel.InfraCmdReq) (tbmodel.InfraSshCmdResultForAPI, error)

RemoteCommandToInfra sends a remote command to the nodes of the specified Infra via Tumblebug's remote command API (POST /ns/{nsId}/cmd/infra/{infraId}). Pass nodeGroupId and/or nodeId to target a specific nodeGroup or node; pass "" to target all nodes.

func (*Session) ReviewSpecImagePair added in v0.5.1

ReviewSpecImagePair calls POST /specImagePairReview to validate a spec-image pair and resolve the latest CSP image name (e.g., Alibaba ImageFamily resolution).

func (*Session) SearchVmOsImage added in v0.5.1

func (s *Session) SearchVmOsImage(nsId string, searchImageReq tbmodel.SearchImageRequest) (tbmodel.SearchImageResponse, error)

SearchVmOsImage searches VM OS images

func (*Session) SetBody added in v0.5.1

func (s *Session) SetBody(body any) *Session

SetBody sets the request body.

func (*Session) SetCacheDuration added in v0.5.1

func (s *Session) SetCacheDuration(d time.Duration) *Session

SetCacheDuration sets the cache duration for the request.

func (*Session) SetContext added in v0.5.1

func (s *Session) SetContext(ctx context.Context) *Session

SetContext sets the context for the request.

func (*Session) SetHeader added in v0.5.1

func (s *Session) SetHeader(key, value string) *Session

SetHeader sets a single header.

func (*Session) SetHeaders added in v0.5.1

func (s *Session) SetHeaders(headers map[string]string) *Session

SetHeaders sets multiple headers.

func (*Session) SetObjectStorageCORS added in v0.5.1

func (s *Session) SetObjectStorageCORS(nsId string, osId string, req tbmodel.ObjectStorageSetCorsRequest) error

SetObjectStorageCORS sets the CORS configuration of an object storage (bucket)

func (*Session) SetObjectStorageVersioning added in v0.5.1

func (s *Session) SetObjectStorageVersioning(nsId string, osId string, req tbmodel.ObjectStorageSetVersioningRequest) error

SetObjectStorageVersioning sets the versioning configuration of an object storage (bucket)

func (*Session) SetQueryParam added in v0.5.1

func (s *Session) SetQueryParam(key, value string) *Session

SetQueryParam sets a single query parameter.

func (*Session) SetQueryParams added in v0.5.1

func (s *Session) SetQueryParams(params map[string]string) *Session

SetQueryParams sets multiple query parameters.

func (*Session) SetResult added in v0.5.1

func (s *Session) SetResult(res any) *Session

SetResult sets the result object to unmarshal the response into.

func (*Session) SetTraceInfo added in v0.5.1

func (s *Session) SetTraceInfo(ctx context.Context) *Session

SetTraceInfo injects the OpenTelemetry trace context into the request headers. This enables distributed tracing by propagating the trace ID and span ID to the Tumblebug API. It uses the global TextMapPropagator to ensure compatibility with the configured tracing backend.

Note: This method modifies the request headers in-place (merging with existing headers). It does not affect the request context or other headers, so it is safe to call regardless of the order of SetHeader or SetContext.

type TbInfraInfoList added in v0.5.1

type TbInfraInfoList struct {
	Infra []tbmodel.InfraInfo `json:"infra"`
}

type TumblebugClient

type TumblebugClient struct {
	// contains filtered or unexported fields
}

TumblebugClient is the factory for creating request sessions. It holds the shared configuration and connection pool.

func NewClient

func NewClient(cfg ApiConfig) *TumblebugClient

NewClient creates a new TumblebugClient instance.

func NewDefaultClient

func NewDefaultClient() *TumblebugClient

NewDefaultClient creates a new default client.

func (*TumblebugClient) NewSession added in v0.5.1

func (c *TumblebugClient) NewSession() *Session

NewSession creates a new Session for making requests.

type TumblebugTransport added in v0.5.1

type TumblebugTransport struct {
	Transport     http.RoundTripper
	CacheDuration time.Duration
}

TumblebugTransport is a custom http.RoundTripper that adds caching and circuit breaker logic.

func (*TumblebugTransport) RoundTrip added in v0.5.1

func (t *TumblebugTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a single HTTP transaction, returning a Response for the provided Request.

Jump to

Keyboard shortcuts

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