Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify discard unpacked layers setting #237

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [#237](https://github.com/XenitAB/spegel/pull/237) Verify discard unpacked layers setting.

### Changed

### Deprecated
Expand Down
8 changes: 8 additions & 0 deletions internal/oci/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,19 @@ func verifyStatusResponse(resp *runtimeapi.StatusResponse, configPath string) er
Registry struct {
ConfigPath string `json:"configPath"`
} `json:"registry"`
Containerd struct {
Runtimes struct {
DiscardUnpackedLayers bool `json:"discardUnpackedLayers"`
} `json:"runtimes"`
} `json:"containerd"`
}{}
err := json.Unmarshal([]byte(str), cfg)
if err != nil {
return err
}
if cfg.Containerd.Runtimes.DiscardUnpackedLayers {
return fmt.Errorf("Containerd discard unpacked layers cannot be enabled")
}
if cfg.Registry.ConfigPath == "" {
return fmt.Errorf("Containerd registry config path needs to be set for mirror configuration to take effect")
}
Expand Down
54 changes: 30 additions & 24 deletions internal/oci/containerd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,55 @@ import (

func TestVerifyStatusResponse(t *testing.T) {
tests := []struct {
name string
infoConfigPath string
configPath string
expectedErrMsg string
name string
configPath string
discardUnpackedLayers bool
requiredConfigPath string
expectedErrMsg string
}{
{
name: "empty config path",
infoConfigPath: "",
configPath: "/etc/containerd/certs.d",
expectedErrMsg: "Containerd registry config path needs to be set for mirror configuration to take effect",
name: "empty config path",
configPath: "",
requiredConfigPath: "/etc/containerd/certs.d",
expectedErrMsg: "Containerd registry config path needs to be set for mirror configuration to take effect",
},
{
name: "single config path",
infoConfigPath: "/etc/containerd/certs.d",
configPath: "/etc/containerd/certs.d",
name: "single config path",
configPath: "/etc/containerd/certs.d",
requiredConfigPath: "/etc/containerd/certs.d",
},
{
name: "missing single config path",
infoConfigPath: "/etc/containerd/certs.d",
configPath: "/var/lib/containerd/certs.d",
expectedErrMsg: "Containerd registry config path is /etc/containerd/certs.d but needs to contain path /var/lib/containerd/certs.d for mirror configuration to take effect",
name: "missing single config path",
configPath: "/etc/containerd/certs.d",
requiredConfigPath: "/var/lib/containerd/certs.d",
expectedErrMsg: "Containerd registry config path is /etc/containerd/certs.d but needs to contain path /var/lib/containerd/certs.d for mirror configuration to take effect",
},
{
name: "multiple config paths",
infoConfigPath: "/etc/containerd/certs.d:/etc/docker/certs.d",
configPath: "/etc/containerd/certs.d",
name: "multiple config paths",
configPath: "/etc/containerd/certs.d:/etc/docker/certs.d",
requiredConfigPath: "/etc/containerd/certs.d",
},
{
name: "missing multiple config paths",
infoConfigPath: "/etc/containerd/certs.d:/etc/docker/certs.d",
configPath: "/var/lib/containerd/certs.d",
expectedErrMsg: "Containerd registry config path is /etc/containerd/certs.d:/etc/docker/certs.d but needs to contain path /var/lib/containerd/certs.d for mirror configuration to take effect",
name: "missing multiple config paths",
configPath: "/etc/containerd/certs.d:/etc/docker/certs.d",
requiredConfigPath: "/var/lib/containerd/certs.d",
expectedErrMsg: "Containerd registry config path is /etc/containerd/certs.d:/etc/docker/certs.d but needs to contain path /var/lib/containerd/certs.d for mirror configuration to take effect",
},
{
name: "discard unpacked layers enabled",
discardUnpackedLayers: true,
expectedErrMsg: "Containerd discard unpacked layers cannot be enabled",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resp := &runtimeapi.StatusResponse{
Info: map[string]string{
"config": fmt.Sprintf(`{"registry": {"configPath": "%s"}}`, tt.infoConfigPath),
"config": fmt.Sprintf(`{"registry": {"configPath": "%s"}, "containerd": {"runtimes":{"discardUnpackedLayers": %v}}}`, tt.configPath, tt.discardUnpackedLayers),
},
}
err := verifyStatusResponse(resp, tt.configPath)
err := verifyStatusResponse(resp, tt.requiredConfigPath)
if tt.expectedErrMsg != "" {
require.EqualError(t, err, tt.expectedErrMsg)
return
Expand Down
Loading