Skip to content

Commit

Permalink
fix linter and test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Neha Manjunath committed Jul 20, 2023
1 parent 2c58a3a commit 5fc1f94
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 115 deletions.
233 changes: 123 additions & 110 deletions events/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
var (
normal1eventstring = `{Name: "service-r2.1772fc5571f425ff", UID: "a756a650-bf61-4da6-8d69-d5ae40bd943c", Namespace: "ceos2"}`

Check failure on line 32 in events/data_test.go

View workflow job for this annotation

GitHub Actions / lint

var `normal1eventstring` is unused (unused)
warning1eventstring = `{Name: "r1.177351c307a38f38", UID: "a0450cc2-26e5-46e6-8ef8-be9dec02cd35", Namespace: "ceos1"}`

Check failure on line 33 in events/data_test.go

View workflow job for this annotation

GitHub Actions / lint

var `warning1eventstring` is unused (unused)
warning2eventstring = `{Name: "r1.17735337a69ffd33", UID: "efa6a664-ccf3-4ba8-a30b-09e0ebeaa269", Namespace: "ceos6"}`

Check failure on line 34 in events/data_test.go

View workflow job for this annotation

GitHub Actions / lint

var `warning2eventstring` is unused (unused)
)

var (
Expand Down Expand Up @@ -88,118 +89,130 @@ var (
`

normal1eventstatus = EventStatus{
"Name": "service-r2.1772fc5571f425ff",
"UID": "a756a650-bf61-4da6-8d69-d5ae40bd943c",
"Namespace": "ceos2",
"Message": "announcing from node \"kne-control-plane\" with protocol \"layer2\"",
"Type": "Normal",
"Event": {
"metadata": {
"name": "service-r2.1772fc5571f425ff",
"namespace": "ceos2",
"uid": "a756a650-bf61-4da6-8d69-d5ae40bd943c",
"resourceVersion": "3243",
"creationTimestamp": "2023-07-18T14:24:14Z",
"managedFields": [
{
"manager": "speaker",
"operation": "Update",
"apiVersion": "v1",
"time": "2023-07-18T14:24:14Z",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:count": {},
"f:firstTimestamp": {},
"f:involvedObject": {},
"f:lastTimestamp": {},
"f:message": {},
"f:reason": {},
"f:source": {
"f:component": {}
},
"f:type": {}
}
Name: "service-r2.1772fc5571f425ff",
UID: "a756a650-bf61-4da6-8d69-d5ae40bd943c",
Namespace: "ceos2",
Message: "announcing from node \"kne-control-plane\" with protocol \"layer2\"",
Type: "Normal",
}

warning1eventdata = `
{
"metadata": {
"name": "r1.177351c307a38f38",
"namespace": "ceos1",
"uid": "a0450cc2-26e5-46e6-8ef8-be9dec02cd35",
"resourceVersion": "325871",
"creationTimestamp": "2023-07-19T16:29:43Z",
"managedFields": [
{
"manager": "kube-scheduler",
"operation": "Update",
"apiVersion": "v1",
"time": "2023-07-19T16:39:50Z",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:count": {},
"f:firstTimestamp": {},
"f:involvedObject": {},
"f:lastTimestamp": {},
"f:message": {},
"f:reason": {},
"f:source": {
"f:component": {}
},
"f:type": {}
}
]
},
"involvedObject": {
"kind": "Service",
"namespace": "ceos2",
"name": "service-r2",
"uid": "2459a3c5-c353-4a50-aa70-dc897ffb051e",
"apiVersion": "v1",
"resourceVersion": "3076"
},
"reason": "nodeAssigned",
"message": "announcing from node \"kne-control-plane\" with protocol \"layer2\"",
"source": {
"component": "metallb-speaker"
},
"firstTimestamp": "2023-07-18T14:24:14Z",
"lastTimestamp": "2023-07-18T14:24:14Z",
"count": 1,
"type": "Normal",
"eventTime": null,
"reportingComponent": "",
"reportingInstance": ""
}
}
]
},
"involvedObject": {
"kind": "Pod",
"namespace": "ceos1",
"name": "r1",
"uid": "b69a3fd5-2f25-42aa-91c4-146c40e53053",
"apiVersion": "v1",
"resourceVersion": "323358"
},
"reason": "FailedScheduling",
"message": "0/1 nodes are available: 1 Insufficient cpu. preemption: 0/1 nodes are available: 1 No preemption victims found for incoming pod..",
"source": {
"component": "default-scheduler"
},
"firstTimestamp": "2023-07-19T16:29:43Z",
"lastTimestamp": "2023-07-19T16:39:50Z",
"count": 3,
"type": "Warning",
"eventTime": null,
"reportingComponent": "",
"reportingInstance": ""
}

