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

OneKE: Apply node labels using context or user inputs #195

Open
Aletibazo opened this issue Feb 11, 2025 · 1 comment
Open

OneKE: Apply node labels using context or user inputs #195

Aletibazo opened this issue Feb 11, 2025 · 1 comment
Labels
category: oneke OpenNebula Kubernetes appliance type: feature A new feature planned for implementation

Comments

@Aletibazo
Copy link
Contributor

Having a way to apply labels to the k8s cluster using context attributes or user inputs would be a good addition, allowing to apply labels per role in the OneKE Flow Template. Related to this blog post. User in the blog post talks about doing so using VM Templates, but the correct approach may be adding the labels in the OneFlow Template instead.

@Aletibazo Aletibazo added category: oneke OpenNebula Kubernetes appliance type: feature A new feature planned for implementation labels Feb 11, 2025
@blackhelicopters
Copy link

Hey, thank you for opening this.
Currently I have this configuration in order to have different node-groups:

in the onke appliance kubernetes.rb amended the detect_node method:


def detect_node
    current_vm   = onegate_vm_show
    current_vmid = current_vm.dig 'VM', 'ID'
    current_role = current_vm.dig 'VM', 'USER_TEMPLATE', 'ROLE_NAME'

    ready = current_vm.dig('VM', 'USER_TEMPLATE', 'READY') == 'YES'

    master_vm   = master_vm_show
    master_vmid = master_vm.dig 'VM', 'ID'

    master_vm = wait_for_any_master if current_vmid != master_vmid

    token         = master_vm.dig 'VM', 'USER_TEMPLATE', 'ONEGATE_K8S_TOKEN'
    ready_to_join = !token.nil?

    msg :debug, "current_role: #{current_role}"

    results = {
        init_master:  !ready && current_role == 'master'  && current_vmid == master_vmid && !ready_to_join,
        join_master:  !ready && current_role == 'master'  && current_vmid != master_vmid && ready_to_join,
        join_worker:  !ready && !%w[storage master].include?(current_role)  && current_vmid != master_vmid && ready_to_join,
        join_storage: !ready && current_role == 'storage' && current_vmid != master_vmid && ready_to_join,
        start_server: current_role == 'master',
        start_agent:  current_role != 'master',
        token: token
    }

    msg :debug, "detect_node / #{results}"
    results
end

and amended join_worker method like this:

def join_worker(token)
    ipv4 = external_ipv4s.first

    current_vm   = onegate_vm_show
    current_role = current_vm.dig 'VM', 'USER_TEMPLATE', 'ROLE_NAME'
    name = "oneke-ip-#{ipv4.gsub '.', '-'}-#{current_role}"

    msg :info, "Set local hostname: #{name}"
    msg :info, "Worker role: #{current_role}"
    bash "hostnamectl set-hostname #{name}"

    onegate_vm_update ["ONEGATE_K8S_NODE_NAME=#{name}"]

    agent_config = {
        'node-name' => name,
        'server'    => "https://#{ONEAPP_RKE2_SUPERVISOR_EP}",
        'token'     => token
    }

    label_source = ENV['NODE_POOL'] || current_role
    if label_source
        agent_config['node-label'] = ["node_pool=#{label_source}"]
    end
    if label_source
        agent_config['node-label'] = ["node_pool=#{label_source}"]
    end

    msg :info, 'Prepare rke2-agent config'
    file '/etc/rancher/rke2/config.yaml', YAML.dump(agent_config), overwrite: true

    configure_rke2_proxy 'worker'

    msg :info, "Join worker: #{name}"
    bash 'systemctl enable rke2-agent.service --now'
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: oneke OpenNebula Kubernetes appliance type: feature A new feature planned for implementation
Projects
None yet
Development

No branches or pull requests

2 participants