Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ tests/temp
.cache/
.project
.wercker/
.venv/
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,18 @@ def _merge_kubeconfig_yaml(dst_yaml, src_yaml, merge_key):
# It is either an update or repeat of an existing record so we need to update the existing record with
# new one
match = True
# we preserve some fields from the config cause the user might have set them for better dex
# this is a simple approach, if the list grows too big, consider another;
# like whitelisting on our side and only copying those
preserved_fields = {
'contexts': ('context', ['namespace']),
'clusters': ('cluster', ['proxy-url'])
}.get(merge_key)
if preserved_fields:
section, fields = preserved_fields
for field in fields:
if field in j[section]:
i[section][field] = j[section][field]
dst_yaml[merge_key][idx] = i
if not match:
# It is a new record so we need to add it to the list
Expand Down
48 changes: 48 additions & 0 deletions services/container_engine/tests/unit/test_kubeconfig_merge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# coding: utf-8
# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.

import unittest

from services.container_engine.src.oci_cli_container_engine.containerengine_cli_extended import _merge_kubeconfig_yaml


class TestKubeconfigMerge(unittest.TestCase):
def test_preserves_namespace_when_updating_context(self):
destination = {
'contexts': [{
'name': 'cluster',
'context': {'cluster': 'cluster', 'user': 'user', 'namespace': 'workloads'}
}]
}
source = {
'contexts': [{
'name': 'cluster',
'context': {'cluster': 'cluster', 'user': 'updated-user'}
}]
}

_merge_kubeconfig_yaml(destination, source, 'contexts')

assert destination['contexts'][0]['context'] == {
'cluster': 'cluster', 'user': 'updated-user', 'namespace': 'workloads'
}

def test_preserves_proxy_url_when_updating_cluster(self):
destination = {
'clusters': [{
'name': 'cluster',
'cluster': {'server': 'https://old.example', 'proxy-url': 'http://proxy.example'}
}]
}
source = {
'clusters': [{
'name': 'cluster',
'cluster': {'server': 'https://new.example'}
}]
}

_merge_kubeconfig_yaml(destination, source, 'clusters')

assert destination['clusters'][0]['cluster'] == {
'server': 'https://new.example', 'proxy-url': 'http://proxy.example'
}