Skip to content

Commit e4bac53

Browse files
committed
fix bug 8170 to support old env var
Signed-off-by: Maxim Rubchinsky <[email protected]>
1 parent bb8fe52 commit e4bac53

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

cluster-autoscaler/cloudprovider/alicloud/alibaba-cloud-sdk-go/sdk/auth/signers/signer_oidc.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,26 @@ package signers
1919
import (
2020
"encoding/json"
2121
"fmt"
22+
"net/http"
23+
"os"
24+
"runtime"
25+
"strconv"
26+
"strings"
27+
"time"
28+
2229
"github.com/jmespath/go-jmespath"
2330
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/alicloud/alibaba-cloud-sdk-go/sdk/auth/credentials"
2431
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/alicloud/alibaba-cloud-sdk-go/sdk/errors"
2532
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/alicloud/alibaba-cloud-sdk-go/sdk/requests"
2633
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/alicloud/alibaba-cloud-sdk-go/sdk/responses"
2734
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/alicloud/alibaba-cloud-sdk-go/sdk/utils"
2835
"k8s.io/klog/v2"
29-
"net/http"
30-
"os"
31-
"runtime"
32-
"strconv"
33-
"strings"
34-
"time"
3536
)
3637

3738
const (
3839
defaultOIDCDurationSeconds = 3600
40+
oidcTokenFilePath = "ALIBABA_CLOUD_OIDC_TOKEN_FILE"
41+
oldOidcTokenFilePath = "ALICLOUD_OIDC_TOKEN_FILE_PATH"
3942
)
4043

4144
// OIDCSigner is kind of signer
@@ -149,7 +152,7 @@ func (signer *OIDCSigner) getOIDCToken(OIDCTokenFilePath string) string {
149152
tokenPath := OIDCTokenFilePath
150153
_, err := os.Stat(tokenPath)
151154
if os.IsNotExist(err) {
152-
tokenPath = os.Getenv("ALIBABA_CLOUD_OIDC_TOKEN_FILE")
155+
tokenPath = utils.FirstNotEmpty(os.Getenv(oidcTokenFilePath), os.Getenv(oldOidcTokenFilePath))
153156
if tokenPath == "" {
154157
klog.Error("oidc token file path is missing")
155158
return ""

cluster-autoscaler/cloudprovider/alicloud/alibaba-cloud-sdk-go/sdk/utils/utils.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ import (
2222
"encoding/hex"
2323
"encoding/json"
2424
"fmt"
25-
"github.com/google/uuid"
2625
"net/url"
2726
"reflect"
2827
"strconv"
2928
"time"
29+
30+
"github.com/google/uuid"
3031
)
3132

3233
/* if you use go 1.10 or higher, you can hack this util by these to avoid "TimeZone.zip not found" on Windows */
@@ -127,3 +128,15 @@ func InitStructWithDefaultTag(bean interface{}) {
127128
}
128129
}
129130
}
131+
132+
// FirstNotEmpty returns the first non-empty string from the input list.
133+
// If all strings are empty or no arguments are provided, it returns an empty string.
134+
func FirstNotEmpty(strs ...string) string {
135+
for _, str := range strs {
136+
if str != "" {
137+
return str
138+
}
139+
}
140+
141+
return ""
142+
}

cluster-autoscaler/cloudprovider/alicloud/alicloud_cloud_config.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package alicloud
1919
import (
2020
"os"
2121

22+
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/alicloud/alibaba-cloud-sdk-go/sdk/utils"
2223
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/alicloud/metadata"
2324
"k8s.io/klog/v2"
2425
)
@@ -63,19 +64,19 @@ func (cc *cloudConfig) isValid() bool {
6364
}
6465

6566
if cc.OIDCProviderARN == "" {
66-
cc.OIDCProviderARN = firstNotEmpty(os.Getenv(oidcProviderARN), os.Getenv(oldOidcProviderARN))
67+
cc.OIDCProviderARN = utils.FirstNotEmpty(os.Getenv(oidcProviderARN), os.Getenv(oldOidcProviderARN))
6768
}
6869

6970
if cc.OIDCTokenFilePath == "" {
70-
cc.OIDCTokenFilePath = firstNotEmpty(os.Getenv(oidcTokenFilePath), os.Getenv(oldOidcTokenFilePath))
71+
cc.OIDCTokenFilePath = utils.FirstNotEmpty(os.Getenv(oidcTokenFilePath), os.Getenv(oldOidcTokenFilePath))
7172
}
7273

7374
if cc.RoleARN == "" {
74-
cc.RoleARN = firstNotEmpty(os.Getenv(roleARN), os.Getenv(oldRoleARN))
75+
cc.RoleARN = utils.FirstNotEmpty(os.Getenv(roleARN), os.Getenv(oldRoleARN))
7576
}
7677

7778
if cc.RoleSessionName == "" {
78-
cc.RoleSessionName = firstNotEmpty(os.Getenv(roleSessionName), os.Getenv(oldRoleSessionName))
79+
cc.RoleSessionName = utils.FirstNotEmpty(os.Getenv(roleSessionName), os.Getenv(oldRoleSessionName))
7980
}
8081

8182
if cc.RegionId != "" && cc.AccessKeyID != "" && cc.AccessKeySecret != "" {
@@ -133,15 +134,3 @@ func (cc *cloudConfig) getRegion() string {
133134
}
134135
return r
135136
}
136-
137-
// firstNotEmpty returns the first non-empty string from the input list.
138-
// If all strings are empty or no arguments are provided, it returns an empty string.
139-
func firstNotEmpty(strs ...string) string {
140-
for _, str := range strs {
141-
if str != "" {
142-
return str
143-
}
144-
}
145-
146-
return ""
147-
}

0 commit comments

Comments
 (0)