-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7281da7
commit 66ecca1
Showing
103 changed files
with
10,281 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file | ||
# Ignore build and test binaries. | ||
bin/ | ||
testbin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Build the manager binary | ||
FROM golang:1.20 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/ | ||
COPY pkg/ pkg/ | ||
COPY versions.txt versions.txt | ||
|
||
ARG VERSION_PKG | ||
ARG VERSION | ||
ARG VERSION_DATE | ||
ARG NEWRELIC_INSTRUMENTATION_JAVA_VERSION | ||
ARG NEWRELIC_INSTRUMENTATION_NODEJS_VERSION | ||
ARG NEWRELIC_INSTRUMENTATION_PYTHON_VERSION | ||
ARG NEWRELIC_INSTRUMENTATION_DOTNET_VERSION | ||
ARG NEWRELIC_INSTRUMENTATION_PHP_VERSION | ||
ARG AUTO_INSTRUMENTATION_GO_VERSION | ||
# 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 -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.autoInstrumentationJava=${NEWRELIC_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${NEWRELIC_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${NEWRELIC_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${NEWRELIC_INSTRUMENTATION_DOTNET_VERSION} -X ${VERSION_PKG}.autoInstrumentationPhp=${NEWRELIC_INSTRUMENTATION_PHP_VERSION}" -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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,315 @@ | ||
# VERSION defines the project version for the bundle. | ||
# Update this value when you upgrade the version of your project. | ||
# To re-generate a bundle for another specific version without changing the standard setup, you can: | ||
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2) | ||
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2) | ||
VERSION ?= "$(shell git describe --tags | sed 's/^v//')" | ||
VERSION_DATE ?= $(shell date -u +'%Y-%m-%dT%H:%M:%SZ') | ||
VERSION_PKG ?= "github.com/newrelic-experimental/newrelic-aganet-operator/internal/version" | ||
OPERATOR_VERSION ?= "$(shell grep -v '\#' versions.txt | grep newrelic-agent-operator | awk -F= '{print $$2}')" | ||
NEWRELIC_INSTRUMENTATION_JAVA_VERSION ?= "$(shell grep -v '\#' versions.txt | grep newrelic-instrumentation-java | awk -F= '{print $$2}')" | ||
NEWRELIC_INSTRUMENTATION_NODEJS_VERSION ?= "$(shell grep -v '\#' versions.txt | grep newrelic-instrumentation-nodejs | awk -F= '{print $$2}')" | ||
NEWRELIC_INSTRUMENTATION_PYTHON_VERSION ?= "$(shell grep -v '\#' versions.txt | grep newrelic-instrumentation-python | awk -F= '{print $$2}')" | ||
NEWRELIC_INSTRUMENTATION_DOTNET_VERSION ?= "$(shell grep -v '\#' versions.txt | grep newrelic-instrumentation-dotnet | awk -F= '{print $$2}')" | ||
NEWRELIC_INSTRUMENTATION_PHP_VERSION ?= "$(shell grep -v '\#' versions.txt | grep newrelic-instrumentation-php | awk -F= '{print $$2}')" | ||
AUTO_INSTRUMENTATION_GO_VERSION ?= "$(shell grep -v '\#' versions.txt | grep autoinstrumentation-go | awk -F= '{print $$2}')" | ||
LD_FLAGS ?= "-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.autoInstrumentationJava=${NEWRELIC_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${NEWRELIC_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${NEWRELIC_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationGo=${AUTO_INSTRUMENTATION_GO_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${NEWRELIC_INSTRUMENTATION_DOTNET_VERSION} -X ${VERSION_PKG}.autoInstrumentationPhp=${NEWRELIC_INSTRUMENTATION_PHP_VERSION}" | ||
ARCH ?= $(shell go env GOARCH) | ||
|
||
# Image URL to use all building/pushing image targets | ||
IMG_PREFIX ?= ghcr.io/${USER}/newrelic-agent-operator | ||
IMG_REPO ?= newrelic-agent-operator | ||
IMG ?= ${IMG_PREFIX}/${IMG_REPO}:${VERSION} | ||
BUNDLE_IMG ?= ${IMG_PREFIX}/${IMG_REPO}-bundle:${VERSION} | ||
|
||
# Options for 'bundle-build' | ||
ifneq ($(origin CHANNELS), undefined) | ||
BUNDLE_CHANNELS := --channels=$(CHANNELS) | ||
endif | ||
ifneq ($(origin DEFAULT_CHANNEL), undefined) | ||
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) | ||
endif | ||
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) | ||
|
||
CRD_OPTIONS ?= "crd:generateEmbeddedObjectMeta=true" | ||
|
||
# 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 | ||
|
||
# by default, do not run the manager with webhooks enabled. This only affects local runs, not the build or in-cluster deployments. | ||
ENABLE_WEBHOOKS ?= false | ||
|
||
# If we are running in CI, run go test in verbose mode | ||
ifeq (,$(CI)) | ||
GOTEST_OPTS=-race | ||
else | ||
GOTEST_OPTS=-race -v | ||
endif | ||
|
||
START_KIND_CLUSTER ?= true | ||
|
||
KUBE_VERSION ?= 1.24 | ||
KIND_CONFIG ?= kind-$(KUBE_VERSION).yaml | ||
|
||
OPERATOR_SDK_VERSION ?= 1.27.0 | ||
|
||
CERTMANAGER_VERSION ?= 1.10.0 | ||
|
||
ifndef ignore-not-found | ||
ignore-not-found = false | ||
endif | ||
|
||
## Location to install dependencies to | ||
LOCALBIN ?= $(shell pwd)/bin | ||
$(LOCALBIN): | ||
mkdir -p $(LOCALBIN) | ||
|
||
.PHONY: ensure-generate-is-noop | ||
ensure-generate-is-noop: VERSION=$(OPERATOR_VERSION) | ||
ensure-generate-is-noop: USER=${USER} | ||
ensure-generate-is-noop: set-image-controller generate bundle | ||
@# on make bundle config/manager/kustomization.yaml includes changes, which should be ignored for the below check | ||
@git restore config/manager/kustomization.yaml | ||
@git diff -s --exit-code apis/v1alpha1/zz_generated.*.go || (echo "Build failed: a model has been changed but the generated resources aren't up to date. Run 'make generate' and update your PR." && exit 1) | ||
@git diff -s --exit-code bundle config || (echo "Build failed: the bundle, config files has been changed but the generated bundle, config files aren't up to date. Run 'make bundle' and update your PR." && git diff && exit 1) | ||
@git diff -s --exit-code bundle.Dockerfile || (echo "Build failed: the bundle.Dockerfile file has been changed. The file should be the same as generated one. Run 'make bundle' and update your PR." && git diff && exit 1) | ||
|
||
.PHONY: all | ||
all: manager | ||
|
||
# Build manager binary | ||
.PHONY: manager | ||
manager: generate fmt vet | ||
go build -o bin/manager main.go | ||
|
||
# Run against the configured Kubernetes cluster in ~/.kube/config | ||
.PHONY: run | ||
run: generate fmt vet manifests | ||
ENABLE_WEBHOOKS=$(ENABLE_WEBHOOKS) go run -ldflags ${LD_FLAGS} ./main.go --zap-devel | ||
|
||
# Install CRDs into a cluster | ||
.PHONY: install | ||
install: manifests kustomize | ||
$(KUSTOMIZE) build config/crd | kubectl apply -f - | ||
|
||
# Uninstall CRDs from a cluster | ||
.PHONY: uninstall | ||
uninstall: manifests kustomize | ||
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f - | ||
|
||
# Set the controller image parameters | ||
.PHONY: set-image-controller | ||
set-image-controller: manifests kustomize | ||
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} | ||
|
||
# Deploy controller in the current Kubernetes context, configured in ~/.kube/config | ||
.PHONY: deploy | ||
deploy: set-image-controller | ||
$(KUSTOMIZE) build config/default | kubectl apply -f - | ||
go run hack/check-operator-ready.go 300 | ||
|
||
# Undeploy controller in the current Kubernetes context, configured in ~/.kube/config | ||
.PHONY: undeploy | ||
undeploy: set-image-controller | ||
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f - | ||
|
||
# Generates the released manifests | ||
.PHONY: release-artifacts | ||
release-artifacts: set-image-controller | ||
mkdir -p dist | ||
$(KUSTOMIZE) build config/default -o dist/newrelic-agent-operator.yaml | ||
|
||
# Generate manifests e.g. CRD, RBAC etc. | ||
.PHONY: manifests | ||
manifests: controller-gen | ||
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
|
||
# Run go fmt against code | ||
.PHONY: fmt | ||
fmt: | ||
go fmt ./... | ||
|
||
# Run go vet against code | ||
.PHONY: vet | ||
vet: | ||
go vet ./... | ||
|
||
# Run go lint against code | ||
.PHONY: lint | ||
lint: | ||
golangci-lint run | ||
|
||
# Generate code | ||
.PHONY: generate | ||
generate: controller-gen | ||
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." | ||
|
||
.PHONY: scorecard-tests | ||
scorecard-tests: operator-sdk | ||
$(OPERATOR_SDK) scorecard -w=5m bundle || (echo "scorecard test failed" && exit 1) | ||
|
||
# Build the container image, used only for local dev purposes | ||
# buildx is used to ensure same results for arm based systems (m1/2 chips) | ||
.PHONY: container | ||
container: | ||
docker buildx build --load --platform linux/${ARCH} -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg NEWRELIC_INSTRUMENTATION_JAVA_VERSION=${NEWRELIC_INSTRUMENTATION_JAVA_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_NODEJS_VERSION=${NEWRELIC_INSTRUMENTATION_NODEJS_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_PYTHON_VERSION=${NEWRELIC_INSTRUMENTATION_PYTHON_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_DOTNET_VERSION=${NEWRELIC_INSTRUMENTATION_DOTNET_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_PHP_VERSION=${NEWRELIC_INSTRUMENTATION_PHP_VERSION} . | ||
|
||
# Push the container image, used only for local dev purposes | ||
.PHONY: container-push | ||
container-push: | ||
docker push ${IMG} | ||
|
||
.PHONY: start-kind | ||
start-kind: | ||
ifeq (true,$(START_KIND_CLUSTER)) | ||
kind create cluster --config $(KIND_CONFIG) | ||
endif | ||
|
||
.PHONY: install-openshift-routes | ||
install-openshift-routes: | ||
./hack/install-openshift-routes.sh | ||
|
||
.PHONY: load-image-all | ||
load-image-all: load-image-operator load-image-target-allocator load-image-operator-opamp-bridge | ||
|
||
.PHONY: load-image-operator | ||
load-image-operator: container | ||
ifeq (true,$(START_KIND_CLUSTER)) | ||
kind load docker-image $(IMG) | ||
else | ||
$(MAKE) container-push | ||
endif | ||
|
||
.PHONY: cert-manager | ||
cert-manager: cmctl | ||
# Consider using cmctl to install the cert-manager once install command is not experimental | ||
kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v${CERTMANAGER_VERSION}/cert-manager.yaml | ||
$(CMCTL) check api --wait=5m | ||
|
||
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
CMCTL = $(shell pwd)/bin/cmctl | ||
.PHONY: cmctl | ||
cmctl: | ||
@{ \ | ||
set -e ;\ | ||
if (`pwd`/bin/cmctl version | grep ${CERTMANAGER_VERSION}) > /dev/null 2>&1 ; then \ | ||
exit 0; \ | ||
fi ;\ | ||
TMP_DIR=$$(mktemp -d) ;\ | ||
curl -L -o $$TMP_DIR/cmctl.tar.gz https://github.com/jetstack/cert-manager/releases/download/v$(CERTMANAGER_VERSION)/cmctl-`go env GOOS`-`go env GOARCH`.tar.gz ;\ | ||
tar xzf $$TMP_DIR/cmctl.tar.gz -C $$TMP_DIR ;\ | ||
[ -d bin ] || mkdir bin ;\ | ||
mv $$TMP_DIR/cmctl $(CMCTL) ;\ | ||
rm -rf $$TMP_DIR ;\ | ||
} | ||
|
||
KUSTOMIZE ?= $(LOCALBIN)/kustomize | ||
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen | ||
|
||
## Tool Versions | ||
KUSTOMIZE_VERSION ?= v5.0.0 | ||
CONTROLLER_TOOLS_VERSION ?= v0.11.3 | ||
|
||
.PHONY: kustomize | ||
kustomize: ## Download kustomize locally if necessary. | ||
$(call go-get-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) | ||
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) | ||
|
||
# go-get-tool will 'go get' any package $2 and install it to $1. | ||
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
define go-get-tool | ||
@[ -f $(1) ] || { \ | ||
set -e ;\ | ||
TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
echo "Downloading $(2)" ;\ | ||
go get -d $(2)@$(3) ;\ | ||
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\ | ||
rm -rf $$TMP_DIR ;\ | ||
} | ||
endef | ||
|
||
.PHONY: kuttl | ||
kuttl: | ||
ifeq (, $(shell which kubectl-kuttl)) | ||
echo ${PATH} | ||
ls -l /usr/local/bin | ||
which kubectl-kuttl | ||
|
||
@{ \ | ||
set -e ;\ | ||
echo "" ;\ | ||
echo "ERROR: kuttl not found." ;\ | ||
echo "Please check https://kuttl.dev/docs/cli.html for installation instructions and try again." ;\ | ||
echo "" ;\ | ||
exit 1 ;\ | ||
} | ||
else | ||
KUTTL=$(shell which kubectl-kuttl) | ||
endif | ||
|
||
.PHONY: kind | ||
kind: | ||
ifeq (, $(shell which kind)) | ||
@{ \ | ||
set -e ;\ | ||
echo "" ;\ | ||
echo "ERROR: kind not found." ;\ | ||
echo "Please check https://kind.sigs.k8s.io/docs/user/quick-start/#installation for installation instructions and try again." ;\ | ||
echo "" ;\ | ||
exit 1 ;\ | ||
} | ||
else | ||
KIND=$(shell which kind) | ||
endif | ||
|
||
OPERATOR_SDK = $(shell pwd)/bin/operator-sdk | ||
.PHONY: operator-sdk | ||
operator-sdk: | ||
@{ \ | ||
set -e ;\ | ||
if (`pwd`/bin/operator-sdk version | grep ${OPERATOR_SDK_VERSION}) > /dev/null 2>&1 ; then \ | ||
exit 0; \ | ||
fi ;\ | ||
[ -d bin ] || mkdir bin ;\ | ||
curl -L -o $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/v${OPERATOR_SDK_VERSION}/operator-sdk_`go env GOOS`_`go env GOARCH`;\ | ||
chmod +x $(OPERATOR_SDK) ;\ | ||
} | ||
|
||
# Generate bundle manifests and metadata, then validate generated files. | ||
.PHONY: bundle | ||
bundle: kustomize operator-sdk manifests set-image-controller | ||
$(OPERATOR_SDK) generate kustomize manifests -q | ||
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) | ||
$(OPERATOR_SDK) bundle validate ./bundle | ||
./hack/ignore-createdAt-bundle.sh | ||
|
||
|
||
# Build the bundle image, used only for local dev purposes | ||
.PHONY: bundle-build | ||
bundle-build: | ||
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . | ||
|
||
.PHONY: bundle-push | ||
bundle-push: | ||
docker push $(BUNDLE_IMG) | ||
|
||
HELMIFY ?= $(LOCALBIN)/helmify | ||
HELMIFY_VERSION ?= v0.3.34 | ||
|
||
.PHONY: helmify | ||
helmify: $(HELMIFY) ## Download helmify locally if necessary. | ||
$(HELMIFY): $(LOCALBIN) | ||
test -s $(LOCALBIN)/helmify || GOBIN=$(LOCALBIN) go install github.com/arttor/helmify/cmd/helmify@$(HELMIFY_VERSION) | ||
|
||
helm: manifests kustomize helmify | ||
$(KUSTOMIZE) build config/default | $(HELMIFY) |
Oops, something went wrong.