Documentation
¶
Index ¶
- Constants
- Variables
- func AesDecrypt(crypted, key []byte) ([]byte, error)
- func AesEncrypt(origin, key []byte) ([]byte, error)
- func AggregateErrs(errs []error) error
- func AppNamespace(app, owner, ns string) (string, error)
- func CheckSSLCertificate(cert, key []byte, hostname string) error
- func DecodeNodeGPU(str string) ([]api.GPUInfo, error)
- func EnvNameToResourceName(envName string) (string, error)
- func EnvOrDefault(name, def string) string
- func ExtractGPUVersion(gpuName string) string
- func FindOwnerUser(ctrlClient client.Client, user *iamv1alpha2.User) (*iamv1alpha2.User, error)
- func FmtAppName(name, namespace string) string
- func GetAllGpuTypesFromNodes(nodes *corev1.NodeList) (map[string]struct{}, error)
- func GetAllNodesPodCIDRs() (cidrs []string)
- func GetAllNodesTunnelIPCIDRs() (cidrs []string)
- func GetClient() (*versioned.Clientset, error)
- func GetDeploymentName(pod *corev1.Pod) string
- func GetDeviceName() (string, error)
- func GetMirrorsEndpoint() (ep []string)
- func GetMyExternalIPAddr() string
- func GetNodeInfo(ctx context.Context) (ret []api.NodeInfo, err error)
- func GetPendingKind(ctrlClient client.Client, pod *corev1.Pod) (string, error)
- func GetRandomCharacters() (r string)
- func GetRefFromResourceList(chartPath string, values map[string]interface{}, images []string) (refs []v1alpha1.Ref, err error)
- func GetResourceListFromChart(chartPath string, values map[string]interface{}) (resources kube.ResourceList, err error)
- func GetServerServiceAccountToken() (string, error)
- func GetTerminus(ctx context.Context, ctrlClient client.Client) (*sysv1alpha1.Terminus, error)
- func GetTerminusVersion(ctx context.Context, config *rest.Config) (*sysv1alpha1.Terminus, error)
- func GetUserServiceAccountToken(ctx context.Context, client kubernetes.Interface, user string) (string, error)
- func InitAction() (*action.Install, error)
- func IsCPUOnlyNodeLabel(label string, present bool) bool
- func IsMinikubeNode(node *corev1.Node) bool
- func IsNodeReady(node *corev1.Node) bool
- func IsPortAvailable(protocol string, port int) bool
- func IsRunningOnMinikube(ctx context.Context, client kubernetes.Interface) (bool, error)
- func ListToMap[K comparable, T any](list []T, keyFunc func(T) K) map[K]T
- func MatchVersion(version, constraint string) bool
- func Md5String(s string) string
- func MessageToAny(msg proto.Message) *anypb.Any
- func MessageToAnyWithError(msg proto.Message) (*anypb.Any, error)
- func NewNatsConn() (*nats.Conn, error)
- func NodeSupportedGPUTypes(node *corev1.Node) []string
- func Pbkdf2Crypto(password string) (hash string, err error)
- func PrettyJSON(v any) string
- func PublishEvent(nc *nats.Conn, subject string, data interface{}) error
- func RandString() string
- func RemoteIP(req *http.Request) string
- func ReplacedImageRef(mirrorsEndpoint []string, oldImageRef string, checkConnection bool) (string, bool)
- func SubnetSplit(n int) map[string]*net.IPNet
- func ToJSON(msg proto.Message) (string, error)
- func ToJSONMap(msg proto.Message) (map[string]any, error)
- func ToJSONWithIndent(msg proto.Message, indent string) (string, error)
- func ToJSONWithOptions(msg proto.Message, indent string, enumsAsInts bool) (string, error)
- func ToYAML(msg proto.Message) (string, error)
- func UserspaceName(user string) string
- type Cryptographical
- func (r *Cryptographical) Bytes() (data []byte)
- func (r *Cryptographical) BytesCustom(n int, charset []byte) (data []byte)
- func (r *Cryptographical) BytesCustomErr(n int, charset []byte) (data []byte, err error)
- func (r *Cryptographical) BytesErr() (data []byte, err error)
- func (r *Cryptographical) Int(max *big.Int) (value *big.Int)
- func (r *Cryptographical) IntErr(max *big.Int) (value *big.Int, err error)
- func (r *Cryptographical) Intn(n int) (value int)
- func (r *Cryptographical) IntnErr(n int) (value int, err error)
- func (r *Cryptographical) Prime(bits int) (prime *big.Int, err error)
- func (r *Cryptographical) Read(p []byte) (n int, err error)
- func (r *Cryptographical) StringCustom(n int, characters string) (data string)
- func (r *Cryptographical) StringCustomErr(n int, characters string) (data string, err error)
- type Event
- type EventParams
- type SnakeCaseMarshaller
- type SystemStatusResponse
- type WorkloadResourceTotals
Constants ¶
const ( // NodeGPUTypeLabel is the legacy single-value node label // (gpu.bytetrade.io/type=<mode>). Current olares-cli no longer writes it // — it uses the existence-based per-mode labels below so a node can // advertise several modes at once. It is still read so a historical // nvidia node labeled by an older olares-cli keeps working: nvidia is the // only pre-existing GPU type and its name is unchanged, so no alias // mapping is needed. NodeGPUTypeLabel = "gpu.bytetrade.io/type" // NodeGPUTypeLabelPrefix is the prefix for the existence-based per-mode // node labels. A node supports mode <m> iff it carries the label // gpu.bytetrade.io/<m> (the value is ignored; olares-cli writes "true"). // cpu is never labeled — every node implicitly supports cpu workloads. NodeGPUTypeLabelPrefix = "gpu.bytetrade.io/" )
const ( CPUType = "cpu" // force to use CPU, no GPU NvidiaCardType = "nvidia" // discrete NVIDIA card, handled by HAMi GB10ChipType = "nvidia-gb10" // NVIDIA GB10 Superchip & unified system memory AppleMChipType = "apple-m" // Apple M-series SoC (unified memory) IntelType = "intel" // Intel integrated GPU (unified memory) AMDType = "amd" // AMD integrated GPU (Ryzen AI Max) IntelGPUType = "intel-gpu" // Intel discrete GPU AMDGPUType = "amd-gpu" // AMD discrete GPU MooreSocType = "moore-soc" // Moore Threads SoC )
const ( XForwardedFor = "X-Forwarded-For" XRealIP = "X-Real-IP" XClientIP = "x-client-ip" )
const ( // CalicoTunnelAddrAnnotation annotation key for calico tunnel address. CalicoTunnelAddrAnnotation = "projectcalico.org/IPv4IPIPTunnelAddr" DefaultRegistry = "https://registry-1.docker.io" )
const ( // CharSetAlphabeticLower are literally just valid alphabetic lowercase printable ASCII chars. CharSetAlphabeticLower = "abcdefghijklmnopqrstuvwxyz" // CharSetAlphabeticUpper are literally just valid alphabetic uppercase printable ASCII chars. CharSetAlphabeticUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" // CharSetAlphabetic are literally just valid alphabetic printable ASCII chars. CharSetAlphabetic = CharSetAlphabeticLower + CharSetAlphabeticUpper // CharSetNumeric are literally just valid numeric chars. CharSetNumeric = "0123456789" // CharSetNumericHex are literally just valid hexadecimal printable ASCII chars. CharSetNumericHex = CharSetNumeric + "ABCDEF" // CharSetSymbolic are literally just valid symbolic printable ASCII chars. CharSetSymbolic = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" // CharSetSymbolicRFC3986Unreserved are RFC3986 unreserved symbol characters. // See https://datatracker.ietf.org/doc/html/rfc3986#section-2.3. CharSetSymbolicRFC3986Unreserved = "-._~" // CharSetAlphaNumeric are literally just valid alphanumeric printable ASCII chars. CharSetAlphaNumeric = CharSetAlphabetic + CharSetNumeric // CharSetASCII are literally just valid printable ASCII chars. CharSetASCII = CharSetAlphabetic + CharSetNumeric + CharSetSymbolic // CharSetRFC3986Unreserved are RFC3986 unreserved characters. // See https://datatracker.ietf.org/doc/html/rfc3986#section-2.3. CharSetRFC3986Unreserved = CharSetAlphabetic + CharSetNumeric + CharSetSymbolicRFC3986Unreserved // CharSetUnambiguousUpper are a set of unambiguous uppercase characters. CharSetUnambiguousUpper = "ABCDEFGHJKLMNOPQRTUVWYXZ2346789" )
const (
// DefaultN is the default value of n.
DefaultN = 72
)
const (
PendingKindInSufficientGPU = "InsufficientGPU"
)
Variables ¶
var ArchNameMap = map[int64]string{
2: "Kepler",
3: "Maxwell",
4: "Pascal",
5: "Volta",
6: "Turing",
7: "Ampere",
8: "Ada Lovelace",
9: "Hopper",
10: "Blackwell",
}
var ErrUnPadding = errors.New("UnPadding error")
Functions ¶
func AesDecrypt ¶
AesDecrypt decrypts the given ciphertext using AES encryption with the specified key.
func AesEncrypt ¶
AesEncrypt encrypts the given plaintext using AES encryption with the specified key.
func AggregateErrs ¶
AggregateErrs aggregates a slice of errors into a single error.
func AppNamespace ¶
AppNamespace returns the namespace of an application.
func CheckSSLCertificate ¶
CheckSSLCertificate checks the validity of an SSL certificate and private key for a given hostname.
func EnvNameToResourceName ¶
EnvNameToResourceName validates and converts an env name to a k8s resource name. - must start with a letter - allowed chars: letters, digits, underscore - output: lowercase, underscores converted to hyphens
func EnvOrDefault ¶
func ExtractGPUVersion ¶
func FindOwnerUser ¶
func FindOwnerUser(ctrlClient client.Client, user *iamv1alpha2.User) (*iamv1alpha2.User, error)
func FmtAppName ¶
FmtAppName returns application name.
func GetAllGpuTypesFromNodes ¶
GetAllGpuTypesFromNodes returns the set of non-cpu GPU modes declared across the cluster's nodes. Each node may advertise several modes at once via the existence-based per-mode labels gpu.bytetrade.io/<mode> (and the legacy single-value gpu.bytetrade.io/type label is still honored for backward compatibility) — see NodeSupportedGPUTypes. Nodes without any GPU label contribute nothing, so a pure-CPU cluster returns an empty map. Callers that need to surface "CPU" as a user-selectable option should add it on top of this set themselves; mixing it in here would break the chart-render auto-detect path which expects len(gpuTypes)==1 to mean "this cluster has exactly one GPU flavour".
func GetAllNodesPodCIDRs ¶
func GetAllNodesPodCIDRs() (cidrs []string)
GetAllNodesPodCIDRs returns all node pod's cidr.
func GetAllNodesTunnelIPCIDRs ¶
func GetAllNodesTunnelIPCIDRs() (cidrs []string)
GetAllNodesTunnelIPCIDRs returns all node tunnel's ip cidr.
func GetDeploymentName ¶
func GetDeviceName ¶
func GetMirrorsEndpoint ¶
func GetMirrorsEndpoint() (ep []string)
func GetMyExternalIPAddr ¶
func GetMyExternalIPAddr() string
GetMyExternalIPAddr get my network outgoing ip address
func GetPendingKind ¶
func GetRandomCharacters ¶
func GetRandomCharacters() (r string)
func GetRefFromResourceList ¶
func GetResourceListFromChart ¶
func GetResourceListFromChart(chartPath string, values map[string]interface{}) (resources kube.ResourceList, err error)
func GetTerminus ¶
func GetTerminusVersion ¶
func InitAction ¶
func IsCPUOnlyNodeLabel ¶
IsCPUOnlyNodeLabel reports whether the value read from a node's legacy gpu.bytetrade.io/type label denotes a cpu-only node. Use this at boundaries where you've already extracted the label string and need to decide whether to skip / fall back to CPUType, e.g. inside iteration over a NodeList.
func IsMinikubeNode ¶
func IsNodeReady ¶
func IsPortAvailable ¶
func IsRunningOnMinikube ¶
func ListToMap ¶
func ListToMap[K comparable, T any](list []T, keyFunc func(T) K) map[K]T
func MatchVersion ¶
MatchVersion check if the version satisfies the constraint.
func MessageToAny ¶
MessageToAny converts from proto message to proto Any
func MessageToAnyWithError ¶
MessageToAnyWithError converts from proto message to proto Any
func NewNatsConn ¶
func NodeSupportedGPUTypes ¶
NodeSupportedGPUTypes returns the deduplicated set of non-cpu GPU modes a node supports, combining:
- the existence-based per-mode labels gpu.bytetrade.io/<mode> written by current olares-cli (a node may carry several at once), and
- the legacy single-value gpu.bytetrade.io/type label, retained so a historical nvidia node labeled by an older olares-cli is still honored.
cpu is never included (every node implicitly supports cpu). Results are deduplicated. Declaration order follows canonicalGPUTypes with any extra legacy-label value appended last.
func Pbkdf2Crypto ¶
func ReplacedImageRef ¶
func ReplacedImageRef(mirrorsEndpoint []string, oldImageRef string, checkConnection bool) (string, bool)
ReplacedImageRef return replaced image ref and true if mirror is support http
func ToJSONMap ¶
ToJSONMap converts a proto message to a generic map using canonical JSON encoding JSON encoding is specified here: https://developers.google.com/protocol-buffers/docs/proto3#json
func ToJSONWithIndent ¶
ToJSONWithIndent marshals a proto to canonical JSON with pretty printed string
func ToJSONWithOptions ¶
ToJSONWithOptions marshals a proto to canonical JSON with options to indent and print enums' int values
func UserspaceName ¶
UserspaceName returns user-space namespace for a user.
Types ¶
type Cryptographical ¶
type Cryptographical struct{}
Cryptographical is the production random.Provider which uses crypto/rand.
func (*Cryptographical) Bytes ¶
func (r *Cryptographical) Bytes() (data []byte)
Bytes returns random data as bytes with the standard random.DefaultN length and can contain any byte values (including unreadable byte values). If an error is returned from the random read this function ignores it.
func (*Cryptographical) BytesCustom ¶
func (r *Cryptographical) BytesCustom(n int, charset []byte) (data []byte)
BytesCustom returns random data as bytes with n length and can contain only byte values from the provided values. If n is less than 1 then DefaultN is used instead. If an error is returned from the random read this function ignores it.
func (*Cryptographical) BytesCustomErr ¶
func (r *Cryptographical) BytesCustomErr(n int, charset []byte) (data []byte, err error)
BytesCustomErr returns random data as bytes with n length and can contain only byte values from the provided values. If n is less than 1 then DefaultN is used instead. If an error is returned from the random read this function returns it.
func (*Cryptographical) BytesErr ¶
func (r *Cryptographical) BytesErr() (data []byte, err error)
BytesErr returns random data as bytes with the standard random.DefaultN length and can contain any byte values (including unreadable byte values). If an error is returned from the random read this function returns it.
func (*Cryptographical) Int ¶
func (r *Cryptographical) Int(max *big.Int) (value *big.Int)
Int returns a random *big.Int with a maximum of max.
func (*Cryptographical) IntErr ¶
IntErr returns a random *big.Int error combination with a maximum of max.
func (*Cryptographical) Intn ¶
func (r *Cryptographical) Intn(n int) (value int)
Intn returns a random int with a maximum of n.
func (*Cryptographical) IntnErr ¶
func (r *Cryptographical) IntnErr(n int) (value int, err error)
IntnErr returns a random int error combination with a maximum of n.
func (*Cryptographical) Prime ¶
func (r *Cryptographical) Prime(bits int) (prime *big.Int, err error)
Prime returns a number of the given bit length that is prime with high probability. Prime will return error for any error returned by rand.Read or if bits < 2.
func (*Cryptographical) Read ¶
func (r *Cryptographical) Read(p []byte) (n int, err error)
Read implements the io.Reader interface.
func (*Cryptographical) StringCustom ¶
func (r *Cryptographical) StringCustom(n int, characters string) (data string)
StringCustom is an overload of BytesCustom which takes a characters string and returns a string.
func (*Cryptographical) StringCustomErr ¶
func (r *Cryptographical) StringCustomErr(n int, characters string) (data string, err error)
StringCustomErr is an overload of BytesCustomWithErr which takes a characters string and returns a string.
type Event ¶
type Event struct {
EventID string `json:"eventID"`
CreateTime time.Time `json:"createTime"`
Name string `json:"name"`
RawAppName string `json:"rawAppName"`
Type string `json:"type"`
OpType string `json:"opType,omitempty"`
OpID string `json:"opID,omitempty"`
State string `json:"state"`
Progress string `json:"progress,omitempty"`
User string `json:"user"`
EntranceStatuses []v1alpha1.EntranceStatus `json:"entranceStatuses,omitempty"`
Title string `json:"title,omitempty"`
Icon string `json:"icon,omitempty"`
Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"`
MarketSource string `json:"marketSource,omitempty"`
// ChartOwner identifies the owner of the chart the app was installed
// from: for market apps it is the installing user; for uploaded apps it
// is the user who uploaded the chart. Always present on push events.
ChartOwner string `json:"chartOwner"`
}
type EventParams ¶
type EventParams struct {
Owner string
Name string
OpType string
OpID string
State string
Progress string
EntranceStatuses []v1alpha1.EntranceStatus
RawAppName string
Type string // "app" (default) or "middleware"
Title string
Reason string
Message string
Icon string
MarketSource string
// ChartOwner identifies the owner of the chart the app was installed
// from: the installing user for market apps, or the uploading user for
// uploaded apps. See appcfg.GetChartOwner.
ChartOwner string
// (apiVersion: v3 + options.shared: true). When true,
// PublishAppEventToQueue fans out the event to every activated user
// (annotation bytetrade.io/wizard-status == "completed" AND
// User.Status.State == "Created") instead of routing only to the
// app's nominal Owner. Per-user events (v1 and v3+per-user) keep the
// single-owner behavior.
IsShared bool
}
EventParams defines parameters to publish an app-related event
type SnakeCaseMarshaller ¶
type SnakeCaseMarshaller struct {
Value interface{}
}
SnakeCaseMarshaller is a struct that contains a field `Value`. This struct is intended to implement custom JSON marshalling by converting the field names in `Value` from camelCase or PascalCase to snake_case which is often used in JSON keys.
func (SnakeCaseMarshaller) MarshalJSON ¶
func (sc SnakeCaseMarshaller) MarshalJSON() ([]byte, error)
MarshalJSON implements the marshalling to JSON for the SnakeCaseMarshaller. This method overrides the standard marshalling behavior to convert the field names of the 'Value' to snake_case.
type SystemStatusResponse ¶
type SystemStatusResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Data struct {
TerminusdState string `json:"terminusdState"`
TerminusState string `json:"terminusState"`
TerminusName string `json:"terminusName"`
TerminusVersion string `json:"terminusVersion"`
InstalledTime int64 `json:"installedTime"`
InitializedTime int64 `json:"initializedTime"`
OlaresdVersion string `json:"olaresdVersion"`
DeviceName string `json:"device_name"`
HostName string `json:"host_name"`
OsType string `json:"os_type"`
OsArch string `json:"os_arch"`
OsInfo string `json:"os_info"`
OsVersion string `json:"os_version"`
CpuInfo string `json:"cpu_info"`
GpuInfo string `json:"gpu_info"`
Memory string `json:"memory"`
Disk string `json:"disk"`
WifiConnected bool `json:"wifiConnected"`
WiredConnected bool `json:"wiredConnected"`
HostIp string `json:"hostIp"`
ExternalIp string `json:"externalIp"`
InstallingState string `json:"installingState"`
InstallingProgress string `json:"installingProgress"`
UninstallingState string `json:"uninstallingState"`
UninstallingProgress string `json:"uninstallingProgress"`
UpgradingTarget string `json:"upgradingTarget"`
UpgradingRetryNum int `json:"upgradingRetryNum"`
UpgradingState string `json:"upgradingState"`
UpgradingStep string `json:"upgradingStep"`
UpgradingProgress string `json:"upgradingProgress"`
UpgradingError string `json:"upgradingError"`
UpgradingDownloadState string `json:"upgradingDownloadState"`
UpgradingDownloadStep string `json:"upgradingDownloadStep"`
UpgradingDownloadProgress string `json:"upgradingDownloadProgress"`
UpgradingDownloadError string `json:"upgradingDownloadError"`
CollectingLogsState string `json:"collectingLogsState"`
CollectingLogsError string `json:"collectingLogsError"`
DefaultFrpServer string `json:"defaultFrpServer"`
FrpEnable string `json:"frpEnable"`
} `json:"data"`
}
type WorkloadResourceTotals ¶
type WorkloadResourceTotals struct {
RequestsCPU apiresource.Quantity
LimitsCPU apiresource.Quantity
RequestsMemory apiresource.Quantity
LimitsMemory apiresource.Quantity
RequestsGPUMem apiresource.Quantity
LimitsGPUMem apiresource.Quantity
}
WorkloadResourceTotals is the per-pod sum (across every rendered workload's pod template) of the container resource requests and limits relevant to install-time auto-resource resolution.
GPUMem is summed from the per-pod nvidia.com/gpumem extended resource. The remaining fields are standard k8s quantities (cpu, memory) and are summed in their declared representation.
func GetWorkloadResourcesFromChart ¶
func GetWorkloadResourcesFromChart(chartPath string, values map[string]interface{}) (WorkloadResourceTotals, error)
GetWorkloadResourcesFromChart renders the chart at chartPath with the given Helm values (a side-effect-free dry-run, reusing GetResourceListFromChart) and sums the per-pod container resource requests/limits across every workload's pod template.
It is the install-time mechanism behind the auto-resource ("-1") sentinel: for a template app whose concrete resource demand only materializes once the user-selected appenv (model, gpu memory, ...) is injected into the chart, the caller renders once with the chosen mode + applied appenv and reads back the real requirement here.
Per-pod effective request/limit for a resource follows the Kubernetes rule max(maxInitContainer, sum(regularContainers)).