From d86f4ce0d260039e853010e3e5b3489184705830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mudrini=C4=87?= Date: Wed, 24 May 2023 23:55:58 +0200 Subject: [PATCH] Address review comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marko Mudrinić --- pkg/obs/metadata/metadata.go | 5 +++-- pkg/obs/options/options.go | 12 ++++++------ pkg/obs/specs/archive.go | 5 +++-- pkg/obs/specs/helpers.go | 6 +----- pkg/obs/specs/specs.go | 8 +------- pkg/obs/specs/template.go | 3 ++- 6 files changed, 16 insertions(+), 23 deletions(-) diff --git a/pkg/obs/metadata/metadata.go b/pkg/obs/metadata/metadata.go index 0c8ae4c3091..2152beaa0f3 100644 --- a/pkg/obs/metadata/metadata.go +++ b/pkg/obs/metadata/metadata.go @@ -17,6 +17,7 @@ limitations under the License. package metadata import ( + "errors" "fmt" "os" @@ -24,7 +25,7 @@ import ( "sigs.k8s.io/yaml" ) -// PackageMetadata is a struct that containts the following information about a package: +// PackageMetadata is a struct that contains the following information about a package: // - URL from which to download artifacts needed to build the package // - Indicator if artifacts are packed in a .tar.gz archive // - Dependencies needed to install the package @@ -54,7 +55,7 @@ type PackageMetadataList map[string][]PackageMetadata // LoadPackageMetadata loads metadata.yaml file from the given path. func LoadPackageMetadata(path string) (PackageMetadataList, error) { if path == "" { - return nil, fmt.Errorf("path cannot be empty") + return nil, errors.New("path cannot be empty") } logrus.Infof("Loading metadata from %s...", path) diff --git a/pkg/obs/options/options.go b/pkg/obs/options/options.go index 0e50985ab7f..b99a5373383 100644 --- a/pkg/obs/options/options.go +++ b/pkg/obs/options/options.go @@ -17,7 +17,7 @@ limitations under the License. package options import ( - "fmt" + "errors" "os" "path/filepath" @@ -128,21 +128,21 @@ func New() *Options { // Validate verifies if all set options are valid func (o *Options) Validate() error { if ok := isSupported("package", []string{o.Package}, supportedPackages); !ok { - return fmt.Errorf("selected package is not supported") + return errors.New("selected package is not supported") } if ok := isSupported("channel", []string{o.Channel}, supportedChannels); !ok { - return fmt.Errorf("selected channel is not supported") + return errors.New("selected channel is not supported") } if ok := isSupported("architectures", o.Architectures, supportedArchitectures); !ok { - return fmt.Errorf("architectures selection is not supported") + return errors.New("architectures selection is not supported") } if o.Revision == "" { - return fmt.Errorf("revision is required") + return errors.New("revision is required") } if o.SpecOutputPath != "" { if _, err := os.Stat(o.SpecOutputPath); err != nil { - return fmt.Errorf("output dir doesn't exist") + return errors.New("output dir doesn't exist") } } diff --git a/pkg/obs/specs/archive.go b/pkg/obs/specs/archive.go index e281210bd64..1d24169419d 100644 --- a/pkg/obs/specs/archive.go +++ b/pkg/obs/specs/archive.go @@ -17,6 +17,7 @@ limitations under the License. package specs import ( + "errors" "fmt" "io" "net/http" @@ -35,7 +36,7 @@ import ( // This archive is used as a source for artifacts by OpenBuildService when building the package. func (c *Client) BuildArtifactsArchive(pkgDef *PackageDefinition) error { if pkgDef == nil { - return fmt.Errorf("package definition cannot be nil") + return errors.New("package definition cannot be nil") } logrus.Infof("Downloading artifacts for %s %s...", pkgDef.Name, pkgDef.Version) @@ -51,7 +52,7 @@ func (c *Client) BuildArtifactsArchive(pkgDef *PackageDefinition) error { } } - logrus.Debug("Saving downloaded artifacts to temporary location %s...", dlRootPath) + logrus.Debugf("Saving downloaded artifacts to temporary location %s...", dlRootPath) var dlPath string var dlTarGz bool diff --git a/pkg/obs/specs/helpers.go b/pkg/obs/specs/helpers.go index c5b59f012d0..91f3815ff65 100644 --- a/pkg/obs/specs/helpers.go +++ b/pkg/obs/specs/helpers.go @@ -29,11 +29,7 @@ import ( func isCoreKubernetesPackage(packageName string) bool { switch packageName { - case options.PackageKubeadm: - fallthrough - case options.PackageKubectl: - fallthrough - case options.PackageKubelet: + case options.PackageKubeadm, options.PackageKubectl, options.PackageKubelet: return true default: return false diff --git a/pkg/obs/specs/specs.go b/pkg/obs/specs/specs.go index 3b3dc5df3fc..29ce99890b0 100644 --- a/pkg/obs/specs/specs.go +++ b/pkg/obs/specs/specs.go @@ -201,13 +201,7 @@ func getMetadataWithVersionConstraint(packageName, packageVersion string, constr // getPackageSource gets the download link for artifacts for the given package. // This function runs template on sourceURLTemplate defined in the metadata manifest. -func (c *Client) getPackageSource( - templateBaseURL, - baseURL, - packageName, - packageVersion, - packageArch, - channel string) (string, error) { +func (c *Client) getPackageSource(templateBaseURL, baseURL, packageName, packageVersion, packageArch, channel string) (string, error) { data := struct { BaseURL string PackageName string diff --git a/pkg/obs/specs/template.go b/pkg/obs/specs/template.go index 7aa043fe05c..230d7977372 100644 --- a/pkg/obs/specs/template.go +++ b/pkg/obs/specs/template.go @@ -18,6 +18,7 @@ package specs import ( "bytes" + "errors" "fmt" "os" "path/filepath" @@ -37,7 +38,7 @@ type work struct { // BuildSpecs creates spec file based on provided package definition. func (c *Client) BuildSpecs(pkgDef *PackageDefinition, specOnly bool) (err error) { if pkgDef == nil { - return fmt.Errorf("package definition cannot be nil") + return errors.New("package definition cannot be nil") } workItems := []work{}