This repository has been archived by the owner on Jul 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Ultimaker/restore_helper
Restore helper
- Loading branch information
Showing
73 changed files
with
1,861 additions
and
1,139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) 2018 Ultimaker B.V. | ||
# This file contains the flake8 rules used in the stardust projects. | ||
|
||
# To configure Flake8 as an external tool in PyCharm, create a new External Tool with the settings: | ||
# | ||
# Name: Flake8 | ||
# Program: Check with 'which flake8'. For example: /home/dschiavini/.local/bin/flake8 | ||
# Arguments: $ContentRoot$/$FileDirRelativeToProjectRoot$ --config=$ContentRoot$/lib/stardustCommons/.flake8 --count | ||
# Working directory: $ContentRoot$ | ||
# Output filters: $FILE_PATH$:$LINE$:$COLUMN$:.* | ||
# | ||
# You can add a keyboard shortcut in the keymap settings. Select the folder you want to check (e.g. the root of the | ||
# project) before running the external tool. | ||
# | ||
# If you find a better way to configure the external tool please edit this file. | ||
|
||
[flake8] | ||
# E251 allows us to add extra spaces in constructors and method calls, i.e. method(value = result). | ||
# F401 is ignored because it gives false positives for # type comments | ||
# W503 forbids line breaks before binary operators, we use instead W504 to forbid breaks after the operators | ||
ignore = E251, F401, W503 | ||
exclude = .git,__pycache__,node_modules,libCharon,venv | ||
max-complexity = 6 | ||
max-line-length = 120 | ||
inline-quotes = double |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,4 +106,4 @@ ENV/ | |
.idea | ||
|
||
# Google credentials | ||
google_credentials.json | ||
google-credentials.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# Copyright (c) 2018 Ultimaker B.V. | ||
# This file contains the Pylint rules used in the stardust projects. | ||
|
||
# To configure PyLint as an external tool in PyCharm, create a new External Tool with the settings: | ||
# | ||
# Name: PyLint | ||
# Program: Check with 'which pylint'. For example: /home/dschiavini/.local/bin/pylint | ||
# Arguments: $FileDirName$ --rcfile=lib/stardustCommons/.pylintrc --msg-template='{abspath}:{line}:{column}:({symbol}):{msg_id}:{msg}' | ||
# Working directory: $ContentRoot$ | ||
# Output filters: $FILE_PATH$:$LINE$:$COLUMN$:.* | ||
# | ||
# You can add a keyboard shortcut in the keymap settings. To run Pylint to a project, select the module | ||
# you want to check (e.g. stardustAuthServerApi folder) before running the external tool. | ||
# | ||
# If you find a better way to configure the external tool please edit this file. | ||
|
||
[MASTER] | ||
# List of plugins (as comma separated values of python modules names) to load, | ||
# usually to register additional checkers. | ||
load-plugins=pylint_quotes | ||
|
||
# We expect double string quotes | ||
string-quote=double-avoid-escape | ||
|
||
# When enabled, pylint would attempt to guess common misconfiguration and emit | ||
# user-friendly hints instead of false-positive error messages. | ||
suggestion-mode=yes | ||
|
||
# Add files or directories to the blacklist. They should be base names, not paths. | ||
ignore=node_modules,tests | ||
|
||
[REFACTORING] | ||
# Maximum number of nested blocks for function / method body | ||
max-nested-blocks=3 | ||
|
||
[MESSAGES CONTROL] | ||
# C0326: No space allowed around keyword argument assignment | ||
# C0111: Missing module docstring (because we use a file per class, this would lead to duplicate docstrings) | ||
# C0411: Ignore import order because the rules are different than in PyCharm, so automatic imports break lots of builds | ||
# R0201: Method could be a function (no-self-use) | ||
# R0401: Cyclic imports (cyclic-import) are used for typing | ||
# R0801: Unfortunately the error is triggered for a lot of similar models (duplicate-code) | ||
# R1710: Either all return statements in a function should return an expression, or none of them should. | ||
# W0221: Parameters differ from overridden method (tornado http methods have a flexible number of parameters) | ||
# W0511: Ignore warnings generated for TODOs in the code | ||
disable=C0326,C0411,C0111,R0201,R0401,R0801,R1710,W0221,W0511 | ||
|
||
[FORMAT] | ||
# Maximum number of characters on a single line. | ||
max-line-length=120 | ||
|
||
# Maximum number of lines in a module. | ||
max-module-lines=500 | ||
|
||
good-names=os | ||
|
||
[BASIC] | ||
# allow modules and functions to use pascalCase | ||
module-rgx=[a-zA-Z0-9_]+$ | ||
function-rgx= | ||
method-rgx=([a-z_][a-z0-9_]{2,30}|([a-z_][A-Za-z0-9]{2,30}))$ | ||
|
||
[DESIGN] | ||
# Maximum number of arguments for function / method. | ||
max-args=7 | ||
|
||
# Maximum number of attributes for a class (see R0902). | ||
max-attributes=8 | ||
|
||
# Maximum number of boolean expressions in an if statement. | ||
max-bool-expr=5 | ||
|
||
# Maximum number of branch for function / method body. | ||
max-branches=12 | ||
|
||
# Maximum number of locals for function / method body. | ||
max-locals=15 | ||
|
||
# Maximum number of parents for a class (see R0901). | ||
max-parents=7 | ||
|
||
# Maximum number of public methods for a class (see R0904). | ||
max-public-methods=20 | ||
|
||
# Maximum number of return / yield for function / method body. | ||
max-returns=6 | ||
|
||
# Maximum number of statements in function / method body. | ||
max-statements=50 | ||
|
||
# Minimum number of public methods for a class (R0903). | ||
# We set this to 0 because our models and fields do not have methods. | ||
min-public-methods=0 | ||
|
||
[CLASSES] | ||
defining-attr-methods=__init__,__new__,setUp,initialize | ||
|
||
[TYPECHECK] | ||
ignored-classes=NotImplemented | ||
|
||
[VARIABLES] | ||
dummy-variables-rgx=_+[a-z0-9_]{2,30} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) 2018 Ultimaker B.V. | ||
FROM python:3.6-stretch AS base | ||
WORKDIR /usr/src/app | ||
|
||
COPY requirements*.txt ./ | ||
# install MongoDB tools | ||
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5 && \ | ||
echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/3.6 main" | tee /etc/apt/sources.list.d/mongodb-org-3.6.list && \ | ||
apt-get update && \ | ||
DEBIAN_FRONTEND=noninteractive apt-get install -y mongodb-org-tools mongodb-org-shell | ||
|
||
RUN pip install --no-cache-dir -r requirements.txt | ||
RUN pip install --no-cache-dir -r requirements-testing.txt | ||
|
||
ARG cache=1 | ||
ARG KUBERNETES_SERVICE_HOST="localhost" | ||
ARG KUBERNETES_SERVICE_PORT=8081 | ||
RUN mkdir -p /var/run/secrets/kubernetes.io/serviceaccount && \ | ||
echo "unit-test" >> /var/run/secrets/kubernetes.io/serviceaccount/token && \ | ||
echo "unit-test" >> /var/run/secrets/kubernetes.io/serviceaccount/ca.crt | ||
ADD . . | ||
|
||
ENTRYPOINT ["python", "./main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,56 @@ | ||
#!/usr/bin/env bash | ||
set -eo pipefail | ||
|
||
EXAMPLE_FILE=${1:-examples/mongo-3-replicas.yaml} | ||
|
||
if ! [[ -e "google-credentials.json" ]]; then | ||
echo "google-credentials.json file is missing, aborting." | ||
exit -1 | ||
fi | ||
|
||
# set the environment of the minikube docker | ||
eval $(minikube docker-env) | ||
|
||
readonly NAMESPACE="mongo-operator-cluster" | ||
readonly KUBECTL="kubectl --namespace=${NAMESPACE}" | ||
|
||
# build the docker image | ||
docker build --tag ultimaker/k8s-mongo-operator:local . | ||
|
||
# print out the Kubernetes client and server versions | ||
kubectl version | ||
${KUBECTL} version | ||
|
||
if ! kubectl get namespace ${NAMESPACE}; then | ||
kubectl create namespace ${NAMESPACE} | ||
fi | ||
|
||
# remove the deployment, if needed, and apply the new one | ||
kubectl delete deployment mongo-operator 2>/dev/null | ||
kubectl apply --filename=kubernetes/operators/mongo-operator/service-account.yaml | ||
kubectl apply --filename=kubernetes/operators/mongo-operator/cluster-role.yaml | ||
kubectl apply --filename=kubernetes/operators/mongo-operator/cluster-role-binding.yaml | ||
kubectl apply --filename=kubernetes/operators/mongo-operator/deployment.yaml | ||
${KUBECTL} delete deployment mongo-operator 1>/dev/null | ||
${KUBECTL} apply --filename=kubernetes/operators/mongo-operator/service-account.yaml | ||
${KUBECTL} apply --filename=kubernetes/operators/mongo-operator/cluster-role.yaml | ||
${KUBECTL} apply --filename=kubernetes/operators/mongo-operator/cluster-role-binding.yaml | ||
${KUBECTL} apply --filename=kubernetes/operators/mongo-operator/deployment.yaml | ||
|
||
# show some details about the deployment | ||
kubectl describe deploy mongo-operator | ||
${KUBECTL} describe deploy mongo-operator | ||
|
||
# create a secret with the google account credentials | ||
kubectl create secret generic storage-serviceaccount --from-file=json=google_credentials.json | ||
if ${KUBECTL} get secret storage-serviceaccount 1>/dev/null; then | ||
${KUBECTL} delete secret storage-serviceaccount | ||
fi | ||
${KUBECTL} create secret generic storage-serviceaccount --from-file=json=google-credentials.json | ||
|
||
# wait for the pod to startup to retrieve its name | ||
sleep 10 | ||
POD_NAME=$(kubectl get pods | grep -e "mongo-operator.*Running" | cut --fields=1 --delimiter=" ") | ||
POD_NAME=$(${KUBECTL} get pod -l app=mongo-operator -o jsonpath="{.items[0].metadata.name}") | ||
if [ -z $POD_NAME ]; then | ||
echo "The operator pod is not running!" | ||
kubectl get pods | ||
${KUBECTL} get pods | ||
exit 1 | ||
fi | ||
|
||
# apply the example file | ||
kubectl apply --filename=examples/mongo-3-replicas.yaml | ||
${KUBECTL} apply --filename=${EXAMPLE_FILE} | ||
|
||
# show the pod logs | ||
kubectl logs ${POD_NAME} --follow | ||
${KUBECTL} logs ${POD_NAME} --follow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apiVersion: "operators.ultimaker.com/v1" | ||
kind: Mongo | ||
metadata: | ||
name: mongo-cluster | ||
namespace: mongo-operator-cluster | ||
labels: | ||
app: mongo-cluster | ||
spec: | ||
mongodb: | ||
replicas: 3 # Must be between 3 and 50 | ||
cpu_limit: "200m" | ||
memory_limit: "64Mi" | ||
backups: | ||
cron: "0 * * * *" # every hour at 0 minutes | ||
gcs: | ||
bucket: "ultimaker-mongo-backups" | ||
# Set restore_from to 'latest' to use the last backup created when initializing the replicaset. | ||
restore_from: "latest" | ||
# set restore_bucket if the file in restore_from is in another bucket. | ||
# restore_bucket: | ||
prefix: "test-backups" | ||
serviceAccount: | ||
secretKeyRef: | ||
name: storage-serviceaccount | ||
key: json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apiVersion: "operators.ultimaker.com/v1" | ||
kind: Mongo | ||
metadata: | ||
name: mongo-cluster | ||
namespace: mongo-operator-cluster | ||
labels: | ||
app: mongo-cluster | ||
spec: | ||
mongodb: | ||
replicas: 3 # Must be between 3 and 50 | ||
cpu_limit: "200m" | ||
memory_limit: "64Mi" | ||
backups: | ||
cron: "0 * * * *" # every hour at 0 minutes | ||
gcs: | ||
bucket: "ultimaker-mongo-backups" | ||
# Set restore_from to 'latest' to use the last backup created when initializing the replicaset. | ||
restore_from: mongodb-backup-default-mongo-cluster-2019-02-07_132931.archive.gz | ||
# set restore_bucket if the file in restore_from is in another bucket. | ||
# restore_bucket: | ||
prefix: "test-backups" | ||
serviceAccount: | ||
secretKeyRef: | ||
name: storage-serviceaccount | ||
key: json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.