Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1232 from kinvolk/invidian/fix-tinkerbell
Browse files Browse the repository at this point in the history
pkg/platform/tinkerbell: update the way we unpack controlplane charts
  • Loading branch information
invidian authored Dec 2, 2020
2 parents fbb8a30 + b7819ae commit d034509
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 78 deletions.
30 changes: 3 additions & 27 deletions pkg/platform/tinkerbell/tinkerbell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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),
}
}

Expand All @@ -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)
Expand Down
51 changes: 0 additions & 51 deletions pkg/platform/tinkerbell/tinkerbell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
package tinkerbell_test

import (
"io/ioutil"
"os"
"path/filepath"
"reflect"
"testing"

Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
}

0 comments on commit d034509

Please sign in to comment.