-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mcbs] Validate rpm-ostree version is new enough #2859
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,12 @@ import ( | |
"fmt" | ||
"os" | ||
"os/exec" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/containers/image/v5/types" | ||
yaml "github.com/ghodss/yaml" | ||
"github.com/golang/glog" | ||
"github.com/opencontainers/go-digest" | ||
pivotutils "github.com/openshift/machine-config-operator/pkg/daemon/pivot/utils" | ||
|
@@ -20,8 +22,21 @@ const ( | |
numRetriesNetCommands = 5 | ||
// Pull secret. Written by the machine-config-operator | ||
kubeletAuthFile = "/var/lib/kubelet/config.json" | ||
|
||
// rpmOstreeVersionMinimum is the minimum required version | ||
rpmOstreeVersionMinimum = "2021.14" | ||
) | ||
|
||
// rpmOstreeVersionOuter is YAML output by `rpm-ostree --version` | ||
type rpmOstreeVersionOuter struct { | ||
Root rpmOstreeVersionData `json:"rpm-ostree"` | ||
} | ||
|
||
type rpmOstreeVersionData struct { | ||
Version string `json:"Version"` | ||
Features []string `json:"Features"` | ||
} | ||
|
||
// rpmOstreeState houses zero or more RpmOstreeDeployments | ||
// Subset of `rpm-ostree status --json` | ||
// https://github.com/projectatomic/rpm-ostree/blob/bce966a9812df141d38e3290f845171ec745aa4e/src/daemon/rpmostreed-deployment-utils.c#L227 | ||
|
@@ -100,6 +115,60 @@ func (r *RpmOstreeClient) loadStatus() (*rpmOstreeState, error) { | |
return &rosState, nil | ||
} | ||
|
||
func parseVer(s string) ([]int, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rust has totally spoiled me. I find it soooo hard to write code like this. In Rust it's just that simple and elegant: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3709150890266cfee1f09a35c1f7391f There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. colin we're not rewriting openshift in rust. at least... not yet. ;) |
||
r := []int{} | ||
for _, s := range strings.Split(s, ".") { | ||
n, err := strconv.Atoi(s) | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed to parse %s: %v", s, err) | ||
} | ||
r = append(r, n) | ||
} | ||
return r, nil | ||
} | ||
|
||
func validateVersion(current rpmOstreeVersionOuter) error { | ||
requiredVer, err := parseVer(rpmOstreeVersionMinimum) | ||
if err != nil { | ||
return err | ||
} | ||
curVer, err := parseVer(current.Root.Version) | ||
if err != nil { | ||
return err | ||
} | ||
if len(curVer) < len(requiredVer) { | ||
return fmt.Errorf("Too few components in %s, expected to match %s", current.Root.Version, rpmOstreeVersionMinimum) | ||
} | ||
for i, v := range requiredVer { | ||
if curVer[i] < v { | ||
return fmt.Errorf("Too old %s, expected to match %s", current.Root.Version, rpmOstreeVersionMinimum) | ||
} | ||
// Shortcut for e.g. 2022 > 2021 | ||
if curVer[i] > v { | ||
return nil | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func checkNodeRpmOstreeVersion() error { | ||
versionBytes, err := runGetOut("rpm-ostree", "--version") | ||
if err != nil { | ||
return err | ||
} | ||
var versionData rpmOstreeVersionOuter | ||
if err := yaml.Unmarshal(versionBytes, &versionData); err != nil { | ||
return fmt.Errorf("failed to parse rpm-ostree --version as YAML: %v", err) | ||
} | ||
|
||
if err := validateVersion(versionData); err != nil { | ||
return fmt.Errorf("Too old rpm-ostree: %v", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (r *RpmOstreeClient) Initialize() error { | ||
// This replicates https://github.com/coreos/rpm-ostree/pull/2945 | ||
// and can be removed when we have a new enough rpm-ostree with | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice idea for sanity check (aside from immediate mcbs use) 1 q from that pov: would hardcoding directly in file might make it go stale over time? how often would we expect this to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we wouldn't change this too often. In practice, we'll just know out of band when we're using a new feature - it'll have landed in rhel 8.z or fast tracked into OCP.
I honestly don't have a really strong opinion on actually merging this patch. We can drop it too when we look at merging the mcbs branch.
But for now it'll be a sanity check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense to me!