Skip to content

Commit 3ab494f

Browse files
stmcginnisankeesler
authored andcommitted
Switch from strings.Title to cases.Title (vmware-tanzu#2218)
`strings.Title` has been deprecated starting in go 1.18. We haven't moved to this version yet, but we will need to at some point in the near future. To avoid issues when that time comes, this updates the few instances we had of this to start using the recommended replacement of `cases.Title`. golang/go#48367 https://tip.golang.org/doc/go1.18#minor_library_changes Signed-off-by: Sean McGinnis <[email protected]>
1 parent 173e728 commit 3ab494f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

addons/controllers/packageinstallstatus_controller.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111

1212
"github.com/go-logr/logr"
1313
"github.com/pkg/errors"
14+
"golang.org/x/text/cases"
15+
"golang.org/x/text/language"
1416
apierrors "k8s.io/apimachinery/pkg/api/errors"
1517
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1618
"k8s.io/apimachinery/pkg/runtime"
@@ -294,8 +296,9 @@ func (r *PackageInstallStatusReconciler) reconcileClusterBootstrapStatus(
294296
}
295297

296298
// we populate 'Message' with Carvel's PackageInstall 'UsefulErrorMessage' field as it contains more detailed information in case of an error
299+
title := cases.Title(language.Und)
297300
condition := clusterapiv1beta1.Condition{
298-
Type: clusterapiv1beta1.ConditionType(strings.Title(pkgShortname)) + "-" +
301+
Type: clusterapiv1beta1.ConditionType(title.String(pkgShortname)) + "-" +
299302
clusterapiv1beta1.ConditionType(pkgiCondition.Type),
300303
Status: pkgiCondition.Status,
301304
Message: util.GetKappUsefulErrorMessage(pkgi.Status.UsefulErrorMessage),
@@ -309,7 +312,7 @@ func (r *PackageInstallStatusReconciler) reconcileClusterBootstrapStatus(
309312
// to only consider condition types' prefix (pkgi name) rather than the full condition type for condition's equality check and custom comparison logic is net implemented in CAPI's condition util Set() as of now
310313
var conditionExists bool
311314
for i, existingCond := range clusterBootstrap.Status.Conditions {
312-
if !strings.Contains(string(existingCond.Type), strings.Title(pkgShortname)) {
315+
if !strings.Contains(string(existingCond.Type), title.String(pkgShortname)) {
313316
continue
314317
}
315318
conditionExists = true
@@ -328,7 +331,7 @@ func (r *PackageInstallStatusReconciler) reconcileClusterBootstrapStatus(
328331
func (r *PackageInstallStatusReconciler) removeConditionIfExistsForPkgName(clusterBootstrap *runtanzuv1alpha3.ClusterBootstrap, pkgRefName string) {
329332
for i, existingCond := range clusterBootstrap.Status.Conditions {
330333
pkgShortname := strings.Split(pkgRefName, ".")[0]
331-
if strings.Contains(string(existingCond.Type), strings.Title(pkgShortname)) {
334+
if strings.Contains(string(existingCond.Type), cases.Title(language.Und).String(pkgShortname)) {
332335
clusterBootstrap.Status.Conditions = append(clusterBootstrap.Status.Conditions[:i], clusterBootstrap.Status.Conditions[i+1:]...)
333336
}
334337
}

0 commit comments

Comments
 (0)