From 0698b0c4d6cff08f2bc43d31f158e267461969c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B3=B0=E5=8F=8B?= Date: Sun, 25 Jun 2023 14:15:49 +0800 Subject: [PATCH] fix: deprecated docker field leads to failure of nydusify check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `NydusImage.Config.Config.ArgsEscaped` is present only for legacy compatibility with Docker and should not be used by new image builders. Nydusify (1.6 and above) ignores it, which is an expected behavior. This pr ignores comparision of it in nydusify checking, which leads to failure. Signed-off-by: 泰友 --- contrib/nydusify/pkg/checker/rule/manifest.go | 14 +++++++ .../pkg/checker/rule/manifest_test.go | 38 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 contrib/nydusify/pkg/checker/rule/manifest_test.go diff --git a/contrib/nydusify/pkg/checker/rule/manifest.go b/contrib/nydusify/pkg/checker/rule/manifest.go index 2ac1d2bf049..0e121016aa3 100644 --- a/contrib/nydusify/pkg/checker/rule/manifest.go +++ b/contrib/nydusify/pkg/checker/rule/manifest.go @@ -80,6 +80,20 @@ func (rule *ManifestRule) Validate() error { // Check Nydus image config with OCI image if rule.SourceParsed.OCIImage != nil { + + //nolint:staticcheck + // ignore static check SA1019 here. We have to assign deprecated field. + // + // Skip ArgsEscaped's Check + // + // This field is present only for legacy compatibility with Docker and + // should not be used by new image builders. Nydusify (1.6 and above) + // ignores it, which is an expected behavior. + // Also ignore it in check. + // + // Addition: [ArgsEscaped in spec](https://github.com/opencontainers/image-spec/pull/892) + rule.TargetParsed.NydusImage.Config.Config.ArgsEscaped = rule.SourceParsed.OCIImage.Config.Config.ArgsEscaped + ociConfig, err := json.Marshal(rule.SourceParsed.OCIImage.Config.Config) if err != nil { return errors.New("marshal oci image config") diff --git a/contrib/nydusify/pkg/checker/rule/manifest_test.go b/contrib/nydusify/pkg/checker/rule/manifest_test.go new file mode 100644 index 00000000000..1fa209966a3 --- /dev/null +++ b/contrib/nydusify/pkg/checker/rule/manifest_test.go @@ -0,0 +1,38 @@ +package rule + +import ( + "testing" + + "github.com/dragonflyoss/image-service/contrib/nydusify/pkg/parser" + "github.com/stretchr/testify/assert" + + v1 "github.com/opencontainers/image-spec/specs-go/v1" +) + +func TestManifestRuleValidate_IgnoreDeprecatedField(t *testing.T) { + source := &parser.Parsed{ + NydusImage: &parser.Image{ + Config: v1.Image{ + Config: v1.ImageConfig{ + ArgsEscaped: true, // deprecated field + }, + }, + }, + } + target := &parser.Parsed{ + NydusImage: &parser.Image{ + Config: v1.Image{ + Config: v1.ImageConfig{ + ArgsEscaped: false, + }, + }, + }, + } + + rule := ManifestRule{ + SourceParsed: source, + TargetParsed: target, + } + + assert.Nil(t, rule.Validate()) +}