Skip to content

Commit 4eb298f

Browse files
committed
operator refactor to use uv and ops
1 parent 24e090b commit 4eb298f

11 files changed

Lines changed: 170 additions & 89 deletions

File tree

DEVEL.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

README.md

Lines changed: 79 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,78 +20,116 @@
2020

2121
# Apache OpenServerless Operator
2222

23-
NOTE: this readme is outdated and needs to be updated, not everyhing is still relevant.
23+
In this README we explain how to do development with the Operator
2424

25-
---
25+
The operator is a collection of modules managed with ops.
2626

27-
In this readme there are information for developers.
27+
The operator itself is an ops plugin to invoke some of functions from the command line.
2828

29-
We describe how to build and test the operator in our development environment
29+
To work with it, install ops and clone the source code from the top level, so you get the operator code under `openserverless/operator-op`
3030

31-
Please refer to the [website](https://openserverless.apache.org) for user information.
31+
```
32+
curl -sL bit.ly/get-ops | bash
33+
git clone https://github.com/apache/openserverless --recurse-submodules
34+
cd openserverless
35+
```
3236

33-
## How to build and use an operator image
37+
To be able to work with the operator you need a Kubernetes cluster and a Working configuration.
3438

35-
Ensure you have satisfied the prerequisites below. Most notably, you need to use our development virtual machine and you
36-
need write access to a GitHub repository.
39+
You can easily create one with kind:
3740

38-
Once you have satisfied the prerequisites, you can build an image you can use in the development machine.
41+
```
42+
# destroy the old one
43+
ops op clu kind destroy
44+
# create a new cluster
45+
ops op clu kind create
46+
```
3947

40-
Build an image with:
48+
If you want to use kubectl directory use `ops util kubeconfig`
49+
to export the kind configurat to `~/.kube/config`. WARNING it overwrites yout existing one.
4150

42-
```shell
43-
task build
51+
## Configuration
52+
53+
You need a full configuration to be able to work with the operator.
54+
55+
You can create an actual configuration on the cluster skipping the launch of the operator:
56+
57+
For example this is a config of slim mode:
58+
59+
```
60+
# configure slim mode for example
61+
ops config slim
62+
# configure
63+
ops setup kubernetes configure
4464
```
4565

46-
Please note that it will build the image locally and push in an internal registry, even if it is name is
47-
`ghcr.io/${GITHUB_USER}/openserverless-operator`.
66+
## Execute the operator as a cli plugin
4867

49-
To be able to build, the task `build` will commit and push all your changes and then build the operator from the public
50-
sources in your local k3s.
68+
Many modules are now executable as `ops op nuvolaris` commands.
5169

52-
It will also show the logs for the latest build.
70+
For example: `ops op nuv etcd`
5371

54-
You can then deploy it with:
72+
It shows the subcommand with `create [<replicas>]` and `delete`
5573

56-
```shell
57-
task deploy
74+
## Working on the cli
75+
76+
You can also test and work on the cli. Try this:
77+
78+
```
79+
ops op cli
5880
```
5981

60-
Once you have finished with development you can create a public image with `task publish` that will publish the tag and
61-
trigger a creation of the image.
82+
Initialize the configuration:
6283

63-
## Prerequisites
84+
```
85+
import nuvolaris.operator_util as operator_util
86+
owner = kube.get("wsk/controller")
87+
operator_util.config_from_spec(owner['spec'])
88+
```
6489

65-
1. Please set up and use a development VM [as described here](https://github.com/apache/openserverless)
90+
Create the components:
6691

67-
2. With VSCode, access the development VM, open the workspace `openserverless/openserverless.code-workspace` and then
68-
open a terminal with `operator` subproject: this will enable the `nix` environment with direnv (provided by the VM).
92+
```
93+
import nuvolaris.etcd as etcd
94+
msg = etcd.create(owner)
95+
```
6996

70-
3. Create a fork of `github.com/apache/openserverless-operator`
97+
## How to publish the operator image
7198

72-
4. Copy .env.dist in .env and put your GitHub username in it
99+
When you are satisfied with your development you can publish the image.
73100

74-
5. Since the build requires you push your sources in your repo, you need the credentials to access it. The fastest way
75-
is
76-
to [create a personal token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
101+
First, install [task](http://taskfile.dev/docs/installation).
77102

78-
6. Now set up a remote to access your repo and set it as your default upstream branch.
103+
You need to setup some environment variables. Copy .env.dist in .env and put your GitHub username in it
79104

80-
```
81-
git remote add fork https://<GITHUB_USERNAME>:<GITHUB_TOKEN>@github.com/<GITHUB_USERNAME>/openserverless-operator
82-
git branch -u https://github.com/<GITHUB_USERNAME>/openserverless-operator
105+
Since the build requires you push your sources in your repo, you need the credentials to access it. The fastest way is
106+
to [create a personal token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
107+
108+
Build an image with:
109+
110+
```shell
111+
task build
83112
```
84113

85-
That's it. Now you can use `task build` to build the image.
114+
Please note that it will build the image locally and push in an internal registry, even if it is name is
115+
`ghcr.io/${GITHUB_USER}/openserverless-operator`.
116+
117+
To be able to build, the task `build` will commit and push all your changes and then build the operator from the public
118+
sources in your local k3s.
86119

87-
7. Deploy the operator
120+
It will also show the logs for the latest build.
88121

89-
To deploy a testing configuration of the Apache OpenServerless operator execute the command
122+
You can then deploy it with:
90123

91124
```shell
92-
task all
125+
task deploy
93126
```
94127

95-
The operator instance will be configured applying the `test/k3s/whisk.yaml` template.
96-
All the components are activated except TLS and MONITORING.
128+
Once you have finished with development you can create a public image with `task publish` that will publish the tag and
129+
trigger a creation of the image.
97130

131+
Once the image is publicly available you have to put in in `opsroot.json` to use it:
132+
133+
```
134+
https://github.com/apache/openserverless-task/blob/9d2227b87196be9b487673d4d1f8202c2ec354f2/opsroot.json#L8
135+
```

clusters/kind/kind.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# three node (two workers) cluster config
2+
kind: Cluster
3+
apiVersion: kind.x-k8s.io/v1alpha4
4+
nodes:
5+
- role: control-plane
6+
- role: worker
7+
- role: worker

clusters/kind/opsfile.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ tasks:
3232
create:
3333
desc: create
3434
cmds:
35-
- kind create cluster --name "{{.NAME}}"
36-
- kind get kubeconfig --name="{{.NAME}}" >{{.KUBEFILE}}
35+
- kind create cluster --name "{{.NAME}}" #--config kind.yaml
36+
- kind get kubeconfig --name="{{.NAME}}" >{{.KUBEFILE}}
3737
- cp "{{.KUBEFILE}}" "$OPS_TMP/kubeconfig"
3838
- kubectl --namespace=ingress-nginx --kubeconfig "{{.KUBEFILE}}" apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
3939

nuvolaris/etcd.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
from nuvolaris.util import get_etcd_replica
2929

30-
3130
def create(owner=None):
3231
logging.info("create etcd")
3332
data = util.get_etcd_config_data()
@@ -173,4 +172,23 @@ def patch(status, action, owner=None):
173172
if action == 'create':
174173
status['whisk_create']['etcd']='error'
175174
else:
176-
status['whisk_create']['etcd']='error'
175+
status['whisk_create']['etcd']='error'
176+
177+
import fire
178+
from nuvolaris.operator_util import LoadConfig
179+
180+
class Etcd(LoadConfig):
181+
def create(self, replicas: int = 0):
182+
"""
183+
[<replicas>]
184+
"""
185+
if replicas > 0:
186+
print("setting replicas to:", replicas)
187+
cfg.put("etcd.replicas", replicas)
188+
print(create(self.owner))
189+
190+
def delete(self):
191+
print(delete(self.owner))
192+
193+
if __name__ == "__main__":
194+
fire.Fire(Etcd)

nuvolaris/operator_util.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
#
18-
import logging
18+
import sys, logging
1919
import nuvolaris.openwhisk as openwhisk
2020
import nuvolaris.kube as kube
2121
import nuvolaris.userdb_util as userdb
@@ -132,4 +132,15 @@ def patch_operator_status(status,component, status_code):
132132
logging.debug(f"patching component {component} with code = {status_code} from event handler {status}")
133133
status['whisk_create'][component]=status_code
134134
except Exception as e:
135-
logging.error('*** failed to patch_operator_status: %s' % e)
135+
logging.error('*** failed to patch_operator_status: %s' % e)
136+
137+
138+
# base class to load config from the kubernetes cluster
139+
class LoadConfig:
140+
def __init__(self):
141+
self.owner = kube.get("wsk/controller")
142+
if not self.owner:
143+
print("cannot find a config in kubernetes\nplease use ops setup kubernetes configure")
144+
sys.exit(1)
145+
spec = self.owner.get("spec")
146+
config_from_spec(spec)

nuvolaris/opsfile.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: '3'
2+
3+
4+
tasks:
5+
6+
etcd:
7+
silent: true
8+
desc: etcd
9+
dir: ..
10+
cmds:
11+
- uv run nuvolaris/etcd.py {{.CLI_ARGS}}

nuvolaris/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import nuvolaris.kube as kube
3434
import nuvolaris.template as template
3535

36+
3637
# Implements truncated exponential backoff from
3738
# https://cloud.google.com/storage/docs/retry-strategy#exponential-backoff
3839
def nuv_retry(deadline_seconds=120, max_backoff=5):
@@ -842,4 +843,3 @@ def get_registry_config_data():
842843
registry_affinity_tolerations_data(data)
843844
return data
844845

845-

opsfile.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,27 @@ vars:
2424

2525
tasks:
2626

27+
setup:
28+
silent: true
29+
desc: setup the environment
30+
cmds:
31+
- uv venv
32+
- uv pip install -r pyproject.toml
33+
2734
cli:
2835
silent: true
29-
desc: run cli commands
36+
desc: launch a cli for interactive development
3037
cmds:
3138
- |
3239
export IPYTHONDIR="$(pwd)"
3340
export PYTHONPATH="$(pwd)"
3441
uv run ipython
3542
36-
setup:
37-
silent: true
38-
desc: setup the environment
39-
cmds:
40-
- uv venv
41-
- uv pip install -r pyproject.toml
4243
4344
clusters:
4445
silent: true
45-
desc: setup the environment
46+
desc: install clusters
47+
48+
nuvolaris:
49+
silent: true
50+
desc: install nuvolaris services

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dependencies = [
4141
"redis>=5.0.4,<6",
4242
"bcrypt>=4.2.1,<5",
4343
"python-dotenv>=1.1.1",
44+
"fire>=0.7.1",
4445
]
4546

4647
[project.scripts]

0 commit comments

Comments
 (0)