Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>
  • Loading branch information
xmudrii committed May 24, 2023
1 parent 34289aa commit d86f4ce
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 23 deletions.
5 changes: 3 additions & 2 deletions pkg/obs/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ limitations under the License.
package metadata

import (
"errors"
"fmt"
"os"

"github.com/sirupsen/logrus"
"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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions pkg/obs/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package options

import (
"fmt"
"errors"
"os"
"path/filepath"

Expand Down Expand Up @@ -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")
}
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/obs/specs/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package specs

import (
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -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)
Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions pkg/obs/specs/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions pkg/obs/specs/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/obs/specs/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package specs

import (
"bytes"
"errors"
"fmt"
"os"
"path/filepath"
Expand All @@ -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{}
Expand Down

0 comments on commit d86f4ce

Please sign in to comment.