Skip to content

Commit

Permalink
Merge pull request kubernetes#18047 from caesarxuchao/munger-tag-new
Browse files Browse the repository at this point in the history
Stop munger produce the link to a release version doc if it doesn't exit in the release branch
  • Loading branch information
brendandburns committed Dec 22, 2015
2 parents ac5c0aa + 2b2f285 commit 4ca66d2
Show file tree
Hide file tree
Showing 325 changed files with 456 additions and 188 deletions.
29 changes: 29 additions & 0 deletions cmd/mungedocs/mungedocs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"strings"

flag "github.com/spf13/pflag"
)

// This needs to be updated when we cut a new release series.
const latestReleaseBranch = "release-1.1"

var (
verbose = flag.Bool("verbose", false, "On verification failure, emit pre-munge and post-munge versions.")
verify = flag.Bool("verify", false, "Exit with status 1 if files would have needed changes but do not change.")
Expand All @@ -44,6 +48,11 @@ Examples:

ErrChangesNeeded = errors.New("mungedocs: changes required")

// This records the files in the rootDir in upstream/latest-release
filesInLatestRelease string
// This indicates if the munger is running inside Jenkins
inJenkins bool

// All of the munge operations to perform.
// TODO: allow selection from command line. (e.g., just check links in the examples directory.)
allMunges = []munge{
Expand Down Expand Up @@ -192,6 +201,26 @@ func main() {
os.Exit(2)
}

absRootDir, err := filepath.Abs(*rootDir)
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
os.Exit(2)
}
inJenkins = len(os.Getenv("JENKINS_HOME")) != 0
out, err := exec.Command("git", "ls-tree", "-r", "--name-only", fmt.Sprintf("%s/%s", "upstream", latestReleaseBranch), absRootDir).CombinedOutput()
if err != nil {
if inJenkins {
fmt.Fprintf(os.Stderr, "output: %s,\nERROR: %v\n", out, err)
os.Exit(2)
} else {
fmt.Fprintf(os.Stdout, "output: %s,\nERROR: %v\n", out, err)
fmt.Fprintf(os.Stdout, "`git ls-tree -r --name-only upstream/%s failed. We'll ignore this error locally, but Jenkins may pick an error. Munger uses the output of this command to determine in unversioned warning, if it should add a link to the doc in release branch.\n", latestReleaseBranch)
filesInLatestRelease = ""
}
} else {
filesInLatestRelease = string(out)
}

fp := fileProcessor{
munges: wantedMunges(),
verifyOnly: *verify,
Expand Down
34 changes: 26 additions & 8 deletions cmd/mungedocs/unversioned_warning.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ limitations under the License.

package main

import "fmt"
import (
"fmt"
"strings"
)

const unversionedWarningTag = "UNVERSIONED_WARNING"

Expand All @@ -37,13 +40,14 @@ const unversionedWarningPre = `
<h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2>
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.
refer to the docs that go with that version.`

const unversionedWarningLink = `
<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
`

const unversionedWarningFmt = `[here](http://releases.k8s.io/release-1.1/%s).`
[here](http://releases.k8s.io/%s/%s).`

const unversionedWarningPost = `
Expand All @@ -56,8 +60,13 @@ Documentation for other releases can be found at
`

func makeUnversionedWarning(fileName string) mungeLines {
insert := unversionedWarningPre + fmt.Sprintf(unversionedWarningFmt, fileName) + unversionedWarningPost
func makeUnversionedWarning(fileName string, linkToReleaseDoc bool) mungeLines {
var insert string
if linkToReleaseDoc {
insert = unversionedWarningPre + fmt.Sprintf(unversionedWarningLink, latestReleaseBranch, fileName) + unversionedWarningPost
} else {
insert = unversionedWarningPre + unversionedWarningPost
}
return getMungeLines(insert)
}

Expand All @@ -71,11 +80,20 @@ func updateUnversionedWarning(file string, mlines mungeLines) (mungeLines, error
// No warnings on release branches
return mlines, nil
}

var linkToReleaseDoc bool
checkDocExistence := inJenkins || (len(filesInLatestRelease) != 0)
if checkDocExistence {
linkToReleaseDoc = strings.Contains(filesInLatestRelease, file)
} else {
linkToReleaseDoc = hasLine(mlines, "<!-- TAG RELEASE_LINK, added by the munger automatically -->")
}

if !hasMacroBlock(mlines, unversionedWarningTag) {
mlines = prependMacroBlock(unversionedWarningTag, mlines)
}

mlines, err = updateMacroBlock(mlines, unversionedWarningTag, makeUnversionedWarning(file))
mlines, err = updateMacroBlock(mlines, unversionedWarningTag, makeUnversionedWarning(file, linkToReleaseDoc))
if err != nil {
return mlines, err
}
Expand Down
81 changes: 80 additions & 1 deletion cmd/mungedocs/unversioned_warning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestUnversionedWarning(t *testing.T) {
beginMark := beginMungeTag(unversionedWarningTag)
endMark := endMungeTag(unversionedWarningTag)

warningString := makeUnversionedWarning("filename.md").String()
warningString := makeUnversionedWarning("filename.md", false).String()
warningBlock := beginMark + "\n" + warningString + endMark + "\n"
var cases = []struct {
in string
Expand Down Expand Up @@ -68,3 +68,82 @@ func TestUnversionedWarning(t *testing.T) {
}
}
}

func TestMakeUnversionedWarning(t *testing.T) {
const fileName = "filename.md"
var cases = []struct {
linkToReleaseDoc bool
expected string
}{
{
true,
`
<!-- BEGIN STRIP_FOR_RELEASE -->
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2>
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.
<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/filename.md).
Documentation for other releases can be found at
[releases.k8s.io](http://releases.k8s.io).
</strong>
--
<!-- END STRIP_FOR_RELEASE -->
`,
},
{
false,
`
<!-- BEGIN STRIP_FOR_RELEASE -->
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2>
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.
Documentation for other releases can be found at
[releases.k8s.io](http://releases.k8s.io).
</strong>
--
<!-- END STRIP_FOR_RELEASE -->
`,
},
}
for i, c := range cases {
if e, a := c.expected, makeUnversionedWarning(fileName, c.linkToReleaseDoc).String(); e != a {
t.Errorf("case[%d]: \nexpected %s\ngot %s", i, e, a)
}
}
}
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/README.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/README.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/accessing-the-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/accessing-the-api.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/admission-controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/admission-controllers.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/authentication.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/authorization.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/cluster-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/cluster-components.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/cluster-large.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/cluster-large.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/cluster-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/cluster-management.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/cluster-troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/cluster-troubleshooting.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/daemons.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/daemons.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/dns.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/dns.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/etcd.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/etcd.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/garbage-collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/garbage-collection.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/high-availability.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/high-availability.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/introduction.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/kube-apiserver.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/kube-apiserver.md).
Expand Down
1 change: 1 addition & 0 deletions docs/admin/kube-controller-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/kube-controller-manager.md).
Expand Down
3 changes: 2 additions & 1 deletion docs/admin/kube-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/kube-proxy.md).
Expand Down Expand Up @@ -73,7 +74,7 @@ kube-proxy
--udp-timeout=250ms: How long an idle UDP connection will be kept open (e.g. '250ms', '2s'). Must be greater than 0. Only applicable for proxy-mode=userspace
```

###### Auto generated by spf13/cobra on 21-Nov-2015
###### Auto generated by spf13/cobra on 8-Dec-2015


<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
Expand Down
1 change: 1 addition & 0 deletions docs/admin/kube-scheduler.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.

<!-- TAG RELEASE_LINK, added by the munger automatically -->
<strong>
The latest release of this document can be found
[here](http://releases.k8s.io/release-1.1/docs/admin/kube-scheduler.md).
Expand Down
Loading

0 comments on commit 4ca66d2

Please sign in to comment.