Skip to content

Commit

Permalink
script to detect dangling imports, generates explicit multirepo impor…
Browse files Browse the repository at this point in the history
…ts from the nav

Signed-off-by: Jason Madigan <[email protected]>
  • Loading branch information
jasonmadigan committed Jan 24, 2025
1 parent df183be commit a0c3b1f
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 42 deletions.
2 changes: 1 addition & 1 deletion docs/install-olm.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ kubectl apply -k config/observability/openshift/grafana
Create the example dashboards in Grafana

```bash
kubectl apply -k https://github.com/Kuadrant/kuadrant-operator//examples/dashboards?ref=v1.0.1
kubectl apply -k https://github.com/Kuadrant/kuadrant-operator/examples/dashboards?ref=v1.0.1
```

Access the Grafana UI, using the default user/pass of root/secret.
Expand Down
118 changes: 77 additions & 41 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,59 +52,95 @@ plugins:
css_dir: css
javascript_dir: js
- search
# Note: Try to avoid globs for `imports`. Be explicit about imports, so we can avoid having
# published dangling docs with no routes to them from the nav/other pages - these will go stale quickly.
- multirepo:
cleanup: true
keep_docs_dir: true
nav_repos:
- name: kuadrant-operator
import_url: 'https://github.com/kuadrant/kuadrant-operator?edit_uri=/blob/main/&branch=main'
import_url: https://github.com/kuadrant/kuadrant-operator?edit_uri=/blob/main/&branch=main
imports:
- /README.md
- /doc/*
- /config/samples/*
- /examples/*
- /doc/install/mtls-configuration.md
- /doc/observability/examples.md
- /doc/observability/metrics.md
- /doc/observability/tracing.md
- /doc/overviews/auth.md
- /doc/overviews/dns.md
- /doc/overviews/rate-limiting.md
- /doc/overviews/tls.md
- /doc/reference/authpolicy.md
- /doc/reference/dnspolicy.md
- /doc/reference/kuadrant.md
- /doc/reference/ratelimitpolicy.md
- /doc/reference/tlspolicy.md
- /doc/user-guides/auth/auth-for-app-devs-and-platform-engineers.md
- /doc/user-guides/dns/basic-dns-configuration.md
- /doc/user-guides/dns/dnshealthchecks.md
- /doc/user-guides/dns/gateway-dns.md
- /doc/user-guides/dns/load-balanced-dns.md
- /doc/user-guides/full-walkthrough/secure-protect-connect.md
- /doc/user-guides/ratelimiting/authenticated-rl-for-app-developers.md
- /doc/user-guides/ratelimiting/authenticated-rl-with-jwt-and-k8s-authnz.md
- /doc/user-guides/ratelimiting/gateway-rl-for-cluster-operators.md
- /doc/user-guides/ratelimiting/multi-auth-rlp-diff-section.md
- /doc/user-guides/ratelimiting/multi-auth-rlp-same-section.md
- /doc/user-guides/tls/gateway-tls.md
- /doc/observability/grafana_trace.png
- /doc/observability/grafana_tracing_loki.png
- /doc/user-guides/ratelimiting/simple-rl-for-app-developers.md
- name: authorino
import_url: 'https://github.com/kuadrant/authorino?edit_uri=/blob/main/&branch=main'
import_url: https://github.com/kuadrant/authorino?edit_uri=/blob/main/&branch=main
imports:
- /README.md
- /docs/*
- /docs/user-guides/*
- /install/crd/*
- name: authorino-operator
import_url: 'https://github.com/kuadrant/authorino-operator?edit_uri=/blob/main/&branch=main'
imports:
- /README.md
- name: limitador
import_url: 'https://github.com/kuadrant/limitador?edit_uri=/blob/main/&branch=main'
imports:
- /README.md
- /doc/*
- /limitador-server/README.md
- /limitador-server/docs/*
- /limitador/README.md
- /limitador-server/kubernetes/*
- /limitador-server/sandbox/*
- /LICENSE
- name: limitador-operator
import_url: 'https://github.com/kuadrant/limitador-operator?edit_uri=/blob/main/&branch=main'
imports:
- /README.md
- /doc/*
- /docs/user-guides/observability.md
- /docs/features.md
- /docs/architecture.md
- /docs/architecture.gif
- /docs/auth-pipeline.gif
- /install/crd/*
- /docs/user-guides.md
- /docs/user-guides/*
- /docs/user-guides/hello-world.md
- /docs/user-guides/anonymous-access.md
- /docs/user-guides/oidc-user-info.md
- /docs/user-guides/oidc-rbac.md
- /docs/user-guides/authzed.md
- /docs/user-guides/injecting-data.md
- /docs/user-guides/host-override.md
- /docs/user-guides/sharding.md
- /docs/user-guides/caching.md
- /docs/user-guides/sharding.md
- /docs/getting-started.md
- /docs/user-guides/api-key-authentication.md
- /docs/user-guides/authenticated-rate-limiting-envoy-dynamic-metadata.md
- /docs/user-guides/deny-with-redirect-to-login.md
- /docs/user-guides/edge-authentication-architecture-festival-wristbands.md
- /docs/user-guides/envoy-jwt-authn-and-authorino.md
- /docs/user-guides/external-metadata.md
- /docs/user-guides/http-basic-authentication.md
- /docs/user-guides/json-pattern-matching-authorization.md
- /docs/user-guides/keycloak-authorization-services.md
- /docs/user-guides/kubernetes-subjectaccessreview.md
- /docs/user-guides/kubernetes-tokenreview.md
- /docs/user-guides/mtls-authentication.md
- /docs/user-guides/oauth2-token-introspection.md
- /docs/user-guides/oidc-jwt-authentication.md
- /docs/user-guides/opa-authorization.md
- /docs/user-guides/passing-credentials.md
- /docs/user-guides/resource-level-authorization-uma.md
- /docs/user-guides/token-normalization.md
- /docs/terminology.md
- /docs/contributing.md
- /docs/README.md
- name: architecture
import_url: 'https://github.com/kuadrant/architecture?edit_uri=/blob/main/&branch=main'
imports:
- /docs/design/*
- name: kuadrantctl
import_url: 'https://github.com/kuadrant/kuadrantctl?edit_uri=/blob/main/&branch=main'
import_url: https://github.com/kuadrant/architecture?edit_uri=/blob/main/&branch=main
imports:
- /README.md
- /doc/*
- /docs/design/architectural-overview-v1.md
- /docs/design/images/*
- name: dns-operator
import_url: 'https://github.com/kuadrant/dns-operator?edit_uri=/blob/main/&branch=main'
import_url: https://github.com/kuadrant/dns-operator?edit_uri=/blob/main/&branch=main
imports:
- /README.md
- /docs/*
- /config/samples/*
- /docs/provider.md
- redirects:
redirect_maps:
'getting-started-single-cluster.md': 'getting-started.md'
Expand Down
88 changes: 88 additions & 0 deletions validate_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Helper script to generate explicit imports for the multirepo plugin from the nav
# Note: this will not find certain kinds of links, e.g. images or links between docs - so you'll still need to do a bit of manual work to generate imports.
# The list if imports it produces will not be exhaustive. Re run `mkdocs -s` to find other, missing imports

import yaml

def generate_explicit_nav_repos(mkdocs_file):
with open(mkdocs_file, 'r') as f:
raw_content = f.read()

# Preprocess to remove problematic syntax (e.g., !!python/name)
sanitized_content = clean(raw_content)
config = yaml.safe_load(sanitized_content)

# Extract files from nav
nav_files = set(extract_files_from_nav(config['nav']))

# Build new multirepo imports
explicit_imports = generate_imports(config['plugins'], nav_files)

print("Updated nav_repos:")
print(yaml.dump(explicit_imports, default_flow_style=False, sort_keys=False))

def clean(content):
return "\n".join([line for line in content.splitlines() if '!!python/name:' not in line])

def extract_files_from_nav(nav):
files = []
for item in nav:
if isinstance(item, dict):
for key, value in item.items():
if isinstance(value, list):
files.extend(extract_files_from_nav(value))
else:
files.append(value)
else:
files.append(item)
return files

def generate_imports(plugins, nav_files):
new_imports = []
for plugin in plugins:
if isinstance(plugin, dict) and 'multirepo' in plugin:
for repo in plugin['multirepo']['nav_repos']:
repo_name = repo['name']
repo_import_url = repo['import_url']
repo_explicit_imports = []

for pattern in repo['imports']:
matching_files = match_files_to_pattern(nav_files, pattern, repo_name)

repo_explicit_imports.extend(
add_leading_slash(remove_repo_name_prefix(matching_files, repo_name))
)

# Deduplicate imports (may be used multiple times in nav)
repo_explicit_imports = sorted(set(repo_explicit_imports))

new_imports.append({
'name': repo_name,
'import_url': repo_import_url,
'imports': repo_explicit_imports,
})
return new_imports

def match_files_to_pattern(nav_files, pattern, repo_name):
base_path = f"{repo_name}/"
if pattern.startswith('/'):
pattern = pattern[1:] # Remove leading slash
if '*' in pattern or '?' in pattern:
# Handle glob patterns
prefix = base_path + pattern.split('*')[0]
return {file for file in nav_files if file.startswith(prefix)}
else:
# Handle exact matches
expected_path = base_path + pattern.lstrip('/')
return {file for file in nav_files if file == expected_path}

def remove_repo_name_prefix(files, repo_name):
# Remove the repo name prefix from file paths
prefix = f"{repo_name}/"
return [file[len(prefix):] for file in files if file.startswith(prefix)]

def add_leading_slash(files):
return [f"/{file}" if not file.startswith("/") else file for file in files]

# Run
generate_explicit_nav_repos('mkdocs.yml')

0 comments on commit a0c3b1f

Please sign in to comment.