From bc6673e3f68c94c1dfef737e7360e238964fbfb1 Mon Sep 17 00:00:00 2001 From: Aleksei Sizov Date: Thu, 12 Dec 2024 20:47:18 -0500 Subject: [PATCH] Fix k0s installation in airgap env --- Makefile | 12 +++++++++-- hack/k0s-ag-image/Dockerfile | 19 +++++++++++++++++ hack/k0s-ag-image/default.conf | 21 +++++++++++++++++++ scripts/bundle-images.sh | 2 +- .../cluster/vsphere-hosted-cp/Chart.yaml | 2 +- .../templates/k0sworkerconfigtemplate.yaml | 7 +++++++ .../vsphere-hosted-cp/values.schema.json | 12 +++++++++++ .../cluster/vsphere-hosted-cp/values.yaml | 4 ++++ .../cluster/vsphere-standalone-cp/Chart.yaml | 2 +- .../templates/k0scontrolplane.yaml | 7 +++++++ .../templates/k0sworkerconfigtemplate.yaml | 7 +++++++ .../vsphere-standalone-cp/values.schema.json | 12 +++++++++++ .../cluster/vsphere-standalone-cp/values.yaml | 4 ++++ ...-0-3.yaml => vsphere-hosted-cp-0-0-4.yaml} | 4 ++-- ....yaml => vsphere-standalone-cp-0-0-4.yaml} | 4 ++-- 15 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 hack/k0s-ag-image/Dockerfile create mode 100644 hack/k0s-ag-image/default.conf rename templates/provider/hmc-templates/files/templates/{vsphere-hosted-cp-0-0-3.yaml => vsphere-hosted-cp-0-0-4.yaml} (83%) rename templates/provider/hmc-templates/files/templates/{vsphere-standalone-cp-0-0-3.yaml => vsphere-standalone-cp-0-0-4.yaml} (83%) diff --git a/Makefile b/Makefile index 230fbd88..127c2c98 100644 --- a/Makefile +++ b/Makefile @@ -134,8 +134,11 @@ add-license: addlicense TEMPLATES_DIR := templates PROVIDER_TEMPLATES_DIR := $(TEMPLATES_DIR)/provider export PROVIDER_TEMPLATES_DIR +CLUSTER_TEMPLATES_DIR := $(TEMPLATES_DIR)/cluster CHARTS_PACKAGE_DIR ?= $(LOCALBIN)/charts EXTENSION_CHARTS_PACKAGE_DIR ?= $(LOCALBIN)/charts/extensions +K0S_VERSION = $(shell $(YQ) '.k0s.version' $(CLUSTER_TEMPLATES_DIR)/vsphere-standalone-cp/values.yaml) +K0S_AG_IMAGE = k0s-ag-image:$(subst +,-,$(K0S_VERSION)) $(EXTENSION_CHARTS_PACKAGE_DIR): | $(LOCALBIN) mkdir -p $(EXTENSION_CHARTS_PACKAGE_DIR) $(CHARTS_PACKAGE_DIR): | $(LOCALBIN) @@ -156,8 +159,13 @@ collect-airgap-providers: yq helm clusterctl $(PROVIDER_TEMPLATES_DIR) $(LOCALBI helm-package: $(CHARTS_PACKAGE_DIR) $(EXTENSION_CHARTS_PACKAGE_DIR) helm collect-airgap-providers @make $(patsubst %,package-%-tmpl,$(TEMPLATE_FOLDERS)) -bundle-images: dev-apply $(IMAGES_PACKAGE_DIR) ## Create a tarball with all images used by HMC. - @BUNDLE_TARBALL=$(IMAGES_PACKAGE_DIR)/hmc-images-$(VERSION).tgz EXTENSIONS_BUNDLE_TARBALL=$(IMAGES_PACKAGE_DIR)/hmc-extension-images-$(VERSION).tgz IMG=$(IMG) KUBECTL=$(KUBECTL) YQ=$(YQ) HELM=$(HELM) NAMESPACE=$(NAMESPACE) TEMPLATES_DIR=$(TEMPLATES_DIR) KIND_CLUSTER_NAME=$(KIND_CLUSTER_NAME) $(SHELL) $(CURDIR)/scripts/bundle-images.sh +.PHONY: k0s-image +k0s-image: + export DOCKER_BUILDKIT=1 + $(CONTAINER_TOOL) build --build-arg K0S_VERSION=$(K0S_VERSION) -t $(K0S_AG_IMAGE) hack/k0s-ag-image + +bundle-images: dev-apply $(IMAGES_PACKAGE_DIR) k0s-image ## Create a tarball with all images used by HMC. + @BUNDLE_TARBALL=$(IMAGES_PACKAGE_DIR)/hmc-images-$(VERSION).tgz EXTENSIONS_BUNDLE_TARBALL=$(IMAGES_PACKAGE_DIR)/hmc-extension-images-$(VERSION).tgz IMG=$(IMG) KUBECTL=$(KUBECTL) YQ=$(YQ) HELM=$(HELM) NAMESPACE=$(NAMESPACE) TEMPLATES_DIR=$(TEMPLATES_DIR) KIND_CLUSTER_NAME=$(KIND_CLUSTER_NAME) K0S_AG_IMAGE=$(K0S_AG_IMAGE) $(SHELL) $(CURDIR)/scripts/bundle-images.sh airgap-package: bundle-images ## Create a tarball with all images and Helm charts used by HMC, useful for deploying in air-gapped environments. @TEMPLATES_DIR=$(TEMPLATES_DIR) EXTENSION_CHARTS_PACKAGE_DIR=$(EXTENSION_CHARTS_PACKAGE_DIR) HELM=$(HELM) YQ=$(YQ) $(SHELL) $(CURDIR)/scripts/package-k0s-extensions-helm.sh diff --git a/hack/k0s-ag-image/Dockerfile b/hack/k0s-ag-image/Dockerfile new file mode 100644 index 00000000..f0bf57a9 --- /dev/null +++ b/hack/k0s-ag-image/Dockerfile @@ -0,0 +1,19 @@ +# Copyright 2024 +# +# 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. + +FROM nginx:1.27 +ARG K0S_VERSION +ADD default.conf /etc/nginx/conf.d/default.conf +ADD --chown=nginx https://github.com/k0sproject/k0s/releases/download/${K0S_VERSION}/k0s-${K0S_VERSION}-amd64 /var/www/html/k0s +ADD --chown=nginx https://github.com/k0sproject/k0s/releases/download/${K0S_VERSION}/k0s-airgap-bundle-${K0S_VERSION}-amd64 /var/www/html/k0s-airgap-bundle diff --git a/hack/k0s-ag-image/default.conf b/hack/k0s-ag-image/default.conf new file mode 100644 index 00000000..ccc4bc98 --- /dev/null +++ b/hack/k0s-ag-image/default.conf @@ -0,0 +1,21 @@ +server { + proxy_max_temp_file_size 0; + listen 80; + sendfile on; + tcp_nopush on; + tcp_nodelay on; + server_name localhost; + + keepalive_timeout 70; + + root /var/www/html; + location / { + } + + client_max_body_size 512m; + + location /heathz { + return 200 'OK'; + } + +} diff --git a/scripts/bundle-images.sh b/scripts/bundle-images.sh index 3db64549..fa54c429 100755 --- a/scripts/bundle-images.sh +++ b/scripts/bundle-images.sh @@ -21,7 +21,7 @@ # Usage: make bundle-images # This script should not be run directly. Use 'make bundle-images' instead. LABEL_KEY="cluster.x-k8s.io/provider" -IMAGES_BUNDLED="$IMG" +IMAGES_BUNDLED="$IMG $K0S_AG_IMAGE" EXTENSION_IMAGES_BUNDLED="" echo -e "Bundling images for HMC, this may take awhile...\n" diff --git a/templates/cluster/vsphere-hosted-cp/Chart.yaml b/templates/cluster/vsphere-hosted-cp/Chart.yaml index 30c953f1..4449eb3d 100644 --- a/templates/cluster/vsphere-hosted-cp/Chart.yaml +++ b/templates/cluster/vsphere-hosted-cp/Chart.yaml @@ -7,7 +7,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.0.3 +version: 0.0.4 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. diff --git a/templates/cluster/vsphere-hosted-cp/templates/k0sworkerconfigtemplate.yaml b/templates/cluster/vsphere-hosted-cp/templates/k0sworkerconfigtemplate.yaml index 37e09dd2..942b18eb 100644 --- a/templates/cluster/vsphere-hosted-cp/templates/k0sworkerconfigtemplate.yaml +++ b/templates/cluster/vsphere-hosted-cp/templates/k0sworkerconfigtemplate.yaml @@ -6,9 +6,16 @@ spec: template: spec: version: {{ .Values.k0s.version }} + {{- if .Values.airgap }} + downloadURL: {{ required ".Values.k0s.downloadURL is required on airgap deployment" .Values.k0s.downloadURL }} + {{- end }} files: - path: /home/{{ .Values.ssh.user }}/.ssh/authorized_keys permissions: "0600" content: "{{ trim .Values.ssh.publicKey }}" preStartCommands: + {{- if .Values.airgap }} + - mkdir -p /var/lib/k0s/images + - curl -fsL {{ required ".Values.k0s.bundleURL is required on airgap deployment" .Values.k0s.bundleURL }} -o /var/lib/k0s/images/k0s-airgap-bundle + {{- end }} - chown {{ .Values.ssh.user }} /home/{{ .Values.ssh.user }}/.ssh/authorized_keys diff --git a/templates/cluster/vsphere-hosted-cp/values.schema.json b/templates/cluster/vsphere-hosted-cp/values.schema.json index 1d89a3f2..c4c8137d 100644 --- a/templates/cluster/vsphere-hosted-cp/values.schema.json +++ b/templates/cluster/vsphere-hosted-cp/values.schema.json @@ -26,6 +26,10 @@ "type": "number", "minimum": 1 }, + "airgap": { + "description": "Cluster created in airgap env", + "type": "boolean" + }, "clusterNetwork": { "type": "object", "properties": { @@ -146,6 +150,14 @@ "version":{ "description": "K0s version to use", "type": "string" + }, + "downloadURL":{ + "description": "K0s download URL", + "type": "string" + }, + "bundleURL":{ + "description": "K0s airgap bundle URL", + "type": "string" } } } diff --git a/templates/cluster/vsphere-hosted-cp/values.yaml b/templates/cluster/vsphere-hosted-cp/values.yaml index 187774dc..161fc9bd 100644 --- a/templates/cluster/vsphere-hosted-cp/values.yaml +++ b/templates/cluster/vsphere-hosted-cp/values.yaml @@ -42,9 +42,13 @@ k0smotron: # K0s parameters k0s: version: v1.31.1+k0s.1 + downloadURL: "" + bundleURL: "" # extensions defines custom Helm and image repositories to use for pulling # k0s extensions. extensions: chartRepository: "" imageRepository: "" + +airgap: false diff --git a/templates/cluster/vsphere-standalone-cp/Chart.yaml b/templates/cluster/vsphere-standalone-cp/Chart.yaml index bce65dc3..1c17ffd1 100644 --- a/templates/cluster/vsphere-standalone-cp/Chart.yaml +++ b/templates/cluster/vsphere-standalone-cp/Chart.yaml @@ -6,7 +6,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.0.3 +version: 0.0.4 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. diff --git a/templates/cluster/vsphere-standalone-cp/templates/k0scontrolplane.yaml b/templates/cluster/vsphere-standalone-cp/templates/k0scontrolplane.yaml index e2011291..7d5b3b55 100644 --- a/templates/cluster/vsphere-standalone-cp/templates/k0scontrolplane.yaml +++ b/templates/cluster/vsphere-standalone-cp/templates/k0scontrolplane.yaml @@ -6,11 +6,18 @@ spec: replicas: {{ .Values.controlPlaneNumber }} version: {{ .Values.k0s.version }} k0sConfigSpec: + {{- if .Values.airgap }} + downloadURL: {{ required ".Values.k0s.downloadURL is required on airgap deployment" .Values.k0s.downloadURL }} + {{- end }} files: - path: /home/{{ .Values.controlPlane.ssh.user }}/.ssh/authorized_keys permissions: "0600" content: "{{ trim .Values.controlPlane.ssh.publicKey }}" preStartCommands: + {{- if .Values.airgap }} + - mkdir -p /var/lib/k0s/images + - curl -fsL {{ required ".Values.k0s.bundleURL is required on airgap deployment" .Values.k0s.bundleURL }} -o /var/lib/k0s/images/k0s-airgap-bundle + {{- end }} - chown {{ .Values.controlPlane.ssh.user }} /home/{{ .Values.controlPlane.ssh.user }}/.ssh/authorized_keys - sed -i 's/"externalAddress":"{{ .Values.controlPlaneEndpointIP }}",//' /etc/k0s.yaml args: diff --git a/templates/cluster/vsphere-standalone-cp/templates/k0sworkerconfigtemplate.yaml b/templates/cluster/vsphere-standalone-cp/templates/k0sworkerconfigtemplate.yaml index 332f5212..17638faf 100644 --- a/templates/cluster/vsphere-standalone-cp/templates/k0sworkerconfigtemplate.yaml +++ b/templates/cluster/vsphere-standalone-cp/templates/k0sworkerconfigtemplate.yaml @@ -6,9 +6,16 @@ spec: template: spec: version: {{ .Values.k0s.version }} + {{- if .Values.airgap }} + downloadURL: {{ required ".Values.k0s.downloadURL is required on airgap deployment" .Values.k0s.downloadURL }} + {{- end }} files: - path: /home/{{ .Values.worker.ssh.user }}/.ssh/authorized_keys permissions: "0600" content: "{{ trim .Values.worker.ssh.publicKey }}" preStartCommands: + {{- if .Values.airgap }} + - mkdir -p /var/lib/k0s/images + - curl -fsL {{ required ".Values.k0s.bundleURL is required on airgap deployment" .Values.k0s.bundleURL }} -o /var/lib/k0s/images/k0s-airgap-bundle + {{- end }} - chown {{ .Values.worker.ssh.user }} /home/{{ .Values.worker.ssh.user }}/.ssh/authorized_keys diff --git a/templates/cluster/vsphere-standalone-cp/values.schema.json b/templates/cluster/vsphere-standalone-cp/values.schema.json index f2be23fb..0283e145 100644 --- a/templates/cluster/vsphere-standalone-cp/values.schema.json +++ b/templates/cluster/vsphere-standalone-cp/values.schema.json @@ -20,6 +20,10 @@ "type": "number", "minimum": 1 }, + "airgap": { + "description": "Cluster created in airgap env", + "type": "boolean" + }, "clusterNetwork": { "type": "object", "properties": { @@ -198,6 +202,14 @@ "version":{ "description": "K0s version to use", "type": "string" + }, + "downloadURL":{ + "description": "K0s download URL", + "type": "string" + }, + "bundleURL":{ + "description": "K0s airgap bundle URL", + "type": "string" } } } diff --git a/templates/cluster/vsphere-standalone-cp/values.yaml b/templates/cluster/vsphere-standalone-cp/values.yaml index eb64d708..0236a8c0 100644 --- a/templates/cluster/vsphere-standalone-cp/values.yaml +++ b/templates/cluster/vsphere-standalone-cp/values.yaml @@ -46,9 +46,13 @@ worker: # K0s parameters k0s: version: v1.31.1+k0s.1 + downloadURL: "" + bundleURL: "" # extensions defines custom Helm and image repositories to use for pulling # k0s extensions. extensions: chartRepository: "" imageRepository: "" + +airgap: false diff --git a/templates/provider/hmc-templates/files/templates/vsphere-hosted-cp-0-0-3.yaml b/templates/provider/hmc-templates/files/templates/vsphere-hosted-cp-0-0-4.yaml similarity index 83% rename from templates/provider/hmc-templates/files/templates/vsphere-hosted-cp-0-0-3.yaml rename to templates/provider/hmc-templates/files/templates/vsphere-hosted-cp-0-0-4.yaml index 4fcc0b11..24e53625 100644 --- a/templates/provider/hmc-templates/files/templates/vsphere-hosted-cp-0-0-3.yaml +++ b/templates/provider/hmc-templates/files/templates/vsphere-hosted-cp-0-0-4.yaml @@ -1,14 +1,14 @@ apiVersion: hmc.mirantis.com/v1alpha1 kind: ClusterTemplate metadata: - name: vsphere-hosted-cp-0-0-3 + name: vsphere-hosted-cp-0-0-4 annotations: helm.sh/resource-policy: keep spec: helm: chartSpec: chart: vsphere-hosted-cp - version: 0.0.3 + version: 0.0.4 interval: 10m0s sourceRef: kind: HelmRepository diff --git a/templates/provider/hmc-templates/files/templates/vsphere-standalone-cp-0-0-3.yaml b/templates/provider/hmc-templates/files/templates/vsphere-standalone-cp-0-0-4.yaml similarity index 83% rename from templates/provider/hmc-templates/files/templates/vsphere-standalone-cp-0-0-3.yaml rename to templates/provider/hmc-templates/files/templates/vsphere-standalone-cp-0-0-4.yaml index f628b735..bdd95c1f 100644 --- a/templates/provider/hmc-templates/files/templates/vsphere-standalone-cp-0-0-3.yaml +++ b/templates/provider/hmc-templates/files/templates/vsphere-standalone-cp-0-0-4.yaml @@ -1,14 +1,14 @@ apiVersion: hmc.mirantis.com/v1alpha1 kind: ClusterTemplate metadata: - name: vsphere-standalone-cp-0-0-3 + name: vsphere-standalone-cp-0-0-4 annotations: helm.sh/resource-policy: keep spec: helm: chartSpec: chart: vsphere-standalone-cp - version: 0.0.3 + version: 0.0.4 interval: 10m0s sourceRef: kind: HelmRepository