Run sanitization outside the spec building functions

To limit responsibility or those functions and to keep the tests passing
(because they assumed no sanitization)

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
Dimitris Karakasilis 2023-10-02 10:57:11 +03:00
parent d1e84c186c
commit 80f83ba676
No known key found for this signature in database
GPG Key ID: 286DCAFD2C97DDE3
2 changed files with 8 additions and 7 deletions

View File

@ -19,10 +19,11 @@ package action_test
import (
"bytes"
"fmt"
agentConfig "github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/utils/fs"
"path/filepath"
agentConfig "github.com/kairos-io/kairos-agent/v2/pkg/config"
fsutils "github.com/kairos-io/kairos-agent/v2/pkg/utils/fs"
"github.com/jaypipes/ghw/pkg/block"
"github.com/kairos-io/kairos-agent/v2/pkg/action"
"github.com/kairos-io/kairos-agent/v2/pkg/constants"

View File

@ -577,6 +577,11 @@ func ReadSpecFromCloudConfig(r *Config, spec string) (v1.Spec, error) {
return nil, fmt.Errorf("failed initializing spec: %v", err)
}
err = sp.Sanitize()
if err != nil {
return sp, fmt.Errorf("sanitizing the %s spec: %w", spec, err)
}
r.Logger.Debugf("Loaded %s spec: %s", spec, litter.Sdump(sp))
return sp, nil
}
@ -738,10 +743,5 @@ func unmarshallFullSpec(r *Config, subkey string, sp v1.Spec) error {
return fmt.Errorf("error unmarshalling %s Spec: %w", subkey, err)
}
err = sp.Sanitize()
if err != nil {
return fmt.Errorf("sanitizing the % spec: %w", subkey, err)
}
return nil
}