Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Switch to a kuberlr based Shell Image #249

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ clean: ## clean up project.
test: test-build ## test the build against all target platforms.
$(MAKE) image-build
IMAGE=$(IMAGE) \
KUBECTL_VERSION=$(KUBECTL_VERSION) HELM_VERSION=$(HELM_VERSION) \
KUSTOMIZE_VERSION=$(KUSTOMIZE_VERSION) K9S_VERSION=$(K9S_VERSION) \
HELM_VERSION=$(HELM_VERSION) \
KUSTOMIZE_VERSION=$(KUSTOMIZE_VERSION) \
K9S_VERSION=$(K9S_VERSION) \
./hack/test

test-build:
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ This is the current branch strategy for `rancher/shell`, it may change in the fu
This branch supports Rancher 2.9 and spans supporting k8s 1.27 through 1.30.
Here are the current component versions and their k8s support:

| Component | Version | Supported K8s |
|-------------|-----------------------------------------|-----------------------------------------------|
| `kuberlr` | `v0.4.5` | n/a |
| `kubectl` | `v1.27.x`,`v1.28.x`,`v1.29.x`,`v1.30.x` | `1.26`-`1.31` |
| `kustomize` | `v5.4.x` | n/a |
| `helm` | `v3.15.1-rancher2` | `1.27`-`1.30` (based on upstream helm policy) |
| `k9s` | `v0.32.4` | Uses `client-go` v0.29.3 |


#### Pre-Kuberlr
> These docs are preserved during the transition to kuberlr.

This branch supports Rancher 2.9 and spans supporting k8s 1.27 through 1.30.
Here are the current component versions and their k8s support:

| Component | Version | Supported K8s |
|-------------|--------------------|----------------------------|
| `kubectl` | `v1.28.x` | `1.27`,`1.28`,`1.29` |
Expand Down
6 changes: 0 additions & 6 deletions hack/make/deps.mk
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# renovate: datasource=github-release-attachments depName=rancher/helm
HELM_VERSION := v3.15.1-rancher2

KUBECTL_VERSION := v1.28.11
KUBECTL_SUM_arm64 ?= $(shell curl -L "https://dl.k8s.io/release/$(KUBECTL_VERSION)/bin/linux/arm64/kubectl.sha256")
KUBECTL_SUM_amd64 ?= $(shell curl -L "https://dl.k8s.io/release/$(KUBECTL_VERSION)/bin/linux/amd64/kubectl.sha256")
KUBECTL_SUM_s390x ?= $(shell curl -L "https://dl.k8s.io/release/$(KUBECTL_VERSION)/bin/linux/s390x/kubectl.sha256")

# renovate: datasource=github-release-attachments depName=kubernetes-sigs/kustomize extractVersion=kustomize/v(?<version>\d+\.\d+\.\d+)
KUSTOMIZE_VERSION := v5.4.2
# renovate: datasource=github-release-attachments depName=kubernetes-sigs/kustomize versioning=regex:^kustomize/v(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)$ digestVersion=kustomize/v5.4.1
Expand All @@ -26,6 +21,5 @@ K9S_SUM_s390x := 8aea75262492a699c150833cafc65465541c74becc1b0236b4a7e368f5bd512

