From 44acd7e4dbb5fb79b3ce83e357dc29ac4855e729 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Fri, 14 Jun 2019 15:08:29 +0100 Subject: [PATCH] Not being able to register CRD is not a fatal error (#444) Operator proceeds to checking if CRD is present and ready, and if not, only then it is a fatal error. --- docs/reference/operator_parameters.md | 2 +- pkg/controller/util.go | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/reference/operator_parameters.md b/docs/reference/operator_parameters.md index 9c14b8669..c9a9db753 100644 --- a/docs/reference/operator_parameters.md +++ b/docs/reference/operator_parameters.md @@ -32,7 +32,7 @@ configuration. kubectl create -f manifests/postgresql-operator-default-configuration.yaml kubectl get operatorconfigurations postgresql-operator-default-configuration -o yaml ``` - Note that the operator first registers the CRD of the `OperatorConfiguration` + Note that the operator first attempts to register the CRD of the `OperatorConfiguration` and then waits for an instance to be created. In between these two event the operator pod may be failing since it cannot fetch the not-yet-existing `OperatorConfiguration` instance. diff --git a/pkg/controller/util.go b/pkg/controller/util.go index f9fc4468a..0adb85dbd 100644 --- a/pkg/controller/util.go +++ b/pkg/controller/util.go @@ -51,17 +51,18 @@ func (c *Controller) clusterWorkerID(clusterName spec.NamespacedName) uint32 { func (c *Controller) createOperatorCRD(crd *apiextv1beta1.CustomResourceDefinition) error { if _, err := c.KubeClient.CustomResourceDefinitions().Create(crd); err != nil { - if !k8sutil.ResourceAlreadyExists(err) { - return fmt.Errorf("could not create customResourceDefinition: %v", err) - } - c.logger.Infof("customResourceDefinition %q is already registered and will only be updated", crd.Name) + if k8sutil.ResourceAlreadyExists(err) { + c.logger.Infof("customResourceDefinition %q is already registered and will only be updated", crd.Name) - patch, err := json.Marshal(crd) - if err != nil { - return fmt.Errorf("could not marshal new customResourceDefintion: %v", err) - } - if _, err := c.KubeClient.CustomResourceDefinitions().Patch(crd.Name, types.MergePatchType, patch); err != nil { - return fmt.Errorf("could not update customResourceDefinition: %v", err) + patch, err := json.Marshal(crd) + if err != nil { + return fmt.Errorf("could not marshal new customResourceDefintion: %v", err) + } + if _, err := c.KubeClient.CustomResourceDefinitions().Patch(crd.Name, types.MergePatchType, patch); err != nil { + return fmt.Errorf("could not update customResourceDefinition: %v", err) + } + } else { + c.logger.Errorf("could not create customResourceDefinition %q: %v", crd.Name, err) } } else { c.logger.Infof("customResourceDefinition %q has been registered", crd.Name)