Skip to content
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

chore: explicitly pass the pkg name #2

Merged
merged 1 commit into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 5 additions & 26 deletions cmd/extensions-validator/cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ package cmd
import (
"errors"
"fmt"
"os"
"strings"

"github.com/blang/semver/v4"
"github.com/siderolabs/talos/pkg/machinery/extensions"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
)

var validateCmd = &cobra.Command{
Expand All @@ -29,22 +27,16 @@ var validateCmd = &cobra.Command{

var (
rootfsPath string
pkgFile string
pkgName string
)

func init() {
validateCmd.Flags().StringVar(&rootfsPath, "rootfs", "", "Path to the rootfs")
validateCmd.MarkFlagRequired("rootfs") //nolint:errcheck
validateCmd.Flags().StringVar(&pkgFile, "pkg-file", "", "Path to the pkg.yaml file")
validateCmd.Flags().StringVar(&pkgName, "pkg-name", "", "Pkg name defined in the pkg file")
rootCmd.AddCommand(validateCmd)
}

// PartialPkgFile represents a partial package file
// we only care about the name field.
type PartialPkgFile struct {
Name string `yaml:"name"`
}

func validateRootfs() error {
if rootfsPath == "" {
return errors.New("rootfs path is required")
Expand All @@ -55,22 +47,9 @@ func validateRootfs() error {
return fmt.Errorf("error loading extension: %w", err)
}

if pkgFile != "" {
// load the pkg file
pkgFileData, err := os.ReadFile(pkgFile)
if err != nil {
return fmt.Errorf("error loading pkg file: %w", err)
}

var pkg PartialPkgFile

// unmarshal the pkg file
if err := yaml.Unmarshal(pkgFileData, &pkg); err != nil {
return fmt.Errorf("error unmarshalling pkg file: %w", err)
}

if pkg.Name != extension.Manifest.Metadata.Name {
return fmt.Errorf("pkg name does not match extension name: %s != %s", pkg.Name, extension.Manifest.Metadata.Name)
if pkgName != "" {
if pkgName != extension.Manifest.Metadata.Name {
return fmt.Errorf("pkg name does not match extension name: %s != %s", pkgName, extension.Manifest.Metadata.Name)
}
}

Expand Down