Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Selector based injection for all available agents #87

Merged
merged 7 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
.github/
bin/
charts/
config/
local/
testbin/
tests/
tmp/
3 changes: 2 additions & 1 deletion .github/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ linters:
- errcheck
- errorlint
- exhaustive
- exportloopref
#- exportloopref Since Go1.22 (loopvar) this linter is no longer relevant.
- copyloopvar
- gocyclo
- goprintffuncname
- gosimple
Expand Down
14 changes: 7 additions & 7 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* @newrelic/k8s-agents
tippmar-nr marked this conversation as resolved.
Show resolved Hide resolved

# APM team owned directories
/src/apm/dotnet.go @newrelic/dotnet
/src/apm/golang.go @newrelic/go-agent
/src/apm/javaagent.go @newrelic/java-agent
/src/apm/nodejs.go @newrelic/node-js-agent
/src/apm/php.go @newrelic/php-agent
/src/apm/python.go @newrelic/python
/src/apm/ruby.go @newrelic/ruby-agent
/src/apm/dotnet*.go @newrelic/dotnet
/src/apm/golang*.go @newrelic/go
/src/apm/java*.go @newrelic/java
/src/apm/nodejs*.go @newrelic/node
/src/apm/php*.go @newrelic/php-agent
danielstokes marked this conversation as resolved.
Show resolved Hide resolved
/src/apm/python*.go @newrelic/python
/src/apm/ruby*.go @newrelic/ruby
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
# In certain contexts, only the less ambiguous ${version} form works
# Source: https://tldp.org/LDP/abs/html/parameter-substitution.html
run: |
version="v1.13.1"
version="v1.14.2"
stripped=$( echo "${version}" | sed s'/v//' )
wget https://github.com/norwoodj/helm-docs/releases/download/${version}/helm-docs_${stripped}_Linux_x86_64.tar.gz
tar --extract --verbose --file="helm-docs_${stripped}_Linux_x86_64.tar.gz" helm-docs
Expand Down Expand Up @@ -128,7 +128,7 @@ jobs:
matrix:
# Latest patch version can be found in https://github.com/kubernetes/website/blob/main/content/en/releases/patch-releases.md
# Some versions might not be available yet in https://storage.googleapis.com/kubernetes-release/release/v1.X.Y/bin/linux/amd64/kubelet
k8sVersion: [ "v1.30.0", "v1.29.5", "v1.28.3", "v1.27.5", "v1.26.8" ]
k8sVersion: [ "v1.31.1", "v1.30.5", "v1.29.9", "v1.28.14", "v1.27.16", "v1.26.15" ]
steps:
- name: Checkout GitHub Repository
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
bin/
tmp/

config
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ RUN go mod download
COPY ./src/ ./src/
COPY Makefile .

ARG TARGETOS TARGETARCH
ARG TARGETOS
ARG TARGETARCH
ARG GOOS=$TARGETOS
ARG GOARCH=$TARGETARCH

Expand Down
219 changes: 193 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,225 @@ GO_DIR = ./src
BIN_DIR = ./bin
TMP_DIR = $(shell pwd)/tmp

LICENSE_KEY ?= fake-abc123
E2E_K8S_VERSION ?= v1.31.1
ALL_E2E_K8S_VERSIONS ?= v1.31.1 v1.30.5 v1.29.9 v1.28.14 v1.27.16 v1.26.15

.DEFAULT_GOAL := help

# Go packages to test
TEST_PACKAGES = ./src/internal/config \
./src/api/v1alpha1 \
./src/api/v1alpha2 \
./src/autodetect \
./src/instrumentation/ \
./src/instrumentation/upgrade \
./src/internal/version
./src/internal/version \
./src/apm

# Kubebuilder variables
SETUP_ENVTEST = sigs.k8s.io/controller-runtime/tools/setup-envtest
ENVTEST_VERSION = release-0.18
ENVTEST_BIN = $(TMP_DIR)/setup-envtest
ENVTEST_K8S_VERSION = 1.29.0
SETUP_ENVTEST = $(TMP_DIR)/setup-envtest
SETUP_ENVTEST_VERSION ?= release-0.19
SETUP_ENVTEST_K8S_VERSION ?= 1.29.0
ALL_SETUP_ENVTEST_K8S_VERSIONS ?= 1.30.0 1.29.3 1.28.3 1.27.1 1.26.1 #https://storage.googleapis.com/kubebuilder-tools

## Tool Versions
KUSTOMIZE ?= $(LOCALBIN)/kustomize
KUSTOMIZE_VERSION ?= v5.4.3
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
CONTROLLER_TOOLS_VERSION ?= v0.14.0
HELMIFY ?= $(LOCALBIN)/helmify
HELMIFY_VERSION ?= v0.3.34
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
GOLANGCI_LINT_VERSION ?= v1.61.0
HELM ?= $(LOCALBIN)/helm
HELM_VERSION ?= v3.16.1
HELM_DOCS ?= $(LOCALBIN)/helm-docs
HELM_DOCS_VERSION ?= v1.14.2
HELM_DOCS_VERSION_ST ?= $(subst v,,$(HELM_DOCS_VERSION))
CT ?= $(LOCALBIN)/ct
CT_VERSION ?= v3.11.0
HELM_UNITTEST ?= $(LOCALBIN)/helm-unittest
HELM_UNITTEST_VERSION ?= v0.6.2

