@@ -34,6 +34,7 @@ import (
3434 "sigs.k8s.io/cloud-provider-azure/pkg/azclient/securitygroupclient"
3535 azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
3636 "sigs.k8s.io/cloud-provider-azure/pkg/consts"
37+ "sigs.k8s.io/cloud-provider-azure/pkg/log"
3738 "sigs.k8s.io/cloud-provider-azure/pkg/util/errutils"
3839)
3940
@@ -55,6 +56,7 @@ type securityGroupRepo struct {
5556}
5657
5758func NewSecurityGroupRepo (securityGroupResourceGroup string , securityGroupName string , nsgCacheTTLInSeconds int , disableAPICallCache bool , securityGroupClient securitygroupclient.Interface ) (Repository , error ) {
59+ logger := log .Background ().WithName ("NewSecurityGroupRepo" )
5860 getter := func (ctx context.Context , key string ) (interface {}, error ) {
5961 nsg , err := securityGroupClient .Get (ctx , securityGroupResourceGroup , key )
6062 exists , rerr := errutils .CheckResourceExistsFromAzcoreError (err )
@@ -63,7 +65,7 @@ func NewSecurityGroupRepo(securityGroupResourceGroup string, securityGroupName s
6365 }
6466
6567 if ! exists {
66- klog .V (2 ).Infof ("Security group %q not found" , key )
68+ logger .V (2 ).Info ("Security group not found" , "securityGroup " , key )
6769 return nil , nil
6870 }
6971
@@ -90,8 +92,9 @@ func NewSecurityGroupRepo(securityGroupResourceGroup string, securityGroupName s
9092
9193// CreateOrUpdateSecurityGroup invokes az.SecurityGroupsClient.CreateOrUpdate with exponential backoff retry
9294func (az * securityGroupRepo ) CreateOrUpdateSecurityGroup (ctx context.Context , sg * armnetwork.SecurityGroup ) error {
95+ logger := log .Background ().WithName ("CreateOrUpdateSecurityGroup" )
9396 _ , rerr := az .securigyGroupClient .CreateOrUpdate (ctx , az .securityGroupResourceGroup , * sg .Name , * sg )
94- klog .V (10 ).Infof ("SecurityGroupsClient.CreateOrUpdate(%s) : end" , * sg .Name )
97+ logger .V (10 ).Info ("SecurityGroupsClient.CreateOrUpdate: end" , "securityGroupName " , * sg .Name )
9598 if rerr == nil {
9699 // Invalidate the cache right after updating
97100 _ = az .nsgCache .Delete (* sg .Name )
@@ -104,13 +107,13 @@ func (az *securityGroupRepo) CreateOrUpdateSecurityGroup(ctx context.Context, sg
104107
105108 // Invalidate the cache because ETAG precondition mismatch.
106109 if respError .StatusCode == http .StatusPreconditionFailed {
107- klog .V (3 ).Infof ("SecurityGroup cache for %s is cleanup because of http.StatusPreconditionFailed" , * sg .Name )
110+ logger .V (3 ).Info ("SecurityGroup cache is cleanup because of http.StatusPreconditionFailed" , "securityGroupName " , * sg .Name )
108111 _ = az .nsgCache .Delete (* sg .Name )
109112 }
110113
111114 // Invalidate the cache because another new operation has canceled the current request.
112115 if strings .Contains (strings .ToLower (respError .Error ()), consts .OperationCanceledErrorMessage ) {
113- klog .V (3 ).Infof ("SecurityGroup cache for %s is cleanup because CreateOrUpdateSecurityGroup is canceled by another operation" , * sg .Name )
116+ logger .V (3 ).Info ("SecurityGroup cache is cleanup because CreateOrUpdateSecurityGroup is canceled by another operation" , "securityGroupName " , * sg .Name )
114117 _ = az .nsgCache .Delete (* sg .Name )
115118 }
116119 }
0 commit comments