Skip to content

Commit

Permalink
don't fail when agent config is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoShaka committed Dec 17, 2024
1 parent a94f7ae commit 7e14a89
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/auth/autoupdate/autoupdatev1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,10 @@ var (
// This function should not be confused with api/types/autoupdate.ValidateAutoUpdateConfig which validates the integrity
// of the resource and does not enforce potentially changing rules.
func validateServerSideAgentConfig(config *autoupdate.AutoUpdateConfig) error {
agentsSpec := config.GetSpec().GetAgents()
if agentsSpec == nil {
return nil
}
// We must check resource integrity before, because it makes no sense to try to enforce rules on an invalid resource.
// The generic backend service will likely check integrity again, but it's not a large performance problem.
err := update.ValidateAutoUpdateConfig(config)
Expand All @@ -667,7 +671,6 @@ func validateServerSideAgentConfig(config *autoupdate.AutoUpdateConfig) error {
var maxGroups int
isCloud := modules.GetModules().Features().Cloud

agentsSpec := config.GetSpec().GetAgents()
switch {
case isCloud && agentsSpec.GetStrategy() == update.AgentsStrategyHaltOnError:
maxGroups = maxGroupsHaltOnErrorStrategyCloud
Expand Down
6 changes: 6 additions & 0 deletions lib/auth/autoupdate/autoupdatev1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,12 @@ func TestValidateServerSideAgentConfig(t *testing.T) {
modules modules.Modules
expectErr require.ErrorAssertionFunc
}{
{
name: "empty agent config",
modules: selfHostedModules,
config: nil,
expectErr: require.NoError,
},
{
name: "over max groups time-based",
modules: selfHostedModules,
Expand Down

0 comments on commit 7e14a89

Please sign in to comment.