- Add GetMetrics method to MetricsClient interface and implement cluster metrics API - Add QuotaPrecheck service for validating resource quotas before deployment - Add auth DTO with role/permission models and auth handler tests - Add instance diagnostics: mounted NFS volumes, labels, annotations in pod diagnostics - Update workspace handler with GetWorkspace endpoint and shared-user list - Fix monitoring handler to use correct service method name - Add tail_lines fallback in instance handler for snake_case query params - Update nginx config for SSE log streaming support (no buffering) - Add comprehensive test coverage: auth_service_test, auth_handler_test, auth_dto_test, metrics_client_test, quota_precheck_test - Update error messages for quota validation and instance operations - ModifyModal: fix YAML lineWidth:0, modified keys summary, delta-only submit - InstanceCard: correctly disable scale-minus when replicas <= 0 - SidebarLayout: add hover transition for sidebar items - Update todo.md and lessons.md with latest fixes
59 lines
2.1 KiB
Go
59 lines
2.1 KiB
Go
package k8s
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/ocdp/cluster-service/internal/domain/entity"
|
|
"github.com/ocdp/cluster-service/internal/domain/repository"
|
|
)
|
|
|
|
type MockTenantClient struct{}
|
|
|
|
func NewMockTenantClient() repository.TenantKubeClient {
|
|
return &MockTenantClient{}
|
|
}
|
|
|
|
func (c *MockTenantClient) EnsureTenant(ctx context.Context, cluster *entity.Cluster, binding entity.TenantBinding) error {
|
|
return binding.Validate()
|
|
}
|
|
|
|
func (c *MockTenantClient) IssueKubeconfig(ctx context.Context, cluster *entity.Cluster, binding entity.TenantBinding, ttl time.Duration) (*entity.TenantKubeconfig, error) {
|
|
if err := binding.Validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
expiresAt := time.Now().Add(entity.TenantTokenTTL(ttl))
|
|
return &entity.TenantKubeconfig{
|
|
Kubeconfig: fmt.Sprintf("apiVersion: v1\nkind: Config\nclusters:\n- name: %s\n cluster:\n server: %s\ncontexts:\n- name: %s\n context:\n cluster: %s\n namespace: %s\n user: %s\ncurrent-context: %s\nusers:\n- name: %s\n user:\n token: mock-ephemeral-token\n",
|
|
cluster.Name, cluster.Host, binding.Namespace, cluster.Name, binding.Namespace, binding.ServiceAccountName, binding.Namespace, binding.ServiceAccountName),
|
|
ExpiresAt: expiresAt,
|
|
}, nil
|
|
}
|
|
|
|
func (c *MockTenantClient) GetResourceQuotaUsage(ctx context.Context, cluster *entity.Cluster, binding entity.TenantBinding) (*repository.ResourceQuotaUsage, error) {
|
|
if err := binding.Validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
return &repository.ResourceQuotaUsage{
|
|
Hard: resourceVectorFromList(binding.ResourceQuotaHard),
|
|
Used: repository.ResourceVector{},
|
|
}, nil
|
|
}
|
|
|
|
func (c *MockTenantClient) SuspendTenant(ctx context.Context, cluster *entity.Cluster, binding entity.TenantBinding) error {
|
|
return binding.Validate()
|
|
}
|
|
|
|
func (c *MockTenantClient) DeleteTenant(ctx context.Context, cluster *entity.Cluster, binding entity.TenantBinding) error {
|
|
if err := binding.Validate(); err != nil {
|
|
return err
|
|
}
|
|
switch binding.Namespace {
|
|
case "", "default", "kube-system", "kube-public", "kube-node-lease":
|
|
return entity.ErrProtectedNamespace
|
|
default:
|
|
return nil
|
|
}
|
|
}
|