@@ -35,9 +35,14 @@ func NewKubeReconciler(
3535 interval time.Duration ,
3636 channel string ,
3737) * ClusterVersionScheduler {
38+ // If no channel is specified, return nil to indicate disabled
39+ if channel == "" {
40+ log .Info ("Kubernetes version checking disabled (no channel specified)" )
41+ return nil
42+ }
3843
3944 return & ClusterVersionScheduler {
40- log : log ,
45+ log : log . WithField ( "channel" , channel ) ,
4146 client : kubernetes .NewForConfigOrDie (config ),
4247 interval : interval ,
4348 metrics : metrics ,
@@ -47,7 +52,7 @@ func NewKubeReconciler(
4752
4853func (s * ClusterVersionScheduler ) Start (ctx context.Context ) error {
4954 go s .runScheduler (ctx )
50- return s .reconcile (ctx )
55+ return s .reconcile ()
5156}
5257
5358func (s * ClusterVersionScheduler ) runScheduler (ctx context.Context ) {
@@ -63,14 +68,14 @@ func (s *ClusterVersionScheduler) runScheduler(ctx context.Context) {
6368 s .log .Info ("ClusterVersionScheduler stopping" )
6469 return
6570 case <- ticker .C :
66- if err := s .reconcile (ctx ); err != nil {
71+ if err := s .reconcile (); err != nil {
6772 s .log .Error (err , "Failed to reconcile cluster version" )
6873 }
6974 }
7075 }
7176}
7277
73- func (s * ClusterVersionScheduler ) reconcile (_ context. Context ) error {
78+ func (s * ClusterVersionScheduler ) reconcile () error {
7479 // Get current cluster version
7580 current , err := s .client .Discovery ().ServerVersion ()
7681 if err != nil {
@@ -110,11 +115,21 @@ func (s *ClusterVersionScheduler) reconcile(_ context.Context) error {
110115}
111116
112117func getLatestVersion (channel string ) (string , error ) {
118+ // Always use upstream Kubernetes channels - this is the authoritative source
119+ // Platform detection is kept for logging purposes only
120+ return getLatestVersionFromUpstream (channel )
121+ }
122+
123+ func getLatestVersionFromUpstream (channel string ) (string , error ) {
124+ // Validate channel - only allow known Kubernetes channels
125+ if ! isValidKubernetesChannel (channel ) {
126+ return "" , fmt .Errorf ("unsupported channel: %s. Valid channels: stable, latest, latest-1.xx" , channel )
127+ }
128+
113129 if ! strings .HasSuffix (channel , ".txt" ) {
114130 channel += ".txt"
115131 }
116132
117- // Use url.JoinPath to safely join the base URL and channel path
118133 channelURL , err := url .JoinPath (channelURLSuffix , channel )
119134 if err != nil {
120135 return "" , fmt .Errorf ("failed to join channel URL: %w" , err )
@@ -124,18 +139,13 @@ func getLatestVersion(channel string) (string, error) {
124139 client .RetryMax = 3
125140 client .RetryWaitMin = 1 * time .Second
126141 client .RetryWaitMax = 30 * time .Second
127- // Optional: Log using your own logrus/logr logger
128142 client .Logger = nil
129143
130144 resp , err := client .Get (channelURL )
131145 if err != nil {
132146 return "" , fmt .Errorf ("failed to fetch from channel URL %s: %w" , channelURL , err )
133147 }
134- defer func () {
135- if cerr := resp .Body .Close (); cerr != nil {
136- fmt .Printf ("warning: failed to close response body: %v\n " , cerr )
137- }
138- }()
148+ defer resp .Body .Close ()
139149
140150 if resp .StatusCode != 200 {
141151 return "" , fmt .Errorf ("unexpected status code %d when fetching channel %s" , resp .StatusCode , channel )
@@ -153,3 +163,20 @@ func getLatestVersion(channel string) (string, error) {
153163
154164 return version , nil
155165}
166+
167+ func isValidKubernetesChannel (channel string ) bool {
168+ // Only allow official Kubernetes channels
169+ validChannels := []string {"stable" , "latest" }
170+
171+ // Allow latest-X.Y format
172+ if strings .HasPrefix (channel , "latest-1." ) {
173+ return true
174+ }
175+
176+ for _ , valid := range validChannels {
177+ if channel == valid {
178+ return true
179+ }
180+ }
181+ return false
182+ }
0 commit comments