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
Merged
11 changes: 10 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,23 @@ jobs:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}

- name: Build container image
- name: Build controller image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: rancher/k3k:${{ github.ref_name }}
file: package/Dockerfile
platforms: linux/amd64

- name: Build Virtual Kubelet image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: rancher/k3k:k3k-kubelet
galal-hussein marked this conversation as resolved.
Show resolved Hide resolved
file: package/Dockerfile.kubelet
platforms: linux/amd64



10 changes: 10 additions & 0 deletions charts/k3k/crds/k3k.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ spec:
description: NodeSelector is the node selector that will be applied
to all server/agent pods
type: object
mode:
description: Mode is the cluster provisioning mode which can be either
"virtual" or "shared". Defaults to "shared"
type: string
x-kubernetes-validations:
- message: mode is immutable
rule: self == oldSelf
- message: invalid value for mode
rule: self == "virtual" || self == "shared"
persistence:
description: |-
Persistence contains options controlling how the etcd data of the virtual cluster is persisted. By default, no data
Expand Down Expand Up @@ -191,6 +200,7 @@ spec:
type: string
required:
- agents
- mode
- servers
- token
- version
Expand Down
File renamed without changes.
72 changes: 72 additions & 0 deletions k3k-kubelet/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package main

import (
"errors"
"os"

"gopkg.in/yaml.v2"
)

// Config has all virtual-kubelet startup options
galal-hussein marked this conversation as resolved.
Show resolved Hide resolved
type config struct {
clusterName string `yaml:"clusterName"`
clusterNamespace string `yaml:"clusterNamespace"`
hostConfigPath string `yaml:"hostConfigPath"`
virtualConfigPath string `yaml:"virtualConfigPath"`
kubeletPort string `yaml:"kubeletPort"`
nodeName string `yaml:"nodeName"`
agentPodIP string `yaml:"agentPodIP"`
galal-hussein marked this conversation as resolved.
Show resolved Hide resolved
token string `yaml:"token"`
}

func (t *config) UnmarshalYAML(data []byte) error {
var c config
galal-hussein marked this conversation as resolved.
Show resolved Hide resolved
if err := yaml.Unmarshal(data, &c); err != nil {
return err
}
if t.clusterName == "" {
t.clusterName = c.clusterName
}
if t.clusterNamespace == "" {
t.clusterNamespace = c.clusterNamespace
}
if t.hostConfigPath == "" {
t.hostConfigPath = c.hostConfigPath
}
if t.virtualConfigPath == "" {
t.virtualConfigPath = c.virtualConfigPath
}
if t.kubeletPort == "" {
t.kubeletPort = c.kubeletPort
}
if t.nodeName == "" {
t.nodeName = c.nodeName
}

return nil
}

func (t *config) Validate() error {
if t.clusterName == "" {
return errors.New("cluster name is not provided")
}
if t.clusterNamespace == "" {
return errors.New("cluster namespace is not provided")
}
if t.agentPodIP == "" {
return errors.New("agent POD IP is not provided")
}
return nil
}

func (t *config) Parse(path string) error {
if _, err := os.Stat(path); os.IsNotExist(err) {
return nil
}

configFileBytes, err := os.ReadFile(path)
galal-hussein marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
return t.UnmarshalYAML(configFileBytes)
}
Loading