-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from siemens/develop
Develop
- Loading branch information
Showing
33 changed files
with
5,534 additions
and
5,482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,10 @@ | |
# Nota bene: not all existing value combinations with respect to Alpine and Node | ||
# versions might work, so you'll need to check Docker hub for the available base | ||
# image versions. | ||
ARG ALPINE_VERSION=3.19 | ||
ARG ALPINE_PATCH=1 | ||
ARG GO_VERSION=1.22.2 | ||
ARG NODE_VERSION=21 | ||
ARG ALPINE_VERSION=3.20 | ||
ARG ALPINE_PATCH=2 | ||
ARG GO_VERSION=1.22.5 | ||
ARG NODE_VERSION=20 | ||
|
||
# Go build settings | ||
ARG LDFLAGS="-s -w -extldflags=-static" | ||
|
@@ -166,7 +166,7 @@ RUN setcap "cap_sys_admin,cap_sys_chroot,cap_sys_ptrace,cap_dac_read_search,cap_ | |
# | ||
# In the final stage we now "only" need to install the gostwire service binary | ||
# and its web ui application into the final image. | ||
FROM alpine:${ALPINE_VERSION}.${ALPINE_PATCH} as final | ||
FROM alpine:${ALPINE_VERSION}.${ALPINE_PATCH} AS final | ||
LABEL maintainer="Harald Albrecht <[email protected]>" | ||
ARG ALPINE_VERSION | ||
ARG GOLANG_VERSION | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// (c) Siemens AG 2024 | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
package cpus | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/siemens/ghostwire/v2/metadata" | ||
"github.com/thediveo/go-plugger/v3" | ||
"github.com/thediveo/lxkns/log" | ||
"github.com/thediveo/lxkns/model" | ||
|
||
gostwire "github.com/siemens/ghostwire/v2" | ||
) | ||
|
||
func init() { | ||
plugger.Group[metadata.Metadata]().Register( | ||
Metadata, plugger.WithPlugin("cpus")) | ||
} | ||
|
||
// Metadata returns metadata describing certain aspects of the host the | ||
// discovery was run on, such as its host name, OS version, ... | ||
func Metadata(r gostwire.DiscoveryResult) map[string]interface{} { | ||
onlinecpus, err := os.ReadFile("/sys/devices/system/cpu/online") | ||
if err != nil { | ||
log.Errorf("cannot retrieve list of online cpus, reason: %s", err.Error()) | ||
return nil | ||
} | ||
cpulist := parseCPUList(strings.TrimSuffix(string(onlinecpus), "\n")) | ||
if cpulist == nil { | ||
log.Errorf("malformed /sys/devices/system/cpu/online") | ||
return nil | ||
} | ||
return map[string]interface{}{ | ||
"cpus": cpulist, | ||
} | ||
} | ||
|
||
// parseCPUList parses the textual representation of a CPU list in form of | ||
// comma-separated CPU ranges, returning the CPUList if successful; otherwise, | ||
// it returns nil. | ||
func parseCPUList(cpus string) (list model.CPUList) { | ||
for cpus != "" { | ||
cpurange := cpus | ||
sepIdx := strings.Index(cpus, ",") | ||
if sepIdx < 0 { | ||
// final range, so there won't be any further ranges | ||
cpus = "" | ||
} else { | ||
// intermediate range... | ||
cpurange = cpus[:sepIdx] | ||
cpus = cpus[sepIdx+1:] | ||
// ...there needs to be something following, so no hanging commas. | ||
if cpus == "" { | ||
return nil | ||
} | ||
} | ||
dashIdx := strings.Index(cpurange, "-") | ||
if dashIdx < 0 { | ||
// single CPU number | ||
cpuno, err := strconv.ParseUint(cpurange, 10, 32) | ||
if err != nil { | ||
return nil | ||
} | ||
list = append(list, [2]uint{uint(cpuno), uint(cpuno)}) | ||
continue | ||
} | ||
// CPU number range | ||
fromcpu, err := strconv.ParseUint(cpurange[:dashIdx], 10, 32) | ||
if err != nil { | ||
return nil | ||
} | ||
tocpu, err := strconv.ParseUint(cpurange[dashIdx+1:], 10, 32) | ||
if err != nil { | ||
return nil | ||
} | ||
list = append(list, [2]uint{uint(fromcpu), uint(tocpu)}) | ||
} | ||
return list | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// (c) Siemens AG 2024 | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
package cpus | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/thediveo/lxkns/model" | ||
) | ||
|
||
var _ = Describe("CPUs online", func() { | ||
|
||
DescribeTable("parsing CPU ranges", | ||
func(cpus string, expected model.CPUList) { | ||
Expect(parseCPUList(cpus)).To(Equal(expected)) | ||
}, | ||
Entry(nil, "", nil), | ||
Entry(nil, "abc", nil), | ||
Entry(nil, "42,", nil), | ||
Entry(nil, "42-", nil), | ||
Entry(nil, "42-abc", nil), | ||
Entry(nil, "def-42", nil), | ||
Entry(nil, "42", model.CPUList{{42, 42}}), | ||
Entry(nil, "42,43", model.CPUList{{42, 42}, {43, 43}}), | ||
Entry(nil, "1-42", model.CPUList{{1, 42}}), | ||
Entry(nil, "1-42,555,666-667", model.CPUList{{1, 42}, {555, 555}, {666, 667}}), | ||
) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
Package cpus provides a metadata plugin returning information about the CPUs in | ||
the system that are currently “online”. | ||
The information about the CPUs being online is taken from | ||
“/sys/devices/system/cpu/online” (a list of CPU ranges in textual format, | ||
separated by commas). | ||
The (JSON) metadata is structured (inside “metadata”) as follows: | ||
- “cpus”: slice of two-elements slice ranges. | ||
*/ | ||
package cpus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// (c) Siemens AG 2024 | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
package cpus | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestMetadataCPUs(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "ghostwire/metadata/cpus package") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// (c) Siemens AG 2023 | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
package metadata | ||
|
||
import ( | ||
|
Oops, something went wrong.