Merge pull request #105159 from jyz0309/fix-klog-error

Fix klog error in `pkg/proxy`
This commit is contained in:
Kubernetes Prow Robot 2021-09-23 11:17:38 -07:00 committed by GitHub
commit ab4d8bd1e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 35 deletions

View File

@ -194,7 +194,7 @@ func (hns hnsV1) getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFl
} else if len(elbPolicy.VIPs) != 0 {
continue
}
LogJson("policyList", plist, "Found existing Hns loadbalancer policy resource", 1)
klog.V(1).InfoS("Found existing Hns loadbalancer policy resource", "policies", plist)
return &loadBalancerInfo{
hnsID: plist.ID,
}, nil
@ -220,7 +220,7 @@ func (hns hnsV1) getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFl
)
if err == nil {
LogJson("policyList", lb, "Hns loadbalancer policy resource", 1)
klog.V(1).InfoS("Hns loadbalancer policy resource", "policies", lb)
} else {
return nil, err
}
@ -239,7 +239,7 @@ func (hns hnsV1) deleteLoadBalancer(hnsID string) error {
if err != nil {
return err
}
LogJson("policyList", hnsloadBalancer, "Removing Policy", 2)
klog.V(2).InfoS("Removing Policy", "policies", hnsloadBalancer)
_, err = hnsloadBalancer.Delete()
return err

View File

@ -202,7 +202,7 @@ func (hns hnsV2) getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFl
} else if len(plist.FrontendVIPs) != 0 {
continue
}
LogJson("policyList", plist, "Found existing Hns loadbalancer policy resource", 1)
klog.V(1).InfoS("Found existing Hns loadbalancer policy resource", "policies", plist)
return &loadBalancerInfo{
hnsID: plist.Id,
}, nil
@ -281,8 +281,7 @@ func (hns hnsV2) getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFl
return nil, err
}
LogJson("hostComputeLoadBalancer", lb, "Hns loadbalancer policy resource", 1)
klog.V(1).InfoS("Hns loadbalancer policy resource", "loadBalancer", lb)
return &loadBalancerInfo{
hnsID: lb.Id,
}, err

View File

@ -20,7 +20,6 @@ limitations under the License.
package winkernel
import (
"encoding/json"
"fmt"
"net"
"os"
@ -32,7 +31,6 @@ import (
"github.com/Microsoft/hcsshim"
"github.com/Microsoft/hcsshim/hcn"
"github.com/davecgh/go-spew/spew"
v1 "k8s.io/api/core/v1"
discovery "k8s.io/api/discovery/v1"
"k8s.io/apimachinery/pkg/types"
@ -222,23 +220,6 @@ func (t DualStackCompatTester) DualStackCompatible(networkName string) bool {
return true
}
func Log(v interface{}, message string, level klog.Level) {
klog.V(level).InfoS("%s", message, "spewConfig", spewSdump(v))
}
func LogJson(interfaceName string, v interface{}, message string, level klog.Level) {
jsonString, err := json.Marshal(v)
if err == nil {
klog.V(level).InfoS("%s", message, interfaceName, string(jsonString))
}
}
func spewSdump(v interface{}) string {
scs := spew.NewDefaultConfig()
scs.DisableMethods = true
return scs.Sdump(v)
}
// internal struct for endpoints information
type endpointsInfo struct {
ip string
@ -442,7 +423,7 @@ func newSourceVIP(hns HostNetworkService, network string, ip string, mac string,
}
func (ep *endpointsInfo) Cleanup() {
Log(ep, "Endpoint Cleanup", 3)
klog.V(3).InfoS("Endpoint cleanup", "endpointsInfo", ep)
if !ep.GetIsLocal() && ep.refCount != nil {
*ep.refCount--
@ -787,7 +768,7 @@ func CleanupLeftovers() (encounteredError bool) {
}
func (svcInfo *serviceInfo) cleanupAllPolicies(endpoints []proxy.Endpoint) {
Log(svcInfo, "Service Cleanup", 3)
klog.V(3).InfoS("Service cleanup", "serviceInfo", svcInfo)
// Skip the svcInfo.policyApplied check to remove all the policies
svcInfo.deleteAllHnsLoadBalancerPolicy()
// Cleanup Endpoints references
@ -829,7 +810,7 @@ func deleteAllHnsLoadBalancerPolicy() {
return
}
for _, plist := range plists {
LogJson("policyList", plist, "Remove Policy", 3)
klog.V(3).InfoS("Remove policy", "policies", plist)
_, err = plist.Delete()
if err != nil {
klog.ErrorS(err, "Failed to delete policy list")
@ -1058,7 +1039,7 @@ func (proxier *Proxier) syncProxyRules() {
}
if svcInfo.policyApplied {
klog.V(4).InfoS("Policy already applied", "spewConfig", spewSdump(svcInfo))
klog.V(4).InfoS("Policy already applied", "serviceInfo", svcInfo)
continue
}
@ -1155,7 +1136,7 @@ func (proxier *Proxier) syncProxyRules() {
newHnsEndpoint, err = hns.createEndpoint(hnsEndpoint, hnsNetworkName)
if err != nil {
klog.ErrorS(err, "Remote endpoint creation failed", "spewConfig", spewSdump(hnsEndpoint))
klog.ErrorS(err, "Remote endpoint creation failed", "endpointsInfo", hnsEndpoint)
continue
}
} else {
@ -1197,7 +1178,8 @@ func (proxier *Proxier) syncProxyRules() {
}
// Save the hnsId for reference
LogJson("endpointInfo", newHnsEndpoint, "Hns Endpoint resource", 1)
klog.V(1).InfoS("Hns endpoint resource", "endpointsInfo", newHnsEndpoint)
hnsEndpoints = append(hnsEndpoints, *newHnsEndpoint)
if newHnsEndpoint.GetIsLocal() {
hnsLocalEndpoints = append(hnsLocalEndpoints, *newHnsEndpoint)
@ -1209,10 +1191,10 @@ func (proxier *Proxier) syncProxyRules() {
ep.hnsID = newHnsEndpoint.hnsID
Log(ep, "Endpoint resource found", 3)
klog.V(3).InfoS("Endpoint resource found", "endpointsInfo", ep)
}
klog.V(3).InfoS("Associated endpoints for service", "spewConfig", spewSdump(hnsEndpoints), "svcName", svcName.String())
klog.V(3).InfoS("Associated endpoints for service", "endpointsInfo", hnsEndpoints, "svcName", svcName.String())
if len(svcInfo.hnsID) > 0 {
// This should not happen
@ -1224,7 +1206,7 @@ func (proxier *Proxier) syncProxyRules() {
continue
}
klog.V(4).Infof("Trying to Apply Policies for service", "spewConfig", spewSdump(svcInfo))
klog.V(4).Infof("Trying to apply Policies for service", "serviceInfo", svcInfo)
var hnsLoadBalancer *loadBalancerInfo
var sourceVip = proxier.sourceVip
if containsPublicIP || containsNodeIP {
@ -1327,7 +1309,7 @@ func (proxier *Proxier) syncProxyRules() {
klog.V(3).InfoS("Hns LoadBalancer resource created for loadBalancer Ingress resources", "lbIngressIP", lbIngressIP)
}
svcInfo.policyApplied = true
Log(svcInfo, "+++Policy Successfully applied for service +++", 2)
klog.V(2).InfoS("Policy successfully applied for service", "serviceInfo", svcInfo)
}
if proxier.healthzServer != nil {