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

Added sshd, kubeconfig and insecure-serving flags to localkube for di… #1975

Merged
merged 1 commit into from
Sep 29, 2017

Conversation

aaron-prindle
Copy link
Contributor

…nd image

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 18, 2017
APIServerName: constants.APIServerName,
ShouldGenerateKubeconfig: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this default to false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

RUN sed -i 's|authorized_keys|authorized_keys /etc/localkube-ssh/localkube_rsa.pub|g' /etc/ssh/sshd_config

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
Copy link
Contributor

Choose a reason for hiding this comment

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

What do these two lines do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

--extra-config=kubelet.AllowPrivileged="true"
--extra-config=kubelet.AllowPrivileged="true" \
--v=100 \
--logtostderr &> /var/log/localkube/logs.txt
Copy link
Contributor

Choose a reason for hiding this comment

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

newline

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done. Also added auto-newline setting to editor, hopefully this will be the last newline comment

Copy link
Contributor

Choose a reason for hiding this comment

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

theres a vs-code addon if you haven't gotten it 😂

@@ -62,7 +69,11 @@ func StartProxyServer(lk LocalkubeServer) func() error {

return func() error {
// Creating this config requires the API Server to be up, so do it in the start function itself.
server, err := kubeproxy.NewProxyServer(config, false, runtime.NewScheme(), "")
url := ""
Copy link
Contributor

Choose a reason for hiding this comment

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

use var url string instead

server, err := kubeproxy.NewProxyServer(config, false, runtime.NewScheme(), "")
url := ""
if lk.APIServerInsecurePort != 0 {
url = lk.GetAPIServerInsecureURL()
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this function just return "" if lk.APIServerInsecurePort == 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you mean. If insecureport is enabled, use that url as the parameter as was done previously. If not, do what is done currently and use "".
https://github.com/kubernetes/minikube/blob/master/pkg/localkube/proxy.go#L65

Are you suggesting to flip the case so that the url defaults to the insecureURL and then reverse the if statement so that it would set it oppositely? I don't understand what is gained.

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant

func (lk LocalkubeServer) GetAPIServerInsecureURL() {
  if lk.APIServerInsecurePort != 0 {
    	return fmt.Sprintf("http://%s:%d", lk.APIServerInsecureAddress.String(), lk.APIServerInsecurePort)
  }
  return ""
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Otherwise, you might end up calling GetAPIServerInsecureURL() with lk.APIServerInsecurePort == 0 and get

http://:0

It might as well give the default value of the return type instead of garbage, that way you can use it how you want to here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -27,7 +27,26 @@ import (

type HealthCheck func() bool

func healthCheck(addr string, lk LocalkubeServer) HealthCheck {
func healthCheckInsecure(addr string, lk LocalkubeServer) HealthCheck {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you refactor this to be more like

func healthCheck(addr, lk LocalkubeServer) {
   transport := lk.GetTransport()
   client := http.Client{Transport: transport}
   ...
}

lk.GetTransport() will return a new http.Transport with the TLSconfig set if it is secure serving, otherwise just a http.Transport{} if not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -38,6 +40,11 @@ func (lk LocalkubeServer) NewProxyServer() Server {
}

func StartProxyServer(lk LocalkubeServer) func() error {
fmt.Println(lk.APIServerAddress)
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

hostport := net.JoinHostPort("localhost", strconv.Itoa(lk.APIServerPort))
addr := "https://" + path.Join(hostport, "healthz")
return healthCheck(addr, lk)
if lk.APIServerInsecurePort != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

see comments below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to only have one invocation of healtCheck

fmt.Println(lk.APIServerAddress)
bindaddress := lk.APIServerAddress.String()
if lk.APIServerInsecurePort != 0 {
bindaddress = lk.APIServerInsecureAddress.String()
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth it to split this out into another helper function where the logic is clearer:

If insecure serving and and secure serving are both enabled, the insecure serving address will be used as the bind address.

like

func (LocalkubeServer) GetAPIServerAddress() net.IP {
  ...
}

which you could use here, anywhere else that needs to know how to talk to the API server, and for the healthchecks

return healthCheck(addr, lk)
protocol := "https://"
if lk.APIServerInsecurePort != 0 {
protocol = "http://"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you generally want to stay away from constructions like

default value
if condition {
 overwrite default value
}

Here is another place where you're implicitly hiding the behavior of
"if both secure and insecure serving are enabled, use the insecure serving port"
which is a bit arbitrary and I'd like to minimize the amount of places that logic has to live, so its easy to change/maintain/notice

Copy link
Contributor

Choose a reason for hiding this comment

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

This could live in the GetTransport function - since if you're adding a TLSConfig, you know that you'll be using https

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -50,8 +50,8 @@ func healthCheck(addr string, lk LocalkubeServer) HealthCheck {
RootCAs: caCertPool,
}
tlsConfig.BuildNameToCertificate()
transport := &http.Transport{TLSClientConfig: tlsConfig}
client := &http.Client{Transport: transport}
transport := lk.GetTransport()
Copy link
Contributor

Choose a reason for hiding this comment

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

This function doesn't exist yet - you'll have to rip out the relevant parts from the existing healthCheck function

@codecov-io
Copy link

Codecov Report

Merging #1975 into master will decrease coverage by 0.21%.
The diff coverage is 20%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1975      +/-   ##
=========================================
- Coverage   29.81%   29.6%   -0.22%     
=========================================
  Files          77      77              
  Lines        4769    4810      +41     
=========================================
+ Hits         1422    1424       +2     
- Misses       3167    3204      +37     
- Partials      180     182       +2
Impacted Files Coverage Δ
pkg/localkube/apiserver.go 0% <0%> (ø) ⬆️
pkg/localkube/proxy.go 0% <0%> (ø) ⬆️
pkg/localkube/ready.go 48% <100%> (-5.85%) ⬇️
pkg/localkube/localkube.go 44.23% <20.75%> (-7.7%) ⬇️

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 9d0c80d...ec17df3. Read the comment docs.

Copy link
Contributor

@r2d4 r2d4 left a comment

Choose a reason for hiding this comment

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

once you remove the panic, LGTM

if s.ShouldGenerateKubeconfig {
if err := s.GenerateKubeconfig(); err != nil {
fmt.Println("Failed to create kubeconfig!")
panic(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

handle this error by logging it to glog and exiting

Copy link
Contributor Author

@aaron-prindle aaron-prindle Sep 29, 2017

Choose a reason for hiding this comment

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

sorry I didn't see this, merged the PR. ShouldGenerateCerts panics also. We should add a PR to change both of them.

@aaron-prindle
Copy link
Contributor Author

PTAL

@aaron-prindle aaron-prindle merged commit 7abee78 into kubernetes:master Sep 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants