Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobebway committed Jan 18, 2024
1 parent 226e2f9 commit 4eecb1e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
19 changes: 11 additions & 8 deletions api/operator/v1alpha1/eventing_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions api/operator/v1alpha1/eventing_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
11 changes: 6 additions & 5 deletions api/operator/v1alpha1/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
16 changes: 8 additions & 8 deletions api/operator/v1alpha1/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,39 +108,39 @@ 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",
}
publisherProxyReadyCondition = kmetav1.Condition{
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",
}
webhookReadyCondition = kmetav1.Condition{
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",
}
subscriptionManagerReadyCondition = kmetav1.Condition{
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",
}
deletedCondition = kmetav1.Condition{
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",
}
Expand All @@ -150,23 +150,23 @@ 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",
}
unsupportedTypeCondition2 = kmetav1.Condition{
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",
}
unsupportedTypeCondition3 = kmetav1.Condition{
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",
}
Expand Down

0 comments on commit 4eecb1e

Please sign in to comment.