Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some addon files are being templated when they shouldn't #18784

Closed
spowelljr opened this issue May 1, 2024 · 0 comments · Fixed by #18785
Closed

Some addon files are being templated when they shouldn't #18784

spowelljr opened this issue May 1, 2024 · 0 comments · Fixed by #18785
Assignees

Comments

@spowelljr
Copy link
Member

When adding addon files we call MustBinAsset:

"auto-pause": NewAddon([]*BinAsset{
MustBinAsset(
addons.AutoPauseAssets,
"auto-pause/auto-pause.yaml",
vmpath.GuestAddonsDir,
"auto-pause.yaml",
"0640"),

Which calls NewBinAsset:

func NewBinAsset(fs embed.FS, name, targetDir, targetName, permissions string) (*BinAsset, error) {
m := &BinAsset{
FS: fs,
BaseAsset: BaseAsset{
SourcePath: name,
TargetDir: targetDir,
TargetName: targetName,
Permissions: permissions,
},
template: nil,
}
err := m.loadData()
return m, err
}

Which calls loadData:

func (m *BinAsset) loadData() error {
contents, err := m.FS.ReadFile(m.SourcePath)
if err != nil {
return err
}
tpl, err := template.New(m.SourcePath).Funcs(template.FuncMap{"default": defaultValue}).Parse(string(contents))
if err != nil {
return err
}
m.template = tpl
m.length = len(contents)
m.reader = bytes.NewReader(contents)
klog.V(1).Infof("Created asset %s with %d bytes", m.SourcePath, m.length)
if m.length == 0 {
return fmt.Errorf("%s is an empty asset", m.SourcePath)
}
return nil
}

Which results in every addon file running through a templater. Only some files need templating, but up to now templating files that don't need it hasn't caused any issues.

But while trying to update the Kubeflow addon the YAML file has templating that essentially is used as validation during runtime to check for version compatibilities, but we're trying to template the file on load, resulting in:

panic: Failed to define asset kubeflow/kubeflow.yaml: template: kubeflow/kubeflow.yaml:118901: function "Template_Version_And_Istio_Version_Mismatched_Check_Installation" not defined

goroutine 1 [running]:
k8s.io/minikube/pkg/minikube/assets.MustBinAsset({0x10317f7e0?}, {0x101f2a8ec, 0x16}, {0x101f29d94?, 0x1?}, {0x101f1131e?, 0x14000593928?}, {0x101efea1b?, 0x10?})
	/Users/powellsteven/repo/minikube/pkg/minikube/assets/vm_assets.go:323 +0xb8
k8s.io/minikube/pkg/minikube/assets.init()
	/Users/powellsteven/repo/minikube/pkg/minikube/assets/addons.go:780 +0x687c

We have strictly been suffixing files that need templating with .tmpl so we can use that to decide what files need our templating. Everything else just load normally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant