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

"okteto init" asking for target deployment #918

Merged
merged 3 commits into from Jun 16, 2020
Merged

"okteto init" asking for target deployment #918

merged 3 commits into from Jun 16, 2020

Conversation

pchico83
Copy link
Contributor

Signed-off-by: Pablo Chico de Guzman pchico83@gmail.com

Fixes #907

@pchico83
Copy link
Contributor Author

Still requires some more testing, but the code should be ready for review

@codecov
Copy link

codecov bot commented Jun 14, 2020

Codecov Report

Merging #918 into master will increase coverage by 1.13%.
The diff coverage is 47.51%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #918      +/-   ##
==========================================
+ Coverage   33.54%   34.68%   +1.13%     
==========================================
  Files          67       67              
  Lines        5386     5648     +262     
==========================================
+ Hits         1807     1959     +152     
- Misses       3429     3535     +106     
- Partials      150      154       +4     
Impacted Files Coverage Δ
cmd/restart.go 0.00% <0.00%> (ø)
pkg/analytics/analytics.go 15.89% <0.00%> (-0.22%) ⬇️
pkg/k8s/deployments/crud.go 11.28% <0.00%> (-0.30%) ⬇️
pkg/k8s/pods/pod.go 12.74% <0.00%> (-1.55%) ⬇️
pkg/k8s/services/crud.go 4.34% <0.00%> (-1.72%) ⬇️
pkg/model/dev.go 65.09% <ø> (ø)
cmd/init.go 13.15% <14.67%> (-4.29%) ⬇️
pkg/linguist/linguist.go 47.47% <20.00%> (-2.00%) ⬇️
pkg/linguist/dev.go 83.81% <90.66%> (+19.63%) ⬆️

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 b8a485f...5da751f. Read the comment docs.

@pchico83 pchico83 force-pushed the init branch 2 times, most recently from 0523758 to 5ff69c6 Compare June 14, 2020 23:21
@derek
Copy link

derek bot commented Jun 15, 2020

Thank you for your contribution. I've just checked and your commit doesn't appear to be signed-off. That's something we need before your Pull Request can be merged. Please see our contributing guide.
Tip: if you only have one commit so far then run: git commit --amend --signoff and then git push --force.

cmd/init.go Outdated
return err
}

log.Success(fmt.Sprintf("Okteto manifest (%s) created", devPath))
log.Success(fmt.Sprintf("Okteto manifest (%s) created. Check its content in case you need to adapt it", devPath))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log.Success(fmt.Sprintf("Okteto manifest (%s) created. Check its content in case you need to adapt it", devPath))
log.Success(fmt.Sprintf("Okteto manifest (%s) created", devPath))

That second sentence sounds bad, let's not have it.

cmd/init.go Outdated
log.Info(err)
return fmt.Errorf("Failed to determine the language of the current directory")
}
ifAskingForDeployment := language == ""
Copy link
Member

Choose a reason for hiding this comment

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

I'd be more explicit to make the code easier to read.

Suggested change
ifAskingForDeployment := language == ""
askForDeployment := false
if language == "" {
askForDeployment = true
}

container = d.Spec.Template.Spec.Containers[0].Name
}

postfix := fmt.Sprintf("Analyzing deployment '%s'...", d.Name)
Copy link
Member

Choose a reason for hiding this comment

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

put the spinner before getting the deployment to it's also shown while doing the get

cmd/init.go Outdated
postfix := fmt.Sprintf("Analyzing deployment '%s'...", d.Name)
spinner := utils.NewSpinner(postfix)
spinner.Start()
defer spinner.Stop()
Copy link
Member

Choose a reason for hiding this comment

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

doing defers with the spinner create odd behaviors in the UI. It's better to start the spinner, call teh function, stop the spinner, and then check for error.

fmt.Printf("Which docker image do you want to use for your development container? [%s]: ", defaultImage)
_, err := fmt.Scanln(&image)
fmt.Println()
func getDeployment(namespace string) (*appsv1.Deployment, string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

can split this in two functions? one that gets the deployment / container, and another one that asks the user for info?

Copy link
Member

Choose a reason for hiding this comment

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

Also, you need to stop the spinner before showing text or the terminal can start behaving strangely.

}

