- Activate / Deactivate via flox activate --detach (with graceful SIGTERM→SIGKILL) - Non-privileged IsAlive process check with Linux /proc fallback - Dev-mode stub when flox is missing or FLOXENV_DEV_MODE=1 - Unit and integration tests Closes #16
46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package webhook
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
|
|
|
kubeclawv1alpha1 "github.com/nousresearch/kubeclaw/api/v1alpha1"
|
|
)
|
|
|
|
// AgentValidator validates Agent resources on create/update.
|
|
type AgentValidator struct{}
|
|
|
|
// +kubebuilder:webhook:path=/validate-kubeclaw-nousresearch-com-v1alpha1-agent,mutating=false,failurePolicy=fail,sideEffects=None,groups=kubeclaw.nousresearch.com,resources=agents,verbs=create;update,versions=v1alpha1,name=vagent.kubeclaw.nousresearch.com,admissionReviewVersions=v1
|
|
|
|
func (v *AgentValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
|
|
agent, ok := obj.(*kubeclawv1alpha1.Agent)
|
|
if !ok {
|
|
return nil, fmt.Errorf("expected Agent got %T", obj)
|
|
}
|
|
if agent.Spec.Identity.DisplayName == "" {
|
|
return admission.Warnings{"Agent must have a display name"}, nil
|
|
}
|
|
// TODO: Validate provider references exist
|
|
// TODO: Validate channel references exist
|
|
// TODO: Validate workflow template references exist
|
|
return nil, nil
|
|
}
|
|
|
|
func (v *AgentValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (v *AgentValidator) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (v *AgentValidator) SetupWebhookWithManager(mgr ctrl.Manager) error {
|
|
return ctrl.NewWebhookManagedBy(mgr).
|
|
For(&kubeclawv1alpha1.Agent{}).
|
|
WithValidator(v).
|
|
Complete()
|
|
}
|