Ditch rc-service control-agent, use daemonset insteaad
This commit is contained in:
@@ -2,17 +2,56 @@ package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"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 StartControlAgent(ctx context.Context, n *NodeContext) error {
|
||||
err := ConfigureUBootCommands(ctx, n)
|
||||
if err == nil {
|
||||
return system.EnsureServiceRunning(ctx, n.SystemRunner, "control-agent")
|
||||
func ApplyCRDs(ctx context.Context, n *NodeContext) error {
|
||||
if n.Config.Spec.ClusterRole != "control-plane" {
|
||||
return nil
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user