mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #105159 from jyz0309/fix-klog-error
Fix klog error in `pkg/proxy`
This commit is contained in:
commit
ab4d8bd1e5
@ -194,7 +194,7 @@ func (hns hnsV1) getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFl
|
|||||||
} else if len(elbPolicy.VIPs) != 0 {
|
} else if len(elbPolicy.VIPs) != 0 {
|
||||||
continue
|
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{
|
return &loadBalancerInfo{
|
||||||
hnsID: plist.ID,
|
hnsID: plist.ID,
|
||||||
}, nil
|
}, nil
|
||||||
@ -220,7 +220,7 @@ func (hns hnsV1) getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFl
|
|||||||
)
|
)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
LogJson("policyList", lb, "Hns loadbalancer policy resource", 1)
|
klog.V(1).InfoS("Hns loadbalancer policy resource", "policies", lb)
|
||||||
} else {
|
} else {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -239,7 +239,7 @@ func (hns hnsV1) deleteLoadBalancer(hnsID string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
LogJson("policyList", hnsloadBalancer, "Removing Policy", 2)
|
klog.V(2).InfoS("Removing Policy", "policies", hnsloadBalancer)
|
||||||
|
|
||||||
_, err = hnsloadBalancer.Delete()
|
_, err = hnsloadBalancer.Delete()
|
||||||
return err
|
return err
|
||||||
|
@ -202,7 +202,7 @@ func (hns hnsV2) getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFl
|
|||||||
} else if len(plist.FrontendVIPs) != 0 {
|
} else if len(plist.FrontendVIPs) != 0 {
|
||||||
continue
|
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{
|
return &loadBalancerInfo{
|
||||||
hnsID: plist.Id,
|
hnsID: plist.Id,
|
||||||
}, nil
|
}, nil
|
||||||
@ -281,8 +281,7 @@ func (hns hnsV2) getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFl
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
LogJson("hostComputeLoadBalancer", lb, "Hns loadbalancer policy resource", 1)
|
klog.V(1).InfoS("Hns loadbalancer policy resource", "loadBalancer", lb)
|
||||||
|
|
||||||
return &loadBalancerInfo{
|
return &loadBalancerInfo{
|
||||||
hnsID: lb.Id,
|
hnsID: lb.Id,
|
||||||
}, err
|
}, err
|
||||||
|
@ -20,7 +20,6 @@ limitations under the License.
|
|||||||
package winkernel
|
package winkernel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
@ -32,7 +31,6 @@ import (
|
|||||||
|
|
||||||
"github.com/Microsoft/hcsshim"
|
"github.com/Microsoft/hcsshim"
|
||||||
"github.com/Microsoft/hcsshim/hcn"
|
"github.com/Microsoft/hcsshim/hcn"
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
discovery "k8s.io/api/discovery/v1"
|
discovery "k8s.io/api/discovery/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
@ -222,23 +220,6 @@ func (t DualStackCompatTester) DualStackCompatible(networkName string) bool {
|
|||||||
return true
|
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
|
// internal struct for endpoints information
|
||||||
type endpointsInfo struct {
|
type endpointsInfo struct {
|
||||||
ip string
|
ip string
|
||||||
@ -442,7 +423,7 @@ func newSourceVIP(hns HostNetworkService, network string, ip string, mac string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ep *endpointsInfo) Cleanup() {
|
func (ep *endpointsInfo) Cleanup() {
|
||||||
Log(ep, "Endpoint Cleanup", 3)
|
klog.V(3).InfoS("Endpoint cleanup", "endpointsInfo", ep)
|
||||||
if !ep.GetIsLocal() && ep.refCount != nil {
|
if !ep.GetIsLocal() && ep.refCount != nil {
|
||||||
*ep.refCount--
|
*ep.refCount--
|
||||||
|
|
||||||
@ -787,7 +768,7 @@ func CleanupLeftovers() (encounteredError bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (svcInfo *serviceInfo) cleanupAllPolicies(endpoints []proxy.Endpoint) {
|
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
|
// Skip the svcInfo.policyApplied check to remove all the policies
|
||||||
svcInfo.deleteAllHnsLoadBalancerPolicy()
|
svcInfo.deleteAllHnsLoadBalancerPolicy()
|
||||||
// Cleanup Endpoints references
|
// Cleanup Endpoints references
|
||||||
@ -829,7 +810,7 @@ func deleteAllHnsLoadBalancerPolicy() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, plist := range plists {
|
for _, plist := range plists {
|
||||||
LogJson("policyList", plist, "Remove Policy", 3)
|
klog.V(3).InfoS("Remove policy", "policies", plist)
|
||||||
_, err = plist.Delete()
|
_, err = plist.Delete()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.ErrorS(err, "Failed to delete policy list")
|
klog.ErrorS(err, "Failed to delete policy list")
|
||||||
@ -1058,7 +1039,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if svcInfo.policyApplied {
|
if svcInfo.policyApplied {
|
||||||
klog.V(4).InfoS("Policy already applied", "spewConfig", spewSdump(svcInfo))
|
klog.V(4).InfoS("Policy already applied", "serviceInfo", svcInfo)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1155,7 +1136,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
|
|
||||||
newHnsEndpoint, err = hns.createEndpoint(hnsEndpoint, hnsNetworkName)
|
newHnsEndpoint, err = hns.createEndpoint(hnsEndpoint, hnsNetworkName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.ErrorS(err, "Remote endpoint creation failed", "spewConfig", spewSdump(hnsEndpoint))
|
klog.ErrorS(err, "Remote endpoint creation failed", "endpointsInfo", hnsEndpoint)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1197,7 +1178,8 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save the hnsId for reference
|
// 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)
|
hnsEndpoints = append(hnsEndpoints, *newHnsEndpoint)
|
||||||
if newHnsEndpoint.GetIsLocal() {
|
if newHnsEndpoint.GetIsLocal() {
|
||||||
hnsLocalEndpoints = append(hnsLocalEndpoints, *newHnsEndpoint)
|
hnsLocalEndpoints = append(hnsLocalEndpoints, *newHnsEndpoint)
|
||||||
@ -1209,10 +1191,10 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
|
|
||||||
ep.hnsID = newHnsEndpoint.hnsID
|
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 {
|
if len(svcInfo.hnsID) > 0 {
|
||||||
// This should not happen
|
// This should not happen
|
||||||
@ -1224,7 +1206,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
continue
|
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 hnsLoadBalancer *loadBalancerInfo
|
||||||
var sourceVip = proxier.sourceVip
|
var sourceVip = proxier.sourceVip
|
||||||
if containsPublicIP || containsNodeIP {
|
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)
|
klog.V(3).InfoS("Hns LoadBalancer resource created for loadBalancer Ingress resources", "lbIngressIP", lbIngressIP)
|
||||||
}
|
}
|
||||||
svcInfo.policyApplied = true
|
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 {
|
if proxier.healthzServer != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user