-
-
Notifications
You must be signed in to change notification settings - Fork 8
Add creation handler (WIP) #20
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
Open
gautamp8
wants to merge
1
commit into
master
Choose a base branch
from
kopf-creation-handler
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from typing import List | ||
from kubernetes import client as k8s | ||
from kubernetes_utils.pod_generator import PodGenerator | ||
from models.celery_custom_resource import CeleryCustomResource | ||
|
||
|
||
class FlowerDeploymentGenerator(object): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. explicit inheritance from the object is not needed |
||
|
||
def __init__(self, namespace: str, celery_cr: CeleryCustomResource): | ||
self.namespace = namespace | ||
self.celery_cr = celery_cr | ||
|
||
def get_flower_deployment(self) -> k8s.V1Deployment: | ||
template = k8s.V1PodTemplateSpec( | ||
metadata=k8s.V1ObjectMeta( | ||
labels={"app": f'{self.celery_cr.app_name}-celery-flower'} | ||
), | ||
spec=self.get_flower_pod().spec | ||
) | ||
deployment_spec = k8s.V1DeploymentSpec( | ||
replicas=self.celery_cr.worker_replicas, | ||
template=template, | ||
selector={'matchLabels': {'app': f'{self.celery_cr.app_name}-celery-flower'}} | ||
) | ||
|
||
return k8s.V1Deployment( | ||
api_version="apps/v1", | ||
kind="Deployment", | ||
metadata=k8s.V1ObjectMeta(name=f'{self.celery_cr.app_name}-celery-flower'), | ||
spec=deployment_spec | ||
) | ||
|
||
def get_flower_pod(self) -> k8s.V1Pod: | ||
return PodGenerator( | ||
namespace=self.namespace, | ||
image=self.celery_cr.image, | ||
image_pull_policy=self.celery_cr.image_pull_policy, | ||
image_pull_secrets=self.celery_cr.image_pull_secrets, | ||
name=f"{self.celery_cr.app_name}-celery-flower", | ||
container_name='flower', | ||
volume_mounts=self.celery_cr.volume_mounts, | ||
volumes=self.celery_cr.volumes, | ||
init_containers=self.celery_cr.init_containers, | ||
cmds=["flower"], | ||
envs=self.celery_cr.flower_spec.env, | ||
args=self.__get_flower_container_args( | ||
self.celery_cr.celery_app, self.celery_cr.flower_spec.args | ||
), | ||
node_selectors=self.celery_cr.flower_spec.node_selector, | ||
resources=self.celery_cr.flower_spec.resources.to_dict(), | ||
readiness_probe=self.celery_cr.readiness_probe, | ||
liveness_probe=self.celery_cr.liveness_probe | ||
).gen_pod() | ||
|
||
def get_flower_svc(self) -> k8s.V1Service: | ||
svc_template = self.celery_cr.flower_spec.service | ||
metadata = { | ||
'name': f'{self.celery_cr.app_name}-celery-flower' | ||
} | ||
return k8s.V1Service( | ||
metadata=metadata, | ||
spec=svc_template.get('spec') | ||
) | ||
|
||
def __get_flower_container_args( | ||
self, celery_app: str, args: List[str] | ||
) -> List[str]: | ||
base_args = [f"--app={celery_app}", "flower"] | ||
if args: | ||
base_args.extend(args) | ||
return base_args |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can try httpx and see if any side effect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, actually, it's the old code dependency that I wrote for the prototype. I'll remove it in the next PR. It is being used to poll flower API to fetch queue length. Autoscaling implementation will change entirely.