From ffcef9dc329fd3b4beb91d798758a7b5a4128587 Mon Sep 17 00:00:00 2001 From: Brandon Lum Date: Fri, 24 Jan 2020 15:46:30 +0000 Subject: [PATCH] Addressed nits Signed-off-by: Brandon Lum --- pkg/config/config.go | 6 +++--- pkg/server/image_pull.go | 3 ++- pkg/server/image_pull_test.go | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 2395f60d2..e0fa16694 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -153,7 +153,7 @@ type RegistryConfig struct { TLS *TLSConfig `toml:"tls" json:"tls"` } -type EncryptedImagesConfig struct { +type ImageEncryption struct { // KeyModel specifies the model of where keys should reside KeyModel string `toml:"key_model" json:"keyModel"` } @@ -167,8 +167,8 @@ type PluginConfig struct { CniConfig `toml:"cni" json:"cni"` // Registry contains config related to the registry Registry Registry `toml:"registry" json:"registry"` - // EncryptedImagesConfig contains config related to handling of encrypted images - EncryptedImagesConfig `toml:"image_encryption" json:"imageEncryption"` + // ImageEncryption contains config related to handling of encrypted images + ImageEncryption `toml:"image_encryption" json:"imageEncryption"` // DisableTCPService disables serving CRI on the TCP server. DisableTCPService bool `toml:"disable_tcp_service" json:"disableTCPService"` // StreamServerAddress is the ip address streaming server is listening on. diff --git a/pkg/server/image_pull.go b/pkg/server/image_pull.go index c5863ce84..ef4a24e70 100644 --- a/pkg/server/image_pull.go +++ b/pkg/server/image_pull.go @@ -414,7 +414,8 @@ func newTransport() *http.Transport { // addEncryptedImagesPullOpts adds the necessary pull options to a list of // pull options if enabled. func (c *criService) encryptedImagesPullOpts() []containerd.RemoteOpt { - if c.config.EncryptedImagesConfig.KeyModel == criconfig.EncryptionKeyModelNode { + if c.config.ImageEncryption.KeyModel == criconfig.EncryptionKeyModelNode || + c.config.ImageEncryption.KeyModel == "" { ltdd := imgcrypt.Payload{} decUnpackOpt := encryption.WithUnpackConfigApplyOpts(encryption.WithDecryptedUnpack(<dd)) opt := containerd.WithUnpackOpts([]containerd.UnpackOpt{decUnpackOpt}) diff --git a/pkg/server/image_pull_test.go b/pkg/server/image_pull_test.go index 95c920efc..8b474d57f 100644 --- a/pkg/server/image_pull_test.go +++ b/pkg/server/image_pull_test.go @@ -298,14 +298,14 @@ func TestEncryptedImagePullOpts(t *testing.T) { keyModel: criconfig.EncryptionKeyModelNode, expectedOpts: 1, }, - "no key model selected should not add any opts": { + "no key model selected should default to node key model": { keyModel: "", - expectedOpts: 0, + expectedOpts: 1, }, } { t.Logf("TestCase %q", desc) c := newTestCRIService() - c.config.EncryptedImagesConfig.KeyModel = test.keyModel + c.config.ImageEncryption.KeyModel = test.keyModel got := len(c.encryptedImagesPullOpts()) assert.Equal(t, test.expectedOpts, got) }