Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial API objects & vendoring #2

Merged
merged 10 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
.git
.gobuild
docs
pkg
tools
vendor

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
.gobuild
bin

37 changes: 37 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"git.ignoreLimitWarning": true,
"fileHeaderComment.parameter":{
"*":{
"commentprefix": "//",
"company": "ArangoDB GmbH, Cologne, Germany",
"author": "Ewout Prangsma"
}
},
"fileHeaderComment.template":{
"*":[
"${commentprefix} ",
"${commentprefix} DISCLAIMER",
"${commentprefix} ",
"${commentprefix} Copyright ${year} ArangoDB GmbH, Cologne, Germany",
"${commentprefix} ",
"${commentprefix} Licensed under the Apache License, Version 2.0 (the \"License\");",
"${commentprefix} you may not use this file except in compliance with the License.",
"${commentprefix} You may obtain a copy of the License at",
"${commentprefix} ",
"${commentprefix} http://www.apache.org/licenses/LICENSE-2.0",
"${commentprefix} ",
"${commentprefix} Unless required by applicable law or agreed to in writing, software",
"${commentprefix} distributed under the License is distributed on an \"AS IS\" BASIS,",
"${commentprefix} WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.",
"${commentprefix} See the License for the specific language governing permissions and",
"${commentprefix} limitations under the License.",
"${commentprefix} ",
"${commentprefix} Copyright holder is ArangoDB GmbH, Cologne, Germany",
"${commentprefix} ",
"${commentprefix} Author ${author}",
"${commentprefix} ",
""
]
},
"go.gopath": "${workspaceRoot}/.gobuild"
}
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch

ADD bin/arangodb_operator /usr/bin/

ENTRYPOINT [ "/usr/bin/arangodb_operator" ]
165 changes: 165 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
PROJECT := arangodb_operator
SCRIPTDIR := $(shell pwd)
ROOTDIR := $(shell cd $(SCRIPTDIR) && pwd)
VERSION := $(shell cat $(ROOTDIR)/VERSION)
VERSION_MAJOR_MINOR_PATCH := $(shell echo $(VERSION) | cut -f 1 -d '+')
VERSION_MAJOR_MINOR := $(shell echo $(VERSION_MAJOR_MINOR_PATCH) | cut -f 1,2 -d '.')
VERSION_MAJOR := $(shell echo $(VERSION_MAJOR_MINOR) | cut -f 1 -d '.')
COMMIT := $(shell git rev-parse --short HEAD)
DOCKERCLI := $(shell which docker)

GOBUILDDIR := $(SCRIPTDIR)/.gobuild
SRCDIR := $(SCRIPTDIR)
BINDIR := $(ROOTDIR)/bin
VENDORDIR := $(ROOTDIR)/vendor

ORGPATH := github.com/arangodb
ORGDIR := $(GOBUILDDIR)/src/$(ORGPATH)
REPONAME := k8s-operator
REPODIR := $(ORGDIR)/$(REPONAME)
REPOPATH := $(ORGPATH)/$(REPONAME)

GOPATH := $(GOBUILDDIR)
GOVERSION := 1.9.3-alpine

PULSAR := $(GOBUILDDIR)/bin/pulsar$(shell go env GOEXE)

ifndef DOCKERNAMESPACE
DOCKERNAMESPACE := arangodb
endif
ifndef DOCKERFILE
DOCKERFILE := Dockerfile
#DOCKERFILE := Dockerfile.debug
endif

BINNAME := $(PROJECT)
BIN := $(BINDIR)/$(BINNAME)
RELEASE := $(GOBUILDDIR)/bin/release
GHRELEASE := $(GOBUILDDIR)/bin/github-release

SOURCES := $(shell find $(SRCDIR) -name '*.go' -not -path './test/*')

.PHONY: all clean deps docker update-vendor update-generated verify-generated

all: verify-generated docker

#
# Tip: Run `eval $(minikube docker-env)` before calling make if you're developing on minikube.
#

build: docker

clean:
rm -Rf $(BIN) $(BINDIR) $(GOBUILDDIR)

deps:
@${MAKE} -B -s $(GOBUILDDIR)

