Skip to content
Merged
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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.23.0-dev
v0.23.1
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/google/uuid v1.6.0
github.com/onsi/ginkgo/v2 v2.25.3
github.com/onsi/gomega v1.38.2
github.com/openmcp-project/controller-utils/api v0.23.0
github.com/openmcp-project/controller-utils/api v0.23.1
github.com/spf13/pflag v1.0.10
github.com/stretchr/testify v1.11.1
go.uber.org/zap v1.27.0
Expand Down
64 changes: 62 additions & 2 deletions pkg/controller/status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,71 @@ func GenerateCreateConditionFunc[Obj client.Object](rr *ReconcileResult[Obj]) fu
}
return func(conType string, status metav1.ConditionStatus, reason, message string) {
rr.Conditions = append(rr.Conditions, metav1.Condition{
Type: conType,
Type: ReplaceIllegalCharsInConditionType(conType),
Status: status,
ObservedGeneration: gen,
Reason: reason,
Reason: ReplaceIllegalCharsInConditionReason(reason),
Message: message,
})
}
}

// ReplaceIllegalCharsInConditionType replaces all characters in the given string that are not allowed in condition types with underscores.
func ReplaceIllegalCharsInConditionType(s string) string {
if s == "" {
return s
}

result := make([]rune, 0, len(s))
for _, r := range s {
// Valid characters for condition types are:
// - lowercase letters (a-z)
// - uppercase letters (A-Z)
// - digits (0-9)
// - underscore (_)
// - hyphen (-)
// - dot (.)
// All other characters are replaced with underscore
if (r >= 'a' && r <= 'z') ||
(r >= 'A' && r <= 'Z') ||
(r >= '0' && r <= '9') ||
r == '_' ||
r == '-' ||
r == '.' {
result = append(result, r)
} else {
result = append(result, '_')
}
}
return string(result)
}

// ReplaceIllegalCharsInConditionReason replaces all characters in the given string that are not allowed in condition reasons with underscores.
func ReplaceIllegalCharsInConditionReason(s string) string {
if s == "" {
return s
}

result := make([]rune, 0, len(s))
for _, r := range s {
// Valid characters for condition types are:
// - lowercase letters (a-z)
// - uppercase letters (A-Z)
// - digits (0-9)
// - underscore (_)
// - colon (:)
//- comma (,)
// All other characters are replaced with underscore
if (r >= 'a' && r <= 'z') ||
(r >= 'A' && r <= 'Z') ||
(r >= '0' && r <= '9') ||
r == '_' ||
r == ':' ||
r == ',' {
result = append(result, r)
} else {
result = append(result, '_')
}
}
return string(result)
}
15 changes: 15 additions & 0 deletions pkg/controller/status_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ var _ = Describe("Status Updater", func() {
))
})

It("should replace illegal characters in condition type and reason", func() {
env := testutils.NewEnvironmentBuilder().WithFakeClient(coScheme).WithInitObjectPath("testdata", "test-02").WithDynamicObjectsWithStatus(&CustomObject{}).Build()
obj := &CustomObject{}
Expect(env.Client().Get(env.Ctx, controller.ObjectKey("status", "default"), obj)).To(Succeed())
rr := &controller.ReconcileResult[*CustomObject]{
Object: obj,
}
condFunc := controller.GenerateCreateConditionFunc(rr)

condFunc("CondType :,;-_.Test02@", metav1.ConditionTrue, "Reason -.,:_Test93$", "Message")
Expect(rr.Conditions).To(HaveLen(1))
Expect(rr.Conditions[0].Type).To(Equal("CondType____-_.Test02_"))
Expect(rr.Conditions[0].Reason).To(Equal("Reason___,:_Test93_"))
})

It("should not update disabled fields", func() {
env := testutils.NewEnvironmentBuilder().WithFakeClient(coScheme).WithInitObjectPath("testdata", "test-02").WithDynamicObjectsWithStatus(&CustomObject{}).Build()
obj := &CustomObject{}
Expand Down