CRD_OPTIONS ?= "crd:generateEmbeddedObjectMeta=true"

LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

# Temp location to install dependencies
$(TMP_DIR):
mkdir $(TMP_DIR)

# Install setup-envtest
$(ENVTEST_BIN): $(TMP_DIR)
GOBIN="$(realpath $(TMP_DIR))" go install $(SETUP_ENVTEST)@$(ENVTEST_VERSION)
##@ Targets

.PHONY: help
help: ## Show help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-17s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } END{printf "\n"}' $(MAKEFILE_LIST)

.PHONY: all
all: clean format modules test build
all: clean format modules test build ## clean, format, modules, test, build

.PHONY: clean
clean:
clean: ## cleanup temp files
rm -rf $(BIN_DIR) $(TMP_DIR)

.PHONY: format
format:
go fmt ./...
go vet ./...

.PHONY: modules
modules:
modules: ## Download go dependencies
@# Add any missing modules and remove unused modules in go.mod and go.sum
go mod tidy
@# Verify dependencies have not been modified since being downloaded
go mod verify

.PHONY: test
test: $(ENVTEST_BIN)
@chmod -R 755 $(TMP_DIR)/k8s
KUBEBUILDER_ASSETS="$(shell $(TMP_DIR)/setup-envtest use $(ENVTEST_K8S_VERSION) --bin-dir $(TMP_DIR) -p path)" \
go test -cover -covermode=count -coverprofile=$(TMP_DIR)/cover.out $(TEST_PACKAGES)
##@ Testing

.PHONY: build
build:
CGO_ENABLED=0 go build -o $(BIN_DIR)/operator $(GO_DIR)
$(TMP_DIR)/cover.out: test

.PHONY: coverprofile
coverprofile:
coverprofile: $(TMP_DIR)/cover.out ## Generate coverage report
go tool cover -html=$(TMP_DIR)/cover.out
go tool cover -func=$(TMP_DIR)/cover.out

.PHONY: go-test
go-test: $(SETUP_ENVTEST) ## Run Go tests with k8s version specified by $SETUP_ENVTEST_K8S_VERSION
@chmod -R 755 $(TMP_DIR)/k8s
KUBEBUILDER_ASSETS="$(shell $(TMP_DIR)/setup-envtest use $(SETUP_ENVTEST_K8S_VERSION) --bin-dir $(TMP_DIR) -p path)" \
go test -v -cover -covermode=count -coverprofile=$(TMP_DIR)/cover.out $(TEST_PACKAGES)

.PHONY: all-go-tests
all-go-tests: ## Run go tests with all k8s versions specified by $ALL_SETUP_ENVTEST_K8S_VERSIONS
@for k8s_version in $(ALL_SETUP_ENVTEST_K8S_VERSIONS); do \
env SETUP_ENVTEST_K8S_VERSION=$$k8s_version $(MAKE) -f $(MAKEFILE_LIST) go-test; \
done

.PHONY: e2e-tests
e2e-tests: ## Run e2e tests with k8s version specified by $E2E_K8S_VERSION
@for cmd in docker minikube helm kubectl yq; do \
if ! command -v $$cmd > /dev/null; then \
echo "$$cmd required" >&2; \
exit 1; \
fi; \
done
cd tests/e2e && ./e2e-tests.sh --k8s_version $(E2E_K8S_VERSION) --license_key $(LICENSE_KEY) --run_tests

.PHONY: all-e2e-tests
all-e2e-tests: ## Run e2e tests with all k8s versions specified by $ALL_E2E_K8S_VERSIONS
@for k8s_version in $(ALL_E2E_K8S_VERSIONS); do \
env E2E_K8S_VERSION=$$k8s_version $(MAKE) -f $(MAKEFILE_LIST) e2e-tests; \
done

.PHONY: run-helm-unittest
run-helm-unittest: $(CT) ## Run helm unit tests based on changes
@if ! test -f ./.github/ct-lint.yaml; then echo "missing .github/ct-lint.yaml" >&2; exit 1; fi
@for chart in $$($(CT) list-changed --config ./.github/ct-lint.yaml); do \
if test -d "$$chart/tests/"; then \
$(HELM_UNITTEST) $$chart; \
else \
echo "No unit tests found for $$chart"; \
fi; \
done;

.PHONY: test
test: go-test # run-helm-unittest ## Run go tests (just an alias)

##@ Linting

.PHONY: go-lint
go-lint: golangci-lint ## Lint all go files
$(GOLANGCI_LINT) run --config=./.github/.golangci.yml

.PHONY: lint
lint: go-lint run-helm-lint ## Lint everything

