From e7a92878488c6153e17a16c001b66d47761d7e55 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 --- hack/k0s-ag-image/Dockerfile | 5 +++++ hack/k0s-ag-image/default.conf | 21 +++++++++++++++++++ .../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 ++++ 7 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 hack/k0s-ag-image/Dockerfile create mode 100644 hack/k0s-ag-image/default.conf diff --git a/hack/k0s-ag-image/Dockerfile b/hack/k0s-ag-image/Dockerfile new file mode 100644 index 000000000..70f84cba2 --- /dev/null +++ b/hack/k0s-ag-image/Dockerfile @@ -0,0 +1,5 @@ +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 000000000..ccc4bc98f --- /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/templates/cluster/vsphere-standalone-cp/Chart.yaml b/templates/cluster/vsphere-standalone-cp/Chart.yaml index bce65dc31..1c17ffd1e 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 e20112915..a5417cd73 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: {{ .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 {{ .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 332f52125..7ef024a53 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: {{ .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 {{ .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 f2be23fb4..0283e145b 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 eb64d7080..0236a8c0b 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