Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ func (p *Preflight) runPreflight(ctx context.Context, rel *release.Release) erro
resultErrs := crdWideErrors(results)
resultErrs = append(resultErrs, sameVersionErrors(results)...)
resultErrs = append(resultErrs, servedVersionErrors(results)...)

validateErrors = append(validateErrors, fmt.Errorf("validating upgrade for CRD %q: %w", newCrd.Name, errors.Join(resultErrs...)))
if len(resultErrs) > 0 {
validateErrors = append(validateErrors, fmt.Errorf("validating upgrade for CRD %q: %w", newCrd.Name, errors.Join(resultErrs...)))
}
}
}

Expand Down Expand Up @@ -171,7 +172,11 @@ func sameVersionErrors(results *runner.Results) []error {
for property, comparisonResults := range propertyResults {
for _, result := range comparisonResults {
for _, err := range result.Errors {
errs = append(errs, fmt.Errorf("%s: %s: %s: %s", version, property, result.Name, err))
msg := err
if result.Name == "unhandled" {
msg = "unhandled changes found"
}
errs = append(errs, fmt.Errorf("%s: %s: %s: %s", version, property, result.Name, msg))
}
}
}
Expand All @@ -190,7 +195,11 @@ func servedVersionErrors(results *runner.Results) []error {
for property, comparisonResults := range propertyResults {
for _, result := range comparisonResults {
for _, err := range result.Errors {
errs = append(errs, fmt.Errorf("%s: %s: %s: %s", version, property, result.Name, err))
msg := err
if result.Name == "unhandled" {
msg = "unhandled changes found"
}
errs = append(errs, fmt.Errorf("%s: %s: %s: %s", version, property, result.Name, msg))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
crdifyconfig "sigs.k8s.io/crdify/pkg/config"

"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/preflights/crdupgradesafety"
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util"
Expand Down Expand Up @@ -379,3 +380,36 @@ func TestUpgrade(t *testing.T) {
})
}
}

func TestUpgrade_UnhandledChanges_InSpec_DefaultPolicy(t *testing.T) {
t.Run("unhandled spec changes cause error by default", func(t *testing.T) {
preflight := newMockPreflight(getCrdFromManifestFile(t, "crd-unhandled-old.json"), nil)
rel := &release.Release{
Name: "test-release",
Manifest: getManifestString(t, "crd-unhandled-new.json"),
}
err := preflight.Upgrade(context.Background(), rel)
require.Error(t, err)
require.ErrorContains(t, err, "unhandled changes found")
require.NotContains(t, err.Error(), "v1.JSONSchemaProps", "error message should be concise without raw diff")
})
}

func TestUpgrade_UnhandledChanges_PolicyError(t *testing.T) {
t.Run("unhandled changes error when policy is Error", func(t *testing.T) {
oldCrd := getCrdFromManifestFile(t, "crd-unhandled-old.json")
preflight := crdupgradesafety.NewPreflight(&MockCRDGetter{oldCrd: oldCrd}, crdupgradesafety.WithConfig(&crdifyconfig.Config{
Conversion: crdifyconfig.ConversionPolicyIgnore,
UnhandledEnforcement: crdifyconfig.EnforcementPolicyError,
}))

rel := &release.Release{
Name: "test-release",
Manifest: getManifestString(t, "crd-unhandled-new.json"),
}

err := preflight.Upgrade(context.Background(), rel)
require.Error(t, err)
require.ErrorContains(t, err, "unhandled changes found")
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"apiVersion": "apiextensions.k8s.io/v1",
"kind": "CustomResourceDefinition",
"metadata": {
"name": "widgets.example.com"
},
"spec": {
"group": "example.com",
"versions": [
{
"name": "v1alpha1",
"served": true,
"storage": true,
"schema": {
"openAPIV3Schema": {
"type": "object",
"properties": {
"spec": {
"type": "object",
"properties": {
"field": {
"type": "string",
"format": "email"
}
}
}
}
}
}
}
],
"scope": "Namespaced",
"names": {
"plural": "widgets",
"singular": "widget",
"kind": "Widget"
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"apiVersion": "apiextensions.k8s.io/v1",
"kind": "CustomResourceDefinition",
"metadata": {
"name": "widgets.example.com"
},
"spec": {
"group": "example.com",
"versions": [
{
"name": "v1alpha1",
"served": true,
"storage": true,
"schema": {
"openAPIV3Schema": {
"type": "object",
"properties": {
"spec": {
"type": "object",
"properties": {
"field": {
"type": "string"
}
}
}
}
}
}
}
],
"scope": "Namespaced",
"names": {
"plural": "widgets",
"singular": "widget",
"kind": "Widget"
}
}
}

Loading