Skip to content

Commit 7580e6a

Browse files
committed
Revert PR kubernetes#126533 and add a test case for the case where there is yaml
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]>
1 parent 6b031e5 commit 7580e6a

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

staging/src/k8s.io/kubectl/pkg/explain/v2/funcs.go

-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ func WithBuiltinTemplateFuncs(tmpl *template.Template) *template.Template {
5656
return "", errors.New(message)
5757
},
5858
"wrap": func(l int, s string) (string, error) {
59-
// realign all line breaks
60-
s = strings.ReplaceAll(s, "\n", "")
61-
6259
buf := bytes.NewBuffer(nil)
6360
writer := term.NewWordWrapWriter(buf, uint(l))
6461
_, err := writer.Write([]byte(s))

staging/src/k8s.io/kubectl/pkg/explain/v2/funcs_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ func TestFuncs(t *testing.T) {
5757
Expect: "[this is a slash separated thing]",
5858
},
5959
{
60-
Name: "realign line breaks",
60+
// TODO: we should find a way to both realign line breaks and not break yaml texts in descriptions
61+
// example from https://github.com/kubernetes-sigs/cluster-api/blob/f495466327aa340ad8c36182eb4e2797e7e35bef/config/crd/bases/cluster.x-k8s.io_machinedrainrules.yaml#L89
62+
Name: "make sure explain doesnt break current descriptions",
6163
FuncName: "wrap",
6264
Source: `{{wrap 76 .}}`,
63-
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.",
64-
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.",
65+
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",
66+
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",
6567
},
6668
{
6769
Name: "basic",

0 commit comments

Comments
 (0)