clienterrors: rename WorkerClientError to clienterrors.New
The usual convention to create new object is to prefix `New*` so this commit renames the `WorkerClientError`. Initially I thought it would be `NewWorkerClientError()` but looking at the package prefix it seems unneeded, i.e. `clienterrors.New()` already provides enough context it seems and it's the only error we construct. We could consider renaming it to `clienterror` (singular) too but that could be a followup. I would also like to make `clienterror.Error` implement the `error` interface but that should be a followup to make this (mechanical) rename trivial to review.
This commit is contained in:
parent
09445a1030
commit
573b349f16
19 changed files with 188 additions and 188 deletions
|
|
@ -36,31 +36,31 @@ func (impl *AWSEC2CopyJobImpl) Run(job worker.Job) error {
|
|||
var args worker.AWSEC2CopyJob
|
||||
err := job.Args(&args)
|
||||
if err != nil {
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorParsingJobArgs, fmt.Sprintf("Error parsing arguments: %v", err), nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorParsingJobArgs, fmt.Sprintf("Error parsing arguments: %v", err), nil)
|
||||
return err
|
||||
}
|
||||
|
||||
aws, err := getAWS(impl.AWSCreds, args.TargetRegion)
|
||||
if err != nil {
|
||||
logWithId.Errorf("Error creating aws client: %v", err)
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, "Invalid worker config", nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorInvalidConfig, "Invalid worker config", nil)
|
||||
return err
|
||||
}
|
||||
|
||||
ami, err := aws.CopyImage(args.TargetName, args.Ami, args.SourceRegion)
|
||||
if err != nil {
|
||||
logWithId.Errorf("Error copying ami: %v", err)
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorSharingTarget, fmt.Sprintf("Error copying ami %s", args.Ami), nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorSharingTarget, fmt.Sprintf("Error copying ami %s", args.Ami), nil)
|
||||
if aerr, ok := err.(awserr.Error); ok {
|
||||
switch aerr.Code() {
|
||||
case "InvalidRegion":
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorSharingTarget, fmt.Sprintf("Invalid source region '%s'", args.SourceRegion), nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorSharingTarget, fmt.Sprintf("Invalid source region '%s'", args.SourceRegion), nil)
|
||||
case "InvalidAMIID.Malformed":
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorSharingTarget, fmt.Sprintf("Malformed source ami id '%s'", args.Ami), nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorSharingTarget, fmt.Sprintf("Malformed source ami id '%s'", args.Ami), nil)
|
||||
case "InvalidAMIID.NotFound":
|
||||
fallthrough // CopyImage returns InvalidRequest instead of InvalidAMIID.NotFound
|
||||
case "InvalidRequest":
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorSharingTarget, fmt.Sprintf("Source ami '%s' not found", args.Ami), nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorSharingTarget, fmt.Sprintf("Source ami '%s' not found", args.Ami), nil)
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
|
@ -89,24 +89,24 @@ func (impl *AWSEC2ShareJobImpl) Run(job worker.Job) error {
|
|||
var args worker.AWSEC2ShareJob
|
||||
err := job.Args(&args)
|
||||
if err != nil {
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorParsingJobArgs, fmt.Sprintf("Error parsing arguments: %v", err), nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorParsingJobArgs, fmt.Sprintf("Error parsing arguments: %v", err), nil)
|
||||
return err
|
||||
}
|
||||
|
||||
if args.Ami == "" || args.Region == "" {
|
||||
if job.NDynamicArgs() != 1 {
|
||||
logWithId.Error("No arguments given and dynamic args empty")
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorNoDynamicArgs, "An ec2 share job should have args or depend on an ec2 copy job", nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorNoDynamicArgs, "An ec2 share job should have args or depend on an ec2 copy job", nil)
|
||||
return nil
|
||||
}
|
||||
var cjResult worker.AWSEC2CopyJobResult
|
||||
err = job.DynamicArgs(0, &cjResult)
|
||||
if err != nil {
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorParsingDynamicArgs, "Error parsing dynamic args as ec2 copy job", nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorParsingDynamicArgs, "Error parsing dynamic args as ec2 copy job", nil)
|
||||
return err
|
||||
}
|
||||
if cjResult.JobError != nil {
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorJobDependency, "AWSEC2CopyJob dependency failed", nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorJobDependency, "AWSEC2CopyJob dependency failed", nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -117,22 +117,22 @@ func (impl *AWSEC2ShareJobImpl) Run(job worker.Job) error {
|
|||
aws, err := getAWS(impl.AWSCreds, args.Region)
|
||||
if err != nil {
|
||||
logWithId.Errorf("Error creating aws client: %v", err)
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, "Invalid worker config", nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorInvalidConfig, "Invalid worker config", nil)
|
||||
return err
|
||||
}
|
||||
|
||||
err = aws.ShareImage(args.Ami, args.ShareWithAccounts)
|
||||
if err != nil {
|
||||
logWithId.Errorf("Error sharing image: %v", err)
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorSharingTarget, fmt.Sprintf("Error sharing image with target %v", args.ShareWithAccounts), nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorSharingTarget, fmt.Sprintf("Error sharing image with target %v", args.ShareWithAccounts), nil)
|
||||
if aerr, ok := err.(awserr.Error); ok {
|
||||
switch aerr.Code() {
|
||||
case "InvalidAMIID.Malformed":
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorSharingTarget, fmt.Sprintf("Malformed ami id '%s'", args.Ami), nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorSharingTarget, fmt.Sprintf("Malformed ami id '%s'", args.Ami), nil)
|
||||
case "InvalidAMIID.NotFound":
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorSharingTarget, fmt.Sprintf("Ami '%s' not found in region '%s'", args.Ami, args.Region), nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorSharingTarget, fmt.Sprintf("Ami '%s' not found in region '%s'", args.Ami, args.Region), nil)
|
||||
case "InvalidAMIAttributeItemValue":
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorSharingTarget, fmt.Sprintf("Invalid user id to share ami with: %v", args.ShareWithAccounts), nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorSharingTarget, fmt.Sprintf("Invalid user id to share ami with: %v", args.ShareWithAccounts), nil)
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func (impl *ContainerResolveJobImpl) Run(job worker.Job) error {
|
|||
specs, err := resolver.Finish()
|
||||
|
||||
if err != nil {
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorContainerResolution, err.Error(), nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorContainerResolution, err.Error(), nil)
|
||||
} else {
|
||||
for i, spec := range specs {
|
||||
result.Specs[i] = worker.ContainerSpec{
|
||||
|
|
|
|||
|
|
@ -81,16 +81,16 @@ func workerClientErrorFrom(err error) (*clienterrors.Error, error) {
|
|||
details := e.Reason
|
||||
switch e.Kind {
|
||||
case "DepsolveError":
|
||||
return clienterrors.WorkerClientError(clienterrors.ErrorDNFDepsolveError, reason, details), nil
|
||||
return clienterrors.New(clienterrors.ErrorDNFDepsolveError, reason, details), nil
|
||||
case "MarkingErrors":
|
||||
return clienterrors.WorkerClientError(clienterrors.ErrorDNFMarkingErrors, reason, details), nil
|
||||
return clienterrors.New(clienterrors.ErrorDNFMarkingErrors, reason, details), nil
|
||||
case "RepoError":
|
||||
return clienterrors.WorkerClientError(clienterrors.ErrorDNFRepoError, reason, details), nil
|
||||
return clienterrors.New(clienterrors.ErrorDNFRepoError, reason, details), nil
|
||||
default:
|
||||
err := fmt.Errorf("Unhandled dnf-json error in depsolve job: %v", err)
|
||||
// This still has the kind/reason format but a kind that's returned
|
||||
// by dnf-json and not explicitly handled here.
|
||||
return clienterrors.WorkerClientError(clienterrors.ErrorDNFOtherError, reason, details), err
|
||||
return clienterrors.New(clienterrors.ErrorDNFOtherError, reason, details), err
|
||||
}
|
||||
default:
|
||||
reason := "rpmmd error in depsolve job"
|
||||
|
|
@ -101,7 +101,7 @@ func workerClientErrorFrom(err error) (*clienterrors.Error, error) {
|
|||
details = err.Error()
|
||||
}
|
||||
// Error originates from internal/rpmmd, not from dnf-json
|
||||
return clienterrors.WorkerClientError(clienterrors.ErrorRPMMDError, reason, details), err
|
||||
return clienterrors.New(clienterrors.ErrorRPMMDError, reason, details), err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ func (impl *DepsolveJobImpl) Run(job worker.Job) error {
|
|||
for _, baseurlstr := range repo.BaseURLs {
|
||||
match, err := impl.RepositoryMTLSConfig.CompareBaseURL(baseurlstr)
|
||||
if err != nil {
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidRepositoryURL, "Repository URL is malformed", err.Error())
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorInvalidRepositoryURL, "Repository URL is malformed", err.Error())
|
||||
return err
|
||||
}
|
||||
if match {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ func (impl *FileResolveJobImpl) Run(job worker.Job) error {
|
|||
|
||||
if result.Results == nil || len(result.Results) == 0 {
|
||||
logWithId.Infof("Resolving file contents failed: %v", err)
|
||||
result.JobError = clienterrors.WorkerClientError(
|
||||
result.JobError = clienterrors.New(
|
||||
clienterrors.ErrorRemoteFileResolution,
|
||||
"Error resolving file contents",
|
||||
"All remote file contents returned empty",
|
||||
|
|
@ -70,7 +70,7 @@ func (impl *FileResolveJobImpl) Run(job worker.Job) error {
|
|||
if len(resolutionErrors) == 0 {
|
||||
result.Success = true
|
||||
} else {
|
||||
result.JobError = clienterrors.WorkerClientError(
|
||||
result.JobError = clienterrors.New(
|
||||
clienterrors.ErrorRemoteFileResolution,
|
||||
"at least one file resolution failed",
|
||||
resolutionErrors,
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ func (impl *KojiFinalizeJobImpl) Run(job worker.Job) error {
|
|||
|
||||
err := job.Args(args)
|
||||
if err != nil {
|
||||
kojiFinalizeJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorParsingJobArgs, "Error parsing job args", err.Error())
|
||||
kojiFinalizeJobResult.JobError = clienterrors.New(clienterrors.ErrorParsingJobArgs, "Error parsing job args", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -124,13 +124,13 @@ func (impl *KojiFinalizeJobImpl) Run(job worker.Job) error {
|
|||
var osbuildResults []worker.OSBuildJobResult
|
||||
initArgs, osbuildResults, err = extractDynamicArgs(job)
|
||||
if err != nil {
|
||||
kojiFinalizeJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorParsingDynamicArgs, "Error parsing dynamic args", err.Error())
|
||||
kojiFinalizeJobResult.JobError = clienterrors.New(clienterrors.ErrorParsingDynamicArgs, "Error parsing dynamic args", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
// Check the dependencies early.
|
||||
if hasFailedDependency(*initArgs, osbuildResults) {
|
||||
kojiFinalizeJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorKojiFailedDependency, "At least one job dependency failed", nil)
|
||||
kojiFinalizeJobResult.JobError = clienterrors.New(clienterrors.ErrorKojiFailedDependency, "At least one job dependency failed", nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -149,7 +149,7 @@ func (impl *KojiFinalizeJobImpl) Run(job worker.Job) error {
|
|||
kojiTargetResults := buildResult.TargetResultsByName(target.TargetNameKoji)
|
||||
// Only a single Koji target is allowed per osbuild job
|
||||
if len(kojiTargetResults) != 1 {
|
||||
kojiFinalizeJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorKojiFinalize, "Exactly one Koji target result is expected per osbuild job", nil)
|
||||
kojiFinalizeJobResult.JobError = clienterrors.New(clienterrors.ErrorKojiFinalize, "Exactly one Koji target result is expected per osbuild job", nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -301,7 +301,7 @@ func (impl *KojiFinalizeJobImpl) Run(job worker.Job) error {
|
|||
|
||||
err = impl.kojiImport(args.Server, build, buildRoots, outputs, args.KojiDirectory, initArgs.Token)
|
||||
if err != nil {
|
||||
kojiFinalizeJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorKojiFinalize, err.Error(), nil)
|
||||
kojiFinalizeJobResult.JobError = clienterrors.New(clienterrors.ErrorKojiFinalize, err.Error(), nil)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ func (impl *KojiInitJobImpl) Run(job worker.Job) error {
|
|||
var result worker.KojiInitJobResult
|
||||
result.Token, result.BuildID, err = impl.kojiInit(args.Server, args.Name, args.Version, args.Release)
|
||||
if err != nil {
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorKojiInit, err.Error(), nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorKojiInit, err.Error(), nil)
|
||||
}
|
||||
|
||||
err = job.Update(&result)
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@ func validateResult(result *worker.OSBuildJobResult, jobID string) {
|
|||
if result.OSBuildOutput == nil || !result.OSBuildOutput.Success {
|
||||
reason := "osbuild job was unsuccessful"
|
||||
logWithId.Errorf("osbuild job failed: %s", reason)
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorBuildJob, reason, nil)
|
||||
result.JobError = clienterrors.New(clienterrors.ErrorBuildJob, reason, nil)
|
||||
return
|
||||
} else {
|
||||
logWithId.Infof("osbuild job succeeded")
|
||||
|
|
@ -265,14 +265,14 @@ func uploadToS3(a *awscloud.AWS, outputDirectory, exportPath, bucket, key, filen
|
|||
|
||||
result, err := a.Upload(imagePath, bucket, key)
|
||||
if err != nil {
|
||||
return "", clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
return "", clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
|
||||
}
|
||||
|
||||
if public {
|
||||
err := a.MarkS3ObjectAsPublic(bucket, key)
|
||||
if err != nil {
|
||||
return "", clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
return "", clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
}
|
||||
|
||||
return result.Location, nil
|
||||
|
|
@ -280,7 +280,7 @@ func uploadToS3(a *awscloud.AWS, outputDirectory, exportPath, bucket, key, filen
|
|||
|
||||
url, err := a.S3ObjectPresignedURL(bucket, key)
|
||||
if err != nil {
|
||||
return "", clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
return "", clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
}
|
||||
|
||||
return url, nil
|
||||
|
|
@ -375,7 +375,7 @@ func makeJobErrorFromOsbuildOutput(osbuildOutput *osbuild.Result) *clienterrors.
|
|||
if failedStage != "" {
|
||||
reason += fmt.Sprintf(" in stage: %q", failedStage)
|
||||
}
|
||||
return clienterrors.WorkerClientError(clienterrors.ErrorBuildJob, reason, osbErrors)
|
||||
return clienterrors.New(clienterrors.ErrorBuildJob, reason, osbErrors)
|
||||
}
|
||||
|
||||
func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
||||
|
|
@ -403,7 +403,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
logWithId.Errorf("Recovered from panic: %v", r)
|
||||
logWithId.Errorf("%s", debug.Stack())
|
||||
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(
|
||||
osbuildJobResult.JobError = clienterrors.New(
|
||||
clienterrors.ErrorJobPanicked,
|
||||
fmt.Sprintf("job panicked:\n%v\n\noriginal error:\n%v", r, osbuildJobResult.JobError),
|
||||
nil,
|
||||
|
|
@ -430,7 +430,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
|
||||
osbuildVersion, err := osbuild.OSBuildVersion()
|
||||
if err != nil {
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorBuildJob, "Error getting osbuild binary version", err.Error())
|
||||
osbuildJobResult.JobError = clienterrors.New(clienterrors.ErrorBuildJob, "Error getting osbuild binary version", err.Error())
|
||||
return err
|
||||
}
|
||||
osbuildJobResult.OSBuildVersion = osbuildVersion
|
||||
|
|
@ -459,13 +459,13 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
err = job.DynamicArgs(*jobArgs.ManifestDynArgsIdx, &manifestJR)
|
||||
}
|
||||
if err != nil {
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorParsingDynamicArgs, "Error parsing dynamic args", nil)
|
||||
osbuildJobResult.JobError = clienterrors.New(clienterrors.ErrorParsingDynamicArgs, "Error parsing dynamic args", nil)
|
||||
return err
|
||||
}
|
||||
|
||||
// skip the job if the manifest generation failed
|
||||
if manifestJR.JobError != nil {
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorManifestDependency, "Manifest dependency failed", nil)
|
||||
osbuildJobResult.JobError = clienterrors.New(clienterrors.ErrorManifestDependency, "Manifest dependency failed", nil)
|
||||
return nil
|
||||
}
|
||||
jobArgs.Manifest = manifestJR.Manifest
|
||||
|
|
@ -473,7 +473,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
}
|
||||
|
||||
if len(jobArgs.Manifest) == 0 {
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorEmptyManifest, "Job has no manifest", nil)
|
||||
osbuildJobResult.JobError = clienterrors.New(clienterrors.ErrorEmptyManifest, "Job has no manifest", nil)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
@ -484,12 +484,12 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
var jobResult worker.JobResult
|
||||
err = job.DynamicArgs(idx, &jobResult)
|
||||
if err != nil {
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorParsingDynamicArgs, "Error parsing dynamic args", nil)
|
||||
osbuildJobResult.JobError = clienterrors.New(clienterrors.ErrorParsingDynamicArgs, "Error parsing dynamic args", nil)
|
||||
return err
|
||||
}
|
||||
|
||||
if jobResult.JobError != nil {
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorJobDependency, "Job dependency failed", nil)
|
||||
osbuildJobResult.JobError = clienterrors.New(clienterrors.ErrorJobDependency, "Job dependency failed", nil)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
@ -503,7 +503,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
// get exports for all job's targets
|
||||
exports := jobArgs.OsbuildExports()
|
||||
if len(exports) == 0 {
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, "no osbuild export specified for the job", nil)
|
||||
osbuildJobResult.JobError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, "no osbuild export specified for the job", nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -533,18 +533,18 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
case "aws.ec2":
|
||||
err = os.MkdirAll("/var/tmp/osbuild-composer", 0755)
|
||||
if err != nil {
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, "Unable to create /var/tmp/osbuild-composer needed to aws.ec2 executor", nil)
|
||||
osbuildJobResult.JobError = clienterrors.New(clienterrors.ErrorInvalidConfig, "Unable to create /var/tmp/osbuild-composer needed to aws.ec2 executor", nil)
|
||||
return err
|
||||
}
|
||||
tmpDir, err := os.MkdirTemp("/var/tmp/osbuild-composer", "")
|
||||
if err != nil {
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, "Unable to create /var/tmp/osbuild-composer needed to aws.ec2 executor", nil)
|
||||
osbuildJobResult.JobError = clienterrors.New(clienterrors.ErrorInvalidConfig, "Unable to create /var/tmp/osbuild-composer needed to aws.ec2 executor", nil)
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
executor = osbuildexecutor.NewAWSEC2Executor(impl.OSBuildExecutor.IAMProfile, impl.OSBuildExecutor.KeyName, impl.OSBuildExecutor.CloudWatchGroup, job.Id().String(), tmpDir)
|
||||
default:
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, "No osbuild executor defined", nil)
|
||||
osbuildJobResult.JobError = clienterrors.New(clienterrors.ErrorInvalidConfig, "No osbuild executor defined", nil)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -564,7 +564,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
osbuildJobResult.OSBuildOutput, err = executor.RunOSBuild(jobArgs.Manifest, opts, os.Stderr)
|
||||
// First handle the case when "running" osbuild failed
|
||||
if err != nil {
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorBuildJob, "osbuild build failed", err.Error())
|
||||
osbuildJobResult.JobError = clienterrors.New(clienterrors.ErrorBuildJob, "osbuild build failed", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -606,13 +606,13 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
imagePath := path.Join(outputDirectory, jobTarget.OsbuildArtifact.ExportName, jobTarget.OsbuildArtifact.ExportFilename)
|
||||
f, err = os.Open(imagePath)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
defer f.Close()
|
||||
err = job.UploadArtifact(jobTarget.ImageName, f)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -630,7 +630,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
|
||||
tempDirectory, err := os.MkdirTemp(impl.Output, job.Id().String()+"-vmware-*")
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -650,23 +650,23 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
|
||||
err = os.Symlink(exportedImagePath, imagePath)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
err = vmware.ImportVmdk(credentials, imagePath)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
} else if strings.HasSuffix(exportedImagePath, ".ova") {
|
||||
err = vmware.ImportOva(credentials, exportedImagePath, jobTarget.ImageName)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
} else {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, "No vmdk or ova provided", nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, "No vmdk or ova provided", nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -674,12 +674,12 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
targetResult = target.NewAWSTargetResult(nil, &artifact)
|
||||
a, err := impl.getAWS(targetOptions.Region, targetOptions.AccessKeyID, targetOptions.SecretAccessKey, targetOptions.SessionToken)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
if targetOptions.Key == "" {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, "No AWS object key provided", nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, "No AWS object key provided", nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -687,7 +687,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
if bucket == "" {
|
||||
bucket = impl.AWSBucket
|
||||
if bucket == "" {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, "No AWS bucket provided", nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, "No AWS bucket provided", nil)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -701,25 +701,25 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
if strings.HasSuffix(imagePath, ".xz") {
|
||||
imagePath, err = extractXzArchive(imagePath)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorTargetError, "Failed to extract compressed image", err.Error())
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorTargetError, "Failed to extract compressed image", err.Error())
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
_, err = a.Upload(imagePath, bucket, targetOptions.Key)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
ami, err := a.Register(jobTarget.ImageName, bucket, targetOptions.Key, targetOptions.ShareWithAccounts, arch.Current().String(), targetOptions.BootMode)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorImportingImage, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorImportingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
if ami == nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorImportingImage, "No ami returned", nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorImportingImage, "No ami returned", nil)
|
||||
break
|
||||
}
|
||||
targetResult.Options = &target.AWSTargetResultOptions{
|
||||
|
|
@ -731,12 +731,12 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
targetResult = target.NewAWSS3TargetResult(nil, &artifact)
|
||||
a, bucket, err := impl.getAWSForS3Target(targetOptions)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
if targetOptions.Key == "" {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, "No AWS object key provided", nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, "No AWS object key provided", nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -751,7 +751,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
targetResult = target.NewAzureTargetResult(&artifact)
|
||||
azureStorageClient, err := azure.NewStorageClient(targetOptions.StorageAccount, targetOptions.StorageAccessKey)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -771,7 +771,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
)
|
||||
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -781,12 +781,12 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
|
||||
g, err := impl.getGCP(targetOptions.Credentials)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
if targetOptions.Object == "" {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, "No GCP object key provided", nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, "No GCP object key provided", nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -794,7 +794,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
if bucket == "" {
|
||||
bucket = impl.GCPConfig.Bucket
|
||||
if bucket == "" {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, "No GCP bucket provided", nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, "No GCP bucket provided", nil)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -803,7 +803,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
_, err = g.StorageObjectUpload(ctx, path.Join(outputDirectory, jobTarget.OsbuildArtifact.ExportName, jobTarget.OsbuildArtifact.ExportFilename),
|
||||
bucket, targetOptions.Object, map[string]string{gcp.MetadataKeyImageName: jobTarget.ImageName})
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -822,7 +822,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
|
||||
// check error from ComputeImageInsert()
|
||||
if importErr != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorImportingImage, importErr.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorImportingImage, importErr.Error(), nil)
|
||||
break
|
||||
}
|
||||
logWithId.Infof("[GCP] 💿 Image URL: %s", g.ComputeImageURL(jobTarget.ImageName))
|
||||
|
|
@ -831,7 +831,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
logWithId.Infof("[GCP] 🔗 Sharing the image with: %+v", targetOptions.ShareWithAccounts)
|
||||
err = g.ComputeImageShare(ctx, jobTarget.ImageName, targetOptions.ShareWithAccounts)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorSharingTarget, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorSharingTarget, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -845,13 +845,13 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
ctx := context.Background()
|
||||
|
||||
if impl.AzureConfig.Creds == nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorSharingTarget, "osbuild job has org.osbuild.azure.image target but this worker doesn't have azure credentials", nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorSharingTarget, "osbuild job has org.osbuild.azure.image target but this worker doesn't have azure credentials", nil)
|
||||
break
|
||||
}
|
||||
|
||||
c, err := azure.NewClient(*impl.AzureConfig.Creds, targetOptions.TenantID, targetOptions.SubscriptionID)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
logWithId.Info("[Azure] 🔑 Logged in Azure")
|
||||
|
|
@ -860,7 +860,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
if location == "" {
|
||||
location, err = c.GetResourceGroupLocation(ctx, targetOptions.ResourceGroup)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("retrieving resource group location failed: %v", err), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("retrieving resource group location failed: %v", err), nil)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -876,7 +876,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
storageAccountTag,
|
||||
)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("searching for a storage account failed: %v", err), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("searching for a storage account failed: %v", err), nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -893,7 +893,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
storageAccountTag,
|
||||
)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("creating a new storage account failed: %v", err), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("creating a new storage account failed: %v", err), nil)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -905,13 +905,13 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
storageAccount,
|
||||
)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("retrieving the storage account key failed: %v", err), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("retrieving the storage account key failed: %v", err), nil)
|
||||
break
|
||||
}
|
||||
|
||||
azureStorageClient, err := azure.NewStorageClient(storageAccount, storageAccessKey)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("creating the storage client failed: %v", err), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("creating the storage client failed: %v", err), nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -920,7 +920,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
logWithId.Info("[Azure] 📦 Ensuring that we have a storage container")
|
||||
err = azureStorageClient.CreateStorageContainerIfNotExist(ctx, storageAccount, storageContainer)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("cannot create a storage container: %v", err), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("cannot create a storage container: %v", err), nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -936,7 +936,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
if strings.HasSuffix(imagePath, ".xz") {
|
||||
imagePath, err = extractXzArchive(imagePath)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorTargetError, "Failed to extract compressed image", err.Error())
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorTargetError, "Failed to extract compressed image", err.Error())
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -952,7 +952,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
impl.AzureConfig.UploadThreads,
|
||||
)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, fmt.Sprintf("uploading the image failed: %v", err), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, fmt.Sprintf("uploading the image failed: %v", err), nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -968,7 +968,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
location,
|
||||
)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorImportingImage, fmt.Sprintf("registering the image failed: %v", err), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorImportingImage, fmt.Sprintf("registering the image failed: %v", err), nil)
|
||||
break
|
||||
}
|
||||
logWithId.Info("[Azure] 🎉 Image uploaded and registered!")
|
||||
|
|
@ -980,13 +980,13 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
targetResult = target.NewKojiTargetResult(nil, &artifact)
|
||||
kojiServerURL, err := url.Parse(targetOptions.Server)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("failed to parse Koji server URL: %v", err), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("failed to parse Koji server URL: %v", err), nil)
|
||||
break
|
||||
}
|
||||
|
||||
kojiServer, exists := impl.KojiServers[kojiServerURL.Hostname()]
|
||||
if !exists {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("Koji server has not been configured: %s", kojiServerURL.Hostname()), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("Koji server has not been configured: %s", kojiServerURL.Hostname()), nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -995,7 +995,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
kojiAPI, err := koji.NewFromGSSAPI(targetOptions.Server, &kojiServer.creds, kojiTransport)
|
||||
if err != nil {
|
||||
logWithId.Warnf("[Koji] 🔑 login failed: %v", err) // DON'T EDIT: Used for Splunk dashboard
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("failed to authenticate with Koji server %q: %v", kojiServerURL.Hostname(), err), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidTargetConfig, fmt.Sprintf("failed to authenticate with Koji server %q: %v", kojiServerURL.Hostname(), err), nil)
|
||||
break
|
||||
}
|
||||
logWithId.Infof("[Koji] 🔑 Authenticated with %q", kojiServerURL.Hostname())
|
||||
|
|
@ -1008,7 +1008,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
|
||||
file, err := os.Open(path.Join(outputDirectory, jobTarget.OsbuildArtifact.ExportName, jobTarget.OsbuildArtifact.ExportFilename))
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorKojiBuild, fmt.Sprintf("failed to open the image for reading: %v", err), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorKojiBuild, fmt.Sprintf("failed to open the image for reading: %v", err), nil)
|
||||
break
|
||||
}
|
||||
defer file.Close()
|
||||
|
|
@ -1017,7 +1017,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
imageHash, imageSize, err := kojiAPI.Upload(file, targetOptions.UploadDirectory, jobTarget.ImageName)
|
||||
if err != nil {
|
||||
logWithId.Warnf("[Koji] ⬆ upload failed: %v", err) // DON'T EDIT: used for Splunk dashboard
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
logWithId.Info("[Koji] 🎉 Image successfully uploaded")
|
||||
|
|
@ -1026,7 +1026,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
err = json.Indent(&manifest, jobArgs.Manifest, "", " ")
|
||||
if err != nil {
|
||||
logWithId.Warnf("[Koji] Indenting osbuild manifest failed: %v", err)
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorKojiBuild, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorKojiBuild, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
logWithId.Info("[Koji] ⬆ Uploading the osbuild manifest")
|
||||
|
|
@ -1034,7 +1034,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
manifestHash, manifestSize, err := kojiAPI.Upload(&manifest, targetOptions.UploadDirectory, manifestFilename)
|
||||
if err != nil {
|
||||
logWithId.Warnf("[Koji] ⬆ upload failed: %v", err)
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
logWithId.Info("[Koji] 🎉 Manifest successfully uploaded")
|
||||
|
|
@ -1043,7 +1043,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
err = osbuildJobResult.OSBuildOutput.Write(&osbuildLog)
|
||||
if err != nil {
|
||||
logWithId.Warnf("[Koji] Converting osbuild log to text failed: %v", err)
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorKojiBuild, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorKojiBuild, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
logWithId.Info("[Koji] ⬆ Uploading the osbuild output log")
|
||||
|
|
@ -1051,7 +1051,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
osbuildOutputHash, osbuildOutputSize, err := kojiAPI.Upload(&osbuildLog, targetOptions.UploadDirectory, osbuildOutputFilename)
|
||||
if err != nil {
|
||||
logWithId.Warnf("[Koji] ⬆ upload failed: %v", err)
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
logWithId.Info("[Koji] 🎉 osbuild output log successfully uploaded")
|
||||
|
|
@ -1112,14 +1112,14 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
PrivateKey: targetOptions.PrivateKey,
|
||||
})
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
logWithId.Info("[OCI] 🔑 Logged in OCI")
|
||||
logWithId.Info("[OCI] ⬆ Uploading the image")
|
||||
file, err := os.Open(path.Join(outputDirectory, jobTarget.OsbuildArtifact.ExportName, jobTarget.OsbuildArtifact.ExportFilename))
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
defer file.Close()
|
||||
|
|
@ -1139,7 +1139,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
file,
|
||||
)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -1155,7 +1155,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
jobTarget.ImageName,
|
||||
)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -1172,14 +1172,14 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
PrivateKey: targetOptions.PrivateKey,
|
||||
})
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
logWithId.Info("[OCI] 🔑 Logged in OCI")
|
||||
logWithId.Info("[OCI] ⬆ Uploading the image")
|
||||
file, err := os.Open(path.Join(outputDirectory, jobTarget.OsbuildArtifact.ExportName, jobTarget.OsbuildArtifact.ExportFilename))
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
defer file.Close()
|
||||
|
|
@ -1199,13 +1199,13 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
file,
|
||||
)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
uri, err := ociClient.PreAuthenticatedRequest(fmt.Sprintf("osbuild-upload-%d", i), bucket, namespace)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorGeneratingSignedURL, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorGeneratingSignedURL, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
logWithId.Info("[OCI] 🎉 Image uploaded and pre-authenticated request generated!")
|
||||
|
|
@ -1218,7 +1218,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
|
||||
client, err := impl.getContainerClient(destination, targetOptions)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -1233,7 +1233,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
|
||||
if err != nil {
|
||||
logWithId.Infof("[container] 🙁 Upload of '%s' failed: %v", sourceRef, err)
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
logWithId.Printf("[container] 🎉 Image uploaded (%s)!", digest.String())
|
||||
|
|
@ -1245,13 +1245,13 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
|
||||
client, err := impl.getPulpClient(targetOptions)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
url, err := client.UploadAndDistributeCommit(archivePath, targetOptions.Repository, targetOptions.BasePath)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
targetResult.TargetError = clienterrors.New(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
targetResult.Options = &target.PulpOSTreeTargetResultOptions{RepoURL: url}
|
||||
|
|
@ -1259,7 +1259,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
default:
|
||||
// TODO: we may not want to return completely here with multiple targets, because then no TargetErrors will be added to the JobError details
|
||||
// Nevertheless, all target errors will be still in the OSBuildJobResult.
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTarget, fmt.Sprintf("invalid target type: %s", jobTarget.Name), nil)
|
||||
osbuildJobResult.JobError = clienterrors.New(clienterrors.ErrorInvalidTarget, fmt.Sprintf("invalid target type: %s", jobTarget.Name), nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -1272,7 +1272,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
|
||||
targetErrors := osbuildJobResult.TargetErrors()
|
||||
if len(targetErrors) != 0 {
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorTargetError, "at least one target failed", targetErrors)
|
||||
osbuildJobResult.JobError = clienterrors.New(clienterrors.ErrorTargetError, "at least one target failed", targetErrors)
|
||||
} else {
|
||||
osbuildJobResult.Success = true
|
||||
osbuildJobResult.UploadStatus = "success"
|
||||
|
|
|
|||
|
|
@ -16,19 +16,19 @@ type OSTreeResolveJobImpl struct {
|
|||
func setError(err error, result *worker.OSTreeResolveJobResult) {
|
||||
switch err.(type) {
|
||||
case ostree.RefError:
|
||||
result.JobError = clienterrors.WorkerClientError(
|
||||
result.JobError = clienterrors.New(
|
||||
clienterrors.ErrorOSTreeRefInvalid,
|
||||
"Invalid OSTree ref",
|
||||
err.Error(),
|
||||
)
|
||||
case ostree.ResolveRefError:
|
||||
result.JobError = clienterrors.WorkerClientError(
|
||||
result.JobError = clienterrors.New(
|
||||
clienterrors.ErrorOSTreeRefResolution,
|
||||
"Error resolving OSTree ref",
|
||||
err.Error(),
|
||||
)
|
||||
default:
|
||||
result.JobError = clienterrors.WorkerClientError(
|
||||
result.JobError = clienterrors.New(
|
||||
clienterrors.ErrorOSTreeParamsInvalid,
|
||||
"Invalid OSTree parameters or parameter combination",
|
||||
err.Error(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue