Skip to content

Commit 5390ccd

Browse files
committed
chore: replace []byte with string and use go:embed for templates
Optimize code a bit. Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
1 parent ba7cdc8 commit 5390ccd

16 files changed

+574
-550
lines changed

internal/app/machined/pkg/controllers/k8s/manifest.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (ctrl *ManifestController) Run(ctx context.Context, r controller.Runtime, l
112112
func(r *k8s.Manifest) error {
113113
return k8sadapter.Manifest(r).SetYAML(renderedManifest.data)
114114
}); err != nil {
115-
return fmt.Errorf("error updating manifests: %w", err)
115+
return fmt.Errorf("error updating manifest %q: %w", renderedManifest.name, err)
116116
}
117117
}
118118

@@ -122,7 +122,7 @@ func (ctrl *ManifestController) Run(ctx context.Context, r controller.Runtime, l
122122
return fmt.Errorf("error listing manifests: %w", err)
123123
}
124124

125-
manifestsToDelete := map[string]struct{}{}
125+
manifestsToDelete := make(map[string]struct{}, len(manifests.Items))
126126

127127
for _, manifest := range manifests.Items {
128128
if manifest.Metadata().Owner() != ctrl.Name() {
@@ -192,7 +192,7 @@ func (ctrl *ManifestController) render(cfg k8s.BootstrapManifestsConfigSpec, scr
192192

193193
type manifestDesc struct {
194194
name string
195-
template []byte
195+
template string
196196
}
197197

198198
defaultManifests := []manifestDesc{
@@ -252,7 +252,7 @@ func (ctrl *ManifestController) render(cfg k8s.BootstrapManifestsConfigSpec, scr
252252
"join": strings.Join,
253253
"contains": strings.Contains,
254254
}).
255-
Parse(string(defaultManifests[i].template))
255+
Parse(defaultManifests[i].template)
256256
if err != nil {
257257
return nil, fmt.Errorf("error parsing manifest template %q: %w", defaultManifests[i].name, err)
258258
}

internal/app/machined/pkg/controllers/k8s/render_secrets_static_pod.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (ctrl *RenderSecretsStaticPodController) Run(ctx context.Context, r control
158158

159159
type template struct {
160160
filename string
161-
template []byte
161+
template string
162162
}
163163

164164
for _, pod := range []struct {
@@ -253,7 +253,7 @@ func (ctrl *RenderSecretsStaticPodController) Run(ctx context.Context, r control
253253
templates: []template{
254254
{
255255
filename: "kubeconfig",
256-
template: []byte("{{ .Secrets.ControllerManagerKubeconfig }}"),
256+
template: "{{ .Secrets.ControllerManagerKubeconfig }}",
257257
},
258258
},
259259
},
@@ -265,7 +265,7 @@ func (ctrl *RenderSecretsStaticPodController) Run(ctx context.Context, r control
265265
templates: []template{
266266
{
267267
filename: "kubeconfig",
268-
template: []byte("{{ .Secrets.SchedulerKubeconfig }}"),
268+
template: "{{ .Secrets.SchedulerKubeconfig }}",
269269
},
270270
},
271271
},
@@ -311,7 +311,7 @@ func (ctrl *RenderSecretsStaticPodController) Run(ctx context.Context, r control
311311
for _, templ := range pod.templates {
312312
var t *stdlibtemplate.Template
313313

314-
t, err = stdlibtemplate.New(templ.filename).Parse(string(templ.template))
314+
t, err = stdlibtemplate.New(templ.filename).Parse(templ.template)
315315
if err != nil {
316316
return fmt.Errorf("error parsing template %q: %w", templ.filename, err)
317317
}

0 commit comments

Comments
 (0)