Skip to content

Commit 0c514f8

Browse files
committed
Add Hugo shortcode to fetch and display release binaries details
Signed-off-by: Dipesh Rawat <[email protected]>
1 parent c74d92c commit 0c514f8

File tree

5 files changed

+300
-22
lines changed

5 files changed

+300
-22
lines changed

content/en/releases/download.md

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ cluster. Those components are also shipped in container images as part of the
1010
official release process. All binaries as well as container images are available
1111
for multiple operating systems as well as hardware architectures.
1212

13+
### kubectl
14+
15+
<!-- overview -->
16+
17+
The Kubernetes command-line tool, [kubectl](/docs/reference/kubectl/kubectl/), allows
18+
you to run commands against Kubernetes clusters.
19+
20+
You can use kubectl to deploy applications, inspect and manage cluster resources,
21+
and view logs. For more information including a complete list of kubectl operations, see the
22+
[`kubectl` reference documentation](/docs/reference/kubectl/).
23+
24+
kubectl is installable on a variety of Linux platforms, macOS and Windows.
25+
Find your preferred operating system below.
26+
27+
- [Install kubectl on Linux](/docs/tasks/tools/install-kubectl-linux)
28+
- [Install kubectl on macOS](/docs/tasks/tools/install-kubectl-macos)
29+
- [Install kubectl on Windows](/docs/tasks/tools/install-kubectl-windows)
30+
1331
## Container Images
1432

1533
All Kubernetes container images are deployed to the
@@ -53,25 +71,4 @@ To manually verify signed container images of Kubernetes core components, refer
5371

5472
## Binaries
5573