func setWorkDirFromPod(ctx context.Context, dev *model.Dev, pod *apiv1.Pod, container string, config *rest.Config, c *kubernetes.Clientset) *model.Dev {
if dev.WorkDir != "" {
Copy link
Member

Choose a reason for hiding this comment

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

why would this be set if we are in the process of generating the manifest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it depends on the language

for _, port := range ports {
localPort := port
if port <= 1024 {
localPort = port + 8000
Copy link
Member

Choose a reason for hiding this comment

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

also check if there's no collision with other port forwards?


}

func setAnnotationsFromDeployment(dev *model.Dev, d *appsv1.Deployment) *model.Dev {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func setAnnotationsFromDeployment(dev *model.Dev, d *appsv1.Deployment) *model.Dev {
func setFluxAnnotationsIfNeeded(dev *model.Dev, d *appsv1.Deployment) *model.Dev {

}
if pod.Spec.Containers[i].Resources.Limits != nil {
dev.Resources = model.ResourceRequirements{
Limits: model.ResourceList{
Copy link
Member

Choose a reason for hiding this comment

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

how about requests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for dev, it is a good practice to leave them as they are. also, they are useless in Okteto Cloud

if pod.Spec.Containers[i].Resources.Limits != nil {
dev.Resources = model.ResourceRequirements{
Limits: model.ResourceList{
apiv1.ResourceCPU: resource.MustParse("1"),
Copy link
Member

Choose a reason for hiding this comment

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

why are you hardcoding them instead of using the ones from 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.

the ones on the pod are not valid for dev. thinks about a go binary image using 50m cpus.
I have set defaults we have seen in Okteto Cloud that makes sense. this also helps for the feature discoverability


//GetPortsByPod returns the ports exposed via endpoint of a given pod
func GetPortsByPod(p *apiv1.Pod, c *kubernetes.Clientset) ([]int, error) {
eList, err := c.CoreV1().Endpoints(p.Namespace).List(metav1.ListOptions{})
Copy link
Member

Choose a reason for hiding this comment

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

why endpoints instead of checking the pod directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ports at the pod level are only decorative. the endpoints tell exactly which ports are mapped to a kubernetes service (healthy or not).

Copy link
Member

@rberrelleza rberrelleza left a comment

Choose a reason for hiding this comment

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

Looks good. I think that now that we do a lot of more things, we should explain them as they happen.npm init is a good example of this:

image

Copy link
Contributor Author

@pchico83 pchico83 left a comment

Choose a reason for hiding this comment

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

@rberrelleza I will add info at the beginning of the init execution explaining its behavior.

}

func setWorkDirFromPod(ctx context.Context, dev *model.Dev, pod *apiv1.Pod, container string, config *rest.Config, c *kubernetes.Clientset) *model.Dev {
if dev.WorkDir != "" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it depends on the language

}
if pod.Spec.Containers[i].Resources.Limits != nil {
dev.Resources = model.ResourceRequirements{
Limits: model.ResourceList{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for dev, it is a good practice to leave them as they are. also, they are useless in Okteto Cloud

if pod.Spec.Containers[i].Resources.Limits != nil {
dev.Resources = model.ResourceRequirements{
Limits: model.ResourceList{
apiv1.ResourceCPU: resource.MustParse("1"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the ones on the pod are not valid for dev. thinks about a go binary image using 50m cpus.
I have set defaults we have seen in Okteto Cloud that makes sense. this also helps for the feature discoverability


//GetPortsByPod returns the ports exposed via endpoint of a given pod
func GetPortsByPod(p *apiv1.Pod, c *kubernetes.Clientset) ([]int, error) {
eList, err := c.CoreV1().Endpoints(p.Namespace).List(metav1.ListOptions{})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ports at the pod level are only decorative. the endpoints tell exactly which ports are mapped to a kubernetes service (healthy or not).

@derek
Copy link

derek bot commented Jun 16, 2020

Thank you for your contribution. I've just checked and your commit doesn't appear to be signed-off. That's something we need before your Pull Request can be merged. Please see our contributing guide.
Tip: if you only have one commit so far then run: git commit --amend --signoff and then git push --force.

Signed-off-by: Pablo Chico de Guzman <pchico83@gmail.com>
Signed-off-by: Pablo Chico de Guzman <pchico83@gmail.com>
Signed-off-by: Pablo Chico de Guzman <pchico83@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Next "okteto init" iteration
2 participants