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
  • Loading branch information
ckannon committed Oct 31, 2022
1 parent 2fed9a8 commit 70c85bc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
21 changes: 13 additions & 8 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 @@ -562,13 +567,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 +719,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 +734,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 +749,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
27 changes: 27 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,22 @@ 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})
}

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

if versionDetails.MinikubeVersion != version.GetVersion() {
out.WarningT("Image was not built for the current minikube version: 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
6 changes: 5 additions & 1 deletion deploy/kicbase/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,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 +199,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

0 comments on commit 70c85bc

Please sign in to comment.