Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Revert previously undeployed changes #348

Merged
merged 2 commits into from
Oct 18, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ autoscaling:
instance_loss_threshold: 3

alert_on_max_capacity: false
pool_owner: compute_infra
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ autoscale_signal:
minute_range: 10

alert_on_max_capacity: false
pool_owner: compute_infra
18 changes: 7 additions & 11 deletions clusterman/autoscaler/autoscaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,12 @@ def run(self, dry_run: bool = False, timestamp: Optional[arrow.Arrow] = None) ->
else:
capacity_offset = get_capacity_offset(self.cluster, self.pool, self.scheduler, timestamp)
new_target_capacity = self._compute_target_capacity(resource_request) + capacity_offset
self.target_capacity_gauge.set(new_target_capacity, self.add_metric_labels(dry_run))
self.max_capacity_gauge.set(self.pool_manager.max_capacity, self.add_metric_labels(dry_run))
self.setpoint_gauge.set(self.autoscaling_config.setpoint, self.add_metric_labels(dry_run))
self.target_capacity_gauge.set(new_target_capacity, {"dry_run": dry_run})
self.max_capacity_gauge.set(
self.pool_manager.max_capacity,
{"dry_run": dry_run, "alert_on_max_capacity": self.pool_manager.alert_on_max_capacity},
)
self.setpoint_gauge.set(self.autoscaling_config.setpoint, {"dry_run": dry_run})
self._emit_requested_resource_metrics(resource_request, dry_run=dry_run)

try:
Expand All @@ -199,14 +202,7 @@ def run(self, dry_run: bool = False, timestamp: Optional[arrow.Arrow] = None) ->
def _emit_requested_resource_metrics(self, resource_request: SignalResourceRequest, dry_run: bool) -> None:
for resource_type, resource_gauge in self.resource_request_gauges.items():
if getattr(resource_request, resource_type) is not None:
resource_gauge.set(getattr(resource_request, resource_type), self.add_metric_labels(dry_run))

def add_metric_labels(self, dry_run):
return {
"dry_run": dry_run,
"alert_on_max_capacity": self.pool_manager.alert_on_max_capacity,
"team": self.pool_manager.pool_owner,
}
resource_gauge.set(getattr(resource_request, resource_type), {"dry_run": dry_run})

def _get_signal_for_app(self, app: str) -> Signal:
"""Load the signal object to use for autoscaling for a particular app
Expand Down
1 change: 0 additions & 1 deletion clusterman/autoscaler/pool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def __init__(
"autoscaling.killable_nodes_prioritizing_v2", default=False
)
self.alert_on_max_capacity = self.pool_config.read_bool("alert_on_max_capacity", default=True)
self.pool_owner = self.pool_config.read_string("pool_owner", default="compute_infra")
monitoring_info = {"cluster": cluster, "pool": pool}
self.killable_nodes_counter = get_monitoring_client().create_counter(SFX_KILLABLE_NODES_COUNT, monitoring_info)

Expand Down
4 changes: 2 additions & 2 deletions clusterman/kubernetes/kubernetes_cluster_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import colorlog
import kubernetes
import staticconf
from kubernetes.client import V1beta1Eviction
from kubernetes.client import V1DeleteOptions
from kubernetes.client import V1Eviction
from kubernetes.client import V1ObjectMeta
from kubernetes.client.models.v1_node import V1Node as KubernetesNode
from kubernetes.client.models.v1_pod import V1Pod as KubernetesPod
Expand Down Expand Up @@ -356,7 +356,7 @@ def _evict_pod(self, pod: KubernetesPod):
self._core_api.create_namespaced_pod_eviction(
name=pod.metadata.name,
namespace=pod.metadata.namespace,
body=V1Eviction(
body=V1beta1Eviction(
metadata=V1ObjectMeta(
name=pod.metadata.name,
namespace=pod.metadata.namespace,
Expand Down
3 changes: 1 addition & 2 deletions clusterman/kubernetes/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from kubernetes.client.models.v1_node_selector_requirement import V1NodeSelectorRequirement
from kubernetes.client.models.v1_node_selector_term import V1NodeSelectorTerm
from kubernetes.client.models.v1_pod import V1Pod as KubernetesPod
from kubernetes.config.config_exception import ConfigException

from clusterman.util import ClustermanResources

Expand Down Expand Up @@ -73,7 +72,7 @@ def __init__(self, kubeconfig_path: str, client_class: Type) -> None:
kubernetes.config.load_incluster_config()
else:
kubernetes.config.load_kube_config(kubeconfig_path, context=os.getenv("KUBECONTEXT"))
except (TypeError, ConfigException):
except TypeError:
error_msg = "Could not load KUBECONFIG; is this running on Kubernetes master?"
if "yelpcorp" in socket.getfqdn():
error_msg += "\nHint: try using the clusterman-k8s-<clustername> wrapper script!"
Expand Down
1 change: 0 additions & 1 deletion clusterman/simulator/simulated_pool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def __init__(
MAX_MIN_NODE_SCALEIN_UPTIME_SECONDS,
)
self.alert_on_max_capacity = self.pool_config.read_bool("alert_on_max_capacity", default=True)
self.pool_owner = self.pool_config.read_string("pool_owner", default="compute_infra")
self.killable_nodes_prioritizing_v2 = self.pool_config.read_bool(
"autoscaling.killable_nodes_prioritizing_v2", default=False
)
Expand Down
3 changes: 1 addition & 2 deletions examples/schemas/pool.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@
"additionalProperties": false
},
"sensu_config": {"$ref": "definitions.json#sensu_config"},
"alert_on_max_capacity": {"type": "boolean"},
"pool_owner": {"type": "string"}
"alert_on_max_capacity": {"type": "boolean"}
},
"additionalProperties": false
}
2 changes: 0 additions & 2 deletions itests/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def setup_configurations(context):
],
},
"alert_on_max_capacity": True,
"pool_owner": "compute_infra",
}
kube_pool_config = {
"resource_groups": [
Expand All @@ -145,7 +144,6 @@ def setup_configurations(context):
"period_minutes": 7,
},
"alert_on_max_capacity": True,
"pool_owner": "compute_infra",
}
with staticconf.testing.MockConfiguration(
boto_config, namespace=CREDENTIALS_NAMESPACE
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ idna==2.8
jmespath==0.9.4
jsonpickle==1.4.2
kiwisolver==1.1.0
kubernetes==24.2.0
kubernetes==10.0.1
matplotlib==3.4.2
mypy-extensions==0.4.3
numpy==1.21.6
Expand Down
18 changes: 4 additions & 14 deletions tests/autoscaler/autoscaler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def pool_configs():
"max_weight_to_remove": 10,
},
"alert_on_max_capacity": True,
"pool_owner": "compute_infra",
},
namespace=POOL_NAMESPACE.format(pool="bar", scheduler="mesos"),
):
Expand Down Expand Up @@ -92,10 +91,6 @@ def mock_autoscaler():
"alert_on_max_capacity",
namespace=POOL_NAMESPACE.format(pool="bar", scheduler="mesos"),
)
mock_autoscaler.pool_manager.pool_owner = staticconf.read_string(
"pool_owner",
namespace=POOL_NAMESPACE.format(pool="bar", scheduler="mesos"),
)
mock_autoscaler.pool_manager.non_orphan_fulfilled_capacity = 0

mock_autoscaler.target_capacity_gauge = mock.Mock(spec=GaugeProtocol)
Expand Down Expand Up @@ -163,22 +158,17 @@ def test_autoscaler_run(dry_run, mock_autoscaler, run_timestamp):
), pytest.raises(ValueError):
mock_autoscaler.run(dry_run=dry_run, timestamp=run_timestamp)

assert mock_autoscaler.target_capacity_gauge.set.call_args == mock.call(
100, {"dry_run": dry_run, "alert_on_max_capacity": True, "team": "compute_infra"}
)
assert mock_autoscaler.target_capacity_gauge.set.call_args == mock.call(100, {"dry_run": dry_run})
assert mock_autoscaler.max_capacity_gauge.set.call_args == mock.call(
mock_autoscaler.pool_manager.max_capacity,
{"dry_run": dry_run, "alert_on_max_capacity": True, "team": "compute_infra"},
)
assert mock_autoscaler.setpoint_gauge.set.call_args == mock.call(
0.7, {"dry_run": dry_run, "alert_on_max_capacity": True, "team": "compute_infra"}
mock_autoscaler.pool_manager.max_capacity, {"dry_run": dry_run, "alert_on_max_capacity": True}
)
assert mock_autoscaler.setpoint_gauge.set.call_args == mock.call(0.7, {"dry_run": dry_run})
assert mock_autoscaler._compute_target_capacity.call_args == mock.call(resource_request)
assert mock_autoscaler.pool_manager.modify_target_capacity.call_count == 1

assert mock_autoscaler.resource_request_gauges["cpus"].set.call_args == mock.call(
resource_request.cpus,
{"dry_run": dry_run, "alert_on_max_capacity": True, "team": "compute_infra"},
{"dry_run": dry_run},
)
assert mock_autoscaler.resource_request_gauges["mem"].set.call_count == 0
assert mock_autoscaler.resource_request_gauges["disk"].set.call_count == 0
Expand Down
2 changes: 0 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def clusterman_pool_config():
],
},
"alert_on_max_capacity": True,
"pool_owner": "compute_infra",
}
with staticconf.testing.MockConfiguration(config, namespace="bar.mesos_config"):
yield
Expand Down Expand Up @@ -203,7 +202,6 @@ def clusterman_k8s_pool_config():
"disable_autoscaling": False,
},
"alert_on_max_capacity": False,
"pool_owner": "foo",
}
with staticconf.testing.MockConfiguration(config, namespace="bar.kubernetes_config"):
yield
Expand Down
3 changes: 1 addition & 2 deletions tests/kubernetes/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pytest
from kubernetes.client.models.v1_node_selector_requirement import V1NodeSelectorRequirement
from kubernetes.client.models.v1_node_selector_term import V1NodeSelectorTerm
from kubernetes.config import ConfigException

from clusterman.kubernetes.util import CachedCoreV1Api
from clusterman.kubernetes.util import ConciseCRDApi
Expand All @@ -22,7 +21,7 @@ def mock_cached_core_v1_api():


def test_cached_corev1_api_no_kubeconfig(caplog):
with pytest.raises(ConfigException):
with pytest.raises(TypeError):
CachedCoreV1Api("/foo/bar/admin.conf")
assert "Could not load KUBECONFIG" in caplog.text

Expand Down
Loading