Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use klog for kindnetd #991 #1000

Merged
merged 1 commit into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions images/kindnetd/cmd/kindnetd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/klog"
"k8s.io/utils/net"
)

Expand Down Expand Up @@ -54,7 +55,7 @@ func main() {
// obtain the host and pod ip addresses
// if both ips are different we are not using the host network
hostIP, podIP := os.Getenv("HOST_IP"), os.Getenv("POD_IP")
fmt.Printf("hostIP = %s\npodIP = %s\n", hostIP, podIP)
klog.Infof("hostIP = %s\npodIP = %s\n", hostIP, podIP)
if hostIP != podIP {
panic(fmt.Sprintf(
"hostIP(= %q) != podIP(= %q) but must be running with host network: ",
Expand Down Expand Up @@ -109,21 +110,21 @@ func makeNodesReconciler(cniConfig *CNIConfigWriter, hostIP string) func(*corev1
// first get this node's IP
nodeIP := internalIP(node)
if nodeIP == "" {
fmt.Printf("Node %v has no Internal IP, ignoring\n", node.Name)
klog.Infof("Node %v has no Internal IP, ignoring\n", node.Name)
return nil
}

// don't do anything unless there is a PodCIDR
podCIDR := node.Spec.PodCIDR
if podCIDR == "" {
fmt.Printf("Node %v has no CIDR, ignoring\n", node.Name)
klog.Infof("Node %v has no CIDR, ignoring\n", node.Name)
return nil
}

// This is our node. We don't need to add routes, but we might need to
// update the cni config.
if nodeIP == hostIP {
fmt.Printf("handling current node\n")
klog.Infof("handling current node\n")
// compute the current cni config inputs
if err := cniConfig.Write(
ComputeCNIConfigInputs(node),
Expand All @@ -134,8 +135,8 @@ func makeNodesReconciler(cniConfig *CNIConfigWriter, hostIP string) func(*corev1
return nil
}

fmt.Printf("Handling node with IP: %s\n", nodeIP)
fmt.Printf("Node %v has CIDR %s \n", node.Name, podCIDR)
klog.Infof("Handling node with IP: %s\n", nodeIP)
klog.Infof("Node %v has CIDR %s \n", node.Name, podCIDR)
if err := syncRoute(nodeIP, podCIDR); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions images/kindnetd/cmd/kindnetd/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ limitations under the License.
package main

import (
"fmt"
"net"

"github.com/vishvananda/netlink"
"github.com/vishvananda/netlink/nl"
"k8s.io/klog"
)

func syncRoute(nodeIP, podCIDR string) error {
Expand All @@ -44,7 +44,7 @@ func syncRoute(nodeIP, podCIDR string) error {
if err := netlink.RouteAdd(&routeToDst); err != nil {
return err
}
fmt.Printf("Adding route %v \n", routeToDst)
klog.Infof("Adding route %v \n", routeToDst)
}

return nil
Expand Down
1 change: 1 addition & 0 deletions images/kindnetd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
k8s.io/apimachinery v0.0.0-20190404173353-6a84e37a896d
k8s.io/client-go v11.0.0+incompatible
k8s.io/klog v0.3.0
k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5
sigs.k8s.io/yaml v1.1.0 // indirect
)