@@ -8,253 +8,26 @@ The goal of this library is to provide a reusable and generic way of exposing k8
88This enables UIs that need to consume these objects to do so in a developer-friendly way, leveraging a rich ecosystem.
99
1010## Overview
11- GQL Gateway expects a directory as input to watch for files containing OpenAPI specifications with resources.
1211
13- Each file in that directory will correspond to a KCP workspace (or API server).
12+ This repository contains two main components:
13+ - [ Listener] ( ./docs/listener.md ) : watches a cluster and stores its openAPI spec in a directory.
14+ - [ Gateway] ( ./docs/gateway.md ) : exposes the openAPI spec as a GraphQL endpoints.
1415
15- For each file it will create a separate URL like ` /<workspace-name>/graphql ` which will be used to query the resources of that workspace.
16+ ## Quickstart
1617
17- It will be watching for changes in the directory and update the schema accordingly .
18+ If you want to get started quickly, you can follow the [ quickstart guide ] ( ./docs/quickstart.md ) .
1819
19- ## Usage
20-
21- ### OpenAPI Spec
22-
23- You can run the gateway using the existing generic OpenAPI spec file which is located in the ` ./definitions ` directory.
24-
25- (Optional) Or you can generate a new one from your own cluster by running the following command:
26- ``` shell
27- kubectl get --raw /openapi/v2 > filename
28- ```
29- ### Start the Service
30- ``` shell
31- task start
32- ```
33- OR
34- ``` shell
35- go run main.go start --watched-dir=./definitions
36- # where ./definitions is the directory containing the OpenAPI spec files
37- ```
38-
39- After service start you can access the GraphQL playground.
40- All addresses correspond the content of the watched directory and can be found in the terminal output.
41-
42- For example, we have two KCP workspaces: ` root ` and ` root:alpha ` , for each of them we have a separate spec file in the ` ./definitions ` directory.
43-
44- Then we will have two URLs:
45- - ` http://localhost:3000/root/graphql `
46- - ` http://localhost:3000/root:alpha/graphql `
47-
48- Open the URL in the browser and you will see the GraphQL playground.
49-
50- ### Authorization
51-
52- To send the request, you can attach the ` Authorization ` header with the token from kubeconfig ` users.user.token ` :
53- ``` shell
54- {
55- " Authorization" : " 5f89bc76-c5b8-4d6f-b575-9ca7a6240bca"
56- }
57- ```
58-
59- ** If you skip that header, service will try to use a runtime client with current context.(` kubectl config current-context ` )**
60-
61- P.S. Skipping the header works with both API server and KCP workspace.
62-
63- #### Sending queries
64-
65- ##### Create a Pod:
66-
67- ``` shell
68- mutation {
69- core {
70- createPod(
71- namespace: " default" ,
72- object: {
73- metadata: {
74- name: " my-new-pod" ,
75- labels: {
76- app: " my-app"
77- }
78- }
79- spec: {
80- containers: [
81- {
82- name: " nginx-container"
83- image: " nginx:latest"
84- ports: [
85- {
86- containerPort: 80
87- }
88- ]
89- }
90- ]
91- restartPolicy: " Always"
92- }
93- }
94- ) {
95- metadata {
96- name
97- namespace
98- labels
99- }
100- spec {
101- containers {
102- name
103- image
104- ports {
105- containerPort
106- }
107- }
108- restartPolicy
109- }
110- status {
111- phase
112- }
113- }
114- }
115- }
116- ```
117-
118- ##### Get the created Pod:
119- ``` shell
120- query {
121- core {
122- Pod(name:" my-new-pod" , namespace:" default" ) {
123- metadata {
124- name
125- }
126- spec{
127- containers {
128- image
129- ports {
130- containerPort
131- }
132- }
133- }
134- }
135- }
136- }
137- ```
138-
139- ##### Delete the created Pod:
140- ``` shell
141- mutation {
142- core {
143- deletePod(
144- namespace: " default" ,
145- name: " my-new-pod"
146- )
147- }
148- }
149- ```
150- ### Components Overview
151-
152- #### Workspace manager
153-
154- Holds the logic for watching a directory, triggering schema generation, and binding it to an HTTP handler.
155-
156- * P.S. We are going to have an Event Listener that will watch the KCP workspace and write the OpenAPI spec into that directory.*
157-
158- #### Gateway
159-
160- Is responsible for the conversion from OpenAPI spec into the GraphQL schema.
161-
162- #### Resolver
163-
164- Holds the logic of interaction with the cluster.
165-
166- ### Testing
167-
168- ``` shell
169- task test
170- ```
171-
172- If you want to run single test, you need to export a KUBEBUILDER_ASSETS environment variable:
173- ``` shell
174- KUBEBUILDER_ASSETS=$( pwd) /bin/k8s/$DIR_WITH_ASSETS
175- # where $DIR_WITH_ASSETS is the directory that contains binaries for your OS.
176- ```
177- P.S. You can also integrate it within your IDE run configuration.
178-
179- Then you can run the test:
180- ```
181-
182-
183- You can also check the coverage:
184- ```shell
185- task coverage
186- ```
187- P.S. If you want to exclude some files from the coverage report, you can add them to the ` .testcoverage.yml ` file.
188-
189-
190-
191- ### Linting
192-
193- ``` shell
194- task lint
195- ```
196-
197- ### Subscriptions
198-
199- To subscribe to events, you should use the SSE (Server-Sent Events) protocol.
200-
201- Since GraphQL playground doesn't support it, you should use curl.
202-
203- For instance, to subscribe to a change of a displayName field in a specific account in root workspace, you can run the following command:
204- ``` shell
205- curl \
206- -H " Accept: text/event-stream" \
207- -H " Content-Type: application/json" \
208- -H " Authorization: 7f41d4ea-6809-4714-b345-f9281981b2dd" \
209- -d ' {"query": "subscription { core_openmfp_org_account(name: \"root-account\") { spec { displayName }}}"}' \
210- http://localhost:8080/root/graphql
211- ```
212- Fields that will be listened are defined in the graphql query within the ` {} ` brackets.
213-
214- P.S. Don't forget to replace the ` Authorization ` header with the token from the kubeconfig.
215-
216- If you want to listen to all fields, you can set ` subscribeToAll ` to ` true ` :
217- ``` shell
218- curl \
219- -H " Accept: text/event-stream" \
220- -H " Content-Type: application/json" \
221- -H " Authorization: 7f41d4ea-6809-4714-b345-f9281981b2dd" \
222- -d ' {"query": "subscription { core_openmfp_org_account(name: \"root-account\", subscribeToAll: true) { metadata { name } }}"}' \
223- http://localhost:8080/root/graphql
224- ```
225- P.S. Note, that only fields specified in ` {} ` brackets will be returned.
226-
227- To subscribe to all accounts in the root workspace, you can run the following command:
228- ``` shell
229- curl \
230- -H " Accept: text/event-stream" \
231- -H " Content-Type: application/json" \
232- -H " Authorization: 7f41d4ea-6809-4714-b345-f9281981b2dd" \
233- -d ' {"query": "subscription { core_openmfp_org_accounts { spec { displayName }}}"}' \
234- http://localhost:8080/root/graphql
235- ```
20+ ## Contributing
21+ Please refer to the [ contributing] ( ./docs/contributing.md ) section for instructions on how to contribute to OpenMFP.
23622
23723## Releasing
23824
239- The release is performed automatically through a GitHub Actions Workflow. The resulting website will be available as github page under the following URL: https://openmfp.github.io/openmfp.org/
240-
241- ## Requirements
242-
243- Please refer [ README.md#usage] ( README.md#usage ) for the requirements.
25+ The release is performed automatically through a GitHub Actions Workflow. The resulting website will be available as Github page under the following URL: https://openmfp.github.io/openmfp.org/
24426
24527## Security / Disclosure
24628
24729If you find any bug that may be a security problem, please follow our instructions at [ in our security policy] ( https://github.com/openmfp/openmfp.org/security/policy ) on how to report it. Please do not create GitHub issues for security-related doubts or problems.
24830
249- ## Contributing
250-
251- Please refer to the [ CONTRIBUTING.md] ( CONTRIBUTING.md ) file in this repository for instructions on how to contribute to OpenMFP.
252-
253- ## Code of Conduct
254-
255- Please refer to the [ CODE_OF_CONDUCT.md] ( CODE_OF_CONDUCT.md ) file in this repository for information on the expected Code of Conduct for contributing to OpenMFP.
256-
257-
25831## Licensing
25932
26033Copyright 2025 SAP SE or an SAP affiliate company and OpenMFP contributors. Please see our [ LICENSE] ( LICENSE ) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [ via the REUSE tool] ( https://api.reuse.software/info/github.com/openmfp/openmfp.org ) .
0 commit comments