Skip to content

Commit

Permalink
Merge pull request #1994 from rmweir/validate-ha-store
Browse files Browse the repository at this point in the history
Prevent unsupported HA setup
  • Loading branch information
rmweir authored Jul 29, 2024
2 parents 2b5bc24 + 6fbe705 commit 3b377fc
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/backport.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Automatic backport action

on:
pull_request_target:
types: ["labeled", "closed"]

jobs:
backport:
name: Backport PR
if: github.event.pull_request.merged == true && !(contains(github.event.pull_request.labels.*.name, 'backport'))
runs-on: ubuntu-latest
steps:
- name: Backport Action
uses: sorenlouv/[email protected]
with:
github_token: ${{ secrets.GH_ACCESS_TOKEN }}
auto_backport_label_prefix: backport-to-

- name: Info log
if: ${{ success() }}
run: cat ~/.backport/backport.info.log

- name: Debug log
if: ${{ failure() }}
run: cat ~/.backport/backport.debug.log

4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ func (c *Config) BackingStoreType() StoreType {
}
}

func (c *Config) EmbeddedDatabase() bool {
return !c.ControlPlane.BackingStore.Database.External.Enabled && !c.ControlPlane.BackingStore.Etcd.Embedded.Enabled && !c.ControlPlane.BackingStore.Etcd.Deploy.Enabled
}

func (c *Config) Distro() string {
if c.ControlPlane.Distro.K3S.Enabled {
return K3SDistro
Expand Down
15 changes: 15 additions & 0 deletions pkg/cli/create_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ func CreateHelm(ctx context.Context, options *CreateOptions, globalFlags *flags.
}
}

err = validateHABackingStoreCompatibility(vClusterConfig)
if err != nil {
return err
}

if isVClusterDeployed(release) {
// While certain backing store changes are allowed we prohibit changes to another distro.
if err := config.ValidateChanges(currentVClusterConfig, vClusterConfig); err != nil {
Expand Down Expand Up @@ -412,6 +417,16 @@ func isLegacyVCluster(version string) bool {
return semver.Compare("v"+version, "v0.20.0-alpha.0") == -1
}

func validateHABackingStoreCompatibility(config *config.Config) error {
if !config.EmbeddedDatabase() {
return nil
}
if !(config.ControlPlane.StatefulSet.HighAvailability.Replicas > 1) {
return nil
}
return fmt.Errorf("cannot use default embedded database (sqlite) in high availability mode. Try embedded etcd backing store instead")
}

func isLegacyConfig(values []byte) bool {
cfg := legacyconfig.LegacyK0sAndK3s{}
if err := cfg.UnmarshalYAMLStrict(values); err != nil {
Expand Down
4 changes: 0 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ type VirtualClusterConfig struct {
ControlPlaneNamespace string `json:"controlPlaneNamespace,omitempty"`
}

func (v VirtualClusterConfig) EmbeddedDatabase() bool {
return !v.ControlPlane.BackingStore.Database.External.Enabled && !v.ControlPlane.BackingStore.Etcd.Embedded.Enabled && !v.ControlPlane.BackingStore.Etcd.Deploy.Enabled
}

func (v VirtualClusterConfig) VirtualClusterKubeConfig() config.VirtualClusterKubeConfig {
distroConfig := config.VirtualClusterKubeConfig{}
switch v.Distro() {
Expand Down

0 comments on commit 3b377fc

Please sign in to comment.