Skip to content

Commit

Permalink
ref(apis): parse version out for replicasets
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptophobia committed Oct 21, 2019
1 parent a6fa780 commit d8e65a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion rootfs/scheduler/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ def upsert_pods(controller, url):
# turn RC / RS (which a Deployment creates) url into pods one
url = url.replace(cache_key(controller['metadata']['name']), '')
if '_replicasets_' in url:
# We need to try to replace both just in case, one or the other exists (api backwards compatibility)
url = url.replace('_replicasets_', '_pods').replace('apis_apps_v1', 'api_v1') # noqa
url = url.replace('_replicasets_', '_pods').replace('apis_extensions_v1beta1', 'api_v1') # noqa
else:
url = url.replace('_replicationcontrollers_', '_pods')
# make sure url only has up to "_pods"
Expand Down Expand Up @@ -450,7 +452,6 @@ def manage_replicasets(deployment, url):

# get RS url
rs_url = url.replace('_deployments_', '_replicasets_')
rs_url = rs_url.replace('apis_extensions_v1beta1_', 'apis_apps_v1_')
rs_url += '_' + pod_hash
namespaced_url = rs_url[0:(rs_url.find("_replicasets") + 12)]

Expand Down Expand Up @@ -514,6 +515,8 @@ def manage_replicasets(deployment, url):
def update_deployment_status(namespaced_url, url, deployment, rs):
# Fill out deployment.status for success as pods transition to running state
pod_url = namespaced_url.replace('_replicasets', '_pods').replace('apis_apps_v1', 'api_v1') # noqa
# We need to try to replace both just in case, one or the other exists (api backwards compatibility)
pod_url = pod_url.replace('_replicasets', '_pods').replace('apis_extensions_v1beta1', 'api_v1') # noqa
while True:
# The below needs to be done to emulate Deployment handling things
# always cleanup pods
Expand Down
12 changes: 11 additions & 1 deletion rootfs/scheduler/resources/replicaset.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
from scheduler.exceptions import KubeHTTPException
from scheduler.resources import Resource

from packaging.version import parse


class ReplicaSet(Resource):
api_prefix = 'apis'
api_version = 'apps/v1'
short_name = 'rs'

@property
def api_version(self):
# API locations have changed since 1.9 and deprecated in 1.16
# https://kubernetes.io/blog/2019/07/18/api-deprecations-in-1-16/
if self.version() >= parse("1.9.0"):
return 'apps/v1'

return 'extensions/v1beta1'

def get(self, namespace, name=None, **kwargs):
"""
Fetch a single ReplicaSet or a list
Expand Down

0 comments on commit d8e65a9

Please sign in to comment.