Skip to content

Commit

Permalink
Build grpc ingestor image (DataDog#201)
Browse files Browse the repository at this point in the history
* add local build for ingestor

* fix build ingestor image

* reduce binary arch supported

* removing goreleaser

* adding version tag for embed compose files

* removing version deprecated

* fix compose datadog

* PR comment

* Update pkg/backend/project.go

Co-authored-by: Edouard Schweisguth <edouard.schweisguth@datadoghq.com>

---------

Co-authored-by: Edouard Schweisguth <edouard.schweisguth@datadoghq.com>
  • Loading branch information
jt-dd and edznux-dd authored Jun 11, 2024
1 parent 8b7951b commit 6483322
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 127 deletions.
57 changes: 0 additions & 57 deletions .github/workflows/release.yml

This file was deleted.

51 changes: 0 additions & 51 deletions .goreleaser.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SYSTEM_TEST_CMD := system-test system-test-clean
COMMIT := $(shell git rev-parse --short HEAD)
DATE := $(shell git log -1 --format=%cd --date=format:"%Y%m%d")

BUILD_VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags)
BUILD_VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty --always --tags)
BUILD_ARCH := $(shell go env GOARCH)
BUILD_OS := $(shell go env GOOS)

Expand Down
3 changes: 0 additions & 3 deletions cmd/kubehound/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ var (
Backend *docker.Backend
hard bool
composePath []string

downTesting bool
uiTesting bool
)

