Skip to content

Commit

Permalink
Revert PR #126533 and add a test case for the case where there is yaml
Browse files Browse the repository at this point in the history
structed texts in the description.
We should find a way to both relign line breaks and not break these kind
of texts.

Signed-off-by: ah8ad3 <[email protected]>

Kubernetes-commit: 7580e6ac00b00cf6e7ba375a3730e0dccbf40463
  • Loading branch information
ah8ad3 authored and k8s-publishing-bot committed Nov 12, 2024
1 parent 6e4fe32 commit 7ff7f80
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 0 additions & 3 deletions pkg/explain/v2/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ func WithBuiltinTemplateFuncs(tmpl *template.Template) *template.Template {
return "", errors.New(message)
},
"wrap": func(l int, s string) (string, error) {
// realign all line breaks
s = strings.ReplaceAll(s, "\n", "")

buf := bytes.NewBuffer(nil)
writer := term.NewWordWrapWriter(buf, uint(l))
_, err := writer.Write([]byte(s))
Expand Down
8 changes: 5 additions & 3 deletions pkg/explain/v2/funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ func TestFuncs(t *testing.T) {
Expect: "[this is a slash separated thing]",
},
{
Name: "realign line breaks",
// TODO: we should find a way to both realign line breaks and not break yaml texts in descriptions
// example from https://github.com/kubernetes-sigs/cluster-api/blob/f495466327aa340ad8c36182eb4e2797e7e35bef/config/crd/bases/cluster.x-k8s.io_machinedrainrules.yaml#L89
Name: "make sure explain doesnt break current descriptions",
FuncName: "wrap",
Source: `{{wrap 76 .}}`,
Context: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus pulvinar in libero id sagittis. \nAliquam sem enim, vehicula et urna ac, vehicula ullamcorper sem. Morbi turpis arcu, aliquet at \neros quis, sodales dignissim eros. \nQuisque ut lectus quis magna maximus elementum a nec felis. \nNulla ultricies pulvinar quam, id tincidunt.",
Expect: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus pulvinar in\nlibero id sagittis. Aliquam sem enim, vehicula et urna ac, vehicula\nullamcorper sem. Morbi turpis arcu, aliquet at eros quis, sodales dignissim\neros. Quisque ut lectus quis magna maximus elementum a nec felis. Nulla\nultricies pulvinar quam, id tincidunt.",
Context: "machines defines to which Machines this MachineDrainRule should be applied.\nIf machines is not set, the MachineDrainRule applies to all Machines in the Namespace.\nIf machines contains multiple selectors, the results are ORed.\nWithin a single Machine selector the results of selector and clusterSelector are ANDed.\nMachines will be selected from all Clusters in the Namespace unless otherwise restricted with the clusterSelector.\nExample: Selects control plane Machines in all Clusters or Machines with label \"os\" == \"linux\" in Clusters with label \"stage\" == \"production\".\n - selector:\n matchExpressions:\n - key: cluster.x-k8s.io/control-plane\n operator: Exists\n - selector:\n matchLabels:\n os: linux\n clusterSelector:\n matchExpressions:\n - key: stage\n operator: In\n values:\n - production",
Expect: "machines defines to which Machines this MachineDrainRule should be applied.\nIf machines is not set, the MachineDrainRule applies to all Machines in the\nNamespace.\nIf machines contains multiple selectors, the results are ORed.\nWithin a single Machine selector the results of selector and clusterSelector\nare ANDed.\nMachines will be selected from all Clusters in the Namespace unless\notherwise restricted with the clusterSelector.\nExample: Selects control plane Machines in all Clusters or Machines with\nlabel \"os\" == \"linux\" in Clusters with label \"stage\" == \"production\".\n - selector:\n matchExpressions:\n - key: cluster.x-k8s.io/control-plane\n operator: Exists\n - selector:\n matchLabels:\n os: linux\n clusterSelector:\n matchExpressions:\n - key: stage\n operator: In\n values:\n - production",
},
{
Name: "basic",
Expand Down

0 comments on commit 7ff7f80

Please sign in to comment.