# Reduces the code duplication on Makefile by keeping all args into a single variable.
IMAGE_ARGS := --build-arg HELM_VERSION=$(HELM_VERSION) \
--build-arg KUBECTL_VERSION=$(KUBECTL_VERSION) --build-arg KUBECTL_SUM_arm64=$(KUBECTL_SUM_arm64) --build-arg KUBECTL_SUM_amd64=$(KUBECTL_SUM_amd64) --build-arg KUBECTL_SUM_s390x=$(KUBECTL_SUM_s390x) \
--build-arg KUSTOMIZE_VERSION=$(KUSTOMIZE_VERSION) --build-arg KUSTOMIZE_SUM_arm64=$(KUSTOMIZE_SUM_arm64) --build-arg KUSTOMIZE_SUM_amd64=$(KUSTOMIZE_SUM_amd64) --build-arg KUSTOMIZE_SUM_s390x=$(KUSTOMIZE_SUM_s390x) \
--build-arg K9S_VERSION=$(K9S_VERSION) --build-arg K9S_SUM_arm64=$(K9S_SUM_arm64) --build-arg K9S_SUM_amd64=$(K9S_SUM_amd64) --build-arg K9S_SUM_s390x=$(K9S_SUM_s390x)
6 changes: 2 additions & 4 deletions hack/test
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function check_files(){
expected_file "/usr/local/bin/helm" "0:0" "755"
expected_file "/usr/local/bin/helm-cmd" "0:0" "755"
expected_file "/usr/local/bin/k9s" "0:0" "755"
expected_file "/usr/local/bin/kubectl" "0:0" "755"
expected_file "/bin/kuberlr" "0:0" "755"
expected_file "/bin/kubectl" "0:0" "777"
expected_file "/usr/local/bin/kustomize" "0:0" "755"
expected_file "/usr/local/bin/welcome" "0:0" "755"
expected_file "/home/shell/kustomize.sh" "1000:1000" "755"
Expand Down Expand Up @@ -64,9 +65,6 @@ function check_versions(){
expected_version "helm" "${HELM_VERSION}"
expected_version "kustomize" "${KUSTOMIZE_VERSION}"
expected_version "k9s" "${K9S_VERSION}"
# --client=true is used so that it does not fail trying to
# identify the server version.
expected_version "kubectl --client=true" "${KUBECTL_VERSION}"
}

function main(){
Expand Down
32 changes: 16 additions & 16 deletions package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
ARG BCI_VERSION=15.6
FROM registry.suse.com/bci/bci-busybox:${BCI_VERSION} as final
FROM --platform=$BUILDPLATFORM mallardduck/rancher-kuberlr-kubectl:v2.0.0-beta.2 AS kuberlr
FROM registry.suse.com/bci/bci-busybox:${BCI_VERSION} AS final

# Image that provides cross compilation tooling.
FROM --platform=$BUILDPLATFORM rancher/mirrored-tonistiigi-xx:1.3.0 as xx
FROM --platform=$BUILDPLATFORM rancher/mirrored-tonistiigi-xx:1.3.0 AS xx

FROM --platform=$BUILDPLATFORM registry.suse.com/bci/golang:1.22 as helm
FROM --platform=$BUILDPLATFORM registry.suse.com/bci/golang:1.22 AS helm

# Clone repository once, and reuse it for target archs.
ARG HELM_VERSION
Expand All @@ -24,20 +25,11 @@ FROM --platform=$BUILDPLATFORM registry.suse.com/bci/bci-base:${BCI_VERSION} AS
RUN zypper -n install curl gzip tar

# Define build arguments
ARG KUBECTL_VERSION KUBECTL_SUM_arm64 KUBECTL_SUM_amd64 KUBECTL_SUM_s390x \
KUSTOMIZE_VERSION KUSTOMIZE_SUM_arm64 KUSTOMIZE_SUM_amd64 KUSTOMIZE_SUM_s390x \
ARG KUBECTL_VERSION KUSTOMIZE_VERSION KUSTOMIZE_SUM_arm64 KUSTOMIZE_SUM_amd64 KUSTOMIZE_SUM_s390x \
K9S_VERSION K9S_SUM_arm64 K9S_SUM_amd64 K9S_SUM_s390x

ARG TARGETARCH
# Stage kubectl into build
ADD --chown=root:root --chmod=0755 \
"https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/${TARGETARCH}/kubectl" \
/kubectl

ENV KUBECTL_SUM="KUBECTL_SUM_${TARGETARCH}"
RUN echo "${!KUBECTL_SUM} /kubectl" | sha256sum -c -

# Stage kubectl into build
# Stage kustomize into build
ENV KUSTOMIZE_SUM="KUSTOMIZE_SUM_${TARGETARCH}"
RUN curl --output /tmp/kustomize.tar.gz -sLf "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_linux_${TARGETARCH}.tar.gz" && \
echo "${!KUSTOMIZE_SUM} /tmp/kustomize.tar.gz" | sha256sum -c - && \
Expand All @@ -49,7 +41,7 @@ RUN curl --output /tmp/k9s.tar.gz -sLf "https://github.com/derailed/k9s/releases
echo "${!K9S_SUM} /tmp/k9s.tar.gz" | sha256sum -c - && \
tar -xvzf /tmp/k9s.tar.gz -C / k9s

FROM registry.suse.com/bci/bci-base:${BCI_VERSION} as zypper
FROM registry.suse.com/bci/bci-base:${BCI_VERSION} AS zypper

# Creates the based dir for the target image, and hydrades it with the
# original contents of the final image.
Expand Down Expand Up @@ -77,14 +69,22 @@ RUN echo 'shell:x:1000:1000:shell,,,:/home/shell:/bin/bash' > /chroot/etc/passwd
echo 'LANG=en_US.UTF-8' >> /chroot/home/shell/.bashrc && \
echo 'PS1="> "' >> /chroot/home/shell/.bashrc && \
mkdir /chroot/home/shell/.kube && \
mkdir /chroot/home/shell/.kuberlr && \
touch /chroot/home/shell/.kuberlr/kuberlr.conf && \
echo "AllowDownload = false" >> /chroot/home/shell/.kuberlr/kuberlr.conf && \
echo 'SystemPath = "/usr/local/bin"' >> /chroot/home/shell/.kuberlr/kuberlr.conf && \
echo "Timeout = 6" >> /chroot/home/shell/.kuberlr/kuberlr.conf && \
chown -R 1000:1000 /chroot/home/shell && \
chmod 700 /chroot/run

FROM scratch

COPY --from=zypper /chroot /
COPY --chown=root:root --chmod=0755 --from=helm /helm/bin/helm /usr/local/bin/
COPY --chown=root:root --chmod=0755 --from=build /kubectl /k9s /kustomize* /usr/local/bin/
COPY --chown=root:root --chmod=0755 --from=build /k9s /kustomize* /usr/local/bin/
COPY --chown=root:root --chmod=0755 --from=kuberlr /usr/bin/kubectl* /usr/local/bin/
COPY --chown=root:root --chmod=0755 --from=kuberlr /bin/kuberlr /bin/
RUN ln -s /bin/kuberlr /bin/kubectl
COPY --chown=root:root --chmod=0755 package/helm-cmd package/welcome /usr/local/bin/
COPY --chown=1000:1000 --chmod=0755 package/kustomize.sh /home/shell/

Expand Down