Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gzip cloud-init data #556

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 10 additions & 4 deletions bootstrap/internal/cloudinit/cloudinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import (
"bytes"
"compress/gzip"
"fmt"
"strings"
"text/template"
Expand Down Expand Up @@ -135,12 +136,17 @@
return nil, errors.Wrapf(err, "failed to parse %s template", kind)
}

var out bytes.Buffer
if err := t.Execute(&out, data); err != nil {
var buf bytes.Buffer
out := gzip.NewWriter(&buf)
err = t.Execute(out, data)
if err != nil {

Check failure on line 142 in bootstrap/internal/cloudinit/cloudinit.go

View workflow job for this annotation

GitHub Actions / lint

only one cuddle assignment allowed before if statement (wsl)

Check failure on line 142 in bootstrap/internal/cloudinit/cloudinit.go

View workflow job for this annotation

GitHub Actions / lint

only one cuddle assignment allowed before if statement (wsl)
return nil, errors.Wrapf(err, "failed to generate %s template", kind)
}

return out.Bytes(), nil
err = out.Close()

Check failure on line 145 in bootstrap/internal/cloudinit/cloudinit.go

View workflow job for this annotation

GitHub Actions / lint

assignments should only be cuddled with other assignments (wsl)

Check failure on line 145 in bootstrap/internal/cloudinit/cloudinit.go

View workflow job for this annotation

GitHub Actions / lint

assignments should only be cuddled with other assignments (wsl)
if err != nil {

Check failure on line 146 in bootstrap/internal/cloudinit/cloudinit.go

View workflow job for this annotation

GitHub Actions / lint

only one cuddle assignment allowed before if statement (wsl)

Check failure on line 146 in bootstrap/internal/cloudinit/cloudinit.go

View workflow job for this annotation

GitHub Actions / lint

only one cuddle assignment allowed before if statement (wsl)
return nil, errors.Wrapf(err, "failed to generate %s compressed userdata", kind)
}
return buf.Bytes(), nil

Check failure on line 149 in bootstrap/internal/cloudinit/cloudinit.go

View workflow job for this annotation

GitHub Actions / lint

return statements should not be cuddled if block has more than two lines (wsl)

Check failure on line 149 in bootstrap/internal/cloudinit/cloudinit.go

View workflow job for this annotation

GitHub Actions / lint

return statements should not be cuddled if block has more than two lines (wsl)
}

func cleanupAdditionalCloudInit(cloudInitData string) (string, error) {
Expand Down
11 changes: 11 additions & 0 deletions bootstrap/internal/cloudinit/cloudinit_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ limitations under the License.
package cloudinit

import (
"bytes"
"compress/gzip"
"io"
"testing"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -28,3 +31,11 @@ func TestCloudInit(t *testing.T) {

RunSpecs(t, "CloudInit Suite")
}

func unzipUserdata(userdata []byte) string {
r, err := gzip.NewReader(bytes.NewBuffer(userdata))
Expect(err).ToNot(HaveOccurred())
content, err := io.ReadAll(r)
Expect(err).ToNot(HaveOccurred())
return string(content)
}
14 changes: 7 additions & 7 deletions bootstrap/internal/cloudinit/cloudinit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var _ = Describe("WorkerAirGappedCloudInitTest", func() {
It("Should use the image embedded install.sh method", func() {
workerCloudInitData, err := NewJoinWorker(input)
Expect(err).ToNot(HaveOccurred())
workerCloudInitString := string(workerCloudInitData)
workerCloudInitString := unzipUserdata(workerCloudInitData)
_, err = GinkgoWriter.Write(workerCloudInitData)
Expect(err).NotTo(HaveOccurred())
Expect(workerCloudInitString).To(Equal(`## template: jinja
Expand Down Expand Up @@ -66,7 +66,7 @@ var _ = Describe("WorkerAirGappedWithChecksumCloudInitTest", func() {
It("Should use the image embedded install.sh method and check the checksum first", func() {
workerCloudInitData, err := NewJoinWorker(input)
Expect(err).ToNot(HaveOccurred())
workerCloudInitString := string(workerCloudInitData)
workerCloudInitString := unzipUserdata(workerCloudInitData)
_, err = GinkgoWriter.Write(workerCloudInitData)
Expect(err).NotTo(HaveOccurred())
Expect(workerCloudInitString).To(Equal(`## template: jinja
Expand Down Expand Up @@ -101,7 +101,7 @@ var _ = Describe("WorkerOnlineCloudInitTest", func() {
It("Should use the RKE2 Online installation method", func() {
workerCloudInitData, err := NewJoinWorker(input)
Expect(err).ToNot(HaveOccurred())
workerCloudInitString := string(workerCloudInitData)
workerCloudInitString := unzipUserdata(workerCloudInitData)
_, err = GinkgoWriter.Write(workerCloudInitData)
Expect(err).NotTo(HaveOccurred())
Expect(workerCloudInitString).To(Equal(`## template: jinja
Expand Down Expand Up @@ -134,7 +134,7 @@ var _ = Describe("NTPWorkerTest", func() {
It("Should use the RKE2 Online installation method", func() {
workerCloudInitData, err := NewJoinWorker(input)
Expect(err).ToNot(HaveOccurred())
workerCloudInitString := string(workerCloudInitData)
workerCloudInitString := unzipUserdata(workerCloudInitData)
_, err = GinkgoWriter.Write(workerCloudInitData)
Expect(err).NotTo(HaveOccurred())
Expect(workerCloudInitString).To(Equal(`## template: jinja
Expand Down Expand Up @@ -172,7 +172,7 @@ var _ = Describe("WorkerCISTest", func() {
It("Should run the CIS script", func() {
workerCloudInitData, err := NewJoinWorker(input)
Expect(err).ToNot(HaveOccurred())
workerCloudInitString := string(workerCloudInitData)
workerCloudInitString := unzipUserdata(workerCloudInitData)
_, err = GinkgoWriter.Write(workerCloudInitData)
Expect(err).NotTo(HaveOccurred())
Expect(workerCloudInitString).To(Equal(`## template: jinja
Expand Down Expand Up @@ -274,7 +274,7 @@ runcmd:
}
workerCloudInitData, err := NewJoinWorker(input)
Expect(err).ToNot(HaveOccurred())
workerCloudInitString := string(workerCloudInitData)
workerCloudInitString := unzipUserdata(workerCloudInitData)
_, err = GinkgoWriter.Write(workerCloudInitData)
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -312,7 +312,7 @@ runcmd:
}
workerCloudInitData, err := NewJoinWorker(input)
Expect(err).ToNot(HaveOccurred())
workerCloudInitString := string(workerCloudInitData)
workerCloudInitString := unzipUserdata(workerCloudInitData)
_, err = GinkgoWriter.Write(workerCloudInitData)
Expect(err).NotTo(HaveOccurred())

Expand Down
Loading