Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plan fails when updating arrays #18

Open
silvpol opened this issue Oct 11, 2023 · 0 comments
Open

Plan fails when updating arrays #18

silvpol opened this issue Oct 11, 2023 · 0 comments
Assignees

Comments

@silvpol
Copy link

silvpol commented Oct 11, 2023

Issue

I have come across an issue when updating BackendConfig object in GCP. When trying to add values to an array-type field, the request fails with an odd error message about request being invalid.

Based on my investigation, when the array-type field is empty, it gets deleted during apply. If you then try to add a value to it, the json patch that plugin generates, fails due to array field missing. The plugin should check if array field is missing, create it and then execute the original patch.

Plugin just generates this op:

[{"path":"/spec/customRequestHeaders/headers/0","value":"X-Client-Region:{client_region_subdivision}","op":"add"}]

but when headers key is missing it should do this first to prevent failed request:

[{"path":"/spec/customRequestHeaders/headers","value":[],"op":"add"}]

Steps to replicate

Option 1

  1. Comment out custom_request_headers section from example
  2. Apply plan
  3. Uncomment custom_request_headers section
  4. Apply plan

Option 2

  1. Create it using YAML
  2. Empty the headers array in TF
  3. Apply plan - it will execute [{"path":"/spec/customRequestHeaders/headers","op":"remove"}]
  4. Add the value back in
  5. Apply plan

Workaround

  1. Create headers key manually:
kubectl patch backendconfig www --type='json' -p='[{"path":"/spec/customRequestHeaders/headers","value":[],"op":"add"}]'
  1. Apply the plan

Test setup

I have tested with versions 1.0.6 and 1.0.2.

Example BackendConfig

resource "k8s_cloud_google_com_v1_backend_config" "www" {

  metadata {
    name      = "www"
    namespace = "test"
  }

  spec {
    timeout_sec = 600

    connection_draining {
      draining_timeout_sec = 121
    }

    cdn {
      enabled = true

      cache_policy {
        include_host         = true
        include_protocol     = true
        include_query_string = true
      }
    }

    custom_request_headers {
      headers = ["X-Client-Region: {client_region_subdivision}"]
    }
  }
}

Corresponding YAML from API

apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
  name: www
  namespace: test
spec:
  cdn:
    cachePolicy:
      includeHost: true
      includeProtocol: true
      includeQueryString: true
    enabled: true
  connectionDraining:
    drainingTimeoutSec: 121
  customRequestHeaders:
    headers:
    - 'X-Client-Region: {client_region_subdivision}'
  timeoutSec: 600
@mingfang mingfang self-assigned this Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants