Skip to content

Commit c304741

Browse files
authored
Bump boxcutter to v0.13.0 (#2617)
Bumps boxcutter to latest version which now contains the FieldValue probe, which allows us to remove it from our codebase. Signed-off-by: Daniel Franz <dfranz@redhat.com>
1 parent 10dc0bc commit c304741

File tree

5 files changed

+4
-152
lines changed

5 files changed

+4
-152
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ require (
4545
k8s.io/klog/v2 v2.140.0
4646
k8s.io/kubernetes v1.35.0
4747
k8s.io/utils v0.0.0-20260319190234-28399d86e0b5
48-
pkg.package-operator.run/boxcutter v0.12.0
48+
pkg.package-operator.run/boxcutter v0.13.0
4949
sigs.k8s.io/controller-runtime v0.23.3
5050
sigs.k8s.io/controller-tools v0.20.1
5151
sigs.k8s.io/crdify v0.5.1-0.20260309184313-54162f2e3097

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,8 @@ k8s.io/utils v0.0.0-20260319190234-28399d86e0b5 h1:kBawHLSnx/mYHmRnNUf9d4CpjREbe
796796
k8s.io/utils v0.0.0-20260319190234-28399d86e0b5/go.mod h1:xDxuJ0whA3d0I4mf/C4ppKHxXynQ+fxnkmQH0vTHnuk=
797797
oras.land/oras-go/v2 v2.6.0 h1:X4ELRsiGkrbeox69+9tzTu492FMUu7zJQW6eJU+I2oc=
798798
oras.land/oras-go/v2 v2.6.0/go.mod h1:magiQDfG6H1O9APp+rOsvCPcW1GD2MM7vgnKY0Y+u1o=
799-
pkg.package-operator.run/boxcutter v0.12.0 h1:9XAi8MjwghfNHyuWzhqrEjY+XIGUz2rg+A72KITb+wA=
800-
pkg.package-operator.run/boxcutter v0.12.0/go.mod h1:Bo1tgiXCYJtehp5p+2aTrKt7VnJhrGKSSBvUQofnDRg=
799+
pkg.package-operator.run/boxcutter v0.13.0 h1:LNUS36NFkI+6J1CcVMrmTOtZt8UoalwXcIDlTPG66C4=
800+
pkg.package-operator.run/boxcutter v0.13.0/go.mod h1:Bo1tgiXCYJtehp5p+2aTrKt7VnJhrGKSSBvUQofnDRg=
801801
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.34.0 h1:hSfpvjjTQXQY2Fol2CS0QHMNs/WI1MOSGzCm1KhM5ec=
802802
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.34.0/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw=
803803
sigs.k8s.io/controller-runtime v0.23.3 h1:VjB/vhoPoA9l1kEKZHBMnQF33tdCLQKJtydy4iqwZ80=

internal/operator-controller/applier/phase.go

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@ package applier
22

33
import (
44
"cmp"
5-
"encoding/json"
6-
"fmt"
75
"slices"
8-
"strings"
96

10-
"k8s.io/apimachinery/pkg/api/equality"
11-
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
127
"k8s.io/apimachinery/pkg/runtime/schema"
13-
"pkg.package-operator.run/boxcutter/probing"
14-
"sigs.k8s.io/controller-runtime/pkg/client"
158

169
ocv1ac "github.com/operator-framework/operator-controller/applyconfigurations/api/v1"
17-
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util"
1810
)
1911

2012
// The following, with modifications, is taken from:
@@ -206,58 +198,3 @@ func PhaseSort(unsortedObjs []ocv1ac.ClusterObjectSetObjectApplyConfiguration) [
206198

207199
return phasesSorted
208200
}
209-
210-
// FieldValueProbe checks if the value found at FieldPath matches the provided Value
211-
type FieldValueProbe struct {
212-
FieldPath, Value string
213-
}
214-
215-
var _ probing.Prober = (*FieldValueProbe)(nil)
216-
217-
// Probe executes the probe.
218-
func (fe *FieldValueProbe) Probe(obj client.Object) probing.Result {
219-
uMap, err := util.ToUnstructured(obj)
220-
if err != nil {
221-
return probing.UnknownResult(fmt.Sprintf("failed to convert to unstructured: %v", err))
222-
}
223-
return fe.probe(uMap)
224-
}
225-
226-
func (fv *FieldValueProbe) probe(obj *unstructured.Unstructured) probing.Result {
227-
fieldPath := strings.Split(strings.Trim(fv.FieldPath, "."), ".")
228-
229-
fieldVal, ok, err := unstructured.NestedFieldCopy(obj.Object, fieldPath...)
230-
if err != nil {
231-
return probing.Result{
232-
Status: probing.StatusFalse,
233-
Messages: []string{fmt.Sprintf(`error locating key %q; %v`, fv.FieldPath, err)},
234-
}
235-
}
236-
if !ok {
237-
return probing.Result{
238-
Status: probing.StatusFalse,
239-
Messages: []string{fmt.Sprintf(`missing key: %q`, fv.FieldPath)},
240-
}
241-
}
242-
243-
if !equality.Semantic.DeepEqual(fieldVal, fv.Value) {
244-
foundJSON, err := json.Marshal(fieldVal)
245-
if err != nil {
246-
foundJSON = []byte("<value marshal failed>")
247-
}
248-
expectedJSON, err := json.Marshal(fv.Value)
249-
if err != nil {
250-
expectedJSON = []byte("<value marshal failed>")
251-
}
252-
253-
return probing.Result{
254-
Status: probing.StatusFalse,
255-
Messages: []string{fmt.Sprintf(`value at key %q != %q; expected: %s got: %s`, fv.FieldPath, fv.Value, expectedJSON, foundJSON)},
256-
}
257-
}
258-
259-
return probing.Result{
260-
Status: probing.StatusTrue,
261-
Messages: []string{fmt.Sprintf(`value at key %q == %q`, fv.FieldPath, fv.Value)},
262-
}
263-
}

internal/operator-controller/applier/phase_test.go

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@ package applier_test
33
import (
44
"testing"
55

6-
"github.com/stretchr/testify/assert"
76
"github.com/stretchr/testify/require"
8-
corev1 "k8s.io/api/core/v1"
9-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
107
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
118
"k8s.io/utils/ptr"
12-
"pkg.package-operator.run/boxcutter/probing"
13-
"sigs.k8s.io/controller-runtime/pkg/client"
149

1510
ocv1ac "github.com/operator-framework/operator-controller/applyconfigurations/api/v1"
1611
"github.com/operator-framework/operator-controller/internal/operator-controller/applier"
@@ -1036,82 +1031,3 @@ func Test_PhaseSort(t *testing.T) {
10361031
})
10371032
}
10381033
}
1039-
1040-
func Test_FieldValueProbe(t *testing.T) {
1041-
for _, tc := range []struct {
1042-
name string
1043-
obj client.Object
1044-
probe applier.FieldValueProbe
1045-
expectedResult probing.Result
1046-
}{
1047-
{
1048-
name: "True result with found key and equal value",
1049-
obj: &corev1.Service{
1050-
TypeMeta: metav1.TypeMeta{Kind: "Service", APIVersion: "v1"},
1051-
ObjectMeta: metav1.ObjectMeta{Name: "my-service", Namespace: "my-namespace"},
1052-
},
1053-
probe: applier.FieldValueProbe{
1054-
FieldPath: "metadata.name",
1055-
Value: "my-service",
1056-
},
1057-
expectedResult: probing.Result{
1058-
Status: probing.StatusTrue,
1059-
Messages: []string{
1060-
`value at key "metadata.name" == "my-service"`,
1061-
},
1062-
},
1063-
},
1064-
{
1065-
name: "False result with unfound key",
1066-
obj: &corev1.Service{
1067-
TypeMeta: metav1.TypeMeta{Kind: "Service", APIVersion: "v1"},
1068-
ObjectMeta: metav1.ObjectMeta{Name: "my-service", Namespace: "my-namespace"},
1069-
},
1070-
probe: applier.FieldValueProbe{
1071-
FieldPath: "spec.foo",
1072-
Value: "my-service",
1073-
},
1074-
expectedResult: probing.Result{
1075-
Status: probing.StatusFalse,
1076-
Messages: []string{
1077-
`missing key: "spec.foo"`,
1078-
},
1079-
},
1080-
},
1081-
{
1082-
name: "False result with found key and unequal value",
1083-
obj: &corev1.Service{
1084-
TypeMeta: metav1.TypeMeta{Kind: "Service", APIVersion: "v1"},
1085-
ObjectMeta: metav1.ObjectMeta{Name: "my-service", Namespace: "my-namespace"},
1086-
},
1087-
probe: applier.FieldValueProbe{
1088-
FieldPath: "metadata.namespace",
1089-
Value: "bar",
1090-
},
1091-
expectedResult: probing.Result{
1092-
Status: probing.StatusFalse,
1093-
Messages: []string{
1094-
`value at key "metadata.namespace" != "bar"; expected: "bar" got: "my-namespace"`,
1095-
},
1096-
},
1097-
},
1098-
{
1099-
name: "Unknown result unstructured conversion failure",
1100-
obj: nil,
1101-
probe: applier.FieldValueProbe{
1102-
FieldPath: "metadata.name",
1103-
Value: "my-service",
1104-
},
1105-
expectedResult: probing.Result{
1106-
Status: probing.StatusUnknown,
1107-
Messages: []string{
1108-
"failed to convert to unstructured: object is nil",
1109-
},
1110-
},
1111-
},
1112-
} {
1113-
t.Run(tc.name, func(t *testing.T) {
1114-
assert.Equal(t, tc.expectedResult, tc.probe.Probe(tc.obj))
1115-
})
1116-
}
1117-
}

internal/operator-controller/controllers/clusterobjectset_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
"sigs.k8s.io/controller-runtime/pkg/source"
3939

4040
ocv1 "github.com/operator-framework/operator-controller/api/v1"
41-
"github.com/operator-framework/operator-controller/internal/operator-controller/applier"
4241
"github.com/operator-framework/operator-controller/internal/operator-controller/labels"
4342
)
4443

@@ -643,7 +642,7 @@ func buildProgressionProbes(progressionProbes []ocv1.ProgressionProbe) (probing.
643642
fieldsEqualProbe := probing.FieldsEqualProbe(probe.FieldsEqual)
644643
assertions = append(assertions, &fieldsEqualProbe)
645644
case ocv1.ProbeTypeFieldValue:
646-
fieldValueProbe := applier.FieldValueProbe(probe.FieldValue)
645+
fieldValueProbe := probing.FieldValueProbe(probe.FieldValue)
647646
assertions = append(assertions, &fieldValueProbe)
648647
default:
649648
return nil, fmt.Errorf("unknown progressionProbe assertion probe type: %s", probe.Type)

0 commit comments

Comments
 (0)