Skip to content

Commit 4494c45

Browse files
authored
fix: tke_addon - npe error (#762)
1 parent 1530a65 commit 4494c45

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

tencentcloud/resource_tc_kubernetes_addon_attachment.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ resource "tencentcloud_kubernetes_addon_attachment" "addon_tcr" {
2020
version = "1.0.0"
2121
values = [
2222
# imagePullSecretsCrs is an array which can configure image pull
23-
"global.imagePullSecretsCrs[0].name=sample-vpc",
23+
"global.imagePullSecretsCrs[0].name=unique-sample-vpc",
2424
"global.imagePullSecretsCrs[0].namespaces=tcr-assistant-system",
2525
"global.imagePullSecretsCrs[0].serviceAccounts=*",
2626
"global.imagePullSecretsCrs[0].type=docker",
@@ -173,7 +173,7 @@ func resourceTencentCloudTkeAddonAttachmentCreate(d *schema.ResourceData, meta i
173173
phase, has, err := service.PollingAddonsPhase(ctx, clusterId, addonName, resData)
174174

175175
if resData.Status != nil && resData.Status["reason"] != nil {
176-
reason = *resData.Status["reason"]
176+
reason = resData.Status["reason"].(string)
177177
}
178178

179179
if !has {
@@ -202,6 +202,9 @@ func resourceTencentCloudTkeAddonAttachmentRead(d *schema.ResourceData, meta int
202202
id := d.Id()
203203
has := false
204204
split := strings.Split(id, FILED_SP)
205+
if len(split) < 2 {
206+
return fmt.Errorf("id expected format: cluster_id#addon_name but no addon_name provided")
207+
}
205208
clusterId := split[0]
206209
addonName := split[1]
207210

@@ -321,7 +324,7 @@ func getFilteredValues(d *schema.ResourceData, values []*string) []string {
321324
kv := strings.Split(*value, "=")
322325
key := kv[0]
323326

324-
if IsContains(TKE_ADDON_DEFAULT_VALUES_KEY, key) || !IsContains(rawValues, *value) {
327+
if IsContains(TKE_ADDON_DEFAULT_VALUES_KEY, key) || IsContains(rawValues, *value) {
325328
continue
326329
}
327330
rawValues = append(rawValues, *value)

tencentcloud/service_tencentcloud_tke_addons.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ type AddonResponseMeta struct {
4545
}
4646

4747
type AddonResponseData struct {
48-
Kind *string `json:"kind,omitempty"`
49-
ApiVersion *string `json:"apiVersion,omitempty"`
50-
Metadata *AddonResponseMeta `json:"metadata,omitempty"`
51-
Spec *AddonSpec `json:"spec,omitempty"`
52-
Status map[string]*string `json:"status,omitempty"`
48+
Kind *string `json:"kind,omitempty"`
49+
ApiVersion *string `json:"apiVersion,omitempty"`
50+
Metadata *AddonResponseMeta `json:"metadata,omitempty"`
51+
Spec *AddonSpec `json:"spec,omitempty"`
52+
Status map[string]interface{} `json:"status,omitempty"`
5353
}
5454

5555
func (me *TkeService) GetTkeAppChartList(ctx context.Context, request *tke.GetTkeAppChartListRequest) (info []*tke.AppChart, errRet error) {
@@ -79,10 +79,10 @@ func (me *TkeService) GetTkeAppChartList(ctx context.Context, request *tke.GetTk
7979

8080
func (me *TkeService) PollingAddonsPhase(ctx context.Context, clusterId, addonName string, addonResponseData *AddonResponseData) (string, bool, error) {
8181
var (
82-
err error
83-
phase string
82+
err error
83+
phase string
8484
response string
85-
has bool
85+
has bool
8686
)
8787

8888
if addonResponseData == nil {
@@ -104,13 +104,13 @@ func (me *TkeService) PollingAddonsPhase(ctx context.Context, clusterId, addonNa
104104

105105
reason := addonResponseData.Status["reason"]
106106
if addonResponseData.Status["phase"] != nil {
107-
phase = *addonResponseData.Status["phase"]
107+
phase = addonResponseData.Status["phase"].(string)
108108
}
109109
if reason == nil {
110110
reason = helper.String("unknown error")
111111
}
112112

113-
if phase == "Upgrading" || phase == "Installing" || phase == "ChartFetched" || phase == "RollingBack" || phase == "Terminating"{
113+
if phase == "Upgrading" || phase == "Installing" || phase == "ChartFetched" || phase == "RollingBack" || phase == "Terminating" {
114114
return resource.RetryableError(fmt.Errorf("addon %s is %s, retrying", addonName, phase))
115115
}
116116

website/docs/r/kubernetes_addon_attachment.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ resource "tencentcloud_kubernetes_addon_attachment" "addon_tcr" {
2929
version = "1.0.0"
3030
values = [
3131
# imagePullSecretsCrs is an array which can configure image pull
32-
"global.imagePullSecretsCrs[0].name=sample-vpc",
32+
"global.imagePullSecretsCrs[0].name=unique-sample-vpc",
3333
"global.imagePullSecretsCrs[0].namespaces=tcr-assistant-system",
3434
"global.imagePullSecretsCrs[0].serviceAccounts=*",
3535
"global.imagePullSecretsCrs[0].type=docker",

0 commit comments

Comments
 (0)