Open foriequal0 opened 3 years ago
Is there any update on that? I have following issue when using python:
This is simplified version of my code:
eks.KubernetesPatch(
scope=self,
id="some-id",
resource_name="some-name",
cluster=self.cluster,
patch_type=eks.PatchType.JSON,
apply_patch=[{"op": "replace", "path": "/webhooks/0/rules/0/operations/0", "value": "DELETE"}],
)
And this is the result in cdk.out json:
"ApplyPatchJson": "{\"0\":{\"op\":\"replace\",\"path\":\"/webhooks/0/rules/0/operations/0\",\"value\":\"DELETE\"}}",
Which is not good. From CloudWatch logs:
kubectl([ 'patch', resource_name, '-n', resource_namespace, '-p', patch_json, '--type', patch_type ])
Where patch_json
is the one mentioned above which results in:
Error from server (BadRequest): json: cannot unmarshal object into Go value of type jsonpatch.Patch
Using:
aws-cdk.aws-eks==1.103.0
$ cdk --version
1.105.0 (build 4813992)
Any updates on that?
I could not get the above JSON format to work in the Python CDK.
A workaround is to remove the {"op": ..., "path": ..., "value": ...}
format, and patch your resource using the manifest format. For example:
Convert this:
patch = { "op" : "add", "path" : "/spec/tls/0/hosts/-", "value" : '"myhost.com"'}
to this:
patch = {"spec": {"tls": [{"hosts": ['myhost.com']}]
And then apply:
eks.KubernetesPatch(self, "IngressPatch",
cluster=eks_cluster,
resource_name="ingress/my-ingress",
resource_namespace='ingress',
apply_patch=patch,
restore_patch={}
)
You may need to play around with PatchType and contents of your patch to get this right, but was a quick workaround to implement patches into my Stack in the meantime. Official support for other patch formats within Python CDK would be appreciated.
Json Patch standard denotes that https://tools.ietf.org/html/rfc6902#section-3
However
KubernetesPatch.applyPatch
type is{ [key: string]; any }
. https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-eks/lib/k8s-patch.ts#L20-L28It is not wrong, but somewhat confusing.
Reproduction Steps
What did you expect to happen?
it should be
{ [key: string]; any} | {op: "add"|"remove"|"replace"|"move"|"copy"|"test", path: string, value: any}[]
What actually happened?
Environment
Other
This is :bug: Bug Report