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

Cherry-pick: Change readonly oneAgent + custom image validation to a warning #4346 #4386

Merged
merged 10 commits into from
Feb 7, 2025
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 @@ -50,7 +50,7 @@ func TestImageFieldHasTenantImage(t *testing.T) {
Spec: dynakube.DynaKubeSpec{
APIURL: testTenantUrl + "/api",
OneAgent: oneagent.Spec{
ClassicFullStack: &oneagent.HostInjectSpec{
HostMonitoring: &oneagent.HostInjectSpec{
Image: testRegistryUrl + "/linux/oneagent:latest",
},
},
Expand All @@ -72,7 +72,7 @@ func TestImageFieldHasTenantImage(t *testing.T) {
Spec: dynakube.DynaKubeSpec{
APIURL: testTenantUrl + "/api",
OneAgent: oneagent.Spec{
ClassicFullStack: &oneagent.HostInjectSpec{
HostMonitoring: &oneagent.HostInjectSpec{
Image: testRegistryUrl + "/linux/oneagent:latest",
},
},
Expand All @@ -88,7 +88,7 @@ func TestImageFieldHasTenantImage(t *testing.T) {
Spec: dynakube.DynaKubeSpec{
APIURL: testTenantUrl + "/api",
OneAgent: oneagent.Spec{
ClassicFullStack: &oneagent.HostInjectSpec{
HostMonitoring: &oneagent.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.`

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 @@ -118,6 +120,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.OneAgent().IsReadOnlyOneAgentsMode() && dk.OneAgent().GetCustomImage() != "" {
return errorPublicImageWithWrongConfig
}

return ""
}

func imageFieldSetWithoutCSIFlag(_ context.Context, v *Validator, dk *dynakube.DynaKube) string {
if dk.OneAgent().IsApplicationMonitoringMode() {
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 @@ -491,3 +491,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: oneagent.Spec{
HostMonitoring: &oneagent.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: oneagent.Spec{
HostMonitoring: &oneagent.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: oneagent.Spec{
HostMonitoring: &oneagent.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 @@ -60,6 +60,7 @@ var (
duplicatedTelemetryServiceProtocols,
invalidTelemetryServiceName,
extensionsWithoutK8SMonitoring,
publicImageSetWithoutReadOnlyMode,
}
validatorWarningFuncs = []validatorFunc{
missingActiveGateMemoryLimit,
Expand Down
Loading