@@ -394,7 +394,7 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
394
394
if provision .Mode == ProvisionModeDependency && provision .SkipDefaultDependencyResolution == nil {
395
395
provision .SkipDefaultDependencyResolution = ptr .Of (false )
396
396
}
397
- if out , err := executeGuestTemplate (provision .Script , instDir ); err == nil {
397
+ if out , err := executeGuestTemplate (provision .Script , instDir , y . Param ); err == nil {
398
398
provision .Script = out .String ()
399
399
} else {
400
400
logrus .WithError (err ).Warnf ("Couldn't process provisioning script %q as a template" , provision .Script )
@@ -460,17 +460,22 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
460
460
if probe .Description == "" {
461
461
probe .Description = fmt .Sprintf ("user probe %d/%d" , i + 1 , len (y .Probes ))
462
462
}
463
+ if out , err := executeGuestTemplate (probe .Script , instDir , y .Param ); err == nil {
464
+ probe .Script = out .String ()
465
+ } else {
466
+ logrus .WithError (err ).Warnf ("Couldn't process probing script %q as a template" , probe .Script )
467
+ }
463
468
}
464
469
465
470
y .PortForwards = append (append (o .PortForwards , y .PortForwards ... ), d .PortForwards ... )
466
471
for i := range y .PortForwards {
467
- FillPortForwardDefaults (& y .PortForwards [i ], instDir )
472
+ FillPortForwardDefaults (& y .PortForwards [i ], instDir , y . Param )
468
473
// After defaults processing the singular HostPort and GuestPort values should not be used again.
469
474
}
470
475
471
476
y .CopyToHost = append (append (o .CopyToHost , y .CopyToHost ... ), d .CopyToHost ... )
472
477
for i := range y .CopyToHost {
473
- FillCopyToHostDefaults (& y .CopyToHost [i ], instDir )
478
+ FillCopyToHostDefaults (& y .CopyToHost [i ], instDir , y . Param )
474
479
}
475
480
476
481
if y .HostResolver .Enabled == nil {
@@ -669,6 +674,18 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
669
674
}
670
675
y .Env = env
671
676
677
+ param := make (map [string ]string )
678
+ for k , v := range d .Param {
679
+ param [k ] = v
680
+ }
681
+ for k , v := range y .Param {
682
+ param [k ] = v
683
+ }
684
+ for k , v := range o .Param {
685
+ param [k ] = v
686
+ }
687
+ y .Param = param
688
+
672
689
if y .CACertificates .RemoveDefaults == nil {
673
690
y .CACertificates .RemoveDefaults = d .CACertificates .RemoveDefaults
674
691
}
@@ -735,15 +752,16 @@ func fixUpForPlainMode(y *LimaYAML) {
735
752
y .TimeZone = ptr .Of ("" )
736
753
}
737
754
738
- func executeGuestTemplate (format , instDir string ) (bytes.Buffer , error ) {
755
+ func executeGuestTemplate (format , instDir string , param map [ string ] string ) (bytes.Buffer , error ) {
739
756
tmpl , err := template .New ("" ).Parse (format )
740
757
if err == nil {
741
758
user , _ := osutil .LimaUser (false )
742
- data := map [string ]string {
743
- "Home" : fmt .Sprintf ("/home/%s.linux" , user .Username ),
744
- "Name" : filepath .Base (instDir ),
745
- "UID" : user .Uid ,
746
- "User" : user .Username ,
759
+ data := map [string ]interface {}{
760
+ "Home" : fmt .Sprintf ("/home/%s.linux" , user .Username ),
761
+ "Name" : filepath .Base (instDir ),
762
+ "UID" : user .Uid ,
763
+ "User" : user .Username ,
764
+ "Param" : param ,
747
765
}
748
766
var out bytes.Buffer
749
767
if err := tmpl .Execute (& out , data ); err == nil {
@@ -753,18 +771,19 @@ func executeGuestTemplate(format, instDir string) (bytes.Buffer, error) {
753
771
return bytes.Buffer {}, err
754
772
}
755
773
756
- func executeHostTemplate (format , instDir string ) (bytes.Buffer , error ) {
774
+ func executeHostTemplate (format , instDir string , param map [ string ] string ) (bytes.Buffer , error ) {
757
775
tmpl , err := template .New ("" ).Parse (format )
758
776
if err == nil {
759
777
user , _ := osutil .LimaUser (false )
760
778
home , _ := os .UserHomeDir ()
761
779
limaHome , _ := dirnames .LimaDir ()
762
- data := map [string ]string {
763
- "Dir" : instDir ,
764
- "Home" : home ,
765
- "Name" : filepath .Base (instDir ),
766
- "UID" : user .Uid ,
767
- "User" : user .Username ,
780
+ data := map [string ]interface {}{
781
+ "Dir" : instDir ,
782
+ "Home" : home ,
783
+ "Name" : filepath .Base (instDir ),
784
+ "UID" : user .Uid ,
785
+ "User" : user .Username ,
786
+ "Param" : param ,
768
787
769
788
"Instance" : filepath .Base (instDir ), // DEPRECATED, use `{{.Name}}`
770
789
"LimaHome" : limaHome , // DEPRECATED, use `{{.Dir}}` instead of `{{.LimaHome}}/{{.Instance}}`
@@ -777,7 +796,7 @@ func executeHostTemplate(format, instDir string) (bytes.Buffer, error) {
777
796
return bytes.Buffer {}, err
778
797
}
779
798
780
- func FillPortForwardDefaults (rule * PortForward , instDir string ) {
799
+ func FillPortForwardDefaults (rule * PortForward , instDir string , param map [ string ] string ) {
781
800
if rule .Proto == "" {
782
801
rule .Proto = TCP
783
802
}
@@ -809,14 +828,14 @@ func FillPortForwardDefaults(rule *PortForward, instDir string) {
809
828
}
810
829
}
811
830
if rule .GuestSocket != "" {
812
- if out , err := executeGuestTemplate (rule .GuestSocket , instDir ); err == nil {
831
+ if out , err := executeGuestTemplate (rule .GuestSocket , instDir , param ); err == nil {
813
832
rule .GuestSocket = out .String ()
814
833
} else {
815
834
logrus .WithError (err ).Warnf ("Couldn't process guestSocket %q as a template" , rule .GuestSocket )
816
835
}
817
836
}
818
837
if rule .HostSocket != "" {
819
- if out , err := executeHostTemplate (rule .HostSocket , instDir ); err == nil {
838
+ if out , err := executeHostTemplate (rule .HostSocket , instDir , param ); err == nil {
820
839
rule .HostSocket = out .String ()
821
840
} else {
822
841
logrus .WithError (err ).Warnf ("Couldn't process hostSocket %q as a template" , rule .HostSocket )
@@ -827,16 +846,16 @@ func FillPortForwardDefaults(rule *PortForward, instDir string) {
827
846
}
828
847
}
829
848
830
- func FillCopyToHostDefaults (rule * CopyToHost , instDir string ) {
849
+ func FillCopyToHostDefaults (rule * CopyToHost , instDir string , param map [ string ] string ) {
831
850
if rule .GuestFile != "" {
832
- if out , err := executeGuestTemplate (rule .GuestFile , instDir ); err == nil {
851
+ if out , err := executeGuestTemplate (rule .GuestFile , instDir , param ); err == nil {
833
852
rule .GuestFile = out .String ()
834
853
} else {
835
854
logrus .WithError (err ).Warnf ("Couldn't process guest %q as a template" , rule .GuestFile )
836
855
}
837
856
}
838
857
if rule .HostFile != "" {
839
- if out , err := executeHostTemplate (rule .HostFile , instDir ); err == nil {
858
+ if out , err := executeHostTemplate (rule .HostFile , instDir , param ); err == nil {
840
859
rule .HostFile = out .String ()
841
860
} else {
842
861
logrus .WithError (err ).Warnf ("Couldn't process host %q as a template" , rule .HostFile )
0 commit comments