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

virtual-kubelet controller integration #130

Merged
merged 15 commits into from
Oct 21, 2024

Conversation

galal-hussein
Copy link
Collaborator

@galal-hussein galal-hussein commented Oct 15, 2024

The PR does the following:

  • Convert the Agent structure into an interface which has two different implementations:
    • virtual mode: which is the original k3k mode in which the agent will run in a pod
    • shared mode: where the controller will run a virtual kubelet implementation that allows running workloads on the host
  • Restructure the virtual-kubelet implementation:
    • Added a cli implementation
    • Added a config file to be parsed on the start of the program
    • Added a kubelet package where the actual registration/start of the node happens
  • Add the virtual-kubelet (k3k-kubelet) image into the release workflow
    Issue:
  • Virtual Kubelet: Controller Integration #122

Signed-off-by: galal-hussein <[email protected]>
k3k-kubelet/main.go Outdated Show resolved Hide resolved
.github/workflows/release.yml Outdated Show resolved Hide resolved
k3k-kubelet/config.go Outdated Show resolved Hide resolved
pkg/controller/cluster/agent/shared.go Outdated Show resolved Hide resolved
k3k-kubelet/kubelet.go Outdated Show resolved Hide resolved
k3k-kubelet/kubelet.go Outdated Show resolved Hide resolved
k3k-kubelet/main.go Outdated Show resolved Hide resolved
k3k-kubelet/main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
k3k-kubelet/kubelet.go Outdated Show resolved Hide resolved
k3k-kubelet/kubelet.go Outdated Show resolved Hide resolved
k3k-kubelet/kubelet.go Outdated Show resolved Hide resolved
k3k-kubelet/kubelet.go Outdated Show resolved Hide resolved
k3k-kubelet/kubelet.go Outdated Show resolved Hide resolved
k3k-kubelet/kubelet.go Outdated Show resolved Hide resolved
k3k-kubelet/kubelet.go Outdated Show resolved Hide resolved
k3k-kubelet/kubelet.go Outdated Show resolved Hide resolved
k3k-kubelet/kubelet.go Outdated Show resolved Hide resolved
k3k-kubelet/kubelet.go Outdated Show resolved Hide resolved
return nil, fmt.Errorf("unable to create certs: %w", err)
}
pool := x509.NewCertPool()
pool.AddCert(certs[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do a bounds check here to be safe?

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the resolution for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sorry missed this one, adding a check now

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added a check for the length of the certs after this line

Signed-off-by: galal-hussein <[email protected]>
Signed-off-by: galal-hussein <[email protected]>
Signed-off-by: galal-hussein <[email protected]>
Signed-off-by: galal-hussein <[email protected]>
Copy link
Contributor

@MbolotSuse MbolotSuse left a comment

Choose a reason for hiding this comment

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

No major concerns, thanks for all the work on this PR.

Comment on lines +22 to +51
func (c *config) unmarshalYAML(data []byte) error {
var conf config

if err := yaml.Unmarshal(data, &conf); err != nil {
return err
}

if c.ClusterName == "" {
c.ClusterName = conf.ClusterName
}
if c.ClusterNamespace == "" {
c.ClusterNamespace = conf.ClusterNamespace
}
if c.HostConfigPath == "" {
c.HostConfigPath = conf.HostConfigPath
}
if c.VirtualConfigPath == "" {
c.VirtualConfigPath = conf.VirtualConfigPath
}
if c.KubeletPort == "" {
c.KubeletPort = conf.KubeletPort
}
if c.AgentHostname == "" {
c.AgentHostname = conf.AgentHostname
}
if c.NodeName == "" {
c.NodeName = conf.NodeName
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: to avoid copying over the fields (which will get worse over time as we add more fields), you can instead change the method to just return the config:

Suggested change
func (c *config) unmarshalYAML(data []byte) error {
var conf config
if err := yaml.Unmarshal(data, &conf); err != nil {
return err
}
if c.ClusterName == "" {
c.ClusterName = conf.ClusterName
}
if c.ClusterNamespace == "" {
c.ClusterNamespace = conf.ClusterNamespace
}
if c.HostConfigPath == "" {
c.HostConfigPath = conf.HostConfigPath
}
if c.VirtualConfigPath == "" {
c.VirtualConfigPath = conf.VirtualConfigPath
}
if c.KubeletPort == "" {
c.KubeletPort = conf.KubeletPort
}
if c.AgentHostname == "" {
c.AgentHostname = conf.AgentHostname
}
if c.NodeName == "" {
c.NodeName = conf.NodeName
}
return nil
}
func unmarshalYAML(data []byte) (*config, error) {
var conf config
err := yaml.Unmarshal(data, &conf)
return &conf, err

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the problem is that we want the user to be able to mix and match for example, the user can set the --agent-hostname as a flag and at the same time add nodeName in the config file, if we just returned the unmarshalled config it will ignore all the flags sat on the command line

@galal-hussein galal-hussein merged commit d19f0f9 into rancher:main Oct 21, 2024
1 check passed
briandowns pushed a commit to briandowns/k3k that referenced this pull request Dec 4, 2024
* Virtual kubelet controller integration

Signed-off-by: galal-hussein <[email protected]>

* Add k3k-kubelet image to the release workflow

Signed-off-by: galal-hussein <[email protected]>

* Add k3k-kubelet image to the release workflow

Signed-off-by: galal-hussein <[email protected]>

* Fix build/release workflow

Signed-off-by: galal-hussein <[email protected]>

* Remove pkg directory in k3k-kubelet

Signed-off-by: galal-hussein <[email protected]>

* rename Type to Config

Signed-off-by: galal-hussein <[email protected]>

* Move the kubelet and config outside of pkg

Signed-off-by: galal-hussein <[email protected]>

* fix comments

Signed-off-by: galal-hussein <[email protected]>

* Fix naming throughout the package

Signed-off-by: galal-hussein <[email protected]>

* Fix comments

Signed-off-by: galal-hussein <[email protected]>

* more fixes to naming

Signed-off-by: galal-hussein <[email protected]>

* fixes

Signed-off-by: galal-hussein <[email protected]>

* fixes

Signed-off-by: galal-hussein <[email protected]>

* fixes

Signed-off-by: galal-hussein <[email protected]>

* fixes

Signed-off-by: galal-hussein <[email protected]>

---------

Signed-off-by: galal-hussein <[email protected]>
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.

3 participants