Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

snap support #1

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7329f38
add snap packaging
wwwtyro Mar 21, 2017
7d59906
Adding snap for kubefed
ktsakalozos Apr 11, 2017
22a854d
add ceph-common to kube-controller-manager snap (#4)
Cynerva Apr 18, 2017
feca116
Add kubernetes-test snap (#6)
Cynerva Apr 27, 2017
d3e5810
Snaps multiarch support (#7)
Cynerva Apr 28, 2017
d14660b
fix configure hook generation (#8)
wwwtyro May 3, 2017
2503ce7
Fix snap arm/ppc64le builds by mapping to the correct arch (#9)
Cynerva May 9, 2017
0fea5cc
Fix snap configuration not properly handling boolean false values (#10)
Cynerva Jun 28, 2017
ee3013b
Adding a wrapper and HOME env var to kubelet (#11)
ktsakalozos Aug 18, 2017
f52e665
include conntrack bin in the kube-proxy snap (#12)
wwwtyro Mar 2, 2018
44cda3c
Fix configure hook for 1.10 by converting underscores to dashes (#13)
Cynerva Mar 29, 2018
9b59885
Add hidden kubelet args to snap configure hook (#16)
Cynerva Mar 29, 2018
3b21ff4
Stop building kubefed (#17)
ktsakalozos Apr 2, 2018
5a983aa
validate what we download is expected (#14) (#15)
kwmonroe Apr 2, 2018
28a5658
Disable patchelf in classic confinement snaps (#18)
ktsakalozos Apr 3, 2018
cbd379d
Source /root/cdk/kube.env in daemon wrappers (#19)
johnsca Apr 24, 2018
141172c
Update wrappers to use $SNAP_COMMON/environment per review (#20)
johnsca Apr 25, 2018
4156f5f
support building snap variants (#21)
kwmonroe May 31, 2018
bceacb1
prepare -> override-build (#23)
hyperbolic2346 Jun 7, 2018
f5c46cf
Adding snapcraftctl build to the build-override steps (#24)
hyperbolic2346 Jun 7, 2018
dd9238e
Making sure service-account-private-key-file arg is available in kube…
ktsakalozos Jun 18, 2018
d4d3c45
Fix configure hook incorrectly encoding some args (#26)
Cynerva Jul 3, 2018
697052e
Support dynamic kubelet config with restart-condition: always (#27)
Cynerva Aug 8, 2018
3992021
Add snapcraft cleanbuild (#28)
battlemidget Sep 11, 2018
01e32d1
Fix docker builds (#29)
battlemidget Sep 12, 2018
34994b1
Update Makefile to use docker-build (#30)
battlemidget Sep 12, 2018
f08f2e2
Update README to not use docker-build.sh (#31)
Cynerva Sep 12, 2018
f5f8490
Fix KUBE_VERSION and KUBE_ARCH being ignored (#32)
Cynerva Sep 14, 2018
3e9af3a
Add Dockerfile and update build script to use that (#33)
battlemidget Sep 14, 2018
80e5868
Add missing "v" arg to kube-apiserver and kube-controller-manager (#34)
Cynerva Oct 2, 2018
bb82537
Add support for ppc64, arm64, s390x (#35)
battlemidget Oct 20, 2018
8660128
Add custom args (#38)
ktsakalozos Mar 12, 2019
9d7566a
Fix download url for kubernetes-test
battlemidget Sep 3, 2020
5252847
Fixing grep (#39)
joedborg Aug 13, 2021
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,13 @@ cd rpm

Resulting rpms, and a pre-generated yum repository will be generated in rpm/output/x86_64.

### Snap

You can build snap packages with:

```
cd snap
./docker-build.sh
```

The resulting snap packages will be located in snap/build.
1 change: 1 addition & 0 deletions snap/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
15 changes: 15 additions & 0 deletions snap/Dockerfile.aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM arm64v8/ubuntu:xenial
RUN apt-get update && \
apt-get dist-upgrade --yes && \
apt-get install --yes \
snapcraft curl file make sudo jq squashfs-tools && \
apt-get autoclean --yes && \
apt-get clean --yes

ADD . /code
WORKDIR /code
ENV SNAPCRAFT_SETUP_CORE=1
ENV KUBE_ARCH=$KUBE_ARCH
ENV KUBE_VERSION=$KUBE_VERSION
ENTRYPOINT ["./build-scripts/build"]
CMD ["$@"]
15 changes: 15 additions & 0 deletions snap/Dockerfile.ppc64le
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM ppc64le/ubuntu:xenial
RUN apt-get update && \
apt-get dist-upgrade --yes && \
apt-get install --yes \
snapcraft curl file make sudo jq squashfs-tools && \
apt-get autoclean --yes && \
apt-get clean --yes

ADD . /code
WORKDIR /code
ENV SNAPCRAFT_SETUP_CORE=1
ENV KUBE_ARCH=$KUBE_ARCH
ENV KUBE_VERSION=$KUBE_VERSION
ENTRYPOINT ["./build-scripts/build"]
CMD ["$@"]
15 changes: 15 additions & 0 deletions snap/Dockerfile.s390x
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM s390x/ubuntu:xenial
RUN apt-get update && \
apt-get dist-upgrade --yes && \
apt-get install --yes \
snapcraft curl file make sudo jq squashfs-tools && \
apt-get autoclean --yes && \
apt-get clean --yes

ADD . /code
WORKDIR /code
ENV SNAPCRAFT_SETUP_CORE=1
ENV KUBE_ARCH=$KUBE_ARCH
ENV KUBE_VERSION=$KUBE_VERSION
ENTRYPOINT ["./build-scripts/build"]
CMD ["$@"]
10 changes: 10 additions & 0 deletions snap/Dockerfile.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM snapcore/snapcraft:stable
ADD . /code
WORKDIR /code
ENV SNAPCRAFT_SETUP_CORE=1
ENV KUBE_ARCH=$KUBE_ARCH
ENV KUBE_VERSION=$KUBE_VERSION
RUN apt-get update
RUN apt-get -y install wget curl file make
ENTRYPOINT ["./build-scripts/build"]
CMD ["$@"]
42 changes: 42 additions & 0 deletions snap/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
KUBE_VERSION=$(shell curl -L https://dl.k8s.io/release/stable.txt)
KUBE_ARCH=amd64

ifndef VERBOSE
MAKEFLAGS += --no-print-directory
endif

targets = kubectl kube-apiserver kube-controller-manager kube-scheduler kubelet kube-proxy kubeadm kubernetes-test

build = ./build-scripts/docker-build

.PHONY: $(targets)

default:
@KUBE_VERSION=${KUBE_VERSION} KUBE_ARCH="${KUBE_ARCH}" ${build} $(targets)

clean:
@rm -rf build

kubectl:
@KUBE_VERSION=${KUBE_VERSION} KUBE_ARCH="${KUBE_ARCH}" ${build} kubectl

kubeadm:
@KUBE_VERSION=${KUBE_VERSION} KUBE_ARCH="${KUBE_ARCH}" ${build} kubeadm

kube-apiserver:
@KUBE_VERSION=${KUBE_VERSION} KUBE_ARCH="${KUBE_ARCH}" ${build} kube-apiserver

kube-controller-manager:
@KUBE_VERSION=${KUBE_VERSION} KUBE_ARCH="${KUBE_ARCH}" ${build} kube-controller-manager

kube-scheduler:
@KUBE_VERSION=${KUBE_VERSION} KUBE_ARCH="${KUBE_ARCH}" ${build} kube-scheduler

kubelet:
@KUBE_VERSION=${KUBE_VERSION} KUBE_ARCH="${KUBE_ARCH}" ${build} kubelet

kube-proxy:
@KUBE_VERSION=${KUBE_VERSION} KUBE_ARCH="${KUBE_ARCH}" ${build} kube-proxy

kubernetes-test:
@KUBE_VERSION=${KUBE_VERSION} KUBE_ARCH="${KUBE_ARCH}" ${build} kubernetes-test
32 changes: 32 additions & 0 deletions snap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kubernetes Snaps

## Build everything

Run `make` here and check for the results in the `build/` directory.

## Build one snap

To build a specific snap, run `make` with the name of the snap, e.g., for
kubectl:

```sh
$ make kubectl
```

The result will again be in the `build/` directory.

## Build a specific version

Set KUBE_VERSION to build the snaps with a particular Kubernetes version, e.g.,

```sh
$ make KUBE_VERSION=v1.5.5
```

## Cleaning up

Simply run `make clean` to remove everything except downloaded resources:

```sh
$ make clean
```
70 changes: 70 additions & 0 deletions snap/build-scripts/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash
set -eux

apps="$@"
architectures="$KUBE_ARCH"

KUBE_SNAP_BINS="${KUBE_SNAP_BINS:-}"
if [ -z "$KUBE_SNAP_BINS" ]; then
echo "KUBE_SNAP_BINS is not set, downloading binaries from upstream"
export KUBE_SNAP_BINS=build/kube_bins/$KUBE_VERSION
mkdir -p $KUBE_SNAP_BINS
(cd $KUBE_SNAP_BINS
for app in $apps; do
if [ "$app" = "kubernetes-test" ]; then
echo "Fetching https://dl.k8s.io/$KUBE_VERSION/$app-linux-$KUBE_ARCH.tar.gz"
curl -LO \
https://dl.k8s.io/${KUBE_VERSION}/${app}-linux-${KUBE_ARCH}.tar.gz
if ! file ${app}-linux-${KUBE_ARCH}.tar.gz 2>&1 | grep -q 'gzip'; then
echo "${app}.tar.gz is not a gzip archive"
exit 1
fi
else
for arch in $architectures; do
mkdir -p $arch
(cd $arch
echo "Fetching $app $KUBE_VERSION $arch"
curl -LO \
https://dl.k8s.io/${KUBE_VERSION}/bin/linux/$arch/$app
chmod +x $app
if ! file ${app} 2>&1 | grep -q 'executable'; then
echo "${app} is not an executable"
exit 1
fi
)
done
fi
done
)
fi

export KUBE_SNAP_ROOT="$(readlink -f .)"
export KUBE_SNAP_BINS="$(readlink -f $KUBE_SNAP_BINS)"

for app in $apps; do
for arch in $architectures; do
# Add -suffix if it's set
snap_name="${app}${SNAP_SUFFIX:+-${SNAP_SUFFIX}}"

echo "Building $snap_name $KUBE_VERSION for $arch from $KUBE_SNAP_BINS"
build_dir=build/$app
rm -rf $build_dir
mkdir -p $build_dir

export KUBE_ARCH="$arch"
declare -A kube_arch_to_snap_arch=(
[ppc64le]=ppc64el
[arm]=armhf
)
export SNAP_ARCH="${kube_arch_to_snap_arch[$arch]:-$arch}"

# replace the name (in case we have a suffix), version (stripping the 'v'),
# and arch in our $app.yaml.
sed -e "s/name: $app/name: $snap_name/g" \
-e "s/\$KUBE_VERSION/${KUBE_VERSION:1}/g" \
-e "s/\$SNAP_ARCH/$SNAP_ARCH/g" $app.yaml > $build_dir/snapcraft.yaml

(cd $build_dir && snapcraft)
mv $build_dir/*.snap build
done
done
9 changes: 9 additions & 0 deletions snap/build-scripts/docker-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -eux

docker build -f "./Dockerfile.$(uname -m)" -t docker-build .
docker run --rm -v $PWD/build:/code/build \
-e KUBE_ARCH=$KUBE_ARCH \
-e KUBE_VERSION=$KUBE_VERSION \
docker-build "$@"
38 changes: 38 additions & 0 deletions snap/kube-apiserver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: kube-apiserver
architectures: ['$SNAP_ARCH']
version: '$KUBE_VERSION'
summary: kube-apiserver
description: kube-apiserver
grade: stable
confinement: strict

apps:
daemon:
command: run-with-config-args kube-apiserver-wrapper
daemon: simple
plugs:
- home
- network
- network-bind
kube-apiserver:
command: kube-apiserver
plugs:
- home
- network
- network-bind
parts:
kube-apiserver:
plugin: dump
source: .
override-build: |
set -eu
cp $KUBE_SNAP_BINS/$KUBE_ARCH/kube-apiserver .
cp $KUBE_SNAP_ROOT/shared/run-with-config-args .
cp $KUBE_SNAP_ROOT/kube-apiserver/kube-apiserver-wrapper .
$KUBE_SNAP_ROOT/shared/generate-configure-hook kube-apiserver

# --v is missing from help output in 1.12
alias add-arg=$KUBE_SNAP_ROOT/shared/add-arg-to-configure-hook
add-arg string v

snapcraftctl build
10 changes: 10 additions & 0 deletions snap/kube-apiserver/kube-apiserver-wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
set -eu

if [ -e "$SNAP_COMMON/environment" ]; then
set -a # enable auto-export
. "$SNAP_COMMON/environment"
set +a # disable auto-export
fi

exec "$SNAP/kube-apiserver" "$@"
46 changes: 46 additions & 0 deletions snap/kube-controller-manager.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: kube-controller-manager
architectures: ['$SNAP_ARCH']
version: '$KUBE_VERSION'
summary: kube-controller-manager
description: kube-controller-manager
grade: stable
confinement: strict

apps:
daemon:
command: run-with-config-args kube-controller-manager-wrapper
daemon: simple
plugs:
- network
- network-bind
- home
kube-controller-manager:
command: kube-controller-manager-wrapper
plugs:
- network
- network-bind
- home
parts:
kube-controller-manager:
plugin: dump
source: .
stage-packages:
- ceph-common:$SNAP_ARCH
override-build: |
set -eu
cp $KUBE_SNAP_BINS/$KUBE_ARCH/kube-controller-manager .
cp $KUBE_SNAP_ROOT/shared/run-with-config-args .
cp $KUBE_SNAP_ROOT/kube-controller-manager/kube-controller-manager-wrapper .
$KUBE_SNAP_ROOT/shared/generate-configure-hook kube-controller-manager

# --v is missing from help output in 1.12
alias add-arg=$KUBE_SNAP_ROOT/shared/add-arg-to-configure-hook
add-arg string v

# By mistake --service-account-private-key-file was marked as deprecated
# https://github.com/kubernetes/kubernetes/pull/62722
# Should be fixed soon by https://github.com/kubernetes/kubernetes/pull/60270/files#diff-fc9db90cc6b68d7c3ca838a8512447e9R61
# But until then, we need to do 1.11 testing
add-arg string service-account-private-key-file

snapcraftctl build
13 changes: 13 additions & 0 deletions snap/kube-controller-manager/kube-controller-manager-wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
set -eu

# Set CEPH_CONF so `rbd` doesn't try to look in /etc/ceph and error out
export CEPH_CONF="$SNAP_USER_DATA/ceph/ceph.conf"

if [ -e "$SNAP_COMMON/environment" ]; then
set -a # enable auto-export
. "$SNAP_COMMON/environment"
set +a # disable auto-export
fi

exec "$SNAP/kube-controller-manager" "$@"
37 changes: 37 additions & 0 deletions snap/kube-proxy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: kube-proxy
architectures: ['$SNAP_ARCH']
version: '$KUBE_VERSION'
summary: Kubernetes network proxy runs on each node.
description: |
The Kubernetes network proxy runs on each node. This reflects services as
defined in the Kubernetes API on each node and can do simple TCP,UDP stream
forwarding or round robin TCP,UDP forwarding across a set of backends. Service
cluster ips and ports are currently found through Docker-links-compatible
environment variables specifying ports opened by the service proxy. There is
an optional addon that provides cluster DNS for these cluster IPs. The user
must create a service with the apiserver API to configure the proxy.
grade: stable
confinement: classic

apps:
daemon:
command: run-with-config-args kube-proxy-wrapper
daemon: simple
kube-proxy:
command: kube-proxy

parts:
kube-proxy:
plugin: dump
build-attributes: [no-patchelf]
source: .
stage-packages:
- conntrack:$SNAP_ARCH
override-build: |
set -eu
cp $KUBE_SNAP_BINS/$KUBE_ARCH/kube-proxy .
cp $KUBE_SNAP_ROOT/shared/run-with-config-args .
cp $KUBE_SNAP_ROOT/kube-proxy/kube-proxy-wrapper .
$KUBE_SNAP_ROOT/shared/generate-configure-hook kube-proxy

snapcraftctl build
12 changes: 12 additions & 0 deletions snap/kube-proxy/kube-proxy-wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
set -eu

export PATH=$PATH:$SNAP/usr/sbin

if [ -e "$SNAP_COMMON/environment" ]; then
set -a # enable auto-export
. "$SNAP_COMMON/environment"
set +a # disable auto-export
fi

exec "$SNAP/kube-proxy" "$@"
Loading