mirror of
https://github.com/sablierapp/sablier.git
synced 2025-12-21 21:33:06 +01:00
* test(kubernetes): use testcontainers for test
* fix(kubernetes): get state properly reports the workload as down when scaled to 0
* refactor(kubernetes): split provider in multiple files
* refactor(provider): use Instance prefix for actions
* test(testcontainers): use provider.PullImage
* squash
* Revert "test(testcontainers): use provider.PullImage"
This reverts commit 6f958c48a5.
* test: add random generator thread safety
75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package kubernetes
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
v1 "k8s.io/api/apps/v1"
|
|
)
|
|
|
|
type ParsedName struct {
|
|
Original string
|
|
Kind string // deployment or statefulset
|
|
Namespace string
|
|
Name string
|
|
Replicas int32
|
|
}
|
|
|
|
type ParseOptions struct {
|
|
Delimiter string
|
|
}
|
|
|
|
func ParseName(name string, opts ParseOptions) (ParsedName, error) {
|
|
|
|
split := strings.Split(name, opts.Delimiter)
|
|
if len(split) != 4 {
|
|
return ParsedName{}, fmt.Errorf("invalid name [%s] should be: kind%snamespace%sname%sreplicas", name, opts.Delimiter, opts.Delimiter, opts.Delimiter)
|
|
}
|
|
|
|
replicas, err := strconv.Atoi(split[3])
|
|
if err != nil {
|
|
return ParsedName{}, err
|
|
}
|
|
|
|
return ParsedName{
|
|
Original: name,
|
|
Kind: split[0],
|
|
Namespace: split[1],
|
|
Name: split[2],
|
|
Replicas: int32(replicas),
|
|
}, nil
|
|
}
|
|
|
|
func DeploymentName(deployment *v1.Deployment, opts ParseOptions) ParsedName {
|
|
kind := "deployment"
|
|
namespace := deployment.Namespace
|
|
name := deployment.Name
|
|
// TOOD: Use annotation for scale
|
|
original := fmt.Sprintf("%s%s%s%s%s%s%d", kind, opts.Delimiter, namespace, opts.Delimiter, name, opts.Delimiter, 1)
|
|
|
|
return ParsedName{
|
|
Original: original,
|
|
Kind: kind,
|
|
Namespace: namespace,
|
|
Name: name,
|
|
Replicas: 1,
|
|
}
|
|
}
|
|
|
|
func StatefulSetName(statefulSet *v1.StatefulSet, opts ParseOptions) ParsedName {
|
|
kind := "statefulset"
|
|
namespace := statefulSet.Namespace
|
|
name := statefulSet.Name
|
|
// TOOD: Use annotation for scale
|
|
original := fmt.Sprintf("%s%s%s%s%s%s%d", kind, opts.Delimiter, namespace, opts.Delimiter, name, opts.Delimiter, 1)
|
|
|
|
return ParsedName{
|
|
Original: original,
|
|
Kind: kind,
|
|
Namespace: namespace,
|
|
Name: name,
|
|
Replicas: 1,
|
|
}
|
|
}
|