Skip to content

Commit e858f03

Browse files
author
kkumar
committed
Sanity
1 parent 19b8c6b commit e858f03

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

plugins/oob/k8s.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package oob
55

66
import (
77
"context"
8-
"encoding/hex"
98
"encoding/json"
109
"fmt"
1110
"net"
@@ -90,7 +89,7 @@ func (k K8sClient) getIp(
9089
if len(subnetNames) == 0 {
9190
return nil, errors.New("No OOB subnets found")
9291
} else {
93-
log.Infof("%d OOB subnets found: %s", len(subnetNames), strings.Join(subnetNames, " "))
92+
log.Debugf("%d OOB subnets found: %s", len(subnetNames), strings.Join(subnetNames, " "))
9493
subnetMatch := false
9594
for _, subnetName := range subnetNames {
9695
subnet, err := k.getMatchingSubnet(subnetName, ipaddr)
@@ -100,7 +99,7 @@ func (k K8sClient) getIp(
10099
if subnet == nil {
101100
continue
102101
}
103-
log.Infof("Selecting subnet %s/%s", k.Namespace, subnetName)
102+
log.Debugf("Selecting subnet %s/%s", k.Namespace, subnetName)
104103
subnetMatch = true
105104

106105
ipamIP, err = k.prepareCreateIpamIP(subnetName, macKey)
@@ -241,7 +240,7 @@ func (k K8sClient) doCreateIpamIP(
241240
} else {
242241
ipamIP, err = k.waitForCreation(ipamIP)
243242
if err != nil {
244-
return nil, fmt.Errorf("failed to create IP %s/%s: %w", ipamIP.Namespace, ipamIP.Name, err)
243+
return nil, fmt.Errorf("failed to create IP %w", err)
245244
} else {
246245
log.Infof("New IP %s (%s/%s) created in subnet %s", ipamIP.Status.Reserved.String(),
247246
ipamIP.Namespace, ipamIP.Name, ipamIP.Spec.Subnet.Name)
@@ -321,7 +320,7 @@ func (k K8sClient) waitForCreation(ipamIP *ipamv1alpha1.IP) (*ipamv1alpha1.IP, e
321320
}
322321
}
323322
}
324-
return ipamIP, errors.New("Timeout reached, IP not created")
323+
return nil, errors.New("Timeout reached, IP not created")
325324
}
326325

327326
func (k K8sClient) getOOBNetworks(subnetType ipamv1alpha1.SubnetAddressType) []string {
@@ -334,12 +333,10 @@ func (k K8sClient) getOOBNetworks(subnetType ipamv1alpha1.SubnetAddressType) []s
334333
if err != nil {
335334
log.Errorf("Error listing OOB subnets: %v", err)
336335
}
337-
fmt.Printf("OobLabel: %s", k.OobLabel)
338-
fmt.Printf("subnet-list: %v", subnetList)
336+
339337
oobSubnetNames := []string{}
340338
for _, subnet := range subnetList.Items {
341339
if subnet.Status.Type == subnetType {
342-
fmt.Printf("subnet-names: %s", subnet.Name)
343340
oobSubnetNames = append(oobSubnetNames, subnet.Name)
344341
}
345342
}
@@ -360,18 +357,11 @@ func (k K8sClient) getMatchingSubnet(subnetName string, ipaddr net.IP) (*ipamv1a
360357
return nil, fmt.Errorf("failed to get subnet %s/%s: %w", k.Namespace, subnetName, err)
361358
}
362359
if apierrors.IsNotFound(err) {
363-
log.Infof("Cannot select subnet %s/%s, does not exist", k.Namespace, subnetName)
360+
log.Debugf("Cannot select subnet %s/%s, does not exist", k.Namespace, subnetName)
364361
return nil, nil
365362
}
366363
if !checkIPInCIDR(ipaddr, existingSubnet.Status.Reserved.String()) && ipaddr.String() != UNKNOWN_IP {
367-
log.Infof("Cannot select subnet %s/%s, CIDR mismatch, subnet reserved: %s, ipaddr: %s", k.Namespace, subnetName, existingSubnet.Status.Reserved.String(), ipaddr.String())
368-
log.Infof("IP Type: %T, Value: %v", ipaddr, ipaddr)
369-
decodedIP, err := hex.DecodeString(ipaddr.String())
370-
if err != nil {
371-
log.Errorf("Failed to decode IP: %v", err)
372-
} else {
373-
log.Infof("Decoded IP Address: %s", string(decodedIP))
374-
}
364+
log.Debugf("Cannot select subnet %s/%s, CIDR mismatch", k.Namespace, subnetName)
375365
return nil, nil
376366
}
377367

@@ -424,7 +414,7 @@ func checkIPInCIDR(ip net.IP, cidrStr string) bool {
424414
// Parse the CIDR string
425415
_, cidrNet, err := net.ParseCIDR(cidrStr)
426416
if err != nil {
427-
log.Infof("Error parsing CIDR: %v\n", err)
417+
log.Errorf("Error parsing CIDR: %v\n", err)
428418
return false
429419
}
430420

plugins/oob/plugin.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ func handler6(req, resp dhcpv6.DHCPv6) (dhcpv6.DHCPv6, bool) {
107107
ipaddr := make(net.IP, len(relayMsg.LinkAddr))
108108
copy(ipaddr, relayMsg.LinkAddr)
109109

110-
fmt.Printf("k8sclient info: %s", k8sClient.OobLabel)
111-
112110
log.Infof("Requested IP address from relay %s for mac %s", ipaddr.String(), mac.String())
113111
leaseIP, err := k8sClient.getIp(ipaddr, mac, false, ipamv1alpha1.CIPv6SubnetType)
114112
if err != nil {
@@ -162,7 +160,7 @@ func setup4(args ...string) (handler.Handler4, error) {
162160
func handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool) {
163161
mac := req.ClientHWAddr
164162

165-
log.Infof("received DHCPv4 packet: %s", req.Summary())
163+
log.Debugf("received DHCPv4 packet: %s", req.Summary())
166164
log.Tracef("Message type: %s", req.MessageType().String())
167165

168166
var ipaddr net.IP
@@ -175,23 +173,23 @@ func handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool) {
175173
// ack requested address
176174
exactIP = true
177175
ipaddr = clientIP
178-
log.Infof("IP client test: %s", ipaddr)
176+
log.Debugf("IP client: %v", ipaddr)
179177
} else if requestedIP != nil {
180178
// ack requested address
181179
exactIP = true
182180
ipaddr = requestedIP
183-
log.Infof("IP client: %v", ipaddr)
181+
log.Debugf("IP client: %v", ipaddr)
184182
} else if serverIP != nil {
185183
// no client information, use server address for subnet detection
186184
exactIP = false
187185
ipaddr = serverIP
188-
log.Infof("IP server: %v", ipaddr)
186+
log.Debugf("IP server: %v", ipaddr)
189187
} else {
190188
ipaddr = net.ParseIP(UNKNOWN_IP)
191189
exactIP = false
192190
}
193191

194-
log.Infof("IP: %v", ipaddr)
192+
log.Debugf("IP: %v", ipaddr)
195193
leaseIP, err := k8sClient.getIp(ipaddr, mac, exactIP, ipamv1alpha1.CIPv4SubnetType)
196194
if err != nil {
197195
log.Errorf("Could not get IPAM IP: %s", err)
@@ -200,7 +198,7 @@ func handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool) {
200198

201199
resp.YourIPAddr = leaseIP
202200

203-
log.Infof("Sent DHCPv4 response: %s", resp.Summary())
201+
log.Debugf("Sent DHCPv4 response: %s", resp.Summary())
204202

205203
return resp, false
206204
}

0 commit comments

Comments
 (0)