teslur commented on issue #35171: URL: https://github.com/apache/airflow/issues/35171#issuecomment-1792846247
Hello there! I deeply appreciate your insightful feedback. > Your fix appends this list and there might be a situation, when it contains 2 dicts with key-value pair (key and ssh-keys pair), so is it acceptable for gce? It seems you're considering a situation where a `"ssh-keys"` metadata may already exist in the GCE instance as illustrated below: ```python metadata = instance_info["metadata"] #=> { "items": [{ "key": "ssh-keys", "value": "some-ssh-key" }] } ``` From my understanding, it appears that duplicates of `"ssh-keys"` within `"items"`, as you've pointed out, would not occur. This situation is managed by the existing `for ~ if` block, not the part of the code I have altered. Per [the Python language specification, the `else` block isn't executed if the `break` statement is run](https://docs.python.org/3/reference/compound_stmts.html#the-for-statement). If there are any inaccuracies in my understanding, I would greatly appreciate your guidance. ```python keys = self.user + ":" + pubkey + "\n" metadata = instance_info["metadata"] items = metadata.get("items", []) for item in items: if item.get("key") == "ssh-keys": #=> In this case the metadata is processed here. keys += item["value"] item["value"] = keys break #=> This break prevents the else block from being processed. else: new_dict = {"key": "ssh-keys", "value": keys} metadata["items"] = [*items, new_dict] #=> I made changes to this line. ``` The intended outcome for the metadata structure should be: ```python metadata #=> { "items": [{ "key": "ssh-keys", "value": "new-key\nsome-ssh-key" }] } ``` This is in line with the [`setMetadata` API requirements of GCE](https://cloud.google.com/compute/docs/connect/add-ssh-keys#after-vm-creation). The modifications I made would only be implemented if a dict with the key "ssh-keys" is not present in the original metadata. Importantly, my changes are not expected to result in the metadata having multiple dicts with the same key "ssh-keys" coexist in `"items"`. Best regards. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org