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

Implement kubernetes_service registration and startup #4611

Merged
merged 2 commits into from
Oct 30, 2020

Conversation

awly
Copy link
Contributor

@awly awly commented Oct 21, 2020

The new service now starts, registers (locally or via a join token) and
heartbeats its presence to the auth server.

This service can handle k8s requests (like a proxy) but not to remote
teleport clusters. Proxies will be responsible for routing those.
The client (kubectl after tsh configures is) will not yet reach this service automatically, until proxy routing is
implemented. I manually tweaked server addres in kubeconfig to test it.

You can also run tctl get kube_service to list all registered
instances. The reported info is currently limited - only listening
address is set.

Existing k8s functionality in the proxy is not affected.

Updates #3952

@awly awly changed the title Implement kubernetes_service registration and sratup Implement kubernetes_service registration and startup Oct 21, 2020
@awly awly force-pushed the andrew/kubernetes_service_core branch from da90a79 to a1f2b4d Compare October 22, 2020 17:43
@awly awly force-pushed the andrew/kubernetes_service_core branch 2 times, most recently from 79e595a to 40be491 Compare October 26, 2020 16:15
lib/auth/auth_with_roles.go Show resolved Hide resolved
lib/config/configuration.go Show resolved Hide resolved
lib/config/fileconf.go Outdated Show resolved Hide resolved
if s.Configured() {
return !s.Enabled(def)
}
return !def
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, may be just me but it's a bit confusing - so the passed value def is in fact not the default but the inverse of the default? I.e. Disabled(true) will in fact return false if the service is not configured and vice versa?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is more than a little confusing to me too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is confusing.
def specifies whether a given service is enabled by default in teleport, not the default return value for this method if service isn't configured.

Changed this to set the default value as a field in Service. Hopefully it's less confusing.

From: &c.remoteAddr,
To: &utils.NetAddr{AddrNetwork: "tcp", Addr: c.targetAddr},
})
func (c *tpClusterClient) Dial(network, addr string) (net.Conn, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Missing godocs on Dial and DialWithContext.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these methods are on an unexported struct and won't appear in godoc output.

lib/kube/proxy/forwarder.go Outdated Show resolved Hide resolved
lib/service/kubernetes.go Outdated Show resolved Hide resolved
if s.Configured() {
return !s.Enabled(def)
}
return !def
Copy link
Contributor

Choose a reason for hiding this comment

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

This is more than a little confusing to me too.

lib/service/service.go Show resolved Hide resolved
@awly awly force-pushed the andrew/kubernetes_service_core branch from 40be491 to 3e486ee Compare October 28, 2020 21:59
@awly awly requested a review from a-palchikov as a code owner October 28, 2020 21:59
@awly awly force-pushed the andrew/kubernetes_service_core branch 2 times, most recently from 4e81998 to 258c282 Compare October 28, 2020 22:17
@awly awly requested review from r0mant and webvictim October 28, 2020 22:24
lib/auth/permissions.go Outdated Show resolved Hide resolved
c.Assert(conf.Proxy.WebAddr, check.Equals, "tcp://web_addr")
c.Assert(conf.Proxy.TunAddr, check.Equals, "reverse_tunnel_address:3311")
conf, err = ReadFromFile(testConfigs.configFile)
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered asserting the value as a whole instead of individual attributes?
I'm not too familiar with the require package and not sure how one goes about that but it is generally less verbose and more consistent since it avoids unexpected changes to attributes that aren't validated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I was too lazy when refactoring this test the first time.
Changed to do a full struct compare, plus testing the Service helpers

lib/config/fileconf.go Outdated Show resolved Hide resolved
// Only attempt to connect through the proxy for nodes.
if identity.ID.Role != teleport.RoleNode {
// Don't attempt to connect through a tunnel as a proxy or auth server.
if identity.ID.Role == teleport.RoleAuth || identity.ID.Role == teleport.RoleProxy {
return nil, trace.Unwrap(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I've never seen the error being actually unwrapped on return and just wanted to make sure it is intentional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this looks like a typo.
If it's not, there should've been a comment explaining it.
Changed to trace.Wrap

lib/service/kubernetes.go Outdated Show resolved Hide resolved
lib/service/kubernetes.go Outdated Show resolved Hide resolved
@awly awly force-pushed the andrew/kubernetes_service_core branch from 258c282 to 6b035f6 Compare October 29, 2020 16:59
@awly awly requested a review from a-palchikov October 29, 2020 17:00
Copy link
Contributor

@a-palchikov a-palchikov left a comment

Choose a reason for hiding this comment

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

lgtm although I'd need more time for it to sink in in terms of the bigger picture.

lib/auth/apiserver.go Show resolved Hide resolved
lib/cache/cache.go Show resolved Hide resolved
lib/service/kubernetes.go Outdated Show resolved Hide resolved
lib/service/kubernetes.go Outdated Show resolved Hide resolved
Andrew Lytvynov added 2 commits October 30, 2020 09:54
The new service now starts, registers (locally or via a join token) and
heartbeats its presence to the auth server.

This service can handle k8s requests (like a proxy) but not to remote
teleport clusters. Proxies will be responsible for routing those.
The client (tsh) will not yet go to this service, until proxy routing is
implemented. I manually tweaked server addres in kubeconfig to test it.

You can also run `tctl get kube_service` to list all registered
instances. The self-reported info is currently limited - only listening
address is set.
@awly awly force-pushed the andrew/kubernetes_service_core branch from 6b035f6 to 7a52a6d Compare October 30, 2020 17:01
@awly awly merged commit 5ec194c into master Oct 30, 2020
@awly awly deleted the andrew/kubernetes_service_core branch October 30, 2020 17:19
if payload != nil {
// Graceful shutdown.
warnOnErr(kubeServer.Shutdown(payloadContext(payload)))
agentPool.Stop()
Copy link
Collaborator

Choose a reason for hiding this comment

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

@awly Just noticed something in this old PR as I'm working on a similar part in db access. Looks like in case of direct dial (!conn.UseTunnel() case above), agentPool will stay uninitialized so these stop/wait calls will probably panic in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

4 participants