var (
Expand Down
11 changes: 11 additions & 0 deletions cmd/kubehound/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ var (
DefaultComposeTestingPath = []string{"./deployments/kubehound/docker-compose.yaml", "./deployments/kubehound/docker-compose.testing.yaml"}
DefaultComposeDevPath = []string{"./deployments/kubehound/docker-compose.yaml", "./deployments/kubehound/docker-compose.dev.yaml"}
DefaultComposeDevPathUI = "./deployments/kubehound/docker-compose.ui.yaml"
DefaultComposeDevPathGRPC = "./deployments/kubehound/docker-compose.ingestor.yaml"
DefaultDatadogComposePath = "./deployments/kubehound/docker-compose.datadog.yaml"
)

var (
uiTesting bool
grpcTesting bool
downTesting bool
)

var (
envCmd = &cobra.Command{
Use: "dev",
Expand All @@ -28,6 +35,9 @@ var (
if uiTesting {
DefaultComposeDevPath = append(DefaultComposeDevPath, DefaultComposeDevPathUI)
}
if grpcTesting {
DefaultComposeDevPath = append(DefaultComposeDevPath, DefaultComposeDevPathGRPC)
}
// Adding datadog setup
_, ddAPIKeyOk := os.LookupEnv("DD_API_KEY")
_, ddAPPKeyOk := os.LookupEnv("DD_API_KEY")
Expand Down Expand Up @@ -65,6 +75,7 @@ func init() {
envCmd.AddCommand(envTestingCmd)
envCmd.PersistentFlags().BoolVar(&downTesting, "down", false, "Tearing down the kubehound dev stack and deleting the data associated with it")
envCmd.Flags().BoolVar(&uiTesting, "ui", false, "Include the UI in the dev stack")
envCmd.Flags().BoolVar(&grpcTesting, "grpc", false, "Include Grpc Server (ingestor) in the dev stack")

rootCmd.AddCommand(envCmd)
}
2 changes: 0 additions & 2 deletions deployments/kubehound/docker-compose.datadog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ services:
datadog:
image: gcr.io/datadoghq/agent:7-jmx
restart: unless-stopped
profiles: ["infra"]
container_name: ${COMPOSE_PROJECT_NAME}-datadog-agent
ports:
- "127.0.0.1:8225:8125/UDP"
- "127.0.0.1:8226:8126"
Expand Down
13 changes: 13 additions & 0 deletions deployments/kubehound/docker-compose.ingestor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
grpc:
build:
context: ../../
dockerfile: deployments/kubehound/ingestor/Dockerfile
restart: unless-stopped
ports:
- "127.0.0.1:9000:9000"
networks:
- kubenet

networks:
kubenet:
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ services:
- mongodb_data:/data/db

kubegraph:
image: ghcr.io/datadog/kubehound-graph:latest
image: ghcr.io/datadog/kubehound-graph:{{ .VersionTag }}
ports:
- "127.0.0.1:8182:8182"
- "127.0.0.1:8099:8099"
volumes:
- kubegraph_data:/var/lib/janusgraph

ui:
image: ghcr.io/datadog/kubehound-ui:latest
image: ghcr.io/datadog/kubehound-ui:{{ .VersionTag }}
restart: unless-stopped
ports:
- "127.0.0.1:8888:8888"
Expand Down
2 changes: 0 additions & 2 deletions deployments/kubehound/docker-compose.ui.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
version: "3.8"
services:
notebook:
build: ./notebook/
restart: unless-stopped
container_name: ${COMPOSE_PROJECT_NAME}-notebook
ports:
- "127.0.0.1:8888:8888"
networks:
Expand Down
1 change: 1 addition & 0 deletions deployments/kubehound/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import (
)

//go:embed *.yaml
//go:embed *.yaml.tpl
var F embed.FS
2 changes: 1 addition & 1 deletion deployments/kubehound/ingestor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ FROM gcr.io/distroless/base-debian12 AS build-release-stage

WORKDIR /

COPY --from=build-stage /go/bin/kubehound /kubehound
COPY --from=build-stage /go/bin/build/kubehound /kubehound

EXPOSE 9000

Expand Down
4 changes: 0 additions & 4 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,8 @@ target "binary-cross" {
"darwin/amd64",
"darwin/arm64",
"linux/amd64",
"linux/arm/v6",
"linux/arm/v7",
"linux/arm64",
"linux/ppc64le",
"linux/riscv64",
"linux/s390x",
"windows/amd64",
"windows/arm64"
]
Expand Down
35 changes: 31 additions & 4 deletions pkg/backend/project.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package backend

import (
"bytes"
"context"
"fmt"
"os"
"strings"
"text/template"

embedconfigdocker "github.com/DataDog/KubeHound/deployments/kubehound"
"github.com/DataDog/KubeHound/pkg/config"
"github.com/DataDog/KubeHound/pkg/telemetry/log"
"github.com/compose-spec/compose-go/v2/cli"
"github.com/compose-spec/compose-go/v2/loader"
Expand All @@ -16,7 +19,7 @@ import (
)

var (
DefaultReleaseComposePaths = []string{"docker-compose.yaml", "docker-compose.release.yaml"}
DefaultReleaseComposePaths = []string{"docker-compose.yaml", "docker-compose.release.yaml.tpl"}
DefaultDatadogComposePath = "docker-compose.datadog.yaml"
)

Expand Down Expand Up @@ -84,6 +87,7 @@ func loadEmbeddedConfig(ctx context.Context) (*types.Project, error) {
// Adding datadog setup
ddAPIKey, ddAPIKeyOk := os.LookupEnv("DD_API_KEY")
ddAPPKey, ddAPPKeyOk := os.LookupEnv("DD_API_KEY")

if ddAPIKeyOk && ddAPPKeyOk {
DefaultReleaseComposePaths = append(DefaultReleaseComposePaths, DefaultDatadogComposePath)
hostname, err = os.Hostname()
Expand Down Expand Up @@ -123,10 +127,33 @@ func loadEmbeddedConfig(ctx context.Context) (*types.Project, error) {

func loadEmbeddedDockerCompose(_ context.Context, filepath string, dockerComposeFileData map[interface{}]interface{}) (map[interface{}]interface{}, error) {
var localYaml map[interface{}]interface{}
var localData []byte
var err error

localData, err := embedconfigdocker.F.ReadFile(filepath)
if err != nil {
return nil, fmt.Errorf("reading embed config: %w", err)
// Setting the version tag for the release dynamically
// For local version (when the version is "dirty", using latest to have a working binary)
version := map[string]string{"VersionTag": "latest"}
if !strings.HasSuffix(config.BuildVersion, "dirty") {
version["VersionTag"] = config.BuildVersion
}

if strings.HasSuffix(filepath, ".tpl") {
tmpl, err := template.New(filepath).ParseFS(embedconfigdocker.F, filepath)
if err != nil {
return nil, fmt.Errorf("new template: %w", err)
}

var buf bytes.Buffer
err = tmpl.Execute(&buf, version)
if err != nil {
return nil, fmt.Errorf("executing template: %w", err)
}
localData = buf.Bytes()
} else {
localData, err = embedconfigdocker.F.ReadFile(filepath)
if err != nil {
return nil, fmt.Errorf("reading embed config: %w", err)
}
}

err = yaml.Unmarshal(localData, &localYaml)
Expand Down

0 comments on commit 6483322

Please sign in to comment.