Skip to content

Commit

Permalink
Remove unused RemoveStatusCondition method
Browse files Browse the repository at this point in the history
This was used to remove the Conflict condition when the conflict
was resolved but we now update the the condition as there can be
multiple conflicts. In general, the pattern is to update the
condition status rather than removing a condition.

Signed-off-by: Tom Pantelis <[email protected]>
  • Loading branch information
tpantelis committed Aug 26, 2024
1 parent 098cdcc commit b6f1b06
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 50 deletions.
22 changes: 0 additions & 22 deletions pkg/agent/controller/service_export_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

"github.com/pkg/errors"
"github.com/submariner-io/admiral/pkg/log"
"github.com/submariner-io/admiral/pkg/slices"
"github.com/submariner-io/lighthouse/pkg/constants"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -50,27 +49,6 @@ func NewServiceExportClient(client dynamic.Interface, scheme *runtime.Scheme) *S
}
}

func (c *ServiceExportClient) RemoveStatusCondition(ctx context.Context, name, namespace string,
condType mcsv1a1.ServiceExportConditionType, reason string,
) {
c.doUpdate(ctx, name, namespace, func(toUpdate *mcsv1a1.ServiceExport) bool {
condition := FindServiceExportStatusCondition(toUpdate.Status.Conditions, condType)
if condition != nil && reflect.DeepEqual(condition.Reason, &reason) {
logger.V(log.DEBUG).Infof("Removing status condition (Type: %q, Reason: %q) from ServiceExport (%s/%s)",
condType, reason, namespace, name)

toUpdate.Status.Conditions, _ = slices.Remove(toUpdate.Status.Conditions, *condition,
func(c mcsv1a1.ServiceExportCondition) mcsv1a1.ServiceExportConditionType {
return c.Type
})

return true
}

return false
})
}

func (c *ServiceExportClient) UpdateStatusConditions(ctx context.Context, name, namespace string,
conditions ...mcsv1a1.ServiceExportCondition,
) {
Expand Down
28 changes: 0 additions & 28 deletions pkg/agent/controller/service_export_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,34 +100,6 @@ var _ = Describe("ServiceExportClient", func() {
})
})

Context("RemoveStatusCondition", func() {
BeforeEach(func() {
initialServiceExport.Status.Conditions = []mcsv1a1.ServiceExportCondition{
{
Type: constants.ServiceExportReady,
Status: corev1.ConditionFalse,
Reason: ptr.To("Failed"),
},
}
})

It("should remove the condition if the reason matches", func() {
serviceExportClient.RemoveStatusCondition(context.TODO(), serviceName, serviceNamespace,
constants.ServiceExportReady, "Failed")

Expect(controller.FindServiceExportStatusCondition(getServiceExport().Status.Conditions,
constants.ServiceExportReady)).To(BeNil())
})

It("should not remove the condition if the reason does not match", func() {
serviceExportClient.RemoveStatusCondition(context.TODO(), serviceName, serviceNamespace,
constants.ServiceExportReady, "NotMatching")

Expect(controller.FindServiceExportStatusCondition(getServiceExport().Status.Conditions,
constants.ServiceExportReady)).ToNot(BeNil())
})
})

Context("with Conflict condition type", func() {
It("should aggregate the different reasons and messages", func() {
// The condition shouldn't be added with Status False.
Expand Down

0 comments on commit b6f1b06

Please sign in to comment.