From 1423a484a3cd960729273e2cda18fa835abbb199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Cluseau?= Date: Thu, 1 Jul 2021 17:17:05 +0200 Subject: [PATCH] log -> klog --- backends/nft/nft.go | 96 +------------------------------- cmd/kpng-backend-torture/main.go | 8 +-- cmd/kpng-globallog/main.go | 12 ++-- cmd/kpng-nodelog/main.go | 6 +- examples/iptables-extip/main.go | 8 +-- global-state.yaml | 6 +- jobs/file2store/file2store.go | 20 +++---- 7 files changed, 33 insertions(+), 123 deletions(-) diff --git a/backends/nft/nft.go b/backends/nft/nft.go index 6594062ad..419fcf471 100644 --- a/backends/nft/nft.go +++ b/backends/nft/nft.go @@ -20,11 +20,9 @@ import ( "bufio" "bytes" "encoding/hex" - "errors" "fmt" "io" "io/ioutil" - "log" "net" "os" "os/exec" @@ -81,7 +79,7 @@ func PreRun() { for _, cidr := range *clusterCIDRsFlag { ip, ipNet, err := net.ParseCIDR(cidr) if err != nil { - log.Fatalf("bad CIDR given: %q: %v", cidr, err) + klog.Fatalf("bad CIDR given: %q: %v", cidr, err) } if ip.To4() == nil { @@ -90,97 +88,9 @@ func PreRun() { clusterCIDRsV4 = append(clusterCIDRsV4, ipNet.String()) } } - log.Print("cluster CIDRs V4: ", clusterCIDRsV4) - log.Print("cluster CIDRs V6: ", clusterCIDRsV6) -} - -func checkIPTableVersion() { - cmdArr := [2]string{"ip6tables", "iptables"} - for _, value := range cmdArr { - cmd := exec.Command(value, "-V") - stdout, err := cmd.Output() - if err != nil && errors.Unwrap(err) != exec.ErrNotFound { - klog.Warningf("cmd (%v) throws error: %v", cmd, err) - continue - } - if bytes.Contains(stdout, []byte("legacy")) { - klog.Warning("legacy ", value, " found") - } - } -} - -func checkMapIndexBug() { - if *forceNFTHashBug { - hasNFTHashBug = true - return - } - - klog.Info("checking for NFT hash bug") - - // check the nft vmap bug (0.9.5 but protect against the whole class) - nft := exec.Command("nft", "-f", "-") - nft.Stdin = bytes.NewBuffer([]byte(` -table ip k8s_test_vmap_bug -delete table ip k8s_test_vmap_bug -table ip k8s_test_vmap_bug { - map m1 { - typeof numgen random mod 2 : ip daddr - elements = { 1 : 10.0.0.1, 2 : 10.0.0.2 } - } -} -`)) - if err := nft.Run(); err != nil { - klog.Warning("failed to test nft bugs: ", err) - } - // cleanup on return - defer func() { - nft = exec.Command("nft", "-f", "-") - nft.Stdin = bytes.NewBuffer([]byte(` -delete table ip k8s_test_vmap_bug -`)) - nft.Stdout = os.Stdout - nft.Stderr = os.Stderr - err := nft.Run() - if err != nil { - klog.Warning("failed to delete test table k8s_test_vmap_bug: ", err) - } - }() - - // get the recorded map - nft = exec.Command("nft", "list", "map", "ip", "k8s_test_vmap_bug", "m1") - output, err := nft.Output() - if err != nil { - klog.Warning("failed to test nft bugs: ", err) - return - } - - if len(bytes.TrimSpace(output)) == 0 { - klog.Warning(`!!! WARNING !!! NFT is blind, can't auto-detect hash bug; to manually check: --> run in this container: -# nft -f - < run on your system: -# nft list map ip k8s_test_vmap_bug m1 - --> if the output map is { 16777216 : 10.0.0.1, 33554432 : 10.0.0.2 } - then add --force-nft-hash-workaround=true here`) - } - - hasNFTHashBug = bytes.Contains(output, []byte("16777216")) || bytes.Contains(output, []byte("0x01000000")) - - if hasNFTHashBug { - klog.Info("nft vmap bug found, map indices will be affected by the workaround (0x01 will become 0x01000000)") - } + klog.Info("cluster CIDRs V4: ", clusterCIDRsV4) + klog.Info("cluster CIDRs V6: ", clusterCIDRsV6) } func Callback(ch <-chan *client.ServiceEndpoints) { diff --git a/cmd/kpng-backend-torture/main.go b/cmd/kpng-backend-torture/main.go index 2fd0aeb4b..56dfe4209 100644 --- a/cmd/kpng-backend-torture/main.go +++ b/cmd/kpng-backend-torture/main.go @@ -19,7 +19,6 @@ package main import ( "flag" "fmt" - "log" "math/rand" "net" "strconv" @@ -29,6 +28,7 @@ import ( "github.com/gogo/protobuf/proto" "google.golang.org/grpc" "google.golang.org/grpc/codes" + "k8s.io/klog" "sigs.k8s.io/kpng/pkg/api/localnetv1" "sigs.k8s.io/kpng/pkg/diffstore" @@ -101,7 +101,7 @@ func injectState(rev uint64, w *watchstate.WatchState) { args := flag.Args() if int(rev) >= len(args) { - log.Print("waiting forever (rev: ", rev, ")") + klog.Info("waiting forever (rev: ", rev, ")") select {} // tests finished, sleep forever } @@ -111,10 +111,10 @@ func injectState(rev uint64, w *watchstate.WatchState) { _, err := fmt.Sscanf(spec, "%d:%d", &nSvc, &nEpPerSvc) if err != nil { - log.Fatal("failed to parse arg: ", spec, ": ", err) + klog.Fatal("failed to parse arg: ", spec, ": ", err) } - log.Print("sending spec ", spec, " (rev: ", rev, ")") + klog.Info("sending spec ", spec, " (rev: ", rev, ")") svcIP := ipGen(net.ParseIP("10.0.0.0")) epIP := ipGen(net.ParseIP("10.128.0.0")) diff --git a/cmd/kpng-globallog/main.go b/cmd/kpng-globallog/main.go index 0ffc207f2..80ee8edab 100644 --- a/cmd/kpng-globallog/main.go +++ b/cmd/kpng-globallog/main.go @@ -19,7 +19,6 @@ package main import ( "context" "fmt" - "log" "time" "github.com/spf13/cobra" @@ -27,6 +26,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/connectivity" "google.golang.org/protobuf/proto" + "k8s.io/klog" "sigs.k8s.io/kpng/client" "sigs.k8s.io/kpng/pkg/api/localnetv1" @@ -66,7 +66,7 @@ func run() { if isCanceled(err) { return } else if err != nil { - log.Print("failed to connect: ", err) + klog.Info("failed to connect: ", err) time.Sleep(time.Second) return } @@ -82,7 +82,7 @@ func run() { if isCanceled(err) { return } else if err != nil { - log.Print("failed to start the watch: ", err) + klog.Info("failed to start the watch: ", err) time.Sleep(time.Second) return } @@ -92,7 +92,7 @@ func run() { if isCanceled(err) { return } else if err != nil { - log.Print("watch request failed: ", err) + klog.Info("watch request failed: ", err) time.Sleep(time.Second) return } @@ -146,14 +146,14 @@ loop: v = &localnetv1.ServiceInfo{} default: - log.Print("unknown set: ", set.Ref.Set) + klog.Info("unknown set: ", set.Ref.Set) continue loop } if v != nil { err = proto.Unmarshal(set.Bytes, v) if err != nil { - log.Print("failed to parse value: ", err) + klog.Info("failed to parse value: ", err) v = nil } } diff --git a/cmd/kpng-nodelog/main.go b/cmd/kpng-nodelog/main.go index ba0394711..00a559d60 100644 --- a/cmd/kpng-nodelog/main.go +++ b/cmd/kpng-nodelog/main.go @@ -18,11 +18,11 @@ package main import ( "fmt" - "log" "time" "github.com/spf13/cobra" "google.golang.org/protobuf/proto" + "k8s.io/klog" "sigs.k8s.io/kpng/client" "sigs.k8s.io/kpng/localsink" @@ -89,13 +89,13 @@ func (s *sink) Send(op *localnetv1.OpItem) (err error) { v = &localnetv1.ServiceInfo{} default: - log.Print("unknown set: ", set.Ref.Set) + klog.Info("unknown set: ", set.Ref.Set) } if v != nil { err = proto.Unmarshal(set.Bytes, v) if err != nil { - log.Print("failed to parse value: ", err) + klog.Info("failed to parse value: ", err) v = nil } } diff --git a/examples/iptables-extip/main.go b/examples/iptables-extip/main.go index 2a8a9601d..9a7dc043f 100644 --- a/examples/iptables-extip/main.go +++ b/examples/iptables-extip/main.go @@ -20,13 +20,13 @@ import ( "bytes" "flag" "fmt" - "log" "os" "os/exec" "path" "sort" "strings" + "k8s.io/klog" "sigs.k8s.io/kpng/client" ) @@ -178,11 +178,11 @@ func handleEndpoints(items []*client.ServiceEndpoints) { // continue // } - log.Print("ext-iptables: rules have changed, updating") + klog.Info("ext-iptables: rules have changed, updating") rules := ipt.Bytes() if *dryRun { - log.Printf("would have applied those rules:\n%s", ipt.String()) + klog.Infof("would have applied those rules:\n%s", ipt.String()) return } @@ -195,7 +195,7 @@ func handleEndpoints(items []*client.ServiceEndpoints) { err := cmd.Run() if err != nil { - log.Print("ext-iptables: failed to restore iptables rules: ", err, "\n", string(rules)) + klog.Info("ext-iptables: failed to restore iptables rules: ", err, "\n", string(rules)) } } diff --git a/global-state.yaml b/global-state.yaml index 3729de4e0..5743ecc4c 100644 --- a/global-state.yaml +++ b/global-state.yaml @@ -86,7 +86,7 @@ services: ips: v4: - 11.0.1.2 - v6: [] + v6: [ "fd2b::1:2" ] conditions: ready: true topology: @@ -101,7 +101,7 @@ services: ips: v4: - 11.0.2.2 - v6: [] + v6: [ "fd2b::2:2" ] conditions: ready: true topology: @@ -116,7 +116,7 @@ services: ips: v4: - 11.0.3.2 - v6: [] + v6: [ "fd2b::3:2" ] conditions: ready: true topology: diff --git a/jobs/file2store/file2store.go b/jobs/file2store/file2store.go index bc25dad50..7ebb78730 100644 --- a/jobs/file2store/file2store.go +++ b/jobs/file2store/file2store.go @@ -3,7 +3,6 @@ package file2store import ( "context" "io/ioutil" - "log" "os" "path" "time" @@ -11,6 +10,7 @@ import ( "github.com/cespare/xxhash" "github.com/gogo/protobuf/proto" "gopkg.in/yaml.v2" + "k8s.io/klog" "sigs.k8s.io/kpng/jobs/store2file" "sigs.k8s.io/kpng/pkg/api/localnetv1" "sigs.k8s.io/kpng/pkg/diffstore" @@ -51,7 +51,7 @@ func (j *Job) Run(ctx context.Context) { stat, err := os.Stat(configPath) if err != nil { - log.Print("failed to stat config: ", err) + klog.Info("failed to stat config: ", err) continue } @@ -63,14 +63,14 @@ func (j *Job) Run(ctx context.Context) { configBytes, err := ioutil.ReadFile(configPath) if err != nil { - log.Print("failed to read config: ", err) + klog.Info("failed to read config: ", err) continue } state := &store2file.GlobalState{} err = yaml.UnmarshalStrict(configBytes, state) if err != nil { - log.Print("failed to parse config: ", err) + klog.Info("failed to parse config: ", err) continue } @@ -119,16 +119,16 @@ func (j *Job) Run(ctx context.Context) { store.Update(func(tx *proxystore.Tx) { for _, u := range diffNodes.Updated() { - log.Print("U node ", string(u.Key)) + klog.Info("U node ", string(u.Key)) tx.SetNode(u.Value.(*localnetv1.Node)) } for _, u := range diffSvcs.Updated() { - log.Print("U service ", string(u.Key)) + klog.Info("U service ", string(u.Key)) si := u.Value.(*localnetv1.ServiceInfo) tx.SetService(si.Service, si.TopologyKeys) } for _, u := range diffEPs.Updated() { - log.Print("U endpoints ", string(u.Key)) + klog.Info("U endpoints ", string(u.Key)) key := string(u.Key) eis := u.Value.([]*localnetv1.EndpointInfo) @@ -136,17 +136,17 @@ func (j *Job) Run(ctx context.Context) { } for _, d := range diffEPs.Deleted() { - log.Print("D endpoints ", string(d.Key)) + klog.Info("D endpoints ", string(d.Key)) key := string(d.Key) tx.DelEndpointsOfSource(path.Dir(key), path.Base(key)) } for _, d := range diffSvcs.Deleted() { - log.Print("D service ", string(d.Key)) + klog.Info("D service ", string(d.Key)) key := string(d.Key) tx.DelService(path.Dir(key), path.Base(key)) } for _, d := range diffNodes.Deleted() { - log.Print("D node ", string(d.Key)) + klog.Info("D node ", string(d.Key)) tx.DelNode(string(d.Key)) }