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

Refactor & cleanup kclient generators code before migrating to devfile/parser #4134

Merged

Conversation

maysunfaisal
Copy link
Contributor

@maysunfaisal maysunfaisal commented Oct 22, 2020

What type of PR is this?
/kind cleanup
/kind code-refactoring

What does does this PR do / why we need it:
This PR cleans up kclient generators code so that it can be exported out to devfile/parser repo:

  • Moved the generator code from kclient/generators.go to kclient/generator/generators.go
  • Moved some of the adapter/utils.go code to kclient/generator/utils.go
  • Updated the kube adapter createOrUpdateComponent() logic around kclient refactoring
  • Added missing unit tests for some of the util functions

Which issue(s) this PR fixes:

Fixes #4131

PR acceptance criteria:

How to test changes / Special notes to the reviewer:

  • Run the unit and integration tests

@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. kind/cleanup labels Oct 22, 2020
@openshift-ci-robot
Copy link
Collaborator

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@maysunfaisal maysunfaisal force-pushed the ref-kclient-gen-1 branch 3 times, most recently from c781bb5 to c152ca3 Compare October 27, 2020 15:13
@maysunfaisal maysunfaisal marked this pull request as ready for review October 27, 2020 22:43
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. label Oct 27, 2020
@maysunfaisal maysunfaisal changed the title Refactor kclient generators code before migrating to devfile/parser Refactor & cleanup kclient generators code before migrating to devfile/parser Oct 27, 2020
@maysunfaisal maysunfaisal force-pushed the ref-kclient-gen-1 branch 3 times, most recently from 0cb83f8 to 269efe1 Compare October 29, 2020 19:17
}
objectMeta := generator.CreateObjectMeta(componentName, a.Client.Namespace, labels, nil)
supervisordInitContainer := kclient.AddBootstrapSupervisordInitContainer()
initContainers := utils.GetPreStartInitContainers(a.Devfile, containers)
Copy link
Contributor

@adisky adisky Oct 30, 2020

Choose a reason for hiding this comment

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

why we need to pass containers to get init containers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

containers is all the component containers returned from the devfile. PreStart events reference a command(which in turn reference a container component). So we scan thru all the containers that we have and append to initContainers

// Add PVC and Volume Mounts to the podTemplateSpec
err = kclient.AddPVCAndVolumeMount(podTemplateSpec, volumeNameToPVCName, containerNameToVolumes)
// Get PVC volumes and Volume Mounts
containers, pvcVolumes, err := kclient.GetPVCVolAndVolMount(containers, volumeNameToPVCName, containerNameToVolumes)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we do the volume mount part while generating the containers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably can, but that should be done with GetVolumes refactoring. I have not touched those volume logic in this PR.

Pls see the commend below regd Volume refactoring

}

// Get the container info for the given component
if container, ok := containersMap[component]; ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

little confused here, what's the benefit of overriding here? we are not returning containers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I've cleaned this up a little bit and I removed the map; this is basically the same comment as I have mentioned here #4134 (comment) - we pass in containers that we get from devfile to loop thru and append it to initcontainers.


const (
// DevfileSourceVolume is the constant containing the name of the emptyDir volume containing the project source
DevfileSourceVolume = "devfile-projects"
Copy link
Contributor

Choose a reason for hiding this comment

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

do the other projects follows the concept of source volume?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have asked this question on the forum-devfile Slack channel, lets wait for the outcome. I think all devfile consumers should sync the project somewhere in the pod.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved the odo-projects vol mount code out of the generators and made it odo specific

}

// GenerateContainer creates a container spec that can be used when creating a pod
func GenerateContainer(containerParams ContainerParams) *corev1.Container {
Copy link
Contributor

Choose a reason for hiding this comment

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

we do not need to expose this method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated


// GeneratePVCSpec creates a pvc spec
func GeneratePVCSpec(quantity resource.Quantity) *corev1.PersistentVolumeClaimSpec {

Copy link
Contributor

Choose a reason for hiding this comment

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

devfile should be input here and generate pvc specs according to volume component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left this untouched due to the GetVolume refactoring I was talking about. CreatePVC just takes corev1.PersistentVolumeClaimSpec spec to create the pvc. The pvc name is tied with other logic and would need a separate PR to refactor it. I think thats going to be a bigger change.

}

// GenerateServiceSpec creates a service spec
func GenerateServiceSpec(serviceSpecParams ServiceSpecParams) *corev1.ServiceSpec {
Copy link
Contributor

Choose a reason for hiding this comment

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

this should not be exposed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@codecov
Copy link

codecov bot commented Oct 31, 2020

Codecov Report

Merging #4134 (60aaf7f) into master (30d9478) will increase coverage by 0.34%.
The diff coverage is 81.81%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4134      +/-   ##
==========================================
+ Coverage   42.23%   42.57%   +0.34%     
==========================================
  Files         155      156       +1     
  Lines       13204    13258      +54     
==========================================
+ Hits         5577     5645      +68     
+ Misses       7020     7012       -8     
+ Partials      607      601       -6     
Impacted Files Coverage Δ
pkg/component/component_full_description.go 0.00% <0.00%> (ø)
pkg/devfile/adapters/common/types.go 50.00% <ø> (ø)
pkg/devfile/validate/generic/errors.go 9.09% <0.00%> (-10.91%) ⬇️
pkg/kclient/kclient.go 0.00% <0.00%> (-8.46%) ⬇️
pkg/kclient/supervisord.go 0.00% <0.00%> (ø)
pkg/testingutil/devfile.go 0.00% <0.00%> (ø)
pkg/kclient/secrets.go 76.74% <73.33%> (-7.88%) ⬇️
pkg/devfile/adapters/kubernetes/utils/utils.go 81.02% <80.48%> (+0.35%) ⬆️
...g/devfile/adapters/kubernetes/component/adapter.go 37.54% <81.81%> (+6.42%) ⬆️
pkg/kclient/generator/generators.go 86.00% <86.00%> (ø)
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30d9478...60aaf7f. Read the comment docs.

pkg/kclient/supervisord.go Outdated Show resolved Hide resolved
yangcao77 and others added 21 commits November 6, 2020 11:05
Signed-off-by: Stephanie <yangcao@redhat.com>
Signed-off-by: Stephanie <yangcao@redhat.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Stephanie <yangcao@redhat.com>
Signed-off-by: Stephanie <yangcao@redhat.com>
Signed-off-by: Stephanie <yangcao@redhat.com>
Signed-off-by: Stephanie <yangcao@redhat.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Copy link
Contributor

@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.

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Nov 9, 2020
@openshift-bot
Copy link

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit fce3c77 into redhat-developer:master Nov 9, 2020
@rm3l rm3l added the area/refactoring Issues or PRs related to code refactoring label Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. area/refactoring Issues or PRs related to code refactoring lgtm Indicates that a PR is ready to be merged. Required by Prow.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleanup & Refactor kClient generators code before migrating to devfile library
8 participants