Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into laurent/refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentluce committed Oct 17, 2024
2 parents dee81b3 + fe5a044 commit 312c730
Show file tree
Hide file tree
Showing 14 changed files with 317 additions and 135 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
bin/
.idea
6 changes: 4 additions & 2 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ jobs:
- name: Validate that the boutique demo is up and running
run: |
set -x
# Check that the four baseline service pods are running and ready
while [ $(kubectl get pods -n baseline --no-headers -o custom-columns=NAMESPACE:metadata.namespace,POD:metadata.name,PodIP:status.podIP,READY-true:status.containerStatuses[*].ready | grep "true" | wc -l) -ne 4 ]
do
echo "Waiting for baseline pods to run..."
echo "Waiting for baseline pods to run, iteration number $c..."
kubectl get pods -n baseline -o custom-columns=NAMESPACE:metadata.namespace,POD:metadata.name,PodIP:status.podIP,READY-true:status.containerStatuses[*].ready
((c++)) && ((c==12)) && exit 1
sleep 10
done
apps=$(kubectl get pods -n baseline -o custom-columns=:metadata.labels.app | tr " " "\n" | sort -g | tr "\n" " " | xargs)
echo "All baseline pods are running and ready."
apps=$(kubectl get pods -n baseline -o jsonpath='{.items[*].metadata.labels.app\.kubernetes\.io/name}')
echo ${apps}
if [ "${apps}" != "cartservice frontend postgres productcatalogservice" ]; then exit 1; fi
Expand Down
77 changes: 76 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,76 @@
# kardinal-operator
# Kardinal Operator

