Skip to content

Commit

Permalink
add log near err (#3098)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobz965 authored Aug 1, 2023
1 parent c6c472a commit 68dc1c3
Show file tree
Hide file tree
Showing 54 changed files with 472 additions and 10 deletions.
1 change: 1 addition & 0 deletions cmd/daemon/cniserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func mvCNIConf(configDir, configFile, confName string) error {
// #nosec
data, err := os.ReadFile(configFile)
if err != nil {
klog.Errorf("failed to read cni config file %s, %v", configFile, err)
return err
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func ParseFlags() (*Configuration, error) {
if config.DefaultGateway == "" {
gw, err := util.GetGwByCidr(config.DefaultCIDR)
if err != nil {
klog.Error(err)
return nil, err
}
config.DefaultGateway = gw
Expand All @@ -271,6 +272,7 @@ func ParseFlags() (*Configuration, error) {
if config.NodeSwitchGateway == "" {
gw, err := util.GetGwByCidr(config.NodeSwitchCIDR)
if err != nil {
klog.Error(err)
return nil, err
}
config.NodeSwitchGateway = gw
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (c *Controller) handleUpdateEndpoint(key string) error {
if errors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}

Expand All @@ -108,6 +109,7 @@ func (c *Controller) handleUpdateEndpoint(key string) error {
if errors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}
svc := cachedService.DeepCopy()
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/external_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ func (c *Controller) syncExternalVpc() {
}
_, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().UpdateStatus(context.Background(), vpc, metav1.UpdateOptions{})
if err != nil {
klog.V(4).Infof("update vpc %s status failed", vpcName)
klog.Errorf("update vpc %s status failed: %v", vpcName, err)
continue
}
delete(logicalRouters, vpcName)
klog.V(4).Infof("patch vpc %s", vpcName)
} else {
err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Delete(context.Background(), vpcName, metav1.DeleteOptions{})
if err != nil {
klog.V(4).Infof("delete vpc %s failed", vpcName)
klog.Error("delete vpc %s failed: %v", vpcName, err)
continue
}
klog.V(4).Infof("delete vpc %s ", vpcName)
klog.Infof("deleted vpc %s ", vpcName)
}
}
if len(logicalRouters) != 0 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func (c *Controller) gcLoadBalancer() error {
// remove lb from logical switch
vpcs, err := c.vpcsLister.List(labels.Everything())
if err != nil {
klog.Error(err)
return err
}
for _, cachedVpc := range vpcs {
Expand All @@ -405,6 +406,7 @@ func (c *Controller) gcLoadBalancer() error {
if k8serrors.IsNotFound(err) {
continue
}
klog.Error(err)
return err
}
if !isOvnSubnet(subnet) {
Expand All @@ -425,10 +427,12 @@ func (c *Controller) gcLoadBalancer() error {
vpc.Status.SctpSessionLoadBalancer = ""
bytes, err := vpc.Status.Bytes()
if err != nil {
klog.Error(err)
return err
}
_, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Patch(context.Background(), vpc.Name, types.MergePatchType, bytes, metav1.PatchOptions{}, "status")
if err != nil {
klog.Error(err)
return err
}
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (c *Controller) InitDefaultVpc() error {

bytes, err := vpc.Status.Bytes()
if err != nil {
klog.Error(err)
return err
}
_, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Patch(context.Background(), vpc.Name, types.MergePatchType, bytes, metav1.PatchOptions{}, "status")
Expand Down Expand Up @@ -263,10 +264,12 @@ func (c *Controller) initLoadBalancer() error {
vpc.Status.SctpSessionLoadBalancer = vpcLb.SctpSessLoadBalancer
bytes, err := vpc.Status.Bytes()
if err != nil {
klog.Error(err)
return err
}
_, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Patch(context.Background(), vpc.Name, types.MergePatchType, bytes, metav1.PatchOptions{}, "status")
if err != nil {
klog.Error(err)
return err
}
}
Expand Down Expand Up @@ -588,6 +591,7 @@ func (c *Controller) initDefaultVlan() error {
}

if err := c.initDefaultProviderNetwork(); err != nil {
klog.Error(err)
return err
}

Expand Down Expand Up @@ -664,6 +668,7 @@ func (c *Controller) initSyncCrdSubnets() error {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}
for _, orisubnet := range subnets {
Expand Down Expand Up @@ -745,6 +750,7 @@ func (c *Controller) initSyncCrdVlans() error {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/inspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (c *Controller) inspectPod() error {
portName := ovs.PodNameToPortName(podName, pod.Namespace, podNet.ProviderName)
exists, err := c.ovnClient.LogicalSwitchPortExists(portName)
if err != nil {
klog.Errorf("failed to check port %s exists, %v", portName, err)
return err
}

Expand All @@ -51,6 +52,7 @@ func (c *Controller) inspectPod() error {
delete(pod.Annotations, fmt.Sprintf(util.RoutedAnnotationTemplate, podNet.ProviderName))
patch, err := util.GenerateStrategicMergePatchPayload(oriPod, pod)
if err != nil {
klog.Errorf("failed to generate patch payload, %v", err)
return err
}
if _, err := c.config.KubeClient.CoreV1().Pods(pod.Namespace).Patch(context.Background(), pod.Name,
Expand Down
7 changes: 7 additions & 0 deletions pkg/controller/ovn-ic.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ func (c *Controller) startOvnIC(icHost, icNbPort, icSbPort string) error {
}
output, err := cmd.CombinedOutput()
if err != nil {
klog.Error(err)
return fmt.Errorf("%s", output)
}
return nil
Expand All @@ -332,6 +333,7 @@ func (c *Controller) stopOvnIC() error {
cmd := exec.Command("/usr/share/ovn/scripts/ovn-ctl", "stop_ic")
output, err := cmd.CombinedOutput()
if err != nil {
klog.Error(err)
return fmt.Errorf("%s", output)
}
return nil
Expand All @@ -342,6 +344,7 @@ func (c *Controller) waitTsReady() error {
for retry > 0 {
ready, err := c.allSubnetReady(util.InterconnectionSwitch)
if err != nil {
klog.Error(err)
return err
}

Expand Down Expand Up @@ -406,16 +409,19 @@ func (c *Controller) RemoveOldChassisInSbDB(azName string) error {
azUUID, err := c.ovnLegacyClient.GetAzUUID(azName)
if err != nil {
klog.Errorf("failed to get UUID of AZ %s: %v", lastIcCm["az-name"], err)
return err
}

gateways, err := c.ovnLegacyClient.GetGatewayUUIDsInOneAZ(azUUID)
if err != nil {
klog.Errorf("failed to get gateway UUIDs in AZ %s: %v", azUUID, err)
return err
}

routes, err := c.ovnLegacyClient.GetRouteUUIDsInOneAZ(azUUID)
if err != nil {
klog.Errorf("failed to get route UUIDs in AZ %s: %v", azUUID, err)
return err
}

c.ovnLegacyClient.DestroyGateways(gateways)
Expand Down Expand Up @@ -504,6 +510,7 @@ func (c *Controller) listRemoteLogicalSwitchPortAddress() (*strset.Set, error) {
return lsp.Type == "remote"
})
if err != nil {
klog.Error(err)
return nil, fmt.Errorf("list remote logical switch ports: %v", err)
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/controller/ovn_dnat.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func (c *Controller) isOvnDnatDuplicated(eipName, dnatName, externalPort string)
}))
if err != nil {
if !k8serrors.IsNotFound(err) {
klog.Error(err)
return false, err
}
}
Expand All @@ -203,6 +204,7 @@ func (c *Controller) handleAddOvnDnatRule(key string) error {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}

Expand Down Expand Up @@ -318,6 +320,7 @@ func (c *Controller) handleDelOvnDnatRule(key string) error {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}

Expand Down Expand Up @@ -345,6 +348,7 @@ func (c *Controller) handleUpdateOvnDnatRule(key string) error {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}

Expand Down Expand Up @@ -458,6 +462,7 @@ func (c *Controller) patchOvnDnatAnnotations(key, eipName string) error {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}

Expand Down Expand Up @@ -495,6 +500,7 @@ func (c *Controller) patchOvnDnatStatus(key, vpcName, v4Eip, podIp, podMac strin
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}
dnat := oriDnat.DeepCopy()
Expand Down Expand Up @@ -562,6 +568,7 @@ func (c *Controller) patchOvnDnatStatus(key, vpcName, v4Eip, podIp, podMac strin
if changed {
bytes, err := dnat.Status.Bytes()
if err != nil {
klog.Error(err)
return err
}
if _, err = c.config.KubeOvnClient.KubeovnV1().OvnDnatRules().Patch(context.Background(), dnat.Name,
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/ovn_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func (c *Controller) handleAddOvnEip(key string) error {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}
if cachedEip.Status.MacAddress != "" {
Expand Down Expand Up @@ -281,6 +282,7 @@ func (c *Controller) handleUpdateOvnEip(key string) error {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}
klog.V(3).Infof("handle update ovn eip %s", cachedEip.Name)
Expand Down Expand Up @@ -316,6 +318,7 @@ func (c *Controller) handleResetOvnEip(key string) error {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}
if !cachedEip.DeletionTimestamp.IsZero() {
Expand Down Expand Up @@ -384,6 +387,7 @@ func (c *Controller) createOrUpdateCrdOvnEip(key, subnet, v4ip, v6ip, mac, usage
}, metav1.CreateOptions{})
if err != nil {
err := fmt.Errorf("failed to create crd ovn eip '%s', %v", key, err)
klog.Error(err)
return err
}
// wait local cache ready
Expand Down Expand Up @@ -513,6 +517,7 @@ func (c *Controller) natLabelAndAnnoOvnEip(eipName, natName, vpcName string) err
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}
eip := cachedEip.DeepCopy()
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/ovn_fip.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func (c *Controller) handleAddOvnFip(key string) error {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}
if cachedFip.Status.Ready && cachedFip.Status.V4Ip != "" {
Expand Down Expand Up @@ -406,6 +407,7 @@ func (c *Controller) handleDelOvnFip(key string) error {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}
eipName := cachedFip.Spec.OvnEip
Expand All @@ -430,6 +432,7 @@ func (c *Controller) patchOvnFipAnnotations(key, eipName string) error {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}
fip := oriFip.DeepCopy()
Expand Down Expand Up @@ -466,6 +469,7 @@ func (c *Controller) patchOvnFipStatus(key, vpcName, v4Eip, podIp, podMac string
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}
fip := oriFip.DeepCopy()
Expand Down Expand Up @@ -510,6 +514,7 @@ func (c *Controller) patchOvnFipStatus(key, vpcName, v4Eip, podIp, podMac string
if changed {
bytes, err := fip.Status.Bytes()
if err != nil {
klog.Error(err)
return err
}
if _, err = c.config.KubeOvnClient.KubeovnV1().OvnFips().Patch(context.Background(), fip.Name,
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/ovn_snat.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func (c *Controller) handleAddOvnSnatRule(key string) error {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}
if cachedSnat.Status.Ready && cachedSnat.Status.V4IpCidr != "" {
Expand Down Expand Up @@ -272,6 +273,7 @@ func (c *Controller) handleUpdateOvnSnatRule(key string) error {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}
klog.V(3).Infof("handle update ovn snat %s", key)
Expand Down Expand Up @@ -376,6 +378,7 @@ func (c *Controller) patchOvnSnatStatus(key, vpc, v4Eip, v4IpCidr string, ready
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}
snat := oriSnat.DeepCopy()
Expand Down Expand Up @@ -436,6 +439,7 @@ func (c *Controller) patchOvnSnatAnnotation(key, eipName string) error {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Error(err)
return err
}
snat := oriFip.DeepCopy()
Expand Down
Loading

0 comments on commit 68dc1c3

Please sign in to comment.