Repository: kinvolk/lokomotive
Pull request #1232 (2020-12-02 11:35:49)

pkg/platform/tinkerbell: update the way we unpack controlplane charts
45c0f6f13da0658151f94669cd79125ea5be0730,
2ebfb4475b899fb053458adcc558bda542ef5ccc and
f563d565856a8056bf4b2c8b1d14c4d1fd569f96 have been recently merged, in
parallel to adding Tinkerbell platform. Those commits changed how we
unpack controlplane charts and due to no obvious merge conflict,
Tinkerbell code stayed out of date and broke building.

This commit updates Tinkerbell platform to behave the same way as other
platforms.

Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>


Patch:
diff --git a/pkg/platform/tinkerbell/tinkerbell.go b/pkg/platform/tinkerbell/tinkerbell.go
index 6988d8b0..8297f67f 100644
--- a/pkg/platform/tinkerbell/tinkerbell.go
+++ b/pkg/platform/tinkerbell/tinkerbell.go
@@ -25,7 +25,6 @@ import (
 	"github.com/hashicorp/hcl/v2/gohcl"
 	"github.com/mitchellh/go-homedir"
 
-	"github.com/kinvolk/lokomotive/pkg/assets"
 	"github.com/kinvolk/lokomotive/pkg/platform"
 	"github.com/kinvolk/lokomotive/pkg/terraform"
 )
@@ -135,8 +134,9 @@ func (c *Config) Meta() platform.Meta {
 	}
 
 	return platform.Meta{
-		AssetDir:      c.AssetDir,
-		ExpectedNodes: nodes,
+		AssetDir:           c.AssetDir,
+		ExpectedNodes:      nodes,
+		ControlplaneCharts: platform.CommonControlPlaneCharts(!c.DisableSelfHostedKubelet),
 	}
 }
 
@@ -148,30 +148,6 @@ func (c *Config) Initialize(ex *terraform.Executor) error {
 		return err
 	}
 
-	// TODO: A transient change which shall be reverted in a follow up PR to handle
-	// https://github.com/kinvolk/lokomotive/issues/716.
-	// Extract control plane chart files to cluster assets directory.
-	for _, c := range platform.CommonControlPlaneCharts() {
-		src := filepath.Join(assets.ControlPlaneSource, c.Name)
-		dst := filepath.Join(assetDir, "cluster-assets", "charts", c.Namespace, c.Name)
-
-		if err := assets.Extract(src, dst); err != nil {
-			return fmt.Errorf("extracting charts: %w", err)
-		}
-	}
-
-	// TODO: A transient change which shall be reverted in a follow up PR to handle
-	// https://github.com/kinvolk/lokomotive/issues/716.
-	// Extract self-hosted kubelet chart only when enabled in config.
-	if !c.DisableSelfHostedKubelet {
-		src := filepath.Join(assets.ControlPlaneSource, "kubelet")
-		dst := filepath.Join(assetDir, "cluster-assets", "charts", "kube-system", "kubelet")
-
-		if err := assets.Extract(src, dst); err != nil {
-			return fmt.Errorf("extracting kubelet chart: %w", err)
-		}
-	}
-
 	terraformRootDir := terraform.GetTerraformRootDir(assetDir)
 
 	return c.createTerraformConfigFile(terraformRootDir)


Test patch:
diff --git a/pkg/platform/tinkerbell/tinkerbell_test.go b/pkg/platform/tinkerbell/tinkerbell_test.go
index c96f1e4d..c23f920b 100644
--- a/pkg/platform/tinkerbell/tinkerbell_test.go
+++ b/pkg/platform/tinkerbell/tinkerbell_test.go
@@ -15,9 +15,6 @@
 package tinkerbell_test
 
 import (
-	"io/ioutil"
-	"os"
-	"path/filepath"
 	"reflect"
 	"testing"
 
@@ -27,7 +24,6 @@ import (
 
 	lokoconfig "github.com/kinvolk/lokomotive/pkg/config"
 	"github.com/kinvolk/lokomotive/pkg/platform/tinkerbell"
-	"github.com/kinvolk/lokomotive/pkg/terraform"
 )
 
 func baseConfig() *tinkerbell.Config {
@@ -248,50 +244,3 @@ func TestMeta(t *testing.T) {
 		t.Errorf("Expected %d nodes, got %d", expectedNodes, m.ExpectedNodes)
 	}
 }
-
-func TestInitialize(t *testing.T) {
-	tmpDir, err := ioutil.TempDir("", "lokoctl-tests-")
-	if err != nil {
-		t.Fatalf("Creating tmp dir should succeed, got: %v", err)
-	}
-
-	t.Cleanup(func() {
-		if err := os.RemoveAll(tmpDir); err != nil {
-			t.Logf("Failed to remove temp dir %q: %v", tmpDir, err)
-		}
-	})
-
-	c := baseConfig()
-	c.AssetDir = tmpDir
-
-	path := filepath.Join(tmpDir, "terraform")
-	if err := os.MkdirAll(path, 0o700); err != nil {
-		t.Fatalf("Failed creating directory %q: %v", path, err)
-	}
-
-	if err := c.Initialize(nil); err != nil {
-		t.Fatalf("Initializing should work, got: %v", err)
-	}
-
-	tfDir := terraform.GetTerraformRootDir(tmpDir)
-
-	content, err := ioutil.ReadFile(filepath.Join(tfDir, "cluster.tf")) // #nosec G304
-	if err != nil {
-		t.Fatalf("Reading Terraform source file: %v", err)
-	}
-
-	if len(content) == 0 {
-		t.Fatal("Terraform source file should not be empty")
-	}
-
-	path = filepath.Join(tmpDir, "cluster-assets", "charts", "kube-system")
-
-	dirs, err := ioutil.ReadDir(path)
-	if err != nil {
-		t.Fatalf("Listing files in %q: %v", path, err)
-	}
-
-	if len(dirs) == 0 {
-		t.Fatalf("Initialize should extract control plane helm charts, no files found in %q", dirs)
-	}
-}