Skip to content

Commit b1f8ecd

Browse files
committed
Removing scripts, updating READMEs in type-reducer and other nits
Signed-off-by: Dawid Nowak <[email protected]>
1 parent b91120b commit b1f8ecd

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

gateway-api/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ mod tests {
2828
use uuid::Uuid;
2929

3030
use crate::{
31-
apis::standard::common::GatewayAddress,
3231
apis::standard::constants::{
3332
GatewayConditionReason, GatewayConditionType, ListenerConditionReason,
3433
ListenerConditionType,
@@ -89,7 +88,6 @@ mod tests {
8988
assert!(gw.metadata.uid.is_some());
9089

9190
let gw_status = GatewayStatus {
92-
addresses: Some(vec![GatewayAddress::default()]),
9391
listeners: Some(vec![GatewayStatusListeners {
9492
name: "tcp".into(),
9593
attached_routes: 0,
@@ -111,6 +109,7 @@ mod tests {
111109
status: "True".to_string(),
112110
type_: GatewayConditionType::Programmed.to_string(),
113111
}]),
112+
..Default::default()
114113
};
115114

116115
gw = Api::default_namespaced(client)

type-reducer/README.md

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,48 @@
1-
# ast_parser
1+
## Type Reduction
22

3-
Usage :
3+
This application will parse Kopium generated files and will try to identify the types that are potentially the same. The new types will be saved into "common" mod with a new, user selected name and the code will be updated with the new names.
4+
The overall approach has three steps.
45

5-
Will create common types and create APIs using those. Additionally will output the mapped types to "./mapped_types_to_names.txt" and "./mapped_names.txt" files. ./mapped_names.txt can be use as a source to provide some customer/more sensible substitutes for type names in step two.
6+
### 1. Reducing leaf types.
7+
The algorithm will try to identify the structs that can be reduced or "leaf" types. Leaf types are the types with fields which are simple types (String, u32, u64) or types reduced in the previous steps. As the output, the application will produce files with "mappings".
68

7-
1. Step 1 - Reducing leaf types, all structs that only simple types or arrays of simple types such as String, u32, etc.
8-
```bash
9-
cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed --previous-pass-derived-type-names mapped_names.txt --current-pass-derived-type-prefix=Common
10-
```
9+
### 2. Provide new names
10+
The mappings from step 1 should be used to provide new, user selected names.
1111

12-
2. Step 2 (Optional)
13-
Create a file with new type names. The file format is like this:
14-
```
15-
# type_name->new_type_name where type_name is taken from ./mapped_names.txt
1612

17-
CommonAddressesGateway->AddressGateway
18-
CommonBackendFiltersMirrorRefRequestRouteRules->MirrorBackendRef
19-
CommonExtensionFiltersRefRouteRules->FilterExtensionRef
20-
CommonFiltersHeaderModifierRouteRules->HeaderModifier
21-
CommonGatewayKindsListeners->ListenerRouteKinds
22-
CommonParentRoute->ParentRef
13+
##### Before the change.
14+
This shows that all above Kopium generated types are the same and we should replace "GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd" with a more meaningful name.
2315

24-
```
25-
3. Step 3 (Optional)
16+
| Kopium generated names | | User selected name|
17+
|------------------------|--|-------------------|
18+
|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|
19+
|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierSet|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|
20+
|GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierAdd|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|
21+
|GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierSet|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|
22+
|HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|
23+
|HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierSet|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|
24+
|HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierAdd|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|
25+
|HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierSet|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|
2626

27-
Will read a file specified by --with-substitute-names and try to use those names as substitutions when modifying the APIs.
2827

29-
```bash
30-
cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed --with-substitute-names ./custom_mapped_names.txt
31-
```
28+
##### After the change.
29+
On subsequent runs, the algorithm will use HTTPHeader as new name for all those types.
3230

33-
4. Step 4(Optional) - Reducing types further
3431

35-
```bash
36-
cargo run -- --apis-dir ../gateway-api/src/apis/processed --out-dir ../gateway-api/src/apis/processed --previous-pass-derived-type-names mapped_names.txt --current-pass-derived-type-prefix=Common
37-
```
32+
| Kopium generated names | | User selected name|
33+
|------------------------|--|-------------------|
34+
|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|->|HTTPHeader|
35+
|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierSet|->|HTTPHeader|
36+
|GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierAdd|->|HTTPHeader|
37+
|GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierSet|->|HTTPHeader|
38+
|HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|->|HTTPHeader|
39+
|HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierSet|->|HTTPHeader|
40+
|HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierAdd|->|HTTPHeader|
41+
|HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierSet|->|HTTPHeader|
42+
43+
44+
### 3. Re-run the application to produce the code with desired types
45+
46+
47+
Steps 1 to 3 should be repeated until no similar types are detected. Check [update.sh](../update.sh) for more details on how to use it.
3848

type-reducer/reduce_types.sh

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

0 commit comments

Comments
 (0)