mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-08-19 04:26:45 +00:00
* fix(controller): decode old object for delete requests Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: modernize golang Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: modernize golang Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: modernize golang Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * fix: preserve ca-bundles injected from external providers Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * fix: best effort patch reconciling status Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * fix: use different match strategy for truthy and match Signed-off-by: Oliver Baehler <oliver@sudo-i.net> --------- Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
// Copyright 2020-2026 Project Capsule Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/projectcapsule/capsule/internal/cache"
|
|
"github.com/projectcapsule/capsule/pkg/runtime/jsonpath"
|
|
"github.com/projectcapsule/capsule/pkg/runtime/selectors"
|
|
)
|
|
|
|
func CompileFieldSelector(
|
|
cache *cache.JSONPathCache,
|
|
raw string,
|
|
) (selectors.CompiledFieldSelector, error) {
|
|
raw = strings.TrimSpace(raw)
|
|
if raw == "" {
|
|
return selectors.CompiledFieldSelector{}, fmt.Errorf("field selector must not be empty")
|
|
}
|
|
|
|
path, value, ok := jsonpath.SplitFieldSelectorEquals(raw)
|
|
if !ok {
|
|
compiledPath, err := cache.GetOrCompile(raw)
|
|
if err != nil {
|
|
return selectors.CompiledFieldSelector{}, err
|
|
}
|
|
|
|
return selectors.CompiledFieldSelector{
|
|
Raw: raw,
|
|
Path: raw,
|
|
Operator: selectors.FieldSelectorTruthy,
|
|
Compiled: compiledPath,
|
|
}, nil
|
|
}
|
|
|
|
compiledPath, err := cache.GetOrCompile(path)
|
|
if err != nil {
|
|
return selectors.CompiledFieldSelector{}, err
|
|
}
|
|
|
|
return selectors.CompiledFieldSelector{
|
|
Raw: raw,
|
|
Path: path,
|
|
Operator: selectors.FieldSelectorEquals,
|
|
Value: value,
|
|
Compiled: compiledPath,
|
|
}, nil
|
|
}
|