Skip to content

Commit

Permalink
Merge pull request #60 from VictoriaMetrics/upgraded-sdk-version
Browse files Browse the repository at this point in the history
Upgraded sdk and go version, changed folders structure.
  • Loading branch information
f41gh7 authored Aug 18, 2020
2 parents d4510ad + 1faf3cf commit e61faff
Show file tree
Hide file tree
Showing 48 changed files with 2,466 additions and 12,933 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@master
with:
go-version: 1.13
go-version: 1.15
id: go
- name: Dependencies
env:
Expand All @@ -25,7 +25,7 @@ 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.19.0/operator-sdk-v0.19.0-x86_64-linux-gnu"
curl -L -o operator-sdk "https://github.com/operator-framework/operator-sdk/releases/download/v1.0.0/operator-sdk-v0.19.0-x86_64-linux-gnu"
chmod +x operator-sdk
sudo mv operator-sdk /bin/
- name: setup KIND for e2e tests
Expand Down Expand Up @@ -59,5 +59,5 @@ jobs:
password: ${{secrets.REPO_KEY}}
repository: victoriametrics/operator
tag_with_ref: true
dockerfile: build/Dockerfile
dockerfile: Dockerfile

6 changes: 3 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@master
with:
go-version: 1.13
go-version: 1.15
id: go
- name: Dependencies
env:
Expand All @@ -23,7 +23,7 @@ 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.19.0/operator-sdk-v0.19.0-x86_64-linux-gnu"
curl -L -o operator-sdk "https://github.com/operator-framework/operator-sdk/releases/download/v1.0.0/operator-sdk-v0.19.0-x86_64-linux-gnu"
chmod +x operator-sdk
sudo mv operator-sdk /bin/
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
password: ${{secrets.REPO_KEY}}
tag_with_ref: true
repository: victoriametrics/operator
dockerfile: build/Dockerfile
dockerfile: Dockerfile


- name: Upload Release Asset
Expand Down
12 changes: 11 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

