Skip to content

Commit b5dec3e

Browse files
committed
Adjust log level and fix log format
Signed-off-by: Yanjun Zhou <yanjun.zhou@broadcom.com>
1 parent b5a2dac commit b5dec3e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+271
-200
lines changed

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func (nsxConfig *NsxConfig) validateCert() error {
390390
configLog.Infof("Validate thumbprint: %d", tpCount)
391391
if tpCount > 1 && tpCount != mCount {
392392
err := errors.New("thumbprint count not match manager count")
393-
configLog.Error(err, "validate NsxConfig failed", "thumbprint count", tpCount, "manager count", mCount)
393+
configLog.Error(err, "Validate NsxConfig failed", "thumbprint count", tpCount, "manager count", mCount)
394394
return err
395395
}
396396
}

pkg/controllers/common/utils.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ func AllocateSubnetFromSubnetSet(subnetSet *v1alpha1.SubnetSet, vpcService servi
4949
log.Info("The existing subnets are not available, creating new subnet", "subnetList", subnetList, "subnetSet.Name", subnetSet.Name, "subnetSet.Namespace", subnetSet.Namespace)
5050
vpcInfoList := vpcService.ListVPCInfo(subnetSet.Namespace)
5151
if len(vpcInfoList) == 0 {
52-
err := errors.New("no VPC found")
53-
log.Error(err, "Failed to allocate Subnet")
54-
return "", err
52+
log.Warn("No VPC found for SubnetSet, will retry later", "Namespace", subnetSet.Namespace)
53+
return "", errors.New("no VPC found, will retry later")
5554
}
5655
nsxSubnet, err := subnetService.CreateOrUpdateSubnet(subnetSet, vpcInfoList[0], tags)
5756
if err != nil {

pkg/controllers/ipaddressallocation/ipaddressallocation_controller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package ipaddressallocation
55

66
import (
77
"context"
8-
"errors"
98
"fmt"
109

1110
v1 "k8s.io/api/core/v1"
@@ -82,7 +81,9 @@ func setReadyStatusTrue(client client.Client, ctx context.Context, obj client.Ob
8281
e := client.Status().Update(ctx, ipaddressallocation)
8382
if e != nil {
8483
log.Error(e, "Unable to update IPAddressAllocation status", "IPAddressAllocation", ipaddressallocation)
84+
return
8585
}
86+
log.Debug("Updated IPAddressAllocation", "Name", ipaddressallocation.Name, "Namespace", ipaddressallocation.Namespace, "Conditions", conditions)
8687
}
8788

8889
func (r *IPAddressAllocationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
@@ -189,7 +190,7 @@ func (r *IPAddressAllocationReconciler) RestoreReconcile() error {
189190
}
190191
}
191192
if len(errorList) > 0 {
192-
return errors.Join(errorList...)
193+
return fmt.Errorf("errors found in IPAddressAllocation restore: %v", errorList)
193194
}
194195
return nil
195196
}
@@ -213,7 +214,7 @@ func (r *IPAddressAllocationReconciler) getRestoreList() ([]types.NamespacedName
213214

214215
func (r *IPAddressAllocationReconciler) StartController(mgr ctrl.Manager, hookServer webhook.Server) error {
215216
if err := r.setupWithManager(mgr); err != nil {
216-
log.Error(err, "Failed to create ipaddressallocation controller")
217+
log.Error(err, "Failed to create IPAddressAllocation controller")
217218
return err
218219
}
219220
if hookServer != nil {

pkg/controllers/ipaddressallocation/ipaddressallocation_webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ func (v *IPAddressAllocationValidator) Handle(ctx context.Context, req admission
3939
err = v.decoder.Decode(req, ipAddressAllocation)
4040
}
4141
if err != nil {
42-
log.Error(err, "error while decoding IPAddressAllocation", "IPAddressAllocation", req.Namespace+"/"+req.Name)
42+
log.Error(err, "Error while decoding IPAddressAllocation", "IPAddressAllocation", req.Namespace+"/"+req.Name)
4343
return admission.Errored(http.StatusBadRequest, err)
4444
}
4545
switch req.Operation {
4646
case admissionv1.Delete:
4747
existingAddressBindingList := &v1alpha1.AddressBindingList{}
4848
if err := v.Client.List(context.TODO(), existingAddressBindingList, client.InNamespace(ipAddressAllocation.Namespace), client.MatchingFields{util.AddressBindingIPAddressAllocationNameIndexKey: ipAddressAllocation.Name}); err != nil {
49-
log.Error(err, "failed to list AddressBindings", "Namespace", ipAddressAllocation.Namespace)
49+
log.Error(err, "Failed to list AddressBindings", "Namespace", ipAddressAllocation.Namespace)
5050
return admission.Errored(http.StatusBadRequest, err)
5151
}
5252
if len(existingAddressBindingList.Items) > 0 {

pkg/controllers/namespace/namespace_controller.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,11 @@ func (r *NamespaceReconciler) deleteDefaultSubnetSet(ns string) error {
177177
}
178178

179179
func (r *NamespaceReconciler) namespaceError(ctx context.Context, k8sObj client.Object, msg string, err error) {
180-
logErr := util.If(err == nil, errors.New(msg), err).(error)
181-
log.Error(logErr, msg)
180+
if err != nil {
181+
log.Error(err, msg)
182+
} else {
183+
log.Warn(msg)
184+
}
182185
changes := map[string]string{common.AnnotationNamespaceVPCError: msg}
183186
util.UpdateK8sResourceAnnotation(r.Client, ctx, k8sObj, changes)
184187
}
@@ -229,14 +232,16 @@ func (r *NamespaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
229232
return common.ResultRequeue, nil
230233
}
231234
if !ncExist {
235+
// This is expected when the Namespace is just created
236+
// as NetworkConfig is created after Namespace creation
232237
message := fmt.Sprintf("missing NetworkConfig %s for Namespace %s", ncName, ns)
233238
r.namespaceError(ctx, obj, message, nil)
234-
return common.ResultRequeueAfter10sec, errors.New(message)
239+
return common.ResultRequeueAfter10sec, nil
235240
}
236241
if err = r.VPCService.ValidateNetworkConfig(nc); err != nil {
237242
// if network config is not valid, no need to retry, skip processing
238243
message := fmt.Sprintf("invalid NetworkConfig %s for Namespace %s, error: %v", ncName, ns, err)
239-
r.namespaceError(ctx, obj, message, nil)
244+
r.namespaceError(ctx, obj, message, err)
240245
return common.ResultRequeueAfter10sec, errors.New(message)
241246
}
242247

pkg/controllers/namespace/namespace_controller_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ func TestNamespaceReconciler_Reconcile(t *testing.T) {
203203
})
204204
return patches
205205
},
206-
expectErrStr: "missing NetworkConfig",
207-
expectRes: ctrl.Result{Requeue: true, RequeueAfter: 10 * time.Second},
206+
expectRes: ctrl.Result{Requeue: true, RequeueAfter: 10 * time.Second},
208207
existingNamespaceCR: &v1.Namespace{
209208
TypeMeta: metav1.TypeMeta{},
210209
ObjectMeta: metav1.ObjectMeta{Name: "test-ns"},

pkg/controllers/networkinfo/networkinfo_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package networkinfo
55

66
import (
77
"context"
8-
"errors"
98
"fmt"
109
"time"
1110

@@ -666,7 +665,7 @@ func (r *NetworkInfoReconciler) RestoreReconcile() error {
666665
}
667666
}
668667
if len(errorList) > 0 {
669-
return errors.Join(errorList...)
668+
return fmt.Errorf("errors found in NetworkInfo restore: %v", errorList)
670669
}
671670
return nil
672671
}

pkg/controllers/networkinfo/networkinfo_utils.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ func setNetworkInfoVPCStatus(client client.Client, ctx context.Context, obj clie
3030
if args[0] == nil {
3131
// if createdVPC is empty, remove the VPC from networkInfo
3232
networkInfo.VPCs = []v1alpha1.VPCState{}
33-
client.Update(ctx, networkInfo)
33+
if err := client.Update(ctx, networkInfo); err != nil {
34+
log.Error(err, "Failed to update NetworkInfo CR", "NetworkInfo", networkInfo)
35+
}
3436
return
3537
} else {
3638
createdVPC = args[0].(*v1alpha1.VPCState)
@@ -45,7 +47,9 @@ func setNetworkInfoVPCStatus(client client.Client, ctx context.Context, obj clie
4547
return
4648
}
4749
networkInfo.VPCs = []v1alpha1.VPCState{*createdVPC}
48-
client.Update(ctx, networkInfo)
50+
if err := client.Update(ctx, networkInfo); err != nil {
51+
log.Error(err, "Failed to update NetworkInfo CR", "NetworkInfo", networkInfo)
52+
}
4953
return
5054
}
5155

@@ -71,7 +75,7 @@ func setVPCNetworkConfigurationStatusWithLBS(ctx context.Context, client client.
7175
log.Error(err, "Update VPCNetworkConfiguration status failed", "ncName", ncName, "vpcName", vpcName, "nc.Status.VPCs", nc.Status.VPCs)
7276
return
7377
}
74-
log.Info("Updated VPCNetworkConfiguration status", "ncName", ncName, "vpcName", vpcName, "nc.Status.VPCs", nc.Status.VPCs)
78+
log.Debug("Updated VPCNetworkConfiguration status", "ncName", ncName, "vpcName", vpcName, "nc.Status.VPCs", nc.Status.VPCs)
7579
}
7680

7781
func setVPCNetworkConfigurationStatusWithGatewayConnection(ctx context.Context, client client.Client, nc *v1alpha1.VPCNetworkConfiguration, connectionStatus *common.VPCConnectionStatus) {
@@ -102,8 +106,12 @@ func setVPCNetworkConfigurationStatusWithGatewayConnection(ctx context.Context,
102106
}
103107
}
104108
if conditionsUpdated {
105-
client.Status().Update(ctx, nc)
106-
log.Info("Set VPCNetworkConfiguration status", "ncName", nc.Name, "condition", newConditions)
109+
err := client.Status().Update(ctx, nc)
110+
if err != nil {
111+
log.Error(err, "Failed to update VPCNetworkConfiguration status", "Name", nc.Name)
112+
return
113+
}
114+
log.Debug("Updated VPCNetworkConfiguration", "Name", nc.Name, "New Conditions", newConditions)
107115
}
108116
}
109117

@@ -125,7 +133,12 @@ func setVPCNetworkConfigurationStatusWithSnatEnabled(ctx context.Context, client
125133
}
126134
}
127135
if conditionsUpdated {
128-
client.Status().Update(ctx, nc)
136+
err := client.Status().Update(ctx, nc)
137+
if err != nil {
138+
log.Error(err, "Failed to update VPCNetworkConfiguration status", "Name", nc.Name)
139+
return
140+
}
141+
log.Debug("Updated VPCNetworkConfiguration", "Name", nc.Name, "New Conditions", newConditions)
129142
}
130143
}
131144

@@ -147,7 +160,7 @@ func setVPCNetworkConfigurationStatusWithNoExternalIPBlock(ctx context.Context,
147160
return
148161
}
149162
}
150-
log.Info("Updated VPCNetworkConfiguration status", "VPCNetworkConfiguration", nc.Name, "status", newCondition)
163+
log.Debug("Updated VPCNetworkConfiguration status", "VPCNetworkConfiguration", nc.Name, "status", newCondition)
151164
}
152165

