Skip to content

Commit

Permalink
Merge pull request #43 from VictoriaMetrics/olm-integration-e2e-test
Browse files Browse the repository at this point in the history
added api markers for OLM integration
  • Loading branch information
f41gh7 authored Jul 7, 2020
2 parents 38b084e + 959533a commit 69e8202
Show file tree
Hide file tree
Showing 107 changed files with 25,715 additions and 4,010 deletions.
34 changes: 27 additions & 7 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ on:
push:
branches:
- '*'
tags: []
pull_request:

jobs:
build:
name: Build
runs-on: ubuntu-latest
name: test and build
runs-on: ubuntu-18.04
steps:
- name: Inject slug/short variables
uses: rlespinasse/[email protected]
Expand All @@ -27,24 +25,46 @@ jobs:
go get golang.org/x/lint/golint
go get github.com/kisielk/errcheck
go get github.com/golangci/golangci-lint/cmd/[email protected]
curl -L -o operator-sdk "https://github.com/operator-framework/operator-sdk/releases/download/v0.18.1/operator-sdk-v0.18.1-x86_64-linux-gnu"
chmod +x operator-sdk
sudo mv operator-sdk /bin/
- name: setup KIND for e2e tests
uses: engineerd/[email protected]
with:
version: "v0.7.0"
image: kindest/node:v1.16.4
- name: Code checkout
uses: actions/checkout@master
- name: build binary
env:
GO111MODULE: on
TAG: ${{ env.GITHUB_REF_SLUG }}
run: |
export PATH=$PATH:$(go env GOPATH)/bin # temporary fix. See https://github.com/actions/setup-go/issues/14
make lint
make test
make build-app
- name: run e2e tests
run: |
kubectl cluster-info
kubectl get pods -n kube-system
echo "current-context:" $(kubectl config current-context)
echo "environment-kubeconfig:" ${KUBECONFIG}
make e2e-local
- name: build docker
- name: build docker image and push
uses: docker/build-push-action@v1
with:
username: ${{secrets.REPO_USER}}
password: ${{secrets.REPO_KEY}}
registry: "quay.io"
repository: f41gh7/vm-operator
repository: victoriametrics/operator
tag_with_ref: true
dockerfile: cmd/manager/Dockerfile

- name: run e2e with docker
env:
E2E_IMAGE: ${{ env.GITHUB_REF_SLUG }}
run: |
kubectl cluster-info
kubectl get pods -n kube-system
make e2e
26 changes: 25 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ on:
jobs:
release:
name: Release on GitHub
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
steps:
- name: Inject slug/short variables
uses: rlespinasse/[email protected]

- name: Setup Go
uses: actions/setup-go@master
with:
Expand All @@ -22,6 +23,15 @@ jobs:
go get -u golang.org/x/lint/golint
go get -u github.com/kisielk/errcheck
go get github.com/golangci/golangci-lint/cmd/[email protected]
curl -L -o operator-sdk "https://github.com/operator-framework/operator-sdk/releases/download/v0.18.1/operator-sdk-v0.18.1-x86_64-linux-gnu"
chmod +x operator-sdk
sudo mv operator-sdk /bin/
- name: setup KIND for e2e tests
uses: engineerd/[email protected]
with:
version: "v0.7.0"
image: kindest/node:v1.16.4

- name: Check out code
uses: actions/checkout@v2
Expand All @@ -34,6 +44,13 @@ jobs:
make test
make build-app
sh scripts/bundle.sh
- name: run e2e tests local
run: |
kubectl cluster-info
kubectl get pods -n kube-system
echo "current-context:" $(kubectl config current-context)
echo "environment-kubeconfig:" ${KUBECONFIG}
make e2e-local
- name: build docker
uses: docker/build-push-action@v1
Expand All @@ -44,6 +61,13 @@ jobs:
repository: victoriametrics/operator
dockerfile: cmd/manager/Dockerfile

- name: run e2e with docker
env:
E2E_IMAGE: ${{ env.GITHUB_REF_SLUG }}
run: |
kubectl cluster-info
kubectl get pods -n kube-system
make e2e
- name: Upload Release Asset
id: upload-release-asset
Expand Down
77 changes: 77 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

