Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #13 from wzshiming/fix/template-yaml
Browse files Browse the repository at this point in the history
Fix template yaml function
  • Loading branch information
wzshiming authored Apr 16, 2022
2 parents 608c298 + 565e52a commit 76c091f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
8 changes: 4 additions & 4 deletions cmd/fake-kubelet/node.initialization.tpl
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{{ with .status }}
addresses:
{{ with .addresses }}
{{ . | YAML }}
{{ YAML . 1 }}
{{ else }}
- address: {{ NodeIP }}
type: InternalIP
{{ end }}
allocatable:
{{ with .allocatable }}
{{ . | YAML }}
{{ YAML . 1 }}
{{ else }}
cpu: 1k
memory: 1Ti
pods: 1M
{{ end }}
capacity:
{{ with .capacity }}
{{ . | YAML }}
{{ YAML . 1 }}
{{ else }}
cpu: 1k
memory: 1Ti
pods: 1M
{{ end }}
daemonEndpoints:
{{ with .daemonEndpoints }}
{{ . | YAML }}
{{ YAML . 1 }}
{{ else }}
kubeletEndpoint:
Port: 0
Expand Down
9 changes: 7 additions & 2 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,17 @@ func NewController(conf Config) (*Controller, error) {
"PodIP": func() string {
return n.ipPool.Get()
},
"YAML": func(s interface{}) (string, error) {
"YAML": func(s interface{}, indent ...int) (string, error) {
d, err := yaml.Marshal(s)
if err != nil {
return "", err
}
return string(d), nil

data := string(d)
if len(indent) == 1 && indent[0] > 0 {
data = strings.Replace("\n"+data, "\n", "\n"+strings.Repeat(" ", indent[0]), -1)
}
return data, nil
},
}
return n, nil
Expand Down
8 changes: 4 additions & 4 deletions deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,30 +180,30 @@ data:
{{ with .status }}
addresses:
{{ with .addresses }}
{{ . | YAML }}
{{ YAML . 1 }}
{{ else }}
- address: {{ NodeIP }}
type: InternalIP
{{ end }}
allocatable:
{{ with .allocatable }}
{{ . | YAML }}
{{ YAML . 1 }}
{{ else }}
cpu: 1k
memory: 1Ti
pods: 1M
{{ end }}
capacity:
{{ with .capacity }}
{{ . | YAML }}
{{ YAML . 1 }}
{{ else }}
cpu: 1k
memory: 1Ti
pods: 1M
{{ end }}
daemonEndpoints:
{{ with .daemonEndpoints }}
{{ . | YAML }}
{{ YAML . 1 }}
{{ else }}
kubeletEndpoint:
Port: 0
Expand Down

0 comments on commit 76c091f

Please sign in to comment.