-
Notifications
You must be signed in to change notification settings - Fork 36
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 Devfile Kube Struct Library Functions #44
Conversation
Signed-off-by: Maysun J Faisal <[email protected]>
Signed-off-by: Maysun J Faisal <[email protected]>
Signed-off-by: Maysun J Faisal <[email protected]>
Signed-off-by: Maysun J Faisal <[email protected]>
@andrewballantyne this is the PR for the Library functions which should cover those 4 shortlisted ones from https://github.com/openshift/console/pull/6321/files#diff-f8f657472eec48f6e5d2eb27f345b88687919d40900828812362ad5148d29683R35-R38 |
Signed-off-by: Maysun J Faisal <[email protected]>
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.
@maysunfaisal Mostly looks good to me, just had two concerns.
pkg/devfile/generator/generators.go
Outdated
} | ||
container := getContainer(containerParams) | ||
|
||
// If `mountSources: true` was set, add an empty dir volume to the container to sync the source to |
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.
Are we sure that all projects needs this? emptyDir volume?
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.
This is just a comment, we are not doing any empty volume mounting. If mountSources is true, we just set PROJECTS_ROOT
& PROJECT_SOURCE
for the container.
I'll go through the comments to make sure they're updated and clean.
|
||
// GetPortExposure iterate through all endpoints and returns the highest exposure level of all TargetPort. | ||
// exposure level: public > internal > none | ||
func (d *DevfileV2) GetPortExposure() map[int]v1.EndpointExposure { |
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.
not sure about this one in this package? is it intended to be directly consumed by library users? i saw generators code using this
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.
True, it is used by the generator code atm. But the reasoning behind why it was moved to the parser pkg is because the func returns a map with the devfile type v1.EndpointExposure
. We wanted to keep the generator pkg for only Kubernetes type functions.
Any thoughts?
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.
exposed function should return kube objects, but if it is not intended to be used by consumer, we can move this into generator/utils
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.
Updated
Signed-off-by: Maysun J Faisal <[email protected]>
Signed-off-by: Maysun J Faisal <[email protected]>
@adisky @mik-dass I've added more generator funcs to the list like - GetDeployment, GetService, GetIngress, etc... odo currently calls and uses GetDeploymentSpec, GetServiceSpec, GetIngressSpec for its usage and wraps it around with Deployment, Service, Ingress, etc. to create them. I think if we have these funcs it will help odo have less redundant code because there may multiple places where we are creating these kubernetes objects with objectMeta and Spec definitions.. Let me know, what you think. |
Signed-off-by: Maysun J Faisal <[email protected]>
Signed-off-by: Maysun J Faisal <[email protected]>
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.
this way users need to make two calls
GetDeploymentSpec()
and then
GetDeployment()
for simplicity and consistency i think it is better to have one call and all exposed function names be like
GetDeploymentSpec()
GetPodSpec()
GetServiceSpec()
GetIngressSpec()
pkg/devfile/generator/generators.go
Outdated
func GetDeploymentSpec(deploySpecParams DeploymentSpecParams) *appsv1.DeploymentSpec { | ||
deploymentSpec := &appsv1.DeploymentSpec{ | ||
Strategy: appsv1.DeploymentStrategy{ | ||
Type: appsv1.RecreateDeploymentStrategyType, | ||
}, | ||
Selector: &metav1.LabelSelector{ | ||
MatchLabels: deploySpecParams.PodSelectorLabels, | ||
}, | ||
Template: deploySpecParams.PodTemplateSpec, | ||
} | ||
|
||
return deploymentSpec | ||
} | ||
|
||
// DeploymentParams is a struct that contains the required data to create a deployment object | ||
type DeploymentParams struct { | ||
TypeMeta metav1.TypeMeta | ||
ObjectMeta metav1.ObjectMeta | ||
DeploymentSpec appsv1.DeploymentSpec | ||
} | ||
|
||
// GetDeployment gets a deployment object | ||
func GetDeployment(deployParams DeploymentParams) *appsv1.Deployment { | ||
|
||
deployment := &appsv1.Deployment{ | ||
TypeMeta: deployParams.TypeMeta, | ||
ObjectMeta: deployParams.ObjectMeta, | ||
Spec: deployParams.DeploymentSpec, | ||
} | ||
|
||
return deployment |
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.
this is getting confusing, can we have a single function instead?
GetDeployment
GetDeploymentSpec
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.
Currently odo uses GetDeploymentSpec
and wraps the spec with deployment
when odo goes to create it. There is 3-4 lines redundant code in odo for every kube resources. How do you feel about GetDeployment()
being the exposed func and it takes inputs for all the spec generation? Because, we're also creating pod template spec with GetPodTemplateSpec
and then creating a deployment spec with GetDeploymentSpec
. So we have to do multiple func call anyways and this was how the generator code was reviewed and written when it was first put into odo, they wanted it very modular and granular.
If we have one main function GetDeployment/GetService where the func would take all the necessary inputs, this would mean, odo would need to be modified a bit more. I've also mentioned this in the PR here #44 (comment)
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.
For example, like this https://github.com/openshift/odo/blob/master/pkg/kclient/deployments.go#L169
Or we can just merge this PR in with the GetDeploymentSpec, GetPodSpec, GetServiceSpec being the exposed functions and leave it upto the consumers to wrap the spec and object meta with the respective kubernetes resources in their own repo
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.
Updated to have GetDeployment, GetService, GetIngress, etc as exposed func
pkg/devfile/generator/generators.go
Outdated
} | ||
|
||
// GetService gets the service | ||
func GetService(serviceParams ServiceParams) *corev1.Service { |
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.
same for
GetService
GetServiceSpec
Signed-off-by: Maysun J Faisal <[email protected]>
/lgtm |
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.
Adding lgtm label, since it's already approved by requested reviewers
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: maysunfaisal, yangcao77 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Maysun J Faisal [email protected]
What does this PR do?
This PR copies over the refactored generator code from the Odo repo (redhat-developer/odo#4134)
What issues does this PR fix or reference?
Fixes devfile/api#184
Is your PR tested? Consider putting some instruction how to test your changes