|
| 1 | +# Copyright 2023 The Kubernetes Authors. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import logging |
| 16 | +from mkdocs import plugins |
| 17 | +import yaml |
| 18 | +import pandas |
| 19 | +from fnmatch import fnmatch |
| 20 | +import glob |
| 21 | + |
| 22 | +log = logging.getLogger('mkdocs') |
| 23 | + |
| 24 | + |
| 25 | +@plugins.event_priority(100) |
| 26 | +def on_pre_build(config, **kwargs): |
| 27 | + log.info("generating conformance") |
| 28 | + |
| 29 | + yamlReports = getYaml() |
| 30 | + |
| 31 | + generate_conformance_tables(yamlReports) |
| 32 | + |
| 33 | + |
| 34 | +desc = """ |
| 35 | +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. |
| 36 | +Implementations only appear in this page if they pass Core conformance for the resource type, and the features listed should be Extended features. |
| 37 | +""" |
| 38 | + |
| 39 | +warning_text = """ |
| 40 | +???+ warning |
| 41 | +
|
| 42 | +
|
| 43 | + This page is under active development and is not in its final form, |
| 44 | + especially for the project name and the names of the features. |
| 45 | + However, as it is based on submitted conformance reports, the information is correct. |
| 46 | +""" |
| 47 | + |
| 48 | +# NOTE: will have to be updated if new (extended) features are added |
| 49 | +httproute_extended_conformance_features_list = ['HTTPRouteBackendRequestHeaderModification', 'HTTPRouteQueryParamMatching', 'HTTPRouteMethodMatching', 'HTTPRouteResponseHeaderModification', 'HTTPRoutePortRedirect', 'HTTPRouteSchemeRedirect', |
| 50 | + 'HTTPRoutePathRedirect', 'HTTPRouteHostRewrite', 'HTTPRoutePathRewrite', 'HTTPRouteRequestMirror', 'HTTPRouteRequestMultipleMirrors', 'HTTPRouteRequestTimeout', 'HTTPRouteBackendTimeout', 'HTTPRouteParentRefPort'] |
| 51 | + |
| 52 | + |
| 53 | +def generate_conformance_tables(reports): |
| 54 | + |
| 55 | + gateway_http_table = generate_profiles_report(reports, 'HTTP') |
| 56 | + gateway_http_table = gateway_http_table.rename_axis('Organization') |
| 57 | + |
| 58 | + # Currently no implementation has extended supported features listed. |
| 59 | + # Can uncomment once a list is needed to keep track |
| 60 | + # gateway_tls_table = generate_profiles_report(reprots,'TLS') |
| 61 | + |
| 62 | + mesh_http_table = generate_profiles_report(reports, 'MESH') |
| 63 | + mesh_http_table = mesh_http_table.rename_axis('Organization') |
| 64 | + |
| 65 | + with open('site-src/implementation-table.md', 'w') as f: |
| 66 | + f.write(desc) |
| 67 | + f.write("\n\n") |
| 68 | + |
| 69 | + f.write(warning_text) |
| 70 | + f.write("\n\n") |
| 71 | + |
| 72 | + f.write("## Gateway Profile\n\n") |
| 73 | + f.write("### HTTPRoute\n\n") |
| 74 | + f.write(gateway_http_table.to_markdown()+'\n\n') |
| 75 | + |
| 76 | + f.write("## Mesh Profile\n\n") |
| 77 | + f.write("### HTTPRoute\n\n") |
| 78 | + f.write(mesh_http_table.to_markdown()) |
| 79 | + |
| 80 | + |
| 81 | +def generate_profiles_report(reports, route): |
| 82 | + |
| 83 | + http_reports = reports.loc[reports["name"] == route] |
| 84 | + http_reports.set_index('organization') |
| 85 | + http_reports.sort_values(['organization', 'version'], inplace=True) |
| 86 | + |
| 87 | + http_table = pandas.DataFrame( |
| 88 | + columns=http_reports['organization']) |
| 89 | + http_table = http_reports[['organization', 'project', |
| 90 | + 'version', 'extended.supportedFeatures']].T |
| 91 | + http_table.columns = http_table.iloc[0] |
| 92 | + http_table = http_table[1:].T |
| 93 | + |
| 94 | + for row in http_table.itertuples(): |
| 95 | + for feat in row._3: |
| 96 | + http_table.loc[row.Index, feat] = ':white_check_mark:' |
| 97 | + http_table = http_table.fillna(':x:') |
| 98 | + http_table = http_table.drop(['extended.supportedFeatures'], axis=1) |
| 99 | + |
| 100 | + http_table = http_table.rename( |
| 101 | + columns={"project": "Project", "version": "Version"}) |
| 102 | + |
| 103 | + return http_table |
| 104 | + |
| 105 | + |
| 106 | +# the path should be changed when there is a new version |
| 107 | +conformance_path = "conformance/reports/v1.0.0/**" |
| 108 | + |
| 109 | + |
| 110 | +def getYaml(): |
| 111 | + log.info("parsing conformance reports ============================") |
| 112 | + yamls = [] |
| 113 | + |
| 114 | + for p in glob.glob(conformance_path, recursive=True): |
| 115 | + |
| 116 | + if fnmatch(p, "*.yaml"): |
| 117 | + |
| 118 | + x = load_yaml(p) |
| 119 | + profiles = pandas.json_normalize( |
| 120 | + x, record_path='profiles', meta=["implementation"]) |
| 121 | + |
| 122 | + implementation = pandas.json_normalize(profiles.implementation) |
| 123 | + yamls.append(pandas.concat([implementation, profiles], axis=1)) |
| 124 | + |
| 125 | + yamls = pandas.concat(yamls) |
| 126 | + return yamls |
| 127 | + |
| 128 | + |
| 129 | +def load_yaml(name): |
| 130 | + with open(name, 'r') as file: |
| 131 | + x = yaml.safe_load(file) |
| 132 | + |
| 133 | + return x |
0 commit comments