Skip to content

Commit

Permalink
Added version.json to kicbase image and version validation to start.go.
Browse files Browse the repository at this point in the history
Added CHANGELOG to kicbase and ISO.
Updated gh to latest version 2.18.1.
  • Loading branch information
ckannon committed Nov 2, 2022
1 parent 2fed9a8 commit 320c41f
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 20 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ _testmain.go
/deploy/iso/minikube-iso/board/minikube/x86_64/rootfs-overlay/usr/bin/auto-pause
/deploy/iso/minikube-iso/board/minikube/aarch64/rootfs-overlay/usr/bin/auto-pause
/deploy/iso/minikube-iso/Config.in
/deploy/iso/minikube-iso/CHANGELOG
/deploy/kicbase/auto-pause
/deploy/kicbase/CHANGELOG
/deploy/addons/auto-pause/auto-pause-hook
/out
/_gopath

#iso version file
deploy/iso/minikube-iso/board/minikube/x86_64/rootfs-overlay/etc/VERSION
deploy/iso/minikube-iso/board/minikube/aarch64/rootfs-overlay/etc/VERSION
deploy/iso/minikube-iso/board/minikube/x86_64/rootfs-overlay/etc/CHANGELOG
deploy/iso/minikube-iso/board/minikube/aarch64/rootfs-overlay/etc/CHANGELOG
deploy/iso/minikube-iso/board/minikube/x86_64/rootfs-overlay/version.json
deploy/iso/minikube-iso/board/minikube/aarch64/rootfs-overlay/version.json

/minikube

Expand Down
24 changes: 15 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ REGISTRY ?= gcr.io/k8s-minikube
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
COMMIT ?= $(if $(shell git status --porcelain --untracked-files=no),"${COMMIT_NO}-dirty","${COMMIT_NO}")
COMMIT_SHORT = $(shell git rev-parse --short HEAD 2> /dev/null || true)
COMMIT_NOQUOTES := $(patsubst "%",%,$(COMMIT))
# source code for image: https://github.com/spowelljr/xcgo
HYPERKIT_BUILD_IMAGE ?= gcr.io/k8s-minikube/xcgo:go1.17

Expand All @@ -74,7 +75,7 @@ MINIKUBE_UPLOAD_LOCATION := gs://${MINIKUBE_BUCKET}
MINIKUBE_RELEASES_URL=https://github.com/kubernetes/minikube/releases/download

KERNEL_VERSION ?= 5.10.57
# latest from https://github.com/golangci/golangci-lint/releases
# latest from https://github.com/golangci/golangci-lint/releases
# update this only by running `make update-golint-version`
GOLINT_VERSION ?= v1.50.1
# Limit number of default jobs, to avoid the CI builds running out of memory
Expand Down Expand Up @@ -159,6 +160,9 @@ HYPERKIT_LDFLAGS := -X k8s.io/minikube/pkg/drivers/hyperkit.version=$(VERSION) -
# autopush artefacts
AUTOPUSH ?=

# version file json
VERSION_JSON := "{\"iso_version\": \"$(ISO_VERSION)\", \"kicbase_version\": \"$(KIC_VERSION)\", \"minikube_version\": \"$(VERSION)\", \"commit\": \"$(COMMIT_NOQUOTES)\"}"

# don't ask for user confirmation
IN_CI := false

Expand Down Expand Up @@ -286,6 +290,7 @@ minikube-iso-amd64: minikube-iso-x86_64
minikube-iso-arm64: minikube-iso-aarch64

minikube-iso-%: deploy/iso/minikube-iso/board/minikube/%/rootfs-overlay/usr/bin/auto-pause # build minikube iso
echo $(VERSION_JSON) > deploy/iso/minikube-iso/board/minikube/$*/rootfs-overlay/version.json
echo $(ISO_VERSION) > deploy/iso/minikube-iso/board/minikube/$*/rootfs-overlay/etc/VERSION
cp deploy/iso/minikube-iso/arch/$*/Config.in.tmpl deploy/iso/minikube-iso/Config.in
if [ ! -d $(BUILD_DIR)/buildroot ]; then \
Expand Down Expand Up @@ -419,7 +424,7 @@ out/coverage.html: out/coverage.out
$(if $(quiet),@echo " COVER $@")
$(Q)go tool cover -html=$< -o $@

.PHONY: extract
.PHONY: extract
extract: ## extract internationalization words for translations
go run cmd/extract/extract.go

