-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
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
- Comment out
custom_request_headerssection from example - Apply plan
- Uncomment
custom_request_headerssection - Apply plan
Option 2
- Create it using YAML
- Empty the
headersarray in TF - Apply plan - it will execute
[{"path":"/spec/customRequestHeaders/headers","op":"remove"}] - Add the value back in
- Apply plan
Workaround
- Create
headerskey manually:
kubectl patch backendconfig www --type='json' -p='[{"path":"/spec/customRequestHeaders/headers","value":[],"op":"add"}]'- 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: 600Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels