Skip to content

Commit b798497

Browse files
committed
feat(longhorn): generalize install for non-AWS providers
Lift the Longhorn install logic out of the AWS provider into a shared package so the existing-cluster and hetzner providers can opt in. On clusters without managed RWX (Hetzner hcloud-volumes is RWO-only, on-prem k3s, kind/k3d), charts that need RWX previously had to fall back to the in-cluster NFS-on-RWO workaround, which is fragile on overlayfs hosts. Closes #269. Shared package pkg/storage/longhorn: - Install(ctx, kubeconfigBytes, *Config) — idempotent helm install or upgrade. iSCSI prerequisite DaemonSet runs on first install only; upgrade path skips it (saves the 3-minute readiness wait). - Config + IsEnabled / Replicas helpers. nil *Config = do not install. aws provider: - Longhorn field type is now *longhorn.Config; aws.LonghornConfig is a type alias so existing yaml under cluster.aws.longhorn keeps working. - LonghornEnabled() retains AWS's nil-block-as-enabled default. - Provider.Deploy calls longhorn.Install directly. existing provider: - New opt-in longhorn block (nil = no install). - Deploy installs Longhorn when enabled. - GetStorageClass / InfraSettings.StorageClass returns 'longhorn' when Longhorn is enabled and storage_class is unset; explicit storage_class always wins. hetzner provider: - Same opt-in. Deploy reads the kubeconfig hetzner-k3s wrote and installs Longhorn after cluster create. - InfraSettings.StorageClass flips from hcloud-volumes to longhorn when enabled.
1 parent b2c4a2f commit b798497

13 files changed

Lines changed: 1039 additions & 854 deletions

File tree

pkg/provider/aws/config.go

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
package aws
22

3+
import "github.com/nebari-dev/nebari-infrastructure-core/pkg/storage/longhorn"
4+
5+
// LonghornConfig is kept as a package-local alias so existing yaml under
6+
// `longhorn:` still unmarshals into the same shape; the underlying type now
7+
// lives in pkg/storage/longhorn so non-AWS providers can share install logic.
8+
type LonghornConfig = longhorn.Config
9+
10+
// Helpers for tests that need to construct a LonghornConfig without exporting
11+
// internals from the shared package.
12+
func newLonghornCfgWithEnabled(enabled *bool) *LonghornConfig {
13+
return &LonghornConfig{Enabled: enabled}
14+
}
15+
16+
func newLonghornCfgWithReplicas(n int) *LonghornConfig {
17+
return &LonghornConfig{ReplicaCount: n}
18+
}
19+
320
type Config struct {
421
Region string `yaml:"region"`
522
StateBucket string `yaml:"state_bucket,omitempty"`
@@ -19,7 +36,7 @@ type Config struct {
1936
NodeGroups map[string]NodeGroup `yaml:"node_groups"`
2037
Tags map[string]string `yaml:"tags,omitempty"`
2138
EFS *EFSConfig `yaml:"efs,omitempty"`
22-
Longhorn *LonghornConfig `yaml:"longhorn,omitempty"`
39+
Longhorn *longhorn.Config `yaml:"longhorn,omitempty"`
2340
}
2441

2542
type NodeGroup struct {
@@ -41,25 +58,20 @@ type Taint struct {
4158
}
4259

4360
// LonghornEnabled returns whether Longhorn distributed block storage should
44-
// be deployed on this AWS cluster. Defaults to true when the Longhorn config
45-
// is nil or Enabled is not set.
61+
// be deployed on this AWS cluster. Defaults to true when the Longhorn block
62+
// is omitted entirely — Longhorn is the AWS storage default. The shared
63+
// longhorn.Config defaults to disabled-when-nil because non-AWS providers
64+
// require an explicit opt-in.
4665
func (c *Config) LonghornEnabled() bool {
4766
if c.Longhorn == nil {
4867
return true
4968
}
50-
if c.Longhorn.Enabled == nil {
51-
return true
52-
}
53-
return *c.Longhorn.Enabled
69+
return c.Longhorn.IsEnabled()
5470
}
5571

5672
// LonghornReplicaCount returns the number of Longhorn volume replicas.
57-
// Defaults to 2 when not set.
5873
func (c *Config) LonghornReplicaCount() int {
59-
if c.Longhorn == nil || c.Longhorn.ReplicaCount == 0 {
60-
return 2
61-
}
62-
return c.Longhorn.ReplicaCount
74+
return c.Longhorn.Replicas()
6375
}
6476

6577
type EFSConfig struct {
@@ -83,10 +95,3 @@ func (c *Config) EFSStorageClassName() string {
8395
}
8496
return c.EFS.StorageClassName
8597
}
86-
87-
type LonghornConfig struct {
88-
Enabled *bool `yaml:"enabled,omitempty"`
89-
ReplicaCount int `yaml:"replica_count,omitempty"`
90-
DedicatedNodes bool `yaml:"dedicated_nodes,omitempty"`
91-
NodeSelector map[string]string `yaml:"node_selector,omitempty"`
92-
}

0 commit comments

Comments
 (0)