Expand Down Expand Up @@ -449,7 +454,8 @@ checksum: ## Generate checksums
for f in out/minikube-amd64.iso out/minikube-arm64.iso out/minikube-linux-amd64 out/minikube-linux-arm \
out/minikube-linux-arm64 out/minikube-linux-ppc64le out/minikube-linux-s390x \
out/minikube-darwin-amd64 out/minikube-darwin-arm64 out/minikube-windows-amd64.exe \
out/docker-machine-driver-kvm2 out/docker-machine-driver-kvm2-amd64 out/docker-machine-driver-kvm2-arm64 \
out/docker-machine-driver-kvm2 out/docker
-machine-driver-kvm2-amd64 out/docker-machine-driver-kvm2-arm64 \
out/docker-machine-driver-hyperkit; do \
if [ -f "$${f}" ]; then \
openssl sha256 "$${f}" | awk '{print $$2}' > "$${f}.sha256" ; \
Expand Down Expand Up @@ -562,13 +568,13 @@ out/minikube_$(DEB_VERSION)-$(DEB_REVISION)_%.deb: out/minikube-linux-%
sed -E -i 's/--VERSION--/'$(DEB_VERSION)'/g' $(DEB_PACKAGING_DIRECTORY_$*)/DEBIAN/control
sed -E -i 's/--REVISION--/'$(DEB_REVISION)'/g' $(DEB_PACKAGING_DIRECTORY_$*)/DEBIAN/control
sed -E -i 's/--ARCH--/'$*'/g' $(DEB_PACKAGING_DIRECTORY_$*)/DEBIAN/control

if [ "$*" = "amd64" ]; then \
sed -E -i 's/--RECOMMENDS--/virtualbox/' $(DEB_PACKAGING_DIRECTORY_$*)/DEBIAN/control; \
else \
sed -E -i '/Recommends: --RECOMMENDS--/d' $(DEB_PACKAGING_DIRECTORY_$*)/DEBIAN/control; \
fi

mkdir -p $(DEB_PACKAGING_DIRECTORY_$*)/usr/bin
cp $< $(DEB_PACKAGING_DIRECTORY_$*)/usr/bin/minikube
fakeroot dpkg-deb --build $(DEB_PACKAGING_DIRECTORY_$*) $@
Expand Down Expand Up @@ -714,7 +720,7 @@ update-cri-dockerd:

.PHONY: local-kicbase
local-kicbase: ## Builds the kicbase image and tags it local/kicbase:latest and local/kicbase:$(KIC_VERSION)-$(COMMIT_SHORT)
docker build -f ./deploy/kicbase/Dockerfile -t local/kicbase:$(KIC_VERSION) --build-arg COMMIT_SHA=${VERSION}-$(COMMIT) --cache-from $(KICBASE_IMAGE_GCR) .
docker build -f ./deploy/kicbase/Dockerfile -t local/kicbase:$(KIC_VERSION) --build-arg VERSION_JSON=$(VERSION_JSON) --build-arg COMMIT_SHA=${VERSION}-$(COMMIT_NOQUOTES) --cache-from $(KICBASE_IMAGE_GCR) .
docker tag local/kicbase:$(KIC_VERSION) local/kicbase:latest
docker tag local/kicbase:$(KIC_VERSION) local/kicbase:$(KIC_VERSION)-$(COMMIT_SHORT)

Expand All @@ -729,9 +735,9 @@ local-kicbase-debug: local-kicbase ## Builds a local kicbase image and switches

.PHONY: build-kic-base-image
build-kic-base-image: docker-multi-arch-builder ## Build multi-arch local/kicbase:latest
env $(X_BUILD_ENV) docker buildx build -f ./deploy/kicbase/Dockerfile --builder $(X_DOCKER_BUILDER) --platform $(KICBASE_ARCH) $(addprefix -t ,$(KICBASE_IMAGE_REGISTRIES)) --load --build-arg COMMIT_SHA=${VERSION}-$(COMMIT) .
env $(X_BUILD_ENV) docker buildx build -f ./deploy/kicbase/Dockerfile --builder $(X_DOCKER_BUILDER) --platform $(KICBASE_ARCH) $(addprefix -t ,$(KICBASE_IMAGE_REGISTRIES)) --load --build-arg VERSION_JSON=$(VERSION_JSON) --build-arg COMMIT_SHA=${VERSION}-$(COMMIT_NOQUOTES) .

