From e5d7b7a7c588a87b8ed34a25af01aa180964674f Mon Sep 17 00:00:00 2001 From: Harivansh Rathi Date: Sat, 7 Feb 2026 14:39:14 -0500 Subject: [PATCH] update --- internal/commands/create.go | 14 ++++------- internal/commands/destroy.go | 15 ++++-------- internal/commands/down.go | 17 ++------------ internal/commands/helpers.go | 23 +++++++++++++++++++ internal/commands/list.go | 11 ++------- internal/commands/ssh.go | 9 +------- internal/commands/status.go | 17 ++------------ internal/commands/up.go | 2 +- internal/kube/wait.go | 21 ++++++----------- .../templates/sandbox-template.yaml.tmpl | 2 +- .../manifest/templates/warm-pool.yaml.tmpl | 2 +- 11 files changed, 48 insertions(+), 85 deletions(-) diff --git a/internal/commands/create.go b/internal/commands/create.go index 1f38d21..5274594 100644 --- a/internal/commands/create.go +++ b/internal/commands/create.go @@ -9,7 +9,6 @@ import ( "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime/schema" ) func NewCreateCmd() *cobra.Command { @@ -55,7 +54,7 @@ func NewCreateCmd() *cobra.Command { }, } - secretGVR := schema.GroupVersionResource{Group: "", Version: "v1", Resource: "secrets"} + secretGVR := coreGVR("secrets") _, err = client.Dynamic().Resource(secretGVR).Namespace(ns).Create(ctx, secret, metav1.CreateOptions{}) if err != nil { return fmt.Errorf("creating secret %q: %w", name, err) @@ -65,7 +64,7 @@ func NewCreateCmd() *cobra.Command { // Create the SandboxClaim claim := &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "agentsandbox.dev/v1", + "apiVersion": "extensions.agents.x-k8s.io/v1alpha1", "kind": "SandboxClaim", "metadata": map[string]interface{}{ "name": name, @@ -82,12 +81,7 @@ func NewCreateCmd() *cobra.Command { }, } - claimGVR := schema.GroupVersionResource{ - Group: "agentsandbox.dev", - Version: "v1", - Resource: "sandboxclaims", - } - _, err = client.Dynamic().Resource(claimGVR).Namespace(ns).Create(ctx, claim, metav1.CreateOptions{}) + _, err = client.Dynamic().Resource(sandboxClaimGVR).Namespace(ns).Create(ctx, claim, metav1.CreateOptions{}) if err != nil { return fmt.Errorf("creating SandboxClaim %q: %w", name, err) } @@ -98,7 +92,7 @@ func NewCreateCmd() *cobra.Command { waitCtx, cancel := context.WithTimeout(ctx, 3*time.Minute) defer cancel() - if err := client.WaitForReady(waitCtx, ns, "sandboxclaims", name); err != nil { + if err := client.WaitForReady(waitCtx, ns, sandboxClaimGVR, name); err != nil { return fmt.Errorf("waiting for sandbox: %w", err) } diff --git a/internal/commands/destroy.go b/internal/commands/destroy.go index 0175529..c235e19 100644 --- a/internal/commands/destroy.go +++ b/internal/commands/destroy.go @@ -9,9 +9,8 @@ import ( "github.com/rathi/agentikube/internal/kube" "github.com/spf13/cobra" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func NewDestroyCmd() *cobra.Command { @@ -50,17 +49,11 @@ func NewDestroyCmd() *cobra.Command { ns := cfg.Namespace name := "sandbox-" + handle - claimGVR := schema.GroupVersionResource{ - Group: "agentsandbox.dev", - Version: "v1", - Resource: "sandboxclaims", - } - - secretGVR := schema.GroupVersionResource{Group: "", Version: "v1", Resource: "secrets"} - pvcGVR := schema.GroupVersionResource{Group: "", Version: "v1", Resource: "persistentvolumeclaims"} + secretGVR := coreGVR("secrets") + pvcGVR := coreGVR("persistentvolumeclaims") // Delete SandboxClaim - err = client.Dynamic().Resource(claimGVR).Namespace(ns).Delete(ctx, name, metav1.DeleteOptions{}) + err = client.Dynamic().Resource(sandboxClaimGVR).Namespace(ns).Delete(ctx, name, metav1.DeleteOptions{}) if err != nil { return fmt.Errorf("deleting SandboxClaim %q: %w", name, err) } diff --git a/internal/commands/down.go b/internal/commands/down.go index dada100..d5c765f 100644 --- a/internal/commands/down.go +++ b/internal/commands/down.go @@ -7,7 +7,6 @@ import ( "github.com/rathi/agentikube/internal/kube" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" ) func NewDownCmd() *cobra.Command { @@ -30,26 +29,14 @@ func NewDownCmd() *cobra.Command { ns := cfg.Namespace - warmPoolGVR := schema.GroupVersionResource{ - Group: "agentsandbox.dev", - Version: "v1", - Resource: "sandboxwarmpools", - } - - templateGVR := schema.GroupVersionResource{ - Group: "agentsandbox.dev", - Version: "v1", - Resource: "sandboxtemplates", - } - - err = client.Dynamic().Resource(warmPoolGVR).Namespace(ns).Delete(ctx, "sandbox-warm-pool", metav1.DeleteOptions{}) + err = client.Dynamic().Resource(sandboxWarmPoolGVR).Namespace(ns).Delete(ctx, "sandbox-warm-pool", metav1.DeleteOptions{}) if err != nil { fmt.Printf("[warn] could not delete SandboxWarmPool: %v\n", err) } else { fmt.Println("[ok] SandboxWarmPool deleted") } - err = client.Dynamic().Resource(templateGVR).Namespace(ns).Delete(ctx, "sandbox-template", metav1.DeleteOptions{}) + err = client.Dynamic().Resource(sandboxTemplateGVR).Namespace(ns).Delete(ctx, "sandbox-template", metav1.DeleteOptions{}) if err != nil { fmt.Printf("[warn] could not delete SandboxTemplate: %v\n", err) } else { diff --git a/internal/commands/helpers.go b/internal/commands/helpers.go index c7d1093..ad7cbfc 100644 --- a/internal/commands/helpers.go +++ b/internal/commands/helpers.go @@ -3,8 +3,31 @@ package commands import ( "github.com/rathi/agentikube/internal/config" "github.com/spf13/cobra" + "k8s.io/apimachinery/pkg/runtime/schema" ) +var ( + sandboxClaimGVR = schema.GroupVersionResource{ + Group: "extensions.agents.x-k8s.io", + Version: "v1alpha1", + Resource: "sandboxclaims", + } + sandboxTemplateGVR = schema.GroupVersionResource{ + Group: "extensions.agents.x-k8s.io", + Version: "v1alpha1", + Resource: "sandboxtemplates", + } + sandboxWarmPoolGVR = schema.GroupVersionResource{ + Group: "extensions.agents.x-k8s.io", + Version: "v1alpha1", + Resource: "sandboxwarmpools", + } +) + +func coreGVR(resource string) schema.GroupVersionResource { + return schema.GroupVersionResource{Group: "", Version: "v1", Resource: resource} +} + func loadConfig(cmd *cobra.Command) (*config.Config, error) { cfgPath, _ := cmd.Flags().GetString("config") return config.Load(cfgPath) diff --git a/internal/commands/list.go b/internal/commands/list.go index 92605ce..fcbe996 100644 --- a/internal/commands/list.go +++ b/internal/commands/list.go @@ -10,7 +10,6 @@ import ( "github.com/rathi/agentikube/internal/kube" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" ) func NewListCmd() *cobra.Command { @@ -31,13 +30,7 @@ func NewListCmd() *cobra.Command { return fmt.Errorf("connecting to cluster: %w", err) } - claimGVR := schema.GroupVersionResource{ - Group: "agentsandbox.dev", - Version: "v1", - Resource: "sandboxclaims", - } - - list, err := client.Dynamic().Resource(claimGVR).Namespace(cfg.Namespace).List(ctx, metav1.ListOptions{}) + list, err := client.Dynamic().Resource(sandboxClaimGVR).Namespace(cfg.Namespace).List(ctx, metav1.ListOptions{}) if err != nil { return fmt.Errorf("listing SandboxClaims: %w", err) } @@ -114,7 +107,7 @@ func extractPodName(obj map[string]interface{}) string { if ok { annotations, ok := metadata["annotations"].(map[string]interface{}) if ok { - if podName, ok := annotations["agentsandbox.dev/pod-name"].(string); ok { + if podName, ok := annotations["agents.x-k8s.io/pod-name"].(string); ok { return podName } } diff --git a/internal/commands/ssh.go b/internal/commands/ssh.go index c52d1b1..5e9b9f0 100644 --- a/internal/commands/ssh.go +++ b/internal/commands/ssh.go @@ -7,7 +7,6 @@ import ( "github.com/rathi/agentikube/internal/kube" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" ) func NewSSHCmd() *cobra.Command { @@ -33,13 +32,7 @@ func NewSSHCmd() *cobra.Command { ns := cfg.Namespace name := "sandbox-" + handle - claimGVR := schema.GroupVersionResource{ - Group: "agentsandbox.dev", - Version: "v1", - Resource: "sandboxclaims", - } - - claim, err := client.Dynamic().Resource(claimGVR).Namespace(ns).Get(ctx, name, metav1.GetOptions{}) + claim, err := client.Dynamic().Resource(sandboxClaimGVR).Namespace(ns).Get(ctx, name, metav1.GetOptions{}) if err != nil { return fmt.Errorf("getting SandboxClaim %q: %w", name, err) } diff --git a/internal/commands/status.go b/internal/commands/status.go index c87c49f..b870ad0 100644 --- a/internal/commands/status.go +++ b/internal/commands/status.go @@ -7,7 +7,6 @@ import ( "github.com/rathi/agentikube/internal/kube" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" ) func NewStatusCmd() *cobra.Command { @@ -31,13 +30,7 @@ func NewStatusCmd() *cobra.Command { ns := cfg.Namespace // Warm pool status - warmPoolGVR := schema.GroupVersionResource{ - Group: "agentsandbox.dev", - Version: "v1", - Resource: "sandboxwarmpools", - } - - wp, err := client.Dynamic().Resource(warmPoolGVR).Namespace(ns).Get(ctx, "sandbox-warm-pool", metav1.GetOptions{}) + wp, err := client.Dynamic().Resource(sandboxWarmPoolGVR).Namespace(ns).Get(ctx, "sandbox-warm-pool", metav1.GetOptions{}) if err != nil { fmt.Printf("warm pool: not found (%v)\n", err) } else { @@ -55,13 +48,7 @@ func NewStatusCmd() *cobra.Command { } // Sandbox count - claimGVR := schema.GroupVersionResource{ - Group: "agentsandbox.dev", - Version: "v1", - Resource: "sandboxclaims", - } - - claims, err := client.Dynamic().Resource(claimGVR).Namespace(ns).List(ctx, metav1.ListOptions{}) + claims, err := client.Dynamic().Resource(sandboxClaimGVR).Namespace(ns).List(ctx, metav1.ListOptions{}) if err != nil { fmt.Printf("\nsandboxes: error listing (%v)\n", err) } else { diff --git a/internal/commands/up.go b/internal/commands/up.go index ab95a3e..70a3a01 100644 --- a/internal/commands/up.go +++ b/internal/commands/up.go @@ -46,7 +46,7 @@ func NewUpCmd() *cobra.Command { if cfg.Sandbox.WarmPool.Enabled { fmt.Println("waiting for warm pool to become ready...") - if err := client.WaitForReady(ctx, cfg.Namespace, "sandboxwarmpools", "sandbox-warm-pool"); err != nil { + if err := client.WaitForReady(ctx, cfg.Namespace, sandboxWarmPoolGVR, "sandbox-warm-pool"); err != nil { return fmt.Errorf("waiting for warm pool: %w", err) } fmt.Println("[ok] warm pool ready") diff --git a/internal/kube/wait.go b/internal/kube/wait.go index 4d31ee3..48691d1 100644 --- a/internal/kube/wait.go +++ b/internal/kube/wait.go @@ -10,34 +10,27 @@ import ( "k8s.io/apimachinery/pkg/watch" ) -// WaitForReady watches a resource in the agentsandbox.dev/v1 group until its -// Ready condition becomes True or the context is cancelled/times out. -// The resource parameter is the plural resource name (e.g. "sandboxclaims", "sandboxwarmpools"). -func (c *Client) WaitForReady(ctx context.Context, namespace, resource, name string) error { - gvr := schema.GroupVersionResource{ - Group: "agentsandbox.dev", - Version: "v1", - Resource: resource, - } - +// WaitForReady watches a resource until its Ready condition becomes True +// or the context is cancelled/times out. +func (c *Client) WaitForReady(ctx context.Context, namespace string, gvr schema.GroupVersionResource, name string) error { watcher, err := c.Dynamic().Resource(gvr).Namespace(namespace).Watch(ctx, metav1.ListOptions{ FieldSelector: fmt.Sprintf("metadata.name=%s", name), }) if err != nil { - return fmt.Errorf("watching %s %s/%s: %w", resource, namespace, name, err) + return fmt.Errorf("watching %s %s/%s: %w", gvr.Resource, namespace, name, err) } defer watcher.Stop() for { select { case <-ctx.Done(): - return fmt.Errorf("timed out waiting for %s %s/%s to become ready", resource, namespace, name) + return fmt.Errorf("timed out waiting for %s %s/%s to become ready", gvr.Resource, namespace, name) case event, ok := <-watcher.ResultChan(): if !ok { - return fmt.Errorf("watch channel closed for %s %s/%s", resource, namespace, name) + return fmt.Errorf("watch channel closed for %s %s/%s", gvr.Resource, namespace, name) } if event.Type == watch.Error { - return fmt.Errorf("watch error for %s %s/%s", resource, namespace, name) + return fmt.Errorf("watch error for %s %s/%s", gvr.Resource, namespace, name) } obj, ok := event.Object.(*unstructured.Unstructured) diff --git a/internal/manifest/templates/sandbox-template.yaml.tmpl b/internal/manifest/templates/sandbox-template.yaml.tmpl index a968a63..848c8a3 100644 --- a/internal/manifest/templates/sandbox-template.yaml.tmpl +++ b/internal/manifest/templates/sandbox-template.yaml.tmpl @@ -1,4 +1,4 @@ -apiVersion: agentsandbox.dev/v1 +apiVersion: extensions.agents.x-k8s.io/v1alpha1 kind: SandboxTemplate metadata: name: sandbox-template diff --git a/internal/manifest/templates/warm-pool.yaml.tmpl b/internal/manifest/templates/warm-pool.yaml.tmpl index d030490..24c16d9 100644 --- a/internal/manifest/templates/warm-pool.yaml.tmpl +++ b/internal/manifest/templates/warm-pool.yaml.tmpl @@ -1,4 +1,4 @@ -apiVersion: agentsandbox.dev/v1 +apiVersion: extensions.agents.x-k8s.io/v1alpha1 kind: SandboxWarmPool metadata: name: sandbox-warm-pool