Skip to content

Commit

Permalink
switching from strings.Title to cases.Title
Browse files Browse the repository at this point in the history
  • Loading branch information
luthermonson committed Jun 27, 2022
1 parent 2948eb7 commit 500a50d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
go.opentelemetry.io/otel/trace v1.4.0
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871
golang.org/x/mod v0.5.1
golang.org/x/text v0.3.7
helm.sh/helm/v3 v3.8.1
k8s.io/api v0.23.5
k8s.io/apimachinery v0.23.5
Expand Down Expand Up @@ -180,7 +181,6 @@ require (
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
Expand Down
13 changes: 8 additions & 5 deletions pkg/record/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ limitations under the License.
package record

import (
"strings"
"sync"

"golang.org/x/text/cases"
"golang.org/x/text/language"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
Expand All @@ -28,10 +29,12 @@ import (
var (
initOnce sync.Once
defaultRecorder record.EventRecorder
eng cases.Caser
)

func init() {
defaultRecorder = new(record.FakeRecorder)
eng = cases.Title(language.English)
}

// InitFromRecorder initializes the global default recorder. It can only be called once.
Expand All @@ -44,20 +47,20 @@ func InitFromRecorder(recorder record.EventRecorder) {

// Event constructs an event from the given information and puts it in the queue for sending.
func Event(object runtime.Object, reason, message string) {
defaultRecorder.Event(object, corev1.EventTypeNormal, strings.Title(reason), message)
defaultRecorder.Event(object, corev1.EventTypeNormal, eng.String(reason), message)
}

// Eventf is just like Event, but with Sprintf for the message field.
func Eventf(object runtime.Object, reason, message string, args ...interface{}) {
defaultRecorder.Eventf(object, corev1.EventTypeNormal, strings.Title(reason), message, args...)
defaultRecorder.Eventf(object, corev1.EventTypeNormal, eng.String(reason), message, args...)
}

// Warn constructs a warning event from the given information and puts it in the queue for sending.
func Warn(object runtime.Object, reason, message string) {
defaultRecorder.Event(object, corev1.EventTypeWarning, strings.Title(reason), message)
defaultRecorder.Event(object, corev1.EventTypeWarning, eng.String(reason), message)
}

// Warnf is just like Warn, but with Sprintf for the message field.
func Warnf(object runtime.Object, reason, message string, args ...interface{}) {
defaultRecorder.Eventf(object, corev1.EventTypeWarning, strings.Title(reason), message, args...)
defaultRecorder.Eventf(object, corev1.EventTypeWarning, eng.String(reason), message, args...)
}

0 comments on commit 500a50d

Please sign in to comment.