Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example data for gke scaler #1

Merged
merged 1 commit into from
May 24, 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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
export PATH="/usr/share/miniconda/bin:$PATH"
source activate black
pip install -r .github/dev-requirements.txt
pre-commit run --all-files
pre-commit run --all-files
17 changes: 17 additions & 0 deletions examples/data/test-scale-up-1/test-cluster/scaling-0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"times": {
"create_cluster": 312.325,
"scale_up_1_to_2": 34.675,
"scale_up_2_to_3": 28.76,
"scale_up_3_to_4": 37.704,
"delete_cluster": 211.354
},
"cluster_name": "projects/llnl-flux/locations/us-central1-a/clusters/test-scale-up-1-test-cluster",
"name": "test-scale-up-1-test-cluster",
"machine_type": "c2-standard-8",
"region": "us-central1-a",
"tags": [
"kubescaler-cluster"
],
"description": "A Kubescaler testing cluster"
}
2 changes: 1 addition & 1 deletion kubescaler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from kubescaler.scaler import GKECluster
from kubescaler.version import __version__
from kubescaler.scaler import GKECluster
7 changes: 3 additions & 4 deletions kubescaler/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

from kubescaler.utils import write_json


class Cluster:
"""
A base cluster controller for scaling.
"""

def __init__(
self,
name=None,
Expand All @@ -22,9 +24,6 @@ def __init__(
"""
A simple class to control creating a cluster
"""
# This client we can use to interact with Google Cloud GKE
# https://github.com/googleapis/python-container/blob/main/google/cloud/container_v1/services/cluster_manager/client.py#L96
print("⭐️ Creating global cluster manager client...")
self.node_count = node_count
self.tags = tags or ["kubescaler-cluster"]
self.name = name or "kubescaler-cluster"
Expand Down Expand Up @@ -74,4 +73,4 @@ def create_cluster(self):
"""
Create a cluster, with hard coded variables for now.
"""
raise NotImplementedError
raise NotImplementedError
5 changes: 3 additions & 2 deletions kubescaler/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
#
# SPDX-License-Identifier: (MIT)

from functools import partial, update_wrapper
import time
from functools import partial, update_wrapper


class timed:
"""
Expand Down Expand Up @@ -53,4 +54,4 @@ def __call__(self, cls, *args, **kwargs):
print(f"Retrying in {sleep} seconds - error: {e}")
time.sleep(sleep)
attempt += 1
return self.func(cls, *args, **kwargs)
return self.func(cls, *args, **kwargs)
2 changes: 1 addition & 1 deletion kubescaler/scaler/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .google import GKECluster
from .google import GKECluster
13 changes: 8 additions & 5 deletions kubescaler/scaler/google.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from google.cloud import container_v1
import time

from google.api_core.exceptions import NotFound
from kubescaler.decorators import timed, retry
from google.cloud import container_v1

from kubescaler.cluster import Cluster
import time
from kubescaler.decorators import retry, timed


class GKECluster(Cluster):
"""
A scaler for a Google Kubernetes Engine (GKE) cluster
"""

def __init__(
self,
project,
Expand All @@ -16,7 +20,7 @@ def __init__(
machine_type_memory_gb=32,
machine_type_vcpu=8,
region="us-central1-a",
**kwargs
**kwargs,
):
"""
A simple class to control creating a cluster
Expand All @@ -42,7 +46,6 @@ def delete_cluster(self):
# Make the request, and check until deleted!
self.client.delete_cluster(request=request)
self.wait_for_delete()
# TODO we need a wait for create too!

@property
def zone(self):
Expand Down
6 changes: 1 addition & 5 deletions kubescaler/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,4 @@
write_yaml,
)
from .misc import chunks, get_hash, mb_to_bytes, print_bytes, slugify
from .terminal import (
confirm_action,
get_installdir,
run_command,
)
from .terminal import confirm_action, get_installdir, run_command
3 changes: 1 addition & 2 deletions kubescaler/utils/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def mkdir_p(path):
logger.exit("Error creating path %s, exiting." % path)



def get_tmpfile(tmpdir=None, prefix="kubescaler-"):
"""
Get a temporary file with an optional prefix.
Expand Down Expand Up @@ -213,4 +212,4 @@ def read_json(filename, mode="r"):
"""
Read a json file to a dictionary.
"""
return json.loads(read_file(filename))
return json.loads(read_file(filename))
2 changes: 1 addition & 1 deletion kubescaler/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

# Prefer discovery clients - more control
GOOGLE_CLOUD_REQUIRES = (
# ("google-auth", {"min_version": None}),
# ("google-auth", {"min_version": None}),
("google-cloud-container", {"min_version": None}),
)

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ exclude = docs
max-line-length = 100
ignore = E1 E2 E5 W5
per-file-ignores =
kubescaler/__init__.py:F401
kubescaler/utils/__init__.py:F401
kubescaler/scaler/__init__.py:F401
kubescaler/version.py:F401