Some basic agent startup

This commit is contained in:
2026-03-30 21:50:04 +08:00
parent fcf7371e9e
commit bdbc29649c
11 changed files with 98 additions and 48 deletions

View File

@@ -11,4 +11,5 @@ rc-update add fancontrol boot
rc-update add loopback boot rc-update add loopback boot
rc-update add hostname boot rc-update add hostname boot
rc-update add localmount boot rc-update add localmount boot
rc-update add bootstrap-cluster default rc-update add local default
# rc-update add ctl-agent default

View File

@@ -1,25 +0,0 @@
#!/sbin/openrc-run
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
name="Bootstrap the Cluster"
description="Runs the ctl init bootstrap sequence"
command="/usr/local/bin/ctl"
command_args="init --env-file /opt/monok8s/config/cluster.env"
LOG_DIR="/var/log/monok8s"
LOG_FILE="$LOG_DIR/bootstrap-cluster.log"
depend() {
need localmount
}
start() {
checkpath --directory "$LOG_DIR"
ebegin "Starting the bootstrap sequence"
start-stop-daemon --start \
--exec "$command" \
-- $command_args >>"$LOG_FILE" 2>&1
eend $?
}

View File

@@ -0,0 +1,58 @@
#!/sbin/openrc-run
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
name="monok8s-control-agent"
description="System Control Agent (OSUpgrade controller)"
supervisor=supervise-daemon
command="/usr/local/bin/ctl"
command_args="agent --env-file /opt/monok8s/config/cluster.env"
command_user="root:root"
pidfile="/run/${RC_SVCNAME}.pid"
output_log="/var/log/monok8s/agent.log"
error_log="/var/log/monok8s/agent.log"
retry="TERM/10/KILL/5"
depend() {
need localmount
after net
}
start_pre() {
checkpath --directory /run
checkpath --directory /var/log/monok8s
if [ ! -f /opt/monok8s/config/cluster.env ]; then
eerror "Missing env file: /opt/monok8s/config/cluster.env"
return 1
fi
}
start() {
ebegin "Starting monok8s control agent"
supervise-daemon "$RC_SVCNAME" \
--start \
--pidfile "$pidfile" \
--stdout "$output_log" \
--stderr "$error_log" \
--respawn \
--respawn-delay 5 \
--respawn-max 0 \
-- \
$command $command_args
eend $?
}
stop() {
ebegin "Stopping monok8s control agent"
supervise-daemon "$RC_SVCNAME" \
--stop \
--pidfile "$pidfile"
eend $?
}

View File

@@ -0,0 +1,4 @@
#!/bin/sh
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
/usr/local/bin/ctl init --env-file /opt/monok8s/config/cluster.env >>/var/log/monok8s/bootstrap.log 2>&1 &

View File

@@ -38,6 +38,7 @@ func NewRegistry(ctx *node.NodeContext) *Registry {
"RunKubeadmUpgradeApply": node.RunKubeadmUpgradeApply, "RunKubeadmUpgradeApply": node.RunKubeadmUpgradeApply,
"RunKubeadmUpgradeNode": node.RunKubeadmUpgradeNode, "RunKubeadmUpgradeNode": node.RunKubeadmUpgradeNode,
"StartCRIO": node.StartCRIO, "StartCRIO": node.StartCRIO,
"StartControlAgent": node.StartControlAgent,
"ValidateNodeIPAndAPIServerReachability": node.ValidateNodeIPAndAPIServerReachability, "ValidateNodeIPAndAPIServerReachability": node.ValidateNodeIPAndAPIServerReachability,
"ValidateRequiredImagesPresent": node.ValidateRequiredImagesPresent, "ValidateRequiredImagesPresent": node.ValidateRequiredImagesPresent,
"WaitForExistingClusterIfNeeded": node.WaitForExistingClusterIfNeeded, "WaitForExistingClusterIfNeeded": node.WaitForExistingClusterIfNeeded,
@@ -45,14 +46,6 @@ func NewRegistry(ctx *node.NodeContext) *Registry {
} }
} }
func (r *Registry) MustGet(name string) node.Step {
step, ok := r.steps[name]
if !ok {
panic(fmt.Sprintf("unknown step %q", name))
}
return step
}
func (r *Registry) Get(name string) (node.Step, error) { func (r *Registry) Get(name string) (node.Step, error) {
step, ok := r.steps[name] step, ok := r.steps[name]
if !ok { if !ok {

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"k8s.io/klog/v2"
monov1alpha1 "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1" monov1alpha1 "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
"undecided.project/monok8s/pkg/node" "undecided.project/monok8s/pkg/node"
"undecided.project/monok8s/pkg/system" "undecided.project/monok8s/pkg/system"
@@ -131,6 +132,11 @@ func NewRunner(cfg *monov1alpha1.MonoKSConfig) *Runner {
Name: "Apply node metadata", Name: "Apply node metadata",
Desc: "Apply labels/annotations to the local node if API server is reachable", Desc: "Apply labels/annotations to the local node if API server is reachable",
}, },
{
RegKey: "StartControlAgent",
Name: "Starts the Control Agent",
Desc: "Handles OSUpgrade resources polling",
},
}, },
} }
} }
@@ -153,6 +159,7 @@ func (r *Runner) Init(ctx context.Context) error {
return fmt.Errorf("step %d (%s): %w", i+1, step.Name, err) return fmt.Errorf("step %d (%s): %w", i+1, step.Name, err)
} }
} }
klog.Info("All steps completed successfully")
return nil return nil
} }

View File

