Skip to content

Commit 75ad043

Browse files
authored
Handle k8s resource conflict due to same CR names (#201)
* Check for pre-existed deployments and statefulsets not created by the controller * Code review comments * Code review updates * Update error message text * Code review updates * Update OperatorGroup namespace * Code review updates * Code review updates --------- Co-authored-by: Scott McClements <[email protected]>
1 parent 1268531 commit 75ad043

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

controllers/webspherelibertyapplication_controller.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,21 @@ func (r *ReconcileWebSphereLiberty) Reconcile(ctx context.Context, request ctrl.
140140
// Error reading the object - requeue the request.
141141
return reconcile.Result{}, err
142142
}
143+
144+
isKnativeSupported, err := r.IsGroupVersionSupported(servingv1.SchemeGroupVersion.String(), "Service")
145+
if err != nil {
146+
r.ManageError(err, common.StatusConditionTypeReconciled, instance)
147+
} else if !isKnativeSupported && instance.Spec.CreateKnativeService != nil && *instance.Spec.CreateKnativeService {
148+
reqLogger.V(1).Info(fmt.Sprintf("%s is not supported on the cluster", servingv1.SchemeGroupVersion.String()))
149+
}
150+
151+
// Check if there is an existing Deployment, Statefulset or Knative service by this name
152+
// not managed by this operator
153+
err = oputils.CheckForNameConflicts("WebSphereLibertyApplication", instance.Name, instance.Namespace, r.GetClient(), request, isKnativeSupported)
154+
if err != nil {
155+
return r.ManageError(err, common.StatusConditionTypeReconciled, instance)
156+
}
157+
143158
// Check if the WebSphereLibertyApplication instance is marked to be deleted, which is
144159
// indicated by the deletion timestamp being set.
145160
isInstanceMarkedToBeDeleted := instance.GetDeletionTimestamp() != nil
@@ -289,13 +304,6 @@ func (r *ReconcileWebSphereLiberty) Reconcile(ctx context.Context, request ctrl.
289304
}
290305
}
291306

292-
isKnativeSupported, err := r.IsGroupVersionSupported(servingv1.SchemeGroupVersion.String(), "Service")
293-
if err != nil {
294-
r.ManageError(err, common.StatusConditionTypeReconciled, instance)
295-
} else if !isKnativeSupported && instance.Spec.CreateKnativeService != nil && *instance.Spec.CreateKnativeService {
296-
reqLogger.V(1).Info(fmt.Sprintf("%s is not supported on the cluster", servingv1.SchemeGroupVersion.String()))
297-
}
298-
299307
if instance.Spec.CreateKnativeService != nil && *instance.Spec.CreateKnativeService {
300308
// Clean up non-Knative resources
301309
resources := []client.Object{

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/WASdev/websphere-liberty-operator
33
go 1.19
44

55
require (
6-
github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20230221145444-413ec4e4e2e8
6+
github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20230331211904-f635163c3ca2
77
github.com/go-logr/logr v1.2.2
88
github.com/openshift/api v0.0.0-20220414050251-a83e6f8f1d50 // Openshift 4.9
99
github.com/openshift/library-go v0.0.0-20220630204433-c71d40c7de49

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kd
7474
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210826220005-b48c857c3a0e/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
7575
github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20230221145444-413ec4e4e2e8 h1:TQoCfE4LBHdX4+Uy8NYfXdhccjvUuOcNSoNIDW2M7NM=
7676
github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20230221145444-413ec4e4e2e8/go.mod h1:4VWsptFxqCCiaEvAAp1ntOMTjTIUDbYHlRkeE4Aclo0=
77+
github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20230331211904-f635163c3ca2 h1:oJT1ea3w7dEptSPpEWWtWkO2JJbGQYHLdRMwSmw8qTE=
78+
github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20230331211904-f635163c3ca2/go.mod h1:4VWsptFxqCCiaEvAAp1ntOMTjTIUDbYHlRkeE4Aclo0=
7779
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
7880
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
7981
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=

scripts/dev.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ kind: OperatorGroup
207207
metadata:
208208
name: websphere-operator-group
209209
namespace: $NAMESPACE
210+
spec:
211+
targetNamespaces:
212+
- $NAMESPACE
210213
EOF
211214

212215
oc apply -f $OG_FILE

0 commit comments

Comments
 (0)