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

Reject dynakubes that use public image and not read only oneAgents (release-1.4) #4346

Merged
merged 3 commits into from
Jan 29, 2025
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
6 changes: 3 additions & 3 deletions pkg/api/validation/dynakube/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestImageFieldHasTenantImage(t *testing.T) {
Spec: dynakube.DynaKubeSpec{
APIURL: testTenantUrl + "/api",
OneAgent: dynakube.OneAgentSpec{
ClassicFullStack: &dynakube.HostInjectSpec{
HostMonitoring: &dynakube.HostInjectSpec{
Image: testRegistryUrl + "/linux/oneagent:latest",
},
},
Expand All @@ -71,7 +71,7 @@ func TestImageFieldHasTenantImage(t *testing.T) {
Spec: dynakube.DynaKubeSpec{
APIURL: testTenantUrl + "/api",
OneAgent: dynakube.OneAgentSpec{
ClassicFullStack: &dynakube.HostInjectSpec{
HostMonitoring: &dynakube.HostInjectSpec{
Image: testRegistryUrl + "/linux/oneagent:latest",
},
},
Expand All @@ -87,7 +87,7 @@ func TestImageFieldHasTenantImage(t *testing.T) {
Spec: dynakube.DynaKubeSpec{
APIURL: testTenantUrl + "/api",
OneAgent: dynakube.OneAgentSpec{
ClassicFullStack: &dynakube.HostInjectSpec{
HostMonitoring: &dynakube.HostInjectSpec{
Image: "127.0.0.1:5000/test:tag",
},
},
Expand Down
10 changes: 10 additions & 0 deletions pkg/api/validation/dynakube/oneagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Use a nodeSelector to avoid this conflict. Conflicting DynaKubes: %s`

errorVolumeStorageReadOnlyModeConflict = `The DynaKube specification specifies a read-only host file system while OneAgent has volume storage enabled.`

errorPublicImageWithWrongConfig = `The DynaKube specification specifies a custom (and therefor probably a public) image in combination with a mode that needs write permissions for volume mounts.`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
errorPublicImageWithWrongConfig = `The DynaKube specification specifies a custom (and therefor probably a public) image in combination with a mode that needs write permissions for volume mounts.`
errorPublicImageWithWrongConfig = `Custom OneAgent image is only supported when CSI Driver is used.`

It would be much nicer to have a guide in the official documentation to link to explaining the feature flag, but for now I think we can boil it down to this.


warningOneAgentInstallerEnvVars = `The environment variables ONEAGENT_INSTALLER_SCRIPT_URL and ONEAGENT_INSTALLER_TOKEN are only relevant for an unsupported image type. Please ensure you are using a supported image.`

warningHostGroupConflict = `The DynaKube specification sets the host group using the --set-host-group parameter. Instead, specify the new spec.oneagent.hostGroup field. If both settings are used, the new field takes precedence over the parameter.`
Expand Down Expand Up @@ -116,6 +118,14 @@ func mapKeysToString(m map[string]bool, sep string) string {
return strings.Join(keys, sep)
}

func publicImageSetWithoutReadOnlyMode(_ context.Context, v *Validator, dk *dynakube.DynaKube) string {
if !dk.UseReadOnlyOneAgents() && dk.CustomOneAgentImage() != "" {
return errorPublicImageWithWrongConfig
}

return ""
}

func imageFieldSetWithoutCSIFlag(_ context.Context, v *Validator, dk *dynakube.DynaKube) string {
if dk.ApplicationMonitoringMode() {
if len(dk.Spec.OneAgent.ApplicationMonitoring.CodeModulesImage) > 0 && !v.modules.CSIDriver {
Expand Down
44 changes: 44 additions & 0 deletions pkg/api/validation/dynakube/oneagent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,47 @@ func TestIsOneAgentVersionValid(t *testing.T) {
})
}
}

func TestPublicImageSetWithReadOnlyMode(t *testing.T) {
t.Run("reject dk with hostMon without csi and custom image", func(t *testing.T) {
setupDisabledCSIEnv(t)
assertDenied(t, []string{errorPublicImageWithWrongConfig},
&dynakube.DynaKube{
ObjectMeta: defaultDynakubeObjectMeta,
Spec: dynakube.DynaKubeSpec{
APIURL: testApiUrl,
OneAgent: dynakube.OneAgentSpec{
HostMonitoring: &dynakube.HostInjectSpec{
Image: "test/image/test-image:some-tag",
},
},
},
})
})
t.Run("allow dk with hostMon without csi and no custom image", func(t *testing.T) {
setupDisabledCSIEnv(t)
assertAllowed(t,
&dynakube.DynaKube{
ObjectMeta: defaultDynakubeObjectMeta,
Spec: dynakube.DynaKubeSpec{
APIURL: testApiUrl,
OneAgent: dynakube.OneAgentSpec{
HostMonitoring: &dynakube.HostInjectSpec{},
},
},
})
})
t.Run("allow dk with hostMon with csi and custom image", func(t *testing.T) {
assertAllowed(t, &dynakube.DynaKube{
ObjectMeta: defaultDynakubeObjectMeta,
Spec: dynakube.DynaKubeSpec{
APIURL: testApiUrl,
OneAgent: dynakube.OneAgentSpec{
HostMonitoring: &dynakube.HostInjectSpec{
Image: "test/image/test-image:some-tag",
},
},
},
})
})
}
1 change: 1 addition & 0 deletions pkg/api/validation/dynakube/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var (
missingLogMonitoringImage,
logMonitoringWithoutK8SMonitoring,
extensionsWithoutK8SMonitoring,
publicImageSetWithoutReadOnlyMode,
}
validatorWarningFuncs = []validatorFunc{
missingActiveGateMemoryLimit,
Expand Down
Loading