for developing you need:
- golang 1.13+
- operator-sdk 1.19.0
- operator-sdk v1.0.0
- docker
- minikube or kind for e2e tests
- golangci-lint
Expand Down Expand Up @@ -32,6 +32,16 @@ make test #unit tests
make e2e-local #e2e tests with minikube
```

## adding new api

For adding new kind - KIND_NAME, you have to execute command:

```bash
operator-sdk create api --group operator --version v1beta1 --kind KIND_NAME
```

This will scaffold api and controller. Then you have to edit code at `api` and `controllers` folder.

## create olm package

Choose version and generate or update corresponding csv file
Expand Down
31 changes: 8 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
# Build the manager binary
FROM golang:1.13 as builder
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest

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
ENV OPERATOR=/usr/local/bin/manager \
USER_UID=1001 \
USER_NAME=vm-operator

# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
# install operator binary
COPY bin/manager ${OPERATOR}

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
ENTRYPOINT ["/usr/local/bin/manager"]

# 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 nonroot:nonroot

ENTRYPOINT ["/manager"]
USER ${USER_UID}
27 changes: 27 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Build the manager binary
FROM golang:1.15 as builder

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 main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY internal/ internal/
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -trimpath -a -o manager 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 nonroot:nonroot

ENTRYPOINT ["/manager"]
76 changes: 36 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Go parameters
GOCMD=GO111MODULE=on go
TAG ?= 0.0.1
TAG ?= 0.1.0
VERSION=$(TAG)
GOOS ?= linux
GOARCH ?= amd64
Expand All @@ -11,20 +11,13 @@ GOCLEAN=$(GOCMD) clean
GOTEST=CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} $(GOCMD) test
GOGET=$(GOCMD) get
BINARY_NAME=vm-operator
BINARY_UNIX=$(BINARY_NAME)_unix
REPO=github.com/VictoriaMetrics/operator
DOC_GEN_DIR=$(REPO)/cmd/doc-gen/
OPERATOR_BIN=operator-sdk
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=api/v1beta1
GOPATHDIR ?= ~/go
YAML_DROP_PREFIX=spec.validation.openAPIV3Schema.properties.spec.properties
YAML_DROP=yq delete --inplace
YAML_FIX_LIST="vmalertmanagers.yaml vmalerts.yaml vmsingles.yaml vmagents.yaml"
# Current Operator version
# Default bundle image tag
BUNDLE_IMG ?= controller-bundle:$(VERSION)
Expand Down Expand Up @@ -58,19 +51,25 @@ all: build
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
install-docs-generators:
which envconfig-docs || GO111MODULE=off go get -u github.com/f41gh7/envconfig-docs
which doc-print || GO111MODULE=off go get -u github.com/f41gh7/doc-print

install-develop-tools: install-golint install-docs-generators


#YAML_FIX_LIST=vmalertmanagers.yaml vmalerts.yaml vmsingles.yaml vmagents.yaml
fix118:
docker run --rm -v "${PWD}":/workdir mikefarah/yq /bin/sh -c ' \
for file in ${YAML_FIX_LIST} ;\
do \
$(YAML_DROP) config/crd/bases/operator.victoriametrics.com_$$file $(YAML_DROP_PREFIX).initContainers.items.properties &&\
$(YAML_DROP) config/crd/bases/operator.victoriametrics.com_$$file $(YAML_DROP_PREFIX).containers.items.properties ;\
done ; \
$(YAML_DROP) config/crd/bases/operator.victoriametrics.com_vmclusters.yaml $(YAML_DROP_PREFIX).vminsert.properties.containers.items.properties && \
$(YAML_DROP) config/crd/bases/operator.victoriametrics.com_vmalertmanagers.yaml $(YAML_DROP_PREFIX).initContainers.items.properties &&\
$(YAML_DROP) config/crd/bases/operator.victoriametrics.com_vmalertmanagers.yaml $(YAML_DROP_PREFIX).containers.items.properties ;\
$(YAML_DROP) config/crd/bases/operator.victoriametrics.com_vmalerts.yaml $(YAML_DROP_PREFIX).initContainers.items.properties &&\
$(YAML_DROP) config/crd/bases/operator.victoriametrics.com_vmalerts.yaml $(YAML_DROP_PREFIX).containers.items.properties ;\
$(YAML_DROP) config/crd/bases/operator.victoriametrics.com_vmsingles.yaml $(YAML_DROP_PREFIX).initContainers.items.properties &&\
$(YAML_DROP) config/crd/bases/operator.victoriametrics.com_vmsingles.yaml $(YAML_DROP_PREFIX).containers.items.properties ;\
$(YAML_DROP) config/crd/bases/operator.victoriametrics.com_vmagents.yaml $(YAML_DROP_PREFIX).initContainers.items.properties &&\
$(YAML_DROP) config/crd/bases/operator.victoriametrics.com_vmagents.yaml $(YAML_DROP_PREFIX).containers.items.properties ;\
$(YAML_DROP) config/crd/bases/operator.victoriametrics.com_vmclusters.yaml $(YAML_DROP_PREFIX).vminsert.properties.containers.items.properties && \
$(YAML_DROP) config/crd/bases/operator.victoriametrics.com_vmclusters.yaml $(YAML_DROP_PREFIX).vminsert.properties.initContainers.items.properties && \
$(YAML_DROP) config/crd/bases/operator.victoriametrics.com_vmclusters.yaml $(YAML_DROP_PREFIX).vmselect.properties.containers.items.properties && \
$(YAML_DROP) config/crd/bases/operator.victoriametrics.com_vmclusters.yaml $(YAML_DROP_PREFIX).vmselect.properties.initContainers.items.properties && \
Expand All @@ -79,35 +78,29 @@ fix118:
'


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

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


doc:
$(GOBUILD) -o doc-print $(DOC_GEN_DIR)
./doc-print api \
$(APIS_BASE_PATH)/vmalertmanager_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)/vmcluster_types.go \
> docs/api.MD
doc: install-develop-tools
doc-print --paths=\
$(APIS_BASE_PATH)/vmalertmanager_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)/vmcluster_types.go \
--owner VictoriaMetrics \
> docs/api.MD

operator-conf: install-develop-tools
envconfig-docs --input internal/conf/config.go > vars.MD


docker: manager
docker build -t $(DOCKER_REPO) . -f build/Dockerfile
docker build -t $(DOCKER_REPO) . -f Dockerfile


.PHONY:e2e-local
Expand All @@ -117,14 +110,13 @@ e2e-local: generate fmt vet manifests fix118
$(GOCMD) tool cover -func coverage.txt | grep total

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

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


all: manager
Expand Down Expand Up @@ -237,3 +229,7 @@ release-package: kustomize
zip -r operator.zip bin/manager
zip -r bundle_crd.zip release/
rm -rf release/

packagemanifests: manifests fix118
$(OPERATOR_BIN) generate kustomize manifests -q
kustomize build config/manifests | $(OPERATOR_BIN) generate packagemanifests -q --version $(VERSION)
4 changes: 4 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
domain: victoriametrics.com
layout: go.kubebuilder.io/v2
projectName: vm-operator
repo: github.com/VictoriaMetrics/operator
resources:
- group: operator
Expand All @@ -26,6 +27,9 @@ resources:
- group: operator
kind: VMCluster
version: v1beta1
- group: operator
kind: VMProbe
version: v1beta1
version: 3-alpha
plugins:
go.operator-sdk.io/v2-alpha: {}
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# VictoriaMetrics operator


## Documentation

- quick start [doc](/docs/quick-start.MD)
Expand All @@ -13,14 +14,15 @@



## limitations
## kubernetes compatibility versions

- alert relabel is not supported
operator tested at kubernetes versions
from 1.13 to 1.18

## development

- operator-sdk verson v0.19.0 + [https://github.com/operator-framework/operator-sdk]
- golang 1.13 +
- operator-sdk verson v1.0.0 + [https://github.com/operator-framework/operator-sdk]
- golang 1.15 +
- minikube or kind

start:
Expand Down
12 changes: 0 additions & 12 deletions build/Dockerfile

This file was deleted.

Loading

0 comments on commit e61faff

Please sign in to comment.