.PHONY: push-kic-base-image
.PHONY: push-kic-base-image
push-kic-base-image: docker-multi-arch-builder ## Push multi-arch local/kicbase:latest to all remote registries
ifdef AUTOPUSH
docker login gcr.io/k8s-minikube
Expand All @@ -744,7 +750,7 @@ ifndef CIBUILD
$(call user_confirm, 'Are you sure you want to push $(KICBASE_IMAGE_REGISTRIES) ?')
endif
./deploy/kicbase/build_auto_pause.sh $(KICBASE_ARCH)
env $(X_BUILD_ENV) docker buildx build -f ./deploy/kicbase/Dockerfile --builder $(X_DOCKER_BUILDER) --platform $(KICBASE_ARCH) $(addprefix -t ,$(KICBASE_IMAGE_REGISTRIES)) --push --build-arg COMMIT_SHA=${VERSION}-$(COMMIT) --build-arg PREBUILT_AUTO_PAUSE=true .
env $(X_BUILD_ENV) docker buildx build -f ./deploy/kicbase/Dockerfile --builder $(X_DOCKER_BUILDER) --platform $(KICBASE_ARCH) $(addprefix -t ,$(KICBASE_IMAGE_REGISTRIES)) --push --build-arg VERSION_JSON=$(VERSION_JSON) --build-arg COMMIT_SHA=${VERSION}-$(COMMIT_NOQUOTES) --build-arg PREBUILT_AUTO_PAUSE=true .

