Skip to content

Commit fab9a64

Browse files
Add abillity to use server-side-apply feature (#118)
This allows overcome big configmaps limitations
1 parent 697873b commit fab9a64

4 files changed

Lines changed: 15 additions & 0 deletions

File tree

docs/resources/kubectl_manifest.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ YAML
4141
* `yaml_body` - Required. YAML to apply to kubernetes.
4242
* `sensitive_fields` - Optional. List of fields (dot-syntax) which are sensitive and should be obfuscated in output. Defaults to `["data"]` for Secrets.
4343
* `force_new` - Optional. Forces delete & create of resources if the `yaml_body` changes. Default `false`.
44+
* `server_side_apply` - Optional. Allow using server-side-apply method. Default `false`.
4445
* `ignore_fields` - Optional. List of map fields to ignore when applying the manifest. See below for more details.
4546
* `override_namespace` - Optional. Override the namespace to apply the kubernetes resource to, ignoring any declared namespace in the `yaml_body`.
4647
* `validate_schema` - Optional. Setting to `false` will mimic `kubectl apply --validate=false` mode. Default `true`.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ require (
2525
sigs.k8s.io/yaml v1.2.0
2626
)
2727

28+
replace github.com/tencentcloud/tencentcloud-sdk-go => github.com/tencentcloud/tencentcloud-sdk-go v1.0.175
2829
//replace github.com/Azure/go-autorest v10.15.4+incompatible => github.com/Azure/go-autorest v13.0.0+incompatible

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
662662
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
663663
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
664664
github.com/svanharmelen/jsonapi v0.0.0-20180618144545-0c0828c3f16d/go.mod h1:BSTlc8jOjh0niykqEGVXOLXdi9o0r0kR8tCYiMvjFgw=
665+
github.com/tencentcloud/tencentcloud-sdk-go v1.0.175/go.mod h1:asUz5BPXxgoPGaRgZaVm1iGcUAuHyYUo1nXqKa83cvI=
665666
github.com/tencentcloud/tencentcloud-sdk-go v3.0.82+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4=
666667
github.com/tencentyun/cos-go-sdk-v5 v0.0.0-20190808065407-f07404cefc8c/go.mod h1:wk2XFUg6egk4tSDNZtXeKfe2G6690UVyt163PuUxBZk=
667668
github.com/terraform-providers/terraform-provider-openstack v1.15.0/go.mod h1:2aQ6n/BtChAl1y2S60vebhyJyZXBsuAI5G4+lHrT1Ew=

kubernetes/resource_kubectl_manifest.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ metadata:
202202
_ = d.Set("namespace", metaObjLive.GetNamespace())
203203
_ = d.Set("name", metaObjLive.GetName())
204204
_ = d.Set("force_new", false)
205+
_ = d.Set("server_side_apply", false)
205206

206207
// clear out fields user can't set to try and get parity with yaml_body
207208
meta_v1_unstruct.RemoveNestedField(metaObjLive.Object, "metadata", "creationTimestamp")
@@ -409,6 +410,12 @@ metadata:
409410
Optional: true,
410411
Default: false,
411412
},
413+
"server_side_apply": {
414+
Type: schema.TypeBool,
415+
Description: "Default to client-side-apply. Setting to true will use server-side apply.",
416+
Optional: true,
417+
Default: false,
418+
},
412419
"ignore_fields": {
413420
Type: schema.TypeList,
414421
Elem: &schema.Schema{Type: schema.TypeString},
@@ -511,6 +518,11 @@ func resourceKubectlManifestApply(ctx context.Context, d *schema.ResourceData, m
511518
applyOptions.Validator = validation.NullSchema{}
512519
}
513520

521+
if d.Get("server_side_apply").(bool) {
522+
applyOptions.ServerSideApply = true
523+
applyOptions.FieldManager = "kubectl"
524+
}
525+
514526
if manifest.hasNamespace() {
515527
applyOptions.Namespace = manifest.unstruct.GetNamespace()
516528
}

0 commit comments

Comments
 (0)