diff --git a/cmd/mungedocs/mungedocs.go b/cmd/mungedocs/mungedocs.go
index d1b19e59093..21e99d53388 100644
--- a/cmd/mungedocs/mungedocs.go
+++ b/cmd/mungedocs/mungedocs.go
@@ -21,6 +21,7 @@ import (
"fmt"
"io/ioutil"
"os"
+ "os/exec"
"path"
"path/filepath"
"strings"
@@ -28,6 +29,9 @@ import (
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.")
@@ -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{
@@ -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,
diff --git a/cmd/mungedocs/unversioned_warning.go b/cmd/mungedocs/unversioned_warning.go
index 69222bae777..9ec8ce7ecb9 100644
--- a/cmd/mungedocs/unversioned_warning.go
+++ b/cmd/mungedocs/unversioned_warning.go
@@ -16,7 +16,10 @@ limitations under the License.
package main
-import "fmt"
+import (
+ "fmt"
+ "strings"
+)
const unversionedWarningTag = "UNVERSIONED_WARNING"
@@ -37,13 +40,14 @@ const unversionedWarningPre = `
PLEASE NOTE: This document applies to the HEAD of the source tree
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 = `
+
+
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 = `
@@ -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)
}
@@ -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, "")
+ }
+
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
}
diff --git a/cmd/mungedocs/unversioned_warning_test.go b/cmd/mungedocs/unversioned_warning_test.go
index 4d758bd2b98..65adb93ca4d 100644
--- a/cmd/mungedocs/unversioned_warning_test.go
+++ b/cmd/mungedocs/unversioned_warning_test.go
@@ -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
@@ -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,
+ `
+
+
+
+
+
+
+
+
+PLEASE NOTE: This document applies to the HEAD of the source tree
+
+If you are using a released version of Kubernetes, you should
+refer to the docs that go with that version.
+
+
+
+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).
+
+--
+
+
+
+`,
+ },
+ {
+ false,
+ `
+
+
+
+
+
+
+
+
+PLEASE NOTE: This document applies to the HEAD of the source tree
+
+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).
+
+--
+
+
+
+`,
+ },
+ }
+ 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)
+ }
+ }
+}