Skip to content

Commit

Permalink
Custom kubelet port (#154)
Browse files Browse the repository at this point in the history
* Added KubeConfig.kubelet_node_port

* Patched chart

* Fixed linting issues

* Addressed an issue in the chart
  • Loading branch information
dalazx authored Mar 5, 2020
1 parent effe3f5 commit ba1ae7f
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ spec:
value: {{ .Values.NP_MONITORING_REGISTRY_URL }}
- name: NP_CLUSTER_NAME
value: {{ .Values.NP_CLUSTER_NAME }}
- name: NP_MONITORING_K8S_KUBELET_PORT
value: {{ .Values.NP_MONITORING_K8S_KUBELET_PORT | quote }}
{{- if .Values.DOCKER_LOGIN_ARTIFACTORY_SECRET_NAME }}
imagePullSecrets:
- name: {{ .Values.DOCKER_LOGIN_ARTIFACTORY_SECRET_NAME }}
Expand Down
1 change: 1 addition & 0 deletions deploy/platformmonitoringapi/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ NP_MONITORING_ES_HOSTS: http://logging-elasticsearch:9200
NP_MONITORING_K8S_NS: default
NP_MONITORING_REGISTRY_URL: https://registry-dev.neu.ro
NP_CLUSTER_NAME: "default"
NP_MONITORING_K8S_KUBELET_PORT: ""
1 change: 1 addition & 0 deletions deploy/platformmonitoringapi/values-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ NP_MONITORING_ES_HOSTS: http://logging-elasticsearch:9200
NP_MONITORING_K8S_NS: default
NP_MONITORING_REGISTRY_URL: https://registry-staging.neu.ro
NP_CLUSTER_NAME: ""
NP_MONITORING_K8S_KUBELET_PORT: ""
1 change: 1 addition & 0 deletions deploy/platformmonitoringapi/values-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ NP_MONITORING_K8S_NS: default
NP_MONITORING_REGISTRY_URL: https://
DOCKER_LOGIN_ARTIFACTORY_SECRET_NAME: "artifactory-regcred"
NP_CLUSTER_NAME: ""
NP_MONITORING_K8S_KUBELET_PORT: ""
1 change: 1 addition & 0 deletions platform_monitoring/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ async def create_kube_client(config: KubeConfig) -> AsyncIterator[KubeClient]:
conn_timeout_s=config.client_conn_timeout_s,
read_timeout_s=config.client_read_timeout_s,
conn_pool_size=config.client_conn_pool_size,
kubelet_node_port=config.kubelet_node_port,
)
try:
await client.init()
Expand Down
2 changes: 2 additions & 0 deletions platform_monitoring/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class KubeConfig:
client_read_timeout_s: int = 300
client_conn_pool_size: int = 100

kubelet_node_port: int = 10255


@dataclass(frozen=True)
class RegistryConfig:
Expand Down
4 changes: 4 additions & 0 deletions platform_monitoring/config_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def _create_kube(self) -> KubeConfig:
self._environ.get("NP_MONITORING_K8S_CLIENT_CONN_POOL_SIZE")
or KubeConfig.client_conn_pool_size
),
kubelet_node_port=int(
self._environ.get("NP_MONITORING_K8S_KUBELET_PORT")
or KubeConfig.kubelet_node_port
),
)

def _create_registry(self) -> RegistryConfig:
Expand Down
8 changes: 3 additions & 5 deletions platform_monitoring/kube_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
from yarl import URL

from .base import JobStats, Telemetry
from .config import KubeClientAuthType
from .config import KubeClientAuthType, KubeConfig


logger = logging.getLogger(__name__)


KUBELET_NODE_PORT = 10255


class KubeClientException(Exception):
pass

Expand Down Expand Up @@ -91,6 +88,7 @@ def __init__(
conn_timeout_s: int = 300,
read_timeout_s: int = 100,
conn_pool_size: int = 100,
kubelet_node_port: int = KubeConfig.kubelet_node_port,
) -> None:
self._base_url = base_url
self._namespace = namespace
Expand All @@ -109,7 +107,7 @@ def __init__(
self._conn_pool_size = conn_pool_size
self._client: Optional[aiohttp.ClientSession] = None

self._kubelet_port = KUBELET_NODE_PORT
self._kubelet_port = kubelet_node_port

@property
def _is_ssl(self) -> bool:
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/test_kube.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from platform_monitoring.base import LogReader
from platform_monitoring.config import KubeConfig
from platform_monitoring.kube_client import (
KUBELET_NODE_PORT,
JobNotFoundException,
KubeClient,
KubeClientException,
Expand Down Expand Up @@ -235,11 +234,11 @@ async def test_get_node_proxy_client(
node_list = await kube_client.get_node_list()
node_name = node_list["items"][0]["metadata"]["name"]
async with kube_client.get_node_proxy_client(
node_name, KUBELET_NODE_PORT
node_name, KubeConfig.kubelet_node_port
) as client:
assert client.url == URL(
kube_config.endpoint_url
+ f"/api/v1/nodes/{node_name}:{KUBELET_NODE_PORT}/proxy"
+ f"/api/v1/nodes/{node_name}:{KubeConfig.kubelet_node_port}/proxy"
)

async with client.session.get(URL(f"{client.url}/stats/summary")) as resp:
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def test_create(cert_authority_path: str, token_path: str) -> None:
"NP_MONITORING_K8S_CLIENT_CONN_POOL_SIZE": "333",
"NP_MONITORING_REGISTRY_URL": "http://testhost:5000",
"NP_CLUSTER_NAME": "default",
"NP_MONITORING_K8S_KUBELET_PORT": "12321",
}
config = EnvironConfigFactory(environ).create()
assert config == Config(
Expand All @@ -80,6 +81,7 @@ def test_create(cert_authority_path: str, token_path: str) -> None:
client_conn_timeout_s=111,
client_read_timeout_s=222,
client_conn_pool_size=333,
kubelet_node_port=12321,
),
registry=RegistryConfig(url=URL("http://testhost:5000")),
docker=DockerConfig(),
Expand Down

0 comments on commit ba1ae7f

Please sign in to comment.