...
1#!/usr/bin/env bash
2
3# Copyright 2014 The Kubernetes Authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# This file is not intended to be run automatically. It is meant to be run
18# immediately before exporting docs. We do not want to check these documents in
19# by default.
20
21set -o errexit
22set -o nounset
23set -o pipefail
24
25KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
26source "${KUBE_ROOT}/hack/lib/init.sh"
27
28kube::golang::setup_env
29kube::util::ensure-temp-dir
30
31BINS=(
32 ./cmd/gendocs
33 ./cmd/genkubedocs
34 ./cmd/genman
35 ./cmd/genyaml
36)
37GOPROXY=off go install "${BINS[@]}"
38
39# Run all doc generators.
40# $1 is the directory to put those generated documents
41generate_docs() {
42 local dest="$1"
43
44 mkdir -p "${dest}/docs/user-guide/kubectl/"
45 gendocs "${dest}/docs/user-guide/kubectl/"
46
47 mkdir -p "${dest}/docs/admin/"
48 genkubedocs "${dest}/docs/admin/" "kube-apiserver"
49 genkubedocs "${dest}/docs/admin/" "kube-controller-manager"
50 genkubedocs "${dest}/docs/admin/" "kube-proxy"
51 genkubedocs "${dest}/docs/admin/" "kube-scheduler"
52 genkubedocs "${dest}/docs/admin/" "kubelet"
53 genkubedocs "${dest}/docs/admin/" "kubeadm"
54
55 mkdir -p "${dest}/docs/man/man1/"
56 genman "${dest}/docs/man/man1/" "kube-apiserver"
57 genman "${dest}/docs/man/man1/" "kube-controller-manager"
58 genman "${dest}/docs/man/man1/" "kube-proxy"
59 genman "${dest}/docs/man/man1/" "kube-scheduler"
60 genman "${dest}/docs/man/man1/" "kubelet"
61 genman "${dest}/docs/man/man1/" "kubectl"
62 genman "${dest}/docs/man/man1/" "kubeadm"
63
64 mkdir -p "${dest}/docs/yaml/kubectl/"
65 genyaml "${dest}/docs/yaml/kubectl/"
66
67 # create the list of generated files
68 pushd "${dest}" > /dev/null || return 1
69 touch docs/.generated_docs
70 find . -type f | cut -sd / -f 2- | LC_ALL=C sort > docs/.generated_docs
71 popd > /dev/null || return 1
72}
73
74# Removes previously generated docs-- we don't want to check them in. $KUBE_ROOT
75# must be set.
76remove_generated_docs() {
77 if [ -e "${KUBE_ROOT}/docs/.generated_docs" ]; then
78 # remove all of the old docs; we don't want to check them in.
79 while read -r file; do
80 rm "${KUBE_ROOT}/${file}" 2>/dev/null || true
81 done <"${KUBE_ROOT}/docs/.generated_docs"
82 # The docs/.generated_docs file lists itself, so we don't need to explicitly
83 # delete it.
84 fi
85}
86
87# generate into KUBE_TMP
88generate_docs "${KUBE_TEMP}"
89
90# remove all of the existing docs in KUBE_ROOT
91remove_generated_docs
92
93# Copy fresh docs into the repo.
94# the shopt is so that we get docs/.generated_docs from the glob.
95shopt -s dotglob
96cp -af "${KUBE_TEMP}"/* "${KUBE_ROOT}"
97shopt -u dotglob
View as plain text