Generate CRDs with controller-gen instead
This commit is contained in:
@@ -15,7 +15,6 @@ import (
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
monov1alpha1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
|
||||
"example.com/monok8s/pkg/crds"
|
||||
"example.com/monok8s/pkg/kube"
|
||||
templates "example.com/monok8s/pkg/templates"
|
||||
)
|
||||
@@ -27,48 +26,6 @@ const (
|
||||
kubeconfig = "/etc/kubernetes/admin.conf"
|
||||
)
|
||||
|
||||
func ApplyCRDs(ctx context.Context, n *NodeContext) error {
|
||||
if n.Config.Spec.ClusterRole != "control-plane" {
|
||||
return nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func ApplyControlAgentDaemonSetResources(ctx context.Context, n *NodeContext) error {
|
||||
// Only the control-plane should bootstrap this DaemonSet definition.
|
||||
// And only when the feature is enabled.
|
||||
|
||||
Reference in New Issue
Block a user