Skip to content

Commit 44acd7e

Browse files
redbaronsdudoladov
authored andcommitted
Not being able to register CRD is not a fatal error (zalando#444)
Operator proceeds to checking if CRD is present and ready, and if not, only then it is a fatal error.
1 parent e1d9395 commit 44acd7e

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

docs/reference/operator_parameters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ configuration.
3232
kubectl create -f manifests/postgresql-operator-default-configuration.yaml
3333
kubectl get operatorconfigurations postgresql-operator-default-configuration -o yaml
3434
```
35-
Note that the operator first registers the CRD of the `OperatorConfiguration`
35+
Note that the operator first attempts to register the CRD of the `OperatorConfiguration`
3636
and then waits for an instance to be created. In between these two event the
3737
operator pod may be failing since it cannot fetch the not-yet-existing
3838
`OperatorConfiguration` instance.

pkg/controller/util.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,18 @@ func (c *Controller) clusterWorkerID(clusterName spec.NamespacedName) uint32 {
5151

5252
func (c *Controller) createOperatorCRD(crd *apiextv1beta1.CustomResourceDefinition) error {
5353
if _, err := c.KubeClient.CustomResourceDefinitions().Create(crd); err != nil {
54-
if !k8sutil.ResourceAlreadyExists(err) {
55-
return fmt.Errorf("could not create customResourceDefinition: %v", err)
56-
}
57-
c.logger.Infof("customResourceDefinition %q is already registered and will only be updated", crd.Name)
54+
if k8sutil.ResourceAlreadyExists(err) {
55+
c.logger.Infof("customResourceDefinition %q is already registered and will only be updated", crd.Name)
5856

59-
patch, err := json.Marshal(crd)
60-
if err != nil {
61-
return fmt.Errorf("could not marshal new customResourceDefintion: %v", err)
62-
}
63-
if _, err := c.KubeClient.CustomResourceDefinitions().Patch(crd.Name, types.MergePatchType, patch); err != nil {
64-
return fmt.Errorf("could not update customResourceDefinition: %v", err)
57+
patch, err := json.Marshal(crd)
58+
if err != nil {
59+
return fmt.Errorf("could not marshal new customResourceDefintion: %v", err)
60+
}
61+
if _, err := c.KubeClient.CustomResourceDefinitions().Patch(crd.Name, types.MergePatchType, patch); err != nil {
62+
return fmt.Errorf("could not update customResourceDefinition: %v", err)
63+
}
64+
} else {
65+
c.logger.Errorf("could not create customResourceDefinition %q: %v", crd.Name, err)
6566
}
6667
} else {
6768
c.logger.Infof("customResourceDefinition %q has been registered", crd.Name)

0 commit comments

Comments
 (0)