Fix loading and some tests

This commit is contained in:
2025-05-10 18:54:10 -04:00
parent 1ae06781d6
commit 432a3fdbc4
4 changed files with 17 additions and 16 deletions

View File

@ -3,12 +3,13 @@ package config
import (
"fmt"
"io/ioutil"
"net"
"os"
pb "git.dws.rip/dubey/kat/api/v1alpha1" // Adjust to your actual go module path
"gopkg.in/yaml.v3" // Add to go.mod: go get gopkg.in/yaml.v3
pb "git.dws.rip/dubey/kat/api/v1alpha1"
"gopkg.in/yaml.v3"
"encoding/json"
)
var _ = yaml.Unmarshal // Used for Quadlet parsing
@ -19,7 +20,7 @@ func ParseClusterConfiguration(filePath string) (*pb.ClusterConfiguration, error
return nil, fmt.Errorf("cluster configuration file not found: %s", filePath)
}
yamlFile, err := ioutil.ReadFile(filePath)
yamlFile, err := os.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("failed to read cluster configuration file %s: %w", filePath, err)
}
@ -43,11 +44,11 @@ func ParseClusterConfiguration(filePath string) (*pb.ClusterConfiguration, error
if !ok {
return nil, fmt.Errorf("metadata section not found or invalid in %s", filePath)
}
metadataBytes, err := yaml.Marshal(metadataMap)
metadataBytes, err := json.Marshal(metadataMap)
if err != nil {
return nil, fmt.Errorf("failed to re-marshal metadata: %w", err)
}
if err = yaml.Unmarshal(metadataBytes, &config.Metadata); err != nil {
if err = json.Unmarshal(metadataBytes, &config.Metadata); err != nil {
return nil, fmt.Errorf("failed to unmarshal metadata into proto: %w", err)
}
@ -55,11 +56,11 @@ func ParseClusterConfiguration(filePath string) (*pb.ClusterConfiguration, error
if !ok {
return nil, fmt.Errorf("spec section not found or invalid in %s", filePath)
}
specBytes, err := yaml.Marshal(specMap)
specBytes, err := json.Marshal(specMap)
if err != nil {
return nil, fmt.Errorf("failed to re-marshal spec: %w", err)
}
if err = yaml.Unmarshal(specBytes, &config.Spec); err != nil {
if err = json.Unmarshal(specBytes, &config.Spec); err != nil {
return nil, fmt.Errorf("failed to unmarshal spec into proto: %w", err)
}