153166
// TODO: abstract the logic of merging condition for common, which can be used by the other controller, e.g. security policy
@@ -252,7 +265,7 @@ func updateVPCNetworkConfigurationStatusWithAliveVPCs(ctx context.Context, clien
252265
log.Error(err, "Failed to update VPCNetworkConfiguration status", "Name", ncName, "nc.Status.VPCs", nc.Status.VPCs)
253266
return
254267
}
255-
log.Info("Updated VPCNetworkConfiguration status", "Name", ncName, "nc.Status.VPCs", nc.Status.VPCs)
268+
log.Debug("Updated VPCNetworkConfiguration status", "Name", ncName, "nc.Status.VPCs", nc.Status.VPCs)
256269
}
257270
}
258271

@@ -301,7 +314,7 @@ func setNSNetworkReadyCondition(ctx context.Context, kubeClient client.Client, n
301314
log.Error(err, "Failed to update Namespace status", "Namespace", nsName)
302315
return
303316
}
304-
log.Info("Updated Namespace network condition", "Namespace", nsName, "status", condition.Status, "reason", condition.Reason, "message", condition.Message)
317+
log.Debug("Updated Namespace network condition", "Namespace", nsName, "status", condition.Status, "reason", condition.Reason, "message", condition.Message)
305318
}
306319

