-
Notifications
You must be signed in to change notification settings - Fork 318
Modifying build client to handle different build logics #5224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -492,9 +492,15 @@ func handleBuilds(ctx context.Context, buildClient BuildClient, podClient kubern | |
| wg.Add(len(builds)) | ||
| for _, build := range builds { | ||
| go func(b buildapi.Build) { | ||
| var err error | ||
| defer wg.Done() | ||
| metricsAgent.AddNodeWorkload(ctx, b.Namespace, fmt.Sprintf("%s-build", b.Name), b.Name, podClient) | ||
| if err := handleBuild(ctx, buildClient, podClient, b); err != nil { | ||
| if buildClient.BuildType() == api.BuildTypeOpenshift { | ||
| err = handleOpenshiftBuild(ctx, buildClient, podClient, b) | ||
| } else { | ||
| err = fmt.Errorf("undefined build type %s", buildClient.BuildType()) | ||
| } | ||
| if err != nil { | ||
| errChan <- fmt.Errorf("error occurred handling build %s: %w", b.Name, err) | ||
| } | ||
| metricsAgent.RemoveNodeWorkload(b.Name) | ||
|
Comment on lines
+495
to
506
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate workload registration: Line 497 calls Either remove the call here (lines 497) or remove it from 🐛 Proposed fix: remove the call from handleBuilds for _, build := range builds {
go func(b buildapi.Build) {
var err error
defer wg.Done()
- metricsAgent.AddNodeWorkload(ctx, b.Namespace, fmt.Sprintf("%s-build", b.Name), b.Name, podClient)
if buildClient.BuildType() == api.BuildTypeOpenshift {
err = handleOpenshiftBuild(ctx, buildClient, podClient, b)
} else {
err = fmt.Errorf("undefined build type %s", buildClient.BuildType())
}🤖 Prompt for AI Agents |
||
|
|
@@ -552,35 +558,35 @@ func constructMultiArchBuilds(build buildapi.Build, stepArchitectures []string) | |
| return ret | ||
| } | ||
|
|
||
| func handleBuild(ctx context.Context, client BuildClient, podClient kubernetes.PodClient, build buildapi.Build) error { | ||
| func handleOpenshiftBuild(ctx context.Context, buildClient BuildClient, podClient kubernetes.PodClient, build buildapi.Build) error { | ||
| const attempts = 5 | ||
| ns, name := build.Namespace, build.Name | ||
| var errs []error | ||
| if err := wait.ExponentialBackoff(wait.Backoff{Duration: time.Minute, Factor: 1.5, Steps: attempts}, func() (bool, error) { | ||
| var attempt buildapi.Build | ||
|
|
||
| build.DeepCopyInto(&attempt) | ||
| if err := client.Create(ctx, &attempt); err == nil { | ||
| if err := buildClient.Create(ctx, &attempt); err == nil { | ||
| logrus.Infof("Created build %q", name) | ||
| } else if kerrors.IsAlreadyExists(err) { | ||
| logrus.Infof("Found existing build %q", name) | ||
| } else { | ||
| return false, fmt.Errorf("could not create build %s: %w", name, err) | ||
| } | ||
|
|
||
| client.MetricsAgent().AddNodeWorkload(ctx, ns, fmt.Sprintf("%s-build", name), name, podClient) | ||
| client.MetricsAgent().StoreMachinesSnapshotForBuildPod(ctx, ns, fmt.Sprintf("%s-build", name), podClient) | ||
| if err := waitForBuildOrTimeout(ctx, client, podClient, ns, name); err != nil { | ||
| buildClient.MetricsAgent().AddNodeWorkload(ctx, ns, fmt.Sprintf("%s-build", name), name, podClient) | ||
| buildClient.MetricsAgent().StoreMachinesSnapshotForBuildPod(ctx, ns, fmt.Sprintf("%s-build", name), podClient) | ||
| if err := waitForBuildOrTimeout(ctx, buildClient, podClient, ns, name); err != nil { | ||
| errs = append(errs, err) | ||
| return false, handleFailedBuild(ctx, client, ns, name, err) | ||
| return false, handleFailedBuild(ctx, buildClient, ns, name, err) | ||
| } | ||
| if err := gatherSuccessfulBuildLog(client, ns, name); err != nil { | ||
| if err := gatherSuccessfulBuildLog(buildClient, ns, name); err != nil { | ||
| // log error but do not fail successful build | ||
| logrus.WithError(err).Warnf("Failed gathering successful build %s logs into artifacts.", name) | ||
| } | ||
| return true, nil | ||
| }); err != nil { | ||
| if err == wait.ErrWaitTimeout { | ||
| if wait.Interrupted(err) { | ||
| return fmt.Errorf("build not successful after %d attempts: %w", attempts, utilerrors.NewAggregate(errs)) | ||
| } | ||
| return err | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.