Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,20 @@ jobs:
run: make build-${{ matrix.image }}
working-directory: ./

go-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.24"
cache: true
cache-dependency-path: go/go.sum
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: v2.1
working-directory: go
22 changes: 22 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,25 @@ docker buildx create --name kagent-builder-v0.23.0 --platform linux/amd64,linux/
```

Then run the `make helm-install` command again.

### Run kagent and an agent locally.

create a minimal cluster with kind. scale kagent to 0 replicas, as we will run it locally.

```bash
make create-kind-cluster helm-install-provider helm-tools push-test-agent
kubectl scale -n kagent deployment kagent-controller --replicas 0
```

Run kagent with `KAGENT_A2A_DEBUG_ADDR=localhost:8080` environment variable set, and when it connect to agents it will go to "localhost:8080" instead of the Kubernetes service.

Run the agent locally as well, with `--net=host` option, so it can connect to the kagent service on localhost. For example:

```bash
docker run --rm \
-e KAGENT_URL=http://localhost:8083 \
-e KAGENT_NAME=kebab-agent \
-e KAGENT_NAMESPACE=kagent \
--net=host \
localhost:5001/kebab:latest
```
File renamed without changes.
11 changes: 11 additions & 0 deletions go/.golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "2"

linters:
# Default set of linters.
# The value can be:
# - `standard`: https://golangci-lint.run/docs/linters/#enabled-by-default
# - `all`: enables all linters by default.
# - `none`: disables all linters by default.
# - `fast`: enables only linters considered as "fast" (`golangci-lint help linters --json | jq '[ .[] | select(.fast==true) ] | map(.name)'`).
# Default: standard
default: standard
5 changes: 3 additions & 2 deletions go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ RUN --mount=type=cache,target=/root/go/pkg/mod,rw \
go mod download

# Copy the go source
COPY api api
COPY cmd cmd
COPY pkg pkg
COPY internal internal
COPY controller controller
# 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
Expand All @@ -30,7 +31,7 @@ ARG LDFLAGS
RUN --mount=type=cache,target=/root/go/pkg/mod,rw \
--mount=type=cache,target=/root/.cache/go-build,rw \
echo "Building on $BUILDPLATFORM -> linux/$TARGETARCH" && \
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -ldflags "$LDFLAGS" -o manager controller/cmd/main.go
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -ldflags "$LDFLAGS" -o manager cmd/controller/main.go

### STAGE 2: final image
# Use distroless as minimal base image to package the manager binary
Expand Down
12 changes: 6 additions & 6 deletions go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ endif
##@ Development

.PHONY: manifests
manifests: controller-gen generate ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
manifests: controller-gen generate ## Generate ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd 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="controller/hack/boilerplate.go.txt" paths="./..."
$(CONTROLLER_GEN) object:headerFile="internal/controller/hack/boilerplate.go.txt" paths="./..."

.PHONY: fmt
fmt: ## Run go fmt against code.
Expand Down Expand Up @@ -94,7 +94,7 @@ build: bin/kagent-linux-amd64.sha256 bin/kagent-linux-arm64.sha256 bin/kagent-da

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./controller/cmd/main.go
go run ./cmd/controller/main.go

.PHONY: test
test:
Expand Down Expand Up @@ -134,7 +134,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.17.1
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
GOLANGCI_LINT_VERSION ?= v2.4.0

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
Expand All @@ -157,7 +157,7 @@ $(ENVTEST): $(LOCALBIN)
.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))
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/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
Expand Down
15 changes: 10 additions & 5 deletions go/cli/cmd/kagent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/abiosoft/ishell/v2"
"github.com/kagent-dev/kagent/go/cli/internal/cli"
"github.com/kagent-dev/kagent/go/cli/internal/config"
"github.com/kagent-dev/kagent/go/cli/internal/profiles"
"github.com/kagent-dev/kagent/go/pkg/client"
"github.com/spf13/cobra"
)
Expand All @@ -32,14 +33,19 @@ func main() {
rootCmd.PersistentFlags().StringVarP(&cfg.Namespace, "namespace", "n", "kagent", "Namespace")
rootCmd.PersistentFlags().StringVarP(&cfg.OutputFormat, "output-format", "o", "table", "Output format")
rootCmd.PersistentFlags().BoolVarP(&cfg.Verbose, "verbose", "v", false, "Verbose output")
var profile string
installCmd := &cobra.Command{
Use: "install",
Short: "Install kagent",
Long: `Install kagent`,
Run: func(cmd *cobra.Command, args []string) {
cli.InstallCmd(cmd.Context(), cfg)
cli.InstallCmd(cmd.Context(), cfg, profile)
},
}
installCmd.Flags().StringVar(&profile, "profile", "", "Installation profile (minimal|demo)")
_ = installCmd.RegisterFlagCompletionFunc("profile", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return profiles.Profiles, cobra.ShellCompDirectiveNoFileComp
})

uninstallCmd := &cobra.Command{
Use: "uninstall",
Expand Down Expand Up @@ -70,7 +76,7 @@ func main() {
invokeCmd.Flags().BoolVarP(&invokeCfg.Stream, "stream", "S", false, "Stream the response")
invokeCmd.Flags().StringVarP(&invokeCfg.File, "file", "f", "", "File to read the task from")
invokeCmd.Flags().StringVarP(&invokeCfg.URLOverride, "url-override", "u", "", "URL override")
invokeCmd.Flags().MarkHidden("url-override")
invokeCmd.Flags().MarkHidden("url-override") //nolint:errcheck

bugReportCmd := &cobra.Command{
Use: "bug-report",
Expand Down Expand Up @@ -123,7 +129,7 @@ func main() {
Long: `Get a kagent resource`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(os.Stderr, "No resource type provided\n\n")
cmd.Help()
cmd.Help() //nolint:errcheck
os.Exit(1)
},
}
Expand Down Expand Up @@ -434,8 +440,7 @@ Example:
Aliases: []string{"i"},
Help: "Install kagent.",
Func: func(c *ishell.Context) {
cfg := config.GetCfg(c)
if pf := cli.InstallCmd(ctx, cfg); pf != nil {
if pf := cli.InteractiveInstallCmd(ctx, c); pf != nil {
// Set the port-forward to the shell.
shell.Set(portForwardKey, pf)
}
Expand Down
2 changes: 1 addition & 1 deletion go/cli/internal/cli/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"
"strings"

"github.com/kagent-dev/kagent/go/controller/api/v1alpha1"
"github.com/kagent-dev/kagent/go/api/v1alpha1"
)

const (
Expand Down
8 changes: 4 additions & 4 deletions go/cli/internal/cli/const_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"
"testing"

"github.com/kagent-dev/kagent/go/controller/api/v1alpha1"
"github.com/kagent-dev/kagent/go/api/v1alpha1"
)

func TestGetModelProvider(t *testing.T) {
Expand Down Expand Up @@ -62,10 +62,10 @@ func TestGetModelProvider(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if tc.envVarValue == "" {
os.Unsetenv(KAGENT_DEFAULT_MODEL_PROVIDER)
os.Unsetenv(KAGENT_DEFAULT_MODEL_PROVIDER) //nolint:errcheck
} else {
os.Setenv(KAGENT_DEFAULT_MODEL_PROVIDER, tc.expectedHelmKey)
defer os.Unsetenv(KAGENT_DEFAULT_MODEL_PROVIDER)
os.Setenv(KAGENT_DEFAULT_MODEL_PROVIDER, tc.expectedHelmKey) //nolint:errcheck
defer os.Unsetenv(KAGENT_DEFAULT_MODEL_PROVIDER) //nolint:errcheck
}

result := GetModelProvider()
Expand Down
4 changes: 2 additions & 2 deletions go/cli/internal/cli/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func GetAgentCmd(cfg *config.Config, resourceName string) {
return
}
byt, _ := json.MarshalIndent(agent, "", " ")
fmt.Fprintln(os.Stdout, string(byt))
fmt.Fprintln(os.Stdout, string(byt)) //nolint:errcheck
}
}

Expand Down Expand Up @@ -70,7 +70,7 @@ func GetSessionCmd(cfg *config.Config, resourceName string) {
return
}
byt, _ := json.MarshalIndent(session, "", " ")
fmt.Fprintln(os.Stdout, string(byt))
fmt.Fprintln(os.Stdout, string(byt)) //nolint:errcheck
}
}

Expand Down
Loading