From f781ca9e985cf840ec3672103a8dec27bc37424f Mon Sep 17 00:00:00 2001 From: Paul Gottschling Date: Fri, 3 Jan 2025 12:00:26 -0500 Subject: [PATCH] Remove dots from operator reference filenames The dots cause issues with our hosting infrastructure, which returns 404s when users make requests for Kubernetes operator reference pages with no trailing slash. This change returns a filename from the format function in the CRD/CRD docs generator so we can return different file names for CRDs and their docs. It also renames CRD docs pages to include hyphens instead of dots and underscores, and adds redirects. --- docs/config.json | 68 ++++++++++++++++++- ...=> resources-teleport-dev-accesslists.mdx} | 0 ...sources-teleport-dev-githubconnectors.mdx} | 0 ... => resources-teleport-dev-loginrules.mdx} | 0 ...resources-teleport-dev-oidcconnectors.mdx} | 0 ...esources-teleport-dev-oktaimportrules.mdx} | 0 ...ces-teleport-dev-openssheiceserversv2.mdx} | 0 ...sources-teleport-dev-opensshserversv2.mdx} | 0 ...esources-teleport-dev-provisiontokens.mdx} | 0 ...s.mdx => resources-teleport-dev-roles.mdx} | 0 ...mdx => resources-teleport-dev-rolesv6.mdx} | 0 ...mdx => resources-teleport-dev-rolesv7.mdx} | 0 ...resources-teleport-dev-samlconnectors.mdx} | 0 ...s.mdx => resources-teleport-dev-users.mdx} | 0 integrations/operator/crdgen/format.go | 20 ++++-- integrations/operator/crdgen/handlerequest.go | 8 +-- 16 files changed, 84 insertions(+), 12 deletions(-) rename docs/pages/reference/operator-resources/{resources.teleport.dev_accesslists.mdx => resources-teleport-dev-accesslists.mdx} (100%) rename docs/pages/reference/operator-resources/{resources.teleport.dev_githubconnectors.mdx => resources-teleport-dev-githubconnectors.mdx} (100%) rename docs/pages/reference/operator-resources/{resources.teleport.dev_loginrules.mdx => resources-teleport-dev-loginrules.mdx} (100%) rename docs/pages/reference/operator-resources/{resources.teleport.dev_oidcconnectors.mdx => resources-teleport-dev-oidcconnectors.mdx} (100%) rename docs/pages/reference/operator-resources/{resources.teleport.dev_oktaimportrules.mdx => resources-teleport-dev-oktaimportrules.mdx} (100%) rename docs/pages/reference/operator-resources/{resources.teleport.dev_openssheiceserversv2.mdx => resources-teleport-dev-openssheiceserversv2.mdx} (100%) rename docs/pages/reference/operator-resources/{resources.teleport.dev_opensshserversv2.mdx => resources-teleport-dev-opensshserversv2.mdx} (100%) rename docs/pages/reference/operator-resources/{resources.teleport.dev_provisiontokens.mdx => resources-teleport-dev-provisiontokens.mdx} (100%) rename docs/pages/reference/operator-resources/{resources.teleport.dev_roles.mdx => resources-teleport-dev-roles.mdx} (100%) rename docs/pages/reference/operator-resources/{resources.teleport.dev_rolesv6.mdx => resources-teleport-dev-rolesv6.mdx} (100%) rename docs/pages/reference/operator-resources/{resources.teleport.dev_rolesv7.mdx => resources-teleport-dev-rolesv7.mdx} (100%) rename docs/pages/reference/operator-resources/{resources.teleport.dev_samlconnectors.mdx => resources-teleport-dev-samlconnectors.mdx} (100%) rename docs/pages/reference/operator-resources/{resources.teleport.dev_users.mdx => resources-teleport-dev-users.mdx} (100%) diff --git a/docs/config.json b/docs/config.json index 34c0c3f34c91c..204ec4d25b211 100644 --- a/docs/config.json +++ b/docs/config.json @@ -209,5 +209,71 @@ } } }, - "redirects": [] + "redirects": [ + { + "source": "/reference/operator-resources/resources.teleport.dev_accesslists/", + "destination": "/reference/operator-resources/resources-teleport-dev-accesslists/", + "permanent": true + }, + { + "source": "/reference/operator-resources/resources.teleport.dev_githubconnectors/", + "destination": "/reference/operator-resources/resources-teleport-dev-githubconnectors/", + "permanent": true + }, + { + "source": "/reference/operator-resources/resources.teleport.dev_loginrules/", + "destination": "/reference/operator-resources/resources-teleport-dev-loginrules/", + "permanent": true + }, + { + "source": "/reference/operator-resources/resources.teleport.dev_oidcconnectors/", + "destination": "/reference/operator-resources/resources-teleport-dev-oidcconnectors/", + "permanent": true + }, + { + "source": "/reference/operator-resources/resources.teleport.dev_oktaimportrules/", + "destination": "/reference/operator-resources/resources-teleport-dev-oktaimportrules/", + "permanent": true + }, + { + "source": "/reference/operator-resources/resources.teleport.dev_openssheiceserversv2/", + "destination": "/reference/operator-resources/resources-teleport-dev-openssheiceserversv2/", + "permanent": true + }, + { + "source": "/reference/operator-resources/resources.teleport.dev_opensshserversv2/", + "destination": "/reference/operator-resources/resources-teleport-dev-opensshserversv2/", + "permanent": true + }, + { + "source": "/reference/operator-resources/resources.teleport.dev_provisiontokens/", + "destination": "/reference/operator-resources/resources-teleport-dev-provisiontokens/", + "permanent": true + }, + { + "source": "/reference/operator-resources/resources.teleport.dev_roles/", + "destination": "/reference/operator-resources/resources-teleport-dev-roles/", + "permanent": true + }, + { + "source": "/reference/operator-resources/resources.teleport.dev_rolesv6/", + "destination": "/reference/operator-resources/resources-teleport-dev-rolesv6/", + "permanent": true + }, + { + "source": "/reference/operator-resources/resources.teleport.dev_rolesv7/", + "destination": "/reference/operator-resources/resources-teleport-dev-rolesv7/", + "permanent": true + }, + { + "source": "/reference/operator-resources/resources.teleport.dev_samlconnectors/", + "destination": "/reference/operator-resources/resources-teleport-dev-samlconnectors/", + "permanent": true + }, + { + "source": "/reference/operator-resources/resources.teleport.dev_users/", + "destination": "/reference/operator-resources/resources-teleport-dev-users/", + "permanent": true + } + ] } diff --git a/docs/pages/reference/operator-resources/resources.teleport.dev_accesslists.mdx b/docs/pages/reference/operator-resources/resources-teleport-dev-accesslists.mdx similarity index 100% rename from docs/pages/reference/operator-resources/resources.teleport.dev_accesslists.mdx rename to docs/pages/reference/operator-resources/resources-teleport-dev-accesslists.mdx diff --git a/docs/pages/reference/operator-resources/resources.teleport.dev_githubconnectors.mdx b/docs/pages/reference/operator-resources/resources-teleport-dev-githubconnectors.mdx similarity index 100% rename from docs/pages/reference/operator-resources/resources.teleport.dev_githubconnectors.mdx rename to docs/pages/reference/operator-resources/resources-teleport-dev-githubconnectors.mdx diff --git a/docs/pages/reference/operator-resources/resources.teleport.dev_loginrules.mdx b/docs/pages/reference/operator-resources/resources-teleport-dev-loginrules.mdx similarity index 100% rename from docs/pages/reference/operator-resources/resources.teleport.dev_loginrules.mdx rename to docs/pages/reference/operator-resources/resources-teleport-dev-loginrules.mdx diff --git a/docs/pages/reference/operator-resources/resources.teleport.dev_oidcconnectors.mdx b/docs/pages/reference/operator-resources/resources-teleport-dev-oidcconnectors.mdx similarity index 100% rename from docs/pages/reference/operator-resources/resources.teleport.dev_oidcconnectors.mdx rename to docs/pages/reference/operator-resources/resources-teleport-dev-oidcconnectors.mdx diff --git a/docs/pages/reference/operator-resources/resources.teleport.dev_oktaimportrules.mdx b/docs/pages/reference/operator-resources/resources-teleport-dev-oktaimportrules.mdx similarity index 100% rename from docs/pages/reference/operator-resources/resources.teleport.dev_oktaimportrules.mdx rename to docs/pages/reference/operator-resources/resources-teleport-dev-oktaimportrules.mdx diff --git a/docs/pages/reference/operator-resources/resources.teleport.dev_openssheiceserversv2.mdx b/docs/pages/reference/operator-resources/resources-teleport-dev-openssheiceserversv2.mdx similarity index 100% rename from docs/pages/reference/operator-resources/resources.teleport.dev_openssheiceserversv2.mdx rename to docs/pages/reference/operator-resources/resources-teleport-dev-openssheiceserversv2.mdx diff --git a/docs/pages/reference/operator-resources/resources.teleport.dev_opensshserversv2.mdx b/docs/pages/reference/operator-resources/resources-teleport-dev-opensshserversv2.mdx similarity index 100% rename from docs/pages/reference/operator-resources/resources.teleport.dev_opensshserversv2.mdx rename to docs/pages/reference/operator-resources/resources-teleport-dev-opensshserversv2.mdx diff --git a/docs/pages/reference/operator-resources/resources.teleport.dev_provisiontokens.mdx b/docs/pages/reference/operator-resources/resources-teleport-dev-provisiontokens.mdx similarity index 100% rename from docs/pages/reference/operator-resources/resources.teleport.dev_provisiontokens.mdx rename to docs/pages/reference/operator-resources/resources-teleport-dev-provisiontokens.mdx diff --git a/docs/pages/reference/operator-resources/resources.teleport.dev_roles.mdx b/docs/pages/reference/operator-resources/resources-teleport-dev-roles.mdx similarity index 100% rename from docs/pages/reference/operator-resources/resources.teleport.dev_roles.mdx rename to docs/pages/reference/operator-resources/resources-teleport-dev-roles.mdx diff --git a/docs/pages/reference/operator-resources/resources.teleport.dev_rolesv6.mdx b/docs/pages/reference/operator-resources/resources-teleport-dev-rolesv6.mdx similarity index 100% rename from docs/pages/reference/operator-resources/resources.teleport.dev_rolesv6.mdx rename to docs/pages/reference/operator-resources/resources-teleport-dev-rolesv6.mdx diff --git a/docs/pages/reference/operator-resources/resources.teleport.dev_rolesv7.mdx b/docs/pages/reference/operator-resources/resources-teleport-dev-rolesv7.mdx similarity index 100% rename from docs/pages/reference/operator-resources/resources.teleport.dev_rolesv7.mdx rename to docs/pages/reference/operator-resources/resources-teleport-dev-rolesv7.mdx diff --git a/docs/pages/reference/operator-resources/resources.teleport.dev_samlconnectors.mdx b/docs/pages/reference/operator-resources/resources-teleport-dev-samlconnectors.mdx similarity index 100% rename from docs/pages/reference/operator-resources/resources.teleport.dev_samlconnectors.mdx rename to docs/pages/reference/operator-resources/resources-teleport-dev-samlconnectors.mdx diff --git a/docs/pages/reference/operator-resources/resources.teleport.dev_users.mdx b/docs/pages/reference/operator-resources/resources-teleport-dev-users.mdx similarity index 100% rename from docs/pages/reference/operator-resources/resources.teleport.dev_users.mdx rename to docs/pages/reference/operator-resources/resources-teleport-dev-users.mdx diff --git a/integrations/operator/crdgen/format.go b/integrations/operator/crdgen/format.go index 3cdd0afb6add3..b2193284c4271 100644 --- a/integrations/operator/crdgen/format.go +++ b/integrations/operator/crdgen/format.go @@ -31,15 +31,17 @@ import ( ) // crdFormatFunc formats the given CRD into a document. It returns the document -// as a byte slice, plus the file extension for the document. -type crdFormatFunc func(apiextv1.CustomResourceDefinition) ([]byte, string, error) +// as a byte slice, plus the file name for the document. The file name is based +// on the CRD's API group name and plural name. +type crdFormatFunc func(crd apiextv1.CustomResourceDefinition, groupName, pluralName string) ([]byte, string, error) -func formatAsYAML(crd apiextv1.CustomResourceDefinition) ([]byte, string, error) { +func formatAsCRD(crd apiextv1.CustomResourceDefinition, groupName, pluralName string) ([]byte, string, error) { doc, err := yaml.Marshal(crd) if err != nil { return nil, "", err } - return doc, "yaml", nil + filename := fmt.Sprintf("%s_%s.%v", groupName, pluralName, "yaml") + return doc, filename, nil } var crdDocTmpl string = `--- @@ -226,7 +228,7 @@ func propertyTable(currentFieldName string, props *apiextv1.JSONSchemaProps) ([] return tables, nil } -func formatAsDocsPage(crd apiextv1.CustomResourceDefinition) ([]byte, string, error) { +func formatAsDocsPage(crd apiextv1.CustomResourceDefinition, groupName, pluralName string) ([]byte, string, error) { var buf bytes.Buffer rp := ResourcePage{ Title: crd.Spec.Names.Kind, @@ -263,5 +265,11 @@ resource, which you can apply after installing the Teleport Kubernetes operator. return nil, "", trace.Wrap(err) } - return buf.Bytes(), "mdx", nil + filename := fmt.Sprintf( + "%s-%s.%v", + strings.ReplaceAll(groupName, ".", "-"), + pluralName, + "mdx", + ) + return buf.Bytes(), filename, nil } diff --git a/integrations/operator/crdgen/handlerequest.go b/integrations/operator/crdgen/handlerequest.go index 669211d76e3bd..66d90324cc0f4 100644 --- a/integrations/operator/crdgen/handlerequest.go +++ b/integrations/operator/crdgen/handlerequest.go @@ -19,7 +19,6 @@ package crdgen import ( - "fmt" "os" gogodesc "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" @@ -34,7 +33,7 @@ import ( ) func HandleCRDRequest(req *gogoplugin.CodeGeneratorRequest) error { - return handleRequest(req, formatAsYAML) + return handleRequest(req, formatAsCRD) } func HandleDocsRequest(req *gogoplugin.CodeGeneratorRequest) error { @@ -232,13 +231,12 @@ func generateSchema(file *File, groupName string, format crdFormatFunc, resp *go if err != nil { return trace.Wrap(err, "generating CRD") } - data, ext, err := format(crd) + data, filename, err := format(crd, groupName, root.pluralName) if err != nil { return trace.Wrap(err) } - name := fmt.Sprintf("%s_%s.%v", groupName, root.pluralName, ext) content := string(data) - resp.File = append(resp.File, &gogoplugin.CodeGeneratorResponse_File{Name: &name, Content: &content}) + resp.File = append(resp.File, &gogoplugin.CodeGeneratorResponse_File{Name: &filename, Content: &content}) } return nil