Skip to content

Commit

Permalink
Drop usage of deprecated functions (gardener#8026)
Browse files Browse the repository at this point in the history
* Remove usage of `string.Title`

* Use `executor.StreamWithContext` instead of `executor.Stream`
  • Loading branch information
acumino authored Jun 5, 2023
1 parent ae61df2 commit 8215a6c
Show file tree
Hide file tree
Showing 20 changed files with 13,429 additions and 8 deletions.
8 changes: 5 additions & 3 deletions extensions/pkg/controller/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ package controller_test
import (
"context"
"fmt"
"strings"

"github.com/go-logr/logr"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"golang.org/x/text/cases"
"golang.org/x/text/language"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
logzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
Expand All @@ -43,6 +44,7 @@ var _ = Describe("Status", func() {
generation int64 = 1337
lastOpType = gardencorev1beta1.LastOperationTypeCreate
lastOpDesc = "foo"
caser = cases.Title(language.English)

ctrl *gomock.Controller
log logr.Logger
Expand Down Expand Up @@ -115,7 +117,7 @@ var _ = Describe("Status", func() {
c.EXPECT().Status().Return(sw),
sw.EXPECT().Patch(ctx, gomock.AssignableToTypeOf(&extensionsv1alpha1.Infrastructure{}), gomock.Any()).Do(func(ctx context.Context, obj extensionsv1alpha1.Object, patch client.Patch, opts ...client.PatchOption) {
var (
description = strings.Title(lastOpDesc) + ": " + fakeErr.Error()
description = caser.String(lastOpDesc) + ": " + fakeErr.Error()

lastOperation = obj.GetExtensionStatus().GetLastOperation()
lastError = obj.GetExtensionStatus().GetLastError()
Expand Down Expand Up @@ -145,7 +147,7 @@ var _ = Describe("Status", func() {
c.EXPECT().Status().Return(sw),
sw.EXPECT().Patch(ctx, gomock.AssignableToTypeOf(&extensionsv1alpha1.Infrastructure{}), gomock.Any()).Do(func(ctx context.Context, obj extensionsv1alpha1.Object, patch client.Patch, opts ...client.PatchOption) {
var (
description = strings.Title(lastOpDesc) + ": " + err.Error()
description = caser.String(lastOpDesc) + ": " + err.Error()

lastOperation = obj.GetExtensionStatus().GetLastOperation()
lastError = obj.GetExtensionStatus().GetLastError()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (
go.uber.org/goleak v1.2.0
go.uber.org/zap v1.24.0
golang.org/x/crypto v0.6.0
golang.org/x/text v0.8.0
golang.org/x/time v0.3.0
golang.org/x/tools v0.7.0
gomodules.xyz/jsonpatch/v2 v2.2.0
Expand Down Expand Up @@ -163,7 +164,6 @@ require (
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221018160656-63c7b68cfc55 // indirect
google.golang.org/grpc v1.50.1 // indirect
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/kubernetes/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ func NewPodExecutor(config *rest.Config) PodExecutor {

// PodExecutor is the pod executor interface
type PodExecutor interface {
Execute(namespace, name, containerName, command, commandArg string) (io.Reader, error)
Execute(ctx context.Context, namespace, name, containerName, command, commandArg string) (io.Reader, error)
}

type podExecutor struct {
config *rest.Config
}

// Execute executes a command on a pod
func (p *podExecutor) Execute(namespace, name, containerName, command, commandArg string) (io.Reader, error) {
func (p *podExecutor) Execute(ctx context.Context, namespace, name, containerName, command, commandArg string) (io.Reader, error) {
client, err := corev1client.NewForConfig(p.config)
if err != nil {
return nil, err
Expand All @@ -75,7 +75,7 @@ func (p *podExecutor) Execute(namespace, name, containerName, command, commandAr
return nil, fmt.Errorf("failed to initialized the command exector: %w", err)
}

err = executor.Stream(remotecommand.StreamOptions{
err = executor.StreamWithContext(ctx, remotecommand.StreamOptions{
Stdin: strings.NewReader(commandArg),
Stdout: &stdout,
Stderr: &stderr,
Expand Down
4 changes: 3 additions & 1 deletion pkg/component/etcd/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"strings"
"text/template"

"golang.org/x/text/cases"
"golang.org/x/text/language"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
Expand Down Expand Up @@ -403,7 +405,7 @@ func (e *etcd) AlertingRules() (map[string]string, error) {

if err := monitoringAlertingRulesTemplate.Execute(&alertingRules, map[string]interface{}{
"role": e.values.Role,
"Role": strings.Title(e.values.Role),
"Role": cases.Title(language.English).String(e.values.Role),
"class": e.values.Class,
"classImportant": ClassImportant,
"backupEnabled": e.values.BackupConfig != nil,
Expand Down
1 change: 1 addition & 0 deletions test/e2e/gardener/shoot/internal/rotation/ssh_keypair.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (v *SSHKeypairVerifier) readAuthorizedKeysFile(ctx context.Context) (string
podExecutor := kubernetes.NewPodExecutor(v.ShootFramework.SeedClient.RESTConfig())

reader, err := podExecutor.Execute(
ctx,
v.Shoot.Status.TechnicalID,
podList.Items[0].Name,
"node",
Expand Down
162 changes: 162 additions & 0 deletions vendor/golang.org/x/text/cases/cases.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8215a6c

Please sign in to comment.