tests: тестовые ресурсы с префиксом test-/t-, ns fission-test-*, guard в cleanup
This commit is contained in:
@@ -25,10 +25,14 @@ type UserIdentity struct {
|
||||
Email string // email — опционально, для отображения в UI
|
||||
}
|
||||
|
||||
// NamespaceForSub вычисляет детерминированный K8s namespace из Sub:
|
||||
// "fission-" + hex(SHA256(sub)[:8])
|
||||
// NamespaceForSub вычисляет детерминированный K8s namespace из Sub.
|
||||
// Если sub начинается с "test-" → "fission-test-" + hex(SHA256(sub)[:8])
|
||||
// Иначе → "fission-" + hex(SHA256(sub)[:8])
|
||||
func NamespaceForSub(sub string) string {
|
||||
h := sha256.Sum256([]byte(sub))
|
||||
if strings.HasPrefix(sub, "test-") {
|
||||
return "fission-test-" + hex.EncodeToString(h[:8])
|
||||
}
|
||||
return "fission-" + hex.EncodeToString(h[:8])
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -37,16 +38,20 @@ import (
|
||||
// (не ClusterRoleBinding) безопасен — даёт полный доступ только внутри NS.
|
||||
func SetupFissionNamespace(ctx context.Context, dyn dynamic.Interface, ns string) error {
|
||||
// 1. Namespace
|
||||
labels := map[string]any{
|
||||
"managed-by": "fission-console",
|
||||
"fission.io/managed": "true", // Layer 1: executor NSWatcher auto-discovers this NS
|
||||
}
|
||||
if strings.HasPrefix(ns, "fission-test-") {
|
||||
labels["fission-console/env"] = "test"
|
||||
}
|
||||
nsObj := &unstructured.Unstructured{
|
||||
Object: map[string]any{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Namespace",
|
||||
"metadata": map[string]any{
|
||||
"name": ns,
|
||||
"labels": map[string]any{
|
||||
"managed-by": "fission-console",
|
||||
"fission.io/managed": "true", // Layer 1: executor NSWatcher auto-discovers this NS
|
||||
},
|
||||
"name": ns,
|
||||
"labels": labels,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user