Skip to content

Commit

Permalink
Initial SaaS migration notes
Browse files Browse the repository at this point in the history
Add sample redis data pull scripts
  • Loading branch information
Boomatang committed May 5, 2023
1 parent 31a8f2f commit 6a3c480
Show file tree
Hide file tree
Showing 14 changed files with 793 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/.idea

*/.idea
__pycache__/
5 changes: 5 additions & 0 deletions saas-to-rhoam/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [WIP] 3scale SaaS to RHOAM migration

**WARNING:** The work that is on going here is for proof of concepts and should not be used on production systems.

The redis_dump directory holds examples for how to pull metrics from redis on bulk.
20 changes: 20 additions & 0 deletions saas-to-rhoam/redis_dump/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.11 AS base
RUN pip install --upgrade pip

FROM base AS builder

ENV POETRY_VERSION=1.1.13

RUN pip install "poetry==$POETRY_VERSION"

WORKDIR /src

COPY . /src/
RUN poetry build

FROM base as runtime
WORKDIR /app
COPY --from=builder /src/dist/*.whl /app/

RUN pip install --no-cache-dir *.whl \
&& rm -rf *whl
99 changes: 99 additions & 0 deletions saas-to-rhoam/redis_dump/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# redis dump

**WARNING:** These scripts are proof of concept and not complete.
Please refer [MGDAPI-5322](https://issues.redhat.com/browse/MGDAPI-5322) for more information.

This set of scripts is used to pull metrics from the 3scale redis and migrate them to a new instances.

The scripts are design to be run as a pod on cluster.
To run locally there are a number environment variables that need to be set.

The best way to run them locally is by using podman.

## Running Locally

### Target Redis
There needs to be access the target redis locally if using the default configuration.
This can be done by setting up a port forward using `kubectl`.
Personal I use `k9s` to manage this work but the command for `kubectl` would be something like: `kubectl port-forward <pod-name> <local port>:<remote port>`.
The default configuration assumes the port to be `6379`.

### Build the image
From the project root run:

```shell
podman build -t redis_dump:latest .
```

### Pull script
Start the script by calling.
```shell
podman kube play --net=host pullfile.yaml
```

Check pod logs for completion.
```shell
podman pod logs -f foobar
```

Copy the json file form the container.
```shell
podman cp foobar-container:/app/data.json data.json
```

Clean up the pods once finished.
```shell
podman kube down pullfile.yaml
```

### Push script
Start the script by calling.
```shell
podman kube play --net=host pushfile.yaml
```

Check pod logs for completion.
```shell
podman pod logs -f foobar
```

Clean up the pods once finished.
```shell
podman kube down pullfile.yaml
```

### Seed Script
The seed script is design to add volume to a redis instance for checking performances of other scripts.
It is a test script and does not produce a 3scale usable redis instances.

A local redis instance can be configured using the following.
The volume is required if doing a large number of entries as the default container storage will fill.
```shell
podman volume create redisVol
podman run --rm --name redis-server -p 6379:6379 -v redisVol:/data:z redis
```

Set up the pod:
```shell
podman kube play --net=host --start=false seedfile.yaml
```

Added the seed file.
```shell
podman cp seed.json foobar-container:/app/seed.json
```

Start the pod.
```shell
podman pod start foobar
```

Check logs for completed message.
```shell
podman pod logs -f foobar
```

Clean the pod up once finished.
```shell
podman kube down seedfile.yaml
```
137 changes: 137 additions & 0 deletions saas-to-rhoam/redis_dump/poetry.lock

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

41 changes: 41 additions & 0 deletions saas-to-rhoam/redis_dump/pullfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: v1
kind: Secret
metadata:
name: threescale-backend-redis-rhoam
data:
port: NjM3OQ==
uri: bG9jYWxob3N0
---
apiVersion: v1
kind: ConfigMap
metadata:
name: foo
data:
ACCOUNTS: "1,2,3,5,4,6,7"
---
apiVersion: v1
kind: Pod
metadata:
name: foobar
spec:
containers:
- command:
- pull
name: container
image: redis_dump
envFrom:
- configMapRef:
name: foo
optional: false
env:
- name: PORT
valueFrom:
secretKeyRef:
key: port
name: threescale-backend-redis-rhoam
- name: URI
valueFrom:
secretKeyRef:
key: uri
name: threescale-backend-redis-rhoam
restartPolicy: Never
41 changes: 41 additions & 0 deletions saas-to-rhoam/redis_dump/pushfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: v1
kind: Secret
metadata:
name: threescale-backend-redis-rhoam
data:
port: NjM3OQ==
uri: bG9jYWxob3N0
---
apiVersion: v1
kind: ConfigMap
metadata:
name: foo
data:
ACCOUNTS: "1,2,3,5,4,6,7"
---
apiVersion: v1
kind: Pod
metadata:
name: foobar
spec:
containers:
- command:
- push
name: container
image: redis_dump
envFrom:
- configMapRef:
name: foo
optional: false
env:
- name: PORT
valueFrom:
secretKeyRef:
key: port
name: threescale-backend-redis-rhoam
- name: URI
valueFrom:
secretKeyRef:
key: uri
name: threescale-backend-redis-rhoam
restartPolicy: Never
21 changes: 21 additions & 0 deletions saas-to-rhoam/redis_dump/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tool.poetry]
name = "redis_dump"
version = "0.1.0"
description = ""
authors = ["Jim Fitzpatrick <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.10"
redis = "^4.5.4"

[tool.poetry.dev-dependencies]
pytest = "^5.2"

[tool.poetry.scripts]
pull = "redis_dump.main:pull"
push = "redis_dump.main:push"
seed = "redis_dump.main:seed"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
1 change: 1 addition & 0 deletions saas-to-rhoam/redis_dump/redis_dump/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.1.0'
Loading

0 comments on commit 6a3c480

Please sign in to comment.