Skip to content

Commit 8cb0303

Browse files
committed
replace yaml package
Signed-off-by: Markus Blaschke <[email protected]>
1 parent 647fd32 commit 8cb0303

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

config/config.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package config
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"regexp"
67
"strings"
@@ -14,38 +15,38 @@ import (
1415

1516
type (
1617
Config struct {
17-
Pools []PoolConfig `yaml:"pools"`
18+
Pools []PoolConfig `json:"pools"`
1819
}
1920

2021
PoolConfig struct {
21-
Name string `yaml:"pool"`
22-
Continue bool `yaml:"continue"`
23-
Selector []PoolConfigSelector `yaml:"selector"`
24-
Node PoolConfigNode `yaml:"node"`
22+
Name string `json:"pool"`
23+
Continue bool `json:"continue"`
24+
Selector []PoolConfigSelector `json:"selector"`
25+
Node PoolConfigNode `json:"node"`
2526
}
2627

2728
PoolConfigSelector struct {
28-
Path string `yaml:"path"`
29+
Path string `json:"path"`
2930
jsonPath *jsonpath.JSONPath
30-
Match *string `yaml:"match"`
31-
Regexp *string `yaml:"regexp"`
31+
Match *string `json:"match"`
32+
Regexp *string `json:"regexp"`
3233
regexp *regexp.Regexp
3334
}
3435

3536
PoolConfigNode struct {
36-
Roles PoolConfigNodeValueMap `yaml:"roles"`
37-
JsonPatches []k8s.JsonPatchObject `yaml:"jsonPatches"`
38-
ConfigSource *PoolConfigNodeConfigSource `yaml:"configSource"`
39-
Labels PoolConfigNodeValueMap `yaml:"labels"`
40-
Annotations PoolConfigNodeValueMap `yaml:"annotations"`
37+
Roles PoolConfigNodeValueMap `json:"roles"`
38+
JsonPatches []k8s.JsonPatchObject `json:"jsonPatches"`
39+
ConfigSource *PoolConfigNodeConfigSource `json:"configSource"`
40+
Labels PoolConfigNodeValueMap `json:"labels"`
41+
Annotations PoolConfigNodeValueMap `json:"annotations"`
4142
}
4243

4344
PoolConfigNodeConfigSource struct {
4445
ConfigMap struct {
45-
Name string `yaml:"name" json:"name"`
46-
Namespace string `yaml:"namespace" json:"namespace"`
47-
KubeletConfigKey string `yaml:"kubeletConfigKey" json:"kubeletConfigKey"`
48-
} `yaml:"configMap" json:"configMap"`
46+
Name string `json:"name"`
47+
Namespace string `json:"namespace"`
48+
KubeletConfigKey string `json:"kubeletConfigKey"`
49+
} `json:"configMap"`
4950
}
5051

5152
PoolConfigNodeValueMap struct {
@@ -63,12 +64,12 @@ func (valueMap *PoolConfigNodeValueMap) Entries() map[string]*string {
6364
return mapList
6465
}
6566

66-
func (valueMap *PoolConfigNodeValueMap) UnmarshalYAML(unmarshal func(interface{}) error) error {
67+
func (valueMap *PoolConfigNodeValueMap) UnmarshalJSON(b []byte) error {
6768
mapList := map[string]*string{}
68-
err := unmarshal(&mapList)
69+
err := json.Unmarshal(b, &mapList)
6970
if err != nil {
7071
var stringList []string
71-
err := unmarshal(&stringList)
72+
err := json.Unmarshal(b, &stringList)
7273
if err != nil {
7374
return err
7475
}

example.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pools:
2121
match: "windows"
2222
node:
2323
# sets the kubernetes node role
24-
role: [windows]
24+
roles: [windows]
2525

2626
- pool: azure
2727
selector:

main.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/jessevdk/go-flags"
1111
"github.com/prometheus/client_golang/prometheus/promhttp"
1212
"go.uber.org/zap"
13-
"gopkg.in/yaml.v2"
13+
"sigs.k8s.io/yaml"
1414

1515
"github.com/webdevops/kube-pool-manager/config"
1616
"github.com/webdevops/kube-pool-manager/manager"
@@ -73,14 +73,13 @@ func parseAppConfig(path string) (conf config.Config) {
7373

7474
logger.With(zap.String("path", path)).Infof("reading configuration from file %v", path)
7575
/* #nosec */
76-
if data, err := os.ReadFile(path); err == nil {
77-
configRaw = data
78-
} else {
79-
logger.Fatal(err)
76+
configRaw, err := os.ReadFile(path)
77+
if err != nil {
78+
logger.Fatal(err.Error())
8079
}
8180

8281
logger.With(zap.String("path", path)).Info("parsing configuration")
83-
if err := yaml.Unmarshal(configRaw, &conf); err != nil {
82+
if err := yaml.UnmarshalStrict(configRaw, &conf); err != nil {
8483
logger.Fatal(err)
8584
}
8685

0 commit comments

Comments
 (0)