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

Workloads update #13

Merged
merged 1 commit into from
May 27, 2020
Merged

Workloads update #13

merged 1 commit into from
May 27, 2020

Conversation

mdgreenwald
Copy link
Owner

@mdgreenwald mdgreenwald commented May 20, 2020

Changes

  • Adds support for CronJob and DaemonSet workloads. 🎉
  • Deprecate /api/v1/deploy in favor of /api/v1/deployment.
  • Bumps Flask to version 1.1.2.
  • Adds new tests/setup.yaml to create test workloads to patch.
  • Match imports style.
  • Renames functions to match methods in client python API.
  • Rename object_type variable to name for clarity.
  • Added endpoints and parameters section to the README.

Deprecation notice

The original deploy endpoint /api/v1/deploy will continue to work for the foreseeable future, but it is recommended to move to the new deployment /api/v1/deployment endpoint.

@mdgreenwald mdgreenwald added the enhancement New feature or request label May 20, 2020
@mdgreenwald mdgreenwald self-assigned this May 20, 2020
@mdgreenwald mdgreenwald changed the title Matthew/workloads update Workloads update May 20, 2020
@mdgreenwald mdgreenwald force-pushed the matthew/workloads_update branch from 40c134a to 4ad8ce1 Compare May 20, 2020 22:34
@mdgreenwald mdgreenwald marked this pull request as ready for review May 20, 2020 22:34
Copy link

@theIV theIV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly small things, hope it's helpful!

g.PD_REGISTRY = current_app.config['PD_REGISTRY']

def read_deployment(deployment, namespace):
def list_cron_job(name, namespace):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these list_* methods seem to follow the same pattern.

I could see a more general fetch_object(object, name, namespace) (something like that) that would dispatch the calls to the necessary k8s api endpoint. At that point, you could either use the more generic fetch_object or keep the more specialized calls that :just: use the generic one under the hood.

)
if len(api_response.items) == 1:
return api_response.items[0]
else:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if returning a string for the else clause is the best approach. Your consumer of that calls a long chain of methods, e.g. cron_job_object.spec.job_template.spec.template.spec.containers[0].image which will probably blow up if cron_job_object were a string.

Do you want it to raise an exception as opposed to returning a string? I'm not sure if that's considered best practice in Python, but that might be an option.

Comment on lines +112 to +115
image_tag = request.args['image_tag']
image_name = request.args['image_name']
name = request.args['name']
namespace = request.args['namespace']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless this does something special like ensure that the parameters are passed, these assignments feel noisy any unnecessary since you "consume them" just a few lines below.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That style actually does force the request to pass those parameters.

name = request.args['name']
namespace = request.args['namespace']
cronjob = patch_cron_job(
cron_job_object=list_cron_job(name=name, namespace=namespace),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

patch_cron_job should probably be responsible for fetching the cron_job_object. It's signature already takes a name & namespace so you wouldn't have to add anything, but you would be able to remove something and simplify the call sites.

@@ -0,0 +1,89 @@
---
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I run these tests? If so, maybe a few details in the README would go a long way.

@mdgreenwald
Copy link
Owner Author

@theIV I am going to leave these suggestions for a later PR which will add testing and linting. Thank you for your helpful feedback!

@mdgreenwald mdgreenwald merged commit 33fc4e8 into master May 27, 2020
@mdgreenwald mdgreenwald deleted the matthew/workloads_update branch May 27, 2020 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants