Skip to content

Commit cd69554

Browse files
authored
DTIN-6034: Stop calling deprecated K8S endpoint (#1338)
* DTIN-6034: Stop calling deprecated K8S endpoint * Removed no-longer-needed tests
1 parent 9f04df1 commit cd69554

File tree

5 files changed

+16
-332
lines changed

5 files changed

+16
-332
lines changed

.github/workflows/reusable-agent-build-container-images.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,6 @@ jobs:
261261
fail-fast: false
262262
matrix:
263263
k8s_version:
264-
# NOTE: We don't test under very old versions where CronJob was part of v2alpha1 since in
265-
# those versions CronJobs are not enabled by default and need to be installed extra
266-
- { "version": "v1.20.15", "driver": "", "runtime": "docker", "run_cronjob_checks": false }
267-
- { "version": "v1.21.10", "driver": "", "runtime": "docker", "run_cronjob_checks": true }
268-
- { "version": "v1.22.7", "driver": "", "runtime": "docker", "run_cronjob_checks": true }
269264
# NOTE: Using containerd runtime in minikube on GHA only works with docker driver
270265
- { "version": "v1.23.17", "driver": "docker", "runtime": "containerd", "run_cronjob_checks": true }
271266
- { "version": "v1.24.14", "driver": "docker", "runtime": "containerd", "run_cronjob_checks": true }

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
identification within third-party archives.
188188

189189
Copyright 2014-2021 Scalyr, Inc.
190-
Copyright 2021 SentinelOne, Inc.
190+
Copyright 2021-2025 SentinelOne, Inc.
191191

192192
Licensed under the Apache License, Version 2.0 (the "License");
193193
you may not use this file except in compliance with the License.

scalyr_agent/configuration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@ def k8s_controlled_warmer_blacklist_time(self):
11191119
def k8s_events_disable(self):
11201120
return self.__get_config().get_bool("k8s_events_disable")
11211121

1122+
# TODO This has been deprecated and is to be removed
11221123
@property
11231124
def k8s_fallback_urls_disable(self):
11241125
return self.__get_config().get_bool("k8s_fallback_urls_disable")
@@ -3107,6 +3108,7 @@ def __verify_main_config_and_apply_defaults(
31073108
env_aware=True,
31083109
)
31093110

3111+
# TODO This has been deprecated and is to be removed
31103112
self.__verify_or_set_optional_bool(
31113113
config,
31123114
"k8s_fallback_urls_disable",

scalyr_agent/monitor_utils/k8s.py

Lines changed: 13 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -44,43 +44,24 @@
4444
# A regex for splitting a container id and runtime
4545
_CID_RE = re.compile("^(.+)://(.+)$")
4646

47-
# endpoints used by the agent for querying the k8s api. Having this mapping allows
48-
# us to avoid special casing the logic for each different object type. We can just
49-
# look up the appropriate endpoint in this dict and query objects however we need.
47+
# Endpoints used for querying the Kubernetes api
5048
#
51-
# The dict is keyed by object kind, and or each object kind, there are 3 endpoints:
52-
# single, list and list all.
49+
# Keyed by object kind with the following endpoint specifiers:
50+
# - `single` is for querying a single object of a specific kind
51+
# - Requires substitutions for ${namespace} and ${name}
52+
# - `list` is for querying all objects of a given kind in a specific namespace
53+
# - Requires substitution for ${namespace}
54+
# - `list-all` is for querying all objects of a given kind in the entire cluster
5355
#
54-
# `single` is for querying a single object of a specific type
55-
# `list` is for querying all objects of a given type in a specific namespace
56-
# `list-all` is for querying all objects of a given type in the entire cluster
56+
# Each endpoint specifier may be a list and are attempted in order until successful.
57+
# The use case is to support changes, say promotions from /v1beta1 to /v1 and similar.
5758
#
58-
# the `single` and `list` endpoints are Templates that require the caller to substitute
59-
# in the appropriate values for ${namespace} and ${name}.
60-
#
61-
# For each key we also allow values to be a list. This way multiple URLs can be specific. We will
62-
# first try with the first URL with the list and then continue with the next one in case it returns
63-
# 404.
64-
# The use case here is to support URL paths which have changed, e.g. API endpoint which has been
65-
# promoted from /v1beta to /v1 and similar. Keep in mind that this is not a full blown robust
66-
# solution and not a replacement for proper API version management which is a larger and a longer
67-
# term project. It's a short term workaround / compromise to handle some of those scenarios where
68-
# an API endpoint has been promoted from beta to stable.
59+
# TODO Implement proper Kubernetes api version management
6960
_OBJECT_ENDPOINTS = {
7061
"CronJob": {
71-
"single": [
72-
Template("/apis/batch/v1beta1/namespaces/${namespace}/cronjobs/${name}"),
73-
# In Kubernetes v1.25.0 this API endpoint has been promoted from v1beta to v1
74-
Template("/apis/batch/v1/namespaces/${namespace}/cronjobs/${name}"),
75-
],
76-
"list": [
77-
Template("/apis/batch/v1beta1/namespaces/${namespace}/cronjobs"),
78-
Template("/apis/batch/v1/namespaces/${namespace}/cronjobs"),
79-
],
80-
"list-all": [
81-
"/apis/batch/v1beta1/cronjobs",
82-
"/apis/batch/v1/cronjobs",
83-
],
62+
"single": Template("/apis/batch/v1/namespaces/${namespace}/cronjobs/${name}"),
63+
"list": Template("/apis/batch/v1/namespaces/${namespace}/cronjobs"),
64+
"list-all": "/apis/batch/v1/cronjobs",
8465
},
8566
"DaemonSet": {
8667
"single": Template("/apis/apps/v1/namespaces/${namespace}/daemonsets/${name}"),
@@ -1962,9 +1943,6 @@ def create_instance(
19621943
"token_file": global_config.k8s_service_account_token,
19631944
"namespace_file": global_config.k8s_service_account_namespace,
19641945
"token_re_read_interval": global_config.k8s_token_re_read_interval,
1965-
"enable_fallback_urls": not (
1966-
global_config.k8s_fallback_urls_disable
1967-
),
19681946
}
19691947
)
19701948
return KubernetesApi(**kwargs)
@@ -1985,7 +1963,6 @@ def __init__(
19851963
token_file="/var/run/secrets/kubernetes.io/serviceaccount/token",
19861964
namespace_file="/var/run/secrets/kubernetes.io/serviceaccount/namespace",
19871965
token_re_read_interval=300,
1988-
enable_fallback_urls=True,
19891966
):
19901967
"""Init the kubernetes object"""
19911968
self.log_api_responses = log_api_responses
@@ -2005,7 +1982,6 @@ def __init__(
20051982
self._ca_file = ca_file
20061983
self._token_file = token_file
20071984
self._token_re_read_interval = int(token_re_read_interval)
2008-
self._enable_fallback_urls = enable_fallback_urls
20091985

20101986
# We create a few headers ahead of time so that we don't have to recreate them each time we need them.
20111987
self._standard_headers = {
@@ -2491,15 +2467,6 @@ def query_object(self, kind, namespace, name, query_options=None):
24912467
if not isinstance(object_endpoints, list):
24922468
object_endpoints = [object_endpoints]
24932469

2494-
if not self._enable_fallback_urls:
2495-
global_log.info(
2496-
"k8s_fallback_urls_disable option is set to true. Won't fall back to "
2497-
"the next URL in the list if API returns 404 response",
2498-
limit_once_per_x_secs=3600,
2499-
limit_key="k8s_get_object_fallback_url_disabled",
2500-
)
2501-
object_endpoints = object_endpoints[:1]
2502-
25032470
object_endpoints_count = len(object_endpoints)
25042471

25052472
for index, object_endpoint in enumerate(object_endpoints):
@@ -2565,15 +2532,6 @@ def query_objects(self, kind, namespace=None, filter=None):
25652532
if not isinstance(objects_endpoints, list):
25662533
objects_endpoints = [objects_endpoints]
25672534

2568-
if not self._enable_fallback_urls:
2569-
global_log.info(
2570-
"k8s_fallback_urls_disable option is set to true. Won't fall back to "
2571-
"the next URL in the list if API returns 404 response",
2572-
limit_once_per_x_secs=3600,
2573-
limit_key="k8s_list_objects_fallback_url_disabled",
2574-
)
2575-
objects_endpoints = objects_endpoints[:1]
2576-
25772535
objects_endpoints_count = len(objects_endpoints)
25782536

25792537
for index, objects_endpoint in enumerate(objects_endpoints):

0 commit comments

Comments
 (0)