From a740801093dd060f07e2b6d0afcda6f73b6a5bb1 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 21 Jan 2025 15:49:57 +0100 Subject: [PATCH 1/3] Fix typo in docstring Signed-off-by: Evan Lezar --- pkg/cdi/spec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cdi/spec.go b/pkg/cdi/spec.go index f0231d81..6059e992 100644 --- a/pkg/cdi/spec.go +++ b/pkg/cdi/spec.go @@ -259,7 +259,7 @@ func SetSpecValidator(fn func(*cdi.Spec) error) { specValidator = fn } -// validateSpec validates the Spec using the extneral validator. +// validateSpec validates the Spec using the external validator. func validateSpec(raw *cdi.Spec) error { validatorLock.RLock() defer validatorLock.RUnlock() From f1abe95faa1dcdd08fe1c20708b98e4237771650 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 4 Feb 2025 20:13:52 +0100 Subject: [PATCH 2/3] Allow golangci-lint checks to annotate code in PRs Signed-off-by: Evan Lezar --- .github/workflows/golangci-lint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index cbb8e32f..28ec4eb8 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -11,6 +11,8 @@ permissions: contents: read # Optional: allow read access to pull request. Use with `only-new-issues` option. # pull-requests: read + # Optional: allow write access to checks to allow the action to annotate code in the PR. + checks: write jobs: golangci: From d68aa49df679824d0db7ec97105b22f5b22c82da Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 4 Feb 2025 14:05:35 +0100 Subject: [PATCH 3/3] Fix failing tests on Darwin Signed-off-by: Evan Lezar --- pkg/cdi/cache.go | 12 ++++++++++-- pkg/cdi/cache_test_darwin.go | 26 ++++++++++++++++++++++++++ pkg/cdi/cache_test_unix.go | 4 ++-- pkg/cdi/container-edits_test.go | 24 ++++++++++++++++-------- 4 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 pkg/cdi/cache_test_darwin.go diff --git a/pkg/cdi/cache.go b/pkg/cdi/cache.go index 04f15e02..d399c793 100644 --- a/pkg/cdi/cache.go +++ b/pkg/cdi/cache.go @@ -22,6 +22,7 @@ import ( "io/fs" "os" "path/filepath" + "runtime" "sort" "strings" "sync" @@ -529,6 +530,13 @@ func (w *watch) watch(fsw *fsnotify.Watcher, m *sync.Mutex, refresh func() error if watch == nil { return } + + eventMask := fsnotify.Rename | fsnotify.Remove | fsnotify.Write + // On macOS, we also need to watch for Create events. + if runtime.GOOS == "darwin" { + eventMask |= fsnotify.Create + } + for { select { case event, ok := <-watch.Events: @@ -536,10 +544,10 @@ func (w *watch) watch(fsw *fsnotify.Watcher, m *sync.Mutex, refresh func() error return } - if (event.Op & (fsnotify.Rename | fsnotify.Remove | fsnotify.Write)) == 0 { + if (event.Op & eventMask) == 0 { continue } - if event.Op == fsnotify.Write { + if event.Op == fsnotify.Write || event.Op == fsnotify.Create { if ext := filepath.Ext(event.Name); ext != ".json" && ext != ".yaml" { continue } diff --git a/pkg/cdi/cache_test_darwin.go b/pkg/cdi/cache_test_darwin.go new file mode 100644 index 00000000..b09ea6ff --- /dev/null +++ b/pkg/cdi/cache_test_darwin.go @@ -0,0 +1,26 @@ +//go:build darwin +// +build darwin + +/* + Copyright © 2021 The CDI Authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package cdi + +import "syscall" + +func osSync() { + _ = syscall.Sync() +} diff --git a/pkg/cdi/cache_test_unix.go b/pkg/cdi/cache_test_unix.go index 0ee5fb86..b7c44129 100644 --- a/pkg/cdi/cache_test_unix.go +++ b/pkg/cdi/cache_test_unix.go @@ -1,5 +1,5 @@ -//go:build !windows -// +build !windows +//go:build !windows && !darwin +// +build !windows,!darwin /* Copyright © 2021 The CDI Authors diff --git a/pkg/cdi/container-edits_test.go b/pkg/cdi/container-edits_test.go index aaa06203..9f01a6eb 100644 --- a/pkg/cdi/container-edits_test.go +++ b/pkg/cdi/container-edits_test.go @@ -17,6 +17,7 @@ package cdi import ( + "runtime" "testing" oci "github.com/opencontainers/runtime-spec/specs-go" @@ -303,6 +304,13 @@ func TestValidateContainerEdits(t *testing.T) { } func TestApplyContainerEdits(t *testing.T) { + nullDeviceMajor := int64(1) + nullDeviceMinor := int64(3) + if runtime.GOOS == "darwin" { + nullDeviceMajor = 3 + nullDeviceMinor = 2 + } + type testCase struct { name string spec *oci.Spec @@ -346,8 +354,8 @@ func TestApplyContainerEdits(t *testing.T) { { Path: "/dev/null", Type: "c", - Major: 1, - Minor: 3, + Major: nullDeviceMajor, + Minor: nullDeviceMinor, }, }, Resources: &oci.LinuxResources{ @@ -355,8 +363,8 @@ func TestApplyContainerEdits(t *testing.T) { { Allow: true, Type: "c", - Major: int64ptr(1), - Minor: int64ptr(3), + Major: &nullDeviceMajor, + Minor: &nullDeviceMinor, Access: "rwm", }, }, @@ -389,8 +397,8 @@ func TestApplyContainerEdits(t *testing.T) { { Path: "/dev/null", Type: "c", - Major: 1, - Minor: 3, + Major: nullDeviceMajor, + Minor: nullDeviceMinor, }, }, Resources: &oci.LinuxResources{ @@ -398,8 +406,8 @@ func TestApplyContainerEdits(t *testing.T) { { Allow: true, Type: "c", - Major: int64ptr(1), - Minor: int64ptr(3), + Major: &nullDeviceMajor, + Minor: &nullDeviceMinor, Access: "rwm", }, },