Open bradmccoydev opened 1 year ago
Reference to code for stageUtils which this project uses: https://github.com/keptn/go-utils/blob/master/pkg/api/utils/stageUtils.go
Confirmed there is no data regarding index or order in stage model https://github.com/keptn/go-utils/blob/master/pkg/api/models/stage.go
In the promotion_triggerd_event_handler.go on like 212, this logic does not work as when you get the array of stages they are not ordered or indexed therefore if you get the last stage first eg production, and then loop through "test" last there are no new stages so, therefore, it can't find the next stage.
for i, s := range stages { if s.StageName == stage { if len(stages) <= (i + 1) { err = errors.New(fmt.Sprintf("no stage defined after stage %s", stage)) logger.WithField("func", "getNextStage").WithError(err).Errorf("no next stage found for project %s with stage %s", project, stage) return nextStage, err } logger.WithField("func", "getNextStage").Infof("next stage %s found for project %s and stage %s", stages[i+1].StageName, project, stage) return stages[i+1].StageName, nil } }
Example: I have two stages, test, and production. when the code calls the
stages, err := a.api.StagesV1().GetAllStages(project)
(line 193)I get the following, and it will start looping through until it matches the stageName and i (the index) is at the end so it will never find the next stage.
[ { "services": [ { "creationDate": "1664279948598231077", "openApprovals": null, "serviceName": "podtato-head" } ], "stageName": "production" }, { "services": [ { "creationDate": "1664279947708503073", "lastEventTypes": { "sh.keptn.event.catalog.triggered": { "eventId": "cb0fdb71-649f-48a2-87dc-c4ffd819904d", "keptnContext": "76c0146e-58e9-441a-a35a-2255032fafb6", "time": "1664542559990455931" }, "sh.keptn.event.evaluation.finished": { "eventId": "276c6e43-5070-44b8-9ffe-1db64c3b1e40", "keptnContext": "0d09ab65-7cd4-42ac-8788-eaa91cc28d05", "time": "1664594874588015193" }, "sh.keptn.event.evaluation.started": { "eventId": "e3e4e52b-d2d8-456c-a4b2-81365c67aab3", "keptnContext": "0d09ab65-7cd4-42ac-8788-eaa91cc28d05", "time": "1664594874583947222" }, "sh.keptn.event.evaluation.triggered": { "eventId": "12a89acd-efb1-4f9d-abda-de26dc7cae2e", "keptnContext": "0d09ab65-7cd4-42ac-8788-eaa91cc28d05", "time": "1664594869911307171" }, "sh.keptn.event.git-promotion.finished": { "eventId": "b1986bb6-355a-4ac2-8d2e-506cf44d4bae", "keptnContext": "0e4c666e-908e-4b12-ae30-87187e0fe06c", "time": "1664593785287294550" }, "sh.keptn.event.git-promotion.started": { "eventId": "0e2a991f-7e81-4b90-ba50-8aed1795c20d", "keptnContext": "0d09ab65-7cd4-42ac-8788-eaa91cc28d05", "time": "1664594874702474896" }, "sh.keptn.event.git-promotion.triggered": { "eventId": "9ff0a90e-75d4-477a-b6c0-89ebe3c84d03", "keptnContext": "0d09ab65-7cd4-42ac-8788-eaa91cc28d05", "time": "1664594874594860413" }, "sh.keptn.event.test.finished": { "eventId": "3f2731cd-7481-4aff-a812-3fd0344e464c", "keptnContext": "0d09ab65-7cd4-42ac-8788-eaa91cc28d05", "time": "1664594869901505399" }, "sh.keptn.event.test.started": { "eventId": "ea511500-b023-4fd3-92dc-9597e5be8d1e", "keptnContext": "0d09ab65-7cd4-42ac-8788-eaa91cc28d05", "time": "1664594834585659503" }, "sh.keptn.event.test.triggered": { "eventId": "30f47d96-8f01-4bd7-8f8e-a9a941abb0c0", "keptnContext": "0d09ab65-7cd4-42ac-8788-eaa91cc28d05", "time": "1664594833588212197" } }, "openApprovals": null, "serviceName": "podtato-head" } ], "stageName": "test" } ]