forked from kubernetes-sigs/gateway-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkdocs-generate-conformance.py
165 lines (117 loc) · 5.31 KB
/
mkdocs-generate-conformance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Copyright 2023 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from mkdocs import plugins
import yaml
import pandas
from fnmatch import fnmatch
import glob
import os
log = logging.getLogger('mkdocs')
@plugins.event_priority(100)
def on_pre_build(config, **kwargs):
log.info("generating conformance")
vers = getConformancePaths()
for v in vers[3:]:
confYamls = getYaml(v)
releaseVersion = v.split(os.sep)[-2]
generate_conformance_tables(confYamls, releaseVersion)
desc = """
The following tables are populated from the conformance reports [uploaded by project implementations](https://github.com/kubernetes-sigs/gateway-api/tree/main/conformance/reports). They are separated into the extended features that each project supports listed in their reports.
Implementations only appear in this page if they pass Core conformance for the resource type, and the features listed should be Extended features.
"""
warning_text = """
???+ warning
This page is under active development and is not in its final form,
especially for the project name and the names of the features.
However, as it is based on submitted conformance reports, the information is correct.
"""
def generate_conformance_tables(reports, currVersion):
gateway_tls_table = pandas.DataFrame()
gateway_grpc_table = pandas.DataFrame()
if currVersion == allVersions[-1]:
gateway_http_table = generate_profiles_report(reports, 'GATEWAY-HTTP')
gateway_grpc_table = generate_profiles_report(reports, 'GATEWAY-GRPC')
gateway_grpc_table = gateway_grpc_table.rename_axis('Organization')
gateway_tls_table = generate_profiles_report(reports, 'GATEWAY-TLS')
gateway_tls_table = gateway_tls_table.rename_axis('Organization')
mesh_http_table = generate_profiles_report(reports, 'MESH-HTTP')
else:
gateway_http_table = generate_profiles_report(reports, "HTTP")
mesh_http_table = generate_profiles_report(reports, "MESH")
gateway_http_table = gateway_http_table.rename_axis('Organization')
mesh_http_table = mesh_http_table.rename_axis('Organization')
versionFile = ".".join(currVersion.split(".")[:2])
with open('site-src/implementations/'+versionFile+'.md', 'w') as f:
f.write(desc)
f.write("\n\n")
f.write(warning_text)
f.write("\n\n")
f.write("## Gateway Profile\n\n")
f.write("### HTTPRoute\n\n")
f.write(gateway_http_table.to_markdown()+'\n\n')
if currVersion == allVersions[-1]:
f.write('### GRPCRoute\n\n')
f.write(gateway_grpc_table.to_markdown()+'\n\n')
f.write('### TLSRoute\n\n')
f.write(gateway_tls_table.to_markdown()+'\n\n')
f.write("## Mesh Profile\n\n")
f.write("### HTTPRoute\n\n")
f.write(mesh_http_table.to_markdown())
def generate_profiles_report(reports, route):
http_reports = reports.loc[reports["name"] == route]
http_reports.set_index('organization')
http_reports.sort_values(['organization', 'version'], inplace=True)
http_table = pandas.DataFrame(
columns=http_reports['organization'])
http_table = http_reports[['organization', 'project',
'version', 'extended.supportedFeatures']].T
http_table.columns = http_table.iloc[0]
http_table = http_table[1:].T
for row in http_table.itertuples():
if type(row._3) is list:
for feat in row._3:
http_table.loc[row.Index, feat] = ':white_check_mark:'
http_table = http_table.fillna(':x:')
http_table = http_table.drop(['extended.supportedFeatures'], axis=1)
http_table = http_table.rename(
columns={"project": "Project", "version": "Version"})
return http_table
pathTemp = "conformance/reports/*/"
allVersions = []
reportedImplementationsPath = []
# returns v1.0.0 and greater, since that's when reports started being generated in the comparison table
def getConformancePaths():
versions = sorted(glob.glob(pathTemp, recursive=True))
report_path = versions[-1]+"**"
for v in versions:
vers = v.split(os.sep)[-2]
allVersions.append(vers)
reportedImplementationsPath.append(v+"**")
return reportedImplementationsPath
def getYaml(conf_path):
yamls = []
for p in glob.glob(conf_path, recursive=True):
if fnmatch(p, "*.yaml"):
x = load_yaml(p)
profiles = pandas.json_normalize(
x, record_path='profiles', meta=["implementation"])
implementation = pandas.json_normalize(profiles.implementation)
yamls.append(pandas.concat([implementation, profiles], axis=1))
yamls = pandas.concat(yamls)
return yamls
def load_yaml(name):
with open(name, 'r') as file:
x = yaml.safe_load(file)
return x