-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for interop rhel programatically
* Initial re structure for rhel event handling * Added pipeline and evet for interop-rhel * Change interop-rhel topic for testing * Add testing event for interop-rhel * Redactor for handling multiple events from same destination * Add logging for repos debug * fix for decoding _ golang/go#40351 * bump tekton client version to V0.26.0 * Wait reconcile from informer to get results * Fix informer waiting for results on pipelinerun * Added helper function to inspect xunit files
- Loading branch information
1 parent
05bb997
commit 7216aca
Showing
17 changed files
with
513 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package interopRHEL | ||
|
||
import ( | ||
"fmt" | ||
|
||
crcPipelines "github.com/adrianriobo/qe-eventmanager/pkg/crc/pipelines" | ||
"github.com/adrianriobo/qe-eventmanager/pkg/services/ci/pipelines" | ||
"github.com/adrianriobo/qe-eventmanager/pkg/util/http" | ||
"github.com/adrianriobo/qe-eventmanager/pkg/util/logging" | ||
"github.com/adrianriobo/qe-eventmanager/pkg/util/xunit" | ||
|
||
v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
const ( | ||
pipelineRefName string = "interop-rhel" | ||
pipelineRunName string = pipelineRefName + "-" | ||
|
||
rhelVersionParamName string = "rhel-version" | ||
repoBaseosParamName string = "repo-baseos-url" | ||
repoAppStreamParamName string = "repo-appstream-url" | ||
imageIDParamName string = "image-id" | ||
|
||
xunitURLResultName string = "results-url" | ||
qeDurationResultName string = "qe-duration" | ||
|
||
resultStatusPassed string = "passed" | ||
resultStatusFailed string = "failed" | ||
) | ||
|
||
func Run(rhelVersion, repoBaseos, repoAppStream, imageID string) (string, string, string, string, error) { | ||
pipelinerun, err := pipelines.CreatePipelinerun(crcPipelines.Namespace, getSpec(rhelVersion, repoBaseos, repoAppStream, imageID)) | ||
if err != nil { | ||
return "", "", "", "", err | ||
} | ||
status := make(chan *v1beta1.PipelineRunStatus) | ||
informerStopper := make(chan struct{}) | ||
defer close(status) | ||
defer close(informerStopper) | ||
go pipelines.AddInformer(crcPipelines.Namespace, pipelinerun.GetName(), status, informerStopper) | ||
runStatus := <-status | ||
xunitURL := getResultValue(runStatus.PipelineResults, xunitURLResultName) | ||
return pipelinerun.GetName(), | ||
xunitURL, | ||
getResultValue(runStatus.PipelineResults, qeDurationResultName), | ||
getResultState(xunitURL), | ||
nil | ||
} | ||
|
||
// TODO make general vailable | ||
func getResultValue(results []v1beta1.PipelineRunResult, resultParamID string) string { | ||
for _, result := range results { | ||
if result.Name == resultParamID { | ||
return result.Value | ||
} | ||
} | ||
return "" | ||
} | ||
|
||
// TODO this should be moved to result parameter from the pipeline | ||
func getResultState(url string) string { | ||
file, err := http.GetFile(url) | ||
if err != nil { | ||
logging.Error(err) | ||
return "" | ||
} | ||
count, err := xunit.CountFailures(file) | ||
if err != nil { | ||
logging.Error(err) | ||
return "" | ||
} | ||
if count == 0 { | ||
return resultStatusPassed | ||
} | ||
return resultStatusFailed | ||
} | ||
|
||
func getSpec(rhelVersion, repoBaseos, repoAppStream, imageID string) *v1beta1.PipelineRun { | ||
return &v1beta1.PipelineRun{ | ||
TypeMeta: v1.TypeMeta{}, | ||
ObjectMeta: v1.ObjectMeta{GenerateName: pipelineRunName, Namespace: crcPipelines.Namespace}, | ||
Spec: v1beta1.PipelineRunSpec{ | ||
PipelineRef: &v1beta1.PipelineRef{Name: pipelineRefName}, | ||
Params: []v1beta1.Param{ | ||
{Name: rhelVersionParamName, Value: *v1beta1.NewArrayOrString(rhelVersion)}, | ||
{Name: repoBaseosParamName, Value: *v1beta1.NewArrayOrString(repoBaseos)}, | ||
{Name: repoAppStreamParamName, Value: *v1beta1.NewArrayOrString(repoAppStream)}, | ||
{Name: imageIDParamName, Value: *v1beta1.NewArrayOrString(imageID)}}, | ||
Timeout: &crcPipelines.DefaultTimeout, | ||
Workspaces: []v1beta1.WorkspaceBinding{crcPipelines.Workspace}}, | ||
} | ||
} | ||
|
||
func GetPipelinerunDashboardUrl(pipelinerunName string) string { | ||
return fmt.Sprintf(crcPipelines.DashboardUrlFormat, crcPipelines.DashboardBaseUrl, crcPipelines.Namespace, pipelinerunName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package buildComplete | ||
|
||
const ( | ||
// Topic string = "VirtualTopic.qe.ci.product-scenario.vipatel.build.complete" | ||
Topic string = "VirtualTopic.qe.ci.product-scenario.build.complete" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package interopOCP | ||
|
||
import ( | ||
buildComplete "github.com/adrianriobo/qe-eventmanager/pkg/event/build-complete" | ||
) | ||
|
||
type BuildComplete struct { | ||
Artifact Artifact `json:"artifact"` | ||
Contact buildComplete.Contact `json:"contact"` | ||
GenerateAt string `json:"generated_at"` | ||
System []buildComplete.System `json:"system"` | ||
Version string `json:"version"` | ||
} | ||
|
||
type TestComplete struct { | ||
Contact buildComplete.Contact `json:"contact"` | ||
Run buildComplete.Run `json:"run"` | ||
Artifact Artifact `json:"artifact"` | ||
Test buildComplete.Test `json:"test"` | ||
GenerateAt string `json:"generated_at"` | ||
System []buildComplete.System `json:"system"` | ||
Version string `json:"version"` | ||
} | ||
|
||
type TestError struct { | ||
Contact buildComplete.Contact `json:"contact"` | ||
Run buildComplete.Run `json:"run"` | ||
Artifact Artifact `json:"artifact"` | ||
Test buildComplete.Test `json:"test"` | ||
Error buildComplete.Error `json:"error"` | ||
GenerateAt string `json:"generated_at"` | ||
System []buildComplete.System `json:"system"` | ||
Version string `json:"version"` | ||
} | ||
|
||
type Artifact struct { | ||
ArtifcatType string `json:"type"` | ||
Id string `json:"id"` | ||
Products []Product `json:"products"` | ||
Email string `json:"email"` | ||
Url string `json:"url"` | ||
} | ||
|
||
type Product struct { | ||
Id string `json:"id"` | ||
NVR string `json:"nvr"` | ||
Name string `json:"name"` | ||
Version string `json:"version"` | ||
Architecture string `json:"architecture"` | ||
Build string `json:"build"` | ||
Internal_build_index_url string `json:"internal_build_index_url"` | ||
External_build_index_url string `json:"external_build_index_url"` | ||
ProductType string `json:"type"` | ||
State string `json:"state"` | ||
Artifacts []interface{} `json:"artifacts"` | ||
Phase string `json:"phase"` | ||
Release string `json:"release"` | ||
} |
Oops, something went wrong.