Allow to just fetch individual requirements 78/1478/1
authorYolanda Robla <yroblamo@redhat.com>
Wed, 28 Aug 2019 11:32:20 +0000 (13:32 +0200)
committerYolanda Robla <yroblamo@redhat.com>
Wed, 28 Aug 2019 11:32:20 +0000 (13:32 +0200)
If we want to download requirements just for workloads
we will just need kustomize and kubectl. Allow to pass
a list of requirements to download (optional), so we
avoid downloading not needed requirements

Signed-off-by: Yolanda Robla <yroblamo@redhat.com>
Change-Id: I84d552a49eb82b0883faccfbf797afc1a4b23412

cmd/fetch_requirements.go
pkg/site/site.go

index e3f8942..a8a877a 100644 (file)
@@ -18,6 +18,7 @@ import (
        "fmt"
        "log"
        "os"
+       "strings"
 
        "gerrit.akraino.org/kni/installer/pkg/site"
        "github.com/spf13/cobra"
@@ -45,10 +46,18 @@ var fetchRequirementsCmd = &cobra.Command{
                        buildPath = fmt.Sprintf("%s/.kni", os.Getenv("HOME"))
                }
 
+               // check if we have a requirements list specified
+               var requirements []string
+               requirementsList, _ := cmd.Flags().GetString("requirements")
+               if len(requirementsList) > 0 {
+                       // strip list in array
+                       requirements = strings.Split(requirementsList, ",")
+               }
+
                // define a site object and proceed with requirements fetch
                s := site.New(siteRepo, buildPath)
                s.DownloadSite()
-               s.FetchRequirements()
+               s.FetchRequirements(requirements)
        },
 }
 
@@ -56,5 +65,5 @@ func init() {
        rootCmd.AddCommand(fetchRequirementsCmd)
 
        fetchRequirementsCmd.Flags().StringP("build_path", "", "", "Directory to use as build path. If that not exists, the installer will generate a default directory")
-
+       fetchRequirementsCmd.Flags().StringP("requirements", "", "", "Individual requirements list. It needs to be a list of requirements separated by commas. If not supplied, all requirements will be downloaded")
 }
index 3fe6917..b8e8a1b 100644 (file)
@@ -124,7 +124,7 @@ func (s Site) GetProfileFromSite() (string, string, string) {
 }
 
 // using the downloaded site content, fetches (and builds) the specified requirements
-func (s Site) FetchRequirements() {
+func (s Site) FetchRequirements(individualRequirements []string) {
        log.Println(fmt.Sprintf("Downloading requirements for %s", s.siteName))
        sitePath := fmt.Sprintf("%s/%s", s.buildPath, s.siteName)
 
@@ -162,7 +162,24 @@ func (s Site) FetchRequirements() {
 
                // requirements is composed of binary and source
                requirementsBits := strings.SplitN(strings.TrimSpace(requirementsLine), ":", 2)
-               r := requirements.New(strings.TrimSpace(requirementsBits[0]), strings.TrimSpace(requirementsBits[1]), fmt.Sprintf("%s/requirements", sitePath))
+               binaryName := strings.TrimSpace(requirementsBits[0])
+
+               // if we have individual requirements list, check if we have the requirement on it. Otherwise, skip
+               if len(individualRequirements) > 0 {
+                       foundReq := false
+                       for _, individualRequirement := range individualRequirements {
+                               if individualRequirement == binaryName {
+                                       foundReq = true
+                                       break
+                               }
+                       }
+                       if !foundReq {
+                               // skip this iteration
+                               log.Println(fmt.Sprintf("Binary %s not found in list, skipping", binaryName))
+                               continue
+                       }
+               }
+               r := requirements.New(binaryName, strings.TrimSpace(requirementsBits[1]), fmt.Sprintf("%s/requirements", sitePath))
                r.FetchRequirement()
        }