@@ -5,19 +5,19 @@ import (
"fmt" "fmt"
"time" "time"
monov1alpha1 "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
"undecided.project/monok8s/pkg/kube"
"github.com/spf13/cobra" "github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/klog/v2" "k8s.io/klog/v2"
monov1alpha1 "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
"undecided.project/monok8s/pkg/kube"
) )
func NewCmdAgent(flags *genericclioptions.ConfigFlags) *cobra.Command { func NewCmdAgent(flags *genericclioptions.ConfigFlags) *cobra.Command {
var namespace string var namespace string
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "agent", Use: "agent --env-file path",
Short: "Watch OSUpgrade resources and do nothing for now", Short: "Watch OSUpgrade resources and do nothing for now",
RunE: func(cmd *cobra.Command, _ []string) error { RunE: func(cmd *cobra.Command, _ []string) error {
clients, err := kube.NewClients(flags) clients, err := kube.NewClients(flags)

View File

@@ -81,6 +81,7 @@ Supported formats:
rendered := templates.DefaultMonoKSConfig(vals) rendered := templates.DefaultMonoKSConfig(vals)
cfg = &rendered cfg = &rendered
klog.InfoS("starting init", "node", cfg.Spec.NodeName, "envFile", envFile)
default: default:
path, err := (config.Loader{}).ResolvePath(configPath) path, err := (config.Loader{}).ResolvePath(configPath)
if err != nil { if err != nil {
@@ -92,7 +93,7 @@ Supported formats:
return err return err
} }
cfg = loaded cfg = loaded
klog.InfoS("starting init", "config", path, "node", cfg.Spec.NodeName, "envFile", envFile) klog.InfoS("starting init", "node", cfg.Spec.NodeName, "config", path)
} }
runner := bootstrap.NewRunner(cfg) runner := bootstrap.NewRunner(cfg)

View File

@@ -0,0 +1,11 @@
package node
import (
"context"
system "undecided.project/monok8s/pkg/system"
)
func StartControlAgent(ctx context.Context, n *NodeContext) error {
return system.EnsureServiceRunning(ctx, n.SystemRunner, "control-agent")
}

View File

@@ -429,7 +429,7 @@ func ValidateRequiredImagesPresent(ctx context.Context, n *NodeContext) error {
missing = append(missing, img) missing = append(missing, img)
continue continue
} }
klog.Infof("found image: %s", img) klog.V(4).Infof("found image: %s", img)
} }
if len(missing) > 0 { if len(missing) > 0 {

View File

@@ -5,7 +5,7 @@ MKS_NODE_NAME=monok8s-master
# RJ45 Ports from left to right (interface name inside the OS) # RJ45 Ports from left to right (interface name inside the OS)
# - eth1, eth2, eth0 # - eth1, eth2, eth0
MKS_MGMT_IFACE=eth1 MKS_MGMT_IFACE=eth1
MKS_MGMT_ADDRESS=10.0.0.14/24 MKS_MGMT_ADDRESS=10.0.0.10/24
MKS_MGMT_GATEWAY=10.0.0.1 MKS_MGMT_GATEWAY=10.0.0.1
# Space-separated real upstream DNS servers. # Space-separated real upstream DNS servers.
@@ -16,8 +16,9 @@ MKS_DNS_NAMESERVERS="10.0.0.1 1.1.1.1 1.0.0.1"
MKS_DNS_SEARCH_DOMAINS="lan" MKS_DNS_SEARCH_DOMAINS="lan"
## k8s config ## k8s config
MKS_KUBERNETES_VERSION=v1.35.3 # Do not set this yourself, this auto follows the build version
MKS_APISERVER_ADVERTISE_ADDRESS=10.0.0.14 # DEV_ONLY MKS_KUBERNETES_VERSION=v1.35.1
MKS_APISERVER_ADVERTISE_ADDRESS=10.0.0.10
# Optional but strongly recommended # Optional but strongly recommended
MKS_CLUSTER_NAME=monok8s MKS_CLUSTER_NAME=monok8s
@@ -25,11 +26,10 @@ MKS_POD_SUBNET=10.244.0.0/16
MKS_SERVICE_SUBNET=10.96.0.0/12 MKS_SERVICE_SUBNET=10.96.0.0/12
MKS_CLUSTER_DOMAIN=cluster.local MKS_CLUSTER_DOMAIN=cluster.local
# Bootstrap mode: init, join # control-plane, worker
MKS_BOOTSTRAP_MODE=init MKS_CLUSTER_ROLE=control-plane
MKS_INIT_CONTROL_PLANE=yes
# For join mode: worker, control-plane
MKS_JOIN_KIND=worker
MKS_API_SERVER_ENDPOINT= MKS_API_SERVER_ENDPOINT=
MKS_BOOTSTRAP_TOKEN= MKS_BOOTSTRAP_TOKEN=
MKS_DISCOVERY_TOKEN_CA_CERT_HASH= MKS_DISCOVERY_TOKEN_CA_CERT_HASH=
@@ -46,7 +46,7 @@ MKS_NODE_ANNOTATIONS=mono.si/board=ls1046a,mono.si/image-version=dev
# Optional # Optional
# Extra API server SANs, comma-separated # Extra API server SANs, comma-separated
MKS_SANS=127.0.0.1,localhost,monok8s-master,10.0.0.14 MKS_SANS=127.0.0.1,localhost,monok8s-master,10.0.0.10
# CRI-O socket # CRI-O socket
MKS_CONTAINER_RUNTIME_ENDPOINT=unix:///var/run/crio/crio.sock MKS_CONTAINER_RUNTIME_ENDPOINT=unix:///var/run/crio/crio.sock