Skip to content

Commit d95bfc4

Browse files
committed
Detect gardenlinux platform and version
The os-release file is debian but with extra fields so add additional logic to our debian detection to check for those fields and return gardenlinux when present. Signed-off-by: Tim Smith <tsmith84@gmail.com>
1 parent 1c3f958 commit d95bfc4

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

providers/os/detector/detector_all.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,13 @@ var debian = &PlatformResolver{
179179
return false, nil
180180
}
181181

182-
pf.Version = strings.TrimSpace(string(c))
182+
// gardenlinux identifies itself as debian, but we want to set the proper name / version
183+
if osr["GARDENLINUX_VERSION"] != "" {
184+
pf.Name = "gardenlinux"
185+
pf.Version = osr["GARDENLINUX_VERSION"]
186+
} else {
187+
pf.Version = strings.TrimSpace(string(c))
188+
}
183189

184190
unamem, err := osrd.unamem()
185191
if err == nil {

providers/os/detector/detector_platform_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,3 +1050,14 @@ func TestEulerOSDetector(t *testing.T) {
10501050
assert.Equal(t, "x86_64", di.Arch, "os arch should be identified")
10511051
assert.Equal(t, []string{"euler", "linux", "unix", "os"}, di.Family)
10521052
}
1053+
1054+
func TestGardenLinuxDetector(t *testing.T) {
1055+
di, err := detectPlatformFromMock("./testdata/detect-gardenlinux.toml")
1056+
assert.Nil(t, err, "was able to create the provider")
1057+
1058+
assert.Equal(t, "gardenlinux", di.Name, "os name should be identified")
1059+
assert.Equal(t, "Garden Linux 934.0", di.Title, "os title should be identified")
1060+
assert.Equal(t, "x86_64", di.Arch, "os arch should be identified")
1061+
assert.Equal(t, []string{"debian", "linux", "unix", "os"}, di.Family)
1062+
assert.Equal(t, "934.0", di.Version, "os version should be identified")
1063+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[commands."uname -s"]
2+
stdout = "Linux"
3+
4+
[commands."uname -m"]
5+
stdout = "x86_64"
6+
7+
[commands."uname -r"]
8+
stdout = "4.9.125-linuxkit"
9+
10+
[files."/etc/os-release"]
11+
content = """
12+
PRETTY_NAME="Garden Linux 934.0"
13+
NAME="Debian GNU/Linux"
14+
VERSION_CODENAME=bookworm
15+
ID=debian
16+
HOME_URL="https://gardenlinux.io/"
17+
SUPPORT_URL="https://github.com/gardenlinux/gardenlinux"
18+
BUG_REPORT_URL="https://github.com/gardenlinux/gardenlinux/issues"
19+
GARDENLINUX_FEATURES=_slim,base,server,cloud,kvm,_nopkg,_prod
20+
GARDENLINUX_VERSION=934.0
21+
GARDENLINUX_VERSION_AT_BUILD=934.0
22+
GARDENLINUX_COMMIT_ID_LONG=86f69dcbf95d0ab9c6909421d4082449cae05e16
23+
GARDENLINUX_COMMIT_ID=86f69dc
24+
VERSION_CODENAME=934.0
25+
"""
26+
27+
[files."/etc/debian_version"]
28+
content = "bookworm/sid"

0 commit comments

Comments
 (0)