@@ -39,6 +39,7 @@ import (
39
39
"github.com/cloudnative-pg/cloudnative-pg/pkg/certs"
40
40
"github.com/cloudnative-pg/cloudnative-pg/pkg/management/log"
41
41
"github.com/cloudnative-pg/cloudnative-pg/pkg/postgres"
42
+ "github.com/cloudnative-pg/cloudnative-pg/pkg/resources"
42
43
"github.com/cloudnative-pg/cloudnative-pg/pkg/specs"
43
44
"github.com/cloudnative-pg/cloudnative-pg/pkg/utils"
44
45
"github.com/cloudnative-pg/cloudnative-pg/pkg/versions"
@@ -179,7 +180,7 @@ func (r *ClusterReconciler) reconcileSuperuserSecret(ctx context.Context, cluste
179
180
postgresPassword )
180
181
SetClusterOwnerAnnotationsAndLabels (& postgresSecret .ObjectMeta , cluster )
181
182
182
- if err := r . Create (ctx , postgresSecret ); err != nil {
183
+ if err := resources . CreateIfNotFound (ctx , r . Client , postgresSecret ); err != nil {
183
184
if ! apierrs .IsAlreadyExists (err ) {
184
185
return err
185
186
}
@@ -223,7 +224,7 @@ func (r *ClusterReconciler) reconcileAppUserSecret(ctx context.Context, cluster
223
224
appPassword )
224
225
225
226
SetClusterOwnerAnnotationsAndLabels (& appSecret .ObjectMeta , cluster )
226
- if err := r . Create (ctx , appSecret ); err != nil {
227
+ if err := resources . CreateIfNotFound (ctx , r . Client , appSecret ); err != nil {
227
228
if ! apierrs .IsAlreadyExists (err ) {
228
229
return err
229
230
}
@@ -273,7 +274,7 @@ func (r *ClusterReconciler) createPostgresServices(ctx context.Context, cluster
273
274
anyService := specs .CreateClusterAnyService (* cluster )
274
275
SetClusterOwnerAnnotationsAndLabels (& anyService .ObjectMeta , cluster )
275
276
276
- if err := r . Create (ctx , anyService ); err != nil {
277
+ if err := resources . CreateIfNotFound (ctx , r . Client , anyService ); err != nil {
277
278
if ! apierrs .IsAlreadyExists (err ) {
278
279
return err
279
280
}
@@ -282,7 +283,7 @@ func (r *ClusterReconciler) createPostgresServices(ctx context.Context, cluster
282
283
readService := specs .CreateClusterReadService (* cluster )
283
284
SetClusterOwnerAnnotationsAndLabels (& readService .ObjectMeta , cluster )
284
285
285
- if err := r . Create (ctx , readService ); err != nil {
286
+ if err := resources . CreateIfNotFound (ctx , r . Client , readService ); err != nil {
286
287
if ! apierrs .IsAlreadyExists (err ) {
287
288
return err
288
289
}
@@ -291,7 +292,7 @@ func (r *ClusterReconciler) createPostgresServices(ctx context.Context, cluster
291
292
readOnlyService := specs .CreateClusterReadOnlyService (* cluster )
292
293
SetClusterOwnerAnnotationsAndLabels (& readOnlyService .ObjectMeta , cluster )
293
294
294
- if err := r . Create (ctx , readOnlyService ); err != nil {
295
+ if err := resources . CreateIfNotFound (ctx , r . Client , readOnlyService ); err != nil {
295
296
if ! apierrs .IsAlreadyExists (err ) {
296
297
return err
297
298
}
@@ -300,7 +301,7 @@ func (r *ClusterReconciler) createPostgresServices(ctx context.Context, cluster
300
301
readWriteService := specs .CreateClusterReadWriteService (* cluster )
301
302
SetClusterOwnerAnnotationsAndLabels (& readWriteService .ObjectMeta , cluster )
302
303
303
- if err := r . Create (ctx , readWriteService ); err != nil {
304
+ if err := resources . CreateIfNotFound (ctx , r . Client , readWriteService ); err != nil {
304
305
if ! apierrs .IsAlreadyExists (err ) {
305
306
return err
306
307
}
0 commit comments