diff --git a/controller/README.md b/controller/README.md deleted file mode 100644 index d94ffdd22..000000000 --- a/controller/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Controller - -Fill me in. \ No newline at end of file diff --git a/controller/go.mod b/controller/go.mod deleted file mode 100644 index 7ee6405b0..000000000 --- a/controller/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/kagent-dev/kagent/controller - -go 1.23.5 diff --git a/go/autogen/api/client.go b/go/autogen/api/client.go new file mode 100644 index 000000000..b99360557 --- /dev/null +++ b/go/autogen/api/client.go @@ -0,0 +1,116 @@ +package api + +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "strings" + "time" +) + +type Client struct { + BaseURL string + WSURL string + HTTPClient *http.Client +} + +func NewClient(baseURL, wsURL string) *Client { + // Ensure baseURL doesn't end with a slash + baseURL = strings.TrimRight(baseURL, "/") + + return &Client{ + BaseURL: baseURL, + WSURL: wsURL, + HTTPClient: &http.Client{ + Timeout: time.Second * 30, + }, + } +} + +func (c *Client) GetVersion() (string, error) { + var result struct { + Status bool `json:"status"` + Message string `json:"message"` + Data struct { + Version string `json:"version"` + } `json:"data"` + } + + err := c.doRequest("GET", "/version", nil, &result) + if err != nil { + return "", err + } + + if !result.Status { + return "", fmt.Errorf("api error: %s", result.Message) + } + + return result.Data.Version, nil +} + +func (c *Client) doRequest(method, path string, body interface{}, result interface{}) error { + var bodyReader *bytes.Reader + if body != nil { + bodyBytes, err := json.Marshal(body) + if err != nil { + return fmt.Errorf("error marshaling request body: %w", err) + } + bodyReader = bytes.NewReader(bodyBytes) + } + + // Ensure path starts with a slash + if !strings.HasPrefix(path, "/") { + path = "/" + path + } + + url := c.BaseURL + path + + var req *http.Request + var err error + if bodyReader != nil { + req, err = http.NewRequest(method, url, bodyReader) + } else { + req, err = http.NewRequest(method, url, nil) + } + if err != nil { + return fmt.Errorf("error creating request: %w", err) + } + + req.Header.Set("Content-Type", "application/json") + + resp, err := c.HTTPClient.Do(req) + if err != nil { + return fmt.Errorf("error making request: %w", err) + } + defer resp.Body.Close() + + if resp.StatusCode >= 400 { + return fmt.Errorf("request failed with status: %s", resp.Status) + } + + // Decode into APIResponse first + var apiResp APIResponse + if err := json.NewDecoder(resp.Body).Decode(&apiResp); err != nil { + return fmt.Errorf("error decoding response: %w", err) + } + + // Check response status + if !apiResp.Status { + return fmt.Errorf("api error: %s", apiResp.Message) + } + + // If caller wants the result, marshal the Data field into their result type + if result != nil { + dataBytes, err := json.Marshal(apiResp.Data) + if err != nil { + return fmt.Errorf("error re-marshaling data: %w", err) + } + + if err := json.Unmarshal(dataBytes, result); err != nil { + return fmt.Errorf("error unmarshaling into result: %w", err) + } + } + + return nil +} diff --git a/go/autogen/api/run.go b/go/autogen/api/run.go new file mode 100644 index 000000000..369952203 --- /dev/null +++ b/go/autogen/api/run.go @@ -0,0 +1,37 @@ +package api + +import "fmt" + +func (c *Client) CreateRun(req *CreateRunRequest) (*CreateRunResult, error) { + var run CreateRunResult + err := c.doRequest("POST", "/runs", req, &run) + return &run, err +} + +func (c *Client) GetRun(runID string) (*Run, error) { + var run Run + err := c.doRequest("GET", fmt.Sprintf("/runs/%s", runID), nil, &run) + return &run, err +} + +func (c *Client) ListRuns(userID string) ([]Run, error) { + // Go through all sessions and then retrieve all runs for each session + var sessions []Session + err := c.doRequest("GET", fmt.Sprintf("/sessions/?user_id=%s", userID), nil, &sessions) + if err != nil { + return nil, err + } + + // For each session, get the run information + var runs []Run + for _, session := range sessions { + var sessionRuns SessionRuns + err := c.doRequest("GET", fmt.Sprintf("/sessions/%d/runs/?user_id=%s", session.ID, userID), nil, &sessionRuns) + if err != nil { + fmt.Println("Error getting runs for session") + return nil, err + } + runs = append(runs, sessionRuns.Runs...) + } + return runs, nil +} diff --git a/go/autogen/api/session.go b/go/autogen/api/session.go new file mode 100644 index 000000000..d19eabcb0 --- /dev/null +++ b/go/autogen/api/session.go @@ -0,0 +1,25 @@ +package api + +import "fmt" + +func (c *Client) ListSessions(userID string) ([]Session, error) { + var sessions []Session + err := c.doRequest("GET", fmt.Sprintf("/sessions/?user_id=%s", userID), nil, &sessions) + return sessions, err +} + +func (c *Client) CreateSession(session *CreateSession) (*Session, error) { + var result Session + err := c.doRequest("POST", "/sessions/", session, &result) + return &result, err +} + +func (c *Client) GetSession(sessionID int, userID string) (*Session, error) { + var session Session + err := c.doRequest("GET", fmt.Sprintf("/sessions/%d?user_id=%s", sessionID, userID), nil, &session) + return &session, err +} + +func (c *Client) DeleteSession(sessionID int, userID string) error { + return c.doRequest("DELETE", fmt.Sprintf("/sessions/%d?user_id=%s", sessionID, userID), nil, nil) +} diff --git a/go/autogen/api/team.go b/go/autogen/api/team.go new file mode 100644 index 000000000..d2fa06cc9 --- /dev/null +++ b/go/autogen/api/team.go @@ -0,0 +1,32 @@ +package api + +import "fmt" + +func (c *Client) ListTeams(userID string) ([]TeamResponse, error) { + var teams []TeamResponse + err := c.doRequest("GET", fmt.Sprintf("/teams/?user_id=%s", userID), nil, &teams) + return teams, err +} + +func (c *Client) CreateTeam(team *TeamResponse) error { + return c.doRequest("POST", "/teams/", team, team) +} + +func (c *Client) GetTeam(teamLabel string, userID string) (*TeamResponse, error) { + allTeams, err := c.ListTeams(userID) + if err != nil { + return nil, err + } + + for _, team := range allTeams { + if team.Component.Label == teamLabel { + return &team, nil + } + } + + return nil, nil +} + +func (c *Client) DeleteTeam(teamID int, userID string) error { + return c.doRequest("DELETE", fmt.Sprintf("/teams/%d?user_id=%s", teamID, userID), nil, nil) +} diff --git a/go/autogen/api/types.go b/go/autogen/api/types.go new file mode 100644 index 000000000..df6029be0 --- /dev/null +++ b/go/autogen/api/types.go @@ -0,0 +1,320 @@ +package api + +// APIResponse is the common response wrapper for all API responses +type APIResponse struct { + Status bool `json:"status"` + Message string `json:"message"` + Data interface{} `json:"data"` +} + +type Session struct { + ID int `json:"id"` + UserID string `json:"user_id"` + Version string `json:"version"` + TeamID int `json:"team_id"` + Name string `json:"name"` +} + +type CreateSession struct { + UserID string `json:"user_id"` + TeamID int `json:"team_id"` + Name string `json:"name"` +} + +// BaseComponent represents the common fields in all components +type BaseComponent struct { + Provider string `json:"provider"` + ComponentType string `json:"component_type"` + Version int `json:"version"` + ComponentVersion int `json:"component_version"` + Description *string `json:"description"` + Config interface{} `json:"config"` + Label *string `json:"label,omitempty"` +} + +// TeamResponseConfig represents the team component configuration +type TeamResponseConfig struct { + Participants []BaseComponent `json:"participants"` + TerminationCondition *BaseComponent `json:"termination_condition,omitempty"` +} + +// TeamComponent represents the component field in the Team response +type TeamComponent struct { + Provider string `json:"provider"` + ComponentType string `json:"component_type"` + Version int `json:"version"` + ComponentVersion int `json:"component_version"` + Description *string `json:"description"` + Component TeamResponseConfig `json:"component"` + Label string `json:"label"` + Config TeamConfig `json:"config"` +} + +// TeamResponse represents the full team response structure +type TeamResponse struct { + ID int `json:"id"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` + UserID string `json:"user_id"` + Version string `json:"version"` + Component TeamComponent `json:"component"` +} + +// AgentConfig represents the configuration for an agent +type AgentResponseConfig struct { + Name string `json:"name"` + ModelClient *BaseComponent `json:"model_client"` + Tools []BaseComponent `json:"tools,omitempty"` + ModelContext *BaseComponent `json:"model_context,omitempty"` + Description string `json:"description"` + SystemMessage string `json:"system_message"` + ReflectOnToolUse bool `json:"reflect_on_tool_use"` + ToolCallSummaryFormat string `json:"tool_call_summary_format"` +} + +// ModelResponseConfig represents the configuration for a model +type ModelResponseConfig struct { + Model string `json:"model"` +} + +// TerminationResponseConfig represents the configuration for termination conditions +type TerminationResponseConfig struct { + MaxMessages int `json:"max_messages"` +} + +// HTTPToolConfig represents the configuration for HTTP tools +type HTTPToolConfig struct { + Name string `json:"name"` + Description string `json:"description"` + Scheme string `json:"scheme"` + Host string `json:"host"` + Port int `json:"port"` + Path string `json:"path"` + Method string `json:"method"` + Headers map[string]string `json:"headers"` + JSONSchema map[string]interface{} `json:"json_schema"` +} + +// BuiltInToolConfig represents the configuration for built-in tools +type BuiltInToolConfig struct { + FnName string `json:"fn_name"` +} + +// TeamConfig represents either a SelectorGroupChatConfig or RoundRobinGroupChatConfig +type TeamConfig struct { + // Shared fields between both configs + Participants []AgentComponent `json:"participants"` + TerminationCondition *TerminationComponent `json:"termination_condition,omitempty"` + MaxTurns *int `json:"max_turns,omitempty"` + + // SelectorGroupChat specific fields + ModelClient *ModelComponent `json:"model_client,omitempty"` + SelectorPrompt string `json:"selector_prompt,omitempty"` + AllowRepeatedSpeaker bool `json:"allow_repeated_speaker,omitempty"` +} + +// Component types +type AgentComponent struct { + Provider string `json:"provider"` + ComponentType string `json:"component_type"` + Version *int `json:"version,omitempty"` + Description *string `json:"description,omitempty"` + Component AgentConfig `json:"component"` + Label *string `json:"label,omitempty"` +} + +type ModelComponent struct { + Provider string `json:"provider"` + ComponentType string `json:"component_type"` + Version *int `json:"version,omitempty"` + Description *string `json:"description,omitempty"` + Component ModelConfig `json:"component"` + Label *string `json:"label,omitempty"` +} + +type TerminationComponent struct { + Provider string `json:"provider"` + ComponentType string `json:"component_type"` + Version *int `json:"version,omitempty"` + Description *string `json:"description,omitempty"` + Component TerminationConfig `json:"component"` + Label *string `json:"label,omitempty"` +} + +// Agent Configurations +type AgentConfig struct { + // MultimodalWebSurferConfig fields + Name string `json:"name"` + ModelClient *ModelComponent `json:"model_client,omitempty"` + DownloadsFolder *string `json:"downloads_folder,omitempty"` + Description string `json:"description"` + DebugDir *string `json:"debug_dir,omitempty"` + Headless *bool `json:"headless,omitempty"` + StartPage *string `json:"start_page,omitempty"` + AnimateActions *bool `json:"animate_actions,omitempty"` + ToSaveScreenshots *bool `json:"to_save_screenshots,omitempty"` + UseOCR *bool `json:"use_ocr,omitempty"` + BrowserChannel *string `json:"browser_channel,omitempty"` + BrowserDataDir *string `json:"browser_data_dir,omitempty"` + ToResizeViewport *bool `json:"to_resize_viewport,omitempty"` + + // AssistantAgentConfig fields + Tools []ToolComponent `json:"tools,omitempty"` + ModelContext *ChatCompletionContextComponent `json:"model_context,omitempty"` + SystemMessage *string `json:"system_message,omitempty"` + ReflectOnToolUse bool `json:"reflect_on_tool_use,omitempty"` + ToolCallSummaryFormat string `json:"tool_call_summary_format,omitempty"` +} + +// Model Configurations +type ModelInfo struct { + Vision bool `json:"vision"` + FunctionCalling bool `json:"function_calling"` + JSONOutput bool `json:"json_output"` + Family string `json:"family"` +} + +type CreateArgumentsConfig struct { + FrequencyPenalty *float64 `json:"frequency_penalty,omitempty"` + LogitBias map[string]float64 `json:"logit_bias,omitempty"` + MaxTokens *int `json:"max_tokens,omitempty"` + N *int `json:"n,omitempty"` + PresencePenalty *float64 `json:"presence_penalty,omitempty"` + ResponseFormat interface{} `json:"response_format,omitempty"` + Seed *int `json:"seed,omitempty"` + Stop interface{} `json:"stop,omitempty"` + Temperature *float64 `json:"temperature,omitempty"` + TopP *float64 `json:"top_p,omitempty"` + User *string `json:"user,omitempty"` +} + +type ModelConfig struct { + // Base OpenAI fields + Model string `json:"model"` + APIKey *string `json:"api_key,omitempty"` + Timeout *int `json:"timeout,omitempty"` + MaxRetries *int `json:"max_retries,omitempty"` + ModelCapabilities interface{} `json:"model_capabilities,omitempty"` + ModelInfo *ModelInfo `json:"model_info,omitempty"` + CreateArgumentsConfig + + // OpenAIClientConfig specific fields + Organization *string `json:"organization,omitempty"` + BaseURL *string `json:"base_url,omitempty"` + + // AzureOpenAIClientConfig specific fields + AzureEndpoint *string `json:"azure_endpoint,omitempty"` + AzureDeployment *string `json:"azure_deployment,omitempty"` + APIVersion *string `json:"api_version,omitempty"` + AzureADToken *string `json:"azure_ad_token,omitempty"` + AzureADTokenProvider interface{} `json:"azure_ad_token_provider,omitempty"` +} + +// Tool Configuration +type ToolComponent struct { + Provider string `json:"provider"` + ComponentType string `json:"component_type"` + Version *int `json:"version,omitempty"` + Description *string `json:"description,omitempty"` + Component ToolConfig `json:"component"` + Label *string `json:"label,omitempty"` +} + +type ToolConfig struct { + SourceCode string `json:"source_code"` + Name string `json:"name"` + Description string `json:"description"` + GlobalImports []interface{} `json:"global_imports"` + HasCancellationSupport bool `json:"has_cancellation_support"` + + // for BUILTIN TOOL type + FnName string `json:"fn_name,omitempty"` +} + +// ChatCompletionContext Configuration +type ChatCompletionContextComponent struct { + Provider string `json:"provider"` + ComponentType string `json:"component_type"` + Version *int `json:"version,omitempty"` + Description *string `json:"description,omitempty"` + Component ChatCompletionContextConfig `json:"component"` + Label *string `json:"label,omitempty"` +} + +type ChatCompletionContextConfig struct { + // Empty as per the TypeScript definition +} + +// Termination Configurations +type TerminationConfig struct { + // OrTerminationConfig + Conditions []TerminationComponent `json:"conditions,omitempty"` + + // MaxMessageTerminationConfig + MaxMessages *int `json:"max_messages,omitempty"` + + // TextMentionTerminationConfig + Text *string `json:"text,omitempty"` +} +type ModelsUsage struct { + PromptTokens int `json:"prompt_tokens"` + CompletionTokens int `json:"completion_tokens"` +} + +type TaskMessage struct { + Source string `json:"source"` + ModelsUsage *ModelsUsage `json:"models_usage"` + Content string `json:"content"` + Type string `json:"type"` +} + +type RunMessage struct { + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` + Version string `json:"version"` + SessionID int `json:"session_id"` + MessageMeta map[string]interface{} `json:"message_meta"` + ID int `json:"id"` + UserID *string `json:"user_id"` + Component TaskMessage `json:"component"` + RunID string `json:"run_id"` +} + +type CreateRunRequest struct { + SessionID int `json:"session_id"` + UserID string `json:"user_id"` +} + +type CreateRunResult struct { + ID string `json:"run_id"` +} + +type SessionRuns struct { + Runs []Run `json:"runs"` +} + +type Run struct { + ID string `json:"id"` + CreatedAt string `json:"created_at"` + Status string `json:"status"` + Task Task `json:"task"` + TeamResult TeamResult `json:"team_result"` + Messages []RunMessage `json:"messages"` +} + +type Task struct { + Source string `json:"source"` + Content string `json:"content"` + MessageType string `json:"message_type"` +} + +type TeamResult struct { + TaskResult TaskResult `json:"task_result"` + Usage string `json:"usage"` + Duration float64 `json:"duration"` +} + +type TaskResult struct { + Messages []TaskMessage `json:"messages"` + StopReason string `json:"stop_reason"` +} diff --git a/go/controller/.dockerignore b/go/controller/.dockerignore new file mode 100644 index 000000000..a3aab7af7 --- /dev/null +++ b/go/controller/.dockerignore @@ -0,0 +1,3 @@ +# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file +# Ignore build and test binaries. +bin/ diff --git a/go/controller/.gitignore b/go/controller/.gitignore new file mode 100644 index 000000000..ada68ff08 --- /dev/null +++ b/go/controller/.gitignore @@ -0,0 +1,27 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +bin/* +Dockerfile.cross + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Go workspace file +go.work + +# Kubernetes Generated files - skip generated files, except for vendored files +!vendor/**/zz_generated.* + +# editor and IDE paraphernalia +.idea +.vscode +*.swp +*.swo +*~ diff --git a/go/controller/Dockerfile b/go/controller/Dockerfile new file mode 100644 index 000000000..348b8372c --- /dev/null +++ b/go/controller/Dockerfile @@ -0,0 +1,33 @@ +# Build the manager binary +FROM docker.io/golang:1.23 AS builder +ARG TARGETOS +ARG TARGETARCH + +WORKDIR /workspace +# Copy the Go Modules manifests +COPY go.mod go.mod +COPY go.sum go.sum +# cache deps before building and copying source so that we don't need to re-download as much +# and so that source changes don't invalidate our downloaded layer +RUN go mod download + +# Copy the go source +COPY cmd/main.go cmd/main.go +COPY api/ api/ +COPY internal/ internal/ + +# Build +# the GOARCH has not a default value to allow the binary be built according to the host where the command +# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO +# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, +# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go + +# Use distroless as minimal base image to package the manager binary +# Refer to https://github.com/GoogleContainerTools/distroless for more details +FROM gcr.io/distroless/static:nonroot +WORKDIR / +COPY --from=builder /workspace/manager . +USER 65532:65532 + +ENTRYPOINT ["/manager"] diff --git a/go/controller/Makefile b/go/controller/Makefile new file mode 100644 index 000000000..600010cd3 --- /dev/null +++ b/go/controller/Makefile @@ -0,0 +1,225 @@ +# Image URL to use all building/pushing image targets +IMG ?= controller:latest + +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) +ifeq (,$(shell go env GOBIN)) +GOBIN=$(shell go env GOPATH)/bin +else +GOBIN=$(shell go env GOBIN) +endif + +# CONTAINER_TOOL defines the container tool to be used for building images. +# Be aware that the target commands are only tested with Docker which is +# scaffolded by default. However, you might want to replace it to use other +# tools. (i.e. podman) +CONTAINER_TOOL ?= docker + +# Setting SHELL to bash allows bash commands to be executed by recipes. +# Options are set to exit when a recipe line exits non-zero or a piped command fails. +SHELL = /usr/bin/env bash -o pipefail +.SHELLFLAGS = -ec + +.PHONY: all +all: build + +##@ General + +# The help target prints out all targets with their descriptions organized +# beneath their categories. The categories are represented by '##@' and the +# target descriptions by '##'. The awk command is responsible for reading the +# entire set of makefiles included in this invocation, looking for lines of the +# file as xyz: ## something, and then pretty-format the target and help. Then, +# if there's a line with ##@ something, that gets pretty-printed as a category. +# More info on the usage of ANSI control characters for terminal formatting: +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters +# More info on the awk command: +# http://linuxcommand.org/lc3_adv_awk.php + +.PHONY: help +help: ## Display this help. + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + +##@ Development + +.PHONY: manifests +manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. + $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases + +.PHONY: generate +generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. + $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." + +.PHONY: fmt +fmt: ## Run go fmt against code. + go fmt ./... + +.PHONY: vet +vet: ## Run go vet against code. + go vet ./... + +.PHONY: test +test: manifests generate fmt vet setup-envtest ## Run tests. + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out + +# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'. +# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally. +# Prometheus and CertManager are installed by default; skip with: +# - PROMETHEUS_INSTALL_SKIP=true +# - CERT_MANAGER_INSTALL_SKIP=true +.PHONY: test-e2e +test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind. + @command -v kind >/dev/null 2>&1 || { \ + echo "Kind is not installed. Please install Kind manually."; \ + exit 1; \ + } + @kind get clusters | grep -q 'kind' || { \ + echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \ + exit 1; \ + } + go test ./test/e2e/ -v -ginkgo.v + +.PHONY: lint +lint: golangci-lint ## Run golangci-lint linter + $(GOLANGCI_LINT) run + +.PHONY: lint-fix +lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes + $(GOLANGCI_LINT) run --fix + +.PHONY: lint-config +lint-config: golangci-lint ## Verify golangci-lint linter configuration + $(GOLANGCI_LINT) config verify + +##@ Build + +.PHONY: build +build: manifests generate fmt vet ## Build manager binary. + go build -o bin/manager cmd/main.go + +.PHONY: run +run: manifests generate fmt vet ## Run a controller from your host. + go run ./cmd/main.go + +# If you wish to build the manager image targeting other platforms you can use the --platform flag. +# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it. +# More info: https://docs.docker.com/develop/develop-images/build_enhancements/ +.PHONY: docker-build +docker-build: ## Build docker image with the manager. + $(CONTAINER_TOOL) build -t ${IMG} . + +.PHONY: docker-push +docker-push: ## Push docker image with the manager. + $(CONTAINER_TOOL) push ${IMG} + +# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple +# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: +# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/ +# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/ +# - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=> then the export will fail) +# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option. +PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le +.PHONY: docker-buildx +docker-buildx: ## Build and push docker image for the manager for cross-platform support + # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile + sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross + - $(CONTAINER_TOOL) buildx create --name controller-builder + $(CONTAINER_TOOL) buildx use controller-builder + - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . + - $(CONTAINER_TOOL) buildx rm controller-builder + rm Dockerfile.cross + +.PHONY: build-installer +build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment. + mkdir -p dist + cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} + $(KUSTOMIZE) build config/default > dist/install.yaml + +##@ Deployment + +ifndef ignore-not-found + ignore-not-found = false +endif + +.PHONY: install +install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. + $(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f - + +.PHONY: uninstall +uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. + $(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f - + +.PHONY: deploy +deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. + cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} + $(KUSTOMIZE) build config/default | $(KUBECTL) apply -f - + +.PHONY: undeploy +undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. + $(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f - + +##@ Dependencies + +## Location to install dependencies to +LOCALBIN ?= $(shell pwd)/bin +$(LOCALBIN): + mkdir -p $(LOCALBIN) + +## Tool Binaries +KUBECTL ?= kubectl +KUSTOMIZE ?= $(LOCALBIN)/kustomize +CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen +ENVTEST ?= $(LOCALBIN)/setup-envtest +GOLANGCI_LINT = $(LOCALBIN)/golangci-lint + +## Tool Versions +KUSTOMIZE_VERSION ?= v5.5.0 +CONTROLLER_TOOLS_VERSION ?= v0.17.1 +#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20) +ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}') +#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31) +ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}') +GOLANGCI_LINT_VERSION ?= v1.63.4 + +.PHONY: kustomize +kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. +$(KUSTOMIZE): $(LOCALBIN) + $(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION)) + +.PHONY: controller-gen +controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. +$(CONTROLLER_GEN): $(LOCALBIN) + $(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION)) + +.PHONY: setup-envtest +setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory. + @echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..." + @$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \ + echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \ + exit 1; \ + } + +.PHONY: envtest +envtest: $(ENVTEST) ## Download setup-envtest locally if necessary. +$(ENVTEST): $(LOCALBIN) + $(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION)) + +.PHONY: golangci-lint +golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. +$(GOLANGCI_LINT): $(LOCALBIN) + $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) + +# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist +# $1 - target path with name of binary +# $2 - package url which can be installed +# $3 - specific version of package +define go-install-tool +@[ -f "$(1)-$(3)" ] || { \ +set -e; \ +package=$(2)@$(3) ;\ +echo "Downloading $${package}" ;\ +rm -f $(1) || true ;\ +GOBIN=$(LOCALBIN) go install $${package} ;\ +mv $(1) $(1)-$(3) ;\ +} ;\ +ln -sf $(1)-$(3) $(1) +endef diff --git a/go/controller/PROJECT b/go/controller/PROJECT new file mode 100644 index 000000000..caddd4461 --- /dev/null +++ b/go/controller/PROJECT @@ -0,0 +1,47 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html +domain: ai.solo.io +layout: +- go.kubebuilder.io/v4 +projectName: controller +repo: github.com/kagent-dev/kagent/go/controller +resources: +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: ai.solo.io + group: agent + kind: AutogenTeam + path: github.com/kagent-dev/kagent/go/controller/api/v1alpha1 + version: v1alpha1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: ai.solo.io + group: agent + kind: AutogenAgent + path: github.com/kagent-dev/kagent/go/controller/api/v1alpha1 + version: v1alpha1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: ai.solo.io + group: agent + kind: AutogenTool + path: github.com/kagent-dev/kagent/go/controller/api/v1alpha1 + version: v1alpha1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: ai.solo.io + group: agent + kind: AutogenModelConfig + path: github.com/kagent-dev/kagent/go/controller/api/v1alpha1 + version: v1alpha1 +version: "3" diff --git a/go/controller/README.md b/go/controller/README.md new file mode 100644 index 000000000..be1747612 --- /dev/null +++ b/go/controller/README.md @@ -0,0 +1,134 @@ +# controller +// TODO(user): Add simple overview of use/purpose + +## Description +// TODO(user): An in-depth paragraph about your project and overview of use + +## Getting Started + +### Prerequisites +- go version v1.23.0+ +- docker version 17.03+. +- kubectl version v1.11.3+. +- Access to a Kubernetes v1.11.3+ cluster. + +### To Deploy on the cluster +**Build and push your image to the location specified by `IMG`:** + +```sh +make docker-build docker-push IMG=/controller:tag +``` + +**NOTE:** This image ought to be published in the personal registry you specified. +And it is required to have access to pull the image from the working environment. +Make sure you have the proper permission to the registry if the above commands don’t work. + +**Install the CRDs into the cluster:** + +```sh +make install +``` + +**Deploy the Manager to the cluster with the image specified by `IMG`:** + +```sh +make deploy IMG=/controller:tag +``` + +> **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin +privileges or be logged in as admin. + +**Create instances of your solution** +You can apply the samples (examples) from the config/sample: + +```sh +kubectl apply -k config/samples/ +``` + +>**NOTE**: Ensure that the samples has default values to test it out. + +### To Uninstall +**Delete the instances (CRs) from the cluster:** + +```sh +kubectl delete -k config/samples/ +``` + +**Delete the APIs(CRDs) from the cluster:** + +```sh +make uninstall +``` + +**UnDeploy the controller from the cluster:** + +```sh +make undeploy +``` + +## Project Distribution + +Following the options to release and provide this solution to the users. + +### By providing a bundle with all YAML files + +1. Build the installer for the image built and published in the registry: + +```sh +make build-installer IMG=/controller:tag +``` + +**NOTE:** The makefile target mentioned above generates an 'install.yaml' +file in the dist directory. This file contains all the resources built +with Kustomize, which are necessary to install this project without its +dependencies. + +2. Using the installer + +Users can just run 'kubectl apply -f ' to install +the project, i.e.: + +```sh +kubectl apply -f https://raw.githubusercontent.com//controller//dist/install.yaml +``` + +### By providing a Helm Chart + +1. Build the chart using the optional helm plugin + +```sh +kubebuilder edit --plugins=helm/v1-alpha +``` + +2. See that a chart was generated under 'dist/chart', and users +can obtain this solution from there. + +**NOTE:** If you change the project, you need to update the Helm Chart +using the same command above to sync the latest changes. Furthermore, +if you create webhooks, you need to use the above command with +the '--force' flag and manually ensure that any custom configuration +previously added to 'dist/chart/values.yaml' or 'dist/chart/manager/manager.yaml' +is manually re-applied afterwards. + +## Contributing +// TODO(user): Add detailed information on how you would like others to contribute to this project + +**NOTE:** Run `make help` for more information on all potential `make` targets + +More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html) + +## License + +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/go/controller/api/v1alpha1/autogenagent_types.go b/go/controller/api/v1alpha1/autogenagent_types.go new file mode 100644 index 000000000..3a60adff8 --- /dev/null +++ b/go/controller/api/v1alpha1/autogenagent_types.go @@ -0,0 +1,60 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +// AutogenAgentSpec defines the desired state of AutogenAgent. +type AutogenAgentSpec struct { + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + SystemMessage string `json:"systemMessage,omitempty"` + Tools []string `json:"tools,omitempty"` +} + +// AutogenAgentStatus defines the observed state of AutogenAgent. +type AutogenAgentStatus struct{} + +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status + +// AutogenAgent is the Schema for the autogenagents API. +type AutogenAgent struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec AutogenAgentSpec `json:"spec,omitempty"` + Status AutogenAgentStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// AutogenAgentList contains a list of AutogenAgent. +type AutogenAgentList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []AutogenAgent `json:"items"` +} + +func init() { + SchemeBuilder.Register(&AutogenAgent{}, &AutogenAgentList{}) +} diff --git a/go/controller/api/v1alpha1/autogenmodelconfig_types.go b/go/controller/api/v1alpha1/autogenmodelconfig_types.go new file mode 100644 index 000000000..23e20d0c3 --- /dev/null +++ b/go/controller/api/v1alpha1/autogenmodelconfig_types.go @@ -0,0 +1,56 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// AutogenModelConfigSpec defines the desired state of AutogenModelConfig. +type AutogenModelConfigSpec struct { + Model string `json:"model"` + APIKeySecretName string `json:"apiKeySecretName"` + APIKeySecretKey string `json:"apiKeySecretKey"` +} + +// AutogenModelConfigStatus defines the observed state of AutogenModelConfig. +type AutogenModelConfigStatus struct{} + +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status + +// AutogenModelConfig is the Schema for the autogenmodelconfigs API. +type AutogenModelConfig struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec AutogenModelConfigSpec `json:"spec,omitempty"` + Status AutogenModelConfigStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// AutogenModelConfigList contains a list of AutogenModelConfig. +type AutogenModelConfigList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []AutogenModelConfig `json:"items"` +} + +func init() { + SchemeBuilder.Register(&AutogenModelConfig{}, &AutogenModelConfigList{}) +} diff --git a/go/controller/api/v1alpha1/autogenteam_types.go b/go/controller/api/v1alpha1/autogenteam_types.go new file mode 100644 index 000000000..3de638a03 --- /dev/null +++ b/go/controller/api/v1alpha1/autogenteam_types.go @@ -0,0 +1,91 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +// AutogenTeamSpec defines the desired state of AutogenTeam. +type AutogenTeamSpec struct { + Participants []string `json:"participants"` + Description string `json:"description"` + SelectorTeamConfig SelectorTeamConfig `json:"selectorTeamConfig"` + TerminationCondition TerminationCondition `json:"terminationCondition"` + MaxTurns int64 `json:"maxTurns"` +} + +type SelectorTeamConfig struct { + SelectorPrompt string `json:"selectorPrompt"` + ModelConfig string `json:"modelConfig"` +} + +// +kubebuilder:validation:XValidation:message="There must one termination type set",rule="1 == (self.maxMessageTermination != null?1:0) + (self.textMentionTermination != null?1:0) + (self.orTermination != null?1:0)" +type TerminationCondition struct { + // ONEOF: maxMessageTermination, textMentionTermination, orTermination + MaxMessageTermination *MaxMessageTermination `json:"maxMessageTermination,omitempty"` + TextMentionTermination *TextMentionTermination `json:"textMentionTermination,omitempty"` + OrTermination *OrTermination `json:"orTermination,omitempty"` +} + +type MaxMessageTermination struct { + MaxMessages int `json:"maxMessages"` +} + +type TextMentionTermination struct { + Text string `json:"text"` +} + +type OrTermination struct { + Conditions []OrTerminationCondition `json:"conditions"` +} + +type OrTerminationCondition struct { + MaxMessageTermination *MaxMessageTermination `json:"maxMessageTermination,omitempty"` + TextMentionTermination *TextMentionTermination `json:"textMentionTermination,omitempty"` +} + +// AutogenTeamStatus defines the observed state of AutogenTeam. +type AutogenTeamStatus struct{} + +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status + +// AutogenTeam is the Schema for the autogenteams API. +type AutogenTeam struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec AutogenTeamSpec `json:"spec,omitempty"` + Status AutogenTeamStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// AutogenTeamList contains a list of AutogenTeam. +type AutogenTeamList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []AutogenTeam `json:"items"` +} + +func init() { + SchemeBuilder.Register(&AutogenTeam{}, &AutogenTeamList{}) +} diff --git a/go/controller/api/v1alpha1/autogentool_types.go b/go/controller/api/v1alpha1/autogentool_types.go new file mode 100644 index 000000000..f22cbc420 --- /dev/null +++ b/go/controller/api/v1alpha1/autogentool_types.go @@ -0,0 +1,57 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +// AutogenToolSpec defines the desired state of AutogenTool. +type AutogenToolSpec struct { + Description string `json:"description,omitempty"` +} + +// AutogenToolStatus defines the observed state of AutogenTool. +type AutogenToolStatus struct{} + +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status + +// AutogenTool is the Schema for the autogentools API. +type AutogenTool struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec AutogenToolSpec `json:"spec,omitempty"` + Status AutogenToolStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// AutogenToolList contains a list of AutogenTool. +type AutogenToolList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []AutogenTool `json:"items"` +} + +func init() { + SchemeBuilder.Register(&AutogenTool{}, &AutogenToolList{}) +} diff --git a/go/controller/api/v1alpha1/groupversion_info.go b/go/controller/api/v1alpha1/groupversion_info.go new file mode 100644 index 000000000..530b1e190 --- /dev/null +++ b/go/controller/api/v1alpha1/groupversion_info.go @@ -0,0 +1,36 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package v1alpha1 contains API Schema definitions for the agent v1alpha1 API group. +// +kubebuilder:object:generate=true +// +groupName=agent.ai.solo.io +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // GroupVersion is group version used to register these objects. + GroupVersion = schema.GroupVersion{Group: "agent.ai.solo.io", Version: "v1alpha1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme. + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/go/controller/api/v1alpha1/zz_generated.deepcopy.go b/go/controller/api/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 000000000..8f5d7fe54 --- /dev/null +++ b/go/controller/api/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,515 @@ +//go:build !ignore_autogenerated + +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by controller-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenAgent) DeepCopyInto(out *AutogenAgent) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenAgent. +func (in *AutogenAgent) DeepCopy() *AutogenAgent { + if in == nil { + return nil + } + out := new(AutogenAgent) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AutogenAgent) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenAgentList) DeepCopyInto(out *AutogenAgentList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]AutogenAgent, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenAgentList. +func (in *AutogenAgentList) DeepCopy() *AutogenAgentList { + if in == nil { + return nil + } + out := new(AutogenAgentList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AutogenAgentList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenAgentSpec) DeepCopyInto(out *AutogenAgentSpec) { + *out = *in + if in.Tools != nil { + in, out := &in.Tools, &out.Tools + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenAgentSpec. +func (in *AutogenAgentSpec) DeepCopy() *AutogenAgentSpec { + if in == nil { + return nil + } + out := new(AutogenAgentSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenAgentStatus) DeepCopyInto(out *AutogenAgentStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenAgentStatus. +func (in *AutogenAgentStatus) DeepCopy() *AutogenAgentStatus { + if in == nil { + return nil + } + out := new(AutogenAgentStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenModelConfig) DeepCopyInto(out *AutogenModelConfig) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenModelConfig. +func (in *AutogenModelConfig) DeepCopy() *AutogenModelConfig { + if in == nil { + return nil + } + out := new(AutogenModelConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AutogenModelConfig) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenModelConfigList) DeepCopyInto(out *AutogenModelConfigList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]AutogenModelConfig, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenModelConfigList. +func (in *AutogenModelConfigList) DeepCopy() *AutogenModelConfigList { + if in == nil { + return nil + } + out := new(AutogenModelConfigList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AutogenModelConfigList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenModelConfigSpec) DeepCopyInto(out *AutogenModelConfigSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenModelConfigSpec. +func (in *AutogenModelConfigSpec) DeepCopy() *AutogenModelConfigSpec { + if in == nil { + return nil + } + out := new(AutogenModelConfigSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenModelConfigStatus) DeepCopyInto(out *AutogenModelConfigStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenModelConfigStatus. +func (in *AutogenModelConfigStatus) DeepCopy() *AutogenModelConfigStatus { + if in == nil { + return nil + } + out := new(AutogenModelConfigStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenTeam) DeepCopyInto(out *AutogenTeam) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenTeam. +func (in *AutogenTeam) DeepCopy() *AutogenTeam { + if in == nil { + return nil + } + out := new(AutogenTeam) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AutogenTeam) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenTeamList) DeepCopyInto(out *AutogenTeamList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]AutogenTeam, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenTeamList. +func (in *AutogenTeamList) DeepCopy() *AutogenTeamList { + if in == nil { + return nil + } + out := new(AutogenTeamList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AutogenTeamList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenTeamSpec) DeepCopyInto(out *AutogenTeamSpec) { + *out = *in + if in.Participants != nil { + in, out := &in.Participants, &out.Participants + *out = make([]string, len(*in)) + copy(*out, *in) + } + out.SelectorTeamConfig = in.SelectorTeamConfig + in.TerminationCondition.DeepCopyInto(&out.TerminationCondition) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenTeamSpec. +func (in *AutogenTeamSpec) DeepCopy() *AutogenTeamSpec { + if in == nil { + return nil + } + out := new(AutogenTeamSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenTeamStatus) DeepCopyInto(out *AutogenTeamStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenTeamStatus. +func (in *AutogenTeamStatus) DeepCopy() *AutogenTeamStatus { + if in == nil { + return nil + } + out := new(AutogenTeamStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenTool) DeepCopyInto(out *AutogenTool) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenTool. +func (in *AutogenTool) DeepCopy() *AutogenTool { + if in == nil { + return nil + } + out := new(AutogenTool) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AutogenTool) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenToolList) DeepCopyInto(out *AutogenToolList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]AutogenTool, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenToolList. +func (in *AutogenToolList) DeepCopy() *AutogenToolList { + if in == nil { + return nil + } + out := new(AutogenToolList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AutogenToolList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenToolSpec) DeepCopyInto(out *AutogenToolSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenToolSpec. +func (in *AutogenToolSpec) DeepCopy() *AutogenToolSpec { + if in == nil { + return nil + } + out := new(AutogenToolSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutogenToolStatus) DeepCopyInto(out *AutogenToolStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenToolStatus. +func (in *AutogenToolStatus) DeepCopy() *AutogenToolStatus { + if in == nil { + return nil + } + out := new(AutogenToolStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MaxMessageTermination) DeepCopyInto(out *MaxMessageTermination) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MaxMessageTermination. +func (in *MaxMessageTermination) DeepCopy() *MaxMessageTermination { + if in == nil { + return nil + } + out := new(MaxMessageTermination) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OrTermination) DeepCopyInto(out *OrTermination) { + *out = *in + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]OrTerminationCondition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OrTermination. +func (in *OrTermination) DeepCopy() *OrTermination { + if in == nil { + return nil + } + out := new(OrTermination) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OrTerminationCondition) DeepCopyInto(out *OrTerminationCondition) { + *out = *in + if in.MaxMessageTermination != nil { + in, out := &in.MaxMessageTermination, &out.MaxMessageTermination + *out = new(MaxMessageTermination) + **out = **in + } + if in.TextMentionTermination != nil { + in, out := &in.TextMentionTermination, &out.TextMentionTermination + *out = new(TextMentionTermination) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OrTerminationCondition. +func (in *OrTerminationCondition) DeepCopy() *OrTerminationCondition { + if in == nil { + return nil + } + out := new(OrTerminationCondition) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SelectorTeamConfig) DeepCopyInto(out *SelectorTeamConfig) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SelectorTeamConfig. +func (in *SelectorTeamConfig) DeepCopy() *SelectorTeamConfig { + if in == nil { + return nil + } + out := new(SelectorTeamConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TerminationCondition) DeepCopyInto(out *TerminationCondition) { + *out = *in + if in.MaxMessageTermination != nil { + in, out := &in.MaxMessageTermination, &out.MaxMessageTermination + *out = new(MaxMessageTermination) + **out = **in + } + if in.TextMentionTermination != nil { + in, out := &in.TextMentionTermination, &out.TextMentionTermination + *out = new(TextMentionTermination) + **out = **in + } + if in.OrTermination != nil { + in, out := &in.OrTermination, &out.OrTermination + *out = new(OrTermination) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TerminationCondition. +func (in *TerminationCondition) DeepCopy() *TerminationCondition { + if in == nil { + return nil + } + out := new(TerminationCondition) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TextMentionTermination) DeepCopyInto(out *TextMentionTermination) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TextMentionTermination. +func (in *TextMentionTermination) DeepCopy() *TextMentionTermination { + if in == nil { + return nil + } + out := new(TextMentionTermination) + in.DeepCopyInto(out) + return out +} diff --git a/go/controller/cmd/main.go b/go/controller/cmd/main.go new file mode 100644 index 000000000..187f267c3 --- /dev/null +++ b/go/controller/cmd/main.go @@ -0,0 +1,306 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "crypto/tls" + "flag" + "github.com/kagent-dev/kagent/go/autogen/api" + "github.com/kagent-dev/kagent/go/controller/internal/autogen" + "github.com/kagent-dev/kagent/go/controller/internal/utils/syncutils" + "os" + "path/filepath" + + // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) + // to ensure that exec-entrypoint and run can make use of them. + _ "k8s.io/client-go/plugin/pkg/client/auth" + + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + clientgoscheme "k8s.io/client-go/kubernetes/scheme" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/certwatcher" + "sigs.k8s.io/controller-runtime/pkg/healthz" + "sigs.k8s.io/controller-runtime/pkg/log/zap" + "sigs.k8s.io/controller-runtime/pkg/metrics/filters" + metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" + "sigs.k8s.io/controller-runtime/pkg/webhook" + + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" + "github.com/kagent-dev/kagent/go/controller/internal/controller" + // +kubebuilder:scaffold:imports +) + +var ( + scheme = runtime.NewScheme() + setupLog = ctrl.Log.WithName("setup") +) + +func init() { + utilruntime.Must(clientgoscheme.AddToScheme(scheme)) + + utilruntime.Must(agentv1alpha1.AddToScheme(scheme)) + // +kubebuilder:scaffold:scheme +} + +// nolint:gocyclo +func main() { + var metricsAddr string + var metricsCertPath, metricsCertName, metricsCertKey string + var webhookCertPath, webhookCertName, webhookCertKey string + var enableLeaderElection bool + var probeAddr string + var secureMetrics bool + var enableHTTP2 bool + var autogenStudioBaseURL string + var autogenStudioWsURL string + var tlsOpts []func(*tls.Config) + flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+ + "Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.") + flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") + flag.BoolVar(&enableLeaderElection, "leader-elect", false, + "Enable leader election for controller manager. "+ + "Enabling this will ensure there is only one active controller manager.") + flag.BoolVar(&secureMetrics, "metrics-secure", true, + "If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.") + flag.StringVar(&webhookCertPath, "webhook-cert-path", "", "The directory that contains the webhook certificate.") + flag.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt", "The name of the webhook certificate file.") + flag.StringVar(&webhookCertKey, "webhook-cert-key", "tls.key", "The name of the webhook key file.") + flag.StringVar(&metricsCertPath, "metrics-cert-path", "", + "The directory that contains the metrics server certificate.") + flag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.") + flag.StringVar(&metricsCertKey, "metrics-cert-key", "tls.key", "The name of the metrics server key file.") + flag.BoolVar(&enableHTTP2, "enable-http2", false, + "If set, HTTP/2 will be enabled for the metrics and webhook servers") + + flag.StringVar(&autogenStudioBaseURL, "autogen-base-url", "http://localhost:8081/api", "The base url of the Autogen Studio server.") + flag.StringVar(&autogenStudioWsURL, "autogen-ws-url", "ws://localhost:8081/api/ws", "The base url of the Autogen Studio websocket server.") + opts := zap.Options{ + Development: true, + } + opts.BindFlags(flag.CommandLine) + flag.Parse() + + ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) + + // if the enable-http2 flag is false (the default), http/2 should be disabled + // due to its vulnerabilities. More specifically, disabling http/2 will + // prevent from being vulnerable to the HTTP/2 Stream Cancellation and + // Rapid Reset CVEs. For more information see: + // - https://github.com/advisories/GHSA-qppj-fm5r-hxr3 + // - https://github.com/advisories/GHSA-4374-p667-p6c8 + disableHTTP2 := func(c *tls.Config) { + setupLog.Info("disabling http/2") + c.NextProtos = []string{"http/1.1"} + } + + if !enableHTTP2 { + tlsOpts = append(tlsOpts, disableHTTP2) + } + + // Create watchers for metrics and webhooks certificates + var metricsCertWatcher, webhookCertWatcher *certwatcher.CertWatcher + + // Initial webhook TLS options + webhookTLSOpts := tlsOpts + + if len(webhookCertPath) > 0 { + setupLog.Info("Initializing webhook certificate watcher using provided certificates", + "webhook-cert-path", webhookCertPath, "webhook-cert-name", webhookCertName, "webhook-cert-key", webhookCertKey) + + var err error + webhookCertWatcher, err = certwatcher.New( + filepath.Join(webhookCertPath, webhookCertName), + filepath.Join(webhookCertPath, webhookCertKey), + ) + if err != nil { + setupLog.Error(err, "Failed to initialize webhook certificate watcher") + os.Exit(1) + } + + webhookTLSOpts = append(webhookTLSOpts, func(config *tls.Config) { + config.GetCertificate = webhookCertWatcher.GetCertificate + }) + } + + webhookServer := webhook.NewServer(webhook.Options{ + TLSOpts: webhookTLSOpts, + }) + + // Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server. + // More info: + // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.0/pkg/metrics/server + // - https://book.kubebuilder.io/reference/metrics.html + metricsServerOptions := metricsserver.Options{ + BindAddress: metricsAddr, + SecureServing: secureMetrics, + TLSOpts: tlsOpts, + } + + if secureMetrics { + // FilterProvider is used to protect the metrics endpoint with authn/authz. + // These configurations ensure that only authorized users and service accounts + // can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info: + // https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.0/pkg/metrics/filters#WithAuthenticationAndAuthorization + metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization + } + + // If the certificate is not specified, controller-runtime will automatically + // generate self-signed certificates for the metrics server. While convenient for development and testing, + // this setup is not recommended for production. + // + // TODO(user): If you enable certManager, uncomment the following lines: + // - [METRICS-WITH-CERTS] at config/default/kustomization.yaml to generate and use certificates + // managed by cert-manager for the metrics server. + // - [PROMETHEUS-WITH-CERTS] at config/prometheus/kustomization.yaml for TLS certification. + if len(metricsCertPath) > 0 { + setupLog.Info("Initializing metrics certificate watcher using provided certificates", + "metrics-cert-path", metricsCertPath, "metrics-cert-name", metricsCertName, "metrics-cert-key", metricsCertKey) + + var err error + metricsCertWatcher, err = certwatcher.New( + filepath.Join(metricsCertPath, metricsCertName), + filepath.Join(metricsCertPath, metricsCertKey), + ) + if err != nil { + setupLog.Error(err, "to initialize metrics certificate watcher", "error", err) + os.Exit(1) + } + + metricsServerOptions.TLSOpts = append(metricsServerOptions.TLSOpts, func(config *tls.Config) { + config.GetCertificate = metricsCertWatcher.GetCertificate + }) + } + + mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ + Scheme: scheme, + Metrics: metricsServerOptions, + WebhookServer: webhookServer, + HealthProbeBindAddress: probeAddr, + LeaderElection: enableLeaderElection, + LeaderElectionID: "0e9f6799.ai.solo.io", + // LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily + // when the Manager ends. This requires the binary to immediately end when the + // Manager is stopped, otherwise, this setting is unsafe. Setting this significantly + // speeds up voluntary leader transitions as the new leader don't have to wait + // LeaseDuration time first. + // + // In the default scaffold provided, the program ends immediately after + // the manager stops, so would be fine to enable this option. However, + // if you are doing or is intended to do any operation such as perform cleanups + // after the manager stops then its usage might be unsafe. + // LeaderElectionReleaseOnCancel: true, + }) + if err != nil { + setupLog.Error(err, "unable to start manager") + os.Exit(1) + } + + // TODO(ilackarms): aliases for builtin autogen tools + builtinTools := syncutils.NewAtomicMap[string, string]() + builtinTools.Set("k8s-get-pod", "k8s.get_pod") + + autogenClient := api.NewClient( + autogenStudioBaseURL, + autogenStudioWsURL, + ) + + kubeClient := mgr.GetClient() + + apiTranslator := autogen.NewAutogenApiTranslator( + kubeClient, + builtinTools, + ) + + autogenReconciler := autogen.NewAutogenReconciler( + apiTranslator, + kubeClient, + autogenClient, + ) + + if err = (&controller.AutogenTeamReconciler{ + Client: kubeClient, + Scheme: mgr.GetScheme(), + Reconciler: autogenReconciler, + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "AutogenTeam") + os.Exit(1) + } + if err = (&controller.AutogenAgentReconciler{ + Client: kubeClient, + Scheme: mgr.GetScheme(), + Reconciler: autogenReconciler, + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "AutogenAgent") + os.Exit(1) + } + if err = (&controller.AutogenToolReconciler{ + Client: kubeClient, + Scheme: mgr.GetScheme(), + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "AutogenTool") + os.Exit(1) + } + if err = (&controller.AutogenModelConfigReconciler{ + Client: kubeClient, + Scheme: mgr.GetScheme(), + Reconciler: autogenReconciler, + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "AutogenModelConfig") + os.Exit(1) + } + if err = (&controller.AutogenSecretReconciler{ + Client: kubeClient, + Scheme: mgr.GetScheme(), + Reconciler: autogenReconciler, + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "AutogenSecret") + os.Exit(1) + } + // +kubebuilder:scaffold:builder + + if metricsCertWatcher != nil { + setupLog.Info("Adding metrics certificate watcher to manager") + if err := mgr.Add(metricsCertWatcher); err != nil { + setupLog.Error(err, "unable to add metrics certificate watcher to manager") + os.Exit(1) + } + } + + if webhookCertWatcher != nil { + setupLog.Info("Adding webhook certificate watcher to manager") + if err := mgr.Add(webhookCertWatcher); err != nil { + setupLog.Error(err, "unable to add webhook certificate watcher to manager") + os.Exit(1) + } + } + + if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { + setupLog.Error(err, "unable to set up health check") + os.Exit(1) + } + if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil { + setupLog.Error(err, "unable to set up ready check") + os.Exit(1) + } + + setupLog.Info("starting manager") + if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { + setupLog.Error(err, "problem running manager") + os.Exit(1) + } +} diff --git a/go/controller/config/crd/bases/agent.ai.solo.io_autogenagents.yaml b/go/controller/config/crd/bases/agent.ai.solo.io_autogenagents.yaml new file mode 100644 index 000000000..4551034f1 --- /dev/null +++ b/go/controller/config/crd/bases/agent.ai.solo.io_autogenagents.yaml @@ -0,0 +1,60 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.17.1 + name: autogenagents.agent.ai.solo.io +spec: + group: agent.ai.solo.io + names: + kind: AutogenAgent + listKind: AutogenAgentList + plural: autogenagents + singular: autogenagent + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: AutogenAgent is the Schema for the autogenagents API. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: AutogenAgentSpec defines the desired state of AutogenAgent. + properties: + description: + type: string + name: + type: string + systemMessage: + type: string + tools: + items: + type: string + type: array + type: object + status: + description: AutogenAgentStatus defines the observed state of AutogenAgent. + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/go/controller/config/crd/bases/agent.ai.solo.io_autogenmodelconfigs.yaml b/go/controller/config/crd/bases/agent.ai.solo.io_autogenmodelconfigs.yaml new file mode 100644 index 000000000..1e6b15092 --- /dev/null +++ b/go/controller/config/crd/bases/agent.ai.solo.io_autogenmodelconfigs.yaml @@ -0,0 +1,61 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.17.1 + name: autogenmodelconfigs.agent.ai.solo.io +spec: + group: agent.ai.solo.io + names: + kind: AutogenModelConfig + listKind: AutogenModelConfigList + plural: autogenmodelconfigs + singular: autogenmodelconfig + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: AutogenModelConfig is the Schema for the autogenmodelconfigs + API. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: AutogenModelConfigSpec defines the desired state of AutogenModelConfig. + properties: + apiKeySecretKey: + type: string + apiKeySecretName: + type: string + model: + type: string + required: + - apiKeySecretKey + - apiKeySecretName + - model + type: object + status: + description: AutogenModelConfigStatus defines the observed state of AutogenModelConfig. + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/go/controller/config/crd/bases/agent.ai.solo.io_autogenteams.yaml b/go/controller/config/crd/bases/agent.ai.solo.io_autogenteams.yaml new file mode 100644 index 000000000..137372181 --- /dev/null +++ b/go/controller/config/crd/bases/agent.ai.solo.io_autogenteams.yaml @@ -0,0 +1,122 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.17.1 + name: autogenteams.agent.ai.solo.io +spec: + group: agent.ai.solo.io + names: + kind: AutogenTeam + listKind: AutogenTeamList + plural: autogenteams + singular: autogenteam + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: AutogenTeam is the Schema for the autogenteams API. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: AutogenTeamSpec defines the desired state of AutogenTeam. + properties: + description: + type: string + maxTurns: + format: int64 + type: integer + participants: + items: + type: string + type: array + selectorTeamConfig: + properties: + modelConfig: + type: string + selectorPrompt: + type: string + required: + - modelConfig + - selectorPrompt + type: object + terminationCondition: + properties: + maxMessageTermination: + description: 'ONEOF: maxMessageTermination, textMentionTermination, + orTermination' + properties: + maxMessages: + type: integer + required: + - maxMessages + type: object + orTermination: + properties: + conditions: + items: + properties: + maxMessageTermination: + properties: + maxMessages: + type: integer + required: + - maxMessages + type: object + textMentionTermination: + properties: + text: + type: string + required: + - text + type: object + type: object + type: array + required: + - conditions + type: object + textMentionTermination: + properties: + text: + type: string + required: + - text + type: object + type: object + x-kubernetes-validations: + - message: There must one termination type set + rule: 1 == (self.maxMessageTermination != null?1:0) + (self.textMentionTermination + != null?1:0) + (self.orTermination != null?1:0) + required: + - description + - maxTurns + - participants + - selectorTeamConfig + - terminationCondition + type: object + status: + description: AutogenTeamStatus defines the observed state of AutogenTeam. + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/go/controller/config/crd/bases/agent.ai.solo.io_autogentools.yaml b/go/controller/config/crd/bases/agent.ai.solo.io_autogentools.yaml new file mode 100644 index 000000000..459054f12 --- /dev/null +++ b/go/controller/config/crd/bases/agent.ai.solo.io_autogentools.yaml @@ -0,0 +1,52 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.17.1 + name: autogentools.agent.ai.solo.io +spec: + group: agent.ai.solo.io + names: + kind: AutogenTool + listKind: AutogenToolList + plural: autogentools + singular: autogentool + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: AutogenTool is the Schema for the autogentools API. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: AutogenToolSpec defines the desired state of AutogenTool. + properties: + description: + type: string + type: object + status: + description: AutogenToolStatus defines the observed state of AutogenTool. + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/go/controller/config/crd/kustomization.yaml b/go/controller/config/crd/kustomization.yaml new file mode 100644 index 000000000..382bbe50b --- /dev/null +++ b/go/controller/config/crd/kustomization.yaml @@ -0,0 +1,19 @@ +# This kustomization.yaml is not intended to be run by itself, +# since it depends on service name and namespace that are out of this kustomize package. +# It should be run by config/default +resources: +- bases/agent.ai.solo.io_autogenteams.yaml +- bases/agent.ai.solo.io_autogenagents.yaml +- bases/agent.ai.solo.io_autogentools.yaml +- bases/agent.ai.solo.io_autogenmodelconfigs.yaml +# +kubebuilder:scaffold:crdkustomizeresource + +patches: +# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. +# patches here are for enabling the conversion webhook for each CRD +# +kubebuilder:scaffold:crdkustomizewebhookpatch + +# [WEBHOOK] To enable webhook, uncomment the following section +# the following config is for teaching kustomize how to do kustomization for CRDs. +#configurations: +#- kustomizeconfig.yaml diff --git a/go/controller/config/crd/kustomizeconfig.yaml b/go/controller/config/crd/kustomizeconfig.yaml new file mode 100644 index 000000000..ec5c150a9 --- /dev/null +++ b/go/controller/config/crd/kustomizeconfig.yaml @@ -0,0 +1,19 @@ +# This file is for teaching kustomize how to substitute name and namespace reference in CRD +nameReference: +- kind: Service + version: v1 + fieldSpecs: + - kind: CustomResourceDefinition + version: v1 + group: apiextensions.k8s.io + path: spec/conversion/webhook/clientConfig/service/name + +namespace: +- kind: CustomResourceDefinition + version: v1 + group: apiextensions.k8s.io + path: spec/conversion/webhook/clientConfig/service/namespace + create: false + +varReference: +- path: metadata/annotations diff --git a/go/controller/config/rbac/autogenagent_admin_role.yaml b/go/controller/config/rbac/autogenagent_admin_role.yaml new file mode 100644 index 000000000..39b05811c --- /dev/null +++ b/go/controller/config/rbac/autogenagent_admin_role.yaml @@ -0,0 +1,27 @@ +# This rule is not used by the project controller itself. +# It is provided to allow the cluster admin to help manage permissions for users. +# +# Grants full permissions ('*') over agent.ai.solo.io. +# This role is intended for users authorized to modify roles and bindings within the cluster, +# enabling them to delegate specific permissions to other users or groups as needed. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogenagent-admin-role +rules: +- apiGroups: + - agent.ai.solo.io + resources: + - autogenagents + verbs: + - '*' +- apiGroups: + - agent.ai.solo.io + resources: + - autogenagents/status + verbs: + - get diff --git a/go/controller/config/rbac/autogenagent_editor_role.yaml b/go/controller/config/rbac/autogenagent_editor_role.yaml new file mode 100644 index 000000000..26e0686d3 --- /dev/null +++ b/go/controller/config/rbac/autogenagent_editor_role.yaml @@ -0,0 +1,33 @@ +# This rule is not used by the project controller itself. +# It is provided to allow the cluster admin to help manage permissions for users. +# +# Grants permissions to create, update, and delete resources within the agent.ai.solo.io. +# This role is intended for users who need to manage these resources +# but should not control RBAC or manage permissions for others. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogenagent-editor-role +rules: +- apiGroups: + - agent.ai.solo.io + resources: + - autogenagents + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - agent.ai.solo.io + resources: + - autogenagents/status + verbs: + - get diff --git a/go/controller/config/rbac/autogenagent_viewer_role.yaml b/go/controller/config/rbac/autogenagent_viewer_role.yaml new file mode 100644 index 000000000..6b0e2942c --- /dev/null +++ b/go/controller/config/rbac/autogenagent_viewer_role.yaml @@ -0,0 +1,29 @@ +# This rule is not used by the project controller itself. +# It is provided to allow the cluster admin to help manage permissions for users. +# +# Grants read-only access to agent.ai.solo.io resources. +# This role is intended for users who need visibility into these resources +# without permissions to modify them. It is ideal for monitoring purposes and limited-access viewing. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogenagent-viewer-role +rules: +- apiGroups: + - agent.ai.solo.io + resources: + - autogenagents + verbs: + - get + - list + - watch +- apiGroups: + - agent.ai.solo.io + resources: + - autogenagents/status + verbs: + - get diff --git a/go/controller/config/rbac/autogenmodelconfig_admin_role.yaml b/go/controller/config/rbac/autogenmodelconfig_admin_role.yaml new file mode 100644 index 000000000..d5188c6c6 --- /dev/null +++ b/go/controller/config/rbac/autogenmodelconfig_admin_role.yaml @@ -0,0 +1,27 @@ +# This rule is not used by the project controller itself. +# It is provided to allow the cluster admin to help manage permissions for users. +# +# Grants full permissions ('*') over agent.ai.solo.io. +# This role is intended for users authorized to modify roles and bindings within the cluster, +# enabling them to delegate specific permissions to other users or groups as needed. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogenmodelconfig-admin-role +rules: +- apiGroups: + - agent.ai.solo.io + resources: + - autogenmodelconfigs + verbs: + - '*' +- apiGroups: + - agent.ai.solo.io + resources: + - autogenmodelconfigs/status + verbs: + - get diff --git a/go/controller/config/rbac/autogenmodelconfig_editor_role.yaml b/go/controller/config/rbac/autogenmodelconfig_editor_role.yaml new file mode 100644 index 000000000..a4493bfd8 --- /dev/null +++ b/go/controller/config/rbac/autogenmodelconfig_editor_role.yaml @@ -0,0 +1,33 @@ +# This rule is not used by the project controller itself. +# It is provided to allow the cluster admin to help manage permissions for users. +# +# Grants permissions to create, update, and delete resources within the agent.ai.solo.io. +# This role is intended for users who need to manage these resources +# but should not control RBAC or manage permissions for others. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogenmodelconfig-editor-role +rules: +- apiGroups: + - agent.ai.solo.io + resources: + - autogenmodelconfigs + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - agent.ai.solo.io + resources: + - autogenmodelconfigs/status + verbs: + - get diff --git a/go/controller/config/rbac/autogenmodelconfig_viewer_role.yaml b/go/controller/config/rbac/autogenmodelconfig_viewer_role.yaml new file mode 100644 index 000000000..c9ec0aff2 --- /dev/null +++ b/go/controller/config/rbac/autogenmodelconfig_viewer_role.yaml @@ -0,0 +1,29 @@ +# This rule is not used by the project controller itself. +# It is provided to allow the cluster admin to help manage permissions for users. +# +# Grants read-only access to agent.ai.solo.io resources. +# This role is intended for users who need visibility into these resources +# without permissions to modify them. It is ideal for monitoring purposes and limited-access viewing. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogenmodelconfig-viewer-role +rules: +- apiGroups: + - agent.ai.solo.io + resources: + - autogenmodelconfigs + verbs: + - get + - list + - watch +- apiGroups: + - agent.ai.solo.io + resources: + - autogenmodelconfigs/status + verbs: + - get diff --git a/go/controller/config/rbac/autogenteam_admin_role.yaml b/go/controller/config/rbac/autogenteam_admin_role.yaml new file mode 100644 index 000000000..58686b7ab --- /dev/null +++ b/go/controller/config/rbac/autogenteam_admin_role.yaml @@ -0,0 +1,27 @@ +# This rule is not used by the project controller itself. +# It is provided to allow the cluster admin to help manage permissions for users. +# +# Grants full permissions ('*') over agent.ai.solo.io. +# This role is intended for users authorized to modify roles and bindings within the cluster, +# enabling them to delegate specific permissions to other users or groups as needed. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogenteam-admin-role +rules: +- apiGroups: + - agent.ai.solo.io + resources: + - autogenteams + verbs: + - '*' +- apiGroups: + - agent.ai.solo.io + resources: + - autogenteams/status + verbs: + - get diff --git a/go/controller/config/rbac/autogenteam_editor_role.yaml b/go/controller/config/rbac/autogenteam_editor_role.yaml new file mode 100644 index 000000000..f65a6d380 --- /dev/null +++ b/go/controller/config/rbac/autogenteam_editor_role.yaml @@ -0,0 +1,33 @@ +# This rule is not used by the project controller itself. +# It is provided to allow the cluster admin to help manage permissions for users. +# +# Grants permissions to create, update, and delete resources within the agent.ai.solo.io. +# This role is intended for users who need to manage these resources +# but should not control RBAC or manage permissions for others. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogenteam-editor-role +rules: +- apiGroups: + - agent.ai.solo.io + resources: + - autogenteams + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - agent.ai.solo.io + resources: + - autogenteams/status + verbs: + - get diff --git a/go/controller/config/rbac/autogenteam_viewer_role.yaml b/go/controller/config/rbac/autogenteam_viewer_role.yaml new file mode 100644 index 000000000..466da56ed --- /dev/null +++ b/go/controller/config/rbac/autogenteam_viewer_role.yaml @@ -0,0 +1,29 @@ +# This rule is not used by the project controller itself. +# It is provided to allow the cluster admin to help manage permissions for users. +# +# Grants read-only access to agent.ai.solo.io resources. +# This role is intended for users who need visibility into these resources +# without permissions to modify them. It is ideal for monitoring purposes and limited-access viewing. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogenteam-viewer-role +rules: +- apiGroups: + - agent.ai.solo.io + resources: + - autogenteams + verbs: + - get + - list + - watch +- apiGroups: + - agent.ai.solo.io + resources: + - autogenteams/status + verbs: + - get diff --git a/go/controller/config/rbac/autogentool_admin_role.yaml b/go/controller/config/rbac/autogentool_admin_role.yaml new file mode 100644 index 000000000..e69485443 --- /dev/null +++ b/go/controller/config/rbac/autogentool_admin_role.yaml @@ -0,0 +1,27 @@ +# This rule is not used by the project controller itself. +# It is provided to allow the cluster admin to help manage permissions for users. +# +# Grants full permissions ('*') over agent.ai.solo.io. +# This role is intended for users authorized to modify roles and bindings within the cluster, +# enabling them to delegate specific permissions to other users or groups as needed. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogentool-admin-role +rules: +- apiGroups: + - agent.ai.solo.io + resources: + - autogentools + verbs: + - '*' +- apiGroups: + - agent.ai.solo.io + resources: + - autogentools/status + verbs: + - get diff --git a/go/controller/config/rbac/autogentool_editor_role.yaml b/go/controller/config/rbac/autogentool_editor_role.yaml new file mode 100644 index 000000000..1b6b986b3 --- /dev/null +++ b/go/controller/config/rbac/autogentool_editor_role.yaml @@ -0,0 +1,33 @@ +# This rule is not used by the project controller itself. +# It is provided to allow the cluster admin to help manage permissions for users. +# +# Grants permissions to create, update, and delete resources within the agent.ai.solo.io. +# This role is intended for users who need to manage these resources +# but should not control RBAC or manage permissions for others. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogentool-editor-role +rules: +- apiGroups: + - agent.ai.solo.io + resources: + - autogentools + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - agent.ai.solo.io + resources: + - autogentools/status + verbs: + - get diff --git a/go/controller/config/rbac/autogentool_viewer_role.yaml b/go/controller/config/rbac/autogentool_viewer_role.yaml new file mode 100644 index 000000000..7b160ebaa --- /dev/null +++ b/go/controller/config/rbac/autogentool_viewer_role.yaml @@ -0,0 +1,29 @@ +# This rule is not used by the project controller itself. +# It is provided to allow the cluster admin to help manage permissions for users. +# +# Grants read-only access to agent.ai.solo.io resources. +# This role is intended for users who need visibility into these resources +# without permissions to modify them. It is ideal for monitoring purposes and limited-access viewing. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogentool-viewer-role +rules: +- apiGroups: + - agent.ai.solo.io + resources: + - autogentools + verbs: + - get + - list + - watch +- apiGroups: + - agent.ai.solo.io + resources: + - autogentools/status + verbs: + - get diff --git a/go/controller/config/rbac/kustomization.yaml b/go/controller/config/rbac/kustomization.yaml new file mode 100644 index 000000000..0254d86a9 --- /dev/null +++ b/go/controller/config/rbac/kustomization.yaml @@ -0,0 +1,37 @@ +resources: +# All RBAC will be applied under this service account in +# the deployment namespace. You may comment out this resource +# if your manager will use a service account that exists at +# runtime. Be sure to update RoleBinding and ClusterRoleBinding +# subjects if changing service account names. +- service_account.yaml +- role.yaml +- role_binding.yaml +- leader_election_role.yaml +- leader_election_role_binding.yaml +# The following RBAC configurations are used to protect +# the metrics endpoint with authn/authz. These configurations +# ensure that only authorized users and service accounts +# can access the metrics endpoint. Comment the following +# permissions if you want to disable this protection. +# More info: https://book.kubebuilder.io/reference/metrics.html +- metrics_auth_role.yaml +- metrics_auth_role_binding.yaml +- metrics_reader_role.yaml +# For each CRD, "Admin", "Editor" and "Viewer" roles are scaffolded by +# default, aiding admins in cluster management. Those roles are +# not used by the {{ .ProjectName }} itself. You can comment the following lines +# if you do not want those helpers be installed with your Project. +- autogenmodelconfig_admin_role.yaml +- autogenmodelconfig_editor_role.yaml +- autogenmodelconfig_viewer_role.yaml +- autogentool_admin_role.yaml +- autogentool_editor_role.yaml +- autogentool_viewer_role.yaml +- autogenagent_admin_role.yaml +- autogenagent_editor_role.yaml +- autogenagent_viewer_role.yaml +- autogenteam_admin_role.yaml +- autogenteam_editor_role.yaml +- autogenteam_viewer_role.yaml + diff --git a/go/controller/config/rbac/leader_election_role.yaml b/go/controller/config/rbac/leader_election_role.yaml new file mode 100644 index 000000000..445f02706 --- /dev/null +++ b/go/controller/config/rbac/leader_election_role.yaml @@ -0,0 +1,40 @@ +# permissions to do leader election. +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: leader-election-role +rules: +- apiGroups: + - "" + resources: + - configmaps + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - "" + resources: + - events + verbs: + - create + - patch diff --git a/go/controller/config/rbac/leader_election_role_binding.yaml b/go/controller/config/rbac/leader_election_role_binding.yaml new file mode 100644 index 000000000..aed609dd5 --- /dev/null +++ b/go/controller/config/rbac/leader_election_role_binding.yaml @@ -0,0 +1,15 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: leader-election-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: leader-election-role +subjects: +- kind: ServiceAccount + name: controller-manager + namespace: system diff --git a/go/controller/config/rbac/metrics_auth_role.yaml b/go/controller/config/rbac/metrics_auth_role.yaml new file mode 100644 index 000000000..32d2e4ec6 --- /dev/null +++ b/go/controller/config/rbac/metrics_auth_role.yaml @@ -0,0 +1,17 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: metrics-auth-role +rules: +- apiGroups: + - authentication.k8s.io + resources: + - tokenreviews + verbs: + - create +- apiGroups: + - authorization.k8s.io + resources: + - subjectaccessreviews + verbs: + - create diff --git a/go/controller/config/rbac/metrics_auth_role_binding.yaml b/go/controller/config/rbac/metrics_auth_role_binding.yaml new file mode 100644 index 000000000..e775d67ff --- /dev/null +++ b/go/controller/config/rbac/metrics_auth_role_binding.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: metrics-auth-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: metrics-auth-role +subjects: +- kind: ServiceAccount + name: controller-manager + namespace: system diff --git a/go/controller/config/rbac/metrics_reader_role.yaml b/go/controller/config/rbac/metrics_reader_role.yaml new file mode 100644 index 000000000..51a75db47 --- /dev/null +++ b/go/controller/config/rbac/metrics_reader_role.yaml @@ -0,0 +1,9 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: metrics-reader +rules: +- nonResourceURLs: + - "/metrics" + verbs: + - get diff --git a/go/controller/config/rbac/role.yaml b/go/controller/config/rbac/role.yaml new file mode 100644 index 000000000..26e2f74a7 --- /dev/null +++ b/go/controller/config/rbac/role.yaml @@ -0,0 +1,41 @@ +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: manager-role +rules: +- apiGroups: + - agent.ai.solo.io + resources: + - autogenagents + - autogenmodelconfigs + - autogenteams + - autogentools + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - agent.ai.solo.io + resources: + - autogenagents/finalizers + - autogenmodelconfigs/finalizers + - autogenteams/finalizers + - autogentools/finalizers + verbs: + - update +- apiGroups: + - agent.ai.solo.io + resources: + - autogenagents/status + - autogenmodelconfigs/status + - autogenteams/status + - autogentools/status + verbs: + - get + - patch + - update diff --git a/go/controller/config/rbac/role_binding.yaml b/go/controller/config/rbac/role_binding.yaml new file mode 100644 index 000000000..0953223d7 --- /dev/null +++ b/go/controller/config/rbac/role_binding.yaml @@ -0,0 +1,15 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: manager-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: manager-role +subjects: +- kind: ServiceAccount + name: controller-manager + namespace: system diff --git a/go/controller/config/rbac/service_account.yaml b/go/controller/config/rbac/service_account.yaml new file mode 100644 index 000000000..834b343e6 --- /dev/null +++ b/go/controller/config/rbac/service_account.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: controller-manager + namespace: system diff --git a/go/controller/config/samples/agent_v1alpha1_autogenagent.yaml b/go/controller/config/samples/agent_v1alpha1_autogenagent.yaml new file mode 100644 index 000000000..250c89810 --- /dev/null +++ b/go/controller/config/samples/agent_v1alpha1_autogenagent.yaml @@ -0,0 +1,9 @@ +apiVersion: agent.ai.solo.io/v1alpha1 +kind: AutogenAgent +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogenagent-sample +spec: + # TODO(user): Add fields here diff --git a/go/controller/config/samples/agent_v1alpha1_autogenmodelconfig.yaml b/go/controller/config/samples/agent_v1alpha1_autogenmodelconfig.yaml new file mode 100644 index 000000000..04a8f268a --- /dev/null +++ b/go/controller/config/samples/agent_v1alpha1_autogenmodelconfig.yaml @@ -0,0 +1,9 @@ +apiVersion: agent.ai.solo.io/v1alpha1 +kind: AutogenModelConfig +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogenmodelconfig-sample +spec: + # TODO(user): Add fields here diff --git a/go/controller/config/samples/agent_v1alpha1_autogenteam.yaml b/go/controller/config/samples/agent_v1alpha1_autogenteam.yaml new file mode 100644 index 000000000..f53000410 --- /dev/null +++ b/go/controller/config/samples/agent_v1alpha1_autogenteam.yaml @@ -0,0 +1,9 @@ +apiVersion: agent.ai.solo.io/v1alpha1 +kind: AutogenTeam +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogenteam-sample +spec: + # TODO(user): Add fields here diff --git a/go/controller/config/samples/agent_v1alpha1_autogentool.yaml b/go/controller/config/samples/agent_v1alpha1_autogentool.yaml new file mode 100644 index 000000000..4d500713b --- /dev/null +++ b/go/controller/config/samples/agent_v1alpha1_autogentool.yaml @@ -0,0 +1,9 @@ +apiVersion: agent.ai.solo.io/v1alpha1 +kind: AutogenTool +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: autogentool-sample +spec: + # TODO(user): Add fields here diff --git a/go/controller/config/samples/kustomization.yaml b/go/controller/config/samples/kustomization.yaml new file mode 100644 index 000000000..800337ff5 --- /dev/null +++ b/go/controller/config/samples/kustomization.yaml @@ -0,0 +1,7 @@ +## Append samples of your project ## +resources: +- agent_v1alpha1_autogenteam.yaml +- agent_v1alpha1_autogenagent.yaml +- agent_v1alpha1_autogentool.yaml +- agent_v1alpha1_autogenmodelconfig.yaml +# +kubebuilder:scaffold:manifestskustomizesamples diff --git a/go/controller/hack/boilerplate.go.txt b/go/controller/hack/boilerplate.go.txt new file mode 100644 index 000000000..221dcbe0b --- /dev/null +++ b/go/controller/hack/boilerplate.go.txt @@ -0,0 +1,15 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ \ No newline at end of file diff --git a/go/controller/internal/autogen/autogen_api_translator.go b/go/controller/internal/autogen/autogen_api_translator.go new file mode 100644 index 000000000..85ff55612 --- /dev/null +++ b/go/controller/internal/autogen/autogen_api_translator.go @@ -0,0 +1,267 @@ +package autogen + +import ( + "context" + "crypto/sha256" + "encoding/binary" + "fmt" + "github.com/kagent-dev/kagent/go/autogen/api" + "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" + "github.com/kagent-dev/kagent/go/controller/internal/utils/syncutils" + v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +type AutogenApiTranslator interface { + TranslateSelectorGroupChat( + ctx context.Context, + team *v1alpha1.AutogenTeam, + ) (*api.TeamResponse, error) +} + +type autogenApiTranslator struct { + kube client.Client + + // map of tool ref to builtin function name + builtinTools syncutils.AtomicMap[string, string] +} + +func NewAutogenApiTranslator( + kube client.Client, + builtinTools syncutils.AtomicMap[string, string], +) AutogenApiTranslator { + return &autogenApiTranslator{ + kube: kube, + builtinTools: builtinTools, + } +} + +func (a *autogenApiTranslator) TranslateSelectorGroupChat( + ctx context.Context, + team *v1alpha1.AutogenTeam, +) (*api.TeamResponse, error) { + + // get model config + modelConfig := &v1alpha1.AutogenModelConfig{} + err := fetchObjKube( + ctx, + a.kube, + modelConfig, + team.Spec.SelectorTeamConfig.ModelConfig, + team.Namespace, + ) + if err != nil { + return nil, err + } + + // get model api key + modelApiKeySecret := &v1.Secret{} + err = fetchObjKube( + ctx, + a.kube, + modelApiKeySecret, + modelConfig.Spec.APIKeySecretName, + team.Namespace, + ) + if err != nil { + return nil, err + } + + if modelApiKeySecret.Data == nil { + return nil, fmt.Errorf("model api key secret data not found") + } + + modelApiKey, ok := modelApiKeySecret.Data[modelConfig.Spec.APIKeySecretKey] + if !ok { + return nil, fmt.Errorf("model api key not found") + } + + modelClient := &api.ModelComponent{ + Provider: "autogen_ext.models.openai.OpenAIChatCompletionClient", + ComponentType: "model", + Version: makePtr(1), + //ComponentVersion: 1, + Component: api.ModelConfig{ + Model: modelConfig.Spec.Model, + APIKey: makePtr(string(modelApiKey)), + }, + } + + var participants []api.AgentComponent + for _, agentName := range team.Spec.Participants { + agent := &v1alpha1.AutogenAgent{} + err := fetchObjKube( + ctx, + a.kube, + agent, + agentName, + team.Namespace, + ) + if err != nil { + return nil, err + } + + //TODO: currently only supports builtin tools + var tools []api.ToolComponent + for _, toolRef := range agent.Spec.Tools { + // fetch fn name from builtin tools + fnName, ok := a.builtinTools.Get(toolRef) + if !ok { + return nil, fmt.Errorf("builtin tool %s not found", toolRef) + } + + tool := api.ToolComponent{ + Provider: "autogen_agentchat.tools.BuiltinTool", + ComponentType: "tool", + Version: makePtr(1), + //ComponentVersion: 1, + Component: api.ToolConfig{ + FnName: fnName, + }, + } + tools = append(tools, tool) + } + + sysMsgPtr := makePtr(agent.Spec.SystemMessage) + if agent.Spec.SystemMessage == "" { + sysMsgPtr = nil + } + participant := api.AgentComponent{ + //TODO: currently only supports assistant agents + Provider: "autogen_agentchat.agents.AssistantAgent", + ComponentType: "agent", + Version: makePtr(1), + Description: makePtr(agent.Spec.Description), + //ComponentVersion: 1, + Component: api.AgentConfig{ + Name: agent.Spec.Name, + ModelClient: modelClient, + Tools: tools, + ModelContext: &api.ChatCompletionContextComponent{ + Provider: "autogen_core.model_context.UnboundedChatCompletionContext", + ComponentType: "chat_completion_context", + Version: makePtr(1), + //ComponentVersion: 1, + }, + Description: agent.Spec.Description, + // TODO(ilackarms): convert to non-ptr with omitempty? + SystemMessage: sysMsgPtr, + ReflectOnToolUse: false, + ToolCallSummaryFormat: "{result}", + }, + } + participants = append(participants, participant) + } + + terminationCondition, err := translateTerminationCondition(team.Spec.TerminationCondition) + if err != nil { + return nil, err + } + + return &api.TeamResponse{ + ID: generateIdFromString(team.Name + "-" + team.Namespace), + UserID: "guestuser@gmail.com", // always use global id + Component: api.TeamComponent{ + Provider: "autogen_agentchat.teams.SelectorGroupChat", + ComponentType: "team", + Version: 1, + ComponentVersion: 1, + Description: makePtr(team.Spec.Description), + Config: api.TeamConfig{ + Participants: participants, + ModelClient: modelClient, + TerminationCondition: terminationCondition, + SelectorPrompt: team.Spec.SelectorTeamConfig.SelectorPrompt, + AllowRepeatedSpeaker: false, + }, + }, + }, nil +} + +func makePtr[T any](v T) *T { + return &v +} + +func generateIdFromString(s string) int { + hash := sha256.Sum256([]byte(s)) + // Uses first 8 bytes + number := int(binary.BigEndian.Uint64(hash[:8])) + return number +} + +func translateTerminationCondition(terminationCondition v1alpha1.TerminationCondition) (*api.TerminationComponent, error) { + // ensure only one termination condition is set + var conditionsSet int + if terminationCondition.MaxMessageTermination != nil { + conditionsSet++ + } + if terminationCondition.TextMentionTermination != nil { + conditionsSet++ + } + if terminationCondition.OrTermination != nil { + conditionsSet++ + } + if conditionsSet != 1 { + return nil, fmt.Errorf("exactly one termination condition must be set") + } + + switch { + case terminationCondition.MaxMessageTermination != nil: + return &api.TerminationComponent{ + Provider: "autogen_agentchat.conditions.MaxMessageTermination", + ComponentType: "termination", + Version: makePtr(1), + //ComponentVersion: 1, + Component: api.TerminationConfig{ + MaxMessages: makePtr(terminationCondition.MaxMessageTermination.MaxMessages), + }, + }, nil + case terminationCondition.TextMentionTermination != nil: + return &api.TerminationComponent{ + Provider: "autogen_agentchat.conditions.TextMentionTermination", + ComponentType: "termination", + Version: makePtr(1), + //ComponentVersion: 1, + Component: api.TerminationConfig{ + Text: makePtr(terminationCondition.TextMentionTermination.Text), + }, + }, nil + case terminationCondition.OrTermination != nil: + var conditions []api.TerminationComponent + for _, c := range terminationCondition.OrTermination.Conditions { + subConditon := v1alpha1.TerminationCondition{ + MaxMessageTermination: c.MaxMessageTermination, + TextMentionTermination: c.TextMentionTermination, + } + + condition, err := translateTerminationCondition(subConditon) + if err != nil { + return nil, err + } + conditions = append(conditions, *condition) + } + return &api.TerminationComponent{ + Provider: "autogen_agentchat.conditions.OrTerminationCondition", + ComponentType: "termination", + Version: makePtr(1), + //ComponentVersion: 1, + Component: api.TerminationConfig{ + Conditions: conditions, + }, + }, nil + } + + return nil, fmt.Errorf("unsupported termination condition") +} + +func fetchObjKube(ctx context.Context, kube client.Client, obj client.Object, objName, objNamespace string) error { + err := kube.Get(ctx, types.NamespacedName{ + Name: objName, + Namespace: objNamespace, + }, obj) + if err != nil { + return err + } + return nil +} diff --git a/go/controller/internal/autogen/autogen_config_types.go b/go/controller/internal/autogen/autogen_config_types.go new file mode 100644 index 000000000..7430d7182 --- /dev/null +++ b/go/controller/internal/autogen/autogen_config_types.go @@ -0,0 +1,85 @@ +package autogen + +type SelectorGroupChat struct { + ID int `json:"id"` + UserID string `json:"user_id"` + Provider string `json:"provider"` + ComponentType string `json:"component_type"` + Version int `json:"version"` + ComponentVersion int `json:"component_version"` + Description string `json:"description"` + Config SelectorGroupChatConfig `json:"config"` +} + +type SelectorGroupChatConfig struct { + Participants []GroupChatParticipant `json:"participants"` + ModelClient ModelClient `json:"model_client"` + TerminationCondition TerminationCondition `json:"termination_condition"` + SelectorPrompt string `json:"selector_prompt"` + AllowRepeatedSpeaker bool `json:"allow_repeated_speaker"` +} + +type ModelClient struct { + Provider string `json:"provider"` + ComponentType string `json:"component_type"` + Version int `json:"version"` + ComponentVersion int `json:"component_version"` + Config ModelClientConfig `json:"config"` +} + +type GroupChatParticipant struct { + Provider string `json:"provider"` + ComponentType string `json:"component_type"` + Version int `json:"version"` + ComponentVersion int `json:"component_version"` + Config GroupChatParticipantConfig `json:"config"` +} + +type GroupChatParticipantConfig struct { + Name string `json:"name"` + ModelClient ModelClient `json:"model_client"` + Tools []GroupChatParticipantTool `json:"tools"` + ModelContext ModelContext `json:"model_context"` + Description string `json:"description"` + SystemMessage string `json:"system_message"` + ReflectOnToolUse bool `json:"reflect_on_tool_use"` + ToolCallSummaryFormat string `json:"tool_call_summary_format"` +} + +type ModelContext struct { + Provider string `json:"provider"` + ComponentType string `json:"component_type"` + Version int `json:"version"` + ComponentVersion int `json:"component_version"` +} + +type GroupChatParticipantTool struct { + Provider string `json:"provider"` + ComponentType string `json:"component_type"` + Version int `json:"version"` + ComponentVersion int `json:"component_version"` + Config GroupChatParticipantToolConfig `json:"config"` +} + +type GroupChatParticipantToolConfig struct { + FnName string `json:"fn_name"` +} + +type ModelClientConfig struct { + Model string `json:"model"` + ApiKey string `json:"api_key"` +} + +type TerminationCondition struct { + Provider string `json:"provider"` + ComponentType string `json:"component_type"` + Version int `json:"version"` + ComponentVersion int `json:"component_version"` + Config TerminationConditionConfig `json:"config"` +} + +type TerminationConditionConfig struct { + Conditions []TerminationCondition `json:"conditions,omitempty"` + Text string `json:"text,omitempty"` + MaxMessages int `json:"max_messages,omitempty"` +} diff --git a/go/controller/internal/autogen/autogen_reconciler.go b/go/controller/internal/autogen/autogen_reconciler.go new file mode 100644 index 000000000..f800b0324 --- /dev/null +++ b/go/controller/internal/autogen/autogen_reconciler.go @@ -0,0 +1,199 @@ +package autogen + +import ( + "context" + "fmt" + "github.com/kagent-dev/kagent/go/autogen/api" + "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" + "k8s.io/apimachinery/pkg/types" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +type AutogenReconciler interface { + ReconcileAutogenAgent(ctx context.Context, req ctrl.Request) error + ReconcileAutogenModelConfig(ctx context.Context, req ctrl.Request) error + ReconcileAutogenTeam(ctx context.Context, req ctrl.Request) error + ReconcileAutogenApiKeySecret(ctx context.Context, req ctrl.Request) error +} + +type autogenReconciler struct { + translator AutogenApiTranslator + + kube client.Client + autogenClient *api.Client +} + +func NewAutogenReconciler( + translator AutogenApiTranslator, + kube client.Client, + autogenClient *api.Client, +) AutogenReconciler { + return &autogenReconciler{ + translator: translator, + kube: kube, + autogenClient: autogenClient, + } +} + +func (a *autogenReconciler) ReconcileAutogenAgent(ctx context.Context, req ctrl.Request) error { + // find and reconcile all teams which use this agent + teams, err := a.findTeamsUsingAgent(ctx, req) + if err != nil { + return fmt.Errorf("failed to find teams for agent %s: %v", req.Name, err) + } + + return a.reconcileTeams(ctx, teams...) +} + +func (a *autogenReconciler) ReconcileAutogenModelConfig(ctx context.Context, req ctrl.Request) error { + teams, err := a.findTeamsUsingModel(ctx, req) + if err != nil { + return fmt.Errorf("failed to find teams for model %s: %v", req.Name, err) + } + + return a.reconcileTeams(ctx, teams...) +} + +func (a *autogenReconciler) ReconcileAutogenTeam(ctx context.Context, req ctrl.Request) error { + team := &v1alpha1.AutogenTeam{} + if err := a.kube.Get(ctx, req.NamespacedName, team); err != nil { + return fmt.Errorf("failed to get team %s: %v", req.Name, err) + } + + return a.reconcileTeams(ctx, team) +} + +func (a *autogenReconciler) ReconcileAutogenApiKeySecret(ctx context.Context, req ctrl.Request) error { + teams, err := a.findTeamsUsingApiKeySecret(ctx, req) + if err != nil { + return fmt.Errorf("failed to find teams for api key secret %s: %v", req.Name, err) + } + + return a.reconcileTeams(ctx, teams...) +} + +func (a *autogenReconciler) findTeamsUsingAgent(ctx context.Context, req ctrl.Request) ([]*v1alpha1.AutogenTeam, error) { + var teamsList v1alpha1.AutogenTeamList + if err := a.kube.List( + ctx, + &teamsList, + client.InNamespace(req.Namespace), + ); err != nil { + return nil, fmt.Errorf("failed to list teams: %v", err) + } + + var teams []*v1alpha1.AutogenTeam + appendTeamIfUsesAgent := func(team *v1alpha1.AutogenTeam) { + for _, participant := range team.Spec.Participants { + if participant == req.Name { + teams = append(teams, team) + break + } + } + } + for _, team := range teamsList.Items { + team := team + appendTeamIfUsesAgent(&team) + } + + return teams, nil +} + +func (a *autogenReconciler) reconcileTeams(ctx context.Context, teams ...*v1alpha1.AutogenTeam) error { + errs := map[types.NamespacedName]error{} + for _, team := range teams { + autogenTeam, err := a.translator.TranslateSelectorGroupChat(ctx, team) + if err != nil { + errs[types.NamespacedName{Name: team.Name, Namespace: team.Namespace}] = fmt.Errorf("failed to translate team %s: %v", team.Name, err) + continue + } + if err := a.upsertTeam(autogenTeam); err != nil { + errs[types.NamespacedName{Name: team.Name, Namespace: team.Namespace}] = fmt.Errorf("failed to upsert team %s: %v", team.Name, err) + continue + } + } + + if len(errs) > 0 { + return fmt.Errorf("failed to reconcile teams: %v", errs) + } + + return nil +} + +func (a *autogenReconciler) upsertTeam(team *api.TeamResponse) error { + return a.autogenClient.CreateTeam(team) +} + +func (a *autogenReconciler) findTeamsUsingModel(ctx context.Context, req ctrl.Request) ([]*v1alpha1.AutogenTeam, error) { + var teamsList v1alpha1.AutogenTeamList + if err := a.kube.List( + ctx, + &teamsList, + client.InNamespace(req.Namespace), + ); err != nil { + return nil, fmt.Errorf("failed to list teams: %v", err) + } + + var teams []*v1alpha1.AutogenTeam + appendTeamIfUsesModel := func(team *v1alpha1.AutogenTeam) { + if team.Spec.SelectorTeamConfig.ModelConfig == req.Name { + teams = append(teams, team) + } + } + for _, team := range teamsList.Items { + team := team + appendTeamIfUsesModel(&team) + } + + return teams, nil +} + +func (a *autogenReconciler) findTeamsUsingApiKeySecret(ctx context.Context, req ctrl.Request) ([]*v1alpha1.AutogenTeam, error) { + var modelsList v1alpha1.AutogenModelConfigList + if err := a.kube.List( + ctx, + &modelsList, + client.InNamespace(req.Namespace), + ); err != nil { + return nil, fmt.Errorf("failed to list secrets: %v", err) + } + + var models []string + appendModelIfUsesApiKeySecret := func(model v1alpha1.AutogenModelConfig) { + if model.Spec.APIKeySecretName == req.Name { + models = append(models, model.Name) + } + } + for _, model := range modelsList.Items { + appendModelIfUsesApiKeySecret(model) + } + + var teams []*v1alpha1.AutogenTeam + appendUniqueTeam := func(team *v1alpha1.AutogenTeam) { + for _, t := range teams { + if t.Name == team.Name { + return + } + } + teams = append(teams, team) + } + + for _, model := range models { + teamsUsingModel, err := a.findTeamsUsingModel(ctx, ctrl.Request{ + NamespacedName: types.NamespacedName{ + Namespace: req.Namespace, + Name: model, + }, + }) + if err != nil { + return nil, fmt.Errorf("failed to find teams for model %s: %v", model, err) + } + for _, team := range teamsUsingModel { + appendUniqueTeam(team) + } + } + + return teams, nil + +} diff --git a/go/controller/internal/autogen/autogen_suite_test.go b/go/controller/internal/autogen/autogen_suite_test.go new file mode 100644 index 000000000..67c0bed4d --- /dev/null +++ b/go/controller/internal/autogen/autogen_suite_test.go @@ -0,0 +1,13 @@ +package autogen_test + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestAutogen(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Autogen Suite") +} diff --git a/go/controller/internal/autogen/autogen_translator_test.go b/go/controller/internal/autogen/autogen_translator_test.go new file mode 100644 index 000000000..df4e0e07a --- /dev/null +++ b/go/controller/internal/autogen/autogen_translator_test.go @@ -0,0 +1,163 @@ +package autogen_test + +import ( + "context" + "github.com/kagent-dev/kagent/go/autogen/api" + "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" + "github.com/kagent-dev/kagent/go/controller/internal/autogen" + "github.com/kagent-dev/kagent/go/controller/internal/utils/syncutils" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes/scheme" + "os" + "os/exec" + "sigs.k8s.io/controller-runtime/pkg/client/fake" + "time" +) + +var ( + openaiApiKey = os.Getenv("OPENAI_API_KEY") +) + +const ( + apikeySecretKey = "api-key" +) + +var _ = Describe("AutogenClient", func() { + It("should interact with autogen server", func() { + ctx := context.Background() + + go func() { + // start autogen server + startAutogenServer(ctx) + }() + + // sleep for a while to allow autogen server to start + <-time.After(3 * time.Second) + + client := api.NewClient("http://localhost:8081/api", "ws://localhost:8081/api/ws") + + scheme := scheme.Scheme + err := v1alpha1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + kubeClient := fake.NewClientBuilder().WithScheme(scheme).Build() + + builtinTools := syncutils.NewAtomicMap[string, string]() + builtinTools.Set("k8s-get-pod", "k8s.get_pod") + + // add a team + namespace := "team-ns" + + apikeySecret := &v1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-secret", + Namespace: namespace, + }, + Data: map[string][]byte{ + apikeySecretKey: []byte(openaiApiKey), + }, + } + + modelConfig := &v1alpha1.AutogenModelConfig{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-model", + Namespace: namespace, + }, + Spec: v1alpha1.AutogenModelConfigSpec{ + Model: "gpt-4o", + APIKeySecretName: apikeySecret.Name, + APIKeySecretKey: apikeySecretKey, + }, + } + + participant1 := &v1alpha1.AutogenAgent{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-participant1", + Namespace: namespace, + }, + Spec: v1alpha1.AutogenAgentSpec{ + Name: "test-participant1", + Description: "a test participant", + SystemMessage: "You are a test participant", + Tools: nil, + }, + } + + participant2 := &v1alpha1.AutogenAgent{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-participant2", + Namespace: namespace, + }, + Spec: v1alpha1.AutogenAgentSpec{ + Name: "test-participant2", + Description: "a test participant", + SystemMessage: "You are a test participant", + Tools: nil, + }, + } + + apiTeam := &v1alpha1.AutogenTeam{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-team", + Namespace: namespace, + }, + Spec: v1alpha1.AutogenTeamSpec{ + Participants: []string{ + participant1.Name, + participant2.Name, + }, + Description: "a team that tests things", + SelectorTeamConfig: v1alpha1.SelectorTeamConfig{ + ModelConfig: modelConfig.Name, + }, + TerminationCondition: v1alpha1.TerminationCondition{ + MaxMessageTermination: &v1alpha1.MaxMessageTermination{MaxMessages: 10}, + }, + MaxTurns: 10, + }, + } + + err = kubeClient.Create(ctx, apikeySecret) + Expect(err).NotTo(HaveOccurred()) + + err = kubeClient.Create(ctx, modelConfig) + Expect(err).NotTo(HaveOccurred()) + + err = kubeClient.Create(ctx, participant1) + Expect(err).NotTo(HaveOccurred()) + + err = kubeClient.Create(ctx, participant2) + Expect(err).NotTo(HaveOccurred()) + + err = kubeClient.Create(ctx, apiTeam) + Expect(err).NotTo(HaveOccurred()) + + autogenTeam, err := autogen.NewAutogenApiTranslator(kubeClient, builtinTools).TranslateSelectorGroupChat(ctx, apiTeam) + Expect(err).NotTo(HaveOccurred()) + Expect(autogenTeam).NotTo(BeNil()) + + err = client.CreateTeam(autogenTeam) + Expect(err).NotTo(HaveOccurred()) + + list, err := client.ListTeams(autogenTeam.UserID) + Expect(err).NotTo(HaveOccurred()) + Expect(list).NotTo(BeNil()) + Expect(len(list)).To(Equal(1)) + Expect(list[0].ID).To(Equal(autogenTeam.ID)) + }) +}) + +func startAutogenServer(ctx context.Context) { + defer GinkgoRecover() + cmd := exec.CommandContext(ctx, "bash", "-c", "source .venv/bin/activate && uv run autogenstudio ui") + cmd.Dir = "../../../../python" + cmd.Stdout = GinkgoWriter + cmd.Stderr = GinkgoWriter + err := cmd.Run() + if err != nil && err.Error() != "context canceled" { + Expect(err).NotTo(HaveOccurred()) + } +} diff --git a/go/controller/internal/controller/autogenagent_controller.go b/go/controller/internal/controller/autogenagent_controller.go new file mode 100644 index 000000000..7ca026217 --- /dev/null +++ b/go/controller/internal/controller/autogenagent_controller.go @@ -0,0 +1,65 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controller + +import ( + "context" + "github.com/kagent-dev/kagent/go/controller/internal/autogen" + + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" + + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" +) + +// AutogenAgentReconciler reconciles a AutogenAgent object +type AutogenAgentReconciler struct { + client.Client + Scheme *runtime.Scheme + Reconciler autogen.AutogenReconciler +} + +// +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogenagents,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogenagents/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogenagents/finalizers,verbs=update + +// Reconcile is part of the main kubernetes reconciliation loop which aims to +// move the current state of the cluster closer to the desired state. +// TODO(user): Modify the Reconcile function to compare the state specified by +// the AutogenAgent object against the actual cluster state, and then +// perform operations to make the cluster state reflect the state specified by +// the user. +// +// For more details, check Reconcile and its Result here: +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.0/pkg/reconcile +func (r *AutogenAgentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + _ = log.FromContext(ctx) + + // TODO(user): your logic here + + return ctrl.Result{}, r.Reconciler.ReconcileAutogenAgent(ctx, req) +} + +// SetupWithManager sets up the controller with the Manager. +func (r *AutogenAgentReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&agentv1alpha1.AutogenAgent{}). + Named("autogenagent"). + Complete(r) +} diff --git a/go/controller/internal/controller/autogenagent_controller_test.go b/go/controller/internal/controller/autogenagent_controller_test.go new file mode 100644 index 000000000..ec86575f9 --- /dev/null +++ b/go/controller/internal/controller/autogenagent_controller_test.go @@ -0,0 +1,82 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controller + +import ( + "context" + + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" +) + +var _ = Describe("AutogenAgent Controller", func() { + Context("When reconciling a resource", func() { + const resourceName = "test-resource" + + ctx := context.Background() + + typeNamespacedName := types.NamespacedName{ + Name: resourceName, + Namespace: "default", // TODO(user):Modify as needed + } + autogenagent := &agentv1alpha1.AutogenAgent{} + + BeforeEach(func() { + By("creating the custom resource for the Kind AutogenAgent") + err := k8sClient.Get(ctx, typeNamespacedName, autogenagent) + if err != nil && errors.IsNotFound(err) { + resource := &agentv1alpha1.AutogenAgent{ + ObjectMeta: metav1.ObjectMeta{ + Name: resourceName, + Namespace: "default", + }, + // TODO(user): Specify other spec details if needed. + } + Expect(k8sClient.Create(ctx, resource)).To(Succeed()) + } + }) + + AfterEach(func() { + // TODO(user): Cleanup logic after each test, like removing the resource instance. + resource := &agentv1alpha1.AutogenAgent{} + err := k8sClient.Get(ctx, typeNamespacedName, resource) + Expect(err).NotTo(HaveOccurred()) + + By("Cleanup the specific resource instance AutogenAgent") + Expect(k8sClient.Delete(ctx, resource)).To(Succeed()) + }) + It("should successfully reconcile the resource", func() { + By("Reconciling the created resource") + controllerReconciler := &AutogenAgentReconciler{ + Client: k8sClient, + Scheme: k8sClient.Scheme(), + } + + _, err := controllerReconciler.Reconcile(ctx, reconcile.Request{ + NamespacedName: typeNamespacedName, + }) + Expect(err).NotTo(HaveOccurred()) + // TODO(user): Add more specific assertions depending on your controller's reconciliation logic. + // Example: If you expect a certain status condition after reconciliation, verify it here. + }) + }) +}) diff --git a/go/controller/internal/controller/autogenmodelconfig_controller.go b/go/controller/internal/controller/autogenmodelconfig_controller.go new file mode 100644 index 000000000..26379599b --- /dev/null +++ b/go/controller/internal/controller/autogenmodelconfig_controller.go @@ -0,0 +1,63 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controller + +import ( + "context" + "github.com/kagent-dev/kagent/go/controller/internal/autogen" + + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" + + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" +) + +// AutogenModelConfigReconciler reconciles a AutogenModelConfig object +type AutogenModelConfigReconciler struct { + client.Client + Scheme *runtime.Scheme + Reconciler autogen.AutogenReconciler +} + +// +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogenmodelconfigs,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogenmodelconfigs/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogenmodelconfigs/finalizers,verbs=update + +// Reconcile is part of the main kubernetes reconciliation loop which aims to +// move the current state of the cluster closer to the desired state. +// TODO(user): Modify the Reconcile function to compare the state specified by +// the AutogenModelConfig object against the actual cluster state, and then +// perform operations to make the cluster state reflect the state specified by +// the user. +// +// For more details, check Reconcile and its Result here: +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.0/pkg/reconcile +func (r *AutogenModelConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + _ = log.FromContext(ctx) + + return ctrl.Result{}, r.Reconciler.ReconcileAutogenModelConfig(ctx, req) +} + +// SetupWithManager sets up the controller with the Manager. +func (r *AutogenModelConfigReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&agentv1alpha1.AutogenModelConfig{}). + Named("autogenmodelconfig"). + Complete(r) +} diff --git a/go/controller/internal/controller/autogenmodelconfig_controller_test.go b/go/controller/internal/controller/autogenmodelconfig_controller_test.go new file mode 100644 index 000000000..d57ec2f51 --- /dev/null +++ b/go/controller/internal/controller/autogenmodelconfig_controller_test.go @@ -0,0 +1,82 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controller + +import ( + "context" + + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" +) + +var _ = Describe("AutogenModelConfig Controller", func() { + Context("When reconciling a resource", func() { + const resourceName = "test-resource" + + ctx := context.Background() + + typeNamespacedName := types.NamespacedName{ + Name: resourceName, + Namespace: "default", // TODO(user):Modify as needed + } + autogenmodelconfig := &agentv1alpha1.AutogenModelConfig{} + + BeforeEach(func() { + By("creating the custom resource for the Kind AutogenModelConfig") + err := k8sClient.Get(ctx, typeNamespacedName, autogenmodelconfig) + if err != nil && errors.IsNotFound(err) { + resource := &agentv1alpha1.AutogenModelConfig{ + ObjectMeta: metav1.ObjectMeta{ + Name: resourceName, + Namespace: "default", + }, + // TODO(user): Specify other spec details if needed. + } + Expect(k8sClient.Create(ctx, resource)).To(Succeed()) + } + }) + + AfterEach(func() { + // TODO(user): Cleanup logic after each test, like removing the resource instance. + resource := &agentv1alpha1.AutogenModelConfig{} + err := k8sClient.Get(ctx, typeNamespacedName, resource) + Expect(err).NotTo(HaveOccurred()) + + By("Cleanup the specific resource instance AutogenModelConfig") + Expect(k8sClient.Delete(ctx, resource)).To(Succeed()) + }) + It("should successfully reconcile the resource", func() { + By("Reconciling the created resource") + controllerReconciler := &AutogenModelConfigReconciler{ + Client: k8sClient, + Scheme: k8sClient.Scheme(), + } + + _, err := controllerReconciler.Reconcile(ctx, reconcile.Request{ + NamespacedName: typeNamespacedName, + }) + Expect(err).NotTo(HaveOccurred()) + // TODO(user): Add more specific assertions depending on your controller's reconciliation logic. + // Example: If you expect a certain status condition after reconciliation, verify it here. + }) + }) +}) diff --git a/go/controller/internal/controller/autogensecret_controller.go b/go/controller/internal/controller/autogensecret_controller.go new file mode 100644 index 000000000..d1ec42981 --- /dev/null +++ b/go/controller/internal/controller/autogensecret_controller.go @@ -0,0 +1,62 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controller + +import ( + "context" + "github.com/kagent-dev/kagent/go/controller/internal/autogen" + v1 "k8s.io/api/core/v1" + + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" +) + +// AutogenModelConfigReconciler reconciles a Secret object which contains a model config +type AutogenSecretReconciler struct { + client.Client + Scheme *runtime.Scheme + Reconciler autogen.AutogenReconciler +} + +// +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogenmodelconfigs,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogenmodelconfigs/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogenmodelconfigs/finalizers,verbs=update + +// Reconcile is part of the main kubernetes reconciliation loop which aims to +// move the current state of the cluster closer to the desired state. +// TODO(user): Modify the Reconcile function to compare the state specified by +// the AutogenModelConfig object against the actual cluster state, and then +// perform operations to make the cluster state reflect the state specified by +// the user. +// +// For more details, check Reconcile and its Result here: +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.0/pkg/reconcile +func (r *AutogenSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + _ = log.FromContext(ctx) + + return ctrl.Result{}, r.Reconciler.ReconcileAutogenApiKeySecret(ctx, req) +} + +// SetupWithManager sets up the controller with the Manager. +func (r *AutogenSecretReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&v1.Secret{}). + Named("autogenapikeysecret"). + Complete(r) +} diff --git a/go/controller/internal/controller/autogenteam_controller.go b/go/controller/internal/controller/autogenteam_controller.go new file mode 100644 index 000000000..6fd88ecea --- /dev/null +++ b/go/controller/internal/controller/autogenteam_controller.go @@ -0,0 +1,63 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controller + +import ( + "context" + "github.com/kagent-dev/kagent/go/controller/internal/autogen" + + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" + + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" +) + +// AutogenTeamReconciler reconciles a AutogenTeam object +type AutogenTeamReconciler struct { + client.Client + Scheme *runtime.Scheme + Reconciler autogen.AutogenReconciler +} + +// +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogenteams,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogenteams/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogenteams/finalizers,verbs=update + +// Reconcile is part of the main kubernetes reconciliation loop which aims to +// move the current state of the cluster closer to the desired state. +// TODO(user): Modify the Reconcile function to compare the state specified by +// the AutogenTeam object against the actual cluster state, and then +// perform operations to make the cluster state reflect the state specified by +// the user. +// +// For more details, check Reconcile and its Result here: +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.0/pkg/reconcile +func (r *AutogenTeamReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + _ = log.FromContext(ctx) + + return ctrl.Result{}, r.Reconciler.ReconcileAutogenTeam(ctx, req) +} + +// SetupWithManager sets up the controller with the Manager. +func (r *AutogenTeamReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&agentv1alpha1.AutogenTeam{}). + Named("autogenteam"). + Complete(r) +} diff --git a/go/controller/internal/controller/autogenteam_controller_test.go b/go/controller/internal/controller/autogenteam_controller_test.go new file mode 100644 index 000000000..861f18e88 --- /dev/null +++ b/go/controller/internal/controller/autogenteam_controller_test.go @@ -0,0 +1,82 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controller + +import ( + "context" + + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" +) + +var _ = Describe("AutogenTeam Controller", func() { + Context("When reconciling a resource", func() { + const resourceName = "test-resource" + + ctx := context.Background() + + typeNamespacedName := types.NamespacedName{ + Name: resourceName, + Namespace: "default", // TODO(user):Modify as needed + } + autogenteam := &agentv1alpha1.AutogenTeam{} + + BeforeEach(func() { + By("creating the custom resource for the Kind AutogenTeam") + err := k8sClient.Get(ctx, typeNamespacedName, autogenteam) + if err != nil && errors.IsNotFound(err) { + resource := &agentv1alpha1.AutogenTeam{ + ObjectMeta: metav1.ObjectMeta{ + Name: resourceName, + Namespace: "default", + }, + // TODO(user): Specify other spec details if needed. + } + Expect(k8sClient.Create(ctx, resource)).To(Succeed()) + } + }) + + AfterEach(func() { + // TODO(user): Cleanup logic after each test, like removing the resource instance. + resource := &agentv1alpha1.AutogenTeam{} + err := k8sClient.Get(ctx, typeNamespacedName, resource) + Expect(err).NotTo(HaveOccurred()) + + By("Cleanup the specific resource instance AutogenTeam") + Expect(k8sClient.Delete(ctx, resource)).To(Succeed()) + }) + It("should successfully reconcile the resource", func() { + By("Reconciling the created resource") + controllerReconciler := &AutogenTeamReconciler{ + Client: k8sClient, + Scheme: k8sClient.Scheme(), + } + + _, err := controllerReconciler.Reconcile(ctx, reconcile.Request{ + NamespacedName: typeNamespacedName, + }) + Expect(err).NotTo(HaveOccurred()) + // TODO(user): Add more specific assertions depending on your controller's reconciliation logic. + // Example: If you expect a certain status condition after reconciliation, verify it here. + }) + }) +}) diff --git a/go/controller/internal/controller/autogentool_controller.go b/go/controller/internal/controller/autogentool_controller.go new file mode 100644 index 000000000..3f1d3664e --- /dev/null +++ b/go/controller/internal/controller/autogentool_controller.go @@ -0,0 +1,63 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controller + +import ( + "context" + + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" + + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" +) + +// AutogenToolReconciler reconciles a AutogenTool object +type AutogenToolReconciler struct { + client.Client + Scheme *runtime.Scheme +} + +// +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogentools,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogentools/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogentools/finalizers,verbs=update + +// Reconcile is part of the main kubernetes reconciliation loop which aims to +// move the current state of the cluster closer to the desired state. +// TODO(user): Modify the Reconcile function to compare the state specified by +// the AutogenTool object against the actual cluster state, and then +// perform operations to make the cluster state reflect the state specified by +// the user. +// +// For more details, check Reconcile and its Result here: +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.0/pkg/reconcile +func (r *AutogenToolReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + _ = log.FromContext(ctx) + + // TODO(user): your logic here + + return ctrl.Result{}, nil +} + +// SetupWithManager sets up the controller with the Manager. +func (r *AutogenToolReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&agentv1alpha1.AutogenTool{}). + Named("autogentool"). + Complete(r) +} diff --git a/go/controller/internal/controller/autogentool_controller_test.go b/go/controller/internal/controller/autogentool_controller_test.go new file mode 100644 index 000000000..5d5d50dd2 --- /dev/null +++ b/go/controller/internal/controller/autogentool_controller_test.go @@ -0,0 +1,82 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controller + +import ( + "context" + + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" +) + +var _ = Describe("AutogenTool Controller", func() { + Context("When reconciling a resource", func() { + const resourceName = "test-resource" + + ctx := context.Background() + + typeNamespacedName := types.NamespacedName{ + Name: resourceName, + Namespace: "default", // TODO(user):Modify as needed + } + autogentool := &agentv1alpha1.AutogenTool{} + + BeforeEach(func() { + By("creating the custom resource for the Kind AutogenTool") + err := k8sClient.Get(ctx, typeNamespacedName, autogentool) + if err != nil && errors.IsNotFound(err) { + resource := &agentv1alpha1.AutogenTool{ + ObjectMeta: metav1.ObjectMeta{ + Name: resourceName, + Namespace: "default", + }, + // TODO(user): Specify other spec details if needed. + } + Expect(k8sClient.Create(ctx, resource)).To(Succeed()) + } + }) + + AfterEach(func() { + // TODO(user): Cleanup logic after each test, like removing the resource instance. + resource := &agentv1alpha1.AutogenTool{} + err := k8sClient.Get(ctx, typeNamespacedName, resource) + Expect(err).NotTo(HaveOccurred()) + + By("Cleanup the specific resource instance AutogenTool") + Expect(k8sClient.Delete(ctx, resource)).To(Succeed()) + }) + It("should successfully reconcile the resource", func() { + By("Reconciling the created resource") + controllerReconciler := &AutogenToolReconciler{ + Client: k8sClient, + Scheme: k8sClient.Scheme(), + } + + _, err := controllerReconciler.Reconcile(ctx, reconcile.Request{ + NamespacedName: typeNamespacedName, + }) + Expect(err).NotTo(HaveOccurred()) + // TODO(user): Add more specific assertions depending on your controller's reconciliation logic. + // Example: If you expect a certain status condition after reconciliation, verify it here. + }) + }) +}) diff --git a/go/controller/internal/controller/suite_test.go b/go/controller/internal/controller/suite_test.go new file mode 100644 index 000000000..c4b8c270c --- /dev/null +++ b/go/controller/internal/controller/suite_test.go @@ -0,0 +1,113 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controller + +import ( + "context" + "os" + "path/filepath" + "testing" + + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/envtest" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/log/zap" + + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" + // +kubebuilder:scaffold:imports +) + +// These tests use Ginkgo (BDD-style Go testing framework). Refer to +// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. + +var ( + ctx context.Context + cancel context.CancelFunc + testEnv *envtest.Environment + cfg *rest.Config + k8sClient client.Client +) + +func TestControllers(t *testing.T) { + RegisterFailHandler(Fail) + + RunSpecs(t, "Controller Suite") +} + +var _ = BeforeSuite(func() { + logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) + + ctx, cancel = context.WithCancel(context.TODO()) + + var err error + err = agentv1alpha1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + + By("bootstrapping test environment") + testEnv = &envtest.Environment{ + CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, + ErrorIfCRDPathMissing: true, + } + + // Retrieve the first found binary directory to allow running tests from IDEs + if getFirstFoundEnvTestBinaryDir() != "" { + testEnv.BinaryAssetsDirectory = getFirstFoundEnvTestBinaryDir() + } + + // cfg is defined in this file globally. + cfg, err = testEnv.Start() + Expect(err).NotTo(HaveOccurred()) + Expect(cfg).NotTo(BeNil()) + + k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) + Expect(err).NotTo(HaveOccurred()) + Expect(k8sClient).NotTo(BeNil()) +}) + +var _ = AfterSuite(func() { + By("tearing down the test environment") + cancel() + err := testEnv.Stop() + Expect(err).NotTo(HaveOccurred()) +}) + +// getFirstFoundEnvTestBinaryDir locates the first binary in the specified path. +// ENVTEST-based tests depend on specific binaries, usually located in paths set by +// controller-runtime. When running tests directly (e.g., via an IDE) without using +// Makefile targets, the 'BinaryAssetsDirectory' must be explicitly configured. +// +// This function streamlines the process by finding the required binaries, similar to +// setting the 'KUBEBUILDER_ASSETS' environment variable. To ensure the binaries are +// properly set up, run 'make setup-envtest' beforehand. +func getFirstFoundEnvTestBinaryDir() string { + basePath := filepath.Join("..", "..", "bin", "k8s") + entries, err := os.ReadDir(basePath) + if err != nil { + logf.Log.Error(err, "Failed to read directory", "path", basePath) + return "" + } + for _, entry := range entries { + if entry.IsDir() { + return filepath.Join(basePath, entry.Name()) + } + } + return "" +} diff --git a/go/controller/internal/utils/syncutils/sync_utils.go b/go/controller/internal/utils/syncutils/sync_utils.go new file mode 100644 index 000000000..8edc10ac6 --- /dev/null +++ b/go/controller/internal/utils/syncutils/sync_utils.go @@ -0,0 +1,159 @@ +package syncutils + +import ( + "sync" + + "golang.org/x/exp/maps" +) + +// atomicMap is a generic map type that is safe for concurrent access. +// It can be used as any normal map would. +type atomicMap[K comparable, V any] struct { + m map[K]V + lock sync.RWMutex +} + +type AtomicMap[K comparable, V any] interface { + Get(key K) (V, bool) + Set(key K, val V) + Delete(key K) (V, bool) + Filter(filterFunc func(key K, value V) bool) []K + Range(fn func(key K, value V)) + Length() int + Has(key K) bool + Keys() []K + Update(key K, updateFn func(val V) V) +} + +func NewAtomicMap[K comparable, V any]() AtomicMap[K, V] { + return &atomicMap[K, V]{ + m: make(map[K]V), + } +} + +// Get the value for the given key in a thread safe manner. +func (a *atomicMap[K, V]) Get(key K) (V, bool) { + if a == nil { + var val V + return val, false + } + a.lock.RLock() + defer a.lock.RUnlock() + if a.m == nil { + var val V + return val, false + } + val, ok := a.m[key] + return val, ok +} + +// Set the value for the given key in a thread safe manner. +func (a *atomicMap[K, V]) Set(key K, val V) { + a.lock.Lock() + defer a.lock.Unlock() + a.m[key] = val +} + +// Delete the value for the given key in a thread safe manner. +// If a value is present it will also return it +func (a *atomicMap[K, V]) Delete(key K) (V, bool) { + var ( + val V + ok bool + ) + + if a == nil { + return val, false + } + if val, ok = a.Get(key); !ok { + return val, ok + } + a.lock.Lock() + defer a.lock.Unlock() + delete(a.m, key) + return val, true +} + +// Return a filtered list of keys, does NOT modify original atomicMap +func (a *atomicMap[K, V]) Filter(filterFunc func(key K, value V) bool) []K { + if a == nil { + return []K{} + } + a.lock.Lock() + defer a.lock.Unlock() + var matchedKeys []K + if a.m == nil { + return []K{} + } + for k, v := range a.m { + if filterFunc(k, v) { + matchedKeys = append(matchedKeys, k) + } + } + return matchedKeys +} + +func (a *atomicMap[K, V]) Range(fn func(key K, value V)) { + if a == nil { + return + } + a.lock.Lock() + defer a.lock.Unlock() + + if a.m == nil { + return + } + + for k, v := range a.m { + fn(k, v) + } +} + +// Get atomicMap length +func (a *atomicMap[K, V]) Length() int { + if a == nil { + return 0 + } + a.lock.RLock() + defer a.lock.RUnlock() + if a.m == nil { + return 0 + } + return len(a.m) +} + +func (a *atomicMap[K, V]) Has(key K) bool { + if a == nil { + return false + } + a.lock.RLock() + defer a.lock.RUnlock() + if a.m == nil { + return false + } + _, contained := a.m[key] + return contained +} + +func (a *atomicMap[K, V]) Keys() []K { + if a == nil { + return []K{} + } + a.lock.RLock() + defer a.lock.RUnlock() + if a.m == nil { + return []K{} + } + return maps.Keys(a.m) +} + +// Update will pass the current value for the given key to the updateFn which should return a value +// that will be set as the new value for the given key. Useful when multiple routines +// need to read and write to a key as a single atomic operation. +// atomicMap must be initialized before calling Update in multiple goroutines +func (a *atomicMap[K, V]) Update(key K, updateFn func(val V) V) { + a.lock.Lock() + defer a.lock.Unlock() + val := a.m[key] + a.m[key] = updateFn(val) +} diff --git a/go/go.mod b/go/go.mod new file mode 100644 index 000000000..590eb9a10 --- /dev/null +++ b/go/go.mod @@ -0,0 +1,98 @@ +module github.com/kagent-dev/kagent/go + +go 1.23.5 + +require ( + github.com/onsi/ginkgo/v2 v2.21.0 + github.com/onsi/gomega v1.35.1 + golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 + k8s.io/api v0.32.0 + k8s.io/apimachinery v0.32.0 + k8s.io/client-go v0.32.0 + sigs.k8s.io/controller-runtime v0.20.0 +) + +require ( + cel.dev/expr v0.18.0 // indirect + github.com/antlr4-go/antlr/v4 v4.13.0 // indirect + github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect + github.com/beorn7/perks v1.0.1 // indirect + github.com/blang/semver/v4 v4.0.0 // indirect + github.com/cenkalti/backoff/v4 v4.3.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/emicklei/go-restful/v3 v3.11.0 // indirect + github.com/evanphx/json-patch/v5 v5.9.0 // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/fxamacker/cbor/v2 v2.7.0 // indirect + github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-logr/zapr v1.3.0 // indirect + github.com/go-openapi/jsonpointer v0.21.0 // indirect + github.com/go-openapi/jsonreference v0.20.2 // indirect + github.com/go-openapi/swag v0.23.0 // indirect + github.com/go-task/slim-sprig/v3 v3.0.0 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/protobuf v1.5.4 // indirect + github.com/google/btree v1.1.3 // indirect + github.com/google/cel-go v0.22.0 // indirect + github.com/google/gnostic-models v0.6.8 // indirect + github.com/google/go-cmp v0.6.0 // indirect + github.com/google/gofuzz v1.2.0 // indirect + github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/mailru/easyjson v0.7.7 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/prometheus/client_golang v1.19.1 // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/common v0.55.0 // indirect + github.com/prometheus/procfs v0.15.1 // indirect + github.com/spf13/cobra v1.8.1 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/stoewer/go-strcase v1.3.0 // indirect + github.com/x448/float16 v0.8.4 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect + go.opentelemetry.io/otel v1.28.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 // indirect + go.opentelemetry.io/otel/metric v1.28.0 // indirect + go.opentelemetry.io/otel/sdk v1.28.0 // indirect + go.opentelemetry.io/otel/trace v1.28.0 // indirect + go.opentelemetry.io/proto/otlp v1.3.1 // indirect + go.uber.org/multierr v1.11.0 // indirect + go.uber.org/zap v1.27.0 // indirect + golang.org/x/net v0.30.0 // indirect + golang.org/x/oauth2 v0.23.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/term v0.25.0 // indirect + golang.org/x/text v0.19.0 // indirect + golang.org/x/time v0.7.0 // indirect + golang.org/x/tools v0.26.0 // indirect + gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 // indirect + google.golang.org/grpc v1.65.0 // indirect + google.golang.org/protobuf v1.35.1 // indirect + gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect + gopkg.in/inf.v0 v0.9.1 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + k8s.io/apiextensions-apiserver v0.32.0 // indirect + k8s.io/apiserver v0.32.0 // indirect + k8s.io/component-base v0.32.0 // indirect + k8s.io/klog/v2 v2.130.1 // indirect + k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect + k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect + sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0 // indirect + sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect + sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect + sigs.k8s.io/yaml v1.4.0 // indirect +) diff --git a/go/go.sum b/go/go.sum new file mode 100644 index 000000000..725163760 --- /dev/null +++ b/go/go.sum @@ -0,0 +1,247 @@ +cel.dev/expr v0.18.0 h1:CJ6drgk+Hf96lkLikr4rFf19WrU0BOWEihyZnI2TAzo= +cel.dev/expr v0.18.0/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw= +github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI= +github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g= +github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA= +github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= +github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= +github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= +github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= +github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8P3k= +github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= +github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= +github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= +github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ= +github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg= +github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= +github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= +github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= +github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= +github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= +github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= +github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= +github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= +github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg= +github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= +github.com/google/cel-go v0.22.0 h1:b3FJZxpiv1vTMo2/5RDUqAHPxkT8mmMfJIrq1llbf7g= +github.com/google/cel-go v0.22.0/go.mod h1:BuznPXXfQDpXKWQ9sPW3TzlAJN5zzFe+i9tIs0yC4s8= +github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= +github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= +github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgYQBbFN4U4JNXUNYpxael3UzMyo= +github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM= +github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo= +github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4= +github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= +github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc= +github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs= +github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= +github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 h1:4K4tsIXefpVJtvA/8srF4V4y0akAoPHkIslgAkjixJA= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0/go.mod h1:jjdQuTGVsXV4vSs+CJ2qYDeDPf9yIJV23qlIzBm73Vg= +go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo= +go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 h1:3Q/xZUyC1BBkualc9ROb4G8qkH90LXEIICcs5zv1OYY= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0/go.mod h1:s75jGIWA9OfCMzF0xr+ZgfrB5FEbbV7UuYo32ahUiFI= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 h1:qFffATk0X+HD+f1Z8lswGiOQYKHRlzfmdJm0wEaVrFA= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0/go.mod h1:MOiCmryaYtc+V0Ei+Tx9o5S1ZjA7kzLucuVuyzBZloQ= +go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q= +go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s= +go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE= +go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg= +go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g= +go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI= +go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0= +go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= +golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= +golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= +golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= +golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ= +golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= +golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw= +gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY= +google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 h1:YcyjlL1PRr2Q17/I0dPk2JmYS5CDXfcdb2Z3YRioEbw= +google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7/go.mod h1:OCdP9MfskevB/rbYvHTsXTtKC+3bHWajPdoKgjcYkfo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 h1:2035KHhUv+EpyB+hWgJnaWKJOdX1E95w2S8Rr4uWKTs= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= +google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4= +gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M= +gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= +gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +k8s.io/api v0.32.0 h1:OL9JpbvAU5ny9ga2fb24X8H6xQlVp+aJMFlgtQjR9CE= +k8s.io/api v0.32.0/go.mod h1:4LEwHZEf6Q/cG96F3dqR965sYOfmPM7rq81BLgsE0p0= +k8s.io/apiextensions-apiserver v0.32.0 h1:S0Xlqt51qzzqjKPxfgX1xh4HBZE+p8KKBq+k2SWNOE0= +k8s.io/apiextensions-apiserver v0.32.0/go.mod h1:86hblMvN5yxMvZrZFX2OhIHAuFIMJIZ19bTvzkP+Fmw= +k8s.io/apimachinery v0.32.0 h1:cFSE7N3rmEEtv4ei5X6DaJPHHX0C+upp+v5lVPiEwpg= +k8s.io/apimachinery v0.32.0/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE= +k8s.io/apiserver v0.32.0 h1:VJ89ZvQZ8p1sLeiWdRJpRD6oLozNZD2+qVSLi+ft5Qs= +k8s.io/apiserver v0.32.0/go.mod h1:HFh+dM1/BE/Hm4bS4nTXHVfN6Z6tFIZPi649n83b4Ag= +k8s.io/client-go v0.32.0 h1:DimtMcnN/JIKZcrSrstiwvvZvLjG0aSxy8PxN8IChp8= +k8s.io/client-go v0.32.0/go.mod h1:boDWvdM1Drk4NJj/VddSLnx59X3OPgwrOo0vGbtq9+8= +k8s.io/component-base v0.32.0 h1:d6cWHZkCiiep41ObYQS6IcgzOUQUNpywm39KVYaUqzU= +k8s.io/component-base v0.32.0/go.mod h1:JLG2W5TUxUu5uDyKiH2R/7NnxJo1HlPoRIIbVLkK5eM= +k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= +k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= +k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f h1:GA7//TjRY9yWGy1poLzYYJJ4JRdzg3+O6e8I+e+8T5Y= +k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f/go.mod h1:R/HEjbvWI0qdfb8viZUeVZm0X6IZnxAydC7YU42CMw4= +k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 h1:M3sRQVHv7vB20Xc2ybTt7ODCeFj6JSWYFzOFnYeS6Ro= +k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0 h1:CPT0ExVicCzcpeN4baWEV2ko2Z/AsiZgEdwgcfwLgMo= +sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw= +sigs.k8s.io/controller-runtime v0.20.0 h1:jjkMo29xEXH+02Md9qaVXfEIaMESSpy3TBWPrsfQkQs= +sigs.k8s.io/controller-runtime v0.20.0/go.mod h1:BrP3w158MwvB3ZbNpaAcIKkHQ7YGpYnzpoSTZ8E14WU= +sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8= +sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3/go.mod h1:18nIHnGi6636UCz6m8i4DhaJ65T6EruyzmoQqI2BVDo= +sigs.k8s.io/structured-merge-diff/v4 v4.4.2 h1:MdmvkGuXi/8io6ixD5wud3vOLwc1rj0aNqRlpuvjmwA= +sigs.k8s.io/structured-merge-diff/v4 v4.4.2/go.mod h1:N8f93tFZh9U6vpxwRArLiikrE5/2tiu1w1AGfACIGE4= +sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= +sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=