`
warning1eventstatus = EventStatus{
"Name": "r1.177351c307a38f38",
"UID": "a0450cc2-26e5-46e6-8ef8-be9dec02cd35",
"Namespace": "ceos1",
"Message": "0/1 nodes are available: 1 Insufficient cpu. preemption: 0/1 nodes are available: 1 No preemption victims found for incoming pod..",
"Type": "Warning",
"Event": {
"metadata": {
"name": "r1.177351c307a38f38",
"namespace": "ceos1",
"uid": "a0450cc2-26e5-46e6-8ef8-be9dec02cd35",
"resourceVersion": "325871",
"creationTimestamp": "2023-07-19T16:29:43Z",
"managedFields": [
{
"manager": "kube-scheduler",
"operation": "Update",
"apiVersion": "v1",
"time": "2023-07-19T16:39:50Z",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:count": {},
"f:firstTimestamp": {},
"f:involvedObject": {},
"f:lastTimestamp": {},
"f:message": {},
"f:reason": {},
"f:source": {
"f:component": {}
},
"f:type": {}
}
Name: "r1.177351c307a38f38",
UID: "a0450cc2-26e5-46e6-8ef8-be9dec02cd35",
Namespace: "ceos1",
Message: "0/1 nodes are available: 1 Insufficient cpu. preemption: 0/1 nodes are available: 1 No preemption victims found for incoming pod..",
Type: "Warning",
}

warning2eventdata = `
{
"metadata": {
"name": "r1.17735337a69ffd33",
"namespace": "ceos6",
"uid": "efa6a664-ccf3-4ba8-a30b-09e0ebeaa269",
"resourceVersion": "1621",
"creationTimestamp": "2023-07-19T16:56:23Z",
"managedFields": [
{
"manager": "kube-scheduler",
"operation": "Update",
"apiVersion": "v1",
"time": "2023-07-19T16:56:23Z",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:count": {},
"f:firstTimestamp": {},
"f:involvedObject": {},
"f:lastTimestamp": {},
"f:message": {},
"f:reason": {},
"f:source": {
"f:component": {}
},
"f:type": {}
}
]
},
"involvedObject": {
"kind": "Pod",
"namespace": "ceos1",
"name": "r1",
"uid": "b69a3fd5-2f25-42aa-91c4-146c40e53053",
"apiVersion": "v1",
"resourceVersion": "323358"
},
"reason": "FailedScheduling",
"message": "0/1 nodes are available: 1 Insufficient cpu. preemption: 0/1 nodes are available: 1 No preemption victims found for incoming pod..",
"source": {
"component": "default-scheduler"
},
"firstTimestamp": "2023-07-19T16:29:43Z",
"lastTimestamp": "2023-07-19T16:39:50Z",
"count": 3,
"type": "Warning",
"eventTime": null,
"reportingComponent": "",
"reportingInstance": ""
}
}
]
},
"involvedObject": {
"kind": "Pod",
"namespace": "ceos6",
"name": "r1",
"uid": "140da1fb-0ff4-4b9d-b512-41c64bd9b1e1",
"apiVersion": "v1",
"resourceVersion": "1620"
},
"reason": "FailedScheduling",
"message": "0/1 nodes are available: 1 Insufficient memory. preemption: 0/1 nodes are available: 1 No preemption victims found for incoming pod..",
"source": {
"component": "default-scheduler"
},
"firstTimestamp": "2023-07-19T16:56:23Z",
"lastTimestamp": "2023-07-19T16:56:23Z",
"count": 1,
"type": "Warning",
"eventTime": null,
"reportingComponent": "",
"reportingInstance": ""
}
`
warning2eventstatus = EventStatus{
Name: "r1.17735337a69ffd33",
UID: "efa6a664-ccf3-4ba8-a30b-09e0ebeaa269",
Namespace: "ceos6",
Message: "0/1 nodes are available: 1 Insufficient memory. preemption: 0/1 nodes are available: 1 No preemption victims found for incoming pod..",
Type: "Warning",
}
)
)
8 changes: 6 additions & 2 deletions events/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func TestGetEventStatus(t *testing.T) {

var eventGetUpdatesStatus = [][]EventStatus{
{normal1eventstatus},
{warning1eventstatus},
{warning2eventstatus},
}

next := -1
Expand Down Expand Up @@ -114,6 +116,8 @@ func TestWatchEventStatus(t *testing.T) {

var wanted = []*EventStatus{
&normal1eventstatus,
&warning1eventstatus,
&warning2eventstatus,
}
var updates = []*corev1.Event{
normal1event,
Expand Down Expand Up @@ -181,7 +185,7 @@ func TestString(t *testing.T) {
event *EventStatus
status string
}{
{"event1", &EventStatus{Name: "event1", Namespace: "ns", UID: "event-1"}, `{Name: "event1", UID: "event-1", Namespace: "ns"`}, // No containers
{"event1", &EventStatus{Name: "event1", Namespace: "ns", UID: "event-1"}, `{Name: "event1", UID: "event-1", Namespace: "ns"`},
} {
t.Run(tt.name, func(t *testing.T) {
status := tt.event.String()
Expand All @@ -194,7 +198,7 @@ func TestString(t *testing.T) {

func TestEqual(t *testing.T) {
different := &EventStatus{}
for i, event := range []*EventStatus{&normal1eventstatus} {
for i, event := range []*EventStatus{&normal1eventstatus, &warning1eventstatus, &warning2eventstatus} {
lintEvent := event
if !event.Equal(lintEvent) {
t.Errorf("#%d: Equal returned false on equal events", i)
Expand Down
5 changes: 2 additions & 3 deletions events/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func (w *Watcher) displayEvent(s *EventStatus) bool {
newNamespace := s.Namespace != w.currentNamespace
if newNamespace {
w.currentNamespace = s.Namespace
w.display("NS: %s", s.Namespace)
newNamespace = false

Check failure on line 128 in events/status.go

View workflow job for this annotation

GitHub Actions / lint

assigned to newNamespace, but never used afterwards (wastedassign)
}
w.display("NS: %s", s.Namespace)
Expand All @@ -135,8 +134,8 @@ func (w *Watcher) displayEvent(s *EventStatus) bool {

message := s.Message
for _, m := range errorMsgs {
// Error out if namespace is currentnamesapce and message contains predefinedcheck namespace
if w.currentNamespace == s.Namespace && strings.Contains(message, m) {
// Error out if message contains predefined message
if strings.Contains(message, m) {
w.errCh <- fmt.Errorf("Event failed due to %s . Message: %s", s.Event.Reason, message)
w.cancel()
return false
Expand Down

0 comments on commit 5fc1f94

Please sign in to comment.