From a9236c8805a096d2b75e02217007dd58a89015fd Mon Sep 17 00:00:00 2001 From: Ryota Sakamoto Date: Sun, 16 Jun 2024 21:30:09 +0900 Subject: [PATCH] move generate func --- pkg/cloudinit/generator.go | 2 +- pkg/cloudinit/generator_test.go | 4 ++-- pkg/provisioner/instance.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/cloudinit/generator.go b/pkg/cloudinit/generator.go index 359c8fc..c1112f7 100644 --- a/pkg/cloudinit/generator.go +++ b/pkg/cloudinit/generator.go @@ -19,7 +19,7 @@ type WriteFile struct { Permissions string `yaml:"permissions,omitempty"` } -func Generate(c Config, vars map[string]string) (string, error) { +func (c *Config) Generate(vars map[string]string) (string, error) { buff := &bytes.Buffer{} if err := yaml.NewEncoder(buff).Encode(c); err != nil { return "", err diff --git a/pkg/cloudinit/generator_test.go b/pkg/cloudinit/generator_test.go index 9bb102e..ed1eaf5 100644 --- a/pkg/cloudinit/generator_test.go +++ b/pkg/cloudinit/generator_test.go @@ -9,7 +9,7 @@ import ( ) func TestGenerate(t *testing.T) { - result, err := cloudinit.Generate(cloudinit.Config{ + result, err := (&cloudinit.Config{ Packages: []string{ "git", "vim", @@ -28,7 +28,7 @@ func TestGenerate(t *testing.T) { RunCmds: []string{ "/use/bin/ok", }, - }, map[string]string{ + }).Generate(map[string]string{ "Content": "content", }) assert.NoError(t, err) diff --git a/pkg/provisioner/instance.go b/pkg/provisioner/instance.go index 8b10208..d1fff11 100644 --- a/pkg/provisioner/instance.go +++ b/pkg/provisioner/instance.go @@ -26,7 +26,7 @@ func LaunchInstance(clusterName string, config InstanceConfig, cloudinitConfig c return "", fmt.Errorf("instance already exists: %s", instanceName) } - template, err := cloudinit.Generate(cloudinitConfig, map[string]string{ + template, err := cloudinitConfig.Generate(map[string]string{ "KubernetesVersion": config.K8sVersion, "Arch": "amd64", })