Skip to content

Commit

Permalink
Fix BackendConfig.securityPolicy is not removed after config updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixiansong committed Jul 26, 2022
1 parent d5436d7 commit a5bbb02
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/backends/features/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,23 @@ import (
// EnsureSecurityPolicy ensures the security policy link on backend service.
// TODO(mrhohn): Emit event when attach/detach security policy to backend service.
func EnsureSecurityPolicy(cloud *gce.Cloud, sp utils.ServicePort, be *composite.BackendService) error {
if sp.BackendConfig.Spec.SecurityPolicy == nil {
return nil
}

if be.Scope != meta.Global {
return fmt.Errorf("cloud armor security policies not supported for %s backend service %s", be.Scope, be.Name)
}

var desiredPolicyName string
if sp.BackendConfig.Spec.SecurityPolicy != nil {
desiredPolicyName = sp.BackendConfig.Spec.SecurityPolicy.Name
} else {
desiredPolicyName = ""
}

existingPolicyName, err := utils.KeyName(be.SecurityPolicy)
// The parser returns error for empty values.
if be.SecurityPolicy != "" && err != nil {
return err
}
desiredPolicyName := sp.BackendConfig.Spec.SecurityPolicy.Name

if existingPolicyName == desiredPolicyName {
return nil
}
Expand Down

0 comments on commit a5bbb02

Please sign in to comment.