Skip to content

Commit

Permalink
Merge branch 'master' into misc-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvin N authored Oct 27, 2021
2 parents 968b6b9 + db10691 commit 9e63efb
Show file tree
Hide file tree
Showing 30 changed files with 442 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
build-container:
runs-on: ubuntu-latest
env:
DOCKER_PLATFORMS: linux/amd64,linux/arm64
DOCKER_PLATFORMS: linux/amd64,linux/arm64,linux/s390x
services:
registry:
image: registry:2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
env:
DOCKER_REGISTRY: quay.io
DOCKER_REPOSITORY: grafana-operator/grafana-operator
DOCKER_PLATFORMS: linux/amd64,linux/arm64
DOCKER_PLATFORMS: linux/amd64,linux/arm64,linux/s390x
steps:
- name: Clone repo and checkout submodules
uses: actions/checkout@v2.3.4
Expand Down
56 changes: 50 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Current Operator version
VERSION ?= 4.0.1

# IMAGE_TAG_BASE defines the namespace and part of the image name for remote images.
# running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
# quay.io/grafana-operator/controller-bundle:$VERSION and quay.io/grafana-operator/controller-catalog:$VERSION.
IMAGE_TAG_BASE ?= quay.io/grafana-operator/controller
# Default bundle image tag
BUNDLE_IMG ?= quay.io/grafana-operator/controller-bundle:v$(VERSION)
BUNDLE_IMG ?= ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
# Options for 'bundle-build'
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
Expand All @@ -23,14 +28,25 @@ else
GOBIN=$(shell go env GOBIN)
endif

# 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

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.21

all: manager

# Run tests
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: generate fmt vet manifests api-docs
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
test: generate fmt vet envtest manifests api-docs
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out

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)

# Build manager binary
manager: generate fmt vet
Expand Down Expand Up @@ -96,7 +112,7 @@ docker-push:

# Build and push a multi-architecture docker image
docker-buildx: test
docker buildx build --platform linux/amd64,linux/arm64 --push -t ${IMG} .
docker buildx build --platform linux/amd64,linux/arm64,linux/s390x --push -t ${IMG} .

# Download controller-gen locally if necessary
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
Expand Down Expand Up @@ -170,3 +186,31 @@ API_REF_GEN=$(GOBIN)/crdoc
else
API_REF_GEN=$(shell which crdoc)
endif

.PHONY: opm
OPM = ./bin/opm
opm:
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

BUNDLE_IMGS ?= $(BUNDLE_IMG)
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION) ifneq ($(origin CATALOG_BASE_IMG), undefined) FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG) endif

.PHONY: catalog-build
catalog-build: opm
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)

.PHONY: catalog-push
catalog-push: ## Push the catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)
20 changes: 15 additions & 5 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
domain: integreatly.org
layout: go.kubebuilder.io/v3
layout:
- go.kubebuilder.io/v3
projectName: grafana-operator
repo: github.com/integr8ly/grafana-operator
resources:
- crdVersion: v1
- api:
crdVersion: v1
namespaced: true
group: integreatly.org
kind: Grafana
version: v1alpha1
- crdVersion: v1
controller: true
- api:
crdVersion: v1
namespaced: true
group: integreatly.org
kind: GrafanaDashboard
version: v1alpha1
- crdVersion: v1
controller: true
- api:
crdVersion: v1
namespaced: true
group: integreatly.org
kind: GrafanaDatasource
version: v1alpha1
version: 3-alpha
controller: true
version: "3"
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
109 changes: 109 additions & 0 deletions api/integreatly/v1alpha1/selectors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package v1alpha1

import (
"testing"

"github.com/stretchr/testify/require"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var labelSelector = &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "app",
Operator: "In",
Values: []string{"grafana"},
},
},
}

var listLabelSelector = []*metav1.LabelSelector{
{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "ham",
Operator: "In",
Values: []string{"eggs"},
},
},
},
{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "app",
Operator: "NotIn",
Values: []string{"grafana"},
},
},
},
}

func TestDashboardMatchesSelectorFalse(t *testing.T) {
i := &GrafanaDashboard{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: "dashboard",
Namespace: "grafana",
Labels: map[string]string{
"foo": "bar",
},
},
Spec: GrafanaDashboardSpec{},
}
output, err := i.matchesSelector(labelSelector)
require.NoError(t, err)
require.Equal(t, output, false)
}

func TestDashboardMatchesSelectorTrue(t *testing.T) {
i := &GrafanaDashboard{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: "dashboard",
Namespace: "grafana",
Labels: map[string]string{
"app": "grafana",
},
},
Spec: GrafanaDashboardSpec{},
}
output, err := i.matchesSelector(labelSelector)
require.NoError(t, err)
require.Equal(t, output, true)
}

func TestDashboardMatchesSelectorsMultipleNotIn(t *testing.T) {
i := &GrafanaDashboard{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: "dashboard",
Namespace: "grafana",
Labels: map[string]string{
"foo": "bar",
"app": "grafana",
},
},
Spec: GrafanaDashboardSpec{},
}
output, err := i.MatchesSelectors(listLabelSelector)
require.NoError(t, err)
require.Equal(t, output, false)
}

