Skip to content

Commit 2a685b3

Browse files
committed
Update kubernetes templates and README instructions
Signed-off-by: Andres Tobon <andrest2455@gmail.com>
1 parent fe90fdf commit 2a685b3

File tree

6 files changed

+86
-12
lines changed

6 files changed

+86
-12
lines changed

charts/lfx-v2-project-service/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ spec:
2121
image: linuxfoundation/lfx-v2-project-service:0.1.0
2222
securityContext:
2323
allowPrivilegeEscalation: false
24-
imagePullPolicy: Never # todo: fix this
24+
imagePullPolicy: Never # The image is expected to exist locally with the same name and tag. It is not deployed to a registry.
2525
env:
2626
- name: NATS_URL
2727
value: {{.Values.nats.url}}

charts/lfx-v2-project-service/templates/ingressroute.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ spec:
1313
routes:
1414
- kind: Rule
1515
match: >-
16-
Host(`lfx-api.k8s.orb.local`) && PathPrefix(`/query/`)
16+
Host(`lfx-api.k8s.orb.local`)
1717
priority: 10
18-
middlewares:
19-
- name: heimdall
18+
# TODO: add heimdall middleware once it is working - currently it causes a 403
19+
# middlewares:
20+
# - name: heimdall
2021
services:
2122
- kind: Service
2223
name: lfx-v2-project-service
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright The Linux Foundation and each contributor to LFX.
2+
# SPDX-License-Identifier: MIT
3+
---
4+
apiVersion: jetstream.nats.io/v1beta2
5+
kind: KeyValue
6+
metadata:
7+
name: projects
8+
namespace: lfx
9+
spec:
10+
bucket: projects
11+
history: 20
12+
storage: file
13+
maxBytes: 2048
14+
compression: true

charts/lfx-v2-project-service/templates/ruleset.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ spec:
1818
routes:
1919
- path: /projects
2020
- path: /projects/:id
21-
path_params:
22-
- name: id
23-
type: string
2421
execute:
2522
- authenticator: authelia
2623
- authenticator: anonymous_authenticator

charts/lfx-v2-project-service/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
nats:
66
# url is the URL of the NATS server
77
url: nats://nats.lfx.svc.cluster.local:4222
8+
projects_kv_bucket_name: projects

cmd/project-api/README.md

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ This service handles the following NATS subjects:
4343

4444
### Prerequisites
4545

46-
This service uses the [GOA Framework](https://goa.design/) for API generation. You'll need to install GOA before building the service.
46+
- [**Go**](https://go.dev/): the service is built with the Go programming language [[Install](https://go.dev/doc/install)]
47+
- [**Kubernetes**](https://kubernetes.io/): used for deployment of resources [[Install](https://kubernetes.io/releases/download/)]
48+
- [**Helm**](https://helm.sh/): used to manage kubernetes applications [[Install](https://helm.sh/docs/intro/install/)]
49+
- [**NATS**](https://docs.nats.io/): used to communicate with other LFX V2 services [[Install](https://docs.nats.io/running-a-nats-service/introduction/installation)]
50+
- [**GOA Framework**](https://goa.design/): used for API code generation
4751

48-
#### Installing GOA Framework
52+
#### GOA Framework
4953

5054
Follow the [GOA installation guide](https://goa.design/docs/2-getting-started/1-installation/) to install GOA:
5155

@@ -77,31 +81,88 @@ This command generates:
7781
- Service interfaces and types
7882
- Transport layer implementations
7983

80-
#### 2. Development Workflow
84+
#### 2. Set up resources and external services
85+
86+
The service relies on some resources and external services being spun up prior to running this service.
87+
88+
- [NATS service](https://docs.nats.io/): ensure you have a NATS server instance running and set the `NATS_URL` environment variable with the URL of the server
89+
90+
```bash
91+
export NATS_URL=nats://nats.lfx.svc.cluster.local:4222
92+
```
93+
94+
- [NATS key-value bucket](https://docs.nats.io/nats-concepts/jetstream/key-value-store): once you have a NATS service running, you need to create a bucket used by the project service.
95+
96+
```bash
97+
# if using the nats cli tool
98+
nats kv add projects
99+
```
100+
101+
#### 3. Export environment variables
102+
103+
|Environment Variable Name|Description|Default|Required|
104+
|-----------------------|--------------------|-----------|-----|
105+
|PORT|the port for http requests to the project service API|8080|false|
106+
|NATS_URL|the URL of the nats server instance|nats://localhost:4222|false|
107+
|LFX_ENVIRONMENT|the LFX environment (enum: prod, stg, dev)|dev|false|
108+
|LOG_LEVEL|the log level for outputted logs|info|false|
109+
|LOG_ADD_SOURCE|whether to add the source field to outputted logs|false|false|
110+
111+
#### 4. Development Workflow
81112

82113
1. **Make design or implementation changes**: Edit files in the `design/` directory for design changes, and edit the other files for implementation changes.
114+
83115
2. **Regenerate code**: Run `make apigen` after design changes
116+
84117
3. **Build the service**:
85118
```bash
86119
make build
87120
```
88-
4. **Run the service** (for development):
121+
4. **Run the service**:
89122
```bash
90123
make run
91124
92-
# enable debug logging
125+
# or run with debug logs enabled
93126
make debug
127+
128+
# or run with the go command to set custom flags
129+
# -bind string interface to bind on (default "*")
130+
# -d enable debug logging (default false)
131+
# -p string listen port (default "8080")
132+
go run
94133
```
95134
5. **Run tests**:
96135
```bash
97136
make test
137+
138+
# or run go test to set custom flags
139+
go test . -v
98140
```
99141

142+
6. **Docker build + K8**
143+
144+
```bash
145+
# Build the dockerfile (from the root of the repo)
146+
docker build -t lfx-v2-project-service:<release_number> .
147+
148+
# Install the helm chart for the service into the lfx namespace (from the root of the repo)
149+
helm install lfx-v2-project-service ./charts/lfx-v2-project-service/ -n lfx
150+
151+
# Once you have already installed the helm chart and need to just update it, use the following command (from the root of the repo):
152+
helm upgrade lfx-v2-project-service ./charts/lfx-v2-project-service/ -n lfx
153+
154+
# Check that the REST API is accessible by hitting the `/livez` endpoint (you should get a response of OK if it is working):
155+
#
156+
# Note: replace the hostname with the host from ./charts/lfx-v2-project-service/ingressroute.yaml
157+
curl http://lfx-api.k8s.orb.local/livez
158+
```
159+
100160
### Add new API endpoints
101161
Note: follow the [Development Workflow](#2-development-workflow) section on how to run the service code
102162
1. **Update design files**: Edit project file in `design/` to include specicification of the new endpoint with all of its supported parameters, responses, and errors, etc.
103163
2. **Regenerate code**: Run `make apigen` after design changes
104164
3. **Implement code**: Implement the new endpoint in `service_endpoint.go`. Follow similar standards of the other endpoint methods. Include tests for the new endpoint in `service_endpoint_test.go`.
165+
4. **Update heimdall ruleset**: Ensure that `/charts/lfx-v2-project-service/templates/ruleset.yaml` has the route and method for the endpoint set so that authentication is configured when deployed
105166

106167
### Add new message handlers
107168
Note: follow the [Development Workflow](#2-development-workflow) section on how to run the service code

0 commit comments

Comments
 (0)