-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathkubectl.py
More file actions
93 lines (81 loc) · 3.3 KB
/
kubectl.py
File metadata and controls
93 lines (81 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""Kubectl (Kubernetes client) BCI container"""
import textwrap
from bci_build.container_attributes import Arch
from bci_build.container_attributes import SupportLevel
from bci_build.os_version import CAN_BE_LATEST_OS_VERSION
from bci_build.os_version import OsVersion
from bci_build.package import DOCKERFILE_RUN
from bci_build.package import ApplicationStackContainer
from bci_build.package.helpers import generate_from_image_tag
from bci_build.replacement import Replacement
from bci_build.util import ParseVersion
_KUBECTL_VERSIONS = {
OsVersion.TUMBLEWEED: ("1.32", "1.33", "1.34", "1.35"),
OsVersion.SP7: ("1.33", "1.35"),
}
def _is_latest_kubectl(version: str, os_version: OsVersion) -> bool:
return (
version == _KUBECTL_VERSIONS[os_version][-1]
and os_version in CAN_BE_LATEST_OS_VERSION
)
def _get_kubectl_stability_tag(version: str, os_version: OsVersion) -> str | None:
if not os_version.is_sle15:
return None
assert (len(_KUBECTL_VERSIONS[os_version])) == 2, (
"expected max of two versions of kubernetes client in parallel"
)
if version == _KUBECTL_VERSIONS[os_version][-1]:
return "stable"
if version == _KUBECTL_VERSIONS[os_version][0]:
return "oldstable"
return None
KUBECTL_CONTAINERS = [
ApplicationStackContainer(
name="kubectl",
stability_tag=(stability_tag := _get_kubectl_stability_tag(ver, os_version)),
package_name=(
f"kubectl-{stability_tag}-image"
if stability_tag
else f"kubectl-{ver}-image"
),
pretty_name="kubectl",
custom_description="Kubernetes CLI for communicating with a Kubernetes cluster's control plane using the Kubernetes API, {based_on_container}.",
exclusive_arch=[Arch.AARCH64, Arch.PPC64LE, Arch.S390X, Arch.X86_64],
os_version=os_version,
is_latest=_is_latest_kubectl(ver, os_version),
version="%%kubectl_version%%",
from_target_image=generate_from_image_tag(os_version, "bci-micro"),
tag_version=ver,
replacements_via_service=[
Replacement(
regex_in_build_description="%%kubectl_version%%",
package_name=f"kubernetes{ver}-client",
parse_version=ParseVersion.PATCH,
)
],
package_list=(
[f"kubernetes{ver}-client", "diffutils"]
+ (["helm3"] if os_version.is_tumbleweed else ["helm"])
),
entrypoint=["kubectl"],
license="Apache-2.0",
support_level=SupportLevel.L3,
logo_url="https://raw.githubusercontent.com/kubernetes/kubernetes/master/logo/logo.png",
build_stage_custom_end=(
f"{DOCKERFILE_RUN} ln -s /usr/bin/helm3 /target/usr/local/bin/helm"
if os_version.is_tumbleweed
else None
),
custom_end=textwrap.dedent(f"""
{DOCKERFILE_RUN} echo "user:x:999:100:User for CLI:/home/user:/usr/sbin/nologin" >> /etc/passwd && install -d -o 999 -g 100 -m 0755 /home/user /home/user/.kube
WORKDIR /home/user
"""),
)
for ver, os_version in (
[
(kubectl_version, os_version)
for os_version in (OsVersion.TUMBLEWEED, OsVersion.SP7)
for kubectl_version in _KUBECTL_VERSIONS[os_version]
]
)
]