.PHONY: run-helm-lint
run-helm-lint: ## Lint all the helm charts
@helm lint charts/**

##@ Formatting

.PHONY: format
format: go-format ## Format all files

.PHONY: go-format
go-format: ## Format all go files
go fmt ./...
go vet ./...

##@ Builds

.PHONY: build
build: ## Build the go binary
CGO_ENABLED=0 go build -o $(BIN_DIR)/operator $(GO_DIR)

.PHONY: dockerbuild
dockerbuild: ## Build the docker image
DOCKER_BUILDKIT=1 docker build -t k8s-agent-operator:latest \
--platform=linux/amd64,linux/arm64,linux/arm \
.

##@ Tools

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(CONTROLLER_GEN) || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: ct
ct: $(CT) ## Download ct (Chart Testing)
$(CT): $(LOCALBIN)
test -s $(CT) || GOBIN=$(LOCALBIN) go install github.com/helm/chart-testing/v3/ct@$(CT_VERSION)

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint
$(GOLANGCI_LINT): $(LOCALBIN)
test -s $(GOLANGCI_LINT) || GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)

.PHONY: helm
helm: $(HELM) ## Download helmo
$(HELM): $(LOCALBIN)
test -s $(HELM) || GOBIN=$(LOCALBIN) go install helm.sh/helm/v3/cmd/helm@$(HELM_VERSION)

.PHONY: helm-docs
helm-docs: $(HELM_DOCS) ## Download helm-docs
$(HELM_DOCS): $(LOCALBIN)
test -s $(HELM_DOCS) || GOBIN=$(LOCALBIN) go install -ldflags "-X 'main.version=$(HELM_DOCS_VERSION_ST)'" github.com/norwoodj/helm-docs/cmd/helm-docs@$(HELM_DOCS_VERSION)

.PHONY: helm-unittest
helm-unittest: $(HELM_UNITTEST) ## Download helm-unittest
$(HELM_UNITTEST): $(LOCALBIN)
test -s $(HELM_UNITTEST) || GOBIN=$(LOCALBIN) go install github.com/helm-unittest/helm-unittest/cmd/helm-unittest@$(HELM_UNITTEST_VERSION)

.PHONY: helmify
helmify: $(HELMIFY) ## Download helmify
$(HELMIFY): $(LOCALBIN)
test -s $(HELMIFY) || GOBIN=$(LOCALBIN) go install github.com/arttor/helmify/cmd/helmify@$(HELMIFY_VERSION)

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize
$(KUSTOMIZE): $(LOCALBIN)
test -s $(KUSTOMIZE) || GOBIN=$(LOCALBIN) go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION)

.PHONY: setup-envtest
setup-envtest: $(SETUP_ENVTEST) ## Download setup-envtest
$(SETUP_ENVTEST): $(TMP_DIR)
GOBIN="$(realpath $(TMP_DIR))" go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(SETUP_ENVTEST_VERSION)

##@ Generate manifests e.g. CRD, RBAC etc.

.PHONY: gen-helm-docs
gen-helm-docs: helm-docs ## Generate Helm Docs from templates
$(HELM_DOCS)

.PHONY: generate
generate: controller-gen ## Generate stuff
$(CONTROLLER_GEN) object:headerFile="boilerplate.txt" paths="./..."

.PHONY: manifests
manifests: generate controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=tests/kustomize/crd/bases

.PHONY: run-helmify
run-helmify: manifests helmify kustomize ## Generate the CRD with kustomize and helmify from the manifests
@# could we do more here?
$(KUSTOMIZE) build tests/kustomize/default | $(HELMIFY) tmp/k8s-agents-operator
cp ./tmp/k8s-agents-operator/templates/instrumentation-crd.yaml ./charts/k8s-agents-operator/templates/instrumentation-crd.yaml
61 changes: 61 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# -*- mode: Python -*-

#### Config
# This env var is automatically added by the e2e action.
namespace = os.getenv('NAMESPACE','newrelic')
chart_values_file = 'local/super-agent-tilt.yml'


#### Build the final Docker image with the binary.
docker_build(
'tilt.local/operator-dev',
context='.',
dockerfile='./Dockerfile'
)


#### Set-up charts
load('ext://helm_resource', 'helm_repo','helm_resource')
load('ext://git_resource', 'git_checkout')

update_dependencies = True
chart = 'charts/k8s-agents-operator'
deps=[chart]


flags_helm = ['--create-namespace','--version=>=0.0.0-beta','--set=super-agent-deployment.image.imagePullPolicy=Always','--values=' + chart_values_file]


#### Installs charts
helm_repo(
'jetstack',
'https://charts.jetstack.io',
resource_name='jetstack-helm-repo',
)

helm_resource(
'cert-manager',
'jetstack/cert-manager',
namespace='cert-manager',
release_name='cert-manager',
update_dependencies=False,
flags=['--create-namespace', '--set=crds.enabled=true'],
resource_deps=['jetstack-helm-repo']
)


helm_resource(
'operator',
chart,
deps=deps, # re-deploy chart if modified locally
namespace=namespace,
release_name='operator',
update_dependencies=False,
flags=flags_helm,
image_deps=['tilt.local/operator-dev'],
image_keys=[('controllerManager.manager.image.repository', 'controllerManager.manager.image.tag')],
resource_deps=['cert-manager']
)

update_settings(k8s_upsert_timeout_secs=150)

Loading
Loading