307320
// nsConditionEquals compares the old and new Namespace condition. The compare ignores the differences in field

pkg/controllers/networkinfo/vpcnetworkconfig_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (h *VPCNetworkConfigurationHandler) Create(ctx context.Context, e event.Cre
3939
func (h *VPCNetworkConfigurationHandler) Delete(ctx context.Context, e event.DeleteEvent, _ workqueue.TypedRateLimitingInterface[reconcile.Request]) {
4040
vpcConfigCR := e.Object.(*v1alpha1.VPCNetworkConfiguration)
4141
if err := h.ipBlocksInfoService.SyncIPBlocksInfo(ctx); err != nil {
42-
log.Error(err, "failed to synchronize IPBlocksInfo when deleting %s", vpcConfigCR.Name)
42+
log.Error(err, "Failed to synchronize IPBlocksInfo when deleting %s", vpcConfigCR.Name)
4343
} else {
4444
h.ipBlocksInfoService.ResetPeriodicSync()
4545
}

pkg/controllers/node/node_controller.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package node
55

66
import (
77
"context"
8-
"errors"
98
"fmt"
109
"os"
1110
"reflect"
@@ -41,35 +40,35 @@ type NodeReconciler struct {
4140
func (r *NodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
4241
node := &v1.Node{}
4342
deleted := false
44-
log.Info("reconciling node", "node", req.NamespacedName)
43+
log.Info("Reconciling node", "node", req.NamespacedName)
4544

4645
metrics.CounterInc(r.Service.NSXConfig, metrics.ControllerSyncTotal, MetricResTypeNode)
4746

4847
if err := r.Client.Get(ctx, req.NamespacedName, node); err != nil {
4948
if apierrors.IsNotFound(err) {
50-
log.Info("node not found", "req", req.NamespacedName)
49+
log.Info("Node not found", "req", req.NamespacedName)
5150
deleted = true
5251
if err := r.Service.SyncNodeStore(req.NamespacedName.Name, deleted); err != nil {
53-
log.Error(err, "failed to sync node store", "req", req.NamespacedName)
52+
log.Error(err, "Failed to sync node store", "req", req.NamespacedName)
5453
return common.ResultNormal, err
5554
}
5655
} else {
57-
log.Error(err, "unable to fetch node", "req", req.NamespacedName)
56+
log.Error(err, "Unable to fetch node", "req", req.NamespacedName)
5857
}
5958
return common.ResultNormal, client.IgnoreNotFound(err)
6059
}
6160
if common.NodeIsMaster(node) {
6261
// For WCP supervisor cluster, the master node isn't a transport node.
63-
log.Info("skipping handling master node", "node", req.NamespacedName)
62+
log.Info("Skipping handling master node", "node", req.NamespacedName)
6463
return common.ResultNormal, nil
6564
}
6665
if !node.ObjectMeta.DeletionTimestamp.IsZero() {
67-
log.Info("node is being deleted", "node", req.NamespacedName)
66+
log.Info("Node is being deleted", "node", req.NamespacedName)
6867
deleted = true
6968
}
7069

7170
if err := r.Service.SyncNodeStore(node.Name, deleted); err != nil {
72-
log.Error(err, "failed to sync node store", "req", req.NamespacedName)
71+
log.Error(err, "Failed to sync node store", "req", req.NamespacedName)
7372
return common.ResultNormal, err
7473
}
7574
return common.ResultNormal, nil
@@ -92,7 +91,7 @@ func StartNodeController(mgr ctrl.Manager, nodeService *node.NodeService) {
9291
nodePortReconciler.Service = nodeService
9392

9493
if err := nodePortReconciler.Start(mgr); err != nil {
95-
log.Error(err, "failed to create controller", "controller", "Node")
94+
log.Error(err, "Failed to create controller", "controller", "Node")
9695
os.Exit(1)
9796
}
9897
}
@@ -113,7 +112,7 @@ func (r *NodeReconciler) RestoreReconcile() error {
113112
}
114113
}
115114
if len(errorList) > 0 {
116-
return errors.Join(errorList...)
115+
return fmt.Errorf("errors found in Node restore: %v", errorList)
117116
}
118117
return nil
119118
}
@@ -124,7 +123,7 @@ func (r *NodeReconciler) CollectGarbage(_ context.Context) error {
124123

125124
func (r *NodeReconciler) StartController(mgr ctrl.Manager, _ webhook.Server) error {
126125
if err := r.Start(mgr); err != nil {
127-
log.Error(err, "failed to create controller", "controller", "Node")
126+
log.Error(err, "Failed to create controller", "controller", "Node")
128127
return err
129128
}
130129
return nil

0 commit comments

Comments
 (0)