Fix: inheritlabels=true if query param absent

The inheritlabels param must default to true if query param is absent.

Signed-off-by: Matej Vašek <matejvasek@gmail.com>
This commit is contained in:
Matej Vašek
2025-04-25 17:18:49 +02:00
committed by openshift-cherrypick-robot
parent f271c9360d
commit b2a99aab3f
2 changed files with 104 additions and 78 deletions

View File

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

View File

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