out/preload-tool:
go build -ldflags="$(MINIKUBE_LDFLAGS)" -o $@ ./hack/preload-images/*.go
Expand Down
29 changes: 29 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/spf13/viper"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"k8s.io/minikube/pkg/minikube/command"

"k8s.io/klog/v2"
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
Expand Down Expand Up @@ -79,6 +80,13 @@ import (
"k8s.io/minikube/pkg/version"
)

type versionJSON struct {
IsoVersion string `json:"iso_version"`
KicbaseVersion string `json:"kicbase_version"`
MinikubeVersion string `json:"minikube_version"`
Commit string `json:"commit"`
}

var (
registryMirror []string
insecureRegistry []string
Expand Down Expand Up @@ -146,6 +154,7 @@ func runStart(cmd *cobra.Command, args []string) {
exit.Message(reason.Usage, "error initializing tracing: {{.Error}}", out.V{"Error": err.Error()})
}
defer pkgtrace.Cleanup()

displayVersion(version.GetVersion())
go download.CleanUpOlderPreloads()

Expand Down Expand Up @@ -250,6 +259,8 @@ func runStart(cmd *cobra.Command, args []string) {
}
}

validateKicBaseVersion(starter.Runner)

if existing != nil && driver.IsKIC(existing.Driver) {
if viper.GetBool(createMount) {
old := ""
Expand Down Expand Up @@ -359,6 +370,24 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing *
}, nil
}

func validateKicBaseVersion(r command.Runner) {
res, err := r.RunCmd(exec.Command("cat", "/version.json"))
if err != nil {
out.WarningT("Unable to open version.json: {{.error}}", out.V{"error": err})
return
}

var versionDetails versionJSON
if err := json.Unmarshal(res.Stdout.Bytes(), &versionDetails); err != nil {
out.WarningT("Unable to parse version.json: {{.error}}, json: {{.json}}", out.V{"error": err, "json": res.Stdout.String()})
return
}

if versionDetails.MinikubeVersion != version.GetVersion() {
out.WarningT("Image was not built for the current minikube version. To resolve this you can delete and recreate your minikube cluster using the latest images. Expected minikube version: {{.imageMinikubeVersion}} -> Actual minikube version: {{.minikubeVersion}}", out.V{"imageMinikubeVersion": versionDetails.MinikubeVersion, "minikubeVersion": version.GetVersion()})
}
}

func startWithDriver(cmd *cobra.Command, starter node.Starter, existing *config.ClusterConfig) (*kubeconfig.Settings, error) {
kubeconfig, err := node.Start(starter, true)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions deploy/iso/minikube-iso/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ RUN apt-get update \
mkisofs \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir /app
RUN chmod 777 /app

RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8

Expand Down
9 changes: 7 additions & 2 deletions deploy/kicbase/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ COPY deploy/addons ./deploy/addons
COPY translations/ ./translations
COPY third_party/ ./third_party
COPY go.mod go.sum ./

ARG TARGETARCH
ENV GOARCH=${TARGETARCH}
ARG PREBUILT_AUTO_PAUSE
Expand All @@ -53,9 +54,9 @@ COPY deploy/kicbase/containerd.toml /etc/containerd/config.toml
COPY deploy/kicbase/containerd_docker_io_hosts.toml /etc/containerd/certs.d/docker.io/hosts.toml
COPY deploy/kicbase/clean-install /usr/local/bin/clean-install
COPY deploy/kicbase/entrypoint /usr/local/bin/entrypoint
COPY deploy/kicbase/CHANGELOG ./CHANGELOG
COPY --from=auto-pause /src/cmd/auto-pause/auto-pause-${TARGETARCH} /bin/auto-pause


# Install dependencies, first from apt, then from release tarballs.
# NOTE: we use one RUN to minimize layers.
#
Expand Down Expand Up @@ -132,7 +133,7 @@ RUN echo "Installing cri-dockerd" && \
# install system requirements from the regular distro repositories
RUN clean-install \
lz4 \
gnupg \
gnupg \
sudo \
openssh-server \
dnsutils \
Expand Down Expand Up @@ -199,6 +200,10 @@ RUN export ARCH=$(dpkg --print-architecture | sed 's/ppc64el/ppc64le/') && \
echo "d /run/podman 0770 root podman" > /etc/tmpfiles.d/podman.conf && \
systemd-tmpfiles --create; fi

# install version.json
ARG VERSION_JSON
RUN echo "${VERSION_JSON}" > /version.json

# automount service
COPY deploy/kicbase/automount/minikube-automount /usr/sbin/minikube-automount
COPY deploy/kicbase/automount/minikube-automount.service /usr/lib/systemd/system/minikube-automount.service
Expand Down
33 changes: 33 additions & 0 deletions hack/jenkins/build_changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script can take the following env variables
# ARGS: args to pass into the make rule
# ISO_BUCKET = the bucket location to upload the ISO (e.g. minikube-builds/PR_NUMBER)
# ISO_VERSION = the suffix for the iso (i.e. minikube-$(ISO_VERSION).iso)

set -x -o pipefail

if (($# < 1)); then
echo "ERROR: given ! ($#) parameters but expected 1."
echo "USAGE: ./build_changelog.sh OUTPUT_LOCATION"
exit 1
fi

# Make sure gh is installed and configured
#./hack/jenkins/installers/check_install_gh.sh
OUTPUT_LOCATION=${1}
gh search prs --merged --sort updated --limit 100 --repo kubernetes/minikube --json number,title,closedAt --template '{{range .}}{{tablerow (printf "#%v" .number | autocolor "green") .title (timeago .closedAt)}}{{end}}' > ${OUTPUT_LOCATION}
6 changes: 4 additions & 2 deletions hack/jenkins/build_iso.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ set -x -o pipefail
# Make sure golang is installed and configured
./hack/jenkins/installers/check_install_golang.sh "/usr/local"

# Generate changelog for latest github PRs merged
./hack/jenkins/build_changelog.sh ./deploy/iso/minikube-iso/CHANGELOG

# Make sure all required packages are installed
sudo apt-get update
sudo apt-get -y install build-essential unzip rsync bc python3 p7zip-full
Expand All @@ -37,7 +40,6 @@ if [[ -z $ISO_VERSION ]]; then
now=$(date +%s)
export ISO_VERSION=$IV-$now-$ghprbPullId
export ISO_BUCKET=minikube-builds/iso/$ghprbPullId
echo "#$ghprPullId - $ghprPullTitle" >> deploy/iso/minikube-iso/CHANGELOG
else
release=true
export ISO_VERSION
Expand Down Expand Up @@ -109,4 +111,4 @@ else
git push -f minikube-bot ${branch}

gh pr create --fill --base master --head minikube-bot:${branch}
fi
fi
10 changes: 5 additions & 5 deletions hack/jenkins/installers/check_install_gh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
set -eux -o pipefail

echo "Installing latest version of gh"
curl -qLO "https://github.com/cli/cli/releases/download/v1.6.2/gh_1.6.2_linux_amd64.tar.gz"
tar -xf gh_1.6.2_linux_amd64.tar.gz &&
sudo mv gh_1.6.2_linux_amd64/bin/gh /usr/local/bin/gh
rm gh_1.6.2_linux_amd64.tar.gz
rm -rf gh_1.6.2_linux_amd64
curl -qLO "https://github.com/cli/cli/releases/download/v2.18.1/gh_2.18.1_linux_amd64.tar.gz"
tar -xf gh_2.18.1_linux_amd64.tar.gz &&
sudo mv gh_2.18.1_linux_amd64/bin/gh /usr/local/bin/gh
rm gh_2.18.1_linux_amd64.tar.gz
rm -rf gh_2.18.1_linux_amd64

echo "Authorizing bot with gh"
echo "${access_token}" | gh auth login --with-token
Expand Down
2 changes: 2 additions & 0 deletions hack/jenkins/kicbase_auto_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ docker login -u ${DOCKERHUB_USER} -p ${DOCKERHUB_PASS}
# Make sure golang is installed and configured
./hack/jenkins/installers/check_install_golang.sh "/usr/local" || true

./hack/jenkins/build_changelog.sh ./deploy/kicbase/CHANGELOG

export GOBIN=/usr/local/go/bin
export PATH=$PATH:$GOBIN

Expand Down

0 comments on commit 320c41f

Please sign in to comment.