Ditch rc-service control-agent, use daemonset insteaad
This commit is contained in:
@@ -12,4 +12,3 @@ 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 local default
|
rc-update add local default
|
||||||
# rc-update add ctl-agent default
|
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
#!/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-delay 5 \
|
|
||||||
--respawn-max 0 \
|
|
||||||
-- \
|
|
||||||
$command $command_args
|
|
||||||
eend $?
|
|
||||||
}
|
|
||||||
|
|
||||||
stop() {
|
|
||||||
ebegin "Stopping monok8s control agent"
|
|
||||||
supervise-daemon "$RC_SVCNAME" \
|
|
||||||
--stop \
|
|
||||||
--pidfile "$pidfile"
|
|
||||||
eend $?
|
|
||||||
}
|
|
||||||
@@ -39,7 +39,6 @@ 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,
|
||||||
|
|||||||
@@ -132,11 +132,6 @@ 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",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,15 @@ package kube
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
monov1alpha1 "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
|
|
||||||
apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
|
||||||
"k8s.io/client-go/dynamic"
|
|
||||||
kubernetes "k8s.io/client-go/kubernetes"
|
kubernetes "k8s.io/client-go/kubernetes"
|
||||||
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
||||||
|
monov1alpha1 "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
|
"k8s.io/client-go/dynamic"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -42,6 +43,12 @@ func NewClients(flags *genericclioptions.ConfigFlags) (*Clients, error) {
|
|||||||
return &Clients{Config: cfg, Kubernetes: kubeClient, Dynamic: dyn, APIExtensions: ext, RESTClientGetter: flags}, nil
|
return &Clients{Config: cfg, Kubernetes: kubeClient, Dynamic: dyn, APIExtensions: ext, RESTClientGetter: flags}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewClientsFromKubeconfig(kubeconfigPath string) (*Clients, error) {
|
||||||
|
flags := genericclioptions.NewConfigFlags(false)
|
||||||
|
flags.KubeConfig = &kubeconfigPath
|
||||||
|
return NewClients(flags)
|
||||||
|
}
|
||||||
|
|
||||||
func Scheme() *runtime.Scheme {
|
func Scheme() *runtime.Scheme {
|
||||||
scheme := runtime.NewScheme()
|
scheme := runtime.NewScheme()
|
||||||
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
|
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
|
||||||
|
|||||||
@@ -2,17 +2,56 @@ package node
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
system "undecided.project/monok8s/pkg/system"
|
|
||||||
|
"undecided.project/monok8s/pkg/crds"
|
||||||
|
"undecided.project/monok8s/pkg/kube"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cluster is fine without uboot commands, just no OSUpgrade agent
|
func ApplyCRDs(ctx context.Context, n *NodeContext) error {
|
||||||
func StartControlAgent(ctx context.Context, n *NodeContext) error {
|
if n.Config.Spec.ClusterRole != "control-plane" {
|
||||||
err := ConfigureUBootCommands(ctx, n)
|
return nil
|
||||||
if err == nil {
|
|
||||||
return system.EnsureServiceRunning(ctx, n.SystemRunner, "control-agent")
|
|
||||||
}
|
}
|
||||||
klog.Warningf("not starting agent due to uboot: %v", err)
|
|
||||||
|
const kubeconfig = "/etc/kubernetes/admin.conf"
|
||||||
|
|
||||||
|
clients, err := kube.NewClientsFromKubeconfig(kubeconfig)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("build kube clients from %s: %w", kubeconfig, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
crdClient := clients.APIExtensions.ApiextensionsV1().CustomResourceDefinitions()
|
||||||
|
|
||||||
|
for _, wanted := range crds.Definitions() {
|
||||||
|
_, err := crdClient.Create(ctx, wanted, metav1.CreateOptions{})
|
||||||
|
if err == nil {
|
||||||
|
klog.InfoS("crd created", "name", wanted.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !apierrors.IsAlreadyExists(err) {
|
||||||
|
return fmt.Errorf("create CRD %s: %w", wanted.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
current, getErr := crdClient.Get(ctx, wanted.Name, metav1.GetOptions{})
|
||||||
|
if getErr != nil {
|
||||||
|
return fmt.Errorf("get existing CRD %s: %w", wanted.Name, getErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
updated := wanted.DeepCopy()
|
||||||
|
updated.ResourceVersion = current.ResourceVersion
|
||||||
|
|
||||||
|
_, err = crdClient.Update(ctx, updated, metav1.UpdateOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("update CRD %s: %w", wanted.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
klog.InfoS("crd updated", "name", wanted.Name)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user