$(GOBUILDDIR):
# Build pulsar from vendor
@mkdir -p $(GOBUILDDIR)
@ln -s $(VENDORDIR) $(GOBUILDDIR)/src
@GOPATH=$(GOBUILDDIR) go install github.com/pulcy/pulsar
@rm -f $(GOBUILDDIR)/src
# Prepare .gobuild directory
@mkdir -p $(ORGDIR)
@rm -f $(REPODIR) && ln -s ../../../.. $(REPODIR)
GOPATH=$(GOBUILDDIR) $(PULSAR) go flatten -V vendor

update-vendor:
@mkdir -p $(GOBUILDDIR)
@GOPATH=$(GOBUILDDIR) go get github.com/pulcy/pulsar
@rm -Rf $(VENDORDIR)
@mkdir -p $(VENDORDIR)
@git clone https://github.com/kubernetes/code-generator.git $(VENDORDIR)/k8s.io/code-generator
@rm -Rf $(VENDORDIR)/k8s.io/code-generator/.git
@$(PULSAR) go vendor k8s.io/client-go/...
@$(PULSAR) go vendor k8s.io/gengo/args
@$(PULSAR) go vendor k8s.io/apiextensions-apiserver
@$(PULSAR) go vendor github.com/cenkalti/backoff
@$(PULSAR) go vendor github.com/pkg/errors
@$(PULSAR) go vendor github.com/prometheus/client_golang/prometheus
@$(PULSAR) go vendor github.com/pulcy/pulsar
@$(PULSAR) go vendor github.com/rs/zerolog
@$(PULSAR) go vendor github.com/spf13/cobra
@$(PULSAR) go flatten -V $(VENDORDIR) $(VENDORDIR)
@${MAKE} -B -s clean

update-generated: $(GOBUILDDIR)
@docker build $(SRCDIR)/tools/codegen --build-arg GOVERSION=$(GOVERSION) -t k8s-codegen
docker run \
--rm \
-v $(SRCDIR):/usr/code \
-e GOPATH=/usr/code/.gobuild \
-e GOBIN=/usr/code/.gobuild/bin \
-w /usr/code/ \
k8s-codegen \
"./vendor/k8s.io/code-generator/generate-groups.sh" \
"all" \
"github.com/arangodb/k8s-operator/pkg/generated" \
"github.com/arangodb/k8s-operator/pkg/apis" \
"arangodb:v1alpha" \
--go-header-file "./tools/codegen/boilerplate.go.txt" \
$(VERIFYARGS)

verify-generated:
@${MAKE} -B -s VERIFYARGS=--verify-only update-generated

$(BIN): $(GOBUILDDIR) $(SOURCES)
@mkdir -p $(BINDIR)
docker run \
--rm \
-v $(SRCDIR):/usr/code \
-e GOPATH=/usr/code/.gobuild \
-e GOOS=linux \
-e GOARCH=amd64 \
-e CGO_ENABLED=0 \
-w /usr/code/ \
golang:$(GOVERSION) \
go build -installsuffix cgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(BINNAME) $(REPOPATH)

docker: $(BIN)
docker build -f $(DOCKERFILE) -t arangodb/arangodb-operator .

docker-push: docker
ifneq ($(DOCKERNAMESPACE), arangodb)
docker tag arangodb/arangodb-operator $(DOCKERNAMESPACE)/arangodb-operator
endif
docker push $(DOCKERNAMESPACE)/arangodb-operator

docker-push-version: docker
docker tag arangodb/arangodb-operator arangodb/arangodb-operator:$(VERSION)
docker tag arangodb/arangodb-operator arangodb/arangodb-operator:$(VERSION_MAJOR_MINOR)
docker tag arangodb/arangodb-operator arangodb/arangodb-operator:$(VERSION_MAJOR)
docker tag arangodb/arangodb-operator arangodb/arangodb-operator:latest
docker push arangodb/arangodb-operator:$(VERSION)
docker push arangodb/arangodb-operator:$(VERSION_MAJOR_MINOR)
docker push arangodb/arangodb-operator:$(VERSION_MAJOR)
docker push arangodb/arangodb-operator:latest

$(RELEASE): $(GOBUILDDIR) $(SOURCES) $(GHRELEASE)
GOPATH=$(GOBUILDDIR) go build -o $(RELEASE) $(REPOPATH)/tools/release

