Skip to content

Commit

Permalink
Add edpm service support
Browse files Browse the repository at this point in the history
  • Loading branch information
matbu committed Mar 22, 2024
1 parent 9714a98 commit 8c45c54
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
9 changes: 0 additions & 9 deletions pkg/servicecfg/edpm.go
Expand Up @@ -19,20 +19,12 @@ package servicecfg
import (
"fmt"
"io/ioutil"
<<<<<<< HEAD
"strings"

"github.com/openstack-k8s-operators/os-diff/pkg/common"
"github.com/openstack-k8s-operators/os-diff/pkg/godiff"
)

=======
"os-diff/pkg/godiff"
"strings"

"gopkg.in/yaml.v2"
)

var config Config

// Service YAML Config Structure
Expand All @@ -55,7 +47,6 @@ type Config struct {
Services map[string]Service `yaml:"services"`
}

>>>>>>> 2f61bfb (Add edpm service support)
type OpenStackDataPlaneNodeSet struct {
APIVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Expand Down
57 changes: 57 additions & 0 deletions pkg/servicecfg/utils.go
Expand Up @@ -22,13 +22,23 @@ import (
"io/ioutil"
"os"
"os/exec"
"reflect"
"strings"

"github.com/openstack-k8s-operators/os-diff/pkg/common"
"github.com/openstack-k8s-operators/os-diff/pkg/godiff"
"gopkg.in/yaml.v3"
)

func snakeToCamel(s string) string {
parts := strings.Split(s, "_")
var result string
for _, part := range parts {
result += strings.Title(part)
}
return result
}

func CompareIniConfig(rawdata1 []byte, rawdata2 []byte, ocpConfig string, serviceConfig string) ([]string, error) {

report, err := godiff.CompareIni(rawdata1, rawdata2, ocpConfig, serviceConfig, false)
Expand Down Expand Up @@ -176,3 +186,50 @@ func ExtractCustomServiceConfig(yamlData string) ([]string, error) {
}
return customServiceConfigs, nil
}

func getNestedFieldValue(data interface{}, keyName string) interface{} {
val := reflect.ValueOf(data)
for val.Kind() == reflect.Ptr || val.Kind() == reflect.Interface {
val = val.Elem()
}
if val.Kind() != reflect.Struct {
return nil
}

field := val.FieldByName(keyName)
if !field.IsValid() {
return nil
}

return field.Interface()
}

func LoadServiceConfigFile(configPath string) error {
file, err := os.Open(configPath)
if err != nil {
fmt.Println("Error opening file:", err)
return err
}
defer file.Close()

decoder := yaml.NewDecoder(file)
err = decoder.Decode(&config)
if err != nil {
fmt.Println("Error decoding YAML:", err)
return err
}
return nil
}

func ConvertToString(value interface{}) string {
switch v := value.(type) {
case string:
return v
case bool:
return fmt.Sprintf("%t", v)
case []string:
return fmt.Sprintf("%v", v)
default:
return fmt.Sprintf("%v", v)
}
}

0 comments on commit 8c45c54

Please sign in to comment.