## Required programs

for developing you need:
- golang 1.13+
- operator-sdk 1.18.1
- docker
- minikube or kind for e2e tests
- golangci-lint
- operator-courier



## local build and run

Use `make build` - it will generate new crds and build binary


for running locally you need minikube and run two commands:
```bash
kubectl apply -f deploy/crds
make run
```
or you can run it from IDE with ```cmd/manager/main.go```

## publish changes

before creating merge request, ensure that tests passed locally:
```bash
make build # it will update crds
make lint # linting project
make test #unit tests
make e2e-local #e2e tests with minikube
```

## create olm package

Choose version and generate or update corresponding csv file
```bash
CSV_VERSION=0.0.2 make olm
```

it will generate files at directory: `deploy/olm-catalog/victoria-metrics-operator/0.0.3/`

update file: `deploy/olm-catalog/victoria-metrics-operator/0.0.3/victoria-metrics-operator.v0.0.3.clusterserviceversion.yaml`

with fields from file:`deploy/olm-catalog/templates/csv-additional-fields-template.yaml`

replace operator version - specify release instead of latest

commit changes

publish olm package to quay.io with

```bash
make olm-publish
```

### integration with operator-hub

Clone repo locally: git clone https://github.com/operator-framework/community-operators.git

copy content to operator-hub repo and run tests
you can specify version (OP_VER) and channel OP_CHANNEL
```bash
cp -R deploy/olm-catalog/victoria-metrics-operator/ PATH_TO_OPERATOR_REPO/upstream-community-operators/
cd PATH_TO_OPERATOR_REPO
#run tests
make operator.verify OP_PATH=upstream-community-operators/victoria-metrics-operator VERBOSE=1
make operator.test OP_PATH=upstream-community-operators/victoria-metrics-operator/ VERBOSE=1

```

Now you can submit merge request with changes to operator-hub repo


troubleshooting: [url](https://github.com/operator-framework/community-operators/blob/master/docs/using-scripts.md#troubleshooting)
60 changes: 49 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Go parameters
GOCMD=GO111MODULE=on go
VERSION=$($CI_BUILD_TAG)
TAG="master"
VERSION=$(TAG)
BUILD=`date +%FT%T%z`
LDFLAGS=-ldflags "-w -s -X main.Version=${VERSION} -X main.BuildData=${BUILD}"
GOBUILD=CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOCMD) build -trimpath ${LDFLAGS}
Expand All @@ -13,33 +14,68 @@ REPO=github.com/VictoriaMetrics/operator
MAIN_DIR=$(REPO)/cmd/manager/
DOC_GEN_DIR=$(REPO)/cmd/doc-gen/
OPERATOR_BIN=operator-sdk
DOCKER_REPO=quay.io/f41gh7/vm-operator
TAG="master"
DOCKER_REPO=victoriametrics/operator
E2E_IMAGE ?= latest

CSV_VERSION ?= 0.0.1
QUAY_TOKEN=$(REPO_TOKEN)
TEST_ARGS=$(GOCMD) test -covermode=atomic -coverprofile=coverage.txt -v
APIS_BASE_PATH=pkg/apis/victoriametrics/v1beta1
GOPATHDIR ?= ~/go

.PHONY: build

all: build

gen-client:
client-gen --go-header-file $(GOPATHDIR)/pkg/mod/k8s.io/[email protected]/hack/boilerplate.go.txt \
--input-base=""\
--input=$(REPO)/pkg/apis/victoriametrics/v1beta1 \
--clientset-name "versioned" \
--output-package=$(REPO)/pkg/client \
--output-base ""
cp -R $(REPO)/pkg/client ./pkg

install-golint:
which golint || GO111MODULE=off go get -u golang.org/x/lint/golint

install-develop-tools: install-golint
which operator-courier || pip install operator-courier

report:
$(GOCMD) tool cover -html=coverage.txt

gen:
$(OPERATOR_BIN) generate crds
$(OPERATOR_BIN) generate crds --crd-version=v1beta1
$(OPERATOR_BIN) generate k8s

