Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsokolovsky committed Jul 3, 2024
1 parent 114bf38 commit e81133a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/resources/management.cattle.io/v3/setting/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@ func (a *admitter) Admit(request *admission.Request) (*admissionv1.AdmissionResp
if err != nil {
return nil, fmt.Errorf("failed to get Setting from request: %w", err)
}
if request.Operation == admissionv1.Create || request.Operation == admissionv1.Update {
switch request.Operation {
case admissionv1.Create:
if err := a.validateUserRetentionSettings(newSetting); err != nil {
return admission.ResponseBadRequest(err.Error()), nil
}
case admissionv1.Update:
if err := a.validateUserRetentionSettings(newSetting); err != nil {
return admission.ResponseBadRequest(err.Error()), nil
}
}
if request.Operation == admissionv1.Update {
if err := a.validateAgentTLSMode(*oldSetting, *newSetting); err != nil {
return admission.ResponseBadRequest(err.Error()), nil
}
Expand Down Expand Up @@ -145,7 +148,7 @@ func (a *admitter) validateAgentTLSMode(oldSetting, newSetting v3.Setting) error
}
if !clusterConditionMatches(cluster, "AgentTlsStrictCheck", "True") {
return field.Forbidden(field.NewPath("value", "default"),
fmt.Sprintf("AgentTlsStrictCheck status of cluster %s isn't 'True'", cluster.Name))
fmt.Sprintf("AgentTlsStrictCheck condition of cluster %s isn't 'True'", cluster.Name))
}
}
}
Expand Down

0 comments on commit e81133a

Please sign in to comment.