generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 528
/
Copy pathmkdocs-generate-conformance.py
206 lines (150 loc) · 6.65 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# 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 io import StringIO
from mkdocs import plugins
from mkdocs.structure.files import File
import yaml
import pandas
from fnmatch import fnmatch
import glob
import os
log = logging.getLogger(f'mkdocs.plugins.{__name__}')
@plugins.event_priority(100)
def on_files(files, config, **kwargs):
log.info("generating conformance")
vers = getConformancePaths()
# Iterate over the list of versions. Exclude the pre 1.0 versions.
for v in vers[3:]:
confYamls = getYaml(v)
releaseVersion = v.split(os.sep)[-2]
file = generate_conformance_tables(confYamls, releaseVersion, config)
if file:
existing_file = files.get_file_from_path(file.src_uri)
if existing_file:
# Remove the existing file that is likely present in the
# repository
files.remove(existing_file)
# Add the generated file to the site
files.append(file)
return files
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. Implementations that submit conformance reports with skipped tests won't appear in the tables.
"""
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, mkdocsConfig):
# Enable Pandas copy-on-write
pandas.options.mode.copy_on_write = True
gateway_tls_table = pandas.DataFrame()
gateway_grpc_table = pandas.DataFrame()
if currVersion != 'v1.0.0':
gateway_http_table = generate_profiles_report(reports, 'GATEWAY-HTTP',currVersion)
gateway_grpc_table = generate_profiles_report(reports, 'GATEWAY-GRPC',currVersion)
gateway_grpc_table = gateway_grpc_table.rename_axis('Organization')
gateway_tls_table = generate_profiles_report(reports, 'GATEWAY-TLS',currVersion)
gateway_tls_table = gateway_tls_table.rename_axis('Organization')
mesh_http_table = generate_profiles_report(reports, 'MESH-HTTP',currVersion)
else:
gateway_http_table = generate_profiles_report(reports, "HTTP",currVersion)
mesh_http_table = generate_profiles_report(reports, "MESH",currVersion)
gateway_http_table = gateway_http_table.rename_axis('Organization')
mesh_http_table = mesh_http_table.rename_axis('Organization')
versionFile = ".".join(currVersion.split(".")[:2])
entries = gateway_http_table.nunique()
if entries.Project < 3:
return
try:
f = StringIO()
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 != 'v1.0.0':
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())
file_contents = f.getvalue()
finally:
f.close()
new_file = File(
src_dir=None,
dest_dir=mkdocsConfig['site_dir'],
path=f'implementations/{versionFile}.md',
use_directory_urls=mkdocsConfig['use_directory_urls'],
)
new_file.content_string = file_contents
new_file.generated_by = f'{__name__}'
return new_file
def generate_profiles_report(reports, route,version):
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','mode', '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._4) is list:
for feat in row._4:
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", "mode":"Mode"})
if version == 'v1.0.0':
http_table = http_table.drop(columns=["Mode"])
return http_table
pathTemp = "conformance/reports/*/"
allVersions = set()
reportedImplementationsPath = set()
# 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.add(vers)
reportedImplementationsPath.add(v+"**")
return sorted(list(reportedImplementationsPath))
def getYaml(conf_path):
yamls = []
for p in glob.glob(conf_path, recursive=True):
if fnmatch(p, "*.yaml"):
x = load_yaml(p)
if 'profiles' in x:
profiles = pandas.json_normalize(
x, record_path=['profiles'], meta=["mode","implementation"], errors='ignore')
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