Skip to content

Commit 472a099

Browse files
authored
Fix deprecated functions (#329)
Fixup a couple more function deprecations. * Add a test for rest client package. Signed-off-by: SuperQ <superq@gmail.com>
1 parent 92fb743 commit 472a099

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

pkg/external/iam/aliyun.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ func (c *CredentialProvider) Retrieve() (minioCred.Value, error) {
7474
// according to the caller minioCred.Credentials.IsExpired(),
7575
// it already has a lock, so we don't need to worry about concurrency
7676
func (c CredentialProvider) IsExpired() bool {
77-
ak, err := c.aliyunCreds.GetAccessKeyId()
77+
cred, err := c.aliyunCreds.GetCredential()
7878
if err != nil {
7979
log.Println("failed to get access key id from aliyun credential, assume it's expired")
8080
return true
8181
}
82-
return *ak != c.akCache
82+
return *cred.AccessKeyId != c.akCache
8383
}
8484

8585
// RetrieveWithCredContext implements "github.com/minio/minio-go/v7/pkg/credentials".Provider.RetrieveWithCredContext()

pkg/util/rest/rest_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (clis RestClientImpl) Exec(ctx context.Context, namespace, pod, container s
8686
}
8787

8888
var stdoutBuf, stderrBuf bytes.Buffer
89-
err = exec.Stream(remotecommand.StreamOptions{
89+
err = exec.StreamWithContext(ctx, remotecommand.StreamOptions{
9090
Stdout: &stdoutBuf,
9191
Stderr: &stderrBuf,
9292
})

pkg/util/rest/rest_client_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package rest
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
ctrl "sigs.k8s.io/controller-runtime"
9+
)
10+
11+
func TestNewRestClientImpl(t *testing.T) {
12+
config := ctrl.GetConfigOrDie()
13+
restClient, err := newRestClientImpl(config)
14+
assert.NoError(t, err)
15+
assert.NotNil(t, restClient)
16+
17+
_, _, err = restClient.Exec(context.TODO(), "test", "test", "test", []string{"/bin/true"})
18+
// We don't expect this to work in tests.
19+
assert.Error(t, err)
20+
}

0 commit comments

Comments
 (0)