@@ -601,10 +601,6 @@ func ConvertContainer(container *parser.UnitFile, isUser bool, unitsInfoMap map[
601
601
service .Set (ServiceGroup , "KillMode" , "mixed" )
602
602
}
603
603
604
- // Read env early so we can override it below
605
- podmanEnv , warn := container .LookupAllKeyVal (ContainerGroup , KeyEnvironment )
606
- warnings = errors .Join (warnings , warn )
607
-
608
604
// Need the containers filesystem mounted to start podman
609
605
service .Add (UnitGroup , "RequiresMountsFor" , "%t/containers" )
610
606
@@ -814,9 +810,12 @@ func ConvertContainer(container *parser.UnitFile, isUser bool, unitsInfoMap map[
814
810
815
811
update , ok := container .Lookup (ContainerGroup , KeyAutoUpdate )
816
812
if ok && len (update ) > 0 {
817
- podman .addLabels (map [string ]string {
818
- autoUpdateLabel : update ,
819
- })
813
+ podman .addKeys (
814
+ "--label" ,
815
+ map [string ]string {
816
+ autoUpdateLabel : update ,
817
+ },
818
+ )
820
819
}
821
820
822
821
exposedPorts := container .LookupAll (ContainerGroup , KeyExposeHostPort )
@@ -832,15 +831,13 @@ func ConvertContainer(container *parser.UnitFile, isUser bool, unitsInfoMap map[
832
831
833
832
handlePublishPorts (container , ContainerGroup , podman )
834
833
835
- podman .addEnv (podmanEnv )
836
-
837
- labels , warn := container .LookupAllKeyVal (ContainerGroup , KeyLabel )
838
- warnings = errors .Join (warnings , warn )
839
- podman .addLabels (labels )
840
-
841
- annotations , warn := container .LookupAllKeyVal (ContainerGroup , KeyAnnotation )
834
+ keyValKeys := map [string ]string {
835
+ KeyEnvironment : "--env" ,
836
+ KeyLabel : "--label" ,
837
+ KeyAnnotation : "--annotation" ,
838
+ }
839
+ warn = lookupAndAddKeyVals (container , ContainerGroup , keyValKeys , podman )
842
840
warnings = errors .Join (warnings , warn )
843
- podman .addAnnotations (annotations )
844
841
845
842
masks := container .LookupAllArgs (ContainerGroup , KeyMask )
846
843
for _ , mask := range masks {
@@ -1041,17 +1038,12 @@ func ConvertNetwork(network *parser.UnitFile, name string, unitsInfoMap map[stri
1041
1038
return nil , warnings , fmt .Errorf ("cannot set gateway or range without subnet" )
1042
1039
}
1043
1040
1044
- networkOptions , warn := network .LookupAllKeyVal (NetworkGroup , KeyOptions )
1045
- warnings = errors .Join (warnings , warn )
1046
- if len (networkOptions ) > 0 {
1047
- podman .addKeys ("--opt" , networkOptions )
1041
+ keyValKeys := map [string ]string {
1042
+ KeyOptions : "--opt" ,
1043
+ KeyLabel : "--label" ,
1048
1044
}
1049
-
1050
- labels , warn := network .LookupAllKeyVal (NetworkGroup , KeyLabel )
1045
+ warn = lookupAndAddKeyVals (network , NetworkGroup , keyValKeys , podman )
1051
1046
warnings = errors .Join (warnings , warn )
1052
- if len (labels ) > 0 {
1053
- podman .addLabels (labels )
1054
- }
1055
1047
1056
1048
handlePodmanArgs (network , NetworkGroup , podman )
1057
1049
@@ -1111,9 +1103,6 @@ func ConvertVolume(volume *parser.UnitFile, name string, unitsInfoMap map[string
1111
1103
// Need the containers filesystem mounted to start podman
1112
1104
service .Add (UnitGroup , "RequiresMountsFor" , "%t/containers" )
1113
1105
1114
- labels , warn := volume .LookupAllKeyVal (VolumeGroup , "Label" )
1115
- warnings = errors .Join (warnings , warn )
1116
-
1117
1106
podman := createBasePodmanCommand (volume , VolumeGroup )
1118
1107
1119
1108
podman .add ("volume" , "create" , "--ignore" )
@@ -1200,7 +1189,11 @@ func ConvertVolume(volume *parser.UnitFile, name string, unitsInfoMap map[string
1200
1189
podman .add ("--opt" , opts .String ())
1201
1190
}
1202
1191
1203
- podman .addLabels (labels )
1192
+ keyValKeys := map [string ]string {
1193
+ KeyLabel : "--label" ,
1194
+ }
1195
+ warn = lookupAndAddKeyVals (volume , VolumeGroup , keyValKeys , podman )
1196
+ warnings = errors .Join (warnings , warn )
1204
1197
1205
1198
handlePodmanArgs (volume , VolumeGroup , podman )
1206
1199
@@ -1516,18 +1509,13 @@ func ConvertBuild(build *parser.UnitFile, unitsInfoMap map[string]*UnitInfo, isU
1516
1509
}
1517
1510
lookupAndAddAllStrings (build , BuildGroup , allStringKeys , podman )
1518
1511
1519
- annotations , warn := build .LookupAllKeyVal (BuildGroup , KeyAnnotation )
1520
- warnings = errors .Join (warnings , warn )
1521
-
1522
- podman .addAnnotations (annotations )
1523
-
1524
- podmanEnv , warn := build .LookupAllKeyVal (BuildGroup , KeyEnvironment )
1525
- warnings = errors .Join (warnings , warn )
1526
- podman .addEnv (podmanEnv )
1527
-
1528
- labels , warn := build .LookupAllKeyVal (BuildGroup , KeyLabel )
1512
+ keyValKeys := map [string ]string {
1513
+ KeyEnvironment : "--env" ,
1514
+ KeyLabel : "--label" ,
1515
+ KeyAnnotation : "--annotation" ,
1516
+ }
1517
+ warn = lookupAndAddKeyVals (build , BuildGroup , keyValKeys , podman )
1529
1518
warnings = errors .Join (warnings , warn )
1530
- podman .addLabels (labels )
1531
1519
1532
1520
if err := addNetworks (build , BuildGroup , service , unitsInfoMap , podman ); err != nil {
1533
1521
return nil , warnings , err
@@ -1709,9 +1697,11 @@ func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*
1709
1697
1710
1698
handlePublishPorts (podUnit , PodGroup , execStartPre )
1711
1699
1712
- labels , warn := podUnit .LookupAllKeyVal (PodGroup , KeyLabel )
1700
+ keyValKeys := map [string ]string {
1701
+ KeyLabel : "--label" ,
1702
+ }
1703
+ warn = lookupAndAddKeyVals (podUnit , PodGroup , keyValKeys , execStartPre )
1713
1704
warnings = errors .Join (warnings , warn )
1714
- execStartPre .addLabels (labels )
1715
1705
1716
1706
if err := addNetworks (podUnit , PodGroup , service , unitsInfoMap , execStartPre ); err != nil {
1717
1707
return nil , warnings , err
@@ -2368,3 +2358,13 @@ func translateUnitDependencies(serviceUnitFile *parser.UnitFile, unitsInfoMap ma
2368
2358
}
2369
2359
return nil
2370
2360
}
2361
+
2362
+ func lookupAndAddKeyVals (unit * parser.UnitFile , group string , keys map [string ]string , podman * PodmanCmdline ) error {
2363
+ var warnings error
2364
+ for key , flag := range keys {
2365
+ keyVals , warn := unit .LookupAllKeyVal (group , key )
2366
+ warnings = errors .Join (warnings , warn )
2367
+ podman .addKeys (flag , keyVals )
2368
+ }
2369
+ return warnings
2370
+ }
0 commit comments