mirror of
https://github.com/containers/podman.git
synced 2025-06-30 15:49:03 +08:00
Merge pull request #25964 from SuNNjek/quadlet-pod-labels
Add Label to quadlet pod
This commit is contained in:
@ -736,7 +736,7 @@ func process() bool {
|
||||
case strings.HasSuffix(unit.Filename, ".build"):
|
||||
service, warnings, err = quadlet.ConvertBuild(unit, unitsInfoMap, isUserFlag)
|
||||
case strings.HasSuffix(unit.Filename, ".pod"):
|
||||
service, err = quadlet.ConvertPod(unit, unit.Filename, unitsInfoMap, isUserFlag)
|
||||
service, warnings, err = quadlet.ConvertPod(unit, unit.Filename, unitsInfoMap, isUserFlag)
|
||||
default:
|
||||
Logf("Unsupported file type %q", unit.Filename)
|
||||
continue
|
||||
|
@ -1008,6 +1008,7 @@ Valid options for `[Pod]` are listed below:
|
||||
| HostName=name | --hostname=name |
|
||||
| IP=192.5.0.1 | --ip 192.5.0.1 |
|
||||
| IP6=2001:db8::1 | --ip6 2001:db8::1 |
|
||||
| Label="XYZ" | --label "XYZ" |
|
||||
| Network=host | --network host |
|
||||
| NetworkAlias=name | --network-alias name |
|
||||
| PodmanArgs=\-\-cpus=2 | --cpus=2 |
|
||||
@ -1093,6 +1094,13 @@ Equivalent to the Podman `--ip` option.
|
||||
Specify a static IPv6 address for the pod, for example **fd46:db93:aa76:ac37::10**.
|
||||
Equivalent to the Podman `--ip6` option.
|
||||
|
||||
### `Label=`
|
||||
|
||||
Set one or more OCI labels on the pod. The format is a list of
|
||||
`key=value` items, similar to `Environment`.
|
||||
|
||||
This key can be listed multiple times.
|
||||
|
||||
### `Network=`
|
||||
|
||||
Specify a custom network for the pod.
|
||||
|
@ -450,6 +450,7 @@ var (
|
||||
KeyHostName: true,
|
||||
KeyIP: true,
|
||||
KeyIP6: true,
|
||||
KeyLabel: true,
|
||||
KeyNetwork: true,
|
||||
KeyNetworkAlias: true,
|
||||
KeyPodName: true,
|
||||
@ -1622,17 +1623,19 @@ func getServiceName(quadletUnitFile *parser.UnitFile, groupName string, defaultE
|
||||
return removeExtension(quadletUnitFile.Filename, "", defaultExtraSuffix)
|
||||
}
|
||||
|
||||
func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*UnitInfo, isUser bool) (*parser.UnitFile, error) {
|
||||
func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*UnitInfo, isUser bool) (*parser.UnitFile, error, error) {
|
||||
var warn, warnings error
|
||||
|
||||
unitInfo, ok := unitsInfoMap[podUnit.Filename]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("internal error while processing pod %s", podUnit.Filename)
|
||||
return nil, warnings, fmt.Errorf("internal error while processing pod %s", podUnit.Filename)
|
||||
}
|
||||
|
||||
service := podUnit.Dup()
|
||||
service.Filename = unitInfo.ServiceFileName()
|
||||
|
||||
if err := translateUnitDependencies(service, unitsInfoMap); err != nil {
|
||||
return nil, err
|
||||
return nil, warnings, err
|
||||
}
|
||||
|
||||
addDefaultDependencies(service, isUser)
|
||||
@ -1642,7 +1645,7 @@ func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*
|
||||
}
|
||||
|
||||
if err := checkForUnknownKeys(podUnit, PodGroup, supportedPodKeys); err != nil {
|
||||
return nil, err
|
||||
return nil, warnings, err
|
||||
}
|
||||
|
||||
// Derive pod name from unit name (with added prefix), or use user-provided name.
|
||||
@ -1701,13 +1704,17 @@ func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*
|
||||
)
|
||||
|
||||
if err := handleUserMappings(podUnit, PodGroup, execStartPre, true); err != nil {
|
||||
return nil, err
|
||||
return nil, warnings, err
|
||||
}
|
||||
|
||||
handlePublishPorts(podUnit, PodGroup, execStartPre)
|
||||
|
||||
labels, warn := podUnit.LookupAllKeyVal(PodGroup, KeyLabel)
|
||||
warnings = errors.Join(warnings, warn)
|
||||
execStartPre.addLabels(labels)
|
||||
|
||||
if err := addNetworks(podUnit, PodGroup, service, unitsInfoMap, execStartPre); err != nil {
|
||||
return nil, err
|
||||
return nil, warnings, err
|
||||
}
|
||||
|
||||
stringsKeys := map[string]string{
|
||||
@ -1728,7 +1735,7 @@ func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*
|
||||
lookupAndAddAllStrings(podUnit, PodGroup, allStringsKeys, execStartPre)
|
||||
|
||||
if err := addVolumes(podUnit, service, PodGroup, unitsInfoMap, execStartPre); err != nil {
|
||||
return nil, err
|
||||
return nil, warnings, err
|
||||
}
|
||||
|
||||
execStartPre.add("--infra-name", fmt.Sprintf("%s-infra", podName))
|
||||
@ -1745,7 +1752,7 @@ func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*
|
||||
"PIDFile", "%t/%N.pid",
|
||||
)
|
||||
|
||||
return service, nil
|
||||
return service, warnings, nil
|
||||
}
|
||||
|
||||
func handleUser(unitFile *parser.UnitFile, groupName string, podman *PodmanCmdline) error {
|
||||
|
10
test/e2e/quadlet/label.pod
Normal file
10
test/e2e/quadlet/label.pod
Normal file
@ -0,0 +1,10 @@
|
||||
## assert-podman-pre-args "--label" "org.foo.Arg0=arg0"
|
||||
## assert-podman-pre-args "--label" "org.foo.Arg1=arg1"
|
||||
## assert-podman-pre-args "--label" "org.foo.Arg2=arg 2"
|
||||
## assert-podman-pre-args "--label" "org.foo.Arg3=arg3"
|
||||
|
||||
[Pod]
|
||||
Label=org.foo.Arg1=arg1 "org.foo.Arg2=arg 2" \
|
||||
org.foo.Arg3=arg3
|
||||
|
||||
Label=org.foo.Arg0=arg0
|
@ -1078,6 +1078,7 @@ BOGUS=foo
|
||||
Entry("Pod - Host", "host.pod"),
|
||||
Entry("Pod - HostName", "hostname.pod"),
|
||||
Entry("Pod - IP", "ip.pod"),
|
||||
Entry("Pod - Label", "label.pod"),
|
||||
Entry("Pod - Name", "name.pod"),
|
||||
Entry("Pod - Network", "network.pod"),
|
||||
Entry("Pod - PodmanArgs", "podmanargs.pod"),
|
||||
|
Reference in New Issue
Block a user