$(GHRELEASE): $(GOBUILDDIR)
GOPATH=$(GOBUILDDIR) go build -o $(GHRELEASE) github.com/aktau/github-release

release-patch: $(RELEASE)
GOPATH=$(GOBUILDDIR) $(RELEASE) -type=patch

release-minor: $(RELEASE)
GOPATH=$(GOBUILDDIR) $(RELEASE) -type=minor

release-major: $(RELEASE)
GOPATH=$(GOBUILDDIR) $(RELEASE) -type=major

## Kubernetes utilities

minikube-start:
minikube start --cpus=4 --memory=6144

delete-operator:
kubectl delete -f examples/deployment.yaml || true

redeploy-operator: delete-operator
kubectl create -f examples/deployment.yaml
kubectl get pods
2 changes: 2 additions & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0.0.0+git

24 changes: 12 additions & 12 deletions docs/user/custom_resource.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Custom Resource

The ArangoDB operator creates and maintains ArangoDB clusters
The ArangoDB operator creates and maintains ArangoDB deployments
in a Kubernetes cluster, given a cluster specification.
This cluster specification is a CustomResource following
a CustomResourceDefinition created by the operator.

Example minimal cluster definition:

```yaml
apiVersion: "cluster.arangodb.com/v1alpha"
kind: "Cluster"
apiVersion: "database.arangodb.com/v1alpha"
kind: "ArangoDeployment"
metadata:
name: "example-arangodb-cluster"
spec:
Expand All @@ -19,8 +19,8 @@ spec:
Example more elaborate cluster definition:

```yaml
apiVersion: "cluster.arangodb.com/v1alpha"
kind: "Cluster"
apiVersion: "database.arangodb.com/v1alpha"
kind: "ArangoDeployment"
metadata:
name: "example-arangodb-cluster"
spec:
Expand All @@ -46,7 +46,7 @@ spec:

## Specification reference

Below you'll find all settings of the `Cluster` custom resource.
Below you'll find all settings of the `ArangoDeployment` custom resource.
Several settings are for various groups of servers. These are indicated
with `<group>` where `<group>` can be any of:

Expand All @@ -59,23 +59,23 @@ with `<group>` where `<group>` can be any of:

### `spec.mode: string`

This setting specifies the type of cluster you want to create.
This setting specifies the type of deployment you want to create.
Possible values are:

- `cluster` (default) Full cluster. Defaults to 3 agents, 3 dbservers & 3 coordinators.
- `resilientsingle` Resilient single pair. Defaults to 3 agents and 2 single servers.
- `single` Single server only (note this does not provide high availability or reliability).

This setting cannot be changed after the cluster has been created.
This setting cannot be changed after the deployment has been created.

### `spec.environment: string`

This setting specifies the type of environment in which the cluster is created.
This setting specifies the type of environment in which the deployment is created.
Possible values are:

- `development` (default) This value optimizes the cluster for development
use. It is possible to run a cluster on a small number of nodes (e.g. minikube).
- `production` This value optimizes the cluster for production use.
- `development` (default) This value optimizes the deployment for development
use. It is possible to run a deployment on a small number of nodes (e.g. minikube).
- `production` This value optimizes the deployment for production use.
It puts required affinity constraints on all pods to avoid agents & dbservers
from running on the same machine.

Expand Down
1 change: 1 addition & 0 deletions examples/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ spec:
spec:
containers:
- name: arangodb-operator
imagePullPolicy: IfNotPresent
image: arangodb/arangodb-operator:latest
env:
- name: MY_POD_NAMESPACE
Expand Down
4 changes: 2 additions & 2 deletions examples/simple-cluster.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: "cluster.arangodb.com/v1alpha"
kind: "Cluster"
apiVersion: "database.arangodb.com/v1alpha"
kind: "ArangoDeployment"
metadata:
name: "example-arangodb-cluster"
spec:
Expand Down
6 changes: 6 additions & 0 deletions examples/single-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: "database.arangodb.com/v1alpha"
kind: "ArangoDeployment"
metadata:
name: "example-single-arangodb-server"
spec:
mode: single
Loading