Skip to content

Commit

Permalink
Only use CRDv1 - Bump operator-sdk version - Add automatic push to RH…
Browse files Browse the repository at this point in the history
… registries
  • Loading branch information
vboulineau committed Oct 22, 2021
1 parent 4fd8ccf commit c107a10
Show file tree
Hide file tree
Showing 67 changed files with 62,311 additions and 29,375 deletions.
30 changes: 30 additions & 0 deletions .gitlab-ci.yml
Expand Up @@ -78,6 +78,19 @@ build_image_arm64:
- IMG=$TARGET_IMAGE make docker-build-ci docker-push
- if [ -n "$CI_COMMIT_TAG" ]; then docker tag $TARGET_IMAGE $RELEASE_IMAGE && docker push $RELEASE_IMAGE; fi

build_bundle_image:
stage: image
tags: ["runner:docker", "size:large"]
image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docker:v2718644-9ce6565-18.09.6-py3
variables:
TARGET_IMAGE: $BUILD_DOCKER_REGISTRY/$PROJECTNAME:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}-bundle
RELEASE_IMAGE: $BUILD_DOCKER_REGISTRY/$PROJECTNAME:$CI_COMMIT_TAG-bundle
script:
- BUNDLE_IMG=$TARGET_IMAGE make bundle-build
- if [ -n "$CI_COMMIT_TAG" ]; then docker tag $TARGET_IMAGE $RELEASE_IMAGE && docker push $RELEASE_IMAGE; fi
- BUNDLE_IMG=$TARGET_IMAGE-redhat make bundle-redhat-build
- if [ -n "$CI_COMMIT_TAG" ]; then docker tag $TARGET_IMAGE-redhat $RELEASE_IMAGE-redhat && docker push $RELEASE_IMAGE-redhat; fi

publish_public_main:
stage: release
rules:
Expand Down Expand Up @@ -109,6 +122,7 @@ publish_public_tag:
IMG_DESTINATIONS_REGEX: ':v'
IMG_DESTINATIONS_REGEX_REPL: ':'
IMG_SIGNING: "false"
IMG_REGISTRIES: default,redhat-operator

publish_public_latest:
stage: release
Expand All @@ -124,6 +138,22 @@ publish_public_latest:
IMG_SOURCES: $BUILD_DOCKER_REGISTRY/$PROJECTNAME:$CI_COMMIT_TAG-amd64,$BUILD_DOCKER_REGISTRY/$PROJECTNAME:$CI_COMMIT_TAG-arm64
IMG_DESTINATIONS: operator:latest
IMG_SIGNING: "false"
IMG_REGISTRIES: default,redhat-operator

publish_redhat_bundle:
stage: release
rules:
- if: $CI_COMMIT_TAG
when: manual
- when: never
trigger:
project: DataDog/public-images
branch: main
strategy: depend
variables:
IMG_SOURCES: $BUILD_DOCKER_REGISTRY/$PROJECTNAME:$CI_COMMIT_TAG-bundle-redhat
IMG_DESTINATIONS: operator-bundle:$CI_COMMIT_TAG
IMG_REGISTRIES: redhat-operator-bundle

trigger_internal_image:
stage: release
Expand Down
197 changes: 148 additions & 49 deletions LICENSE-3rdparty.csv

Large diffs are not rendered by default.

99 changes: 82 additions & 17 deletions Makefile
@@ -1,7 +1,12 @@
# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# 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

#
# Datadog custom variables
#
SHELL=/bin/bash
BUILDINFOPKG=github.com/DataDog/datadog-operator/pkg/version
GIT_TAG?=$(shell git tag -l --contains HEAD | tail -1)
TAG_HASH=$(shell git tag | tail -1)_$(shell git rev-parse --short HEAD)
Expand All @@ -16,10 +21,22 @@ GOARCH?=amd64

# Default bundle image tag
BUNDLE_IMG ?= controller-bundle:$(VERSION)

# Options for 'bundle-build'
# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif

# DEFAULT_CHANNEL defines the default channel used in the bundle.
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
# To re-generate a bundle for any other default channel without changing the default setup, you can:
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
Expand All @@ -28,6 +45,11 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
# Image URL to use all building/pushing image targets
IMG ?= gcr.io/datadoghq/operator:$(IMG_VERSION)

# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.20

# 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
Expand Down Expand Up @@ -71,8 +93,8 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
manifests: generate-manifests patch-crds ## Generate manifestcd s e.g. CRD, RBAC etc.

generate-manifests: controller-gen
$(CONTROLLER_GEN) crd:trivialVersions=true,crdVersions=v1 rbac:roleName=manager webhook paths="./..." output:crd:artifacts:config=config/crd/bases/v1
$(CONTROLLER_GEN) crd:trivialVersions=true,crdVersions=v1beta1 rbac:roleName=manager webhook paths="./..." output:crd:artifacts:config=config/crd/bases/v1beta1
$(CONTROLLER_GEN) $(CRD_OPTIONS),crdVersions=v1 rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases/v1
$(CONTROLLER_GEN) $(CRD_OPTIONS),crdVersions=v1beta1 rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases/v1beta1

generate: controller-gen generate-openapi generate-docs ## Generate code
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
Expand All @@ -90,20 +112,26 @@ docker-push: ## Push the docker image

##@ Test

test: build manifests generate fmt vet verify-license gotest ## Run unit tests and E2E tests
test: build manifests generate fmt vet verify-license gotest integration-tests ## Run unit tests and E2E tests

gotest:
go test ./... -coverprofile cover.out

ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
gotest: ## Run tests.
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
integration-tests: envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test --tags=integration github.com/DataDog/datadog-operator/controllers -coverprofile cover.out

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.5.0)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.1)

KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)

ENVTEST = $(shell pwd)/bin/setup-envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

# 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
Expand Down Expand Up @@ -131,17 +159,58 @@ bundle: bin/operator-sdk kustomize manifests ## Generate bundle manifests and me
bundle-build: ## Build the bundle image.
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

.PHONY: bundle-redhat-build
bundle-redhat-build:
docker build -f bundle.redhat.Dockerfile -t $(BUNDLE_IMG) .

.PHONY: bundle-push
bundle-push:
docker push $(BUNDLE_IMG)

.PHONY: bundle-redhat-build
bundle-redhat-build:
docker build -f bundle.redhat.Dockerfile -t scan.connect.redhat.com/ospid-1125a16e-7487-49a2-93ae-f6a21920e804/operator-bundle:$(VERSION) .
.PHONY: opm
OPM = ./bin/opm
opm: ## Download opm locally if necessary.
ifeq (,$(wildcard $(OPM)))
ifeq (,$(shell which opm 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(OPM)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm ;\
chmod +x $(OPM) ;\
}
else
OPM = $(shell which opm)
endif
endif

# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
# These images MUST exist in a registry and be pull-able.
BUNDLE_IMGS ?= $(BUNDLE_IMG)

# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)

# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
ifneq ($(origin CATALOG_BASE_IMG), undefined)
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
endif

# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
# This recipe invokes 'opm' in 'semver-skippatch' bundle add mode. For more information on add modes, see:
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
.PHONY: catalog-build
catalog-build: opm ## Build a catalog image.
$(OPM) index add --container-tool docker --mode semver-skippatch --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)

# Push the catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)

##@ Datadog Custom part
.PHONY: install-tools
install-tools: bin/golangci-lint bin/operator-sdk bin/yq bin/kubebuilder
install-tools: bin/golangci-lint bin/operator-sdk bin/yq

.PHONY: generate-openapi
generate-openapi: bin/openapi-gen
Expand Down Expand Up @@ -171,14 +240,10 @@ tidy: ## Run go tidy
.PHONY: vendor
vendor: ## Run go vendor
go mod vendor
./hack/vendor/patch-vendor.sh

kubectl-datadog: lint
go build -ldflags '${LDFLAGS}' -o bin/kubectl-datadog ./cmd/kubectl-datadog/main.go

bin/kubebuilder:
./hack/install-kubebuilder.sh 2.3.2

bin/openapi-gen:
go build -o ./bin/openapi-gen k8s.io/kube-openapi/cmd/openapi-gen

