Skip to content

Commit d28a665

Browse files
committed
Merge pull request kubernetes#11452 from thockin/docs-munge-headerlines
Munge headerlines
2 parents ce6b137 + 33f1862 commit d28a665

File tree

214 files changed

+745
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+745
-29
lines changed

cmd/mungedocs/headers.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Copyright 2015 The Kubernetes Authors All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"fmt"
21+
"regexp"
22+
"strings"
23+
)
24+
25+
var headerRegex = regexp.MustCompile(`^(#+)\s*(.*)$`)
26+
var whitespaceRegex = regexp.MustCompile(`^\s*$`)
27+
28+
func fixHeaderLines(fileBytes []byte) []byte {
29+
lines := splitLines(fileBytes)
30+
out := []string{}
31+
for i := range lines {
32+
matches := headerRegex.FindStringSubmatch(lines[i])
33+
if matches == nil {
34+
out = append(out, lines[i])
35+
continue
36+
}
37+
if i > 0 && !whitespaceRegex.Match([]byte(out[len(out)-1])) {
38+
out = append(out, "")
39+
}
40+
out = append(out, fmt.Sprintf("%s %s", matches[1], matches[2]))
41+
if i+1 < len(lines) && !whitespaceRegex.Match([]byte(lines[i+1])) {
42+
out = append(out, "")
43+
}
44+
}
45+
final := strings.Join(out, "\n")
46+
// Preserve the end of the file.
47+
if len(fileBytes) > 0 && fileBytes[len(fileBytes)-1] == '\n' {
48+
final += "\n"
49+
}
50+
return []byte(final)
51+
}
52+
53+
// Header lines need whitespace around them and after the #s.
54+
func checkHeaderLines(filePath string, fileBytes []byte) ([]byte, error) {
55+
fbs := splitByPreformatted(fileBytes)
56+
fbs = append([]fileBlock{{false, []byte{}}}, fbs...)
57+
fbs = append(fbs, fileBlock{false, []byte{}})
58+
59+
for i := range fbs {
60+
block := &fbs[i]
61+
if block.preformatted {
62+
continue
63+
}
64+
block.data = fixHeaderLines(block.data)
65+
}
66+
output := []byte{}
67+
for _, block := range fbs {
68+
output = append(output, block.data...)
69+
}
70+
return output, nil
71+
}

cmd/mungedocs/headers_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Copyright 2015 The Kubernetes Authors All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"testing"
21+
22+
"github.com/stretchr/testify/assert"
23+
)
24+
25+
func TestHeaderLines(t *testing.T) {
26+
var cases = []struct {
27+
in string
28+
out string
29+
}{
30+
{"", ""},
31+
{
32+
"# ok",
33+
"# ok",
34+
},
35+
{
36+
"## ok",
37+
"## ok",
38+
},
39+
{
40+
"##### ok",
41+
"##### ok",
42+
},
43+
{
44+
"##fix",
45+
"## fix",
46+
},
47+
{
48+
"foo\n\n##fix\n\nbar",
49+
"foo\n\n## fix\n\nbar",
50+
},
51+
{
52+
"foo\n##fix\nbar",
53+
"foo\n\n## fix\n\nbar",
54+
},
55+
{
56+
"foo\n```\n##fix\n```\nbar",
57+
"foo\n```\n##fix\n```\nbar",
58+
},
59+
{
60+
"foo\n#fix1\n##fix2\nbar",
61+
"foo\n\n# fix1\n\n## fix2\n\nbar",
62+
},
63+
}
64+
for i, c := range cases {
65+
actual, err := checkHeaderLines("filename.md", []byte(c.in))
66+
assert.NoError(t, err)
67+
if string(actual) != c.out {
68+
t.Errorf("case[%d]: expected %q got %q", i, c.out, string(actual))
69+
}
70+
}
71+
}

cmd/mungedocs/mungedocs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Examples:
4848
{"table-of-contents", updateTOC},
4949
{"check-links", checkLinks},
5050
{"blank-lines-surround-preformatted", checkPreformatted},
51+
{"header-lines", checkHeaderLines},
5152
{"unversioned-warning", updateUnversionedWarning},
5253
{"analytics", checkAnalytics},
5354
{"kubectl-dash-f", checkKubectlFileTargets},

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Documentation for other releases can be found at
3030
<!-- END STRIP_FOR_RELEASE -->
3131

