From 069ff7887229de39c2188fb125084652fff04b8c Mon Sep 17 00:00:00 2001 From: Scott Weiss Date: Mon, 27 Jan 2025 12:43:08 -0500 Subject: [PATCH 01/12] kubebuilder init --- controller/.devcontainer/devcontainer.json | 25 ++ controller/.devcontainer/post-install.sh | 23 ++ controller/.dockerignore | 3 + controller/.github/workflows/lint.yml | 23 ++ controller/.github/workflows/test-e2e.yml | 35 ++ controller/.github/workflows/test.yml | 23 ++ controller/.gitignore | 27 ++ controller/.golangci.yml | 47 +++ controller/Dockerfile | 33 ++ controller/Makefile | 225 ++++++++++++ controller/PROJECT | 38 ++ controller/README.md | 135 ++++++- controller/api/v1alpha1/autogenagent_types.go | 64 ++++ controller/api/v1alpha1/autogenteam_types.go | 64 ++++ controller/api/v1alpha1/autogentool_types.go | 64 ++++ controller/api/v1alpha1/groupversion_info.go | 36 ++ .../api/v1alpha1/zz_generated.deepcopy.go | 292 +++++++++++++++ controller/cmd/main.go | 258 ++++++++++++++ controller/config/crd/kustomization.yaml | 18 + controller/config/crd/kustomizeconfig.yaml | 19 + .../default/cert_metrics_manager_patch.yaml | 30 ++ controller/config/default/kustomization.yaml | 212 +++++++++++ .../config/default/manager_metrics_patch.yaml | 4 + .../config/default/metrics_service.yaml | 18 + controller/config/manager/kustomization.yaml | 2 + controller/config/manager/manager.yaml | 98 +++++ .../network-policy/allow-metrics-traffic.yaml | 27 ++ .../config/network-policy/kustomization.yaml | 2 + .../config/prometheus/kustomization.yaml | 11 + controller/config/prometheus/monitor.yaml | 27 ++ .../config/prometheus/monitor_tls_patch.yaml | 22 ++ .../config/rbac/autogenagent_admin_role.yaml | 27 ++ .../config/rbac/autogenagent_editor_role.yaml | 33 ++ .../config/rbac/autogenagent_viewer_role.yaml | 29 ++ .../config/rbac/autogenteam_admin_role.yaml | 27 ++ .../config/rbac/autogenteam_editor_role.yaml | 33 ++ .../config/rbac/autogenteam_viewer_role.yaml | 29 ++ .../config/rbac/autogentool_admin_role.yaml | 27 ++ .../config/rbac/autogentool_editor_role.yaml | 33 ++ .../config/rbac/autogentool_viewer_role.yaml | 29 ++ controller/config/rbac/kustomization.yaml | 34 ++ .../config/rbac/leader_election_role.yaml | 40 +++ .../rbac/leader_election_role_binding.yaml | 15 + controller/config/rbac/metrics_auth_role.yaml | 17 + .../rbac/metrics_auth_role_binding.yaml | 12 + .../config/rbac/metrics_reader_role.yaml | 9 + controller/config/rbac/role.yaml | 11 + controller/config/rbac/role_binding.yaml | 15 + controller/config/rbac/service_account.yaml | 8 + .../samples/agent_v1alpha1_autogenagent.yaml | 9 + .../samples/agent_v1alpha1_autogenteam.yaml | 9 + .../samples/agent_v1alpha1_autogentool.yaml | 9 + controller/config/samples/kustomization.yaml | 6 + controller/go.mod | 95 +++++ controller/go.sum | 247 +++++++++++++ controller/hack/boilerplate.go.txt | 15 + .../controller/autogenagent_controller.go | 63 ++++ .../autogenagent_controller_test.go | 84 +++++ .../controller/autogenteam_controller.go | 63 ++++ .../controller/autogenteam_controller_test.go | 84 +++++ .../controller/autogentool_controller.go | 63 ++++ .../controller/autogentool_controller_test.go | 84 +++++ controller/internal/controller/suite_test.go | 116 ++++++ controller/test/e2e/e2e_suite_test.go | 110 ++++++ controller/test/e2e/e2e_test.go | 334 ++++++++++++++++++ controller/test/utils/utils.go | 251 +++++++++++++ 66 files changed, 3973 insertions(+), 2 deletions(-) create mode 100644 controller/.devcontainer/devcontainer.json create mode 100644 controller/.devcontainer/post-install.sh create mode 100644 controller/.dockerignore create mode 100644 controller/.github/workflows/lint.yml create mode 100644 controller/.github/workflows/test-e2e.yml create mode 100644 controller/.github/workflows/test.yml create mode 100644 controller/.gitignore create mode 100644 controller/.golangci.yml create mode 100644 controller/Dockerfile create mode 100644 controller/Makefile create mode 100644 controller/PROJECT create mode 100644 controller/api/v1alpha1/autogenagent_types.go create mode 100644 controller/api/v1alpha1/autogenteam_types.go create mode 100644 controller/api/v1alpha1/autogentool_types.go create mode 100644 controller/api/v1alpha1/groupversion_info.go create mode 100644 controller/api/v1alpha1/zz_generated.deepcopy.go create mode 100644 controller/cmd/main.go create mode 100644 controller/config/crd/kustomization.yaml create mode 100644 controller/config/crd/kustomizeconfig.yaml create mode 100644 controller/config/default/cert_metrics_manager_patch.yaml create mode 100644 controller/config/default/kustomization.yaml create mode 100644 controller/config/default/manager_metrics_patch.yaml create mode 100644 controller/config/default/metrics_service.yaml create mode 100644 controller/config/manager/kustomization.yaml create mode 100644 controller/config/manager/manager.yaml create mode 100644 controller/config/network-policy/allow-metrics-traffic.yaml create mode 100644 controller/config/network-policy/kustomization.yaml create mode 100644 controller/config/prometheus/kustomization.yaml create mode 100644 controller/config/prometheus/monitor.yaml create mode 100644 controller/config/prometheus/monitor_tls_patch.yaml create mode 100644 controller/config/rbac/autogenagent_admin_role.yaml create mode 100644 controller/config/rbac/autogenagent_editor_role.yaml create mode 100644 controller/config/rbac/autogenagent_viewer_role.yaml create mode 100644 controller/config/rbac/autogenteam_admin_role.yaml create mode 100644 controller/config/rbac/autogenteam_editor_role.yaml create mode 100644 controller/config/rbac/autogenteam_viewer_role.yaml create mode 100644 controller/config/rbac/autogentool_admin_role.yaml create mode 100644 controller/config/rbac/autogentool_editor_role.yaml create mode 100644 controller/config/rbac/autogentool_viewer_role.yaml create mode 100644 controller/config/rbac/kustomization.yaml create mode 100644 controller/config/rbac/leader_election_role.yaml create mode 100644 controller/config/rbac/leader_election_role_binding.yaml create mode 100644 controller/config/rbac/metrics_auth_role.yaml create mode 100644 controller/config/rbac/metrics_auth_role_binding.yaml create mode 100644 controller/config/rbac/metrics_reader_role.yaml create mode 100644 controller/config/rbac/role.yaml create mode 100644 controller/config/rbac/role_binding.yaml create mode 100644 controller/config/rbac/service_account.yaml create mode 100644 controller/config/samples/agent_v1alpha1_autogenagent.yaml create mode 100644 controller/config/samples/agent_v1alpha1_autogenteam.yaml create mode 100644 controller/config/samples/agent_v1alpha1_autogentool.yaml create mode 100644 controller/config/samples/kustomization.yaml create mode 100644 controller/go.sum create mode 100644 controller/hack/boilerplate.go.txt create mode 100644 controller/internal/controller/autogenagent_controller.go create mode 100644 controller/internal/controller/autogenagent_controller_test.go create mode 100644 controller/internal/controller/autogenteam_controller.go create mode 100644 controller/internal/controller/autogenteam_controller_test.go create mode 100644 controller/internal/controller/autogentool_controller.go create mode 100644 controller/internal/controller/autogentool_controller_test.go create mode 100644 controller/internal/controller/suite_test.go create mode 100644 controller/test/e2e/e2e_suite_test.go create mode 100644 controller/test/e2e/e2e_test.go create mode 100644 controller/test/utils/utils.go diff --git a/controller/.devcontainer/devcontainer.json b/controller/.devcontainer/devcontainer.json new file mode 100644 index 000000000..0e0eed213 --- /dev/null +++ b/controller/.devcontainer/devcontainer.json @@ -0,0 +1,25 @@ +{ + "name": "Kubebuilder DevContainer", + "image": "docker.io/golang:1.23", + "features": { + "ghcr.io/devcontainers/features/docker-in-docker:2": {}, + "ghcr.io/devcontainers/features/git:1": {} + }, + + "runArgs": ["--network=host"], + + "customizations": { + "vscode": { + "settings": { + "terminal.integrated.shell.linux": "/bin/bash" + }, + "extensions": [ + "ms-kubernetes-tools.vscode-kubernetes-tools", + "ms-azuretools.vscode-docker" + ] + } + }, + + "onCreateCommand": "bash .devcontainer/post-install.sh" +} + diff --git a/controller/.devcontainer/post-install.sh b/controller/.devcontainer/post-install.sh new file mode 100644 index 000000000..265c43ee8 --- /dev/null +++ b/controller/.devcontainer/post-install.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -x + +curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64 +chmod +x ./kind +mv ./kind /usr/local/bin/kind + +curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64 +chmod +x kubebuilder +mv kubebuilder /usr/local/bin/ + +KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt) +curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl" +chmod +x kubectl +mv kubectl /usr/local/bin/kubectl + +docker network create -d=bridge --subnet=172.19.0.0/24 kind + +kind version +kubebuilder version +docker --version +go version +kubectl version --client diff --git a/controller/.dockerignore b/controller/.dockerignore new file mode 100644 index 000000000..a3aab7af7 --- /dev/null +++ b/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/controller/.github/workflows/lint.yml b/controller/.github/workflows/lint.yml new file mode 100644 index 000000000..4951e3316 --- /dev/null +++ b/controller/.github/workflows/lint.yml @@ -0,0 +1,23 @@ +name: Lint + +on: + push: + pull_request: + +jobs: + lint: + name: Run on Ubuntu + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Run linter + uses: golangci/golangci-lint-action@v6 + with: + version: v1.63.4 diff --git a/controller/.github/workflows/test-e2e.yml b/controller/.github/workflows/test-e2e.yml new file mode 100644 index 000000000..b2eda8c3d --- /dev/null +++ b/controller/.github/workflows/test-e2e.yml @@ -0,0 +1,35 @@ +name: E2E Tests + +on: + push: + pull_request: + +jobs: + test-e2e: + name: Run on Ubuntu + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Install the latest version of kind + run: | + curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64 + chmod +x ./kind + sudo mv ./kind /usr/local/bin/kind + + - name: Verify kind installation + run: kind version + + - name: Create kind cluster + run: kind create cluster + + - name: Running Test e2e + run: | + go mod tidy + make test-e2e diff --git a/controller/.github/workflows/test.yml b/controller/.github/workflows/test.yml new file mode 100644 index 000000000..fc2e80d30 --- /dev/null +++ b/controller/.github/workflows/test.yml @@ -0,0 +1,23 @@ +name: Tests + +on: + push: + pull_request: + +jobs: + test: + name: Run on Ubuntu + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Running Tests + run: | + go mod tidy + make test diff --git a/controller/.gitignore b/controller/.gitignore new file mode 100644 index 000000000..ada68ff08 --- /dev/null +++ b/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/controller/.golangci.yml b/controller/.golangci.yml new file mode 100644 index 000000000..6b2974623 --- /dev/null +++ b/controller/.golangci.yml @@ -0,0 +1,47 @@ +run: + timeout: 5m + allow-parallel-runners: true + +issues: + # don't skip warning about doc comments + # don't exclude the default set of lint + exclude-use-default: false + # restore some of the defaults + # (fill in the rest as needed) + exclude-rules: + - path: "api/*" + linters: + - lll + - path: "internal/*" + linters: + - dupl + - lll +linters: + disable-all: true + enable: + - dupl + - errcheck + - copyloopvar + - ginkgolinter + - goconst + - gocyclo + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - prealloc + - revive + - staticcheck + - typecheck + - unconvert + - unparam + - unused + +linters-settings: + revive: + rules: + - name: comment-spacings diff --git a/controller/Dockerfile b/controller/Dockerfile new file mode 100644 index 000000000..348b8372c --- /dev/null +++ b/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/controller/Makefile b/controller/Makefile new file mode 100644 index 000000000..600010cd3 --- /dev/null +++ b/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/controller/PROJECT b/controller/PROJECT new file mode 100644 index 000000000..98cdd42bb --- /dev/null +++ b/controller/PROJECT @@ -0,0 +1,38 @@ +# 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: ai.solo.io/kagent +resources: +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: ai.solo.io + group: agent + kind: AutogenTeam + path: ai.solo.io/kagent/api/v1alpha1 + version: v1alpha1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: ai.solo.io + group: agent + kind: AutogenAgent + path: ai.solo.io/kagent/api/v1alpha1 + version: v1alpha1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: ai.solo.io + group: agent + kind: AutogenTool + path: ai.solo.io/kagent/api/v1alpha1 + version: v1alpha1 +version: "3" diff --git a/controller/README.md b/controller/README.md index d94ffdd22..be1747612 100644 --- a/controller/README.md +++ b/controller/README.md @@ -1,3 +1,134 @@ -# Controller +# controller +// TODO(user): Add simple overview of use/purpose -Fill me in. \ No newline at end of file +## 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/controller/api/v1alpha1/autogenagent_types.go b/controller/api/v1alpha1/autogenagent_types.go new file mode 100644 index 000000000..adfd914ab --- /dev/null +++ b/controller/api/v1alpha1/autogenagent_types.go @@ -0,0 +1,64 @@ +/* +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 { + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + // Important: Run "make" to regenerate code after modifying this file + + // Foo is an example field of AutogenAgent. Edit autogenagent_types.go to remove/update + Foo string `json:"foo,omitempty"` +} + +// AutogenAgentStatus defines the observed state of AutogenAgent. +type AutogenAgentStatus struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + // Important: Run "make" to regenerate code after modifying this file +} + +// +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/controller/api/v1alpha1/autogenteam_types.go b/controller/api/v1alpha1/autogenteam_types.go new file mode 100644 index 000000000..4e3b3fe2d --- /dev/null +++ b/controller/api/v1alpha1/autogenteam_types.go @@ -0,0 +1,64 @@ +/* +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 { + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + // Important: Run "make" to regenerate code after modifying this file + + // Foo is an example field of AutogenTeam. Edit autogenteam_types.go to remove/update + Foo string `json:"foo,omitempty"` +} + +// AutogenTeamStatus defines the observed state of AutogenTeam. +type AutogenTeamStatus struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + // Important: Run "make" to regenerate code after modifying this file +} + +// +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/controller/api/v1alpha1/autogentool_types.go b/controller/api/v1alpha1/autogentool_types.go new file mode 100644 index 000000000..442fde57e --- /dev/null +++ b/controller/api/v1alpha1/autogentool_types.go @@ -0,0 +1,64 @@ +/* +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 { + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + // Important: Run "make" to regenerate code after modifying this file + + // Foo is an example field of AutogenTool. Edit autogentool_types.go to remove/update + Foo string `json:"foo,omitempty"` +} + +// AutogenToolStatus defines the observed state of AutogenTool. +type AutogenToolStatus struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + // Important: Run "make" to regenerate code after modifying this file +} + +// +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/controller/api/v1alpha1/groupversion_info.go b/controller/api/v1alpha1/groupversion_info.go new file mode 100644 index 000000000..530b1e190 --- /dev/null +++ b/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/controller/api/v1alpha1/zz_generated.deepcopy.go b/controller/api/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 000000000..dc13f8813 --- /dev/null +++ b/controller/api/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,292 @@ +//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) + out.Spec = in.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 +} + +// 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 *AutogenTeam) DeepCopyInto(out *AutogenTeam) { + *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 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 +} + +// 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 +} diff --git a/controller/cmd/main.go b/controller/cmd/main.go new file mode 100644 index 000000000..f330f8eb1 --- /dev/null +++ b/controller/cmd/main.go @@ -0,0 +1,258 @@ +/* +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" + "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 "ai.solo.io/kagent/api/v1alpha1" + "ai.solo.io/kagent/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 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") + 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) + } + + if err = (&controller.AutogenTeamReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "AutogenTeam") + os.Exit(1) + } + if err = (&controller.AutogenAgentReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "AutogenAgent") + os.Exit(1) + } + if err = (&controller.AutogenToolReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "AutogenTool") + 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/controller/config/crd/kustomization.yaml b/controller/config/crd/kustomization.yaml new file mode 100644 index 000000000..60e44f8c5 --- /dev/null +++ b/controller/config/crd/kustomization.yaml @@ -0,0 +1,18 @@ +# 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 +# +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/controller/config/crd/kustomizeconfig.yaml b/controller/config/crd/kustomizeconfig.yaml new file mode 100644 index 000000000..ec5c150a9 --- /dev/null +++ b/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/controller/config/default/cert_metrics_manager_patch.yaml b/controller/config/default/cert_metrics_manager_patch.yaml new file mode 100644 index 000000000..d97501553 --- /dev/null +++ b/controller/config/default/cert_metrics_manager_patch.yaml @@ -0,0 +1,30 @@ +# This patch adds the args, volumes, and ports to allow the manager to use the metrics-server certs. + +# Add the volumeMount for the metrics-server certs +- op: add + path: /spec/template/spec/containers/0/volumeMounts/- + value: + mountPath: /tmp/k8s-metrics-server/metrics-certs + name: metrics-certs + readOnly: true + +# Add the --metrics-cert-path argument for the metrics server +- op: add + path: /spec/template/spec/containers/0/args/- + value: --metrics-cert-path=/tmp/k8s-metrics-server/metrics-certs + +# Add the metrics-server certs volume configuration +- op: add + path: /spec/template/spec/volumes/- + value: + name: metrics-certs + secret: + secretName: metrics-server-cert + optional: false + items: + - key: ca.crt + path: ca.crt + - key: tls.crt + path: tls.crt + - key: tls.key + path: tls.key diff --git a/controller/config/default/kustomization.yaml b/controller/config/default/kustomization.yaml new file mode 100644 index 000000000..d2898df5b --- /dev/null +++ b/controller/config/default/kustomization.yaml @@ -0,0 +1,212 @@ +# Adds namespace to all resources. +namespace: controller-system + +# Value of this field is prepended to the +# names of all resources, e.g. a deployment named +# "wordpress" becomes "alices-wordpress". +# Note that it should also match with the prefix (text before '-') of the namespace +# field above. +namePrefix: controller- + +# Labels to add to all resources and selectors. +#labels: +#- includeSelectors: true +# pairs: +# someName: someValue + +resources: +- ../crd +- ../rbac +- ../manager +# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in +# crd/kustomization.yaml +#- ../webhook +# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required. +#- ../certmanager +# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. +#- ../prometheus +# [METRICS] Expose the controller manager metrics service. +- metrics_service.yaml +# [NETWORK POLICY] Protect the /metrics endpoint and Webhook Server with NetworkPolicy. +# Only Pod(s) running a namespace labeled with 'metrics: enabled' will be able to gather the metrics. +# Only CR(s) which requires webhooks and are applied on namespaces labeled with 'webhooks: enabled' will +# be able to communicate with the Webhook Server. +#- ../network-policy + +# Uncomment the patches line if you enable Metrics +patches: +# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443. +# More info: https://book.kubebuilder.io/reference/metrics +- path: manager_metrics_patch.yaml + target: + kind: Deployment + +# Uncomment the patches line if you enable Metrics and CertManager +# [METRICS-WITH-CERTS] To enable metrics protected with certManager, uncomment the following line. +# This patch will protect the metrics with certManager self-signed certs. +#- path: cert_metrics_manager_patch.yaml +# target: +# kind: Deployment + +# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in +# crd/kustomization.yaml +#- path: manager_webhook_patch.yaml +# target: +# kind: Deployment + +# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix. +# Uncomment the following replacements to add the cert-manager CA injection annotations +#replacements: +# - source: # Uncomment the following block to enable certificates for metrics +# kind: Service +# version: v1 +# name: controller-manager-metrics-service +# fieldPath: metadata.name +# targets: +# - select: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: metrics-certs +# fieldPaths: +# - spec.dnsNames.0 +# - spec.dnsNames.1 +# options: +# delimiter: '.' +# index: 0 +# create: true +# +# - source: +# kind: Service +# version: v1 +# name: controller-manager-metrics-service +# fieldPath: metadata.namespace +# targets: +# - select: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: metrics-certs +# fieldPaths: +# - spec.dnsNames.0 +# - spec.dnsNames.1 +# options: +# delimiter: '.' +# index: 1 +# create: true +# +# - source: # Uncomment the following block if you have any webhook +# kind: Service +# version: v1 +# name: webhook-service +# fieldPath: .metadata.name # Name of the service +# targets: +# - select: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert +# fieldPaths: +# - .spec.dnsNames.0 +# - .spec.dnsNames.1 +# options: +# delimiter: '.' +# index: 0 +# create: true +# - source: +# kind: Service +# version: v1 +# name: webhook-service +# fieldPath: .metadata.namespace # Namespace of the service +# targets: +# - select: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert +# fieldPaths: +# - .spec.dnsNames.0 +# - .spec.dnsNames.1 +# options: +# delimiter: '.' +# index: 1 +# create: true +# +# - source: # Uncomment the following block if you have a ValidatingWebhook (--programmatic-validation) +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert # This name should match the one in certificate.yaml +# fieldPath: .metadata.namespace # Namespace of the certificate CR +# targets: +# - select: +# kind: ValidatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 0 +# create: true +# - source: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert +# fieldPath: .metadata.name +# targets: +# - select: +# kind: ValidatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 1 +# create: true +# +# - source: # Uncomment the following block if you have a DefaultingWebhook (--defaulting ) +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert +# fieldPath: .metadata.namespace # Namespace of the certificate CR +# targets: +# - select: +# kind: MutatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 0 +# create: true +# - source: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert +# fieldPath: .metadata.name +# targets: +# - select: +# kind: MutatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 1 +# create: true +# +# - source: # Uncomment the following block if you have a ConversionWebhook (--conversion) +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert +# fieldPath: .metadata.namespace # Namespace of the certificate CR +# targets: # Do not remove or uncomment the following scaffold marker; required to generate code for target CRD. +# +kubebuilder:scaffold:crdkustomizecainjectionns +# - source: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert +# fieldPath: .metadata.name +# targets: # Do not remove or uncomment the following scaffold marker; required to generate code for target CRD. +# +kubebuilder:scaffold:crdkustomizecainjectionname diff --git a/controller/config/default/manager_metrics_patch.yaml b/controller/config/default/manager_metrics_patch.yaml new file mode 100644 index 000000000..2aaef6536 --- /dev/null +++ b/controller/config/default/manager_metrics_patch.yaml @@ -0,0 +1,4 @@ +# This patch adds the args to allow exposing the metrics endpoint using HTTPS +- op: add + path: /spec/template/spec/containers/0/args/0 + value: --metrics-bind-address=:8443 diff --git a/controller/config/default/metrics_service.yaml b/controller/config/default/metrics_service.yaml new file mode 100644 index 000000000..188643018 --- /dev/null +++ b/controller/config/default/metrics_service.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + control-plane: controller-manager + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: controller-manager-metrics-service + namespace: system +spec: + ports: + - name: https + port: 8443 + protocol: TCP + targetPort: 8443 + selector: + control-plane: controller-manager + app.kubernetes.io/name: controller diff --git a/controller/config/manager/kustomization.yaml b/controller/config/manager/kustomization.yaml new file mode 100644 index 000000000..5c5f0b84c --- /dev/null +++ b/controller/config/manager/kustomization.yaml @@ -0,0 +1,2 @@ +resources: +- manager.yaml diff --git a/controller/config/manager/manager.yaml b/controller/config/manager/manager.yaml new file mode 100644 index 000000000..99d9c4628 --- /dev/null +++ b/controller/config/manager/manager.yaml @@ -0,0 +1,98 @@ +apiVersion: v1 +kind: Namespace +metadata: + labels: + control-plane: controller-manager + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: system +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: controller-manager + namespace: system + labels: + control-plane: controller-manager + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize +spec: + selector: + matchLabels: + control-plane: controller-manager + app.kubernetes.io/name: controller + replicas: 1 + template: + metadata: + annotations: + kubectl.kubernetes.io/default-container: manager + labels: + control-plane: controller-manager + app.kubernetes.io/name: controller + spec: + # TODO(user): Uncomment the following code to configure the nodeAffinity expression + # according to the platforms which are supported by your solution. + # It is considered best practice to support multiple architectures. You can + # build your manager image using the makefile target docker-buildx. + # affinity: + # nodeAffinity: + # requiredDuringSchedulingIgnoredDuringExecution: + # nodeSelectorTerms: + # - matchExpressions: + # - key: kubernetes.io/arch + # operator: In + # values: + # - amd64 + # - arm64 + # - ppc64le + # - s390x + # - key: kubernetes.io/os + # operator: In + # values: + # - linux + securityContext: + # Projects are configured by default to adhere to the "restricted" Pod Security Standards. + # This ensures that deployments meet the highest security requirements for Kubernetes. + # For more details, see: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted + runAsNonRoot: true + seccompProfile: + type: RuntimeDefault + containers: + - command: + - /manager + args: + - --leader-elect + - --health-probe-bind-address=:8081 + image: controller:latest + name: manager + ports: [] + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - "ALL" + livenessProbe: + httpGet: + path: /healthz + port: 8081 + initialDelaySeconds: 15 + periodSeconds: 20 + readinessProbe: + httpGet: + path: /readyz + port: 8081 + initialDelaySeconds: 5 + periodSeconds: 10 + # TODO(user): Configure the resources accordingly based on the project requirements. + # More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ + resources: + limits: + cpu: 500m + memory: 128Mi + requests: + cpu: 10m + memory: 64Mi + volumeMounts: [] + volumes: [] + serviceAccountName: controller-manager + terminationGracePeriodSeconds: 10 diff --git a/controller/config/network-policy/allow-metrics-traffic.yaml b/controller/config/network-policy/allow-metrics-traffic.yaml new file mode 100644 index 000000000..5043e4212 --- /dev/null +++ b/controller/config/network-policy/allow-metrics-traffic.yaml @@ -0,0 +1,27 @@ +# This NetworkPolicy allows ingress traffic +# with Pods running on namespaces labeled with 'metrics: enabled'. Only Pods on those +# namespaces are able to gather data from the metrics endpoint. +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: allow-metrics-traffic + namespace: system +spec: + podSelector: + matchLabels: + control-plane: controller-manager + app.kubernetes.io/name: controller + policyTypes: + - Ingress + ingress: + # This allows ingress traffic from any namespace with the label metrics: enabled + - from: + - namespaceSelector: + matchLabels: + metrics: enabled # Only from namespaces with this label + ports: + - port: 8443 + protocol: TCP diff --git a/controller/config/network-policy/kustomization.yaml b/controller/config/network-policy/kustomization.yaml new file mode 100644 index 000000000..ec0fb5e57 --- /dev/null +++ b/controller/config/network-policy/kustomization.yaml @@ -0,0 +1,2 @@ +resources: +- allow-metrics-traffic.yaml diff --git a/controller/config/prometheus/kustomization.yaml b/controller/config/prometheus/kustomization.yaml new file mode 100644 index 000000000..fdc5481b1 --- /dev/null +++ b/controller/config/prometheus/kustomization.yaml @@ -0,0 +1,11 @@ +resources: +- monitor.yaml + +# [PROMETHEUS-WITH-CERTS] The following patch configures the ServiceMonitor in ../prometheus +# to securely reference certificates created and managed by cert-manager. +# Additionally, ensure that you uncomment the [METRICS WITH CERTMANAGER] patch under config/default/kustomization.yaml +# to mount the "metrics-server-cert" secret in the Manager Deployment. +#patches: +# - path: monitor_tls_patch.yaml +# target: +# kind: ServiceMonitor diff --git a/controller/config/prometheus/monitor.yaml b/controller/config/prometheus/monitor.yaml new file mode 100644 index 000000000..041c99b9f --- /dev/null +++ b/controller/config/prometheus/monitor.yaml @@ -0,0 +1,27 @@ +# Prometheus Monitor Service (Metrics) +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + labels: + control-plane: controller-manager + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: controller-manager-metrics-monitor + namespace: system +spec: + endpoints: + - path: /metrics + port: https # Ensure this is the name of the port that exposes HTTPS metrics + scheme: https + bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + tlsConfig: + # TODO(user): The option insecureSkipVerify: true is not recommended for production since it disables + # certificate verification, exposing the system to potential man-in-the-middle attacks. + # For production environments, it is recommended to use cert-manager for automatic TLS certificate management. + # To apply this configuration, enable cert-manager and use the patch located at config/prometheus/servicemonitor_tls_patch.yaml, + # which securely references the certificate from the 'metrics-server-cert' secret. + insecureSkipVerify: true + selector: + matchLabels: + control-plane: controller-manager + app.kubernetes.io/name: controller diff --git a/controller/config/prometheus/monitor_tls_patch.yaml b/controller/config/prometheus/monitor_tls_patch.yaml new file mode 100644 index 000000000..e824dd0ff --- /dev/null +++ b/controller/config/prometheus/monitor_tls_patch.yaml @@ -0,0 +1,22 @@ +# Patch for Prometheus ServiceMonitor to enable secure TLS configuration +# using certificates managed by cert-manager +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: controller-manager-metrics-monitor + namespace: system +spec: + endpoints: + - tlsConfig: + insecureSkipVerify: false + ca: + secret: + name: metrics-server-cert + key: ca.crt + cert: + secret: + name: metrics-server-cert + key: tls.crt + keySecret: + name: metrics-server-cert + key: tls.key diff --git a/controller/config/rbac/autogenagent_admin_role.yaml b/controller/config/rbac/autogenagent_admin_role.yaml new file mode 100644 index 000000000..39b05811c --- /dev/null +++ b/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/controller/config/rbac/autogenagent_editor_role.yaml b/controller/config/rbac/autogenagent_editor_role.yaml new file mode 100644 index 000000000..26e0686d3 --- /dev/null +++ b/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/controller/config/rbac/autogenagent_viewer_role.yaml b/controller/config/rbac/autogenagent_viewer_role.yaml new file mode 100644 index 000000000..6b0e2942c --- /dev/null +++ b/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/controller/config/rbac/autogenteam_admin_role.yaml b/controller/config/rbac/autogenteam_admin_role.yaml new file mode 100644 index 000000000..58686b7ab --- /dev/null +++ b/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/controller/config/rbac/autogenteam_editor_role.yaml b/controller/config/rbac/autogenteam_editor_role.yaml new file mode 100644 index 000000000..f65a6d380 --- /dev/null +++ b/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/controller/config/rbac/autogenteam_viewer_role.yaml b/controller/config/rbac/autogenteam_viewer_role.yaml new file mode 100644 index 000000000..466da56ed --- /dev/null +++ b/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/controller/config/rbac/autogentool_admin_role.yaml b/controller/config/rbac/autogentool_admin_role.yaml new file mode 100644 index 000000000..e69485443 --- /dev/null +++ b/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/controller/config/rbac/autogentool_editor_role.yaml b/controller/config/rbac/autogentool_editor_role.yaml new file mode 100644 index 000000000..1b6b986b3 --- /dev/null +++ b/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/controller/config/rbac/autogentool_viewer_role.yaml b/controller/config/rbac/autogentool_viewer_role.yaml new file mode 100644 index 000000000..7b160ebaa --- /dev/null +++ b/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/controller/config/rbac/kustomization.yaml b/controller/config/rbac/kustomization.yaml new file mode 100644 index 000000000..60243a11d --- /dev/null +++ b/controller/config/rbac/kustomization.yaml @@ -0,0 +1,34 @@ +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. +- 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/controller/config/rbac/leader_election_role.yaml b/controller/config/rbac/leader_election_role.yaml new file mode 100644 index 000000000..445f02706 --- /dev/null +++ b/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/controller/config/rbac/leader_election_role_binding.yaml b/controller/config/rbac/leader_election_role_binding.yaml new file mode 100644 index 000000000..aed609dd5 --- /dev/null +++ b/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/controller/config/rbac/metrics_auth_role.yaml b/controller/config/rbac/metrics_auth_role.yaml new file mode 100644 index 000000000..32d2e4ec6 --- /dev/null +++ b/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/controller/config/rbac/metrics_auth_role_binding.yaml b/controller/config/rbac/metrics_auth_role_binding.yaml new file mode 100644 index 000000000..e775d67ff --- /dev/null +++ b/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/controller/config/rbac/metrics_reader_role.yaml b/controller/config/rbac/metrics_reader_role.yaml new file mode 100644 index 000000000..51a75db47 --- /dev/null +++ b/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/controller/config/rbac/role.yaml b/controller/config/rbac/role.yaml new file mode 100644 index 000000000..0dbb930c5 --- /dev/null +++ b/controller/config/rbac/role.yaml @@ -0,0 +1,11 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: controller + app.kubernetes.io/managed-by: kustomize + name: manager-role +rules: +- apiGroups: [""] + resources: ["pods"] + verbs: ["get", "list", "watch"] diff --git a/controller/config/rbac/role_binding.yaml b/controller/config/rbac/role_binding.yaml new file mode 100644 index 000000000..0953223d7 --- /dev/null +++ b/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/controller/config/rbac/service_account.yaml b/controller/config/rbac/service_account.yaml new file mode 100644 index 000000000..834b343e6 --- /dev/null +++ b/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/controller/config/samples/agent_v1alpha1_autogenagent.yaml b/controller/config/samples/agent_v1alpha1_autogenagent.yaml new file mode 100644 index 000000000..250c89810 --- /dev/null +++ b/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/controller/config/samples/agent_v1alpha1_autogenteam.yaml b/controller/config/samples/agent_v1alpha1_autogenteam.yaml new file mode 100644 index 000000000..f53000410 --- /dev/null +++ b/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/controller/config/samples/agent_v1alpha1_autogentool.yaml b/controller/config/samples/agent_v1alpha1_autogentool.yaml new file mode 100644 index 000000000..4d500713b --- /dev/null +++ b/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/controller/config/samples/kustomization.yaml b/controller/config/samples/kustomization.yaml new file mode 100644 index 000000000..7aedb2c90 --- /dev/null +++ b/controller/config/samples/kustomization.yaml @@ -0,0 +1,6 @@ +## Append samples of your project ## +resources: +- agent_v1alpha1_autogenteam.yaml +- agent_v1alpha1_autogenagent.yaml +- agent_v1alpha1_autogentool.yaml +# +kubebuilder:scaffold:manifestskustomizesamples diff --git a/controller/go.mod b/controller/go.mod index 7ee6405b0..5e2401f72 100644 --- a/controller/go.mod +++ b/controller/go.mod @@ -1,3 +1,98 @@ module github.com/kagent-dev/kagent/controller go 1.23.5 + +require ( + github.com/onsi/ginkgo/v2 v2.21.0 + github.com/onsi/gomega v1.35.1 + 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/exp v0.0.0-20240719175910-8a7402abbf56 // 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/api v0.32.0 // 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/controller/go.sum b/controller/go.sum new file mode 100644 index 000000000..725163760 --- /dev/null +++ b/controller/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= diff --git a/controller/hack/boilerplate.go.txt b/controller/hack/boilerplate.go.txt new file mode 100644 index 000000000..221dcbe0b --- /dev/null +++ b/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/controller/internal/controller/autogenagent_controller.go b/controller/internal/controller/autogenagent_controller.go new file mode 100644 index 000000000..6f197301b --- /dev/null +++ b/controller/internal/controller/autogenagent_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 "ai.solo.io/kagent/api/v1alpha1" +) + +// AutogenAgentReconciler reconciles a AutogenAgent object +type AutogenAgentReconciler struct { + client.Client + Scheme *runtime.Scheme +} + +// +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{}, nil +} + +// 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/controller/internal/controller/autogenagent_controller_test.go b/controller/internal/controller/autogenagent_controller_test.go new file mode 100644 index 000000000..2ef30598c --- /dev/null +++ b/controller/internal/controller/autogenagent_controller_test.go @@ -0,0 +1,84 @@ +/* +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/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "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 "ai.solo.io/kagent/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/controller/internal/controller/autogenteam_controller.go b/controller/internal/controller/autogenteam_controller.go new file mode 100644 index 000000000..8cc0c62ef --- /dev/null +++ b/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" + + "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 "ai.solo.io/kagent/api/v1alpha1" +) + +// AutogenTeamReconciler reconciles a AutogenTeam object +type AutogenTeamReconciler struct { + client.Client + Scheme *runtime.Scheme +} + +// +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) + + // TODO(user): your logic here + + return ctrl.Result{}, nil +} + +// 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/controller/internal/controller/autogenteam_controller_test.go b/controller/internal/controller/autogenteam_controller_test.go new file mode 100644 index 000000000..03d2d0ae0 --- /dev/null +++ b/controller/internal/controller/autogenteam_controller_test.go @@ -0,0 +1,84 @@ +/* +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/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "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 "ai.solo.io/kagent/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/controller/internal/controller/autogentool_controller.go b/controller/internal/controller/autogentool_controller.go new file mode 100644 index 000000000..6579f80d1 --- /dev/null +++ b/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 "ai.solo.io/kagent/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/controller/internal/controller/autogentool_controller_test.go b/controller/internal/controller/autogentool_controller_test.go new file mode 100644 index 000000000..508eb4805 --- /dev/null +++ b/controller/internal/controller/autogentool_controller_test.go @@ -0,0 +1,84 @@ +/* +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/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "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 "ai.solo.io/kagent/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/controller/internal/controller/suite_test.go b/controller/internal/controller/suite_test.go new file mode 100644 index 000000000..00918fa49 --- /dev/null +++ b/controller/internal/controller/suite_test.go @@ -0,0 +1,116 @@ +/* +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" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "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 "ai.solo.io/kagent/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/controller/test/e2e/e2e_suite_test.go b/controller/test/e2e/e2e_suite_test.go new file mode 100644 index 000000000..7b3b4c6b2 --- /dev/null +++ b/controller/test/e2e/e2e_suite_test.go @@ -0,0 +1,110 @@ +/* +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 e2e + +import ( + "fmt" + "os" + "os/exec" + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "ai.solo.io/kagent/test/utils" +) + +var ( + // Optional Environment Variables: + // - PROMETHEUS_INSTALL_SKIP=true: Skips Prometheus Operator installation during test setup. + // - CERT_MANAGER_INSTALL_SKIP=true: Skips CertManager installation during test setup. + // These variables are useful if Prometheus or CertManager is already installed, avoiding + // re-installation and conflicts. + skipPrometheusInstall = os.Getenv("PROMETHEUS_INSTALL_SKIP") == "true" + skipCertManagerInstall = os.Getenv("CERT_MANAGER_INSTALL_SKIP") == "true" + // isPrometheusOperatorAlreadyInstalled will be set true when prometheus CRDs be found on the cluster + isPrometheusOperatorAlreadyInstalled = false + // isCertManagerAlreadyInstalled will be set true when CertManager CRDs be found on the cluster + isCertManagerAlreadyInstalled = false + + // projectImage is the name of the image which will be build and loaded + // with the code source changes to be tested. + projectImage = "example.com/controller:v0.0.1" +) + +// TestE2E runs the end-to-end (e2e) test suite for the project. These tests execute in an isolated, +// temporary environment to validate project changes with the the purposed to be used in CI jobs. +// The default setup requires Kind, builds/loads the Manager Docker image locally, and installs +// CertManager and Prometheus. +func TestE2E(t *testing.T) { + RegisterFailHandler(Fail) + _, _ = fmt.Fprintf(GinkgoWriter, "Starting controller integration test suite\n") + RunSpecs(t, "e2e suite") +} + +var _ = BeforeSuite(func() { + By("Ensure that Prometheus is enabled") + _ = utils.UncommentCode("config/default/kustomization.yaml", "#- ../prometheus", "#") + + By("building the manager(Operator) image") + cmd := exec.Command("make", "docker-build", fmt.Sprintf("IMG=%s", projectImage)) + _, err := utils.Run(cmd) + ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to build the manager(Operator) image") + + // TODO(user): If you want to change the e2e test vendor from Kind, ensure the image is + // built and available before running the tests. Also, remove the following block. + By("loading the manager(Operator) image on Kind") + err = utils.LoadImageToKindClusterWithName(projectImage) + ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to load the manager(Operator) image into Kind") + + // The tests-e2e are intended to run on a temporary cluster that is created and destroyed for testing. + // To prevent errors when tests run in environments with Prometheus or CertManager already installed, + // we check for their presence before execution. + // Setup Prometheus and CertManager before the suite if not skipped and if not already installed + if !skipPrometheusInstall { + By("checking if prometheus is installed already") + isPrometheusOperatorAlreadyInstalled = utils.IsPrometheusCRDsInstalled() + if !isPrometheusOperatorAlreadyInstalled { + _, _ = fmt.Fprintf(GinkgoWriter, "Installing Prometheus Operator...\n") + Expect(utils.InstallPrometheusOperator()).To(Succeed(), "Failed to install Prometheus Operator") + } else { + _, _ = fmt.Fprintf(GinkgoWriter, "WARNING: Prometheus Operator is already installed. Skipping installation...\n") + } + } + if !skipCertManagerInstall { + By("checking if cert manager is installed already") + isCertManagerAlreadyInstalled = utils.IsCertManagerCRDsInstalled() + if !isCertManagerAlreadyInstalled { + _, _ = fmt.Fprintf(GinkgoWriter, "Installing CertManager...\n") + Expect(utils.InstallCertManager()).To(Succeed(), "Failed to install CertManager") + } else { + _, _ = fmt.Fprintf(GinkgoWriter, "WARNING: CertManager is already installed. Skipping installation...\n") + } + } +}) + +var _ = AfterSuite(func() { + // Teardown Prometheus and CertManager after the suite if not skipped and if they were not already installed + if !skipPrometheusInstall && !isPrometheusOperatorAlreadyInstalled { + _, _ = fmt.Fprintf(GinkgoWriter, "Uninstalling Prometheus Operator...\n") + utils.UninstallPrometheusOperator() + } + if !skipCertManagerInstall && !isCertManagerAlreadyInstalled { + _, _ = fmt.Fprintf(GinkgoWriter, "Uninstalling CertManager...\n") + utils.UninstallCertManager() + } +}) diff --git a/controller/test/e2e/e2e_test.go b/controller/test/e2e/e2e_test.go new file mode 100644 index 000000000..14e324a63 --- /dev/null +++ b/controller/test/e2e/e2e_test.go @@ -0,0 +1,334 @@ +/* +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 e2e + +import ( + "encoding/json" + "fmt" + "os" + "os/exec" + "path/filepath" + "time" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "ai.solo.io/kagent/test/utils" +) + +// namespace where the project is deployed in +const namespace = "controller-system" + +// serviceAccountName created for the project +const serviceAccountName = "controller-controller-manager" + +// metricsServiceName is the name of the metrics service of the project +const metricsServiceName = "controller-controller-manager-metrics-service" + +// metricsRoleBindingName is the name of the RBAC that will be created to allow get the metrics data +const metricsRoleBindingName = "controller-metrics-binding" + +var _ = Describe("Manager", Ordered, func() { + var controllerPodName string + + // Before running the tests, set up the environment by creating the namespace, + // enforce the restricted security policy to the namespace, installing CRDs, + // and deploying the controller. + BeforeAll(func() { + By("creating manager namespace") + cmd := exec.Command("kubectl", "create", "ns", namespace) + _, err := utils.Run(cmd) + Expect(err).NotTo(HaveOccurred(), "Failed to create namespace") + + By("labeling the namespace to enforce the restricted security policy") + cmd = exec.Command("kubectl", "label", "--overwrite", "ns", namespace, + "pod-security.kubernetes.io/enforce=restricted") + _, err = utils.Run(cmd) + Expect(err).NotTo(HaveOccurred(), "Failed to label namespace with restricted policy") + + By("installing CRDs") + cmd = exec.Command("make", "install") + _, err = utils.Run(cmd) + Expect(err).NotTo(HaveOccurred(), "Failed to install CRDs") + + By("deploying the controller-manager") + cmd = exec.Command("make", "deploy", fmt.Sprintf("IMG=%s", projectImage)) + _, err = utils.Run(cmd) + Expect(err).NotTo(HaveOccurred(), "Failed to deploy the controller-manager") + }) + + // After all tests have been executed, clean up by undeploying the controller, uninstalling CRDs, + // and deleting the namespace. + AfterAll(func() { + By("cleaning up the curl pod for metrics") + cmd := exec.Command("kubectl", "delete", "pod", "curl-metrics", "-n", namespace) + _, _ = utils.Run(cmd) + + By("undeploying the controller-manager") + cmd = exec.Command("make", "undeploy") + _, _ = utils.Run(cmd) + + By("uninstalling CRDs") + cmd = exec.Command("make", "uninstall") + _, _ = utils.Run(cmd) + + By("removing manager namespace") + cmd = exec.Command("kubectl", "delete", "ns", namespace) + _, _ = utils.Run(cmd) + }) + + // After each test, check for failures and collect logs, events, + // and pod descriptions for debugging. + AfterEach(func() { + specReport := CurrentSpecReport() + if specReport.Failed() { + By("Fetching controller manager pod logs") + cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace) + controllerLogs, err := utils.Run(cmd) + if err == nil { + _, _ = fmt.Fprintf(GinkgoWriter, "Controller logs:\n %s", controllerLogs) + } else { + _, _ = fmt.Fprintf(GinkgoWriter, "Failed to get Controller logs: %s", err) + } + + By("Fetching Kubernetes events") + cmd = exec.Command("kubectl", "get", "events", "-n", namespace, "--sort-by=.lastTimestamp") + eventsOutput, err := utils.Run(cmd) + if err == nil { + _, _ = fmt.Fprintf(GinkgoWriter, "Kubernetes events:\n%s", eventsOutput) + } else { + _, _ = fmt.Fprintf(GinkgoWriter, "Failed to get Kubernetes events: %s", err) + } + + By("Fetching curl-metrics logs") + cmd = exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace) + metricsOutput, err := utils.Run(cmd) + if err == nil { + _, _ = fmt.Fprintf(GinkgoWriter, "Metrics logs:\n %s", metricsOutput) + } else { + _, _ = fmt.Fprintf(GinkgoWriter, "Failed to get curl-metrics logs: %s", err) + } + + By("Fetching controller manager pod description") + cmd = exec.Command("kubectl", "describe", "pod", controllerPodName, "-n", namespace) + podDescription, err := utils.Run(cmd) + if err == nil { + fmt.Println("Pod description:\n", podDescription) + } else { + fmt.Println("Failed to describe controller pod") + } + } + }) + + SetDefaultEventuallyTimeout(2 * time.Minute) + SetDefaultEventuallyPollingInterval(time.Second) + + Context("Manager", func() { + It("should run successfully", func() { + By("validating that the controller-manager pod is running as expected") + verifyControllerUp := func(g Gomega) { + // Get the name of the controller-manager pod + cmd := exec.Command("kubectl", "get", + "pods", "-l", "control-plane=controller-manager", + "-o", "go-template={{ range .items }}"+ + "{{ if not .metadata.deletionTimestamp }}"+ + "{{ .metadata.name }}"+ + "{{ \"\\n\" }}{{ end }}{{ end }}", + "-n", namespace, + ) + + podOutput, err := utils.Run(cmd) + g.Expect(err).NotTo(HaveOccurred(), "Failed to retrieve controller-manager pod information") + podNames := utils.GetNonEmptyLines(podOutput) + g.Expect(podNames).To(HaveLen(1), "expected 1 controller pod running") + controllerPodName = podNames[0] + g.Expect(controllerPodName).To(ContainSubstring("controller-manager")) + + // Validate the pod's status + cmd = exec.Command("kubectl", "get", + "pods", controllerPodName, "-o", "jsonpath={.status.phase}", + "-n", namespace, + ) + output, err := utils.Run(cmd) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(output).To(Equal("Running"), "Incorrect controller-manager pod status") + } + Eventually(verifyControllerUp).Should(Succeed()) + }) + + It("should ensure the metrics endpoint is serving metrics", func() { + By("creating a ClusterRoleBinding for the service account to allow access to metrics") + cmd := exec.Command("kubectl", "create", "clusterrolebinding", metricsRoleBindingName, + "--clusterrole=controller-metrics-reader", + fmt.Sprintf("--serviceaccount=%s:%s", namespace, serviceAccountName), + ) + _, err := utils.Run(cmd) + Expect(err).NotTo(HaveOccurred(), "Failed to create ClusterRoleBinding") + + By("validating that the metrics service is available") + cmd = exec.Command("kubectl", "get", "service", metricsServiceName, "-n", namespace) + _, err = utils.Run(cmd) + Expect(err).NotTo(HaveOccurred(), "Metrics service should exist") + + By("validating that the ServiceMonitor for Prometheus is applied in the namespace") + cmd = exec.Command("kubectl", "get", "ServiceMonitor", "-n", namespace) + _, err = utils.Run(cmd) + Expect(err).NotTo(HaveOccurred(), "ServiceMonitor should exist") + + By("getting the service account token") + token, err := serviceAccountToken() + Expect(err).NotTo(HaveOccurred()) + Expect(token).NotTo(BeEmpty()) + + By("waiting for the metrics endpoint to be ready") + verifyMetricsEndpointReady := func(g Gomega) { + cmd := exec.Command("kubectl", "get", "endpoints", metricsServiceName, "-n", namespace) + output, err := utils.Run(cmd) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(output).To(ContainSubstring("8443"), "Metrics endpoint is not ready") + } + Eventually(verifyMetricsEndpointReady).Should(Succeed()) + + By("verifying that the controller manager is serving the metrics server") + verifyMetricsServerStarted := func(g Gomega) { + cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace) + output, err := utils.Run(cmd) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(output).To(ContainSubstring("controller-runtime.metrics\tServing metrics server"), + "Metrics server not yet started") + } + Eventually(verifyMetricsServerStarted).Should(Succeed()) + + By("creating the curl-metrics pod to access the metrics endpoint") + cmd = exec.Command("kubectl", "run", "curl-metrics", "--restart=Never", + "--namespace", namespace, + "--image=curlimages/curl:latest", + "--overrides", + fmt.Sprintf(`{ + "spec": { + "containers": [{ + "name": "curl", + "image": "curlimages/curl:latest", + "command": ["/bin/sh", "-c"], + "args": ["curl -v -k -H 'Authorization: Bearer %s' https://%s.%s.svc.cluster.local:8443/metrics"], + "securityContext": { + "allowPrivilegeEscalation": false, + "capabilities": { + "drop": ["ALL"] + }, + "runAsNonRoot": true, + "runAsUser": 1000, + "seccompProfile": { + "type": "RuntimeDefault" + } + } + }], + "serviceAccount": "%s" + } + }`, token, metricsServiceName, namespace, serviceAccountName)) + _, err = utils.Run(cmd) + Expect(err).NotTo(HaveOccurred(), "Failed to create curl-metrics pod") + + By("waiting for the curl-metrics pod to complete.") + verifyCurlUp := func(g Gomega) { + cmd := exec.Command("kubectl", "get", "pods", "curl-metrics", + "-o", "jsonpath={.status.phase}", + "-n", namespace) + output, err := utils.Run(cmd) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(output).To(Equal("Succeeded"), "curl pod in wrong status") + } + Eventually(verifyCurlUp, 5*time.Minute).Should(Succeed()) + + By("getting the metrics by checking curl-metrics logs") + metricsOutput := getMetricsOutput() + Expect(metricsOutput).To(ContainSubstring( + "controller_runtime_reconcile_total", + )) + }) + + // +kubebuilder:scaffold:e2e-webhooks-checks + + // TODO: Customize the e2e test suite with scenarios specific to your project. + // Consider applying sample/CR(s) and check their status and/or verifying + // the reconciliation by using the metrics, i.e.: + // metricsOutput := getMetricsOutput() + // Expect(metricsOutput).To(ContainSubstring( + // fmt.Sprintf(`controller_runtime_reconcile_total{controller="%s",result="success"} 1`, + // strings.ToLower(), + // )) + }) +}) + +// serviceAccountToken returns a token for the specified service account in the given namespace. +// It uses the Kubernetes TokenRequest API to generate a token by directly sending a request +// and parsing the resulting token from the API response. +func serviceAccountToken() (string, error) { + const tokenRequestRawString = `{ + "apiVersion": "authentication.k8s.io/v1", + "kind": "TokenRequest" + }` + + // Temporary file to store the token request + secretName := fmt.Sprintf("%s-token-request", serviceAccountName) + tokenRequestFile := filepath.Join("/tmp", secretName) + err := os.WriteFile(tokenRequestFile, []byte(tokenRequestRawString), os.FileMode(0o644)) + if err != nil { + return "", err + } + + var out string + verifyTokenCreation := func(g Gomega) { + // Execute kubectl command to create the token + cmd := exec.Command("kubectl", "create", "--raw", fmt.Sprintf( + "/api/v1/namespaces/%s/serviceaccounts/%s/token", + namespace, + serviceAccountName, + ), "-f", tokenRequestFile) + + output, err := cmd.CombinedOutput() + g.Expect(err).NotTo(HaveOccurred()) + + // Parse the JSON output to extract the token + var token tokenRequest + err = json.Unmarshal(output, &token) + g.Expect(err).NotTo(HaveOccurred()) + + out = token.Status.Token + } + Eventually(verifyTokenCreation).Should(Succeed()) + + return out, err +} + +// getMetricsOutput retrieves and returns the logs from the curl pod used to access the metrics endpoint. +func getMetricsOutput() string { + By("getting the curl-metrics logs") + cmd := exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace) + metricsOutput, err := utils.Run(cmd) + Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod") + Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK")) + return metricsOutput +} + +// tokenRequest is a simplified representation of the Kubernetes TokenRequest API response, +// containing only the token field that we need to extract. +type tokenRequest struct { + Status struct { + Token string `json:"token"` + } `json:"status"` +} diff --git a/controller/test/utils/utils.go b/controller/test/utils/utils.go new file mode 100644 index 000000000..04a5141cc --- /dev/null +++ b/controller/test/utils/utils.go @@ -0,0 +1,251 @@ +/* +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 utils + +import ( + "bufio" + "bytes" + "fmt" + "os" + "os/exec" + "strings" + + . "github.com/onsi/ginkgo/v2" //nolint:golint,revive +) + +const ( + prometheusOperatorVersion = "v0.77.1" + prometheusOperatorURL = "https://github.com/prometheus-operator/prometheus-operator/" + + "releases/download/%s/bundle.yaml" + + certmanagerVersion = "v1.16.3" + certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml" +) + +func warnError(err error) { + _, _ = fmt.Fprintf(GinkgoWriter, "warning: %v\n", err) +} + +// Run executes the provided command within this context +func Run(cmd *exec.Cmd) (string, error) { + dir, _ := GetProjectDir() + cmd.Dir = dir + + if err := os.Chdir(cmd.Dir); err != nil { + _, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %s\n", err) + } + + cmd.Env = append(os.Environ(), "GO111MODULE=on") + command := strings.Join(cmd.Args, " ") + _, _ = fmt.Fprintf(GinkgoWriter, "running: %s\n", command) + output, err := cmd.CombinedOutput() + if err != nil { + return string(output), fmt.Errorf("%s failed with error: (%v) %s", command, err, string(output)) + } + + return string(output), nil +} + +// InstallPrometheusOperator installs the prometheus Operator to be used to export the enabled metrics. +func InstallPrometheusOperator() error { + url := fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion) + cmd := exec.Command("kubectl", "create", "-f", url) + _, err := Run(cmd) + return err +} + +// UninstallPrometheusOperator uninstalls the prometheus +func UninstallPrometheusOperator() { + url := fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion) + cmd := exec.Command("kubectl", "delete", "-f", url) + if _, err := Run(cmd); err != nil { + warnError(err) + } +} + +// IsPrometheusCRDsInstalled checks if any Prometheus CRDs are installed +// by verifying the existence of key CRDs related to Prometheus. +func IsPrometheusCRDsInstalled() bool { + // List of common Prometheus CRDs + prometheusCRDs := []string{ + "prometheuses.monitoring.coreos.com", + "prometheusrules.monitoring.coreos.com", + "prometheusagents.monitoring.coreos.com", + } + + cmd := exec.Command("kubectl", "get", "crds", "-o", "custom-columns=NAME:.metadata.name") + output, err := Run(cmd) + if err != nil { + return false + } + crdList := GetNonEmptyLines(output) + for _, crd := range prometheusCRDs { + for _, line := range crdList { + if strings.Contains(line, crd) { + return true + } + } + } + + return false +} + +// UninstallCertManager uninstalls the cert manager +func UninstallCertManager() { + url := fmt.Sprintf(certmanagerURLTmpl, certmanagerVersion) + cmd := exec.Command("kubectl", "delete", "-f", url) + if _, err := Run(cmd); err != nil { + warnError(err) + } +} + +// InstallCertManager installs the cert manager bundle. +func InstallCertManager() error { + url := fmt.Sprintf(certmanagerURLTmpl, certmanagerVersion) + cmd := exec.Command("kubectl", "apply", "-f", url) + if _, err := Run(cmd); err != nil { + return err + } + // Wait for cert-manager-webhook to be ready, which can take time if cert-manager + // was re-installed after uninstalling on a cluster. + cmd = exec.Command("kubectl", "wait", "deployment.apps/cert-manager-webhook", + "--for", "condition=Available", + "--namespace", "cert-manager", + "--timeout", "5m", + ) + + _, err := Run(cmd) + return err +} + +// IsCertManagerCRDsInstalled checks if any Cert Manager CRDs are installed +// by verifying the existence of key CRDs related to Cert Manager. +func IsCertManagerCRDsInstalled() bool { + // List of common Cert Manager CRDs + certManagerCRDs := []string{ + "certificates.cert-manager.io", + "issuers.cert-manager.io", + "clusterissuers.cert-manager.io", + "certificaterequests.cert-manager.io", + "orders.acme.cert-manager.io", + "challenges.acme.cert-manager.io", + } + + // Execute the kubectl command to get all CRDs + cmd := exec.Command("kubectl", "get", "crds") + output, err := Run(cmd) + if err != nil { + return false + } + + // Check if any of the Cert Manager CRDs are present + crdList := GetNonEmptyLines(output) + for _, crd := range certManagerCRDs { + for _, line := range crdList { + if strings.Contains(line, crd) { + return true + } + } + } + + return false +} + +// LoadImageToKindClusterWithName loads a local docker image to the kind cluster +func LoadImageToKindClusterWithName(name string) error { + cluster := "kind" + if v, ok := os.LookupEnv("KIND_CLUSTER"); ok { + cluster = v + } + kindOptions := []string{"load", "docker-image", name, "--name", cluster} + cmd := exec.Command("kind", kindOptions...) + _, err := Run(cmd) + return err +} + +// GetNonEmptyLines converts given command output string into individual objects +// according to line breakers, and ignores the empty elements in it. +func GetNonEmptyLines(output string) []string { + var res []string + elements := strings.Split(output, "\n") + for _, element := range elements { + if element != "" { + res = append(res, element) + } + } + + return res +} + +// GetProjectDir will return the directory where the project is +func GetProjectDir() (string, error) { + wd, err := os.Getwd() + if err != nil { + return wd, err + } + wd = strings.Replace(wd, "/test/e2e", "", -1) + return wd, nil +} + +// UncommentCode searches for target in the file and remove the comment prefix +// of the target content. The target content may span multiple lines. +func UncommentCode(filename, target, prefix string) error { + // false positive + // nolint:gosec + content, err := os.ReadFile(filename) + if err != nil { + return err + } + strContent := string(content) + + idx := strings.Index(strContent, target) + if idx < 0 { + return fmt.Errorf("unable to find the code %s to be uncomment", target) + } + + out := new(bytes.Buffer) + _, err = out.Write(content[:idx]) + if err != nil { + return err + } + + scanner := bufio.NewScanner(bytes.NewBufferString(target)) + if !scanner.Scan() { + return nil + } + for { + _, err := out.WriteString(strings.TrimPrefix(scanner.Text(), prefix)) + if err != nil { + return err + } + // Avoid writing a newline in case the previous line was the last in target. + if !scanner.Scan() { + break + } + if _, err := out.WriteString("\n"); err != nil { + return err + } + } + + _, err = out.Write(content[idx+len(target):]) + if err != nil { + return err + } + // false positive + // nolint:gosec + return os.WriteFile(filename, out.Bytes(), 0644) +} From fc6d3883a132388a2984a269bd7bd702f2bf9044 Mon Sep 17 00:00:00 2001 From: Scott Weiss Date: Mon, 27 Jan 2025 12:41:39 -0500 Subject: [PATCH 02/12] add autogen api types to kubebuilder --- controller/PROJECT | 9 ++ controller/api/v1alpha1/autogenagent_types.go | 15 ++- .../api/v1alpha1/autogenmodelconfig_types.go | 65 ++++++++++++ controller/api/v1alpha1/autogenteam_types.go | 26 +++-- controller/api/v1alpha1/autogentool_types.go | 11 +-- .../api/v1alpha1/zz_generated.deepcopy.go | 99 ++++++++++++++++++- controller/cmd/main.go | 7 ++ controller/config/crd/kustomization.yaml | 1 + .../rbac/autogenmodelconfig_admin_role.yaml | 27 +++++ .../rbac/autogenmodelconfig_editor_role.yaml | 33 +++++++ .../rbac/autogenmodelconfig_viewer_role.yaml | 29 ++++++ controller/config/rbac/kustomization.yaml | 3 + .../agent_v1alpha1_autogenmodelconfig.yaml | 9 ++ controller/config/samples/kustomization.yaml | 1 + .../autogenmodelconfig_controller.go | 63 ++++++++++++ .../autogenmodelconfig_controller_test.go | 84 ++++++++++++++++ 16 files changed, 454 insertions(+), 28 deletions(-) create mode 100644 controller/api/v1alpha1/autogenmodelconfig_types.go create mode 100644 controller/config/rbac/autogenmodelconfig_admin_role.yaml create mode 100644 controller/config/rbac/autogenmodelconfig_editor_role.yaml create mode 100644 controller/config/rbac/autogenmodelconfig_viewer_role.yaml create mode 100644 controller/config/samples/agent_v1alpha1_autogenmodelconfig.yaml create mode 100644 controller/internal/controller/autogenmodelconfig_controller.go create mode 100644 controller/internal/controller/autogenmodelconfig_controller_test.go diff --git a/controller/PROJECT b/controller/PROJECT index 98cdd42bb..c826d44ac 100644 --- a/controller/PROJECT +++ b/controller/PROJECT @@ -35,4 +35,13 @@ resources: kind: AutogenTool path: ai.solo.io/kagent/api/v1alpha1 version: v1alpha1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: ai.solo.io + group: agent + kind: AutogenModelConfig + path: ai.solo.io/kagent/api/v1alpha1 + version: v1alpha1 version: "3" diff --git a/controller/api/v1alpha1/autogenagent_types.go b/controller/api/v1alpha1/autogenagent_types.go index adfd914ab..786c61837 100644 --- a/controller/api/v1alpha1/autogenagent_types.go +++ b/controller/api/v1alpha1/autogenagent_types.go @@ -25,18 +25,15 @@ import ( // AutogenAgentSpec defines the desired state of AutogenAgent. type AutogenAgentSpec struct { - // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster - // Important: Run "make" to regenerate code after modifying this file - - // Foo is an example field of AutogenAgent. Edit autogenagent_types.go to remove/update - Foo string `json:"foo,omitempty"` + Name string `json:"name,omitempty"` + Type string `json:"type,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 { - // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster - // Important: Run "make" to regenerate code after modifying this file -} +type AutogenAgentStatus struct{} // +kubebuilder:object:root=true // +kubebuilder:subresource:status diff --git a/controller/api/v1alpha1/autogenmodelconfig_types.go b/controller/api/v1alpha1/autogenmodelconfig_types.go new file mode 100644 index 000000000..adbf75e82 --- /dev/null +++ b/controller/api/v1alpha1/autogenmodelconfig_types.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 v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// AutogenModelConfigSpec defines the desired state of AutogenModelConfig. +type AutogenModelConfigSpec struct { + ModelType string `json:"modelType"` + Model string `json:"model"` + APIKeySecret string `json:"apiKeySecret"` + APIKeySecretKey string `json:"apiKeySecretKey"` + BaseURL string `json:"baseUrl"` + Capabilities AutogenModelCapabilities `json:"capabilities"` +} + +type AutogenModelCapabilities struct { + Vision bool `json:"vision"` + FunctionCalling bool `json:"functionCalling"` + JSONOutput bool `json:"jsonOutput"` +} + +// 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/controller/api/v1alpha1/autogenteam_types.go b/controller/api/v1alpha1/autogenteam_types.go index 4e3b3fe2d..e5bf73c3e 100644 --- a/controller/api/v1alpha1/autogenteam_types.go +++ b/controller/api/v1alpha1/autogenteam_types.go @@ -25,19 +25,29 @@ import ( // AutogenTeamSpec defines the desired state of AutogenTeam. type AutogenTeamSpec struct { - // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster - // Important: Run "make" to regenerate code after modifying this file + Participants []string `json:"participants"` + TeamType string `json:"teamType"` + SelectorTeamConfig SelectorTeamConfig `json:"selectorTeamConfig"` + TerminationCondition TerminationCondition `json:"terminationCondition"` + MaxTurns int64 `json:"maxTurns"` +} - // Foo is an example field of AutogenTeam. Edit autogenteam_types.go to remove/update - Foo string `json:"foo,omitempty"` +type SelectorTeamConfig struct { + SelectorPrompt string `json:"selectorPrompt"` + ModelConfig string `json:"modelConfig"` } -// AutogenTeamStatus defines the observed state of AutogenTeam. -type AutogenTeamStatus struct { - // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster - // Important: Run "make" to regenerate code after modifying this file +type TerminationCondition struct { + MaxMessageTermination MaxMessageTermination `json:"maxMessageTermination"` +} + +type MaxMessageTermination struct { + MaxMessages int64 `json:"maxMessages"` } +// AutogenTeamStatus defines the observed state of AutogenTeam. +type AutogenTeamStatus struct{} + // +kubebuilder:object:root=true // +kubebuilder:subresource:status diff --git a/controller/api/v1alpha1/autogentool_types.go b/controller/api/v1alpha1/autogentool_types.go index 442fde57e..f22cbc420 100644 --- a/controller/api/v1alpha1/autogentool_types.go +++ b/controller/api/v1alpha1/autogentool_types.go @@ -25,18 +25,11 @@ import ( // AutogenToolSpec defines the desired state of AutogenTool. type AutogenToolSpec struct { - // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster - // Important: Run "make" to regenerate code after modifying this file - - // Foo is an example field of AutogenTool. Edit autogentool_types.go to remove/update - Foo string `json:"foo,omitempty"` + Description string `json:"description,omitempty"` } // AutogenToolStatus defines the observed state of AutogenTool. -type AutogenToolStatus struct { - // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster - // Important: Run "make" to regenerate code after modifying this file -} +type AutogenToolStatus struct{} // +kubebuilder:object:root=true // +kubebuilder:subresource:status diff --git a/controller/api/v1alpha1/zz_generated.deepcopy.go b/controller/api/v1alpha1/zz_generated.deepcopy.go index dc13f8813..0c1189ad1 100644 --- a/controller/api/v1alpha1/zz_generated.deepcopy.go +++ b/controller/api/v1alpha1/zz_generated.deepcopy.go @@ -29,7 +29,7 @@ func (in *AutogenAgent) DeepCopyInto(out *AutogenAgent) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec + in.Spec.DeepCopyInto(&out.Spec) out.Status = in.Status } @@ -86,6 +86,11 @@ func (in *AutogenAgentList) DeepCopyObject() runtime.Object { // 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. @@ -114,7 +119,7 @@ func (in *AutogenAgentStatus) DeepCopy() *AutogenAgentStatus { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AutogenTeam) DeepCopyInto(out *AutogenTeam) { +func (in *AutogenModelConfig) DeepCopyInto(out *AutogenModelConfig) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) @@ -122,6 +127,95 @@ func (in *AutogenTeam) DeepCopyInto(out *AutogenTeam) { 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 { @@ -175,6 +269,7 @@ func (in *AutogenTeamList) DeepCopyObject() runtime.Object { // 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 + in.Selector.DeepCopyInto(&out.Selector) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutogenTeamSpec. diff --git a/controller/cmd/main.go b/controller/cmd/main.go index f330f8eb1..0232b9356 100644 --- a/controller/cmd/main.go +++ b/controller/cmd/main.go @@ -223,6 +223,13 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "AutogenTool") os.Exit(1) } + if err = (&controller.AutogenModelConfigReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "AutogenModelConfig") + os.Exit(1) + } // +kubebuilder:scaffold:builder if metricsCertWatcher != nil { diff --git a/controller/config/crd/kustomization.yaml b/controller/config/crd/kustomization.yaml index 60e44f8c5..382bbe50b 100644 --- a/controller/config/crd/kustomization.yaml +++ b/controller/config/crd/kustomization.yaml @@ -5,6 +5,7 @@ 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: diff --git a/controller/config/rbac/autogenmodelconfig_admin_role.yaml b/controller/config/rbac/autogenmodelconfig_admin_role.yaml new file mode 100644 index 000000000..d5188c6c6 --- /dev/null +++ b/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/controller/config/rbac/autogenmodelconfig_editor_role.yaml b/controller/config/rbac/autogenmodelconfig_editor_role.yaml new file mode 100644 index 000000000..a4493bfd8 --- /dev/null +++ b/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/controller/config/rbac/autogenmodelconfig_viewer_role.yaml b/controller/config/rbac/autogenmodelconfig_viewer_role.yaml new file mode 100644 index 000000000..c9ec0aff2 --- /dev/null +++ b/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/controller/config/rbac/kustomization.yaml b/controller/config/rbac/kustomization.yaml index 60243a11d..0254d86a9 100644 --- a/controller/config/rbac/kustomization.yaml +++ b/controller/config/rbac/kustomization.yaml @@ -22,6 +22,9 @@ resources: # 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 diff --git a/controller/config/samples/agent_v1alpha1_autogenmodelconfig.yaml b/controller/config/samples/agent_v1alpha1_autogenmodelconfig.yaml new file mode 100644 index 000000000..04a8f268a --- /dev/null +++ b/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/controller/config/samples/kustomization.yaml b/controller/config/samples/kustomization.yaml index 7aedb2c90..800337ff5 100644 --- a/controller/config/samples/kustomization.yaml +++ b/controller/config/samples/kustomization.yaml @@ -3,4 +3,5 @@ resources: - agent_v1alpha1_autogenteam.yaml - agent_v1alpha1_autogenagent.yaml - agent_v1alpha1_autogentool.yaml +- agent_v1alpha1_autogenmodelconfig.yaml # +kubebuilder:scaffold:manifestskustomizesamples diff --git a/controller/internal/controller/autogenmodelconfig_controller.go b/controller/internal/controller/autogenmodelconfig_controller.go new file mode 100644 index 000000000..b0d6ddc63 --- /dev/null +++ b/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" + + "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 "ai.solo.io/kagent/api/v1alpha1" +) + +// AutogenModelConfigReconciler reconciles a AutogenModelConfig object +type AutogenModelConfigReconciler struct { + client.Client + Scheme *runtime.Scheme +} + +// +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) + + // TODO(user): your logic here + + return ctrl.Result{}, nil +} + +// 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/controller/internal/controller/autogenmodelconfig_controller_test.go b/controller/internal/controller/autogenmodelconfig_controller_test.go new file mode 100644 index 000000000..fb25fbc65 --- /dev/null +++ b/controller/internal/controller/autogenmodelconfig_controller_test.go @@ -0,0 +1,84 @@ +/* +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/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "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 "ai.solo.io/kagent/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. + }) + }) +}) From 5c979e971c891142a03335846ba3966fdd37da3d Mon Sep 17 00:00:00 2001 From: Scott Weiss Date: Tue, 28 Jan 2025 12:50:14 -0500 Subject: [PATCH 03/12] implement translator, cleanup apis --- controller/PROJECT | 10 +- controller/api/v1alpha1/autogenagent_types.go | 1 - .../api/v1alpha1/autogenmodelconfig_types.go | 15 +- controller/api/v1alpha1/autogenteam_types.go | 17 +- controller/cmd/main.go | 4 +- controller/go.mod | 3 +- .../autogen/autogen_api_translator.go | 250 ++++++++++++++++++ .../internal/autogen/autogen_config_types.go | 83 ++++++ .../controller/autogenagent_controller.go | 2 +- .../autogenagent_controller_test.go | 4 +- .../autogenmodelconfig_controller.go | 2 +- .../autogenmodelconfig_controller_test.go | 4 +- .../controller/autogenteam_controller.go | 2 +- .../controller/autogenteam_controller_test.go | 4 +- .../controller/autogentool_controller.go | 2 +- .../controller/autogentool_controller_test.go | 4 +- controller/internal/controller/suite_test.go | 5 +- .../internal/utils/syncutils/sync_utils.go | 159 +++++++++++ controller/test/e2e/e2e_suite_test.go | 2 +- controller/test/e2e/e2e_test.go | 2 +- 20 files changed, 528 insertions(+), 47 deletions(-) create mode 100644 controller/internal/autogen/autogen_api_translator.go create mode 100644 controller/internal/autogen/autogen_config_types.go create mode 100644 controller/internal/utils/syncutils/sync_utils.go diff --git a/controller/PROJECT b/controller/PROJECT index c826d44ac..b7c826d5f 100644 --- a/controller/PROJECT +++ b/controller/PROJECT @@ -6,7 +6,7 @@ domain: ai.solo.io layout: - go.kubebuilder.io/v4 projectName: controller -repo: ai.solo.io/kagent +repo: github.com/kagent-dev/kagent/controller resources: - api: crdVersion: v1 @@ -15,7 +15,7 @@ resources: domain: ai.solo.io group: agent kind: AutogenTeam - path: ai.solo.io/kagent/api/v1alpha1 + path: github.com/kagent-dev/kagent/controller/api/v1alpha1 version: v1alpha1 - api: crdVersion: v1 @@ -24,7 +24,7 @@ resources: domain: ai.solo.io group: agent kind: AutogenAgent - path: ai.solo.io/kagent/api/v1alpha1 + path: github.com/kagent-dev/kagent/controller/api/v1alpha1 version: v1alpha1 - api: crdVersion: v1 @@ -33,7 +33,7 @@ resources: domain: ai.solo.io group: agent kind: AutogenTool - path: ai.solo.io/kagent/api/v1alpha1 + path: github.com/kagent-dev/kagent/controller/api/v1alpha1 version: v1alpha1 - api: crdVersion: v1 @@ -42,6 +42,6 @@ resources: domain: ai.solo.io group: agent kind: AutogenModelConfig - path: ai.solo.io/kagent/api/v1alpha1 + path: github.com/kagent-dev/kagent/controller/api/v1alpha1 version: v1alpha1 version: "3" diff --git a/controller/api/v1alpha1/autogenagent_types.go b/controller/api/v1alpha1/autogenagent_types.go index 786c61837..3a60adff8 100644 --- a/controller/api/v1alpha1/autogenagent_types.go +++ b/controller/api/v1alpha1/autogenagent_types.go @@ -26,7 +26,6 @@ import ( // AutogenAgentSpec defines the desired state of AutogenAgent. type AutogenAgentSpec struct { Name string `json:"name,omitempty"` - Type string `json:"type,omitempty"` Description string `json:"description,omitempty"` SystemMessage string `json:"systemMessage,omitempty"` Tools []string `json:"tools,omitempty"` diff --git a/controller/api/v1alpha1/autogenmodelconfig_types.go b/controller/api/v1alpha1/autogenmodelconfig_types.go index adbf75e82..0b995fb26 100644 --- a/controller/api/v1alpha1/autogenmodelconfig_types.go +++ b/controller/api/v1alpha1/autogenmodelconfig_types.go @@ -22,18 +22,9 @@ import ( // AutogenModelConfigSpec defines the desired state of AutogenModelConfig. type AutogenModelConfigSpec struct { - ModelType string `json:"modelType"` - Model string `json:"model"` - APIKeySecret string `json:"apiKeySecret"` - APIKeySecretKey string `json:"apiKeySecretKey"` - BaseURL string `json:"baseUrl"` - Capabilities AutogenModelCapabilities `json:"capabilities"` -} - -type AutogenModelCapabilities struct { - Vision bool `json:"vision"` - FunctionCalling bool `json:"functionCalling"` - JSONOutput bool `json:"jsonOutput"` + Model string `json:"model"` + APIKeySecret string `json:"apiKeySecret"` + APIKeySecretKey string `json:"apiKeySecretKey"` } // AutogenModelConfigStatus defines the observed state of AutogenModelConfig. diff --git a/controller/api/v1alpha1/autogenteam_types.go b/controller/api/v1alpha1/autogenteam_types.go index e5bf73c3e..a53f81705 100644 --- a/controller/api/v1alpha1/autogenteam_types.go +++ b/controller/api/v1alpha1/autogenteam_types.go @@ -26,7 +26,7 @@ import ( // AutogenTeamSpec defines the desired state of AutogenTeam. type AutogenTeamSpec struct { Participants []string `json:"participants"` - TeamType string `json:"teamType"` + Description string `json:"description"` SelectorTeamConfig SelectorTeamConfig `json:"selectorTeamConfig"` TerminationCondition TerminationCondition `json:"terminationCondition"` MaxTurns int64 `json:"maxTurns"` @@ -38,11 +38,22 @@ type SelectorTeamConfig struct { } type TerminationCondition struct { - MaxMessageTermination MaxMessageTermination `json:"maxMessageTermination"` + // ONEOF: maxMessageTermination, textMentionTermination, orTermination + MaxMessageTermination *MaxMessageTermination `json:"maxMessageTermination,omitempty"` + TextMentionTermination *TextMentionTermination `json:"textMentionTermination,omitempty"` + OrTermination *OrTermination `json:"orTermination,omitempty"` } type MaxMessageTermination struct { - MaxMessages int64 `json:"maxMessages"` + MaxMessages int `json:"maxMessages"` +} + +type TextMentionTermination struct { + Text string `json:"text"` +} + +type OrTermination struct { + Conditions []TerminationCondition `json:"conditions"` } // AutogenTeamStatus defines the observed state of AutogenTeam. diff --git a/controller/cmd/main.go b/controller/cmd/main.go index 0232b9356..72594114d 100644 --- a/controller/cmd/main.go +++ b/controller/cmd/main.go @@ -37,8 +37,8 @@ import ( metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" - agentv1alpha1 "ai.solo.io/kagent/api/v1alpha1" - "ai.solo.io/kagent/internal/controller" + agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" + "github.com/kagent-dev/kagent/controller/internal/controller" // +kubebuilder:scaffold:imports ) diff --git a/controller/go.mod b/controller/go.mod index 5e2401f72..98305cbab 100644 --- a/controller/go.mod +++ b/controller/go.mod @@ -1,10 +1,9 @@ module github.com/kagent-dev/kagent/controller -go 1.23.5 +go 1.23.3 require ( github.com/onsi/ginkgo/v2 v2.21.0 - github.com/onsi/gomega v1.35.1 k8s.io/apimachinery v0.32.0 k8s.io/client-go v0.32.0 sigs.k8s.io/controller-runtime v0.20.0 diff --git a/controller/internal/autogen/autogen_api_translator.go b/controller/internal/autogen/autogen_api_translator.go new file mode 100644 index 000000000..e0fb99485 --- /dev/null +++ b/controller/internal/autogen/autogen_api_translator.go @@ -0,0 +1,250 @@ +package autogen + +import ( + "context" + "fmt" + "github.com/kagent-dev/kagent/controller/api/v1alpha1" + "github.com/kagent-dev/kagent/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, + selectorTeamRef types.NamespacedName, + ) (*SelectorGroupChat, 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, + selectorTeamRef types.NamespacedName, +) (*SelectorGroupChat, error) { + // get selector team + selectorTeam := &v1alpha1.AutogenTeam{} + err := fetchObjKube( + ctx, + a.kube, + selectorTeam, + selectorTeamRef.Name, + selectorTeamRef.Namespace, + ) + if err != nil { + return nil, err + } + + // get model config + modelConfig := &v1alpha1.AutogenModelConfig{} + err = fetchObjKube( + ctx, + a.kube, + modelConfig, + selectorTeam.Spec.SelectorTeamConfig.ModelConfig, + selectorTeam.Namespace, + ) + if err != nil { + return nil, err + } + + // get model api key + modelApiKeySecret := &v1.Secret{} + err = fetchObjKube( + ctx, + a.kube, + modelApiKeySecret, + modelConfig.Spec.APIKeySecret, + selectorTeam.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 := ModelClient{ + Provider: "autogen_ext.models.openai.OpenAIChatCompletionClient", + ComponentType: "model", + Version: 1, + ComponentVersion: 1, + Config: ModelClientConfig{ + Model: modelConfig.Spec.Model, + ApiKey: string(modelApiKey), + }, + } + + var participants []GroupChatParticipant + for _, agentName := range selectorTeam.Spec.Participants { + agent := &v1alpha1.AutogenAgent{} + err := fetchObjKube( + ctx, + a.kube, + agent, + agentName, + selectorTeam.Namespace, + ) + if err != nil { + return nil, err + } + + //TODO: currently only supports builtin tools + var tools []GroupChatParticipantTool + 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 := GroupChatParticipantTool{ + Provider: "autogen_agentchat.tools.BuiltinTool", + ComponentType: "tool", + Version: 1, + ComponentVersion: 1, + Config: GroupChatParticipantToolConfig{ + FnName: fnName, + }, + } + tools = append(tools, tool) + } + + participant := GroupChatParticipant{ + //TODO: currently only supports assistant agents + Provider: "autogen_agentchat.agents.AssistantAgent", + ComponentType: "agent", + Version: 1, + ComponentVersion: 1, + Config: GroupChatParticipantConfig{ + Name: agent.Spec.Name, + ModelClient: modelClient, + Tools: tools, + ModelContext: ModelContext{ + Provider: "autogen_core.model_context.UnboundedChatCompletionContext", + ComponentType: "chat_completion_context", + Version: 1, + ComponentVersion: 1, + }, + Description: agent.Spec.Description, + SystemMessage: agent.Spec.SystemMessage, + ReflectOnToolUse: false, + ToolCallSummaryFormat: "{result}", + }, + } + participants = append(participants, participant) + } + + terminationCondition, err := translateTerminationCondition(selectorTeam.Spec.TerminationCondition) + if err != nil { + return nil, err + } + + return &SelectorGroupChat{ + Provider: "autogen_agentchat.teams.SelectorGroupChat", + ComponentType: "team", + Version: 1, + ComponentVersion: 1, + Description: selectorTeam.Spec.Description, + Config: SelectorGroupChatConfig{ + Participants: participants, + ModelClient: modelClient, + TerminationCondition: *terminationCondition, + SelectorPrompt: selectorTeam.Spec.SelectorTeamConfig.SelectorPrompt, + AllowRepeatedSpeaker: false, + }, + }, nil +} + +func translateTerminationCondition(terminationCondition v1alpha1.TerminationCondition) (*TerminationCondition, 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 &TerminationCondition{ + Provider: "autogen_agentchat.conditions.MaxMessageTermination", + ComponentType: "termination", + Version: 1, + ComponentVersion: 1, + Config: TerminationConditionConfig{ + MaxMessages: terminationCondition.MaxMessageTermination.MaxMessages, + }, + }, nil + case terminationCondition.TextMentionTermination != nil: + return &TerminationCondition{ + Provider: "autogen_agentchat.conditions.TextMentionTermination", + ComponentType: "termination", + Version: 1, + ComponentVersion: 1, + Config: TerminationConditionConfig{ + Text: terminationCondition.TextMentionTermination.Text, + }, + }, nil + case terminationCondition.OrTermination != nil: + var conditions []TerminationCondition + for _, c := range terminationCondition.OrTermination.Conditions { + condition, err := translateTerminationCondition(c) + if err != nil { + return nil, err + } + conditions = append(conditions, *condition) + } + return &TerminationCondition{ + Provider: "autogen_agentchat.conditions.OrTerminationCondition", + ComponentType: "termination", + Version: 1, + ComponentVersion: 1, + Config: TerminationConditionConfig{ + 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/controller/internal/autogen/autogen_config_types.go b/controller/internal/autogen/autogen_config_types.go new file mode 100644 index 000000000..96e71819a --- /dev/null +++ b/controller/internal/autogen/autogen_config_types.go @@ -0,0 +1,83 @@ +package autogen + +type SelectorGroupChat struct { + 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/controller/internal/controller/autogenagent_controller.go b/controller/internal/controller/autogenagent_controller.go index 6f197301b..af0680bd9 100644 --- a/controller/internal/controller/autogenagent_controller.go +++ b/controller/internal/controller/autogenagent_controller.go @@ -24,7 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - agentv1alpha1 "ai.solo.io/kagent/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" ) // AutogenAgentReconciler reconciles a AutogenAgent object diff --git a/controller/internal/controller/autogenagent_controller_test.go b/controller/internal/controller/autogenagent_controller_test.go index 2ef30598c..693937fd4 100644 --- a/controller/internal/controller/autogenagent_controller_test.go +++ b/controller/internal/controller/autogenagent_controller_test.go @@ -19,15 +19,13 @@ package controller import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" "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 "ai.solo.io/kagent/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" ) var _ = Describe("AutogenAgent Controller", func() { diff --git a/controller/internal/controller/autogenmodelconfig_controller.go b/controller/internal/controller/autogenmodelconfig_controller.go index b0d6ddc63..9129fee29 100644 --- a/controller/internal/controller/autogenmodelconfig_controller.go +++ b/controller/internal/controller/autogenmodelconfig_controller.go @@ -24,7 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - agentv1alpha1 "ai.solo.io/kagent/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" ) // AutogenModelConfigReconciler reconciles a AutogenModelConfig object diff --git a/controller/internal/controller/autogenmodelconfig_controller_test.go b/controller/internal/controller/autogenmodelconfig_controller_test.go index fb25fbc65..3e7e93129 100644 --- a/controller/internal/controller/autogenmodelconfig_controller_test.go +++ b/controller/internal/controller/autogenmodelconfig_controller_test.go @@ -19,15 +19,13 @@ package controller import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" "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 "ai.solo.io/kagent/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" ) var _ = Describe("AutogenModelConfig Controller", func() { diff --git a/controller/internal/controller/autogenteam_controller.go b/controller/internal/controller/autogenteam_controller.go index 8cc0c62ef..31dac4692 100644 --- a/controller/internal/controller/autogenteam_controller.go +++ b/controller/internal/controller/autogenteam_controller.go @@ -24,7 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - agentv1alpha1 "ai.solo.io/kagent/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" ) // AutogenTeamReconciler reconciles a AutogenTeam object diff --git a/controller/internal/controller/autogenteam_controller_test.go b/controller/internal/controller/autogenteam_controller_test.go index 03d2d0ae0..9a60007ba 100644 --- a/controller/internal/controller/autogenteam_controller_test.go +++ b/controller/internal/controller/autogenteam_controller_test.go @@ -19,15 +19,13 @@ package controller import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" "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 "ai.solo.io/kagent/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" ) var _ = Describe("AutogenTeam Controller", func() { diff --git a/controller/internal/controller/autogentool_controller.go b/controller/internal/controller/autogentool_controller.go index 6579f80d1..9e072c7fd 100644 --- a/controller/internal/controller/autogentool_controller.go +++ b/controller/internal/controller/autogentool_controller.go @@ -24,7 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - agentv1alpha1 "ai.solo.io/kagent/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" ) // AutogenToolReconciler reconciles a AutogenTool object diff --git a/controller/internal/controller/autogentool_controller_test.go b/controller/internal/controller/autogentool_controller_test.go index 508eb4805..58d68480e 100644 --- a/controller/internal/controller/autogentool_controller_test.go +++ b/controller/internal/controller/autogentool_controller_test.go @@ -19,15 +19,13 @@ package controller import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" "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 "ai.solo.io/kagent/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" ) var _ = Describe("AutogenTool Controller", func() { diff --git a/controller/internal/controller/suite_test.go b/controller/internal/controller/suite_test.go index 00918fa49..dd6ae2a2b 100644 --- a/controller/internal/controller/suite_test.go +++ b/controller/internal/controller/suite_test.go @@ -22,9 +22,6 @@ import ( "path/filepath" "testing" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/client" @@ -32,7 +29,7 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - agentv1alpha1 "ai.solo.io/kagent/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" // +kubebuilder:scaffold:imports ) diff --git a/controller/internal/utils/syncutils/sync_utils.go b/controller/internal/utils/syncutils/sync_utils.go new file mode 100644 index 000000000..8edc10ac6 --- /dev/null +++ b/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/controller/test/e2e/e2e_suite_test.go b/controller/test/e2e/e2e_suite_test.go index 7b3b4c6b2..2d02d47c2 100644 --- a/controller/test/e2e/e2e_suite_test.go +++ b/controller/test/e2e/e2e_suite_test.go @@ -25,7 +25,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "ai.solo.io/kagent/test/utils" + "github.com/kagent-dev/kagent/controller/test/utils" ) var ( diff --git a/controller/test/e2e/e2e_test.go b/controller/test/e2e/e2e_test.go index 14e324a63..cccea5c7a 100644 --- a/controller/test/e2e/e2e_test.go +++ b/controller/test/e2e/e2e_test.go @@ -27,7 +27,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "ai.solo.io/kagent/test/utils" + "github.com/kagent-dev/kagent/controller/test/utils" ) // namespace where the project is deployed in From 52cd651f91170d7016d3d39c4404033d8efe5fcd Mon Sep 17 00:00:00 2001 From: Scott Weiss Date: Tue, 28 Jan 2025 12:52:22 -0500 Subject: [PATCH 04/12] regen --- .../bases/agent.ai.solo.io_autogenagents.yaml | 60 +++++++++++ .../agent.ai.solo.io_autogenmodelconfigs.yaml | 61 +++++++++++ .../bases/agent.ai.solo.io_autogenteams.yaml | 102 ++++++++++++++++++ .../bases/agent.ai.solo.io_autogentools.yaml | 52 +++++++++ controller/config/rbac/role.yaml | 42 ++++++-- 5 files changed, 311 insertions(+), 6 deletions(-) create mode 100644 controller/config/crd/bases/agent.ai.solo.io_autogenagents.yaml create mode 100644 controller/config/crd/bases/agent.ai.solo.io_autogenmodelconfigs.yaml create mode 100644 controller/config/crd/bases/agent.ai.solo.io_autogenteams.yaml create mode 100644 controller/config/crd/bases/agent.ai.solo.io_autogentools.yaml diff --git a/controller/config/crd/bases/agent.ai.solo.io_autogenagents.yaml b/controller/config/crd/bases/agent.ai.solo.io_autogenagents.yaml new file mode 100644 index 000000000..4551034f1 --- /dev/null +++ b/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/controller/config/crd/bases/agent.ai.solo.io_autogenmodelconfigs.yaml b/controller/config/crd/bases/agent.ai.solo.io_autogenmodelconfigs.yaml new file mode 100644 index 000000000..eabef33b8 --- /dev/null +++ b/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: + apiKeySecret: + type: string + apiKeySecretKey: + type: string + model: + type: string + required: + - apiKeySecret + - apiKeySecretKey + - 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/controller/config/crd/bases/agent.ai.solo.io_autogenteams.yaml b/controller/config/crd/bases/agent.ai.solo.io_autogenteams.yaml new file mode 100644 index 000000000..65ab7a9bb --- /dev/null +++ b/controller/config/crd/bases/agent.ai.solo.io_autogenteams.yaml @@ -0,0 +1,102 @@ +--- +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: {} + type: array + required: + - conditions + type: object + textMentionTermination: + properties: + text: + type: string + required: + - text + type: object + type: object + 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/controller/config/crd/bases/agent.ai.solo.io_autogentools.yaml b/controller/config/crd/bases/agent.ai.solo.io_autogentools.yaml new file mode 100644 index 000000000..459054f12 --- /dev/null +++ b/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/controller/config/rbac/role.yaml b/controller/config/rbac/role.yaml index 0dbb930c5..26e2f74a7 100644 --- a/controller/config/rbac/role.yaml +++ b/controller/config/rbac/role.yaml @@ -1,11 +1,41 @@ +--- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - labels: - app.kubernetes.io/name: controller - app.kubernetes.io/managed-by: kustomize name: manager-role rules: -- apiGroups: [""] - resources: ["pods"] - verbs: ["get", "list", "watch"] +- 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 From a4044f13ff9ad054bbe3d8d227335c3b199e1898 Mon Sep 17 00:00:00 2001 From: Scott Weiss Date: Thu, 30 Jan 2025 17:40:22 -0500 Subject: [PATCH 05/12] wip: translation tweaks, api --- .../api/v1alpha1/zz_generated.deepcopy.go | 105 +++++++++++++++++- controller/go.mod | 7 +- .../autogen/autogen_api_translator.go | 11 ++ .../internal/autogen/autogen_config_types.go | 2 + 4 files changed, 121 insertions(+), 4 deletions(-) diff --git a/controller/api/v1alpha1/zz_generated.deepcopy.go b/controller/api/v1alpha1/zz_generated.deepcopy.go index 0c1189ad1..b486f7984 100644 --- a/controller/api/v1alpha1/zz_generated.deepcopy.go +++ b/controller/api/v1alpha1/zz_generated.deepcopy.go @@ -269,7 +269,13 @@ func (in *AutogenTeamList) DeepCopyObject() runtime.Object { // 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 - in.Selector.DeepCopyInto(&out.Selector) + 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. @@ -385,3 +391,100 @@ func (in *AutogenToolStatus) DeepCopy() *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([]TerminationCondition, 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 *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/controller/go.mod b/controller/go.mod index 98305cbab..10e089a57 100644 --- a/controller/go.mod +++ b/controller/go.mod @@ -4,6 +4,10 @@ go 1.23.3 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 + golang.org/x/oauth2 v0.23.0 + 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 @@ -66,9 +70,7 @@ require ( 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/exp v0.0.0-20240719175910-8a7402abbf56 // 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 @@ -83,7 +85,6 @@ require ( 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/api v0.32.0 // indirect k8s.io/apiextensions-apiserver v0.32.0 // indirect k8s.io/apiserver v0.32.0 // indirect k8s.io/component-base v0.32.0 // indirect diff --git a/controller/internal/autogen/autogen_api_translator.go b/controller/internal/autogen/autogen_api_translator.go index e0fb99485..5f30eb5d1 100644 --- a/controller/internal/autogen/autogen_api_translator.go +++ b/controller/internal/autogen/autogen_api_translator.go @@ -2,6 +2,8 @@ package autogen import ( "context" + "crypto/sha256" + "encoding/binary" "fmt" "github.com/kagent-dev/kagent/controller/api/v1alpha1" "github.com/kagent-dev/kagent/controller/internal/utils/syncutils" @@ -163,6 +165,8 @@ func (a *autogenApiTranslator) TranslateSelectorGroupChat( } return &SelectorGroupChat{ + ID: generateIdFromString(selectorTeam.Name + "-" + selectorTeam.Namespace), + UserID: "guestuser@gmail.com", // always use global id Provider: "autogen_agentchat.teams.SelectorGroupChat", ComponentType: "team", Version: 1, @@ -178,6 +182,13 @@ func (a *autogenApiTranslator) TranslateSelectorGroupChat( }, nil } +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) (*TerminationCondition, error) { // ensure only one termination condition is set var conditionsSet int diff --git a/controller/internal/autogen/autogen_config_types.go b/controller/internal/autogen/autogen_config_types.go index 96e71819a..7430d7182 100644 --- a/controller/internal/autogen/autogen_config_types.go +++ b/controller/internal/autogen/autogen_config_types.go @@ -1,6 +1,8 @@ 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"` From 9db5fc5a2ace26abc43d9b8dc0cde074b25b1d25 Mon Sep 17 00:00:00 2001 From: Scott Weiss Date: Thu, 30 Jan 2025 20:29:49 -0500 Subject: [PATCH 06/12] move controller --- go/autogen/api/client.go | 116 +++++++ go/autogen/api/run.go | 37 ++ go/autogen/api/session.go | 25 ++ go/autogen/api/team.go | 32 ++ go/autogen/api/types.go | 316 ++++++++++++++++++ .../.devcontainer/devcontainer.json | 0 .../controller}/.devcontainer/post-install.sh | 0 {controller => go/controller}/.dockerignore | 0 .../controller}/.github/workflows/lint.yml | 0 .../.github/workflows/test-e2e.yml | 0 .../controller}/.github/workflows/test.yml | 0 {controller => go/controller}/.gitignore | 0 {controller => go/controller}/.golangci.yml | 0 {controller => go/controller}/Dockerfile | 0 {controller => go/controller}/Makefile | 0 {controller => go/controller}/PROJECT | 10 +- {controller => go/controller}/README.md | 0 .../api/v1alpha1/autogenagent_types.go | 0 .../api/v1alpha1/autogenmodelconfig_types.go | 0 .../api/v1alpha1/autogenteam_types.go | 0 .../api/v1alpha1/autogentool_types.go | 0 .../api/v1alpha1/groupversion_info.go | 0 .../api/v1alpha1/zz_generated.deepcopy.go | 0 {controller => go/controller}/cmd/main.go | 4 +- .../bases/agent.ai.solo.io_autogenagents.yaml | 0 .../agent.ai.solo.io_autogenmodelconfigs.yaml | 0 .../bases/agent.ai.solo.io_autogenteams.yaml | 0 .../bases/agent.ai.solo.io_autogentools.yaml | 0 .../controller}/config/crd/kustomization.yaml | 0 .../config/crd/kustomizeconfig.yaml | 0 .../default/cert_metrics_manager_patch.yaml | 0 .../config/default/kustomization.yaml | 0 .../config/default/manager_metrics_patch.yaml | 0 .../config/default/metrics_service.yaml | 0 .../config/manager/kustomization.yaml | 0 .../controller}/config/manager/manager.yaml | 0 .../network-policy/allow-metrics-traffic.yaml | 0 .../config/network-policy/kustomization.yaml | 0 .../config/prometheus/kustomization.yaml | 0 .../config/prometheus/monitor.yaml | 0 .../config/prometheus/monitor_tls_patch.yaml | 0 .../config/rbac/autogenagent_admin_role.yaml | 0 .../config/rbac/autogenagent_editor_role.yaml | 0 .../config/rbac/autogenagent_viewer_role.yaml | 0 .../rbac/autogenmodelconfig_admin_role.yaml | 0 .../rbac/autogenmodelconfig_editor_role.yaml | 0 .../rbac/autogenmodelconfig_viewer_role.yaml | 0 .../config/rbac/autogenteam_admin_role.yaml | 0 .../config/rbac/autogenteam_editor_role.yaml | 0 .../config/rbac/autogenteam_viewer_role.yaml | 0 .../config/rbac/autogentool_admin_role.yaml | 0 .../config/rbac/autogentool_editor_role.yaml | 0 .../config/rbac/autogentool_viewer_role.yaml | 0 .../config/rbac/kustomization.yaml | 0 .../config/rbac/leader_election_role.yaml | 0 .../rbac/leader_election_role_binding.yaml | 0 .../config/rbac/metrics_auth_role.yaml | 0 .../rbac/metrics_auth_role_binding.yaml | 0 .../config/rbac/metrics_reader_role.yaml | 0 .../controller}/config/rbac/role.yaml | 0 .../controller}/config/rbac/role_binding.yaml | 0 .../config/rbac/service_account.yaml | 0 .../samples/agent_v1alpha1_autogenagent.yaml | 0 .../agent_v1alpha1_autogenmodelconfig.yaml | 0 .../samples/agent_v1alpha1_autogenteam.yaml | 0 .../samples/agent_v1alpha1_autogentool.yaml | 0 .../config/samples/kustomization.yaml | 0 .../controller}/hack/boilerplate.go.txt | 0 .../autogen/autogen_api_translator.go | 7 +- .../internal/autogen/autogen_config_types.go | 0 .../internal/autogen/autogen_suite_test.go | 13 + .../autogen/autogen_translator_test.go | 52 +++ .../controller/autogenagent_controller.go | 2 +- .../autogenagent_controller_test.go | 2 +- .../autogenmodelconfig_controller.go | 2 +- .../autogenmodelconfig_controller_test.go | 2 +- .../controller/autogenteam_controller.go | 2 +- .../controller/autogenteam_controller_test.go | 2 +- .../controller/autogentool_controller.go | 2 +- .../controller/autogentool_controller_test.go | 2 +- .../internal/controller/suite_test.go | 2 +- .../internal/utils/syncutils/sync_utils.go | 0 .../controller}/test/e2e/e2e_suite_test.go | 2 +- .../controller}/test/e2e/e2e_test.go | 2 +- .../controller}/test/utils/utils.go | 0 {controller => go}/go.mod | 4 +- {controller => go}/go.sum | 0 87 files changed, 615 insertions(+), 23 deletions(-) create mode 100644 go/autogen/api/client.go create mode 100644 go/autogen/api/run.go create mode 100644 go/autogen/api/session.go create mode 100644 go/autogen/api/team.go create mode 100644 go/autogen/api/types.go rename {controller => go/controller}/.devcontainer/devcontainer.json (100%) rename {controller => go/controller}/.devcontainer/post-install.sh (100%) rename {controller => go/controller}/.dockerignore (100%) rename {controller => go/controller}/.github/workflows/lint.yml (100%) rename {controller => go/controller}/.github/workflows/test-e2e.yml (100%) rename {controller => go/controller}/.github/workflows/test.yml (100%) rename {controller => go/controller}/.gitignore (100%) rename {controller => go/controller}/.golangci.yml (100%) rename {controller => go/controller}/Dockerfile (100%) rename {controller => go/controller}/Makefile (100%) rename {controller => go/controller}/PROJECT (74%) rename {controller => go/controller}/README.md (100%) rename {controller => go/controller}/api/v1alpha1/autogenagent_types.go (100%) rename {controller => go/controller}/api/v1alpha1/autogenmodelconfig_types.go (100%) rename {controller => go/controller}/api/v1alpha1/autogenteam_types.go (100%) rename {controller => go/controller}/api/v1alpha1/autogentool_types.go (100%) rename {controller => go/controller}/api/v1alpha1/groupversion_info.go (100%) rename {controller => go/controller}/api/v1alpha1/zz_generated.deepcopy.go (100%) rename {controller => go/controller}/cmd/main.go (98%) rename {controller => go/controller}/config/crd/bases/agent.ai.solo.io_autogenagents.yaml (100%) rename {controller => go/controller}/config/crd/bases/agent.ai.solo.io_autogenmodelconfigs.yaml (100%) rename {controller => go/controller}/config/crd/bases/agent.ai.solo.io_autogenteams.yaml (100%) rename {controller => go/controller}/config/crd/bases/agent.ai.solo.io_autogentools.yaml (100%) rename {controller => go/controller}/config/crd/kustomization.yaml (100%) rename {controller => go/controller}/config/crd/kustomizeconfig.yaml (100%) rename {controller => go/controller}/config/default/cert_metrics_manager_patch.yaml (100%) rename {controller => go/controller}/config/default/kustomization.yaml (100%) rename {controller => go/controller}/config/default/manager_metrics_patch.yaml (100%) rename {controller => go/controller}/config/default/metrics_service.yaml (100%) rename {controller => go/controller}/config/manager/kustomization.yaml (100%) rename {controller => go/controller}/config/manager/manager.yaml (100%) rename {controller => go/controller}/config/network-policy/allow-metrics-traffic.yaml (100%) rename {controller => go/controller}/config/network-policy/kustomization.yaml (100%) rename {controller => go/controller}/config/prometheus/kustomization.yaml (100%) rename {controller => go/controller}/config/prometheus/monitor.yaml (100%) rename {controller => go/controller}/config/prometheus/monitor_tls_patch.yaml (100%) rename {controller => go/controller}/config/rbac/autogenagent_admin_role.yaml (100%) rename {controller => go/controller}/config/rbac/autogenagent_editor_role.yaml (100%) rename {controller => go/controller}/config/rbac/autogenagent_viewer_role.yaml (100%) rename {controller => go/controller}/config/rbac/autogenmodelconfig_admin_role.yaml (100%) rename {controller => go/controller}/config/rbac/autogenmodelconfig_editor_role.yaml (100%) rename {controller => go/controller}/config/rbac/autogenmodelconfig_viewer_role.yaml (100%) rename {controller => go/controller}/config/rbac/autogenteam_admin_role.yaml (100%) rename {controller => go/controller}/config/rbac/autogenteam_editor_role.yaml (100%) rename {controller => go/controller}/config/rbac/autogenteam_viewer_role.yaml (100%) rename {controller => go/controller}/config/rbac/autogentool_admin_role.yaml (100%) rename {controller => go/controller}/config/rbac/autogentool_editor_role.yaml (100%) rename {controller => go/controller}/config/rbac/autogentool_viewer_role.yaml (100%) rename {controller => go/controller}/config/rbac/kustomization.yaml (100%) rename {controller => go/controller}/config/rbac/leader_election_role.yaml (100%) rename {controller => go/controller}/config/rbac/leader_election_role_binding.yaml (100%) rename {controller => go/controller}/config/rbac/metrics_auth_role.yaml (100%) rename {controller => go/controller}/config/rbac/metrics_auth_role_binding.yaml (100%) rename {controller => go/controller}/config/rbac/metrics_reader_role.yaml (100%) rename {controller => go/controller}/config/rbac/role.yaml (100%) rename {controller => go/controller}/config/rbac/role_binding.yaml (100%) rename {controller => go/controller}/config/rbac/service_account.yaml (100%) rename {controller => go/controller}/config/samples/agent_v1alpha1_autogenagent.yaml (100%) rename {controller => go/controller}/config/samples/agent_v1alpha1_autogenmodelconfig.yaml (100%) rename {controller => go/controller}/config/samples/agent_v1alpha1_autogenteam.yaml (100%) rename {controller => go/controller}/config/samples/agent_v1alpha1_autogentool.yaml (100%) rename {controller => go/controller}/config/samples/kustomization.yaml (100%) rename {controller => go/controller}/hack/boilerplate.go.txt (100%) rename {controller => go/controller}/internal/autogen/autogen_api_translator.go (97%) rename {controller => go/controller}/internal/autogen/autogen_config_types.go (100%) create mode 100644 go/controller/internal/autogen/autogen_suite_test.go create mode 100644 go/controller/internal/autogen/autogen_translator_test.go rename {controller => go/controller}/internal/controller/autogenagent_controller.go (96%) rename {controller => go/controller}/internal/controller/autogenagent_controller_test.go (97%) rename {controller => go/controller}/internal/controller/autogenmodelconfig_controller.go (96%) rename {controller => go/controller}/internal/controller/autogenmodelconfig_controller_test.go (97%) rename {controller => go/controller}/internal/controller/autogenteam_controller.go (96%) rename {controller => go/controller}/internal/controller/autogenteam_controller_test.go (97%) rename {controller => go/controller}/internal/controller/autogentool_controller.go (96%) rename {controller => go/controller}/internal/controller/autogentool_controller_test.go (97%) rename {controller => go/controller}/internal/controller/suite_test.go (97%) rename {controller => go/controller}/internal/utils/syncutils/sync_utils.go (100%) rename {controller => go/controller}/test/e2e/e2e_suite_test.go (98%) rename {controller => go/controller}/test/e2e/e2e_test.go (99%) rename {controller => go/controller}/test/utils/utils.go (100%) rename {controller => go}/go.mod (98%) rename {controller => go}/go.sum (100%) 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..99bb59b10 --- /dev/null +++ b/go/autogen/api/types.go @@ -0,0 +1,316 @@ +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"` +} + +// TeamResponse represents the full team response structure +type TeamResponse struct { + ID int `json:"id"` + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` + 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"` +} + +// 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/controller/.devcontainer/devcontainer.json b/go/controller/.devcontainer/devcontainer.json similarity index 100% rename from controller/.devcontainer/devcontainer.json rename to go/controller/.devcontainer/devcontainer.json diff --git a/controller/.devcontainer/post-install.sh b/go/controller/.devcontainer/post-install.sh similarity index 100% rename from controller/.devcontainer/post-install.sh rename to go/controller/.devcontainer/post-install.sh diff --git a/controller/.dockerignore b/go/controller/.dockerignore similarity index 100% rename from controller/.dockerignore rename to go/controller/.dockerignore diff --git a/controller/.github/workflows/lint.yml b/go/controller/.github/workflows/lint.yml similarity index 100% rename from controller/.github/workflows/lint.yml rename to go/controller/.github/workflows/lint.yml diff --git a/controller/.github/workflows/test-e2e.yml b/go/controller/.github/workflows/test-e2e.yml similarity index 100% rename from controller/.github/workflows/test-e2e.yml rename to go/controller/.github/workflows/test-e2e.yml diff --git a/controller/.github/workflows/test.yml b/go/controller/.github/workflows/test.yml similarity index 100% rename from controller/.github/workflows/test.yml rename to go/controller/.github/workflows/test.yml diff --git a/controller/.gitignore b/go/controller/.gitignore similarity index 100% rename from controller/.gitignore rename to go/controller/.gitignore diff --git a/controller/.golangci.yml b/go/controller/.golangci.yml similarity index 100% rename from controller/.golangci.yml rename to go/controller/.golangci.yml diff --git a/controller/Dockerfile b/go/controller/Dockerfile similarity index 100% rename from controller/Dockerfile rename to go/controller/Dockerfile diff --git a/controller/Makefile b/go/controller/Makefile similarity index 100% rename from controller/Makefile rename to go/controller/Makefile diff --git a/controller/PROJECT b/go/controller/PROJECT similarity index 74% rename from controller/PROJECT rename to go/controller/PROJECT index b7c826d5f..caddd4461 100644 --- a/controller/PROJECT +++ b/go/controller/PROJECT @@ -6,7 +6,7 @@ domain: ai.solo.io layout: - go.kubebuilder.io/v4 projectName: controller -repo: github.com/kagent-dev/kagent/controller +repo: github.com/kagent-dev/kagent/go/controller resources: - api: crdVersion: v1 @@ -15,7 +15,7 @@ resources: domain: ai.solo.io group: agent kind: AutogenTeam - path: github.com/kagent-dev/kagent/controller/api/v1alpha1 + path: github.com/kagent-dev/kagent/go/controller/api/v1alpha1 version: v1alpha1 - api: crdVersion: v1 @@ -24,7 +24,7 @@ resources: domain: ai.solo.io group: agent kind: AutogenAgent - path: github.com/kagent-dev/kagent/controller/api/v1alpha1 + path: github.com/kagent-dev/kagent/go/controller/api/v1alpha1 version: v1alpha1 - api: crdVersion: v1 @@ -33,7 +33,7 @@ resources: domain: ai.solo.io group: agent kind: AutogenTool - path: github.com/kagent-dev/kagent/controller/api/v1alpha1 + path: github.com/kagent-dev/kagent/go/controller/api/v1alpha1 version: v1alpha1 - api: crdVersion: v1 @@ -42,6 +42,6 @@ resources: domain: ai.solo.io group: agent kind: AutogenModelConfig - path: github.com/kagent-dev/kagent/controller/api/v1alpha1 + path: github.com/kagent-dev/kagent/go/controller/api/v1alpha1 version: v1alpha1 version: "3" diff --git a/controller/README.md b/go/controller/README.md similarity index 100% rename from controller/README.md rename to go/controller/README.md diff --git a/controller/api/v1alpha1/autogenagent_types.go b/go/controller/api/v1alpha1/autogenagent_types.go similarity index 100% rename from controller/api/v1alpha1/autogenagent_types.go rename to go/controller/api/v1alpha1/autogenagent_types.go diff --git a/controller/api/v1alpha1/autogenmodelconfig_types.go b/go/controller/api/v1alpha1/autogenmodelconfig_types.go similarity index 100% rename from controller/api/v1alpha1/autogenmodelconfig_types.go rename to go/controller/api/v1alpha1/autogenmodelconfig_types.go diff --git a/controller/api/v1alpha1/autogenteam_types.go b/go/controller/api/v1alpha1/autogenteam_types.go similarity index 100% rename from controller/api/v1alpha1/autogenteam_types.go rename to go/controller/api/v1alpha1/autogenteam_types.go diff --git a/controller/api/v1alpha1/autogentool_types.go b/go/controller/api/v1alpha1/autogentool_types.go similarity index 100% rename from controller/api/v1alpha1/autogentool_types.go rename to go/controller/api/v1alpha1/autogentool_types.go diff --git a/controller/api/v1alpha1/groupversion_info.go b/go/controller/api/v1alpha1/groupversion_info.go similarity index 100% rename from controller/api/v1alpha1/groupversion_info.go rename to go/controller/api/v1alpha1/groupversion_info.go diff --git a/controller/api/v1alpha1/zz_generated.deepcopy.go b/go/controller/api/v1alpha1/zz_generated.deepcopy.go similarity index 100% rename from controller/api/v1alpha1/zz_generated.deepcopy.go rename to go/controller/api/v1alpha1/zz_generated.deepcopy.go diff --git a/controller/cmd/main.go b/go/controller/cmd/main.go similarity index 98% rename from controller/cmd/main.go rename to go/controller/cmd/main.go index 72594114d..59ee8c851 100644 --- a/controller/cmd/main.go +++ b/go/controller/cmd/main.go @@ -37,8 +37,8 @@ import ( metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" - agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" - "github.com/kagent-dev/kagent/controller/internal/controller" + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" + "github.com/kagent-dev/kagent/go/controller/internal/controller" // +kubebuilder:scaffold:imports ) diff --git a/controller/config/crd/bases/agent.ai.solo.io_autogenagents.yaml b/go/controller/config/crd/bases/agent.ai.solo.io_autogenagents.yaml similarity index 100% rename from controller/config/crd/bases/agent.ai.solo.io_autogenagents.yaml rename to go/controller/config/crd/bases/agent.ai.solo.io_autogenagents.yaml diff --git a/controller/config/crd/bases/agent.ai.solo.io_autogenmodelconfigs.yaml b/go/controller/config/crd/bases/agent.ai.solo.io_autogenmodelconfigs.yaml similarity index 100% rename from controller/config/crd/bases/agent.ai.solo.io_autogenmodelconfigs.yaml rename to go/controller/config/crd/bases/agent.ai.solo.io_autogenmodelconfigs.yaml diff --git a/controller/config/crd/bases/agent.ai.solo.io_autogenteams.yaml b/go/controller/config/crd/bases/agent.ai.solo.io_autogenteams.yaml similarity index 100% rename from controller/config/crd/bases/agent.ai.solo.io_autogenteams.yaml rename to go/controller/config/crd/bases/agent.ai.solo.io_autogenteams.yaml diff --git a/controller/config/crd/bases/agent.ai.solo.io_autogentools.yaml b/go/controller/config/crd/bases/agent.ai.solo.io_autogentools.yaml similarity index 100% rename from controller/config/crd/bases/agent.ai.solo.io_autogentools.yaml rename to go/controller/config/crd/bases/agent.ai.solo.io_autogentools.yaml diff --git a/controller/config/crd/kustomization.yaml b/go/controller/config/crd/kustomization.yaml similarity index 100% rename from controller/config/crd/kustomization.yaml rename to go/controller/config/crd/kustomization.yaml diff --git a/controller/config/crd/kustomizeconfig.yaml b/go/controller/config/crd/kustomizeconfig.yaml similarity index 100% rename from controller/config/crd/kustomizeconfig.yaml rename to go/controller/config/crd/kustomizeconfig.yaml diff --git a/controller/config/default/cert_metrics_manager_patch.yaml b/go/controller/config/default/cert_metrics_manager_patch.yaml similarity index 100% rename from controller/config/default/cert_metrics_manager_patch.yaml rename to go/controller/config/default/cert_metrics_manager_patch.yaml diff --git a/controller/config/default/kustomization.yaml b/go/controller/config/default/kustomization.yaml similarity index 100% rename from controller/config/default/kustomization.yaml rename to go/controller/config/default/kustomization.yaml diff --git a/controller/config/default/manager_metrics_patch.yaml b/go/controller/config/default/manager_metrics_patch.yaml similarity index 100% rename from controller/config/default/manager_metrics_patch.yaml rename to go/controller/config/default/manager_metrics_patch.yaml diff --git a/controller/config/default/metrics_service.yaml b/go/controller/config/default/metrics_service.yaml similarity index 100% rename from controller/config/default/metrics_service.yaml rename to go/controller/config/default/metrics_service.yaml diff --git a/controller/config/manager/kustomization.yaml b/go/controller/config/manager/kustomization.yaml similarity index 100% rename from controller/config/manager/kustomization.yaml rename to go/controller/config/manager/kustomization.yaml diff --git a/controller/config/manager/manager.yaml b/go/controller/config/manager/manager.yaml similarity index 100% rename from controller/config/manager/manager.yaml rename to go/controller/config/manager/manager.yaml diff --git a/controller/config/network-policy/allow-metrics-traffic.yaml b/go/controller/config/network-policy/allow-metrics-traffic.yaml similarity index 100% rename from controller/config/network-policy/allow-metrics-traffic.yaml rename to go/controller/config/network-policy/allow-metrics-traffic.yaml diff --git a/controller/config/network-policy/kustomization.yaml b/go/controller/config/network-policy/kustomization.yaml similarity index 100% rename from controller/config/network-policy/kustomization.yaml rename to go/controller/config/network-policy/kustomization.yaml diff --git a/controller/config/prometheus/kustomization.yaml b/go/controller/config/prometheus/kustomization.yaml similarity index 100% rename from controller/config/prometheus/kustomization.yaml rename to go/controller/config/prometheus/kustomization.yaml diff --git a/controller/config/prometheus/monitor.yaml b/go/controller/config/prometheus/monitor.yaml similarity index 100% rename from controller/config/prometheus/monitor.yaml rename to go/controller/config/prometheus/monitor.yaml diff --git a/controller/config/prometheus/monitor_tls_patch.yaml b/go/controller/config/prometheus/monitor_tls_patch.yaml similarity index 100% rename from controller/config/prometheus/monitor_tls_patch.yaml rename to go/controller/config/prometheus/monitor_tls_patch.yaml diff --git a/controller/config/rbac/autogenagent_admin_role.yaml b/go/controller/config/rbac/autogenagent_admin_role.yaml similarity index 100% rename from controller/config/rbac/autogenagent_admin_role.yaml rename to go/controller/config/rbac/autogenagent_admin_role.yaml diff --git a/controller/config/rbac/autogenagent_editor_role.yaml b/go/controller/config/rbac/autogenagent_editor_role.yaml similarity index 100% rename from controller/config/rbac/autogenagent_editor_role.yaml rename to go/controller/config/rbac/autogenagent_editor_role.yaml diff --git a/controller/config/rbac/autogenagent_viewer_role.yaml b/go/controller/config/rbac/autogenagent_viewer_role.yaml similarity index 100% rename from controller/config/rbac/autogenagent_viewer_role.yaml rename to go/controller/config/rbac/autogenagent_viewer_role.yaml diff --git a/controller/config/rbac/autogenmodelconfig_admin_role.yaml b/go/controller/config/rbac/autogenmodelconfig_admin_role.yaml similarity index 100% rename from controller/config/rbac/autogenmodelconfig_admin_role.yaml rename to go/controller/config/rbac/autogenmodelconfig_admin_role.yaml diff --git a/controller/config/rbac/autogenmodelconfig_editor_role.yaml b/go/controller/config/rbac/autogenmodelconfig_editor_role.yaml similarity index 100% rename from controller/config/rbac/autogenmodelconfig_editor_role.yaml rename to go/controller/config/rbac/autogenmodelconfig_editor_role.yaml diff --git a/controller/config/rbac/autogenmodelconfig_viewer_role.yaml b/go/controller/config/rbac/autogenmodelconfig_viewer_role.yaml similarity index 100% rename from controller/config/rbac/autogenmodelconfig_viewer_role.yaml rename to go/controller/config/rbac/autogenmodelconfig_viewer_role.yaml diff --git a/controller/config/rbac/autogenteam_admin_role.yaml b/go/controller/config/rbac/autogenteam_admin_role.yaml similarity index 100% rename from controller/config/rbac/autogenteam_admin_role.yaml rename to go/controller/config/rbac/autogenteam_admin_role.yaml diff --git a/controller/config/rbac/autogenteam_editor_role.yaml b/go/controller/config/rbac/autogenteam_editor_role.yaml similarity index 100% rename from controller/config/rbac/autogenteam_editor_role.yaml rename to go/controller/config/rbac/autogenteam_editor_role.yaml diff --git a/controller/config/rbac/autogenteam_viewer_role.yaml b/go/controller/config/rbac/autogenteam_viewer_role.yaml similarity index 100% rename from controller/config/rbac/autogenteam_viewer_role.yaml rename to go/controller/config/rbac/autogenteam_viewer_role.yaml diff --git a/controller/config/rbac/autogentool_admin_role.yaml b/go/controller/config/rbac/autogentool_admin_role.yaml similarity index 100% rename from controller/config/rbac/autogentool_admin_role.yaml rename to go/controller/config/rbac/autogentool_admin_role.yaml diff --git a/controller/config/rbac/autogentool_editor_role.yaml b/go/controller/config/rbac/autogentool_editor_role.yaml similarity index 100% rename from controller/config/rbac/autogentool_editor_role.yaml rename to go/controller/config/rbac/autogentool_editor_role.yaml diff --git a/controller/config/rbac/autogentool_viewer_role.yaml b/go/controller/config/rbac/autogentool_viewer_role.yaml similarity index 100% rename from controller/config/rbac/autogentool_viewer_role.yaml rename to go/controller/config/rbac/autogentool_viewer_role.yaml diff --git a/controller/config/rbac/kustomization.yaml b/go/controller/config/rbac/kustomization.yaml similarity index 100% rename from controller/config/rbac/kustomization.yaml rename to go/controller/config/rbac/kustomization.yaml diff --git a/controller/config/rbac/leader_election_role.yaml b/go/controller/config/rbac/leader_election_role.yaml similarity index 100% rename from controller/config/rbac/leader_election_role.yaml rename to go/controller/config/rbac/leader_election_role.yaml diff --git a/controller/config/rbac/leader_election_role_binding.yaml b/go/controller/config/rbac/leader_election_role_binding.yaml similarity index 100% rename from controller/config/rbac/leader_election_role_binding.yaml rename to go/controller/config/rbac/leader_election_role_binding.yaml diff --git a/controller/config/rbac/metrics_auth_role.yaml b/go/controller/config/rbac/metrics_auth_role.yaml similarity index 100% rename from controller/config/rbac/metrics_auth_role.yaml rename to go/controller/config/rbac/metrics_auth_role.yaml diff --git a/controller/config/rbac/metrics_auth_role_binding.yaml b/go/controller/config/rbac/metrics_auth_role_binding.yaml similarity index 100% rename from controller/config/rbac/metrics_auth_role_binding.yaml rename to go/controller/config/rbac/metrics_auth_role_binding.yaml diff --git a/controller/config/rbac/metrics_reader_role.yaml b/go/controller/config/rbac/metrics_reader_role.yaml similarity index 100% rename from controller/config/rbac/metrics_reader_role.yaml rename to go/controller/config/rbac/metrics_reader_role.yaml diff --git a/controller/config/rbac/role.yaml b/go/controller/config/rbac/role.yaml similarity index 100% rename from controller/config/rbac/role.yaml rename to go/controller/config/rbac/role.yaml diff --git a/controller/config/rbac/role_binding.yaml b/go/controller/config/rbac/role_binding.yaml similarity index 100% rename from controller/config/rbac/role_binding.yaml rename to go/controller/config/rbac/role_binding.yaml diff --git a/controller/config/rbac/service_account.yaml b/go/controller/config/rbac/service_account.yaml similarity index 100% rename from controller/config/rbac/service_account.yaml rename to go/controller/config/rbac/service_account.yaml diff --git a/controller/config/samples/agent_v1alpha1_autogenagent.yaml b/go/controller/config/samples/agent_v1alpha1_autogenagent.yaml similarity index 100% rename from controller/config/samples/agent_v1alpha1_autogenagent.yaml rename to go/controller/config/samples/agent_v1alpha1_autogenagent.yaml diff --git a/controller/config/samples/agent_v1alpha1_autogenmodelconfig.yaml b/go/controller/config/samples/agent_v1alpha1_autogenmodelconfig.yaml similarity index 100% rename from controller/config/samples/agent_v1alpha1_autogenmodelconfig.yaml rename to go/controller/config/samples/agent_v1alpha1_autogenmodelconfig.yaml diff --git a/controller/config/samples/agent_v1alpha1_autogenteam.yaml b/go/controller/config/samples/agent_v1alpha1_autogenteam.yaml similarity index 100% rename from controller/config/samples/agent_v1alpha1_autogenteam.yaml rename to go/controller/config/samples/agent_v1alpha1_autogenteam.yaml diff --git a/controller/config/samples/agent_v1alpha1_autogentool.yaml b/go/controller/config/samples/agent_v1alpha1_autogentool.yaml similarity index 100% rename from controller/config/samples/agent_v1alpha1_autogentool.yaml rename to go/controller/config/samples/agent_v1alpha1_autogentool.yaml diff --git a/controller/config/samples/kustomization.yaml b/go/controller/config/samples/kustomization.yaml similarity index 100% rename from controller/config/samples/kustomization.yaml rename to go/controller/config/samples/kustomization.yaml diff --git a/controller/hack/boilerplate.go.txt b/go/controller/hack/boilerplate.go.txt similarity index 100% rename from controller/hack/boilerplate.go.txt rename to go/controller/hack/boilerplate.go.txt diff --git a/controller/internal/autogen/autogen_api_translator.go b/go/controller/internal/autogen/autogen_api_translator.go similarity index 97% rename from controller/internal/autogen/autogen_api_translator.go rename to go/controller/internal/autogen/autogen_api_translator.go index 5f30eb5d1..d6cacb9c9 100644 --- a/controller/internal/autogen/autogen_api_translator.go +++ b/go/controller/internal/autogen/autogen_api_translator.go @@ -5,8 +5,9 @@ import ( "crypto/sha256" "encoding/binary" "fmt" - "github.com/kagent-dev/kagent/controller/api/v1alpha1" - "github.com/kagent-dev/kagent/controller/internal/utils/syncutils" + "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" @@ -16,7 +17,7 @@ type AutogenApiTranslator interface { TranslateSelectorGroupChat( ctx context.Context, selectorTeamRef types.NamespacedName, - ) (*SelectorGroupChat, error) + ) (*api.TeamConfig, error) } type autogenApiTranslator struct { diff --git a/controller/internal/autogen/autogen_config_types.go b/go/controller/internal/autogen/autogen_config_types.go similarity index 100% rename from controller/internal/autogen/autogen_config_types.go rename to go/controller/internal/autogen/autogen_config_types.go 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..f0296b76a --- /dev/null +++ b/go/controller/internal/autogen/autogen_translator_test.go @@ -0,0 +1,52 @@ +package autogen_test + +import ( + "context" + "github.com/kagent-dev/kagent/go/autogen/api" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "os/exec" + "time" +) + +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:8080", "ws://localhost:8080") + + err := client.CreateTeam().UpsertTeam(ctx, &SelectorGroupChat{ + ID: 1234, + UserID: "guestuser@gmail.com", + Provider: "autogen_agentchat.teams.SelectorGroupChat", + ComponentType: "team", + Version: 1, + ComponentVersion: 1, + Description: "a test team, pls ignore", + Config: SelectorGroupChatConfig{}, + }) + Expect(err).NotTo(HaveOccurred()) + + list, err := client.ListTeams(ctx, "guestuser@gmail.com") + Expect(err).NotTo(HaveOccurred()) + Expect(list).NotTo(BeNil()) + }) +}) + +func startAutogenServer(ctx context.Context) { + defer GinkgoRecover() + cmd := exec.CommandContext(ctx, "uv", "run", "autogenstudio", "ui") + cmd.Dir = "../../../python" + err := cmd.Run() + if err != nil && err.Error() != "context canceled" { + Expect(err).NotTo(HaveOccurred()) + } +} diff --git a/controller/internal/controller/autogenagent_controller.go b/go/controller/internal/controller/autogenagent_controller.go similarity index 96% rename from controller/internal/controller/autogenagent_controller.go rename to go/controller/internal/controller/autogenagent_controller.go index af0680bd9..c0534d102 100644 --- a/controller/internal/controller/autogenagent_controller.go +++ b/go/controller/internal/controller/autogenagent_controller.go @@ -24,7 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" ) // AutogenAgentReconciler reconciles a AutogenAgent object diff --git a/controller/internal/controller/autogenagent_controller_test.go b/go/controller/internal/controller/autogenagent_controller_test.go similarity index 97% rename from controller/internal/controller/autogenagent_controller_test.go rename to go/controller/internal/controller/autogenagent_controller_test.go index 693937fd4..ec86575f9 100644 --- a/controller/internal/controller/autogenagent_controller_test.go +++ b/go/controller/internal/controller/autogenagent_controller_test.go @@ -25,7 +25,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" ) var _ = Describe("AutogenAgent Controller", func() { diff --git a/controller/internal/controller/autogenmodelconfig_controller.go b/go/controller/internal/controller/autogenmodelconfig_controller.go similarity index 96% rename from controller/internal/controller/autogenmodelconfig_controller.go rename to go/controller/internal/controller/autogenmodelconfig_controller.go index 9129fee29..ef25eb052 100644 --- a/controller/internal/controller/autogenmodelconfig_controller.go +++ b/go/controller/internal/controller/autogenmodelconfig_controller.go @@ -24,7 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" ) // AutogenModelConfigReconciler reconciles a AutogenModelConfig object diff --git a/controller/internal/controller/autogenmodelconfig_controller_test.go b/go/controller/internal/controller/autogenmodelconfig_controller_test.go similarity index 97% rename from controller/internal/controller/autogenmodelconfig_controller_test.go rename to go/controller/internal/controller/autogenmodelconfig_controller_test.go index 3e7e93129..d57ec2f51 100644 --- a/controller/internal/controller/autogenmodelconfig_controller_test.go +++ b/go/controller/internal/controller/autogenmodelconfig_controller_test.go @@ -25,7 +25,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" ) var _ = Describe("AutogenModelConfig Controller", func() { diff --git a/controller/internal/controller/autogenteam_controller.go b/go/controller/internal/controller/autogenteam_controller.go similarity index 96% rename from controller/internal/controller/autogenteam_controller.go rename to go/controller/internal/controller/autogenteam_controller.go index 31dac4692..20a41235d 100644 --- a/controller/internal/controller/autogenteam_controller.go +++ b/go/controller/internal/controller/autogenteam_controller.go @@ -24,7 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" ) // AutogenTeamReconciler reconciles a AutogenTeam object diff --git a/controller/internal/controller/autogenteam_controller_test.go b/go/controller/internal/controller/autogenteam_controller_test.go similarity index 97% rename from controller/internal/controller/autogenteam_controller_test.go rename to go/controller/internal/controller/autogenteam_controller_test.go index 9a60007ba..861f18e88 100644 --- a/controller/internal/controller/autogenteam_controller_test.go +++ b/go/controller/internal/controller/autogenteam_controller_test.go @@ -25,7 +25,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" ) var _ = Describe("AutogenTeam Controller", func() { diff --git a/controller/internal/controller/autogentool_controller.go b/go/controller/internal/controller/autogentool_controller.go similarity index 96% rename from controller/internal/controller/autogentool_controller.go rename to go/controller/internal/controller/autogentool_controller.go index 9e072c7fd..3f1d3664e 100644 --- a/controller/internal/controller/autogentool_controller.go +++ b/go/controller/internal/controller/autogentool_controller.go @@ -24,7 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" ) // AutogenToolReconciler reconciles a AutogenTool object diff --git a/controller/internal/controller/autogentool_controller_test.go b/go/controller/internal/controller/autogentool_controller_test.go similarity index 97% rename from controller/internal/controller/autogentool_controller_test.go rename to go/controller/internal/controller/autogentool_controller_test.go index 58d68480e..5d5d50dd2 100644 --- a/controller/internal/controller/autogentool_controller_test.go +++ b/go/controller/internal/controller/autogentool_controller_test.go @@ -25,7 +25,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" ) var _ = Describe("AutogenTool Controller", func() { diff --git a/controller/internal/controller/suite_test.go b/go/controller/internal/controller/suite_test.go similarity index 97% rename from controller/internal/controller/suite_test.go rename to go/controller/internal/controller/suite_test.go index dd6ae2a2b..c4b8c270c 100644 --- a/controller/internal/controller/suite_test.go +++ b/go/controller/internal/controller/suite_test.go @@ -29,7 +29,7 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - agentv1alpha1 "github.com/kagent-dev/kagent/controller/api/v1alpha1" + agentv1alpha1 "github.com/kagent-dev/kagent/go/controller/api/v1alpha1" // +kubebuilder:scaffold:imports ) diff --git a/controller/internal/utils/syncutils/sync_utils.go b/go/controller/internal/utils/syncutils/sync_utils.go similarity index 100% rename from controller/internal/utils/syncutils/sync_utils.go rename to go/controller/internal/utils/syncutils/sync_utils.go diff --git a/controller/test/e2e/e2e_suite_test.go b/go/controller/test/e2e/e2e_suite_test.go similarity index 98% rename from controller/test/e2e/e2e_suite_test.go rename to go/controller/test/e2e/e2e_suite_test.go index 2d02d47c2..05d057597 100644 --- a/controller/test/e2e/e2e_suite_test.go +++ b/go/controller/test/e2e/e2e_suite_test.go @@ -25,7 +25,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/kagent-dev/kagent/controller/test/utils" + "github.com/kagent-dev/kagent/go/controller/test/utils" ) var ( diff --git a/controller/test/e2e/e2e_test.go b/go/controller/test/e2e/e2e_test.go similarity index 99% rename from controller/test/e2e/e2e_test.go rename to go/controller/test/e2e/e2e_test.go index cccea5c7a..2a3fd3c59 100644 --- a/controller/test/e2e/e2e_test.go +++ b/go/controller/test/e2e/e2e_test.go @@ -27,7 +27,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/kagent-dev/kagent/controller/test/utils" + "github.com/kagent-dev/kagent/go/controller/test/utils" ) // namespace where the project is deployed in diff --git a/controller/test/utils/utils.go b/go/controller/test/utils/utils.go similarity index 100% rename from controller/test/utils/utils.go rename to go/controller/test/utils/utils.go diff --git a/controller/go.mod b/go/go.mod similarity index 98% rename from controller/go.mod rename to go/go.mod index 10e089a57..7e21ca528 100644 --- a/controller/go.mod +++ b/go/go.mod @@ -1,4 +1,4 @@ -module github.com/kagent-dev/kagent/controller +module github.com/kagent-dev/kagent/go go 1.23.3 @@ -6,7 +6,6 @@ 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 - golang.org/x/oauth2 v0.23.0 k8s.io/api v0.32.0 k8s.io/apimachinery v0.32.0 k8s.io/client-go v0.32.0 @@ -71,6 +70,7 @@ require ( 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 diff --git a/controller/go.sum b/go/go.sum similarity index 100% rename from controller/go.sum rename to go/go.sum From 333a936bd9991a8ca5a124282c5de13f880448fd Mon Sep 17 00:00:00 2001 From: Scott Weiss Date: Thu, 30 Jan 2025 21:26:38 -0500 Subject: [PATCH 07/12] get test running, working thru translation --- go/autogen/api/types.go | 4 + .../autogen/autogen_api_translator.go | 144 +++++++++-------- .../autogen/autogen_translator_test.go | 145 ++++++++++++++++-- 3 files changed, 213 insertions(+), 80 deletions(-) diff --git a/go/autogen/api/types.go b/go/autogen/api/types.go index 99bb59b10..756ad27b4 100644 --- a/go/autogen/api/types.go +++ b/go/autogen/api/types.go @@ -47,6 +47,7 @@ type TeamComponent struct { Description *string `json:"description"` Component TeamResponseConfig `json:"component"` Label string `json:"label"` + Config TeamConfig `json:"config"` } // TeamResponse represents the full team response structure @@ -225,6 +226,9 @@ type ToolConfig struct { 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 diff --git a/go/controller/internal/autogen/autogen_api_translator.go b/go/controller/internal/autogen/autogen_api_translator.go index d6cacb9c9..2bf2258bc 100644 --- a/go/controller/internal/autogen/autogen_api_translator.go +++ b/go/controller/internal/autogen/autogen_api_translator.go @@ -17,7 +17,7 @@ type AutogenApiTranslator interface { TranslateSelectorGroupChat( ctx context.Context, selectorTeamRef types.NamespacedName, - ) (*api.TeamConfig, error) + ) (*api.TeamResponse, error) } type autogenApiTranslator struct { @@ -40,7 +40,7 @@ func NewAutogenApiTranslator( func (a *autogenApiTranslator) TranslateSelectorGroupChat( ctx context.Context, selectorTeamRef types.NamespacedName, -) (*SelectorGroupChat, error) { +) (*api.TeamResponse, error) { // get selector team selectorTeam := &v1alpha1.AutogenTeam{} err := fetchObjKube( @@ -89,18 +89,18 @@ func (a *autogenApiTranslator) TranslateSelectorGroupChat( return nil, fmt.Errorf("model api key not found") } - modelClient := ModelClient{ - Provider: "autogen_ext.models.openai.OpenAIChatCompletionClient", - ComponentType: "model", - Version: 1, - ComponentVersion: 1, - Config: ModelClientConfig{ + modelClient := &api.ModelComponent{ + Provider: "autogen_ext.models.openai.OpenAIChatCompletionClient", + ComponentType: "model", + Version: makePtr(1), + //ComponentVersion: 1, + Component: api.ModelConfig{ Model: modelConfig.Spec.Model, - ApiKey: string(modelApiKey), + APIKey: makePtr(string(modelApiKey)), }, } - var participants []GroupChatParticipant + var participants []api.AgentComponent for _, agentName := range selectorTeam.Spec.Participants { agent := &v1alpha1.AutogenAgent{} err := fetchObjKube( @@ -115,7 +115,7 @@ func (a *autogenApiTranslator) TranslateSelectorGroupChat( } //TODO: currently only supports builtin tools - var tools []GroupChatParticipantTool + var tools []api.ToolComponent for _, toolRef := range agent.Spec.Tools { // fetch fn name from builtin tools fnName, ok := a.builtinTools.Get(toolRef) @@ -123,36 +123,42 @@ func (a *autogenApiTranslator) TranslateSelectorGroupChat( return nil, fmt.Errorf("builtin tool %s not found", toolRef) } - tool := GroupChatParticipantTool{ - Provider: "autogen_agentchat.tools.BuiltinTool", - ComponentType: "tool", - Version: 1, - ComponentVersion: 1, - Config: GroupChatParticipantToolConfig{ + tool := api.ToolComponent{ + Provider: "autogen_agentchat.tools.BuiltinTool", + ComponentType: "tool", + Version: makePtr(1), + //ComponentVersion: 1, + Component: api.ToolConfig{ FnName: fnName, }, } tools = append(tools, tool) } - participant := GroupChatParticipant{ + 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: 1, - ComponentVersion: 1, - Config: GroupChatParticipantConfig{ + 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: ModelContext{ - Provider: "autogen_core.model_context.UnboundedChatCompletionContext", - ComponentType: "chat_completion_context", - Version: 1, - ComponentVersion: 1, + ModelContext: &api.ChatCompletionContextComponent{ + Provider: "autogen_core.model_context.UnboundedChatCompletionContext", + ComponentType: "chat_completion_context", + Version: makePtr(1), + //ComponentVersion: 1, }, - Description: agent.Spec.Description, - SystemMessage: agent.Spec.SystemMessage, + Description: agent.Spec.Description, + // TODO(ilackarms): convert to non-ptr with omitempty? + SystemMessage: sysMsgPtr, ReflectOnToolUse: false, ToolCallSummaryFormat: "{result}", }, @@ -165,24 +171,30 @@ func (a *autogenApiTranslator) TranslateSelectorGroupChat( return nil, err } - return &SelectorGroupChat{ - ID: generateIdFromString(selectorTeam.Name + "-" + selectorTeam.Namespace), - UserID: "guestuser@gmail.com", // always use global id - Provider: "autogen_agentchat.teams.SelectorGroupChat", - ComponentType: "team", - Version: 1, - ComponentVersion: 1, - Description: selectorTeam.Spec.Description, - Config: SelectorGroupChatConfig{ - Participants: participants, - ModelClient: modelClient, - TerminationCondition: *terminationCondition, - SelectorPrompt: selectorTeam.Spec.SelectorTeamConfig.SelectorPrompt, - AllowRepeatedSpeaker: false, + return &api.TeamResponse{ + ID: generateIdFromString(selectorTeam.Name + "-" + selectorTeam.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(selectorTeam.Spec.Description), + Config: api.TeamConfig{ + Participants: participants, + ModelClient: modelClient, + TerminationCondition: terminationCondition, + SelectorPrompt: selectorTeam.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 @@ -190,7 +202,7 @@ func generateIdFromString(s string) int { return number } -func translateTerminationCondition(terminationCondition v1alpha1.TerminationCondition) (*TerminationCondition, error) { +func translateTerminationCondition(terminationCondition v1alpha1.TerminationCondition) (*api.TerminationComponent, error) { // ensure only one termination condition is set var conditionsSet int if terminationCondition.MaxMessageTermination != nil { @@ -208,27 +220,27 @@ func translateTerminationCondition(terminationCondition v1alpha1.TerminationCond switch { case terminationCondition.MaxMessageTermination != nil: - return &TerminationCondition{ - Provider: "autogen_agentchat.conditions.MaxMessageTermination", - ComponentType: "termination", - Version: 1, - ComponentVersion: 1, - Config: TerminationConditionConfig{ - MaxMessages: terminationCondition.MaxMessageTermination.MaxMessages, + 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 &TerminationCondition{ - Provider: "autogen_agentchat.conditions.TextMentionTermination", - ComponentType: "termination", - Version: 1, - ComponentVersion: 1, - Config: TerminationConditionConfig{ - Text: terminationCondition.TextMentionTermination.Text, + 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 []TerminationCondition + var conditions []api.TerminationComponent for _, c := range terminationCondition.OrTermination.Conditions { condition, err := translateTerminationCondition(c) if err != nil { @@ -236,12 +248,12 @@ func translateTerminationCondition(terminationCondition v1alpha1.TerminationCond } conditions = append(conditions, *condition) } - return &TerminationCondition{ - Provider: "autogen_agentchat.conditions.OrTerminationCondition", - ComponentType: "termination", - Version: 1, - ComponentVersion: 1, - Config: TerminationConditionConfig{ + return &api.TerminationComponent{ + Provider: "autogen_agentchat.conditions.OrTerminationCondition", + ComponentType: "termination", + Version: makePtr(1), + //ComponentVersion: 1, + Component: api.TerminationConfig{ Conditions: conditions, }, }, nil diff --git a/go/controller/internal/autogen/autogen_translator_test.go b/go/controller/internal/autogen/autogen_translator_test.go index f0296b76a..763a5531b 100644 --- a/go/controller/internal/autogen/autogen_translator_test.go +++ b/go/controller/internal/autogen/autogen_translator_test.go @@ -3,12 +3,29 @@ 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/apimachinery/pkg/types" + "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() @@ -21,30 +38,130 @@ var _ = Describe("AutogenClient", func() { // sleep for a while to allow autogen server to start <-time.After(3 * time.Second) - client := api.NewClient("http://localhost:8080", "ws://localhost:8080") + 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", + APIKeySecret: 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()) + + teamRef := types.NamespacedName{ + Name: apiTeam.Name, + Namespace: apiTeam.Namespace, + } + + autogenTeam, err := autogen.NewAutogenApiTranslator(kubeClient, builtinTools).TranslateSelectorGroupChat(ctx, teamRef) + Expect(err).NotTo(HaveOccurred()) + Expect(autogenTeam).NotTo(BeNil()) - err := client.CreateTeam().UpsertTeam(ctx, &SelectorGroupChat{ - ID: 1234, - UserID: "guestuser@gmail.com", - Provider: "autogen_agentchat.teams.SelectorGroupChat", - ComponentType: "team", - Version: 1, - ComponentVersion: 1, - Description: "a test team, pls ignore", - Config: SelectorGroupChatConfig{}, - }) + err = client.CreateTeam(autogenTeam) Expect(err).NotTo(HaveOccurred()) - list, err := client.ListTeams(ctx, "guestuser@gmail.com") + 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, "uv", "run", "autogenstudio", "ui") - cmd.Dir = "../../../python" + 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()) From 801e4539143922f222d1f89b58f463a4c059182f Mon Sep 17 00:00:00 2001 From: Scott Weiss Date: Mon, 3 Feb 2025 09:47:54 -0500 Subject: [PATCH 08/12] fix api types --- go/autogen/api/types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/autogen/api/types.go b/go/autogen/api/types.go index 756ad27b4..df6029be0 100644 --- a/go/autogen/api/types.go +++ b/go/autogen/api/types.go @@ -53,8 +53,8 @@ type TeamComponent struct { // TeamResponse represents the full team response structure type TeamResponse struct { ID int `json:"id"` - CreatedAt string `json:"created_at"` - UpdatedAt string `json:"updated_at"` + 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"` From 5ca926b756f7395c393dc745e6eb7c767c65d80f Mon Sep 17 00:00:00 2001 From: Scott Weiss Date: Mon, 3 Feb 2025 10:25:45 -0500 Subject: [PATCH 09/12] wire up controller, reconciler, and translator --- .../api/v1alpha1/autogenmodelconfig_types.go | 6 +- .../api/v1alpha1/autogenteam_types.go | 8 +- go/controller/cmd/main.go | 55 ++++- .../autogen/autogen_api_translator.go | 45 ++-- .../internal/autogen/autogen_reconciler.go | 199 ++++++++++++++++++ .../autogen/autogen_translator_test.go | 14 +- .../controller/autogenagent_controller.go | 6 +- .../autogenmodelconfig_controller.go | 8 +- .../controller/autogensecret_controller.go | 62 ++++++ .../controller/autogenteam_controller.go | 8 +- 10 files changed, 354 insertions(+), 57 deletions(-) create mode 100644 go/controller/internal/autogen/autogen_reconciler.go create mode 100644 go/controller/internal/controller/autogensecret_controller.go diff --git a/go/controller/api/v1alpha1/autogenmodelconfig_types.go b/go/controller/api/v1alpha1/autogenmodelconfig_types.go index 0b995fb26..23e20d0c3 100644 --- a/go/controller/api/v1alpha1/autogenmodelconfig_types.go +++ b/go/controller/api/v1alpha1/autogenmodelconfig_types.go @@ -22,9 +22,9 @@ import ( // AutogenModelConfigSpec defines the desired state of AutogenModelConfig. type AutogenModelConfigSpec struct { - Model string `json:"model"` - APIKeySecret string `json:"apiKeySecret"` - APIKeySecretKey string `json:"apiKeySecretKey"` + Model string `json:"model"` + APIKeySecretName string `json:"apiKeySecretName"` + APIKeySecretKey string `json:"apiKeySecretKey"` } // AutogenModelConfigStatus defines the observed state of AutogenModelConfig. diff --git a/go/controller/api/v1alpha1/autogenteam_types.go b/go/controller/api/v1alpha1/autogenteam_types.go index a53f81705..3de638a03 100644 --- a/go/controller/api/v1alpha1/autogenteam_types.go +++ b/go/controller/api/v1alpha1/autogenteam_types.go @@ -37,6 +37,7 @@ type SelectorTeamConfig struct { 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"` @@ -53,7 +54,12 @@ type TextMentionTermination struct { } type OrTermination struct { - Conditions []TerminationCondition `json:"conditions"` + Conditions []OrTerminationCondition `json:"conditions"` +} + +type OrTerminationCondition struct { + MaxMessageTermination *MaxMessageTermination `json:"maxMessageTermination,omitempty"` + TextMentionTermination *TextMentionTermination `json:"textMentionTermination,omitempty"` } // AutogenTeamStatus defines the observed state of AutogenTeam. diff --git a/go/controller/cmd/main.go b/go/controller/cmd/main.go index 59ee8c851..187f267c3 100644 --- a/go/controller/cmd/main.go +++ b/go/controller/cmd/main.go @@ -19,6 +19,9 @@ 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" @@ -63,6 +66,8 @@ func main() { 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.") @@ -81,6 +86,9 @@ func main() { 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, } @@ -202,34 +210,67 @@ func main() { 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: mgr.GetClient(), - Scheme: mgr.GetScheme(), + 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: mgr.GetClient(), - Scheme: mgr.GetScheme(), + 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: mgr.GetClient(), + 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: mgr.GetClient(), - Scheme: mgr.GetScheme(), + 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 { diff --git a/go/controller/internal/autogen/autogen_api_translator.go b/go/controller/internal/autogen/autogen_api_translator.go index 2bf2258bc..85ff55612 100644 --- a/go/controller/internal/autogen/autogen_api_translator.go +++ b/go/controller/internal/autogen/autogen_api_translator.go @@ -16,7 +16,7 @@ import ( type AutogenApiTranslator interface { TranslateSelectorGroupChat( ctx context.Context, - selectorTeamRef types.NamespacedName, + team *v1alpha1.AutogenTeam, ) (*api.TeamResponse, error) } @@ -39,29 +39,17 @@ func NewAutogenApiTranslator( func (a *autogenApiTranslator) TranslateSelectorGroupChat( ctx context.Context, - selectorTeamRef types.NamespacedName, + team *v1alpha1.AutogenTeam, ) (*api.TeamResponse, error) { - // get selector team - selectorTeam := &v1alpha1.AutogenTeam{} - err := fetchObjKube( - ctx, - a.kube, - selectorTeam, - selectorTeamRef.Name, - selectorTeamRef.Namespace, - ) - if err != nil { - return nil, err - } // get model config modelConfig := &v1alpha1.AutogenModelConfig{} - err = fetchObjKube( + err := fetchObjKube( ctx, a.kube, modelConfig, - selectorTeam.Spec.SelectorTeamConfig.ModelConfig, - selectorTeam.Namespace, + team.Spec.SelectorTeamConfig.ModelConfig, + team.Namespace, ) if err != nil { return nil, err @@ -73,8 +61,8 @@ func (a *autogenApiTranslator) TranslateSelectorGroupChat( ctx, a.kube, modelApiKeySecret, - modelConfig.Spec.APIKeySecret, - selectorTeam.Namespace, + modelConfig.Spec.APIKeySecretName, + team.Namespace, ) if err != nil { return nil, err @@ -101,14 +89,14 @@ func (a *autogenApiTranslator) TranslateSelectorGroupChat( } var participants []api.AgentComponent - for _, agentName := range selectorTeam.Spec.Participants { + for _, agentName := range team.Spec.Participants { agent := &v1alpha1.AutogenAgent{} err := fetchObjKube( ctx, a.kube, agent, agentName, - selectorTeam.Namespace, + team.Namespace, ) if err != nil { return nil, err @@ -166,25 +154,25 @@ func (a *autogenApiTranslator) TranslateSelectorGroupChat( participants = append(participants, participant) } - terminationCondition, err := translateTerminationCondition(selectorTeam.Spec.TerminationCondition) + terminationCondition, err := translateTerminationCondition(team.Spec.TerminationCondition) if err != nil { return nil, err } return &api.TeamResponse{ - ID: generateIdFromString(selectorTeam.Name + "-" + selectorTeam.Namespace), + 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(selectorTeam.Spec.Description), + Description: makePtr(team.Spec.Description), Config: api.TeamConfig{ Participants: participants, ModelClient: modelClient, TerminationCondition: terminationCondition, - SelectorPrompt: selectorTeam.Spec.SelectorTeamConfig.SelectorPrompt, + SelectorPrompt: team.Spec.SelectorTeamConfig.SelectorPrompt, AllowRepeatedSpeaker: false, }, }, @@ -242,7 +230,12 @@ func translateTerminationCondition(terminationCondition v1alpha1.TerminationCond case terminationCondition.OrTermination != nil: var conditions []api.TerminationComponent for _, c := range terminationCondition.OrTermination.Conditions { - condition, err := translateTerminationCondition(c) + subConditon := v1alpha1.TerminationCondition{ + MaxMessageTermination: c.MaxMessageTermination, + TextMentionTermination: c.TextMentionTermination, + } + + condition, err := translateTerminationCondition(subConditon) if err != nil { return nil, err } 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_translator_test.go b/go/controller/internal/autogen/autogen_translator_test.go index 763a5531b..df4e0e07a 100644 --- a/go/controller/internal/autogen/autogen_translator_test.go +++ b/go/controller/internal/autogen/autogen_translator_test.go @@ -10,7 +10,6 @@ import ( . "github.com/onsi/gomega" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" "os" "os/exec" @@ -68,9 +67,9 @@ var _ = Describe("AutogenClient", func() { Namespace: namespace, }, Spec: v1alpha1.AutogenModelConfigSpec{ - Model: "gpt-4o", - APIKeySecret: apikeySecret.Name, - APIKeySecretKey: apikeySecretKey, + Model: "gpt-4o", + APIKeySecretName: apikeySecret.Name, + APIKeySecretKey: apikeySecretKey, }, } @@ -136,12 +135,7 @@ var _ = Describe("AutogenClient", func() { err = kubeClient.Create(ctx, apiTeam) Expect(err).NotTo(HaveOccurred()) - teamRef := types.NamespacedName{ - Name: apiTeam.Name, - Namespace: apiTeam.Namespace, - } - - autogenTeam, err := autogen.NewAutogenApiTranslator(kubeClient, builtinTools).TranslateSelectorGroupChat(ctx, teamRef) + autogenTeam, err := autogen.NewAutogenApiTranslator(kubeClient, builtinTools).TranslateSelectorGroupChat(ctx, apiTeam) Expect(err).NotTo(HaveOccurred()) Expect(autogenTeam).NotTo(BeNil()) diff --git a/go/controller/internal/controller/autogenagent_controller.go b/go/controller/internal/controller/autogenagent_controller.go index c0534d102..7ca026217 100644 --- a/go/controller/internal/controller/autogenagent_controller.go +++ b/go/controller/internal/controller/autogenagent_controller.go @@ -18,6 +18,7 @@ package controller import ( "context" + "github.com/kagent-dev/kagent/go/controller/internal/autogen" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" @@ -30,7 +31,8 @@ import ( // AutogenAgentReconciler reconciles a AutogenAgent object type AutogenAgentReconciler struct { client.Client - Scheme *runtime.Scheme + Scheme *runtime.Scheme + Reconciler autogen.AutogenReconciler } // +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogenagents,verbs=get;list;watch;create;update;patch;delete @@ -51,7 +53,7 @@ func (r *AutogenAgentReconciler) Reconcile(ctx context.Context, req ctrl.Request // TODO(user): your logic here - return ctrl.Result{}, nil + return ctrl.Result{}, r.Reconciler.ReconcileAutogenAgent(ctx, req) } // SetupWithManager sets up the controller with the Manager. diff --git a/go/controller/internal/controller/autogenmodelconfig_controller.go b/go/controller/internal/controller/autogenmodelconfig_controller.go index ef25eb052..26379599b 100644 --- a/go/controller/internal/controller/autogenmodelconfig_controller.go +++ b/go/controller/internal/controller/autogenmodelconfig_controller.go @@ -18,6 +18,7 @@ package controller import ( "context" + "github.com/kagent-dev/kagent/go/controller/internal/autogen" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" @@ -30,7 +31,8 @@ import ( // AutogenModelConfigReconciler reconciles a AutogenModelConfig object type AutogenModelConfigReconciler struct { client.Client - Scheme *runtime.Scheme + Scheme *runtime.Scheme + Reconciler autogen.AutogenReconciler } // +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogenmodelconfigs,verbs=get;list;watch;create;update;patch;delete @@ -49,9 +51,7 @@ type AutogenModelConfigReconciler struct { func (r *AutogenModelConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { _ = log.FromContext(ctx) - // TODO(user): your logic here - - return ctrl.Result{}, nil + return ctrl.Result{}, r.Reconciler.ReconcileAutogenModelConfig(ctx, req) } // SetupWithManager sets up the controller with the Manager. 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 index 20a41235d..6fd88ecea 100644 --- a/go/controller/internal/controller/autogenteam_controller.go +++ b/go/controller/internal/controller/autogenteam_controller.go @@ -18,6 +18,7 @@ package controller import ( "context" + "github.com/kagent-dev/kagent/go/controller/internal/autogen" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" @@ -30,7 +31,8 @@ import ( // AutogenTeamReconciler reconciles a AutogenTeam object type AutogenTeamReconciler struct { client.Client - Scheme *runtime.Scheme + Scheme *runtime.Scheme + Reconciler autogen.AutogenReconciler } // +kubebuilder:rbac:groups=agent.ai.solo.io,resources=autogenteams,verbs=get;list;watch;create;update;patch;delete @@ -49,9 +51,7 @@ type AutogenTeamReconciler struct { func (r *AutogenTeamReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { _ = log.FromContext(ctx) - // TODO(user): your logic here - - return ctrl.Result{}, nil + return ctrl.Result{}, r.Reconciler.ReconcileAutogenTeam(ctx, req) } // SetupWithManager sets up the controller with the Manager. From bee82cb9b9a9f204dce3225cff6a04deab41705f Mon Sep 17 00:00:00 2001 From: Scott Weiss Date: Mon, 3 Feb 2025 10:33:16 -0500 Subject: [PATCH 10/12] regen --- .../api/v1alpha1/zz_generated.deepcopy.go | 27 ++++++++++++++++++- .../agent.ai.solo.io_autogenmodelconfigs.yaml | 6 ++--- .../bases/agent.ai.solo.io_autogenteams.yaml | 22 ++++++++++++++- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/go/controller/api/v1alpha1/zz_generated.deepcopy.go b/go/controller/api/v1alpha1/zz_generated.deepcopy.go index b486f7984..8f5d7fe54 100644 --- a/go/controller/api/v1alpha1/zz_generated.deepcopy.go +++ b/go/controller/api/v1alpha1/zz_generated.deepcopy.go @@ -412,7 +412,7 @@ func (in *OrTermination) DeepCopyInto(out *OrTermination) { *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions - *out = make([]TerminationCondition, len(*in)) + *out = make([]OrTerminationCondition, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -429,6 +429,31 @@ func (in *OrTermination) DeepCopy() *OrTermination { 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 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 index eabef33b8..1e6b15092 100644 --- a/go/controller/config/crd/bases/agent.ai.solo.io_autogenmodelconfigs.yaml +++ b/go/controller/config/crd/bases/agent.ai.solo.io_autogenmodelconfigs.yaml @@ -40,15 +40,15 @@ spec: spec: description: AutogenModelConfigSpec defines the desired state of AutogenModelConfig. properties: - apiKeySecret: - type: string apiKeySecretKey: type: string + apiKeySecretName: + type: string model: type: string required: - - apiKeySecret - apiKeySecretKey + - apiKeySecretName - model type: object 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 index 65ab7a9bb..137372181 100644 --- a/go/controller/config/crd/bases/agent.ai.solo.io_autogenteams.yaml +++ b/go/controller/config/crd/bases/agent.ai.solo.io_autogenteams.yaml @@ -72,7 +72,23 @@ spec: orTermination: properties: conditions: - items: {} + 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 @@ -85,6 +101,10 @@ spec: - 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 From 4d04f5ce7303b119775a03a7bc596f5066810b29 Mon Sep 17 00:00:00 2001 From: Scott Weiss Date: Mon, 3 Feb 2025 10:49:47 -0500 Subject: [PATCH 11/12] remove unused files --- go/controller/.devcontainer/devcontainer.json | 25 -- go/controller/.devcontainer/post-install.sh | 23 -- go/controller/.github/workflows/lint.yml | 23 -- go/controller/.github/workflows/test-e2e.yml | 35 -- go/controller/.github/workflows/test.yml | 23 -- go/controller/.golangci.yml | 47 --- .../default/cert_metrics_manager_patch.yaml | 30 -- .../config/default/kustomization.yaml | 212 ----------- .../config/default/manager_metrics_patch.yaml | 4 - .../config/default/metrics_service.yaml | 18 - .../config/manager/kustomization.yaml | 2 - go/controller/config/manager/manager.yaml | 98 ----- .../network-policy/allow-metrics-traffic.yaml | 27 -- .../config/network-policy/kustomization.yaml | 2 - .../config/prometheus/kustomization.yaml | 11 - go/controller/config/prometheus/monitor.yaml | 27 -- .../config/prometheus/monitor_tls_patch.yaml | 22 -- go/controller/test/e2e/e2e_suite_test.go | 110 ------ go/controller/test/e2e/e2e_test.go | 334 ------------------ go/controller/test/utils/utils.go | 251 ------------- 20 files changed, 1324 deletions(-) delete mode 100644 go/controller/.devcontainer/devcontainer.json delete mode 100644 go/controller/.devcontainer/post-install.sh delete mode 100644 go/controller/.github/workflows/lint.yml delete mode 100644 go/controller/.github/workflows/test-e2e.yml delete mode 100644 go/controller/.github/workflows/test.yml delete mode 100644 go/controller/.golangci.yml delete mode 100644 go/controller/config/default/cert_metrics_manager_patch.yaml delete mode 100644 go/controller/config/default/kustomization.yaml delete mode 100644 go/controller/config/default/manager_metrics_patch.yaml delete mode 100644 go/controller/config/default/metrics_service.yaml delete mode 100644 go/controller/config/manager/kustomization.yaml delete mode 100644 go/controller/config/manager/manager.yaml delete mode 100644 go/controller/config/network-policy/allow-metrics-traffic.yaml delete mode 100644 go/controller/config/network-policy/kustomization.yaml delete mode 100644 go/controller/config/prometheus/kustomization.yaml delete mode 100644 go/controller/config/prometheus/monitor.yaml delete mode 100644 go/controller/config/prometheus/monitor_tls_patch.yaml delete mode 100644 go/controller/test/e2e/e2e_suite_test.go delete mode 100644 go/controller/test/e2e/e2e_test.go delete mode 100644 go/controller/test/utils/utils.go diff --git a/go/controller/.devcontainer/devcontainer.json b/go/controller/.devcontainer/devcontainer.json deleted file mode 100644 index 0e0eed213..000000000 --- a/go/controller/.devcontainer/devcontainer.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "Kubebuilder DevContainer", - "image": "docker.io/golang:1.23", - "features": { - "ghcr.io/devcontainers/features/docker-in-docker:2": {}, - "ghcr.io/devcontainers/features/git:1": {} - }, - - "runArgs": ["--network=host"], - - "customizations": { - "vscode": { - "settings": { - "terminal.integrated.shell.linux": "/bin/bash" - }, - "extensions": [ - "ms-kubernetes-tools.vscode-kubernetes-tools", - "ms-azuretools.vscode-docker" - ] - } - }, - - "onCreateCommand": "bash .devcontainer/post-install.sh" -} - diff --git a/go/controller/.devcontainer/post-install.sh b/go/controller/.devcontainer/post-install.sh deleted file mode 100644 index 265c43ee8..000000000 --- a/go/controller/.devcontainer/post-install.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -set -x - -curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64 -chmod +x ./kind -mv ./kind /usr/local/bin/kind - -curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64 -chmod +x kubebuilder -mv kubebuilder /usr/local/bin/ - -KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt) -curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl" -chmod +x kubectl -mv kubectl /usr/local/bin/kubectl - -docker network create -d=bridge --subnet=172.19.0.0/24 kind - -kind version -kubebuilder version -docker --version -go version -kubectl version --client diff --git a/go/controller/.github/workflows/lint.yml b/go/controller/.github/workflows/lint.yml deleted file mode 100644 index 4951e3316..000000000 --- a/go/controller/.github/workflows/lint.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Lint - -on: - push: - pull_request: - -jobs: - lint: - name: Run on Ubuntu - runs-on: ubuntu-latest - steps: - - name: Clone the code - uses: actions/checkout@v4 - - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - - - name: Run linter - uses: golangci/golangci-lint-action@v6 - with: - version: v1.63.4 diff --git a/go/controller/.github/workflows/test-e2e.yml b/go/controller/.github/workflows/test-e2e.yml deleted file mode 100644 index b2eda8c3d..000000000 --- a/go/controller/.github/workflows/test-e2e.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: E2E Tests - -on: - push: - pull_request: - -jobs: - test-e2e: - name: Run on Ubuntu - runs-on: ubuntu-latest - steps: - - name: Clone the code - uses: actions/checkout@v4 - - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - - - name: Install the latest version of kind - run: | - curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64 - chmod +x ./kind - sudo mv ./kind /usr/local/bin/kind - - - name: Verify kind installation - run: kind version - - - name: Create kind cluster - run: kind create cluster - - - name: Running Test e2e - run: | - go mod tidy - make test-e2e diff --git a/go/controller/.github/workflows/test.yml b/go/controller/.github/workflows/test.yml deleted file mode 100644 index fc2e80d30..000000000 --- a/go/controller/.github/workflows/test.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Tests - -on: - push: - pull_request: - -jobs: - test: - name: Run on Ubuntu - runs-on: ubuntu-latest - steps: - - name: Clone the code - uses: actions/checkout@v4 - - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - - - name: Running Tests - run: | - go mod tidy - make test diff --git a/go/controller/.golangci.yml b/go/controller/.golangci.yml deleted file mode 100644 index 6b2974623..000000000 --- a/go/controller/.golangci.yml +++ /dev/null @@ -1,47 +0,0 @@ -run: - timeout: 5m - allow-parallel-runners: true - -issues: - # don't skip warning about doc comments - # don't exclude the default set of lint - exclude-use-default: false - # restore some of the defaults - # (fill in the rest as needed) - exclude-rules: - - path: "api/*" - linters: - - lll - - path: "internal/*" - linters: - - dupl - - lll -linters: - disable-all: true - enable: - - dupl - - errcheck - - copyloopvar - - ginkgolinter - - goconst - - gocyclo - - gofmt - - goimports - - gosimple - - govet - - ineffassign - - lll - - misspell - - nakedret - - prealloc - - revive - - staticcheck - - typecheck - - unconvert - - unparam - - unused - -linters-settings: - revive: - rules: - - name: comment-spacings diff --git a/go/controller/config/default/cert_metrics_manager_patch.yaml b/go/controller/config/default/cert_metrics_manager_patch.yaml deleted file mode 100644 index d97501553..000000000 --- a/go/controller/config/default/cert_metrics_manager_patch.yaml +++ /dev/null @@ -1,30 +0,0 @@ -# This patch adds the args, volumes, and ports to allow the manager to use the metrics-server certs. - -# Add the volumeMount for the metrics-server certs -- op: add - path: /spec/template/spec/containers/0/volumeMounts/- - value: - mountPath: /tmp/k8s-metrics-server/metrics-certs - name: metrics-certs - readOnly: true - -# Add the --metrics-cert-path argument for the metrics server -- op: add - path: /spec/template/spec/containers/0/args/- - value: --metrics-cert-path=/tmp/k8s-metrics-server/metrics-certs - -# Add the metrics-server certs volume configuration -- op: add - path: /spec/template/spec/volumes/- - value: - name: metrics-certs - secret: - secretName: metrics-server-cert - optional: false - items: - - key: ca.crt - path: ca.crt - - key: tls.crt - path: tls.crt - - key: tls.key - path: tls.key diff --git a/go/controller/config/default/kustomization.yaml b/go/controller/config/default/kustomization.yaml deleted file mode 100644 index d2898df5b..000000000 --- a/go/controller/config/default/kustomization.yaml +++ /dev/null @@ -1,212 +0,0 @@ -# Adds namespace to all resources. -namespace: controller-system - -# Value of this field is prepended to the -# names of all resources, e.g. a deployment named -# "wordpress" becomes "alices-wordpress". -# Note that it should also match with the prefix (text before '-') of the namespace -# field above. -namePrefix: controller- - -# Labels to add to all resources and selectors. -#labels: -#- includeSelectors: true -# pairs: -# someName: someValue - -resources: -- ../crd -- ../rbac -- ../manager -# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in -# crd/kustomization.yaml -#- ../webhook -# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required. -#- ../certmanager -# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. -#- ../prometheus -# [METRICS] Expose the controller manager metrics service. -- metrics_service.yaml -# [NETWORK POLICY] Protect the /metrics endpoint and Webhook Server with NetworkPolicy. -# Only Pod(s) running a namespace labeled with 'metrics: enabled' will be able to gather the metrics. -# Only CR(s) which requires webhooks and are applied on namespaces labeled with 'webhooks: enabled' will -# be able to communicate with the Webhook Server. -#- ../network-policy - -# Uncomment the patches line if you enable Metrics -patches: -# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443. -# More info: https://book.kubebuilder.io/reference/metrics -- path: manager_metrics_patch.yaml - target: - kind: Deployment - -# Uncomment the patches line if you enable Metrics and CertManager -# [METRICS-WITH-CERTS] To enable metrics protected with certManager, uncomment the following line. -# This patch will protect the metrics with certManager self-signed certs. -#- path: cert_metrics_manager_patch.yaml -# target: -# kind: Deployment - -# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in -# crd/kustomization.yaml -#- path: manager_webhook_patch.yaml -# target: -# kind: Deployment - -# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix. -# Uncomment the following replacements to add the cert-manager CA injection annotations -#replacements: -# - source: # Uncomment the following block to enable certificates for metrics -# kind: Service -# version: v1 -# name: controller-manager-metrics-service -# fieldPath: metadata.name -# targets: -# - select: -# kind: Certificate -# group: cert-manager.io -# version: v1 -# name: metrics-certs -# fieldPaths: -# - spec.dnsNames.0 -# - spec.dnsNames.1 -# options: -# delimiter: '.' -# index: 0 -# create: true -# -# - source: -# kind: Service -# version: v1 -# name: controller-manager-metrics-service -# fieldPath: metadata.namespace -# targets: -# - select: -# kind: Certificate -# group: cert-manager.io -# version: v1 -# name: metrics-certs -# fieldPaths: -# - spec.dnsNames.0 -# - spec.dnsNames.1 -# options: -# delimiter: '.' -# index: 1 -# create: true -# -# - source: # Uncomment the following block if you have any webhook -# kind: Service -# version: v1 -# name: webhook-service -# fieldPath: .metadata.name # Name of the service -# targets: -# - select: -# kind: Certificate -# group: cert-manager.io -# version: v1 -# name: serving-cert -# fieldPaths: -# - .spec.dnsNames.0 -# - .spec.dnsNames.1 -# options: -# delimiter: '.' -# index: 0 -# create: true -# - source: -# kind: Service -# version: v1 -# name: webhook-service -# fieldPath: .metadata.namespace # Namespace of the service -# targets: -# - select: -# kind: Certificate -# group: cert-manager.io -# version: v1 -# name: serving-cert -# fieldPaths: -# - .spec.dnsNames.0 -# - .spec.dnsNames.1 -# options: -# delimiter: '.' -# index: 1 -# create: true -# -# - source: # Uncomment the following block if you have a ValidatingWebhook (--programmatic-validation) -# kind: Certificate -# group: cert-manager.io -# version: v1 -# name: serving-cert # This name should match the one in certificate.yaml -# fieldPath: .metadata.namespace # Namespace of the certificate CR -# targets: -# - select: -# kind: ValidatingWebhookConfiguration -# fieldPaths: -# - .metadata.annotations.[cert-manager.io/inject-ca-from] -# options: -# delimiter: '/' -# index: 0 -# create: true -# - source: -# kind: Certificate -# group: cert-manager.io -# version: v1 -# name: serving-cert -# fieldPath: .metadata.name -# targets: -# - select: -# kind: ValidatingWebhookConfiguration -# fieldPaths: -# - .metadata.annotations.[cert-manager.io/inject-ca-from] -# options: -# delimiter: '/' -# index: 1 -# create: true -# -# - source: # Uncomment the following block if you have a DefaultingWebhook (--defaulting ) -# kind: Certificate -# group: cert-manager.io -# version: v1 -# name: serving-cert -# fieldPath: .metadata.namespace # Namespace of the certificate CR -# targets: -# - select: -# kind: MutatingWebhookConfiguration -# fieldPaths: -# - .metadata.annotations.[cert-manager.io/inject-ca-from] -# options: -# delimiter: '/' -# index: 0 -# create: true -# - source: -# kind: Certificate -# group: cert-manager.io -# version: v1 -# name: serving-cert -# fieldPath: .metadata.name -# targets: -# - select: -# kind: MutatingWebhookConfiguration -# fieldPaths: -# - .metadata.annotations.[cert-manager.io/inject-ca-from] -# options: -# delimiter: '/' -# index: 1 -# create: true -# -# - source: # Uncomment the following block if you have a ConversionWebhook (--conversion) -# kind: Certificate -# group: cert-manager.io -# version: v1 -# name: serving-cert -# fieldPath: .metadata.namespace # Namespace of the certificate CR -# targets: # Do not remove or uncomment the following scaffold marker; required to generate code for target CRD. -# +kubebuilder:scaffold:crdkustomizecainjectionns -# - source: -# kind: Certificate -# group: cert-manager.io -# version: v1 -# name: serving-cert -# fieldPath: .metadata.name -# targets: # Do not remove or uncomment the following scaffold marker; required to generate code for target CRD. -# +kubebuilder:scaffold:crdkustomizecainjectionname diff --git a/go/controller/config/default/manager_metrics_patch.yaml b/go/controller/config/default/manager_metrics_patch.yaml deleted file mode 100644 index 2aaef6536..000000000 --- a/go/controller/config/default/manager_metrics_patch.yaml +++ /dev/null @@ -1,4 +0,0 @@ -# This patch adds the args to allow exposing the metrics endpoint using HTTPS -- op: add - path: /spec/template/spec/containers/0/args/0 - value: --metrics-bind-address=:8443 diff --git a/go/controller/config/default/metrics_service.yaml b/go/controller/config/default/metrics_service.yaml deleted file mode 100644 index 188643018..000000000 --- a/go/controller/config/default/metrics_service.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - labels: - control-plane: controller-manager - app.kubernetes.io/name: controller - app.kubernetes.io/managed-by: kustomize - name: controller-manager-metrics-service - namespace: system -spec: - ports: - - name: https - port: 8443 - protocol: TCP - targetPort: 8443 - selector: - control-plane: controller-manager - app.kubernetes.io/name: controller diff --git a/go/controller/config/manager/kustomization.yaml b/go/controller/config/manager/kustomization.yaml deleted file mode 100644 index 5c5f0b84c..000000000 --- a/go/controller/config/manager/kustomization.yaml +++ /dev/null @@ -1,2 +0,0 @@ -resources: -- manager.yaml diff --git a/go/controller/config/manager/manager.yaml b/go/controller/config/manager/manager.yaml deleted file mode 100644 index 99d9c4628..000000000 --- a/go/controller/config/manager/manager.yaml +++ /dev/null @@ -1,98 +0,0 @@ -apiVersion: v1 -kind: Namespace -metadata: - labels: - control-plane: controller-manager - app.kubernetes.io/name: controller - app.kubernetes.io/managed-by: kustomize - name: system ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system - labels: - control-plane: controller-manager - app.kubernetes.io/name: controller - app.kubernetes.io/managed-by: kustomize -spec: - selector: - matchLabels: - control-plane: controller-manager - app.kubernetes.io/name: controller - replicas: 1 - template: - metadata: - annotations: - kubectl.kubernetes.io/default-container: manager - labels: - control-plane: controller-manager - app.kubernetes.io/name: controller - spec: - # TODO(user): Uncomment the following code to configure the nodeAffinity expression - # according to the platforms which are supported by your solution. - # It is considered best practice to support multiple architectures. You can - # build your manager image using the makefile target docker-buildx. - # affinity: - # nodeAffinity: - # requiredDuringSchedulingIgnoredDuringExecution: - # nodeSelectorTerms: - # - matchExpressions: - # - key: kubernetes.io/arch - # operator: In - # values: - # - amd64 - # - arm64 - # - ppc64le - # - s390x - # - key: kubernetes.io/os - # operator: In - # values: - # - linux - securityContext: - # Projects are configured by default to adhere to the "restricted" Pod Security Standards. - # This ensures that deployments meet the highest security requirements for Kubernetes. - # For more details, see: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted - runAsNonRoot: true - seccompProfile: - type: RuntimeDefault - containers: - - command: - - /manager - args: - - --leader-elect - - --health-probe-bind-address=:8081 - image: controller:latest - name: manager - ports: [] - securityContext: - allowPrivilegeEscalation: false - capabilities: - drop: - - "ALL" - livenessProbe: - httpGet: - path: /healthz - port: 8081 - initialDelaySeconds: 15 - periodSeconds: 20 - readinessProbe: - httpGet: - path: /readyz - port: 8081 - initialDelaySeconds: 5 - periodSeconds: 10 - # TODO(user): Configure the resources accordingly based on the project requirements. - # More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ - resources: - limits: - cpu: 500m - memory: 128Mi - requests: - cpu: 10m - memory: 64Mi - volumeMounts: [] - volumes: [] - serviceAccountName: controller-manager - terminationGracePeriodSeconds: 10 diff --git a/go/controller/config/network-policy/allow-metrics-traffic.yaml b/go/controller/config/network-policy/allow-metrics-traffic.yaml deleted file mode 100644 index 5043e4212..000000000 --- a/go/controller/config/network-policy/allow-metrics-traffic.yaml +++ /dev/null @@ -1,27 +0,0 @@ -# This NetworkPolicy allows ingress traffic -# with Pods running on namespaces labeled with 'metrics: enabled'. Only Pods on those -# namespaces are able to gather data from the metrics endpoint. -apiVersion: networking.k8s.io/v1 -kind: NetworkPolicy -metadata: - labels: - app.kubernetes.io/name: controller - app.kubernetes.io/managed-by: kustomize - name: allow-metrics-traffic - namespace: system -spec: - podSelector: - matchLabels: - control-plane: controller-manager - app.kubernetes.io/name: controller - policyTypes: - - Ingress - ingress: - # This allows ingress traffic from any namespace with the label metrics: enabled - - from: - - namespaceSelector: - matchLabels: - metrics: enabled # Only from namespaces with this label - ports: - - port: 8443 - protocol: TCP diff --git a/go/controller/config/network-policy/kustomization.yaml b/go/controller/config/network-policy/kustomization.yaml deleted file mode 100644 index ec0fb5e57..000000000 --- a/go/controller/config/network-policy/kustomization.yaml +++ /dev/null @@ -1,2 +0,0 @@ -resources: -- allow-metrics-traffic.yaml diff --git a/go/controller/config/prometheus/kustomization.yaml b/go/controller/config/prometheus/kustomization.yaml deleted file mode 100644 index fdc5481b1..000000000 --- a/go/controller/config/prometheus/kustomization.yaml +++ /dev/null @@ -1,11 +0,0 @@ -resources: -- monitor.yaml - -# [PROMETHEUS-WITH-CERTS] The following patch configures the ServiceMonitor in ../prometheus -# to securely reference certificates created and managed by cert-manager. -# Additionally, ensure that you uncomment the [METRICS WITH CERTMANAGER] patch under config/default/kustomization.yaml -# to mount the "metrics-server-cert" secret in the Manager Deployment. -#patches: -# - path: monitor_tls_patch.yaml -# target: -# kind: ServiceMonitor diff --git a/go/controller/config/prometheus/monitor.yaml b/go/controller/config/prometheus/monitor.yaml deleted file mode 100644 index 041c99b9f..000000000 --- a/go/controller/config/prometheus/monitor.yaml +++ /dev/null @@ -1,27 +0,0 @@ -# Prometheus Monitor Service (Metrics) -apiVersion: monitoring.coreos.com/v1 -kind: ServiceMonitor -metadata: - labels: - control-plane: controller-manager - app.kubernetes.io/name: controller - app.kubernetes.io/managed-by: kustomize - name: controller-manager-metrics-monitor - namespace: system -spec: - endpoints: - - path: /metrics - port: https # Ensure this is the name of the port that exposes HTTPS metrics - scheme: https - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token - tlsConfig: - # TODO(user): The option insecureSkipVerify: true is not recommended for production since it disables - # certificate verification, exposing the system to potential man-in-the-middle attacks. - # For production environments, it is recommended to use cert-manager for automatic TLS certificate management. - # To apply this configuration, enable cert-manager and use the patch located at config/prometheus/servicemonitor_tls_patch.yaml, - # which securely references the certificate from the 'metrics-server-cert' secret. - insecureSkipVerify: true - selector: - matchLabels: - control-plane: controller-manager - app.kubernetes.io/name: controller diff --git a/go/controller/config/prometheus/monitor_tls_patch.yaml b/go/controller/config/prometheus/monitor_tls_patch.yaml deleted file mode 100644 index e824dd0ff..000000000 --- a/go/controller/config/prometheus/monitor_tls_patch.yaml +++ /dev/null @@ -1,22 +0,0 @@ -# Patch for Prometheus ServiceMonitor to enable secure TLS configuration -# using certificates managed by cert-manager -apiVersion: monitoring.coreos.com/v1 -kind: ServiceMonitor -metadata: - name: controller-manager-metrics-monitor - namespace: system -spec: - endpoints: - - tlsConfig: - insecureSkipVerify: false - ca: - secret: - name: metrics-server-cert - key: ca.crt - cert: - secret: - name: metrics-server-cert - key: tls.crt - keySecret: - name: metrics-server-cert - key: tls.key diff --git a/go/controller/test/e2e/e2e_suite_test.go b/go/controller/test/e2e/e2e_suite_test.go deleted file mode 100644 index 05d057597..000000000 --- a/go/controller/test/e2e/e2e_suite_test.go +++ /dev/null @@ -1,110 +0,0 @@ -/* -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 e2e - -import ( - "fmt" - "os" - "os/exec" - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/kagent-dev/kagent/go/controller/test/utils" -) - -var ( - // Optional Environment Variables: - // - PROMETHEUS_INSTALL_SKIP=true: Skips Prometheus Operator installation during test setup. - // - CERT_MANAGER_INSTALL_SKIP=true: Skips CertManager installation during test setup. - // These variables are useful if Prometheus or CertManager is already installed, avoiding - // re-installation and conflicts. - skipPrometheusInstall = os.Getenv("PROMETHEUS_INSTALL_SKIP") == "true" - skipCertManagerInstall = os.Getenv("CERT_MANAGER_INSTALL_SKIP") == "true" - // isPrometheusOperatorAlreadyInstalled will be set true when prometheus CRDs be found on the cluster - isPrometheusOperatorAlreadyInstalled = false - // isCertManagerAlreadyInstalled will be set true when CertManager CRDs be found on the cluster - isCertManagerAlreadyInstalled = false - - // projectImage is the name of the image which will be build and loaded - // with the code source changes to be tested. - projectImage = "example.com/controller:v0.0.1" -) - -// TestE2E runs the end-to-end (e2e) test suite for the project. These tests execute in an isolated, -// temporary environment to validate project changes with the the purposed to be used in CI jobs. -// The default setup requires Kind, builds/loads the Manager Docker image locally, and installs -// CertManager and Prometheus. -func TestE2E(t *testing.T) { - RegisterFailHandler(Fail) - _, _ = fmt.Fprintf(GinkgoWriter, "Starting controller integration test suite\n") - RunSpecs(t, "e2e suite") -} - -var _ = BeforeSuite(func() { - By("Ensure that Prometheus is enabled") - _ = utils.UncommentCode("config/default/kustomization.yaml", "#- ../prometheus", "#") - - By("building the manager(Operator) image") - cmd := exec.Command("make", "docker-build", fmt.Sprintf("IMG=%s", projectImage)) - _, err := utils.Run(cmd) - ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to build the manager(Operator) image") - - // TODO(user): If you want to change the e2e test vendor from Kind, ensure the image is - // built and available before running the tests. Also, remove the following block. - By("loading the manager(Operator) image on Kind") - err = utils.LoadImageToKindClusterWithName(projectImage) - ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to load the manager(Operator) image into Kind") - - // The tests-e2e are intended to run on a temporary cluster that is created and destroyed for testing. - // To prevent errors when tests run in environments with Prometheus or CertManager already installed, - // we check for their presence before execution. - // Setup Prometheus and CertManager before the suite if not skipped and if not already installed - if !skipPrometheusInstall { - By("checking if prometheus is installed already") - isPrometheusOperatorAlreadyInstalled = utils.IsPrometheusCRDsInstalled() - if !isPrometheusOperatorAlreadyInstalled { - _, _ = fmt.Fprintf(GinkgoWriter, "Installing Prometheus Operator...\n") - Expect(utils.InstallPrometheusOperator()).To(Succeed(), "Failed to install Prometheus Operator") - } else { - _, _ = fmt.Fprintf(GinkgoWriter, "WARNING: Prometheus Operator is already installed. Skipping installation...\n") - } - } - if !skipCertManagerInstall { - By("checking if cert manager is installed already") - isCertManagerAlreadyInstalled = utils.IsCertManagerCRDsInstalled() - if !isCertManagerAlreadyInstalled { - _, _ = fmt.Fprintf(GinkgoWriter, "Installing CertManager...\n") - Expect(utils.InstallCertManager()).To(Succeed(), "Failed to install CertManager") - } else { - _, _ = fmt.Fprintf(GinkgoWriter, "WARNING: CertManager is already installed. Skipping installation...\n") - } - } -}) - -var _ = AfterSuite(func() { - // Teardown Prometheus and CertManager after the suite if not skipped and if they were not already installed - if !skipPrometheusInstall && !isPrometheusOperatorAlreadyInstalled { - _, _ = fmt.Fprintf(GinkgoWriter, "Uninstalling Prometheus Operator...\n") - utils.UninstallPrometheusOperator() - } - if !skipCertManagerInstall && !isCertManagerAlreadyInstalled { - _, _ = fmt.Fprintf(GinkgoWriter, "Uninstalling CertManager...\n") - utils.UninstallCertManager() - } -}) diff --git a/go/controller/test/e2e/e2e_test.go b/go/controller/test/e2e/e2e_test.go deleted file mode 100644 index 2a3fd3c59..000000000 --- a/go/controller/test/e2e/e2e_test.go +++ /dev/null @@ -1,334 +0,0 @@ -/* -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 e2e - -import ( - "encoding/json" - "fmt" - "os" - "os/exec" - "path/filepath" - "time" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/kagent-dev/kagent/go/controller/test/utils" -) - -// namespace where the project is deployed in -const namespace = "controller-system" - -// serviceAccountName created for the project -const serviceAccountName = "controller-controller-manager" - -// metricsServiceName is the name of the metrics service of the project -const metricsServiceName = "controller-controller-manager-metrics-service" - -// metricsRoleBindingName is the name of the RBAC that will be created to allow get the metrics data -const metricsRoleBindingName = "controller-metrics-binding" - -var _ = Describe("Manager", Ordered, func() { - var controllerPodName string - - // Before running the tests, set up the environment by creating the namespace, - // enforce the restricted security policy to the namespace, installing CRDs, - // and deploying the controller. - BeforeAll(func() { - By("creating manager namespace") - cmd := exec.Command("kubectl", "create", "ns", namespace) - _, err := utils.Run(cmd) - Expect(err).NotTo(HaveOccurred(), "Failed to create namespace") - - By("labeling the namespace to enforce the restricted security policy") - cmd = exec.Command("kubectl", "label", "--overwrite", "ns", namespace, - "pod-security.kubernetes.io/enforce=restricted") - _, err = utils.Run(cmd) - Expect(err).NotTo(HaveOccurred(), "Failed to label namespace with restricted policy") - - By("installing CRDs") - cmd = exec.Command("make", "install") - _, err = utils.Run(cmd) - Expect(err).NotTo(HaveOccurred(), "Failed to install CRDs") - - By("deploying the controller-manager") - cmd = exec.Command("make", "deploy", fmt.Sprintf("IMG=%s", projectImage)) - _, err = utils.Run(cmd) - Expect(err).NotTo(HaveOccurred(), "Failed to deploy the controller-manager") - }) - - // After all tests have been executed, clean up by undeploying the controller, uninstalling CRDs, - // and deleting the namespace. - AfterAll(func() { - By("cleaning up the curl pod for metrics") - cmd := exec.Command("kubectl", "delete", "pod", "curl-metrics", "-n", namespace) - _, _ = utils.Run(cmd) - - By("undeploying the controller-manager") - cmd = exec.Command("make", "undeploy") - _, _ = utils.Run(cmd) - - By("uninstalling CRDs") - cmd = exec.Command("make", "uninstall") - _, _ = utils.Run(cmd) - - By("removing manager namespace") - cmd = exec.Command("kubectl", "delete", "ns", namespace) - _, _ = utils.Run(cmd) - }) - - // After each test, check for failures and collect logs, events, - // and pod descriptions for debugging. - AfterEach(func() { - specReport := CurrentSpecReport() - if specReport.Failed() { - By("Fetching controller manager pod logs") - cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace) - controllerLogs, err := utils.Run(cmd) - if err == nil { - _, _ = fmt.Fprintf(GinkgoWriter, "Controller logs:\n %s", controllerLogs) - } else { - _, _ = fmt.Fprintf(GinkgoWriter, "Failed to get Controller logs: %s", err) - } - - By("Fetching Kubernetes events") - cmd = exec.Command("kubectl", "get", "events", "-n", namespace, "--sort-by=.lastTimestamp") - eventsOutput, err := utils.Run(cmd) - if err == nil { - _, _ = fmt.Fprintf(GinkgoWriter, "Kubernetes events:\n%s", eventsOutput) - } else { - _, _ = fmt.Fprintf(GinkgoWriter, "Failed to get Kubernetes events: %s", err) - } - - By("Fetching curl-metrics logs") - cmd = exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace) - metricsOutput, err := utils.Run(cmd) - if err == nil { - _, _ = fmt.Fprintf(GinkgoWriter, "Metrics logs:\n %s", metricsOutput) - } else { - _, _ = fmt.Fprintf(GinkgoWriter, "Failed to get curl-metrics logs: %s", err) - } - - By("Fetching controller manager pod description") - cmd = exec.Command("kubectl", "describe", "pod", controllerPodName, "-n", namespace) - podDescription, err := utils.Run(cmd) - if err == nil { - fmt.Println("Pod description:\n", podDescription) - } else { - fmt.Println("Failed to describe controller pod") - } - } - }) - - SetDefaultEventuallyTimeout(2 * time.Minute) - SetDefaultEventuallyPollingInterval(time.Second) - - Context("Manager", func() { - It("should run successfully", func() { - By("validating that the controller-manager pod is running as expected") - verifyControllerUp := func(g Gomega) { - // Get the name of the controller-manager pod - cmd := exec.Command("kubectl", "get", - "pods", "-l", "control-plane=controller-manager", - "-o", "go-template={{ range .items }}"+ - "{{ if not .metadata.deletionTimestamp }}"+ - "{{ .metadata.name }}"+ - "{{ \"\\n\" }}{{ end }}{{ end }}", - "-n", namespace, - ) - - podOutput, err := utils.Run(cmd) - g.Expect(err).NotTo(HaveOccurred(), "Failed to retrieve controller-manager pod information") - podNames := utils.GetNonEmptyLines(podOutput) - g.Expect(podNames).To(HaveLen(1), "expected 1 controller pod running") - controllerPodName = podNames[0] - g.Expect(controllerPodName).To(ContainSubstring("controller-manager")) - - // Validate the pod's status - cmd = exec.Command("kubectl", "get", - "pods", controllerPodName, "-o", "jsonpath={.status.phase}", - "-n", namespace, - ) - output, err := utils.Run(cmd) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(output).To(Equal("Running"), "Incorrect controller-manager pod status") - } - Eventually(verifyControllerUp).Should(Succeed()) - }) - - It("should ensure the metrics endpoint is serving metrics", func() { - By("creating a ClusterRoleBinding for the service account to allow access to metrics") - cmd := exec.Command("kubectl", "create", "clusterrolebinding", metricsRoleBindingName, - "--clusterrole=controller-metrics-reader", - fmt.Sprintf("--serviceaccount=%s:%s", namespace, serviceAccountName), - ) - _, err := utils.Run(cmd) - Expect(err).NotTo(HaveOccurred(), "Failed to create ClusterRoleBinding") - - By("validating that the metrics service is available") - cmd = exec.Command("kubectl", "get", "service", metricsServiceName, "-n", namespace) - _, err = utils.Run(cmd) - Expect(err).NotTo(HaveOccurred(), "Metrics service should exist") - - By("validating that the ServiceMonitor for Prometheus is applied in the namespace") - cmd = exec.Command("kubectl", "get", "ServiceMonitor", "-n", namespace) - _, err = utils.Run(cmd) - Expect(err).NotTo(HaveOccurred(), "ServiceMonitor should exist") - - By("getting the service account token") - token, err := serviceAccountToken() - Expect(err).NotTo(HaveOccurred()) - Expect(token).NotTo(BeEmpty()) - - By("waiting for the metrics endpoint to be ready") - verifyMetricsEndpointReady := func(g Gomega) { - cmd := exec.Command("kubectl", "get", "endpoints", metricsServiceName, "-n", namespace) - output, err := utils.Run(cmd) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(output).To(ContainSubstring("8443"), "Metrics endpoint is not ready") - } - Eventually(verifyMetricsEndpointReady).Should(Succeed()) - - By("verifying that the controller manager is serving the metrics server") - verifyMetricsServerStarted := func(g Gomega) { - cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace) - output, err := utils.Run(cmd) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(output).To(ContainSubstring("controller-runtime.metrics\tServing metrics server"), - "Metrics server not yet started") - } - Eventually(verifyMetricsServerStarted).Should(Succeed()) - - By("creating the curl-metrics pod to access the metrics endpoint") - cmd = exec.Command("kubectl", "run", "curl-metrics", "--restart=Never", - "--namespace", namespace, - "--image=curlimages/curl:latest", - "--overrides", - fmt.Sprintf(`{ - "spec": { - "containers": [{ - "name": "curl", - "image": "curlimages/curl:latest", - "command": ["/bin/sh", "-c"], - "args": ["curl -v -k -H 'Authorization: Bearer %s' https://%s.%s.svc.cluster.local:8443/metrics"], - "securityContext": { - "allowPrivilegeEscalation": false, - "capabilities": { - "drop": ["ALL"] - }, - "runAsNonRoot": true, - "runAsUser": 1000, - "seccompProfile": { - "type": "RuntimeDefault" - } - } - }], - "serviceAccount": "%s" - } - }`, token, metricsServiceName, namespace, serviceAccountName)) - _, err = utils.Run(cmd) - Expect(err).NotTo(HaveOccurred(), "Failed to create curl-metrics pod") - - By("waiting for the curl-metrics pod to complete.") - verifyCurlUp := func(g Gomega) { - cmd := exec.Command("kubectl", "get", "pods", "curl-metrics", - "-o", "jsonpath={.status.phase}", - "-n", namespace) - output, err := utils.Run(cmd) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(output).To(Equal("Succeeded"), "curl pod in wrong status") - } - Eventually(verifyCurlUp, 5*time.Minute).Should(Succeed()) - - By("getting the metrics by checking curl-metrics logs") - metricsOutput := getMetricsOutput() - Expect(metricsOutput).To(ContainSubstring( - "controller_runtime_reconcile_total", - )) - }) - - // +kubebuilder:scaffold:e2e-webhooks-checks - - // TODO: Customize the e2e test suite with scenarios specific to your project. - // Consider applying sample/CR(s) and check their status and/or verifying - // the reconciliation by using the metrics, i.e.: - // metricsOutput := getMetricsOutput() - // Expect(metricsOutput).To(ContainSubstring( - // fmt.Sprintf(`controller_runtime_reconcile_total{controller="%s",result="success"} 1`, - // strings.ToLower(), - // )) - }) -}) - -// serviceAccountToken returns a token for the specified service account in the given namespace. -// It uses the Kubernetes TokenRequest API to generate a token by directly sending a request -// and parsing the resulting token from the API response. -func serviceAccountToken() (string, error) { - const tokenRequestRawString = `{ - "apiVersion": "authentication.k8s.io/v1", - "kind": "TokenRequest" - }` - - // Temporary file to store the token request - secretName := fmt.Sprintf("%s-token-request", serviceAccountName) - tokenRequestFile := filepath.Join("/tmp", secretName) - err := os.WriteFile(tokenRequestFile, []byte(tokenRequestRawString), os.FileMode(0o644)) - if err != nil { - return "", err - } - - var out string - verifyTokenCreation := func(g Gomega) { - // Execute kubectl command to create the token - cmd := exec.Command("kubectl", "create", "--raw", fmt.Sprintf( - "/api/v1/namespaces/%s/serviceaccounts/%s/token", - namespace, - serviceAccountName, - ), "-f", tokenRequestFile) - - output, err := cmd.CombinedOutput() - g.Expect(err).NotTo(HaveOccurred()) - - // Parse the JSON output to extract the token - var token tokenRequest - err = json.Unmarshal(output, &token) - g.Expect(err).NotTo(HaveOccurred()) - - out = token.Status.Token - } - Eventually(verifyTokenCreation).Should(Succeed()) - - return out, err -} - -// getMetricsOutput retrieves and returns the logs from the curl pod used to access the metrics endpoint. -func getMetricsOutput() string { - By("getting the curl-metrics logs") - cmd := exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace) - metricsOutput, err := utils.Run(cmd) - Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod") - Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK")) - return metricsOutput -} - -// tokenRequest is a simplified representation of the Kubernetes TokenRequest API response, -// containing only the token field that we need to extract. -type tokenRequest struct { - Status struct { - Token string `json:"token"` - } `json:"status"` -} diff --git a/go/controller/test/utils/utils.go b/go/controller/test/utils/utils.go deleted file mode 100644 index 04a5141cc..000000000 --- a/go/controller/test/utils/utils.go +++ /dev/null @@ -1,251 +0,0 @@ -/* -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 utils - -import ( - "bufio" - "bytes" - "fmt" - "os" - "os/exec" - "strings" - - . "github.com/onsi/ginkgo/v2" //nolint:golint,revive -) - -const ( - prometheusOperatorVersion = "v0.77.1" - prometheusOperatorURL = "https://github.com/prometheus-operator/prometheus-operator/" + - "releases/download/%s/bundle.yaml" - - certmanagerVersion = "v1.16.3" - certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml" -) - -func warnError(err error) { - _, _ = fmt.Fprintf(GinkgoWriter, "warning: %v\n", err) -} - -// Run executes the provided command within this context -func Run(cmd *exec.Cmd) (string, error) { - dir, _ := GetProjectDir() - cmd.Dir = dir - - if err := os.Chdir(cmd.Dir); err != nil { - _, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %s\n", err) - } - - cmd.Env = append(os.Environ(), "GO111MODULE=on") - command := strings.Join(cmd.Args, " ") - _, _ = fmt.Fprintf(GinkgoWriter, "running: %s\n", command) - output, err := cmd.CombinedOutput() - if err != nil { - return string(output), fmt.Errorf("%s failed with error: (%v) %s", command, err, string(output)) - } - - return string(output), nil -} - -// InstallPrometheusOperator installs the prometheus Operator to be used to export the enabled metrics. -func InstallPrometheusOperator() error { - url := fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion) - cmd := exec.Command("kubectl", "create", "-f", url) - _, err := Run(cmd) - return err -} - -// UninstallPrometheusOperator uninstalls the prometheus -func UninstallPrometheusOperator() { - url := fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion) - cmd := exec.Command("kubectl", "delete", "-f", url) - if _, err := Run(cmd); err != nil { - warnError(err) - } -} - -// IsPrometheusCRDsInstalled checks if any Prometheus CRDs are installed -// by verifying the existence of key CRDs related to Prometheus. -func IsPrometheusCRDsInstalled() bool { - // List of common Prometheus CRDs - prometheusCRDs := []string{ - "prometheuses.monitoring.coreos.com", - "prometheusrules.monitoring.coreos.com", - "prometheusagents.monitoring.coreos.com", - } - - cmd := exec.Command("kubectl", "get", "crds", "-o", "custom-columns=NAME:.metadata.name") - output, err := Run(cmd) - if err != nil { - return false - } - crdList := GetNonEmptyLines(output) - for _, crd := range prometheusCRDs { - for _, line := range crdList { - if strings.Contains(line, crd) { - return true - } - } - } - - return false -} - -// UninstallCertManager uninstalls the cert manager -func UninstallCertManager() { - url := fmt.Sprintf(certmanagerURLTmpl, certmanagerVersion) - cmd := exec.Command("kubectl", "delete", "-f", url) - if _, err := Run(cmd); err != nil { - warnError(err) - } -} - -// InstallCertManager installs the cert manager bundle. -func InstallCertManager() error { - url := fmt.Sprintf(certmanagerURLTmpl, certmanagerVersion) - cmd := exec.Command("kubectl", "apply", "-f", url) - if _, err := Run(cmd); err != nil { - return err - } - // Wait for cert-manager-webhook to be ready, which can take time if cert-manager - // was re-installed after uninstalling on a cluster. - cmd = exec.Command("kubectl", "wait", "deployment.apps/cert-manager-webhook", - "--for", "condition=Available", - "--namespace", "cert-manager", - "--timeout", "5m", - ) - - _, err := Run(cmd) - return err -} - -// IsCertManagerCRDsInstalled checks if any Cert Manager CRDs are installed -// by verifying the existence of key CRDs related to Cert Manager. -func IsCertManagerCRDsInstalled() bool { - // List of common Cert Manager CRDs - certManagerCRDs := []string{ - "certificates.cert-manager.io", - "issuers.cert-manager.io", - "clusterissuers.cert-manager.io", - "certificaterequests.cert-manager.io", - "orders.acme.cert-manager.io", - "challenges.acme.cert-manager.io", - } - - // Execute the kubectl command to get all CRDs - cmd := exec.Command("kubectl", "get", "crds") - output, err := Run(cmd) - if err != nil { - return false - } - - // Check if any of the Cert Manager CRDs are present - crdList := GetNonEmptyLines(output) - for _, crd := range certManagerCRDs { - for _, line := range crdList { - if strings.Contains(line, crd) { - return true - } - } - } - - return false -} - -// LoadImageToKindClusterWithName loads a local docker image to the kind cluster -func LoadImageToKindClusterWithName(name string) error { - cluster := "kind" - if v, ok := os.LookupEnv("KIND_CLUSTER"); ok { - cluster = v - } - kindOptions := []string{"load", "docker-image", name, "--name", cluster} - cmd := exec.Command("kind", kindOptions...) - _, err := Run(cmd) - return err -} - -// GetNonEmptyLines converts given command output string into individual objects -// according to line breakers, and ignores the empty elements in it. -func GetNonEmptyLines(output string) []string { - var res []string - elements := strings.Split(output, "\n") - for _, element := range elements { - if element != "" { - res = append(res, element) - } - } - - return res -} - -// GetProjectDir will return the directory where the project is -func GetProjectDir() (string, error) { - wd, err := os.Getwd() - if err != nil { - return wd, err - } - wd = strings.Replace(wd, "/test/e2e", "", -1) - return wd, nil -} - -// UncommentCode searches for target in the file and remove the comment prefix -// of the target content. The target content may span multiple lines. -func UncommentCode(filename, target, prefix string) error { - // false positive - // nolint:gosec - content, err := os.ReadFile(filename) - if err != nil { - return err - } - strContent := string(content) - - idx := strings.Index(strContent, target) - if idx < 0 { - return fmt.Errorf("unable to find the code %s to be uncomment", target) - } - - out := new(bytes.Buffer) - _, err = out.Write(content[:idx]) - if err != nil { - return err - } - - scanner := bufio.NewScanner(bytes.NewBufferString(target)) - if !scanner.Scan() { - return nil - } - for { - _, err := out.WriteString(strings.TrimPrefix(scanner.Text(), prefix)) - if err != nil { - return err - } - // Avoid writing a newline in case the previous line was the last in target. - if !scanner.Scan() { - break - } - if _, err := out.WriteString("\n"); err != nil { - return err - } - } - - _, err = out.Write(content[idx+len(target):]) - if err != nil { - return err - } - // false positive - // nolint:gosec - return os.WriteFile(filename, out.Bytes(), 0644) -} From 374baa39932732034b4394f721d7b716bfb0f5a2 Mon Sep 17 00:00:00 2001 From: Scott Weiss Date: Mon, 3 Feb 2025 11:00:37 -0500 Subject: [PATCH 12/12] bump go version --- go/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/go.mod b/go/go.mod index 7e21ca528..590eb9a10 100644 --- a/go/go.mod +++ b/go/go.mod @@ -1,6 +1,6 @@ module github.com/kagent-dev/kagent/go -go 1.23.3 +go 1.23.5 require ( github.com/onsi/ginkgo/v2 v2.21.0