change CRD creation strategy
This commit is contained in:
parent
66128c2bfc
commit
6ce84147c1
|
|
@ -54,8 +54,16 @@ func (c *Controller) clusterWorkerID(clusterName spec.NamespacedName) uint32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) createOperatorCRD(desiredCrd *apiextv1.CustomResourceDefinition) error {
|
func (c *Controller) createOperatorCRD(desiredCrd *apiextv1.CustomResourceDefinition) error {
|
||||||
if crd, err := c.KubeClient.CustomResourceDefinitions().Create(context.TODO(), desiredCrd, metav1.CreateOptions{}); err != nil {
|
crd, err := c.KubeClient.CustomResourceDefinitions().Get(context.TODO(), desiredCrd.Name, metav1.GetOptions{})
|
||||||
if k8sutil.ResourceAlreadyExists(err) {
|
if k8sutil.ResourceNotFound(err) {
|
||||||
|
if _, err := c.KubeClient.CustomResourceDefinitions().Create(context.TODO(), desiredCrd, metav1.CreateOptions{}); err != nil {
|
||||||
|
return fmt.Errorf("could not create customResourceDefinition %q: %v", desiredCrd.Name, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
c.logger.Errorf("could not get customResourceDefinition %q: %v", desiredCrd.Name, err)
|
||||||
|
}
|
||||||
|
if crd != nil {
|
||||||
c.logger.Infof("customResourceDefinition %q is already registered and will only be updated", crd.Name)
|
c.logger.Infof("customResourceDefinition %q is already registered and will only be updated", crd.Name)
|
||||||
// copy annotations and labels from existing CRD since we do not define them
|
// copy annotations and labels from existing CRD since we do not define them
|
||||||
desiredCrd.Annotations = crd.Annotations
|
desiredCrd.Annotations = crd.Annotations
|
||||||
|
|
@ -68,9 +76,6 @@ func (c *Controller) createOperatorCRD(desiredCrd *apiextv1.CustomResourceDefini
|
||||||
context.TODO(), crd.Name, types.MergePatchType, patch, metav1.PatchOptions{}); err != nil {
|
context.TODO(), crd.Name, types.MergePatchType, patch, metav1.PatchOptions{}); err != nil {
|
||||||
return fmt.Errorf("could not update customResourceDefinition %q: %v", crd.Name, err)
|
return fmt.Errorf("could not update customResourceDefinition %q: %v", crd.Name, err)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
c.logger.Errorf("could not create customResourceDefinition %q: %v", desiredCrd.Name, err)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
c.logger.Infof("customResourceDefinition %q has been registered", crd.Name)
|
c.logger.Infof("customResourceDefinition %q has been registered", crd.Name)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue