Skip to content

Commit

Permalink
Use statis OS version in node agent
Browse files Browse the repository at this point in the history
  • Loading branch information
afritzler committed Dec 3, 2024
1 parent e1508fb commit 460d5a8
Showing 1 changed file with 34 additions and 36 deletions.
70 changes: 34 additions & 36 deletions pkg/nodeagent/controller/operatingsystemconfig/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package operatingsystemconfig

import (
"bufio"
"bytes"
"context"
"errors"
Expand All @@ -15,8 +14,6 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strings"
"time"

machinev1alpha1 "github.com/gardener/machine-controller-manager/pkg/apis/machine/v1alpha1"
Expand Down Expand Up @@ -651,39 +648,40 @@ func (r *Reconciler) rebootstrapKubelet(ctx context.Context, log logr.Logger, no
}

func getOSVersion() (string, error) {
// Open the /etc/os-release file
file, err := os.Open("/etc/os-release")
if err != nil {
return "", fmt.Errorf("error reading /etc/os-release: %w", err)
}
defer file.Close()

scanner := bufio.NewScanner(file)
var prettyName string

// Look for the PRETTY_NAME line
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "PRETTY_NAME=") {
prettyName = strings.Trim(line, `PRETTY_NAME="`)
break
}
}

if err := scanner.Err(); err != nil {
return "", fmt.Errorf("error scanning /etc/os-release: %w", err)

}

// Extract the version using a regular expression
re := regexp.MustCompile(`\d+\.\d+`)
version := re.FindString(prettyName)

if version == "" {
return "", errors.New("version not found")
} else {
return version, nil
}
return "1592.2", nil
//// Open the /etc/os-release file
//file, err := os.Open("/etc/os-release")
//if err != nil {
// return "", fmt.Errorf("error reading /etc/os-release: %w", err)
//}
//defer file.Close()
//
//scanner := bufio.NewScanner(file)
//var prettyName string
//
//// Look for the PRETTY_NAME line
//for scanner.Scan() {
// line := scanner.Text()
// if strings.HasPrefix(line, "PRETTY_NAME=") {
// prettyName = strings.Trim(line, `PRETTY_NAME="`)
// break
// }
//}
//
//if err := scanner.Err(); err != nil {
// return "", fmt.Errorf("error scanning /etc/os-release: %w", err)
//
//}
//
//// Extract the version using a regular expression
//re := regexp.MustCompile(`\d+\.\d+`)
//version := re.FindString(prettyName)
//
//if version == "" {
// return "", errors.New("version not found")
//} else {
// return version, nil
//}
}

func (r *Reconciler) waitForKubeletHealth(ctx context.Context, log logr.Logger) error {
Expand Down

0 comments on commit 460d5a8

Please sign in to comment.