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
Conversation
Still requires some more testing, but the code should be ready for review |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
0523758
to
5ff69c6
Compare
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. |
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)) |
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.
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 == "" |
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.
I'd be more explicit to make the code easier to read.
ifAskingForDeployment := language == "" | |
askForDeployment := false | |
if language == "" { | |
askForDeployment = true | |
} |
container = d.Spec.Template.Spec.Containers[0].Name | ||
} | ||
|
||
postfix := fmt.Sprintf("Analyzing deployment '%s'...", d.Name) |
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.
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() |
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.
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) { |
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.
can split this in two functions? one that gets the deployment / container, and another one that asks the user for info?
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.
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 != "" { |
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.
why would this be set if we are in the process of generating the manifest?
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.
it depends on the language
for _, port := range ports { | ||
localPort := port | ||
if port <= 1024 { | ||
localPort = port + 8000 |
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.
also check if there's no collision with other port forwards?
|
||
} | ||
|
||
func setAnnotationsFromDeployment(dev *model.Dev, d *appsv1.Deployment) *model.Dev { |
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.
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{ |
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.
how about requests?
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 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"), |
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.
why are you hardcoding them instead of using the ones from the pod?
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.
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{}) |
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.
why endpoints instead of checking the pod directly?
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.
ports at the pod level are only decorative. the endpoints tell exactly which ports are mapped to a kubernetes service (healthy or not).
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.
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.
@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 != "" { |
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.
it depends on the language
} | ||
if pod.Spec.Containers[i].Resources.Limits != nil { | ||
dev.Resources = model.ResourceRequirements{ | ||
Limits: model.ResourceList{ |
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 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"), |
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.
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{}) |
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.
ports at the pod level are only decorative. the endpoints tell exactly which ports are mapped to a kubernetes service (healthy or not).
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. |
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>
Signed-off-by: Pablo Chico de Guzman pchico83@gmail.com
Fixes #907