diff --git a/cli/cmd/cluster-apply.go b/cli/cmd/cluster-apply.go index 187b9be07..d46836dee 100644 --- a/cli/cmd/cluster-apply.go +++ b/cli/cmd/cluster-apply.go @@ -80,7 +80,7 @@ func runClusterApply(cmd *cobra.Command, args []string) { fmt.Printf("\nYour configurations are stored in %s\n", assetDir) kubeconfigPath := assetsKubeconfig(assetDir) - if err := verifyCluster(kubeconfigPath, p.GetExpectedNodes()); err != nil { + if err := verifyCluster(kubeconfigPath, p.Meta().ExpectedNodes); err != nil { ctxLogger.Fatalf("Verify cluster: %v", err) } diff --git a/cli/cmd/cluster.go b/cli/cmd/cluster.go index 6bea1b1f4..bf12f9003 100644 --- a/cli/cmd/cluster.go +++ b/cli/cmd/cluster.go @@ -79,7 +79,7 @@ func initialize(ctxLogger *logrus.Entry) (*terraform.Executor, platform.Platform b = local.NewLocalBackend() } - assetDir, err := homedir.Expand(p.GetAssetDir()) + assetDir, err := homedir.Expand(p.Meta().AssetDir) if err != nil { ctxLogger.Fatalf("Error expanding path: %v", err) } @@ -97,7 +97,7 @@ func initialize(ctxLogger *logrus.Entry) (*terraform.Executor, platform.Platform // initializeTerraform initialized Terraform directory using given backend and platform // and returns configured executor. func initializeTerraform(ctxLogger *logrus.Entry, p platform.Platform, b backend.Backend) *terraform.Executor { - assetDir, err := homedir.Expand(p.GetAssetDir()) + assetDir, err := homedir.Expand(p.Meta().AssetDir) if err != nil { ctxLogger.Fatalf("Error expanding path: %v", err) } diff --git a/cli/cmd/health.go b/cli/cmd/health.go index a359351ce..898215e45 100644 --- a/cli/cmd/health.go +++ b/cli/cmd/health.go @@ -64,7 +64,7 @@ func runHealth(cmd *cobra.Command, args []string) { contextLogger.Fatal("No cluster configured") } - cluster, err := lokomotive.NewCluster(client, p.GetExpectedNodes()) + cluster, err := lokomotive.NewCluster(client, p.Meta().ExpectedNodes) if err != nil { contextLogger.Fatalf("Error in creating new Lokomotive cluster: %q", err) } diff --git a/cli/cmd/utils.go b/cli/cmd/utils.go index 09a550925..1e21a3b69 100644 --- a/cli/cmd/utils.go +++ b/cli/cmd/utils.go @@ -83,7 +83,7 @@ func getAssetDir() (string, error) { return "", nil } - return cfg.GetAssetDir(), nil + return cfg.Meta().AssetDir, nil } // expandKubeconfigPath tries to expand ~ in the given kubeconfig path. diff --git a/pkg/platform/aws/aws.go b/pkg/platform/aws/aws.go index 70e73b9c5..1f1120e3b 100644 --- a/pkg/platform/aws/aws.go +++ b/pkg/platform/aws/aws.go @@ -101,9 +101,17 @@ func NewConfig() *config { } } -// GetAssetDir returns asset directory path -func (c *config) GetAssetDir() string { - return c.AssetDir +// Meta is part of Platform interface and returns common information about the platform configuration. +func (c *config) Meta() platform.Meta { + nodes := c.ControllerCount + for _, workerpool := range c.WorkerPools { + nodes += workerpool.Count + } + + return platform.Meta{ + AssetDir: c.AssetDir, + ExpectedNodes: nodes, + } } func (c *config) Apply(ex *terraform.Executor) error { @@ -212,15 +220,6 @@ func createTerraformConfigFile(cfg *config, terraformRootDir string) error { return nil } -func (c *config) GetExpectedNodes() int { - nodes := c.ControllerCount - for _, workerpool := range c.WorkerPools { - nodes += workerpool.Count - } - - return nodes -} - // checkValidConfig validates cluster configuration. func (c *config) checkValidConfig() hcl.Diagnostics { var diagnostics hcl.Diagnostics diff --git a/pkg/platform/baremetal/baremetal.go b/pkg/platform/baremetal/baremetal.go index a605aadf9..fbd0276ab 100644 --- a/pkg/platform/baremetal/baremetal.go +++ b/pkg/platform/baremetal/baremetal.go @@ -62,9 +62,12 @@ func (c *config) LoadConfig(configBody *hcl.Body, evalContext *hcl.EvalContext) return gohcl.DecodeBody(*configBody, evalContext, c) } -// GetAssetDir returns asset directory path -func (c *config) GetAssetDir() string { - return c.AssetDir +// Meta is part of Platform interface and returns common information about the platform configuration. +func (c *config) Meta() platform.Meta { + return platform.Meta{ + AssetDir: c.AssetDir, + ExpectedNodes: len(c.ControllerMacs) + len(c.WorkerMacs), + } } func NewConfig() *config { @@ -195,7 +198,3 @@ func createTerraformConfigFile(cfg *config, terraformPath string) error { } return nil } - -func (c *config) GetExpectedNodes() int { - return len(c.ControllerMacs) + len(c.WorkerMacs) -} diff --git a/pkg/platform/packet/packet.go b/pkg/platform/packet/packet.go index a5ff0907c..ff6262f37 100644 --- a/pkg/platform/packet/packet.go +++ b/pkg/platform/packet/packet.go @@ -102,9 +102,17 @@ func NewConfig() *config { } } -// GetAssetDir returns asset directory path -func (c *config) GetAssetDir() string { - return c.AssetDir +// Meta is part of Platform interface and returns common information about the platform configuration. +func (c *config) Meta() platform.Meta { + nodes := c.ControllerCount + for _, workerpool := range c.WorkerPools { + nodes += workerpool.Count + } + + return platform.Meta{ + AssetDir: c.AssetDir, + ExpectedNodes: nodes, + } } func (c *config) Initialize(ex *terraform.Executor) error { @@ -237,16 +245,6 @@ func (c *config) terraformSmartApply(ex *terraform.Executor, dnsProvider dns.DNS return ex.Apply() } -func (c *config) GetExpectedNodes() int { - workers := 0 - - for _, wp := range c.WorkerPools { - workers += wp.Count - } - - return c.ControllerCount + workers -} - // checkValidConfig validates cluster configuration. func (c *config) checkValidConfig() hcl.Diagnostics { var diagnostics hcl.Diagnostics diff --git a/pkg/platform/platform.go b/pkg/platform/platform.go index c9d98a5f3..0f2d237cf 100644 --- a/pkg/platform/platform.go +++ b/pkg/platform/platform.go @@ -27,8 +27,13 @@ type Platform interface { Apply(*terraform.Executor) error Destroy(*terraform.Executor) error Initialize(*terraform.Executor) error - GetAssetDir() string - GetExpectedNodes() int + Meta() Meta +} + +// Meta is a generic information format about the platform. +type Meta struct { + AssetDir string + ExpectedNodes int } // platforms is a collection where all platforms gets automatically registered