-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from jakobmoellerdev/OCPVE-677-lvmd-separation
OCPVE-677: chore: separate lvmd package from vgmanager
- Loading branch information
Showing
13 changed files
with
105 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package lvmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/topolvm/topolvm/lvmd" | ||
lvmdCMD "github.com/topolvm/topolvm/pkg/lvmd/cmd" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
type Config = lvmdCMD.Config | ||
|
||
type DeviceClass = lvmd.DeviceClass | ||
type ThinPoolConfig = lvmd.ThinPoolConfig | ||
|
||
var TypeThin = lvmd.TypeThin | ||
|
||
const DefaultFileConfigPath = "/etc/topolvm/lvmd.yaml" | ||
|
||
func DefaultConfigurator() FileConfig { | ||
return NewFileConfigurator(DefaultFileConfigPath) | ||
} | ||
|
||
func NewFileConfigurator(path string) FileConfig { | ||
return FileConfig{path: path} | ||
} | ||
|
||
type Configurator interface { | ||
Load() (*Config, error) | ||
Save(config *Config) error | ||
Delete() error | ||
} | ||
|
||
type FileConfig struct { | ||
path string | ||
} | ||
|
||
func (c FileConfig) Load() (*Config, error) { | ||
cfgBytes, err := os.ReadFile(c.path) | ||
if os.IsNotExist(err) { | ||
// If the file does not exist, return nil for both | ||
return nil, nil | ||
} else if err != nil { | ||
return nil, fmt.Errorf("failed to load config file %s: %w", c.path, err) | ||
} else { | ||
config := &Config{} | ||
if err = yaml.Unmarshal(cfgBytes, config); err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal config file %s: %w", c.path, err) | ||
} | ||
return config, nil | ||
} | ||
} | ||
|
||
func (c FileConfig) Save(config *Config) error { | ||
out, err := yaml.Marshal(config) | ||
if err == nil { | ||
err = os.WriteFile(c.path, out, 0600) | ||
} | ||
if err != nil { | ||
return fmt.Errorf("failed to save config file %s: %w", c.path, err) | ||
} | ||
return nil | ||
} | ||
|
||
func (c FileConfig) Delete() error { | ||
err := os.Remove(c.path) | ||
if err != nil { | ||
return fmt.Errorf("failed to delete config file %s: %w", c.path, err) | ||
} | ||
return err | ||
} |
Oops, something went wrong.