func TestMatchesDashboardSelectorsMultipleTrue(t *testing.T) {
i := &GrafanaDashboard{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: "dashboard",
Namespace: "grafana",
Labels: map[string]string{
"foo": "bar",
},
},
Spec: GrafanaDashboardSpec{},
}
output, err := i.MatchesSelectors(listLabelSelector)
require.NoError(t, err)
require.Equal(t, output, true)
}
1 change: 1 addition & 0 deletions api/integreatly/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bundle.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
LABEL operators.operatorframework.io.bundle.package.v1=grafana-operator
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.3.2
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.13.1
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3
LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/
Expand Down
4 changes: 2 additions & 2 deletions bundle/manifests/grafana-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
annotations:
alm-examples: '[]'
capabilities: Basic Install
operators.operatorframework.io/builder: operator-sdk-v1.3.2
operators.operatorframework.io/builder: operator-sdk-v1.13.1
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
name: grafana-operator.v4.0.1
namespace: placeholder
Expand Down Expand Up @@ -230,7 +230,7 @@ spec:
- --upstream=http://127.0.0.1:8080/
- --logtostderr=true
- --v=10
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0
name: kube-rbac-proxy
ports:
- containerPort: 8443
Expand Down
2 changes: 1 addition & 1 deletion bundle/metadata/annotations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ annotations:
operators.operatorframework.io.bundle.mediatype.v1: registry+v1
operators.operatorframework.io.bundle.metadata.v1: metadata/
operators.operatorframework.io.bundle.package.v1: grafana-operator
operators.operatorframework.io.metrics.builder: operator-sdk-v1.3.2
operators.operatorframework.io.metrics.builder: operator-sdk-v1.13.1
operators.operatorframework.io.metrics.mediatype.v1: metrics+v1
operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v3
operators.operatorframework.io.test.config.v1: tests/scorecard/
Expand Down
12 changes: 6 additions & 6 deletions bundle/tests/scorecard/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,42 @@ stages:
- entrypoint:
- scorecard-test
- basic-check-spec
image: quay.io/operator-framework/scorecard-test:v1.3.0
image: quay.io/operator-framework/scorecard-test:v1.13.1
labels:
suite: basic
test: basic-check-spec-test
- entrypoint:
- scorecard-test
- olm-bundle-validation
image: quay.io/operator-framework/scorecard-test:v1.3.0
image: quay.io/operator-framework/scorecard-test:v1.13.1
labels:
suite: olm
test: olm-bundle-validation-test
- entrypoint:
- scorecard-test
- olm-crds-have-validation
image: quay.io/operator-framework/scorecard-test:v1.3.0
image: quay.io/operator-framework/scorecard-test:v1.13.1
labels:
suite: olm
test: olm-crds-have-validation-test
- entrypoint:
- scorecard-test
- olm-crds-have-resources
image: quay.io/operator-framework/scorecard-test:v1.3.0
image: quay.io/operator-framework/scorecard-test:v1.13.1
labels:
suite: olm
test: olm-crds-have-resources-test
- entrypoint:
- scorecard-test
- olm-spec-descriptors
image: quay.io/operator-framework/scorecard-test:v1.3.0
image: quay.io/operator-framework/scorecard-test:v1.13.1
labels:
suite: olm
test: olm-spec-descriptors-test
- entrypoint:
- scorecard-test
- olm-status-descriptors
image: quay.io/operator-framework/scorecard-test:v1.3.0
image: quay.io/operator-framework/scorecard-test:v1.13.1
labels:
suite: olm
test: olm-status-descriptors-test
3 changes: 2 additions & 1 deletion config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
spec:
containers:
- name: kube-rbac-proxy
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0
args:
- "--secure-listen-address=0.0.0.0:8443"
- "--upstream=http://127.0.0.1:8080/"
Expand All @@ -19,6 +19,7 @@ spec:
ports:
- containerPort: 8443
name: https
protocol: TCP
- name: manager
args:
- "--health-probe-bind-address=:8081"
Expand Down
3 changes: 2 additions & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ spec:
periodSeconds: 10
resources:
limits:
cpu: 100m
cpu: 200m
memory: 300Mi
requests:
cpu: 100m
memory: 100Mi
serviceAccountName: controller-manager
terminationGracePeriodSeconds: 10
18 changes: 18 additions & 0 deletions config/manifests/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,21 @@ resources:
- ../default
- ../samples
- ../scorecard

# If operator uses webhooks, uncomment this YAML block.
#patchesJson6902:
#- target:
# group: apps
# version: v1
# kind: Deployment
# name: controller-manager
# namespace: system
# patch: |-
# # Remove the manager container's "cert" volumeMount, since OLM will create and mount a set of certs.
# # Update the indices in this path if adding or removing containers/volumeMounts in the manager's Deployment.
# - op: remove
# path: /spec/template/spec/containers/1/volumeMounts/0
# # Remove the "cert" volume, since OLM will create and mount a set of certs.
# # Update the indices in this path if adding or removing volumes in the manager's Deployment.
# - op: remove
# path: /spec/template/spec/volumes/0
Loading

0 comments on commit 9e63efb

Please sign in to comment.