Implementation of [Kardinal](https://github.com/kurtosis-tech/kardinal) as a K8S Operator.

## Development

Minikube + K8S manifest deployed. K8S context set to your local cluster.
```
make install (to install the CRDs into the cluster)
```

The following three commands are commonly used during development:

```
make lint (Run golangci linter. Can also be configured inside your IDE.)
make test (Run tests against local cluster)
make run (Run operator against your local cluster)
```

Manage custom resources with kubectl:

```yaml
apiVersion: core.kardinal.dev/v1
kind: Flow
metadata:
labels:
app.kubernetes.io/name: kardinal
app.kubernetes.io/managed-by: kustomize
name: flow-test
namespace: baseline
spec:
service: frontend
image: kurtosistech/frontend:demo-frontend
```
```
# Create a flow
kubectl create -f ./ci/flow-test.yaml

# Delete a flow
kubectl delete -f ./ci/flow-test.yaml

# Get all flows in namespace
kubectl get flows -n baseline

# Describe a flow by its name
kubectl describe flows flow-test -n baseline
```

Deploy the operator inside the cluster
```
make deploy (when you want to test it inside the cluster)
```

## Update the CRDs API

1. Read [this document][api-design-doc] to follow the design rules.
2. The CRDs API files are inside the `./api/core/v1` folder.
3. You can edit the `flow` API for example:
1. Add, update or remove fields in the `FlowSpec` inside the `flow_types.go` file. Don't forget to add the json tags.
2. Run `make manifests` to include your changes in the auto generated `./config/crd/bases/core.kardinal.dev_flows.yaml` manifest file.
3. Update the spec example inside `./config/samples/core_v1_flow.yaml`
4. If you are adding a new CRD make sure its schema has been added in the `init` function in the `./cmd/main.go` file


## Update the RBAC permissions

1. Read [this document][rbac-markers-doc] to understand what are the RBAC markers and how to compose them.
2. Add, update or remove the RBAC markers, for instance the `flow` controller:
1. Open the flow controller file `./internal/controller/core/flow_controller.go`
2. Edit the markers inside of it.
3. Run `make manifests` to include your changes in the auto generated `./config/rbac/role.yaml` manifest file.
4. NOTE: If you receive an error, please run the specified command in the error and re-run make manifests.

[api-design-doc]: https://book.kubebuilder.io/cronjob-tutorial/api-design
[rbac-markers-doc]: https://book.kubebuilder.io/reference/markers/rbac
36 changes: 0 additions & 36 deletions api/v1/groupversion_info.go

This file was deleted.

11 changes: 11 additions & 0 deletions ci/flow-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: core.kardinal.dev/v1
kind: Flow
metadata:
labels:
app.kubernetes.io/name: kardinal
app.kubernetes.io/managed-by: kustomize
name: flow-test
namespace: baseline
spec:
service: frontend
image: kurtosistech/frontend:demo-frontend
92 changes: 23 additions & 69 deletions ci/obd-demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ kind: Deployment
metadata:
name: cartservice-v1
labels:
app: cartservice
version: v1
app.kubernetes.io/name: cartservice
spec:
selector:
matchLabels:
app: cartservice
version: v1
app.kubernetes.io/name: cartservice
template:
metadata:
labels:
app: cartservice
version: v1
app.kubernetes.io/name: cartservice
spec:
terminationGracePeriodSeconds: 5
containers:
Expand Down Expand Up @@ -66,14 +63,13 @@ kind: Service
metadata:
name: cartservice
labels:
app: cartservice
version: v1
app.kubernetes.io/name: cartservice
annotations:
kardinal.dev.service/dependencies: "postgres:tcp"
spec:
type: ClusterIP
selector:
app: cartservice
app.kubernetes.io/name: cartservice
ports:
- name: http
port: 8090
Expand All @@ -86,18 +82,15 @@ kind: Deployment
metadata:
name: frontend-v1
labels:
app: frontend
version: v1
app.kubernetes.io/name: frontend
spec:
selector:
matchLabels:
app: frontend
version: v1
app.kubernetes.io/name: frontend
template:
metadata:
labels:
app: frontend
version: v1
app.kubernetes.io/name: frontend
annotations:
sidecar.istio.io/rewriteAppHTTPProbers: "true"
spec:
Expand Down Expand Up @@ -139,20 +132,14 @@ kind: Service
metadata:
name: frontend
labels:
app: frontend
version: v1
app.kubernetes.io/name: frontend
annotations:
kardinal.dev.service/dependencies: "productcatalogservice:http,cartservice:http"
kardinal.dev.service/plugins: |
- name: https://github.com/kurtosis-tech/free-currency-api-plugin.git
type: external
servicename: free-currency-api
args:
api_key: fca_live_VKZlykCWEiFcpBHnw74pzd4vLi04q1h9JySbVHDF
kardinal.dev.service/plugins: "jsdelivr-api"
spec:
type: ClusterIP
selector:
app: frontend
app.kubernetes.io/name: frontend
ports:
- name: http
port: 80
Expand All @@ -166,19 +153,16 @@ kind: Deployment
metadata:
name: postgres-v1
labels:
app: postgres
version: v1
app.kubernetes.io/name: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
version: v1
app.kubernetes.io/name: postgres
template:
metadata:
labels:
app: postgres
version: v1
app.kubernetes.io/name: postgres
spec:
containers:
- name: postgres
Expand Down Expand Up @@ -206,36 +190,10 @@ kind: Service
metadata:
name: postgres
labels:
app: postgres
version: v1
app.kubernetes.io/name: postgres
annotations:
kardinal.dev.service/stateful: "true"
kardinal.dev.service/plugins: |
- name: github.com/kurtosis-tech/postgres-seed-plugin
args:
seed_script: |
-- create the table
CREATE TABLE IF NOT EXISTS public.items(
id bigserial PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE,
updated_at TIMESTAMP WITH TIME ZONE,
deleted_at TIMESTAMP WITH TIME ZONE,
user_id TEXT,
product_id TEXT,
quantity INTEGER
);
INSERT INTO public.items (id, created_at, updated_at, deleted_at, user_id, product_id, quantity)
VALUES (1, '2024-08-02 13:02:07.656104 +00:00', '2024-08-02 13:02:07.656104 +00:00', null, '0494c5e0-dde0-48fa-a6d8-f7962f5476bf', '66VCHSJNUP', 1);
INSERT INTO public.items (id, created_at, updated_at, deleted_at, user_id, product_id, quantity)
VALUES (2, '2024-08-02 13:02:10.891407 +00:00', '2024-08-02 13:02:10.891407 +00:00', null, '0494c5e0-dde0-48fa-a6d8-f7962f5476bf', '2ZYFJ3GM2N', 1);
-- Set the sequence to the correct value after inserting records
SELECT setval('public.items_id_seq', (SELECT MAX(id) FROM public.items));
db_name: "cart"
db_user: "postgresuser"
db_password: "postgrespass"
kardinal.dev.service/plugins: "postgres-seed-plugin"

spec:
type: ClusterIP
Expand All @@ -245,26 +203,23 @@ spec:
targetPort: 5432
protocol: TCP
selector:
app: postgres
app.kubernetes.io/name: postgres

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: productcatalogservice-v1
labels:
app: productcatalogservice
version: v1
app.kubernetes.io/name: productcatalogservice
spec:
selector:
matchLabels:
app: productcatalogservice
version: v1
app.kubernetes.io/name: productcatalogservice
template:
metadata:
labels:
app: productcatalogservice
version: v1
app.kubernetes.io/name: productcatalogservice
spec:
terminationGracePeriodSeconds: 5
containers:
Expand Down Expand Up @@ -299,12 +254,11 @@ kind: Service
metadata:
name: productcatalogservice
labels:
app: productcatalogservice
version: v1
app.kubernetes.io/name: productcatalogservice
spec:
type: ClusterIP
selector:
app: productcatalogservice
app.kubernetes.io/name: productcatalogservice
ports:
- name: http
port: 8070
Expand All @@ -317,10 +271,10 @@ apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
kardinal.dev.service/ingress: "true"
name: ingress
spec:
ingressClassName: nginx
rules:
- host: prod.app.localhost
http:
Expand Down
3 changes: 2 additions & 1 deletion config/samples/core_v1_flow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ metadata:
app.kubernetes.io/managed-by: kustomize
name: flow-sample
spec:
# TODO(user): Add fields here
service: "frontend"
image: "kurtosistech/frontend:demo-frontend"
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ require (
github.com/onsi/gomega v1.33.1
github.com/samber/lo v1.47.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
istio.io/api v1.23.2
istio.io/client-go v1.23.2
k8s.io/api v0.31.0
k8s.io/apimachinery v0.31.0
k8s.io/client-go v0.31.0
Expand Down Expand Up @@ -55,6 +58,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
Expand Down Expand Up @@ -90,8 +94,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
istio.io/api v1.23.2 // indirect
istio.io/client-go v1.23.2 // indirect
k8s.io/apiextensions-apiserver v0.31.0 // indirect
k8s.io/apiserver v0.31.0 // indirect
k8s.io/component-base v0.31.0 // indirect
Expand Down
Loading

0 comments on commit 312c730

Please sign in to comment.