Expand All @@ -189,7 +254,7 @@ bin/golangci-lint:
hack/golangci-lint.sh v1.38.0

bin/operator-sdk:
./hack/install-operator-sdk.sh v1.5.0
./hack/install-operator-sdk.sh v1.13.1

bin/wwhrd:
./hack/install-wwhrd.sh 0.2.4
Expand Down
26 changes: 17 additions & 9 deletions PROJECT
@@ -1,30 +1,38 @@
domain: com
layout: go.kubebuilder.io/v2
layout: go.kubebuilder.io/v3
multigroup: true
plugins:
go.sdk.operatorframework.io/v2-alpha: {}
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
projectName: datadog-operator
repo: github.com/DataDog/datadog-operator
resources:
- controller: true
- api:
crdVersion: v1
namespaced: true
domain: com
group: datadoghq
kind: DatadogAgent
kind: DatadogMetric
path: github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1
version: v1alpha1
- domain: com
- api:
crdVersion: v1
namespaced: true
domain: com
group: datadoghq
kind: DatadogMetric
kind: DatadogMonitor
path: github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1
version: v1alpha1
- controller: true
- api:
crdVersion: v1
namespaced: true
domain: com
group: datadoghq
kind: DatadogMonitor
kind: DatadogAgent
path: github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1
version: v1alpha1
- api:
crdVersion: v1beta1
crdVersion: v1
namespaced: true
domain: com
group: datadoghq
Expand Down
Expand Up @@ -91,10 +91,11 @@ metadata:
description: Datadog provides a modern monitoring and analytics platform. Gather
metrics, logs and traces for full observability of your Kubernetes cluster with
Datadog Operator.
operators.operatorframework.io/builder: operator-sdk-v1.4.0+git
operators.operatorframework.io/project_layout: go.kubebuilder.io/v2
operators.operatorframework.io/builder: operator-sdk-v1.13.0+git
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/DataDog/datadog-operator
name: datadog-operator.v0.7.0
containerImage: registry.connect.redhat.com/datadog/operator:0.7.1
name: datadog-operator.v0.7.1
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand All @@ -105,6 +106,11 @@ spec:
kind: DatadogAgent
name: datadogagents.datadoghq.com
version: v1alpha1
- description: DatadogAgent is the Schema for the datadogagents API
displayName: Datadog Agent
kind: DatadogAgent
name: datadogagents.datadoghq.com
version: v2alpha1
- description: DatadogMetric allows autoscaling on arbitrary Datadog query
displayName: Datadog Metric
kind: DatadogMetric
Expand Down Expand Up @@ -550,6 +556,12 @@ spec:
- get
- patch
- update
- apiGroups:
- datadoghq.com
resources:
- extendeddaemonsetreplicasets
verbs:
- get
- apiGroups:
- datadoghq.com
resources:
Expand Down Expand Up @@ -736,7 +748,7 @@ spec:
verbs:
- list
- watch
serviceAccountName: datadog-operator-manager
serviceAccountName: datadog-operator-controller-manager
- rules:
- apiGroups:
- security.openshift.io
Expand Down Expand Up @@ -776,7 +788,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.annotations['olm.targetNamespaces']
image: datadog/operator:0.7.0
image: registry.connect.redhat.com/datadog/operator:0.7.1
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
Expand All @@ -795,7 +807,7 @@ spec:
requests:
cpu: 100m
memory: 250Mi
serviceAccountName: datadog-operator-manager
serviceAccountName: datadog-operator-controller-manager
terminationGracePeriodSeconds: 10
permissions:
- rules:
Expand Down Expand Up @@ -838,7 +850,7 @@ spec:
- update
- patch
- delete
serviceAccountName: datadog-operator-manager
serviceAccountName: datadog-operator-controller-manager
strategy: deployment
installModes:
- supported: true
Expand All @@ -863,6 +875,7 @@ spec:
- email: support@datadoghq.com
name: Datadog Inc.
maturity: alpha
minKubeVersion: 1.16.0
provider:
name: Datadog
version: 0.7.0
version: 0.7.1

0 comments on commit c107a10

Please sign in to comment.