olm:
$(OPERATOR_BIN) generate csv --operator-name=victoria-metrics-operator \
--csv-version $(CSV_VERSION)\
--apis-dir=pkg/apis/victoriametrics/ \
--make-manifests=false \
--update-crds

olm-verify:
operator-courier verify deploy/olm-catalog/victoria-metrics-operator/


build-app: fmt
$(GOBUILD) -o $(BINARY_NAME) -v $(MAIN_DIR)


doc:
$(GOBUILD) -o doc-print $(DOC_GEN_DIR)
./doc-print api pkg/apis/victoriametrics/v1beta1/alertmanager_types.go pkg/apis/victoriametrics/v1beta1/vmagent_types.go pkg/apis/victoriametrics/v1beta1/additional.go pkg/apis/victoriametrics/v1beta1/vmalert_types.go pkg/apis/victoriametrics/v1beta1/vmsingle_types.go pkg/apis/monitoring/v1/prometheusrule_types.go pkg/apis/monitoring/v1/servicemonitor_types.go > docs/api.MD
./doc-print api \
$(APIS_BASE_PATH)/alertmanager_types.go \
$(APIS_BASE_PATH)/vmagent_types.go \
$(APIS_BASE_PATH)/additional.go \
$(APIS_BASE_PATH)/vmalert_types.go \
$(APIS_BASE_PATH)/vmsingle_types.go \
$(APIS_BASE_PATH)/vmrule_types.go \
$(APIS_BASE_PATH)/vmservicescrape_types.go \
$(APIS_BASE_PATH)/vmpodscrape_types.go \
$(APIS_BASE_PATH)/vmprometheusconvertor_types.go \
> docs/api.MD


fmt:
Expand All @@ -57,22 +93,24 @@ test:
$(TEST_ARGS) $(REPO)/pkg/...
$(GOCMD) tool cover -func coverage.txt | grep total

.PHONY:e2e
.PHONY:e2e-local
e2e-local:
operator-sdk test local ./e2e/ --up-local --operator-namespace="default" --verbose --image=$(DOCKER_REPO):$(E2E_IMAGE)
$(OPERATOR_BIN) test local ./e2e/ --up-local --operator-namespace="default" --verbose

.PHONY:e2e
e2e:
operator-sdk test local ./e2e/ --operator-namespace="default" --verbose --image=$(DOCKER_REPO):$(E2E_IMAGE)
$(OPERATOR_BIN) test local ./e2e/ --operator-namespace="default" --verbose --image=$(DOCKER_REPO):$(E2E_IMAGE)

lint:
golangci-lint run --exclude '(SA1019):' -E typecheck -E gosimple --timeout 5m
golint ./pkg
golangci-lint run --exclude '(SA1019):' -E typecheck -E gosimple --timeout 5m --skip-dirs 'pkg/client'
golint ./pkg/

.PHONY:clean
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -f $(BINARY_UNIX)

.PHONY: run
run: build
WATCH_NAMESPACE="" OPERATOR_NAME=vms ./$(BINARY_NAME)
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
- design and description of implementation [design](/docs/design.MD)
- high availability [doc](/docs/high-availability.MD)
- operator objects description [doc](/docs/api.MD)
- backup [doc](/docs/backup.MD)



Expand All @@ -18,9 +17,9 @@

## development

- operator-sdk verson v0.17.0 + [https://github.com/operator-framework/operator-sdk]
- operator-sdk verson v0.18.1 + [https://github.com/operator-framework/operator-sdk]
- golang 1.13 +
- minikube
- minikube or kind

start:
```bash
Expand Down
2 changes: 2 additions & 0 deletions cmd/doc-gen/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var (
"v1.Container": "https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#container-v1-core",
"v1.EnvVar": "https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#envvar-v1-core",
"v1.PersistentVolumeClaimSpec": "https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#persistentvolumeclaimspec-v1-core",
"v1.PodSecurityContext": "https://v1-17.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#podsecuritycontext-v1-core",
"v1.DNSPolicy": "https://v1-17.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#pod-v1-core",
}

selfLinks = map[string]string{}
Expand Down
Loading

0 comments on commit 69e8202

Please sign in to comment.