Skip to content

Commit

Permalink
use argument to get images url (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
tashima42 committed Jul 30, 2024
1 parent 5dbd7b9 commit c5c4c0e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
13 changes: 10 additions & 3 deletions cmd/release/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
k3sMilestone string

concurrencyLimit int
imagesListURL string
rancherMissingImagesJSONOutput bool
rke2PrevMilestone string
rke2Milestone string
Expand Down Expand Up @@ -120,12 +121,13 @@ var rancherGenerateMissingImagesListSubCmd = &cobra.Command{
if len(args) < 1 {
return errors.New("expected at least one argument: [version]")
}
checkImages := make([]string, 0)
version := args[0]
rancherRelease, found := rootConfig.Rancher.Versions[version]
if !found {
return errors.New("verify your config file, version not found: " + version)
if found {
checkImages = rancherRelease.CheckImages
}
missingImages, err := rancher.GenerateMissingImagesList(version, concurrencyLimit, rancherRelease.CheckImages)
missingImages, err := rancher.GenerateMissingImagesList(version, imagesListURL, concurrencyLimit, checkImages)
if err != nil {
return err
}
Expand Down Expand Up @@ -201,6 +203,11 @@ func init() {
// rancher generate missing-images-list
rancherGenerateMissingImagesListSubCmd.Flags().IntVarP(&concurrencyLimit, "concurrency-limit", "c", 3, "Concurrency Limit")
rancherGenerateMissingImagesListSubCmd.Flags().BoolVarP(&rancherMissingImagesJSONOutput, "json", "j", false, "JSON Output")
rancherGenerateMissingImagesListSubCmd.Flags().StringVarP(&imagesListURL, "images-list-url", "i", "", "URL of the artifact containing all images for a given version 'rancher-images.txt' (required)")
if err := rancherGenerateMissingImagesListSubCmd.MarkFlagRequired("images-list-url"); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}

// rancher generate docker-images-digests
rancherGenerateDockerImagesDigestsSubCmd.Flags().StringVarP(&rancherImagesDigestsOutputFile, "output-file", "o", "", "Output file with images digests")
Expand Down
10 changes: 5 additions & 5 deletions release/rancher/rancher.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,20 +386,20 @@ func formatContentLine(line string) string {
return strings.TrimSpace(line)
}

func GenerateMissingImagesList(version string, concurrencyLimit int, images []string) ([]string, error) {
func GenerateMissingImagesList(version, imagesListURL string, concurrencyLimit int, images []string) ([]string, error) {
if !semver.IsValid(version) {
return nil, errors.New("version is not a valid semver: " + version)
}
if len(images) == 0 {
const rancherWindowsImagesFile = "rancher-windows-images.txt"
const rancherImagesFile = "rancher-images.txt"

rancherWindowsImages, err := rancherPrimeArtifact(version, rancherWindowsImagesFile)
rancherWindowsImages, err := rancherPrimeArtifact(imagesListURL)
if err != nil {
return nil, errors.New("failed to get rancher windows images: " + err.Error())
}

rancherImages, err := rancherPrimeArtifact(version, rancherImagesFile)
rancherImages, err := rancherPrimeArtifact(imagesListURL)
if err != nil {
return nil, errors.New("failed to get rancher images: " + err.Error())
}
Expand Down Expand Up @@ -679,9 +679,9 @@ func registryAuth(authURL, service, image string) (string, error) {
return auth.Token, nil
}

func rancherPrimeArtifact(version, artifactName string) ([]string, error) {
func rancherPrimeArtifact(url string) ([]string, error) {
httpClient := ecmHTTP.NewClient(time.Second * 15)
res, err := httpClient.Get(rancherArtifactsBaseURL + "/rancher/" + version + "/" + artifactName)
res, err := httpClient.Get(url)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit c5c4c0e

Please sign in to comment.