From 4eecb1eb485dab48ea70636c8a468089439119e3 Mon Sep 17 00:00:00 2001 From: marcobebway Date: Thu, 18 Jan 2024 17:11:29 +0100 Subject: [PATCH] Fix lint --- api/operator/v1alpha1/eventing_types.go | 19 +++++++++++-------- api/operator/v1alpha1/eventing_types_test.go | 12 ++++++++++++ api/operator/v1alpha1/status.go | 11 ++++++----- api/operator/v1alpha1/status_test.go | 16 ++++++++-------- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/api/operator/v1alpha1/eventing_types.go b/api/operator/v1alpha1/eventing_types.go index 5592ff3d..64879ab2 100644 --- a/api/operator/v1alpha1/eventing_types.go +++ b/api/operator/v1alpha1/eventing_types.go @@ -27,14 +27,6 @@ type ConditionReason string type ConditionType string -var supportedConditionsTypes = map[ConditionType]interface{}{ - ConditionBackendAvailable: nil, - ConditionPublisherProxyReady: nil, - ConditionWebhookReady: nil, - ConditionSubscriptionManagerReady: nil, - ConditionDeleted: nil, -} - const ( StateReady string = "Ready" StateError string = "Error" @@ -80,6 +72,17 @@ const ( ConditionReasonEventMeshSubManagerStopFailed ConditionReason = "EventMeshSubscriptionManagerStopFailed" ) +// getSupportedConditionsTypes returns a map of supported condition types. +func getSupportedConditionsTypes() map[ConditionType]interface{} { + return map[ConditionType]interface{}{ + ConditionBackendAvailable: nil, + ConditionPublisherProxyReady: nil, + ConditionWebhookReady: nil, + ConditionSubscriptionManagerReady: nil, + ConditionDeleted: nil, + } +} + // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. // Eventing is the Schema for the eventing API. diff --git a/api/operator/v1alpha1/eventing_types_test.go b/api/operator/v1alpha1/eventing_types_test.go index 8cbc3b79..093672a4 100644 --- a/api/operator/v1alpha1/eventing_types_test.go +++ b/api/operator/v1alpha1/eventing_types_test.go @@ -97,3 +97,15 @@ func TestIsSpecBackendTypeChanged(t *testing.T) { }) } } + +func Test_getSupportedConditionsTypes(t *testing.T) { + want := map[ConditionType]interface{}{ + ConditionBackendAvailable: nil, + ConditionPublisherProxyReady: nil, + ConditionWebhookReady: nil, + ConditionSubscriptionManagerReady: nil, + ConditionDeleted: nil, + } + got := getSupportedConditionsTypes() + require.Equal(t, want, got) +} diff --git a/api/operator/v1alpha1/status.go b/api/operator/v1alpha1/status.go index 15e7e025..e63e0667 100644 --- a/api/operator/v1alpha1/status.go +++ b/api/operator/v1alpha1/status.go @@ -152,11 +152,12 @@ func (es *EventingStatus) RemoveUnsupportedConditions() { return } - supported := make([]kmetav1.Condition, 0, len(es.Conditions)) - for _, c := range es.Conditions { - if _, ok := supportedConditionsTypes[ConditionType(c.Type)]; ok { - supported = append(supported, c) + supportedConditionsTypes := getSupportedConditionsTypes() + supportedConditions := make([]kmetav1.Condition, 0, len(es.Conditions)) + for _, condition := range es.Conditions { + if _, ok := supportedConditionsTypes[ConditionType(condition.Type)]; ok { + supportedConditions = append(supportedConditions, condition) } } - es.Conditions = supported + es.Conditions = supportedConditions } diff --git a/api/operator/v1alpha1/status_test.go b/api/operator/v1alpha1/status_test.go index 274ed23e..011bc855 100644 --- a/api/operator/v1alpha1/status_test.go +++ b/api/operator/v1alpha1/status_test.go @@ -108,7 +108,7 @@ func TestRemoveUnsupportedConditions(t *testing.T) { Type: "BackendAvailable", Status: kmetav1.ConditionStatus("BackendAvailableStatus"), ObservedGeneration: int64(1), - LastTransitionTime: kmetav1.Time{Time: time.Date(2001, 01, 01, 01, 01, 01, 000000001, time.UTC)}, + LastTransitionTime: kmetav1.Time{Time: time.Date(2001, 0o1, 0o1, 0o1, 0o1, 0o1, 0o00000001, time.UTC)}, Reason: "BackendAvailableReason", Message: "BackendAvailableMessage", } @@ -116,7 +116,7 @@ func TestRemoveUnsupportedConditions(t *testing.T) { Type: "PublisherProxyReady", Status: kmetav1.ConditionStatus("PublisherProxyReadyStatus"), ObservedGeneration: int64(2), - LastTransitionTime: kmetav1.Time{Time: time.Date(2002, 02, 02, 02, 02, 02, 000000002, time.UTC)}, + LastTransitionTime: kmetav1.Time{Time: time.Date(2002, 0o2, 0o2, 0o2, 0o2, 0o2, 0o00000002, time.UTC)}, Reason: "PublisherProxyReadyReason", Message: "PublisherProxyReadyMessage", } @@ -124,7 +124,7 @@ func TestRemoveUnsupportedConditions(t *testing.T) { Type: "WebhookReady", Status: kmetav1.ConditionStatus("WebhookReadyStatus"), ObservedGeneration: int64(3), - LastTransitionTime: kmetav1.Time{Time: time.Date(2003, 03, 03, 03, 03, 03, 000000003, time.UTC)}, + LastTransitionTime: kmetav1.Time{Time: time.Date(2003, 0o3, 0o3, 0o3, 0o3, 0o3, 0o00000003, time.UTC)}, Reason: "WebhookReadyReason", Message: "WebhookReadyMessage", } @@ -132,7 +132,7 @@ func TestRemoveUnsupportedConditions(t *testing.T) { Type: "SubscriptionManagerReady", Status: kmetav1.ConditionStatus("SubscriptionManagerReadyStatus"), ObservedGeneration: int64(4), - LastTransitionTime: kmetav1.Time{Time: time.Date(2004, 04, 04, 04, 04, 04, 000000004, time.UTC)}, + LastTransitionTime: kmetav1.Time{Time: time.Date(2004, 0o4, 0o4, 0o4, 0o4, 0o4, 0o00000004, time.UTC)}, Reason: "SubscriptionManagerReadyReason", Message: "SubscriptionManagerReadyMessage", } @@ -140,7 +140,7 @@ func TestRemoveUnsupportedConditions(t *testing.T) { Type: "Deleted", Status: kmetav1.ConditionStatus("DeletedStatus"), ObservedGeneration: int64(5), - LastTransitionTime: kmetav1.Time{Time: time.Date(2005, 05, 05, 05, 05, 05, 000000005, time.UTC)}, + LastTransitionTime: kmetav1.Time{Time: time.Date(2005, 0o5, 0o5, 0o5, 0o5, 0o5, 0o00000005, time.UTC)}, Reason: "DeletedReason", Message: "DeletedMessage", } @@ -150,7 +150,7 @@ func TestRemoveUnsupportedConditions(t *testing.T) { Type: "Unsupported1", Status: kmetav1.ConditionStatus("UnsupportedStatus1"), ObservedGeneration: int64(-1), - LastTransitionTime: kmetav1.Time{Time: time.Date(2011, 11, 11, 11, 11, 11, 000000011, time.UTC)}, + LastTransitionTime: kmetav1.Time{Time: time.Date(2011, 11, 11, 11, 11, 11, 0o00000011, time.UTC)}, Reason: "UnsupportedReason1", Message: "UnsupportedMessage1", } @@ -158,7 +158,7 @@ func TestRemoveUnsupportedConditions(t *testing.T) { Type: "Unsupported2", Status: kmetav1.ConditionStatus("UnsupportedStatus2"), ObservedGeneration: int64(-2), - LastTransitionTime: kmetav1.Time{Time: time.Date(2012, 12, 12, 12, 12, 12, 000000012, time.UTC)}, + LastTransitionTime: kmetav1.Time{Time: time.Date(2012, 12, 12, 12, 12, 12, 0o00000012, time.UTC)}, Reason: "UnsupportedReason2", Message: "UnsupportedMessage2", } @@ -166,7 +166,7 @@ func TestRemoveUnsupportedConditions(t *testing.T) { Type: "Unsupported3", Status: kmetav1.ConditionStatus("UnsupportedStatus3"), ObservedGeneration: int64(-3), - LastTransitionTime: kmetav1.Time{Time: time.Date(2013, 13, 13, 13, 13, 13, 000000013, time.UTC)}, + LastTransitionTime: kmetav1.Time{Time: time.Date(2013, 13, 13, 13, 13, 13, 0o00000013, time.UTC)}, Reason: "UnsupportedReason3", Message: "UnsupportedMessage3", }