Skip to content

Commit 7d88a43

Browse files
authored
feat:support ca addon (#2327)
* feat:support ca addon * feat:add base64 and json * modify logic for json and base64 compatible * update doc
1 parent 0be6cf0 commit 7d88a43

File tree

4 files changed

+79
-21
lines changed

4 files changed

+79
-21
lines changed

.changelog/2327.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_kubernetes_addon_attachment: Support `raw_values` and `raw_values_type`.
3+
```

tencentcloud/resource_tc_kubernetes_addon_attachment.go

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ package tencentcloud
130130

131131
import (
132132
"context"
133+
"encoding/base64"
133134
"fmt"
134135
"strings"
135136

@@ -169,6 +170,21 @@ func resourceTencentCloudTkeAddonAttachment() *schema.Resource {
169170
ConflictsWith: []string{"request_body"},
170171
Elem: &schema.Schema{Type: schema.TypeString},
171172
},
173+
"raw_values": {
174+
Type: schema.TypeString,
175+
Optional: true,
176+
Computed: true,
177+
Description: "Raw Values. Conflict with `request_body`. Required with `raw_values_type`.",
178+
ConflictsWith: []string{"request_body"},
179+
RequiredWith: []string{"raw_values_type"},
180+
},
181+
"raw_values_type": {
182+
Type: schema.TypeString,
183+
Optional: true,
184+
Computed: true,
185+
Description: "The type of raw Values. Required with `raw_values`.",
186+
RequiredWith: []string{"raw_values"},
187+
},
172188
"request_body": {
173189
Type: schema.TypeString,
174190
Optional: true,
@@ -204,11 +220,13 @@ func resourceTencentCloudTkeAddonAttachmentCreate(d *schema.ResourceData, meta i
204220
ctx := context.WithValue(context.TODO(), logIdKey, logId)
205221

206222
var (
207-
clusterId = d.Get("cluster_id").(string)
208-
addonName = d.Get("name").(string)
209-
version = d.Get("version").(string)
210-
values = d.Get("values").([]interface{})
211-
reqBody = d.Get("request_body").(string)
223+
clusterId = d.Get("cluster_id").(string)
224+
addonName = d.Get("name").(string)
225+
version = d.Get("version").(string)
226+
values = d.Get("values").([]interface{})
227+
rawValues *string
228+
rawValuesType *string
229+
reqBody = d.Get("request_body").(string)
212230
)
213231

214232
if version == "" {
@@ -227,9 +245,16 @@ func resourceTencentCloudTkeAddonAttachmentCreate(d *schema.ResourceData, meta i
227245
}
228246

229247
if reqBody == "" {
248+
if v, ok := d.GetOk("raw_values"); ok {
249+
rawValues = helper.String(v.(string))
250+
}
251+
if v, ok := d.GetOk("raw_values_type"); ok {
252+
rawValuesType = helper.String(v.(string))
253+
}
254+
230255
var reqErr error
231256
v := helper.InterfacesStringsPoint(values)
232-
reqBody, reqErr = service.GetAddonReqBody(addonName, version, v)
257+
reqBody, reqErr = service.GetAddonReqBody(addonName, version, v, rawValues, rawValuesType)
233258
if reqErr != nil {
234259
return reqErr
235260
}
@@ -317,6 +342,17 @@ func resourceTencentCloudTkeAddonAttachmentRead(d *schema.ResourceData, meta int
317342
filteredValues := getFilteredValues(d, spec.Values.Values)
318343
_ = d.Set("values", filteredValues)
319344
}
345+
346+
if spec.Values != nil && spec.Values.RawValues != nil {
347+
rawValues := spec.Values.RawValues
348+
rawValuesType := spec.Values.RawValuesType
349+
350+
base64DecodeValues, _ := base64.StdEncoding.DecodeString(*rawValues)
351+
jsonValues := string(base64DecodeValues)
352+
353+
_ = d.Set("raw_values", jsonValues)
354+
_ = d.Set("raw_values_type", rawValuesType)
355+
}
320356
}
321357

322358
if statuses != nil || len(statuses) == 0 {
@@ -339,18 +375,26 @@ func resourceTencentCloudTkeAddonAttachmentUpdate(d *schema.ResourceData, meta i
339375
service := TkeService{client: meta.(*TencentCloudClient).apiV3Conn}
340376

341377
var (
342-
id = d.Id()
343-
split = strings.Split(id, FILED_SP)
344-
clusterId = split[0]
345-
addonName = split[1]
346-
version = d.Get("version").(string)
347-
values = d.Get("values").([]interface{})
348-
reqBody = d.Get("request_body").(string)
349-
err error
378+
id = d.Id()
379+
split = strings.Split(id, FILED_SP)
380+
clusterId = split[0]
381+
addonName = split[1]
382+
version = d.Get("version").(string)
383+
values = d.Get("values").([]interface{})
384+
reqBody = d.Get("request_body").(string)
385+
err error
386+
rawValues *string
387+
rawValuesType *string
350388
)
351389

352-
if d.HasChange("request_body") && reqBody == "" || d.HasChange("version") || d.HasChange("values") {
353-
reqBody, err = service.GetAddonReqBody(addonName, version, helper.InterfacesStringsPoint(values))
390+
if d.HasChange("request_body") && reqBody == "" || d.HasChange("version") || d.HasChange("values") || d.HasChange("raw_values") || d.HasChange("raw_values_type") {
391+
if v, ok := d.GetOk("raw_values"); ok {
392+
rawValues = helper.String(v.(string))
393+
}
394+
if v, ok := d.GetOk("raw_values_type"); ok {
395+
rawValuesType = helper.String(v.(string))
396+
}
397+
reqBody, err = service.GetAddonReqBody(addonName, version, helper.InterfacesStringsPoint(values), rawValues, rawValuesType)
354398
}
355399

356400
if err != nil {

tencentcloud/service_tencentcloud_tke_addons.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tencentcloud
22

33
import (
44
"context"
5+
"encoding/base64"
56
"encoding/json"
67
"fmt"
78
"log"
@@ -19,6 +20,7 @@ type AddonSpecChart struct {
1920

2021
type AddonSpecValues struct {
2122
RawValuesType *string `json:"rawValuesType,omitempty"`
23+
RawValues *string `json:"rawValues,omitempty"`
2224
Values []*string `json:"values,omitempty"`
2325
}
2426

@@ -154,7 +156,7 @@ func (me *TkeService) DescribeExtensionAddon(ctx context.Context, clusterName, a
154156
return
155157
}
156158

157-
func (me *TkeService) GetAddonReqBody(addon, version string, values []*string) (string, error) {
159+
func (me *TkeService) GetAddonReqBody(addon, version string, values []*string, rawValues, rawValuesType *string) (string, error) {
158160
var reqBody = &AddonRequestBody{}
159161
//reqBody.Kind = helper.String("App") // Optional
160162
//reqBody.ApiVersion = helper.String("application.tkestack.io/v1") // Optional
@@ -165,13 +167,20 @@ func (me *TkeService) GetAddonReqBody(addon, version string, values []*string) (
165167
},
166168
}
167169

170+
addonValues := &AddonSpecValues{}
168171
if len(values) > 0 {
169-
reqBody.Spec.Values = &AddonSpecValues{
170-
RawValuesType: helper.String("yaml"),
171-
Values: values,
172-
}
172+
addonValues.RawValuesType = helper.String("yaml")
173+
addonValues.Values = values
174+
}
175+
176+
if rawValuesType != nil && rawValues != nil {
177+
base64EncodeValues := base64.StdEncoding.EncodeToString([]byte(*rawValues))
178+
addonValues.RawValuesType = rawValuesType
179+
addonValues.RawValues = &base64EncodeValues
173180
}
174181

182+
reqBody.Spec.Values = addonValues
183+
175184
result, err := json.Marshal(reqBody)
176185
if err != nil {
177186
return "", err

website/docs/r/kubernetes_addon_attachment.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ The following arguments are supported:
134134

135135
* `cluster_id` - (Required, String, ForceNew) ID of cluster.
136136
* `name` - (Required, String, ForceNew) Name of addon.
137+
* `raw_values_type` - (Optional, String) The type of raw Values. Required with `raw_values`.
138+
* `raw_values` - (Optional, String) Raw Values. Conflict with `request_body`. Required with `raw_values_type`.
137139
* `request_body` - (Optional, String) Serialized json string as request body of addon spec. If set, will ignore `version` and `values`.
138140
* `values` - (Optional, List: [`String`]) Values the addon passthroughs. Conflict with `request_body`.
139141
* `version` - (Optional, String) Addon version, default latest version. Conflict with `request_body`.

0 commit comments

Comments
 (0)