Skip to content
Open
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
33 changes: 14 additions & 19 deletions pkg/provider/aws/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package aws

import "github.com/nebari-dev/nebari-infrastructure-core/pkg/storage/longhorn"

// LonghornConfig is kept as a package-local alias so existing yaml under
// `longhorn:` still unmarshals into the same shape; the underlying type now
// lives in pkg/storage/longhorn so non-AWS providers can share install logic.
type LonghornConfig = longhorn.Config
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question. The comment says this alias exists "so existing yaml under longhorn: still unmarshals into the same shape", but YAML shape comes from the struct tags on longhorn.Config directly - the alias isn't required for unmarshaling and isn't referenced outside tests. Looks like dead surface area; consider removing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stylistic (re: LonghornReplicaCount below, line 63 - outside diff hunk). That method is called when LonghornEnabled() is true, which returns true even when c.Longhorn == nil. Replicas() is nil-safe so this works correctly, but it's non-obvious. A one-line comment on LonghornReplicaCount noting that Replicas() handles the nil case would save the next reader from adding a redundant nil check.


type Config struct {
Region string `yaml:"region"`
StateBucket string `yaml:"state_bucket,omitempty"`
Expand All @@ -19,7 +26,7 @@ type Config struct {
NodeGroups map[string]NodeGroup `yaml:"node_groups"`
Tags map[string]string `yaml:"tags,omitempty"`
EFS *EFSConfig `yaml:"efs,omitempty"`
Longhorn *LonghornConfig `yaml:"longhorn,omitempty"`
Longhorn *longhorn.Config `yaml:"longhorn,omitempty"`
}

type NodeGroup struct {
Expand All @@ -41,25 +48,20 @@ type Taint struct {
}

// LonghornEnabled returns whether Longhorn distributed block storage should
// be deployed on this AWS cluster. Defaults to true when the Longhorn config
// is nil or Enabled is not set.
// be deployed on this AWS cluster. Defaults to true when the Longhorn block
// is omitted entirely — Longhorn is the AWS storage default. The shared
// longhorn.Config defaults to disabled-when-nil because non-AWS providers
// require an explicit opt-in.
func (c *Config) LonghornEnabled() bool {
if c.Longhorn == nil {
return true
}
if c.Longhorn.Enabled == nil {
return true
}
return *c.Longhorn.Enabled
return c.Longhorn.IsEnabled()
}

// LonghornReplicaCount returns the number of Longhorn volume replicas.
// Defaults to 2 when not set.
func (c *Config) LonghornReplicaCount() int {
if c.Longhorn == nil || c.Longhorn.ReplicaCount == 0 {
return 2
}
return c.Longhorn.ReplicaCount
return c.Longhorn.Replicas()
}

type EFSConfig struct {
Expand All @@ -83,10 +85,3 @@ func (c *Config) EFSStorageClassName() string {
}
return c.EFS.StorageClassName
}

type LonghornConfig struct {
Enabled *bool `yaml:"enabled,omitempty"`
ReplicaCount int `yaml:"replica_count,omitempty"`
DedicatedNodes bool `yaml:"dedicated_nodes,omitempty"`
NodeSelector map[string]string `yaml:"node_selector,omitempty"`
}
Loading
Loading