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 Devfile Kube Struct Library Functions #44

Merged
merged 10 commits into from
Nov 25, 2020

Conversation

maysunfaisal
Copy link
Member

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

@maysunfaisal maysunfaisal changed the title Add first set of parser utils Add Devfile Kube Struct Library Functions Nov 9, 2020
@maysunfaisal maysunfaisal marked this pull request as ready for review November 12, 2020 15:35
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]>
@maysunfaisal
Copy link
Member Author

@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]>
Copy link

@adisky adisky left a 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.

}
container := getContainer(containerParams)

// If `mountSources: true` was set, add an empty dir volume to the container to sync the source to
Copy link

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?

Copy link
Member Author

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 {
Copy link

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

Copy link
Member Author

@maysunfaisal maysunfaisal Nov 18, 2020

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?

Copy link

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

@maysunfaisal
Copy link
Member Author

maysunfaisal commented Nov 18, 2020

@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]>
@maysunfaisal
Copy link
Member Author

@adisky @mik-dass Can this be LGTM'd?

Signed-off-by: Maysun J Faisal <[email protected]>
Copy link

@adisky adisky left a 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()

Comment on lines 118 to 148
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
Copy link

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

Copy link
Member Author

@maysunfaisal maysunfaisal Nov 24, 2020

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)

Copy link
Member Author

@maysunfaisal maysunfaisal Nov 24, 2020

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

Copy link
Member Author

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

}

// GetService gets the service
func GetService(serviceParams ServiceParams) *corev1.Service {
Copy link

Choose a reason for hiding this comment

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

same for

GetService
GetServiceSpec

@mik-dass
Copy link
Collaborator

@adisky @mik-dass Can this be LGTM'd?

Please have a look at @adisky 's concerns. Rest looks OK to me.

@adisky
Copy link

adisky commented Nov 25, 2020

/lgtm

Copy link
Collaborator

@yangcao77 yangcao77 left a 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

@openshift-ci-robot
Copy link

[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:
  • OWNERS [maysunfaisal,yangcao77]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

initial Kubernetes object generation piece to unblock openshift/console
5 participants