Merge pull request #25983 from matejvasek/fix-inherit-label

Fix: inheritlabels=true if query param absent
This commit is contained in:
openshift-merge-bot[bot] 2025-04-28 16:02:48 +00:00 committed by GitHub
commit 2679304aa8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 130 additions and 78 deletions

View File

@ -130,7 +130,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
IDMappingOptions string `schema:"idmappingoptions"`
IdentityLabel bool `schema:"identitylabel"`
Ignore bool `schema:"ignore"`
InheritLabels bool `schema:"inheritlabels"`
InheritLabels types.OptionalBool `schema:"inheritlabels"`
Isolation string `schema:"isolation"`
Jobs int `schema:"jobs"`
LabelOpts string `schema:"labelopts"`
@ -745,7 +745,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
IDMappingOptions: &idMappingOptions,
IgnoreUnrecognizedInstructions: query.Ignore,
IgnoreFile: ignoreFile,
InheritLabels: types.NewOptionalBool(query.InheritLabels),
InheritLabels: query.InheritLabels,
Isolation: isolation,
Jobs: &jobs,
Labels: labels,

View File

@ -5,10 +5,12 @@ package handlers
import (
"encoding/json"
"reflect"
"strconv"
"strings"
"syscall"
"time"
"github.com/containers/image/v5/types"
"github.com/containers/podman/v5/libpod/define"
"github.com/containers/podman/v5/pkg/util"
"github.com/gorilla/schema"
@ -28,6 +30,9 @@ func NewAPIDecoder() *schema.Decoder {
var Signal syscall.Signal
d.RegisterConverter(Signal, convertSignal)
d.RegisterConverter(types.OptionalBoolUndefined, convertOptionalBool)
return d
}
@ -39,6 +44,16 @@ func NewCompatAPIDecoder() *schema.Decoder {
s = strings.ToLower(strings.TrimSpace(s))
return reflect.ValueOf(s != "" && s != "0" && s != "no" && s != "false" && s != "none")
})
dec.RegisterConverter(types.OptionalBoolUndefined, func(s string) reflect.Value {
if len(s) == 0 {
return reflect.ValueOf(types.OptionalBoolUndefined)
}
s = strings.ToLower(strings.TrimSpace(s))
if s != "0" && s != "no" && s != "false" && s != "none" {
return reflect.ValueOf(types.OptionalBoolTrue)
}
return reflect.ValueOf(types.OptionalBoolFalse)
})
return dec
}
@ -143,3 +158,14 @@ func convertSignal(query string) reflect.Value {
}
return reflect.ValueOf(signal)
}
func convertOptionalBool(s string) reflect.Value {
if len(s) == 0 {
return reflect.ValueOf(types.OptionalBoolUndefined)
}
val, _ := strconv.ParseBool(s)
if val {
return reflect.ValueOf(types.OptionalBoolTrue)
}
return reflect.ValueOf(types.OptionalBoolFalse)
}

26
test/apiv2/90-build.at Normal file
View File

@ -0,0 +1,26 @@
# -*- sh -*-
#
# Tests for build-related endpoints
#
# test if default compat build contains labels from base image
TMPD=$(mktemp -d podman-apiv2-test.build.XXXXXXXX)
function cleanBuildTest() {
podman rmi -a -f
rm -rf "${TMPD}" &> /dev/null
}
CONTAINERFILE_TAR="${TMPD}/containerfile.tar"
cat > $TMPD/containerfile << EOF
FROM $IMAGE
RUN echo hello
EOF
tar --format=posix -C $TMPD -cvf ${CONTAINERFILE_TAR} containerfile &> /dev/null
t POST "/build?dockerfile=containerfile&t=labeltest" $CONTAINERFILE_TAR 200 \
'.aux|select(has("ID")).ID~^sha256:[0-9a-f]\{64\}$'
t GET images/labeltest/json 200 \
.Config.Labels.created_by="test/system/build-testimage"
cleanBuildTest
# vim: filetype=sh