Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dots from operator reference filenames #50734

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
20 changes: 14 additions & 6 deletions integrations/operator/crdgen/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `---
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
8 changes: 3 additions & 5 deletions integrations/operator/crdgen/handlerequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package crdgen

import (
"fmt"
"os"

gogodesc "github.com/gogo/protobuf/protoc-gen-gogo/descriptor"
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Loading