56-
Find links to download Kubernetes components (and their checksums) in the
57-
[CHANGELOG](https://github.com/kubernetes/kubernetes/tree/master/CHANGELOG) files.
58-
59-
Alternately, use [downloadkubernetes.com](https://www.downloadkubernetes.com/) to filter by version and architecture.
60-
61-
### kubectl
62-
63-
<!-- overview -->
64-
65-
The Kubernetes command-line tool, [kubectl](/docs/reference/kubectl/kubectl/), allows
66-
you to run commands against Kubernetes clusters.
67-
68-
You can use kubectl to deploy applications, inspect and manage cluster resources,
69-
and view logs. For more information including a complete list of kubectl operations, see the
70-
[`kubectl` reference documentation](/docs/reference/kubectl/).
71-
72-
kubectl is installable on a variety of Linux platforms, macOS and Windows.
73-
Find your preferred operating system below.
74-
75-
- [Install kubectl on Linux](/docs/tasks/tools/install-kubectl-linux)
76-
- [Install kubectl on macOS](/docs/tasks/tools/install-kubectl-macos)
77-
- [Install kubectl on Windows](/docs/tasks/tools/install-kubectl-windows)
74+
{{< release-binaries >}}

data/i18n/en/en.toml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,78 @@ other = "Before you begin"
366366
[previous_patches]
367367
other = "Patch Releases:"
368368

369+
# The following text is displayed when JavaScript isn't available.
370+
[release_binary_alternate_links]
371+
other = """You can find links to download Kubernetes components (and their checksums) in the [CHANGELOG](https://github.com/kubernetes/kubernetes/tree/master/CHANGELOG) files.
372+
Alternately, use [downloadkubernetes.com](https://www.downloadkubernetes.com/) to filter by version and architecture."""
373+
374+
[release_binary_arch]
375+
other = "Architecture"
376+
377+
[release_binary_arch_option]
378+
other = "Architectures"
379+
380+
[release_binary_copy_link]
381+
other = "Copy Link"
382+
383+
[release_binary_copy_link_certifcate]
384+
other = "cert"
385+
386+
[release_binary_copy_link_checksum]
387+
other = "checksum"
388+
389+
[release_binary_copy_link_signature]
390+
other = "signature"
391+
392+
[release_binary_copy_link_tooltip]
393+
other = "copy to clipboard"
394+
395+
[release_binary_download]
396+
other = "Download Binary"
397+
398+
[release_binary_download_tooltip]
399+
other = "download binary file"
400+
401+
[release_binary_options]
402+
other = "Download Options"
403+
404+
[release_binary_os]
405+
other = "Operating System"
406+
407+
[release_binary_os_option]
408+
other = "Operating Systems"
409+
410+
[release_binary_os_darwin]
411+
other = "darwin"
412+
413+
[release_binary_os_linux]
414+
other = "linux"
415+
416+
[release_binary_os_windows]
417+
other = "windows"
418+
419+
[release_binary_table_caption]
420+
other = "Download Kubernetes component binaries"
421+
422+
# NOTE: <current-version> is a placeholder for the actual version number set by 'release-binaries' shortcode.
423+
# Please do not localize or modify <current-version> placeholder.
424+
[release_binary_section]
425+
other = """You can find the links to download <current-version> Kubernetes components (along with their checksums) below.
426+
To access downloads for older supported versions, visit the respective documentation
427+
link for [older versions](https://kubernetes.io/docs/home/supported-doc-versions/#versions-older) or use [downloadkubernetes.com](https://www.downloadkubernetes.com/)."""
428+
429+
# NOTE: <current-version> and <current-changelog-url> are placeholders set by 'release-binaries' shortcode.
430+
# Please do not localize or modify <current-version> and <current-changelog-url> placeholders.
431+
[release_binary_section_note]
432+
other = """To download older patch versions of <current-version> Kubernetes components (and their checksums),
433+
please refer to the [CHANGELOG](https://github.com/kubernetes/kubernetes/tree/master/CHANGELOG/CHANGELOG-<current-changelog-url>.md) file."""
434+
435+
[release_binary_version]
436+
other = "Version"
437+
438+
[release_binary_version_option]
439+
other = "Latest Version"
440+
369441
[release_date_after]
370442
other = ")"
371443

layouts/partials/head.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
<script defer src="{{ "js/sortable-table.js" | relURL }}"></script>
8888
{{- end -}}
8989

90+
{{- if .HasShortcode "release-binaries" -}}
91+
<script defer src="{{ "js/release_binaries.js" | relURL }}"></script>
92+
{{- end -}}
93+
9094
{{- if eq (lower .Params.cid) "community" -}}
9195
{{- if eq .Params.community_styles_migrated true -}}
9296
<link href="/css/community.css" rel="stylesheet"><!-- legacy styles -->
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<!-- Fetch release_binaries.json from kubernetes-sigs/downloadkubernetes to render in table -->
2+
{{ $response := getJSON "https://raw.githubusercontent.com/kubernetes-sigs/downloadkubernetes/master/dist/release_binaries.json" }}
3+
4+
{{ $currentVersion := site.Params.version }}
5+
6+
{{ $Binaries := slice }}
7+
{{ $AllOSes := slice }}
8+
{{ $AllArch := slice }}
9+
{{ $AllVersions := slice }}
10+
11+
{{ range $key, $value := $response }}
12+
{{ if eq $key "Binaries" }}
13+
{{ $Binaries = $value }}
14+
{{ else if eq $key "AllOSes" }}
15+
{{ $AllOSes = $value }}
16+
{{ else if eq $key "AllArch" }}
17+
{{ $AllArch = $value }}
18+
{{ else if eq $key "AllVersions" }}
19+
{{ $AllVersions = $value }}
20+
{{ end }}
21+
{{ end }}
22+
23+
24+
<!-- The below <div> defines an alternate content to be displayed only
25+
when Javascript is disabled or when user's browser doesn't support Javascript -->
26+
<div class="downloadbinaries-nojs">
27+
<p>{{ T "release_binary_alternate_links" | markdownify }}</p>
28+
</div>
29+
30+
<!-- The below section containing the release binary details
31+
is enabled by the script "release_binaries.js" -->
32+
<div id="download-kubernetes-data" style="display: none;">
33+
<p>
34+
{{ $releaseBinarySection := T "release_binary_section" }}
35+
{{ $releaseBinarySection = replace $releaseBinarySection "<current-version>" $currentVersion }}
36+
{{ $releaseBinarySection | markdownify }}
37+
</p>
38+
<div class="alert alert-info note callout" role="alert">
39+
<strong>{{ T "note" }}</strong>
40+
{{ $releaseBinarySectionNote := T "release_binary_section_note" }}
41+
{{ $releaseBinarySectionNote = replace $releaseBinarySectionNote "<current-changelog-url>" (replace $currentVersion "v" "") }}
42+
{{ $releaseBinarySectionNote = replace $releaseBinarySectionNote "<current-version>" $currentVersion }}
43+
{{ $releaseBinarySectionNote | markdownify }}
44+
</div>
45+
<details>
46+
<summary>{{ T "release_binary_options" }}</summary>
47+
<div class="text-center w-100">
48+
<div class="d-inline-block text-center pr-4">
49+
<div>
50+
<b>{{ T "release_binary_os_option" }}</b>
51+
<div class="buttons" id="os-filter">
52+
{{- range $AllOSes }}
53+
<button class="btn btn-outline-primary m-1" data-os="{{.}}-data">{{ T (printf "release_binary_os_%s" .) }}</button>
54+
{{- end }}
55+
</div>
56+
</div>
57+
</div>
58+
<div class="d-inline-block text-center pr-4">
59+
<div>
60+
<b>{{ T "release_binary_version_option" }}</b>
61+
<div class="buttons" id="version-filter">
62+
{{- range $AllVersions }}
63+
{{- $releaseBinaryData := printf "%s.%s" (index (split . ".") 0) (index (split . ".") 1) -}}
64+
{{- if eq $releaseBinaryData $currentVersion }}
65+
<button class="btn btn-primary m-1" data-version="{{.}}-data">{{ $currentVersion }} ({{ T "patch_release" }} {{ . }})</button>
66+
{{- end }}
67+
{{- end }}
68+
</div>
69+
</div>
70+
</div>
71+
72+
<div class="text-center w-100 p-4">
73+
<div>
74+
<b>{{ T "release_binary_arch_option" }}</b>
75+
<div class="buttons" id="arch-filter">
76+
{{- range $AllArch }}
77+
<button class="btn btn-outline-primary m-1" data-arch="{{.}}-data">{{.}}</button>
78+
{{- end }}
79+
</div>
80+
</div>
81+
</div>
82+
</div>
83+
</details>
84+
85+
<div class="table-responsive">
86+
<table class="table" id="release-binary-table">
87+
<caption style="display:none">{{ T "release_binary_table_caption" }}</caption>
88+
<thead>
89+
<tr>
90+
<th>{{ T "release_binary_version" }}</th>
91+
<th>{{ T "release_binary_os" }}</th>
92+
<th>{{ T "release_binary_arch" }}</th>
93+
<th>{{ T "release_binary_download" }}</th>
94+
<th>{{ T "release_binary_copy_link" }}</th>
95+
</tr>
96+
</thead>
97+
<tbody>
98+
{{- range $index, $binary := $Binaries -}}
99+
{{- $releaseBinaryData := printf "%s.%s" (index (split $binary.Version ".") 0) (index (split $binary.Version ".") 1) -}}
100+
{{- if eq $releaseBinaryData $currentVersion }}
101+
{{ $LinkText := printf "dl.k8s.io/%s/bin/%s/%s/%s" $binary.Version $binary.OperatingSystem $binary.Architecture $binary.Name }}
102+
{{ $BinaryLink := printf "https://dl.k8s.io/%s/bin/%s/%s/%s" $binary.Version $binary.OperatingSystem $binary.Architecture $binary.Name }}
103+
{{ $ChecksumLink := printf "https://dl.k8s.io/%s/bin/%s/%s/%s.sha256" $binary.Version $binary.OperatingSystem $binary.Architecture $binary.Name }}
104+
{{ $SignatureLink := printf "https://dl.k8s.io/%s/bin/%s/%s/%s.sig" $binary.Version $binary.OperatingSystem $binary.Architecture $binary.Name }}
105+
{{ $CertificateLink := printf "https://dl.k8s.io/%s/bin/%s/%s/%s.cert" $binary.Version $binary.OperatingSystem $binary.Architecture $binary.Name }}
106+
<tr class="{{ $binary.Version }}-data {{ $binary.OperatingSystem }}-data {{ $binary.Architecture }}-data {{ $binary.Name }}-data">
107+
<td>{{ $binary.Version }}</td>
108+
<td>{{ T (printf "release_binary_os_%s" $binary.OperatingSystem) }}</td>
109+
<td>{{ $binary.Architecture }}</td>
110+
<td>
111+
<span title="{{ T "release_binary_download_tooltip" }}">
112+
<a href="{{$BinaryLink}}">{{ $binary.Name }}</a>
113+
</span>
114+
</td>
115+
<td>
116+
<span class="icon">
117+
<i class="fa fa-copy"></i>
118+
</span>
119+
<span title="{{ T "release_binary_copy_link_tooltip" }}">
120+
<a class="release-binary-copy" href="{{$BinaryLink}}">{{$LinkText}}</a>
121+
(<a class="release-binary-copy" href="{{$ChecksumLink}}">{{T "release_binary_copy_link_checksum"}}</a> | <a class="release-binary-copy" href="{{$SignatureLink}}">{{T "release_binary_copy_link_signature"}}</a> | <a class="release-binary-copy" href="{{$CertificateLink}}">{{T "release_binary_copy_link_certifcate"}}</a>)
122+
</span>
123+
</td>
124+
</tr>
125+
{{- end }}
126+
{{- end }}
127+
</tbody>
128+
</table>
129+
</div>
130+
</div>

static/js/release_binaries.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const filterCriteria = {
2+
os: "",
3+
arch: ""
4+
};
5+
6+
["os", "arch"].forEach(kind => {
7+
eventListener(kind);
8+
});
9+
10+
function eventListener(kind) {
11+
let buttonGroupQuery = '#' + kind + '-filter' + ' > button';
12+
let buttonGroup = document.querySelectorAll(buttonGroupQuery);
13+
14+
buttonGroup.forEach(button => {
15+
button.addEventListener('click', (evt) => {
16+
let buttonData = button.dataset[kind];
17+
18+
if (filterCriteria[kind] === buttonData) {
19+
filterCriteria[kind] = "";
20+
button.classList.add('btn-outline-primary');
21+
button.classList.remove('btn-primary');
22+
} else {
23+
filterCriteria[kind] = buttonData;
24+
buttonGroup.forEach(b => {
25+
b.classList.remove('btn-primary');
26+
b.classList.add('btn-outline-primary');
27+
});
28+
button.classList.remove('btn-outline-primary');
29+
button.classList.add('btn-primary');
30+
}
31+
32+
filterRows();
33+
});
34+
});
35+
}
36+
37+
function filterRows() {
38+
const rows = document.querySelectorAll('#release-binary-table tbody tr');
39+
40+
rows.forEach(row => {
41+
const os = row.classList.contains(filterCriteria.os) || filterCriteria.os === "";
42+
const arch = row.classList.contains(filterCriteria.arch) || filterCriteria.arch === "";
43+
44+
if (os && arch) {
45+
row.classList.remove('hide');
46+
} else {
47+
row.classList.add('hide');
48+
}
49+
});
50+
}
51+
52+
document.querySelectorAll("#release-binary-table .release-binary-copy").forEach(link => {
53+
link.addEventListener('click', (evt) => {
54+
evt.preventDefault();
55+
56+
const hrefValue = link.getAttribute('href');
57+
const tempTextArea = document.createElement('textarea');
58+
tempTextArea.value = hrefValue;
59+
document.body.appendChild(tempTextArea);
60+
tempTextArea.select();
61+
document.execCommand('copy');
62+
document.body.removeChild(tempTextArea);
63+
return false;
64+
});
65+
});
66+
67+
// The page and script is loaded successfully
68+
$( document ).ready(function() {
69+
70+
// Remove the non-js content
71+
$('.downloadbinaries-nojs').hide();
72+
73+
// Display the release binary content
74+
$('#download-kubernetes-data').show();
75+
})

0 commit comments

Comments
 (0)