@@ -10,11 +10,12 @@ import (
1010 "time"
1111
1212 vcapi "github.com/jetstack/version-checker/pkg/api"
13+ vcchecker "github.com/jetstack/version-checker/pkg/checker"
14+ vcarchitecture "github.com/jetstack/version-checker/pkg/checker/architecture"
15+ vcsearch "github.com/jetstack/version-checker/pkg/checker/search"
16+ vcversion "github.com/jetstack/version-checker/pkg/checker/version"
1317 vcclient "github.com/jetstack/version-checker/pkg/client"
1418 vcselfhosted "github.com/jetstack/version-checker/pkg/client/selfhosted"
15- vcchecker "github.com/jetstack/version-checker/pkg/controller/checker"
16- vcsearch "github.com/jetstack/version-checker/pkg/controller/search"
17- vcversion "github.com/jetstack/version-checker/pkg/version"
1819 "github.com/sirupsen/logrus"
1920 v1 "k8s.io/api/core/v1"
2021 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -53,7 +54,9 @@ const (
5354type Config struct {
5455 // the version checker dg will also gather pods and so has the same options
5556 // as the dynamic datagatherer
56- Dynamic k8s.ConfigDynamic
57+ DynamicPod k8s.ConfigDynamic
58+ // the nodes information is also gathered by the version checker datagatherer
59+ DynamicNode k8s.ConfigDynamic
5760 VersionCheckerClientOptions vcclient.Options
5861 // Currently unused, but keeping to allow future config of VersionChecker
5962 VersionCheckerCheckerOptions vcapi.Options
@@ -77,13 +80,20 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
7780 return fmt .Errorf ("failed to unmarshal version checker config: %s" , err )
7881 }
7982
80- c .Dynamic .KubeConfigPath = aux .Dynamic .KubeConfigPath
81- c .Dynamic .ExcludeNamespaces = aux .Dynamic .ExcludeNamespaces
82- c .Dynamic .IncludeNamespaces = aux .Dynamic .IncludeNamespaces
83+ c .DynamicPod .KubeConfigPath = aux .Dynamic .KubeConfigPath
84+ c .DynamicPod .ExcludeNamespaces = aux .Dynamic .ExcludeNamespaces
85+ c .DynamicPod .IncludeNamespaces = aux .Dynamic .IncludeNamespaces
8386 // gvr must be pods for the version checker dg
84- c .Dynamic .GroupVersionResource .Group = ""
85- c .Dynamic .GroupVersionResource .Version = "v1"
86- c .Dynamic .GroupVersionResource .Resource = "pods"
87+ c .DynamicPod .GroupVersionResource .Group = ""
88+ c .DynamicPod .GroupVersionResource .Version = "v1"
89+ c .DynamicPod .GroupVersionResource .Resource = "pods"
90+ // node dynamic dg
91+ c .DynamicNode .KubeConfigPath = aux .Dynamic .KubeConfigPath
92+ c .DynamicNode .ExcludeNamespaces = []string {}
93+ c .DynamicNode .IncludeNamespaces = []string {}
94+ c .DynamicNode .GroupVersionResource .Group = ""
95+ c .DynamicNode .GroupVersionResource .Version = "v1"
96+ c .DynamicNode .GroupVersionResource .Resource = "nodes"
8797
8898 c .VersionCheckerClientOptions .Selfhosted = map [string ]* vcselfhosted.Options {}
8999 registryKindCounts := map [string ]int {}
@@ -200,7 +210,12 @@ func loadKeysFromPaths(keys []string, params map[string]string) (map[string]stri
200210// NewDataGatherer creates a new VersionChecker DataGatherer
201211func (c * Config ) NewDataGatherer (ctx context.Context ) (datagatherer.DataGatherer , error ) {
202212 // create the k8s DataGatherer to use when collecting pods
203- dynamicDg , err := c .Dynamic .NewDataGatherer (ctx )
213+ podDynamicDg , err := c .DynamicPod .NewDataGatherer (ctx )
214+ if err != nil {
215+ return nil , err
216+ }
217+ // create a data gatherer to use to collect nodes architecture information
218+ nodeDynamicDg , err := c .DynamicNode .NewDataGatherer (ctx )
204219 if err != nil {
205220 return nil , err
206221 }
@@ -219,13 +234,16 @@ func (c *Config) NewDataGatherer(ctx context.Context) (datagatherer.DataGatherer
219234 timeout ,
220235 vcversion .New (log , imageClient , timeout ),
221236 )
237+ architecture := vcarchitecture .New ()
222238
223239 // dg wraps version checker and dynamic client to request pods
224240 return & DataGatherer {
225241 ctx : ctx ,
226242 config : c ,
227- dynamicDg : dynamicDg ,
228- versionChecker : vcchecker .New (search ),
243+ podDynamicDg : podDynamicDg ,
244+ nodeDynamicDg : nodeDynamicDg ,
245+ nodeArchitecture : architecture ,
246+ versionChecker : vcchecker .New (search , architecture ),
229247 versionCheckerLog : log ,
230248 versionCheckerOptions : c .VersionCheckerCheckerOptions ,
231249 }, nil
@@ -235,7 +253,9 @@ func (c *Config) NewDataGatherer(ctx context.Context) (datagatherer.DataGatherer
235253type DataGatherer struct {
236254 ctx context.Context
237255 config * Config
238- dynamicDg datagatherer.DataGatherer
256+ podDynamicDg datagatherer.DataGatherer
257+ nodeDynamicDg datagatherer.DataGatherer
258+ nodeArchitecture * vcarchitecture.NodeMap
239259 versionChecker * vcchecker.Checker
240260 versionCheckerLog * logrus.Entry
241261 versionCheckerOptions vcapi.Options
@@ -257,9 +277,31 @@ type containerResult struct {
257277
258278// Fetch retrieves cluster information from GKE.
259279func (g * DataGatherer ) Fetch () (interface {}, error ) {
260- rawPods , err := g .dynamicDg .Fetch ()
280+ // Get nodes information to update version-checker architecture structure
281+ rawNodes , err := g .nodeDynamicDg .Fetch ()
261282 if err != nil {
262- return nil , err
283+ return nil , fmt .Errorf ("failed to fetch nodes: %v" , err )
284+ }
285+ nodes , ok := rawNodes .(* unstructured.UnstructuredList )
286+ if ! ok {
287+ return nil , fmt .Errorf ("failed to parse nodes loaded from DataGatherer" )
288+ }
289+ for _ , v := range nodes .Items {
290+ var node v1.Node
291+ err := runtime .DefaultUnstructuredConverter .FromUnstructured (v .Object , & node )
292+ if err != nil {
293+ return nil , fmt .Errorf ("failed to parse node from unstructured data: %v" , err )
294+ }
295+ // update version-checker's internal representation of the current cluster's nodes,
296+ // to correctly select the right OS and Architecture for the images
297+ if err = g .nodeArchitecture .Add (& node ); err != nil {
298+ return nil , fmt .Errorf ("failed to add node to version-checker architecture structure" )
299+ }
300+ }
301+
302+ rawPods , err := g .podDynamicDg .Fetch ()
303+ if err != nil {
304+ return nil , fmt .Errorf ("failed to fetch pods: %v" , err )
263305 }
264306
265307 pods , ok := rawPods .(* unstructured.UnstructuredList )
@@ -272,7 +314,7 @@ func (g *DataGatherer) Fetch() (interface{}, error) {
272314 var pod v1.Pod
273315 err = runtime .DefaultUnstructuredConverter .FromUnstructured (v .Object , & pod )
274316 if err != nil {
275- return nil , fmt .Errorf ("failed to parse pod from unstructured data" )
317+ return nil , fmt .Errorf ("failed to parse pod from unstructured data: %v" , err )
276318 }
277319
278320 var allContainers []v1.Container
0 commit comments