From 823e0420eb3cd3eebbf15472cda0cfac85da14f6 Mon Sep 17 00:00:00 2001 From: Kirtana Ashok Date: Tue, 15 Aug 2023 12:55:56 -0700 Subject: [PATCH] Fix transfer service dependencies: - Fill OSVersion field of ocispec.Platform for windows OS in transfer service plugin init() - Do not return error from transfer service ReceiveStream if stream.Recv() returned context.Canceled error Signed-off-by: Kirtana Ashok --- pkg/transfer/streaming/stream.go | 2 +- platforms/platforms.go | 12 ++++++++++++ platforms/platforms_other.go | 4 ++++ platforms/platforms_windows.go | 8 ++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pkg/transfer/streaming/stream.go b/pkg/transfer/streaming/stream.go index cf77cb8b5..061fd172d 100644 --- a/pkg/transfer/streaming/stream.go +++ b/pkg/transfer/streaming/stream.go @@ -164,7 +164,7 @@ func ReceiveStream(ctx context.Context, stream streaming.Stream) io.Reader { } anyType, err := stream.Recv() if err != nil { - if errors.Is(err, io.EOF) { + if errors.Is(err, io.EOF) || errors.Is(err, context.Canceled) { err = nil } else { err = fmt.Errorf("received failed: %w", err) diff --git a/platforms/platforms.go b/platforms/platforms.go index 0254ec0c5..5aee03a7e 100644 --- a/platforms/platforms.go +++ b/platforms/platforms.go @@ -213,6 +213,10 @@ func Parse(specifier string) (specs.Platform, error) { p.Variant = cpuVariant() } + if p.OS == "windows" { + p.OSVersion = GetWindowsOsVersion() + } + return p, nil } @@ -235,6 +239,10 @@ func Parse(specifier string) (specs.Platform, error) { p.Variant = "" } + if p.OS == "windows" { + p.OSVersion = GetWindowsOsVersion() + } + return p, nil case 3: // we have a fully specified variant, this is rare @@ -244,6 +252,10 @@ func Parse(specifier string) (specs.Platform, error) { p.Variant = "v8" } + if p.OS == "windows" { + p.OSVersion = GetWindowsOsVersion() + } + return p, nil } diff --git a/platforms/platforms_other.go b/platforms/platforms_other.go index 03f4dcd99..59beeb3d1 100644 --- a/platforms/platforms_other.go +++ b/platforms/platforms_other.go @@ -28,3 +28,7 @@ func newDefaultMatcher(platform specs.Platform) Matcher { Platform: Normalize(platform), } } + +func GetWindowsOsVersion() string { + return "" +} diff --git a/platforms/platforms_windows.go b/platforms/platforms_windows.go index 950e2a2dd..733d18dde 100644 --- a/platforms/platforms_windows.go +++ b/platforms/platforms_windows.go @@ -17,7 +17,10 @@ package platforms import ( + "fmt" + specs "github.com/opencontainers/image-spec/specs-go/v1" + "golang.org/x/sys/windows" ) // NewMatcher returns a Windows matcher that will match on osVersionPrefix if @@ -32,3 +35,8 @@ func newDefaultMatcher(platform specs.Platform) Matcher { }, } } + +func GetWindowsOsVersion() string { + major, minor, build := windows.RtlGetNtVersionNumbers() + return fmt.Sprintf("%d.%d.%d", major, minor, build) +}