3232
<!-- END MUNGE: UNVERSIONED_WARNING -->
33+
3334
# Kubernetes Documentation: releases.k8s.io/HEAD
3435

3536
* The [User's guide](user-guide/README.md) is for anyone who wants to run programs and

docs/admin/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Documentation for other releases can be found at
3030
<!-- END STRIP_FOR_RELEASE -->
3131

3232
<!-- END MUNGE: UNVERSIONED_WARNING -->
33+
3334
# Kubernetes Cluster Admin Guide
3435

3536
The cluster admin guide is for anyone creating or administering a Kubernetes cluster.
@@ -72,6 +73,7 @@ If you are modifying an existing guide which uses Salt, this document explains [
7273
project.](salt.md).
7374

7475
## Upgrading a cluster
76+
7577
[Upgrading a cluster](cluster-management.md).
7678

7779
## Managing nodes

docs/admin/accessing-the-api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Documentation for other releases can be found at
3030
<!-- END STRIP_FOR_RELEASE -->
3131

3232
<!-- END MUNGE: UNVERSIONED_WARNING -->
33+
3334
# Configuring APIserver ports
3435

3536
This document describes what ports the kubernetes apiserver
@@ -42,6 +43,7 @@ in [Accessing the cluster](../user-guide/accessing-the-cluster.md).
4243

4344

4445
## Ports and IPs Served On
46+
4547
The Kubernetes API is served by the Kubernetes APIServer process. Typically,
4648
there is one of these running on a single kubernetes-master node.
4749

@@ -93,6 +95,7 @@ variety of uses cases:
9395
setup time. Kubelets use cert-based auth, while kube-proxy uses token-based auth.
9496

9597
## Expected changes
98+
9699
- Policy will limit the actions kubelets can do via the authed port.
97100
- Scheduler and Controller-manager will use the Secure Port too. They
98101
will then be able to run on different machines than the apiserver.

docs/admin/admission-controllers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Documentation for other releases can be found at
3030
<!-- END STRIP_FOR_RELEASE -->
3131

3232
<!-- END MUNGE: UNVERSIONED_WARNING -->
33+
3334
# Admission Controllers
3435

3536
**Table of Contents**

docs/admin/authentication.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Documentation for other releases can be found at
3030
<!-- END STRIP_FOR_RELEASE -->
3131

3232
<!-- END MUNGE: UNVERSIONED_WARNING -->
33+
3334
# Authentication Plugins
3435

3536
Kubernetes uses client certificates, tokens, or http basic auth to authenticate users for API calls.

docs/admin/authorization.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Documentation for other releases can be found at
3030
<!-- END STRIP_FOR_RELEASE -->
3131

3232
<!-- END MUNGE: UNVERSIONED_WARNING -->
33+
3334
# Authorization Plugins
3435

3536

@@ -53,6 +54,7 @@ The following implementations are available, and are selected by flag:
5354
`ABAC` allows for user-configured authorization policy. ABAC stands for Attribute-Based Access Control.
5455

5556
## ABAC Mode
57+
5658
### Request Attributes
5759

5860
A request has 4 attributes that can be considered for authorization:
@@ -105,6 +107,7 @@ To permit any user to do something, write a policy with the user property unset.
105107
To permit an action Policy with an unset namespace applies regardless of namespace.
106108

107109
### Examples
110+
108111
1. Alice can do anything: `{"user":"alice"}`
109112
2. Kubelet can read any pods: `{"user":"kubelet", "resource": "pods", "readonly": true}`
110113
3. Kubelet can read and write events: `{"user":"kubelet", "resource": "events"}`

docs/admin/cluster-components.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Documentation for other releases can be found at
3030
<!-- END STRIP_FOR_RELEASE -->
3131

3232
<!-- END MUNGE: UNVERSIONED_WARNING -->
33+
3334
# Kubernetes Cluster Admin Guide: Cluster Components
3435

3536
This document outlines the various binary components that need to run to
@@ -92,6 +93,7 @@ These controllers include:
9293
selects a node for them to run on.
9394

9495
### addons
96+
9597
Addons are pods and services that implement cluster features. They don't run on
9698
the master VM, but currently the default setup scripts that make the API calls
9799
to create these pods and services does run on the master VM. See:

0 commit comments

Comments
 (0)