@@ -21,6 +21,7 @@ import (
21
21
"fmt"
22
22
"path"
23
23
"path/filepath"
24
+ "strings"
24
25
"text/template"
25
26
"time"
26
27
@@ -47,6 +48,9 @@ type BuildrootProvisioner struct {
47
48
provision.SystemdProvisioner
48
49
}
49
50
51
+ // for escaping systemd template specifiers (e.g. '%i'), which are not supported by minikube
52
+ var systemdSpecifierEscaper = strings .NewReplacer ("%" , "%%" )
53
+
50
54
func init () {
51
55
provision .Register ("Buildroot" , & provision.RegisteredProvisioner {
52
56
New : NewBuildrootProvisioner ,
@@ -64,6 +68,17 @@ func (p *BuildrootProvisioner) String() string {
64
68
return "buildroot"
65
69
}
66
70
71
+ // escapeSystemdDirectives escapes special characters in the input variables used to create the
72
+ // systemd unit file, which would otherwise be interpreted as systemd directives. An example
73
+ // are template specifiers (e.g. '%i') which are predefined variables that get evaluated dynamically
74
+ // (see systemd man pages for more info). This is not supported by minikube, thus needs to be escaped.
75
+ func escapeSystemdDirectives (engineConfigContext * provision.EngineConfigContext ) {
76
+ // escape '%' in Environment option so that it does not evaluate into a template specifier
77
+ engineConfigContext .EngineOptions .Env = util .ReplaceChars (engineConfigContext .EngineOptions .Env , systemdSpecifierEscaper )
78
+ // input might contain whitespaces, wrap it in quotes
79
+ engineConfigContext .EngineOptions .Env = util .ConcatStrings (engineConfigContext .EngineOptions .Env , "\" " , "\" " )
80
+ }
81
+
67
82
// GenerateDockerOptions generates the *provision.DockerOptions for this provisioner
68
83
func (p * BuildrootProvisioner ) GenerateDockerOptions (dockerPort int ) (* provision.DockerOptions , error ) {
69
84
var engineCfg bytes.Buffer
@@ -127,6 +142,8 @@ WantedBy=multi-user.target
127
142
EngineOptions : p .EngineOptions ,
128
143
}
129
144
145
+ escapeSystemdDirectives (& engineConfigContext )
146
+
130
147
if err := t .Execute (& engineCfg , engineConfigContext ); err != nil {
131
148
return nil , err
132
149
}
0 commit comments