1
0
mirror of https://github.com/kubernetes-sigs/descheduler.git synced 2026-01-26 05:14:13 +01:00

Merge pull request #192 from damemi/glog-klog-switch

Switch from glog to klog
This commit is contained in:
Kubernetes Prow Robot
2019-10-28 23:20:43 -07:00
committed by GitHub
71 changed files with 334 additions and 2760 deletions

View File

@@ -24,11 +24,11 @@ import (
"sigs.k8s.io/descheduler/cmd/descheduler/app/options"
"sigs.k8s.io/descheduler/pkg/descheduler"
"github.com/golang/glog"
"github.com/spf13/cobra"
aflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
"k8s.io/klog"
)
// NewDeschedulerCommand creates a *cobra.Command object with default parameters
@@ -43,7 +43,7 @@ func NewDeschedulerCommand(out io.Writer) *cobra.Command {
defer logs.FlushLogs()
err := Run(s)
if err != nil {
glog.Errorf("%v", err)
klog.Errorf("%v", err)
}
},
}

8
glide.lock generated
View File

@@ -1,5 +1,5 @@
hash: f82bf395df6f00004b1794606a9256d5c69b62deb5498b574a08b2b5d15f7a6a
updated: 2019-10-12T11:22:30.564437-04:00
updated: 2019-10-28T17:02:34.793943-04:00
imports:
- name: cloud.google.com/go
version: 8c41231e01b2085512d98153bcffb847ff9b4b9f
@@ -32,8 +32,6 @@ imports:
subpackages:
- proto
- sortkeys
- name: github.com/golang/glog
version: 23def4e6c14b4da8ac2ed8007337bc5eb5007998
- name: github.com/golang/protobuf
version: b5d812f8a3706043e23a9cd5babf2e5423744d30
subpackages:
@@ -362,7 +360,7 @@ imports:
- featuregate
- logs
- name: k8s.io/gengo
version: 7fa3014cb28f99ce2d9e803bcd3efa7edd4effa9
version: 26a664648505d962332bda642b27306bc10d1082
- name: k8s.io/klog
version: 3ca30a56d8a775276f9cdae009ba326fdc05af7f
- name: k8s.io/kube-openapi
@@ -370,7 +368,7 @@ imports:
subpackages:
- pkg/util/proto
- name: k8s.io/kubernetes
version: c97fe5036ef3df2967d086711e6c0c405941e14b
version: b1e4a13ba1f74f363154ea2e1d36047ea55190a3
subpackages:
- pkg/api/legacyscheme
- pkg/api/testapi

View File

@@ -19,7 +19,7 @@ package descheduler
import (
"fmt"
"github.com/golang/glog"
"k8s.io/klog"
"sigs.k8s.io/descheduler/cmd/descheduler/app/options"
"sigs.k8s.io/descheduler/pkg/descheduler/client"
@@ -56,7 +56,7 @@ func Run(rs *options.DeschedulerServer) error {
}
if len(nodes) <= 1 {
glog.V(1).Infof("The cluster size is 0 or 1 meaning eviction causes service disruption or degradation. So aborting..")
klog.V(1).Infof("The cluster size is 0 or 1 meaning eviction causes service disruption or degradation. So aborting..")
return nil
}

View File

@@ -19,7 +19,6 @@ package node
import (
"time"
"github.com/golang/glog"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
@@ -27,6 +26,7 @@ import (
clientset "k8s.io/client-go/kubernetes"
corelisters "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/klog"
"sigs.k8s.io/descheduler/pkg/utils"
)
@@ -48,7 +48,7 @@ func ReadyNodes(client clientset.Interface, nodeSelector string, stopChannel <-c
}
if len(nodes) == 0 {
glog.V(2).Infof("node lister returned empty list, now fetch directly")
klog.V(2).Infof("node lister returned empty list, now fetch directly")
nItems, err := client.CoreV1().Nodes().List(metav1.ListOptions{LabelSelector: nodeSelector})
if err != nil {
@@ -99,19 +99,19 @@ func IsReady(node *v1.Node) bool {
// - NodeOutOfDisk condition status is ConditionFalse,
// - NodeNetworkUnavailable condition status is ConditionFalse.
if cond.Type == v1.NodeReady && cond.Status != v1.ConditionTrue {
glog.V(1).Infof("Ignoring node %v with %v condition status %v", node.Name, cond.Type, cond.Status)
klog.V(1).Infof("Ignoring node %v with %v condition status %v", node.Name, cond.Type, cond.Status)
return false
} /*else if cond.Type == v1.NodeOutOfDisk && cond.Status != v1.ConditionFalse {
glog.V(4).Infof("Ignoring node %v with %v condition status %v", node.Name, cond.Type, cond.Status)
klog.V(4).Infof("Ignoring node %v with %v condition status %v", node.Name, cond.Type, cond.Status)
return false
} else if cond.Type == v1.NodeNetworkUnavailable && cond.Status != v1.ConditionFalse {
glog.V(4).Infof("Ignoring node %v with %v condition status %v", node.Name, cond.Type, cond.Status)
klog.V(4).Infof("Ignoring node %v with %v condition status %v", node.Name, cond.Type, cond.Status)
return false
}*/
}
// Ignore nodes that are marked unschedulable
/*if node.Spec.Unschedulable {
glog.V(4).Infof("Ignoring node %v since it is unschedulable", node.Name)
klog.V(4).Infof("Ignoring node %v since it is unschedulable", node.Name)
return false
}*/
return true
@@ -135,7 +135,7 @@ func PodFitsAnyNode(pod *v1.Pod, nodes []*v1.Node) bool {
}
if ok {
if !IsNodeUschedulable(node) {
glog.V(2).Infof("Pod %v can possibly be scheduled on %v", pod.Name, node.Name)
klog.V(2).Infof("Pod %v can possibly be scheduled on %v", pod.Name, node.Name)
return true
}
return false
@@ -150,15 +150,15 @@ func PodFitsCurrentNode(pod *v1.Pod, node *v1.Node) bool {
ok, err := utils.PodMatchNodeSelector(pod, node)
if err != nil {
glog.Error(err)
klog.Error(err)
return false
}
if !ok {
glog.V(1).Infof("Pod %v does not fit on node %v", pod.Name, node.Name)
klog.V(1).Infof("Pod %v does not fit on node %v", pod.Name, node.Name)
return false
}
glog.V(3).Infof("Pod %v fits on node %v", pod.Name, node.Name)
klog.V(3).Infof("Pod %v fits on node %v", pod.Name, node.Name)
return true
}

View File

@@ -21,8 +21,8 @@ import (
"io/ioutil"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog"
"github.com/golang/glog"
"sigs.k8s.io/descheduler/pkg/api"
"sigs.k8s.io/descheduler/pkg/api/v1alpha1"
"sigs.k8s.io/descheduler/pkg/descheduler/scheme"
@@ -30,7 +30,7 @@ import (
func LoadPolicyConfig(policyConfigFile string) (*api.DeschedulerPolicy, error) {
if policyConfigFile == "" {
glog.V(1).Infof("policy config file not specified")
klog.V(1).Infof("policy config file not specified")
return nil, nil
}

View File

@@ -19,10 +19,9 @@ package strategies
import (
"strings"
"github.com/golang/glog"
"k8s.io/api/core/v1"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/klog"
"sigs.k8s.io/descheduler/cmd/descheduler/app/options"
"sigs.k8s.io/descheduler/pkg/api"
@@ -47,11 +46,11 @@ func RemoveDuplicatePods(ds *options.DeschedulerServer, strategy api.Descheduler
func deleteDuplicatePods(client clientset.Interface, policyGroupVersion string, nodes []*v1.Node, dryRun bool, nodepodCount nodePodEvictedCount, maxPodsToEvict int, evictLocalStoragePods bool) int {
podsEvicted := 0
for _, node := range nodes {
glog.V(1).Infof("Processing node: %#v", node.Name)
klog.V(1).Infof("Processing node: %#v", node.Name)
dpm := ListDuplicatePodsOnANode(client, node, evictLocalStoragePods)
for creator, pods := range dpm {
if len(pods) > 1 {
glog.V(1).Infof("%#v", creator)
klog.V(1).Infof("%#v", creator)
// i = 0 does not evict the first pod
for i := 1; i < len(pods); i++ {
if maxPodsToEvict > 0 && nodepodCount[node]+1 > maxPodsToEvict {
@@ -59,10 +58,10 @@ func deleteDuplicatePods(client clientset.Interface, policyGroupVersion string,
}
success, err := evictions.EvictPod(client, pods[i], policyGroupVersion, dryRun)
if !success {
glog.Infof("Error when evicting pod: %#v (%#v)", pods[i].Name, err)
klog.Infof("Error when evicting pod: %#v (%#v)", pods[i].Name, err)
} else {
nodepodCount[node]++
glog.V(1).Infof("Evicted pod: %#v (%#v)", pods[i].Name, err)
klog.V(1).Infof("Evicted pod: %#v (%#v)", pods[i].Name, err)
}
}
}

View File

@@ -19,10 +19,10 @@ package strategies
import (
"sort"
"github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/klog"
helper "k8s.io/kubernetes/pkg/api/v1/resource"
"sigs.k8s.io/descheduler/cmd/descheduler/app/options"
@@ -63,42 +63,42 @@ func LowNodeUtilization(ds *options.DeschedulerServer, strategy api.DeschedulerS
npm := createNodePodsMap(ds.Client, nodes)
lowNodes, targetNodes := classifyNodes(npm, thresholds, targetThresholds, ds.EvictLocalStoragePods)
glog.V(1).Infof("Criteria for a node under utilization: CPU: %v, Mem: %v, Pods: %v",
klog.V(1).Infof("Criteria for a node under utilization: CPU: %v, Mem: %v, Pods: %v",
thresholds[v1.ResourceCPU], thresholds[v1.ResourceMemory], thresholds[v1.ResourcePods])
if len(lowNodes) == 0 {
glog.V(1).Infof("No node is underutilized, nothing to do here, you might tune your thresholds further")
klog.V(1).Infof("No node is underutilized, nothing to do here, you might tune your thresholds further")
return
}
glog.V(1).Infof("Total number of underutilized nodes: %v", len(lowNodes))
klog.V(1).Infof("Total number of underutilized nodes: %v", len(lowNodes))
if len(lowNodes) < strategy.Params.NodeResourceUtilizationThresholds.NumberOfNodes {
glog.V(1).Infof("number of nodes underutilized (%v) is less than NumberOfNodes (%v), nothing to do here", len(lowNodes), strategy.Params.NodeResourceUtilizationThresholds.NumberOfNodes)
klog.V(1).Infof("number of nodes underutilized (%v) is less than NumberOfNodes (%v), nothing to do here", len(lowNodes), strategy.Params.NodeResourceUtilizationThresholds.NumberOfNodes)
return
}
if len(lowNodes) == len(nodes) {
glog.V(1).Infof("all nodes are underutilized, nothing to do here")
klog.V(1).Infof("all nodes are underutilized, nothing to do here")
return
}
if len(targetNodes) == 0 {
glog.V(1).Infof("all nodes are under target utilization, nothing to do here")
klog.V(1).Infof("all nodes are under target utilization, nothing to do here")
return
}
glog.V(1).Infof("Criteria for a node above target utilization: CPU: %v, Mem: %v, Pods: %v",
klog.V(1).Infof("Criteria for a node above target utilization: CPU: %v, Mem: %v, Pods: %v",
targetThresholds[v1.ResourceCPU], targetThresholds[v1.ResourceMemory], targetThresholds[v1.ResourcePods])
glog.V(1).Infof("Total number of nodes above target utilization: %v", len(targetNodes))
klog.V(1).Infof("Total number of nodes above target utilization: %v", len(targetNodes))
totalPodsEvicted := evictPodsFromTargetNodes(ds.Client, evictionPolicyGroupVersion, targetNodes, lowNodes, targetThresholds, ds.DryRun, ds.MaxNoOfPodsToEvictPerNode, nodepodCount)
glog.V(1).Infof("Total number of pods evicted: %v", totalPodsEvicted)
klog.V(1).Infof("Total number of pods evicted: %v", totalPodsEvicted)
}
func validateThresholds(thresholds api.ResourceThresholds) bool {
if thresholds == nil || len(thresholds) == 0 {
glog.V(1).Infof("no resource threshold is configured")
klog.V(1).Infof("no resource threshold is configured")
return false
}
for name := range thresholds {
@@ -110,7 +110,7 @@ func validateThresholds(thresholds api.ResourceThresholds) bool {
case v1.ResourcePods:
continue
default:
glog.Errorf("only cpu, memory, or pods thresholds can be specified")
klog.Errorf("only cpu, memory, or pods thresholds can be specified")
return false
}
}
@@ -120,10 +120,10 @@ func validateThresholds(thresholds api.ResourceThresholds) bool {
//This function could be merged into above once we are clear.
func validateTargetThresholds(targetThresholds api.ResourceThresholds) bool {
if targetThresholds == nil {
glog.V(1).Infof("no target resource threshold is configured")
klog.V(1).Infof("no target resource threshold is configured")
return false
} else if _, ok := targetThresholds[v1.ResourcePods]; !ok {
glog.V(1).Infof("no target resource threshold for pods is configured")
klog.V(1).Infof("no target resource threshold for pods is configured")
return false
}
return true
@@ -139,15 +139,15 @@ func classifyNodes(npm NodePodsMap, thresholds api.ResourceThresholds, targetThr
// Check if node is underutilized and if we can schedule pods on it.
if !nodeutil.IsNodeUschedulable(node) && IsNodeWithLowUtilization(usage, thresholds) {
glog.V(2).Infof("Node %#v is under utilized with usage: %#v", node.Name, usage)
klog.V(2).Infof("Node %#v is under utilized with usage: %#v", node.Name, usage)
lowNodes = append(lowNodes, nuMap)
} else if IsNodeAboveTargetUtilization(usage, targetThresholds) {
glog.V(2).Infof("Node %#v is over utilized with usage: %#v", node.Name, usage)
klog.V(2).Infof("Node %#v is over utilized with usage: %#v", node.Name, usage)
targetNodes = append(targetNodes, nuMap)
} else {
glog.V(2).Infof("Node %#v is appropriately utilized with usage: %#v", node.Name, usage)
klog.V(2).Infof("Node %#v is appropriately utilized with usage: %#v", node.Name, usage)
}
glog.V(2).Infof("allPods:%v, nonRemovablePods:%v, bePods:%v, bPods:%v, gPods:%v", len(allPods), len(nonRemovablePods), len(bePods), len(bPods), len(gPods))
klog.V(2).Infof("allPods:%v, nonRemovablePods:%v, bePods:%v, bPods:%v, gPods:%v", len(allPods), len(nonRemovablePods), len(bePods), len(bPods), len(gPods))
}
return lowNodes, targetNodes
}
@@ -184,20 +184,20 @@ func evictPodsFromTargetNodes(client clientset.Interface, evictionPolicyGroupVer
}
}
glog.V(1).Infof("Total capacity to be moved: CPU:%v, Mem:%v, Pods:%v", totalCPU, totalMem, totalPods)
glog.V(1).Infof("********Number of pods evicted from each node:***********")
klog.V(1).Infof("Total capacity to be moved: CPU:%v, Mem:%v, Pods:%v", totalCPU, totalMem, totalPods)
klog.V(1).Infof("********Number of pods evicted from each node:***********")
for _, node := range targetNodes {
nodeCapacity := node.node.Status.Capacity
if len(node.node.Status.Allocatable) > 0 {
nodeCapacity = node.node.Status.Allocatable
}
glog.V(3).Infof("evicting pods from node %#v with usage: %#v", node.node.Name, node.usage)
klog.V(3).Infof("evicting pods from node %#v with usage: %#v", node.node.Name, node.usage)
currentPodsEvicted := nodepodCount[node.node]
// Check if one pod has priority, if yes, assume that all pods have priority and evict pods based on priority.
if node.allPods[0].Spec.Priority != nil {
glog.V(1).Infof("All pods have priority associated with them. Evicting pods based on priority")
klog.V(1).Infof("All pods have priority associated with them. Evicting pods based on priority")
evictablePods := make([]*v1.Pod, 0)
evictablePods = append(append(node.bPods, node.bePods...), node.gPods...)
@@ -207,8 +207,8 @@ func evictPodsFromTargetNodes(client clientset.Interface, evictionPolicyGroupVer
} else {
// TODO: Remove this when we support only priority.
// Falling back to evicting pods based on priority.
glog.V(1).Infof("Evicting pods based on QoS")
glog.V(1).Infof("There are %v non-evictable pods on the node", len(node.nonRemovablePods))
klog.V(1).Infof("Evicting pods based on QoS")
klog.V(1).Infof("There are %v non-evictable pods on the node", len(node.nonRemovablePods))
// evict best effort pods
evictPods(node.bePods, client, evictionPolicyGroupVersion, targetThresholds, nodeCapacity, node.usage, &totalPods, &totalCPU, &totalMem, &currentPodsEvicted, dryRun, maxPodsToEvict)
// evict burstable pods
@@ -218,7 +218,7 @@ func evictPodsFromTargetNodes(client clientset.Interface, evictionPolicyGroupVer
}
nodepodCount[node.node] = currentPodsEvicted
podsEvicted = podsEvicted + nodepodCount[node.node]
glog.V(1).Infof("%v pods evicted from node %#v with usage %v", nodepodCount[node.node], node.node.Name, node.usage)
klog.V(1).Infof("%v pods evicted from node %#v with usage %v", nodepodCount[node.node], node.node.Name, node.usage)
}
return podsEvicted
}
@@ -244,9 +244,9 @@ func evictPods(inputPods []*v1.Pod,
mUsage := helper.GetResourceRequest(pod, v1.ResourceMemory)
success, err := evictions.EvictPod(client, pod, evictionPolicyGroupVersion, dryRun)
if !success {
glog.Warningf("Error when evicting pod: %#v (%#v)", pod.Name, err)
klog.Warningf("Error when evicting pod: %#v (%#v)", pod.Name, err)
} else {
glog.V(3).Infof("Evicted pod: %#v (%#v)", pod.Name, err)
klog.V(3).Infof("Evicted pod: %#v (%#v)", pod.Name, err)
// update remaining pods
*podsEvicted++
nodeUsage[v1.ResourcePods] -= onePodPercentage
@@ -260,7 +260,7 @@ func evictPods(inputPods []*v1.Pod,
*totalMem -= float64(mUsage)
nodeUsage[v1.ResourceMemory] -= api.Percentage(float64(mUsage) / float64(nodeCapacity.Memory().Value()) * 100)
glog.V(3).Infof("updated node usage: %#v", nodeUsage)
klog.V(3).Infof("updated node usage: %#v", nodeUsage)
// check if node utilization drops below target threshold or required capacity (cpu, memory, pods) is moved
if !IsNodeAboveTargetUtilization(nodeUsage, targetThresholds) || (*totalPods <= 0 && *totalCPU <= 0 && *totalMem <= 0) {
break
@@ -316,7 +316,7 @@ func createNodePodsMap(client clientset.Interface, nodes []*v1.Node) NodePodsMap
for _, node := range nodes {
pods, err := podutil.ListPodsOnANode(client, node)
if err != nil {
glog.Warningf("node %s will not be processed, error in accessing its pods (%#v)", node.Name, err)
klog.Warningf("node %s will not be processed, error in accessing its pods (%#v)", node.Name, err)
} else {
npm[node] = pods
}

View File

@@ -17,8 +17,9 @@ limitations under the License.
package strategies
import (
"github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/klog"
"sigs.k8s.io/descheduler/cmd/descheduler/app/options"
"sigs.k8s.io/descheduler/pkg/api"
"sigs.k8s.io/descheduler/pkg/descheduler/evictions"
@@ -37,16 +38,16 @@ func removePodsViolatingNodeAffinityCount(ds *options.DeschedulerServer, strateg
}
for _, nodeAffinity := range strategy.Params.NodeAffinityType {
glog.V(2).Infof("Executing for nodeAffinityType: %v", nodeAffinity)
klog.V(2).Infof("Executing for nodeAffinityType: %v", nodeAffinity)
switch nodeAffinity {
case "requiredDuringSchedulingIgnoredDuringExecution":
for _, node := range nodes {
glog.V(1).Infof("Processing node: %#v\n", node.Name)
klog.V(1).Infof("Processing node: %#v\n", node.Name)
pods, err := podutil.ListEvictablePodsOnNode(ds.Client, node, evictLocalStoragePods)
if err != nil {
glog.Errorf("failed to get pods from %v: %v", node.Name, err)
klog.Errorf("failed to get pods from %v: %v", node.Name, err)
}
for _, pod := range pods {
@@ -56,7 +57,7 @@ func removePodsViolatingNodeAffinityCount(ds *options.DeschedulerServer, strateg
if pod.Spec.Affinity != nil && pod.Spec.Affinity.NodeAffinity != nil && pod.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution != nil {
if !nodeutil.PodFitsCurrentNode(pod, node) && nodeutil.PodFitsAnyNode(pod, nodes) {
glog.V(1).Infof("Evicting pod: %v", pod.Name)
klog.V(1).Infof("Evicting pod: %v", pod.Name)
evictions.EvictPod(ds.Client, pod, evictionPolicyGroupVersion, ds.DryRun)
nodepodCount[node]++
}
@@ -65,10 +66,10 @@ func removePodsViolatingNodeAffinityCount(ds *options.DeschedulerServer, strateg
evictedPodCount += nodepodCount[node]
}
default:
glog.Errorf("invalid nodeAffinityType: %v", nodeAffinity)
klog.Errorf("invalid nodeAffinityType: %v", nodeAffinity)
return evictedPodCount
}
}
glog.V(1).Infof("Evicted %v pods", evictedPodCount)
klog.V(1).Infof("Evicted %v pods", evictedPodCount)
return evictedPodCount
}

View File

@@ -22,11 +22,10 @@ import (
"sigs.k8s.io/descheduler/pkg/descheduler/evictions"
podutil "sigs.k8s.io/descheduler/pkg/descheduler/pod"
"github.com/golang/glog"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/klog"
priorityutil "k8s.io/kubernetes/pkg/scheduler/algorithm/priorities/util"
)
@@ -42,7 +41,7 @@ func RemovePodsViolatingInterPodAntiAffinity(ds *options.DeschedulerServer, stra
func removePodsWithAffinityRules(client clientset.Interface, policyGroupVersion string, nodes []*v1.Node, dryRun bool, nodePodCount nodePodEvictedCount, maxPodsToEvict int, evictLocalStoragePods bool) int {
podsEvicted := 0
for _, node := range nodes {
glog.V(1).Infof("Processing node: %#v\n", node.Name)
klog.V(1).Infof("Processing node: %#v\n", node.Name)
pods, err := podutil.ListEvictablePodsOnNode(client, node, evictLocalStoragePods)
if err != nil {
return 0
@@ -55,10 +54,10 @@ func removePodsWithAffinityRules(client clientset.Interface, policyGroupVersion
if checkPodsWithAntiAffinityExist(pods[i], pods) {
success, err := evictions.EvictPod(client, pods[i], policyGroupVersion, dryRun)
if !success {
glog.Infof("Error when evicting pod: %#v (%#v)\n", pods[i].Name, err)
klog.Infof("Error when evicting pod: %#v (%#v)\n", pods[i].Name, err)
} else {
nodePodCount[node]++
glog.V(1).Infof("Evicted pod: %#v (%#v)\n because of existing anti-affinity", pods[i].Name, err)
klog.V(1).Infof("Evicted pod: %#v (%#v)\n because of existing anti-affinity", pods[i].Name, err)
// Since the current pod is evicted all other pods which have anti-affinity with this
// pod need not be evicted.
// Update pods.
@@ -81,7 +80,7 @@ func checkPodsWithAntiAffinityExist(pod *v1.Pod, pods []*v1.Pod) bool {
namespaces := priorityutil.GetNamespacesFromPodAffinityTerm(pod, &term)
selector, err := metav1.LabelSelectorAsSelector(term.LabelSelector)
if err != nil {
glog.Infof("%v", err)
klog.Infof("%v", err)
return false
}
for _, existingPod := range pods {

View File

@@ -19,9 +19,9 @@ package utils
import (
"fmt"
"github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/klog"
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
)
@@ -70,7 +70,7 @@ func podMatchesNodeLabels(pod *v1.Pod, node *v1.Node) bool {
// Match node selector for requiredDuringSchedulingIgnoredDuringExecution.
if nodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution != nil {
nodeSelectorTerms := nodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms
glog.V(10).Infof("Match for RequiredDuringSchedulingIgnoredDuringExecution node selector terms %+v", nodeSelectorTerms)
klog.V(10).Infof("Match for RequiredDuringSchedulingIgnoredDuringExecution node selector terms %+v", nodeSelectorTerms)
return nodeMatchesNodeSelectorTerms(node, nodeSelectorTerms)
}
}
@@ -83,7 +83,7 @@ func nodeMatchesNodeSelectorTerms(node *v1.Node, nodeSelectorTerms []v1.NodeSele
for _, req := range nodeSelectorTerms {
nodeSelector, err := v1helper.NodeSelectorRequirementsAsSelector(req.MatchExpressions)
if err != nil {
glog.V(10).Infof("Failed to parse MatchExpressions: %+v, regarding as not match.", req.MatchExpressions)
klog.V(10).Infof("Failed to parse MatchExpressions: %+v, regarding as not match.", req.MatchExpressions)
return false
}
if nodeSelector.Matches(labels.Set(node.Labels)) {

View File

@@ -21,12 +21,11 @@ import (
"testing"
"time"
"github.com/golang/glog"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/klog"
"k8s.io/kubernetes/pkg/api/testapi"
"sigs.k8s.io/descheduler/cmd/descheduler/app/options"
deschedulerapi "sigs.k8s.io/descheduler/pkg/api"
@@ -104,12 +103,12 @@ func startEndToEndForLowNodeUtilization(clientset clientset.Interface) {
// Run descheduler.
evictionPolicyGroupVersion, err := eutils.SupportEviction(clientset)
if err != nil || len(evictionPolicyGroupVersion) == 0 {
glog.Fatalf("%v", err)
klog.Fatalf("%v", err)
}
stopChannel := make(chan struct{})
nodes, err := nodeutil.ReadyNodes(clientset, "", stopChannel)
if err != nil {
glog.Fatalf("%v", err)
klog.Fatalf("%v", err)
}
nodeUtilizationThresholds := deschedulerapi.NodeResourceUtilizationThresholds{Thresholds: thresholds, TargetThresholds: targetThresholds}
nodeUtilizationStrategyParams := deschedulerapi.StrategyParameters{NodeResourceUtilizationThresholds: nodeUtilizationThresholds}

191
vendor/github.com/golang/glog/LICENSE generated vendored
View File

@@ -1,191 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and
distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright
owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities
that control, are controlled by, or are under common control with that entity.
For the purposes of this definition, "control" means (i) the power, direct or
indirect, to cause the direction or management of such entity, whether by
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising
permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including
but not limited to software source code, documentation source, and configuration
files.
"Object" form shall mean any form resulting from mechanical transformation or
translation of a Source form, including but not limited to compiled object code,
generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made
available under the License, as indicated by a copyright notice that is included
in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that
is based on (or derived from) the Work and for which the editorial revisions,
annotations, elaborations, or other modifications represent, as a whole, an
original work of authorship. For the purposes of this License, Derivative Works
shall not include works that remain separable from, or merely link (or bind by
name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version
of the Work and any modifications or additions to that Work or Derivative Works
thereof, that is intentionally submitted to Licensor for inclusion in the Work
by the copyright owner or by an individual or Legal Entity authorized to submit
on behalf of the copyright owner. For the purposes of this definition,
"submitted" means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems, and
issue tracking systems that are managed by, or on behalf of, the Licensor for
the purpose of discussing and improving the Work, but excluding communication
that is conspicuously marked or otherwise designated in writing by the copyright
owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
of whom a Contribution has been received by Licensor and subsequently
incorporated within the Work.
2. Grant of Copyright License.
Subject to the terms and conditions of this License, each Contributor hereby
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
irrevocable copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the Work and such
Derivative Works in Source or Object form.
3. Grant of Patent License.
Subject to the terms and conditions of this License, each Contributor hereby
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to make, have
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
such license applies only to those patent claims licensable by such Contributor
that are necessarily infringed by their Contribution(s) alone or by combination
of their Contribution(s) with the Work to which such Contribution(s) was
submitted. If You institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
Contribution incorporated within the Work constitutes direct or contributory
patent infringement, then any patent licenses granted to You under this License
for that Work shall terminate as of the date such litigation is filed.
4. Redistribution.
You may reproduce and distribute copies of the Work or Derivative Works thereof
in any medium, with or without modifications, and in Source or Object form,
provided that You meet the following conditions:
You must give any other recipients of the Work or Derivative Works a copy of
this License; and
You must cause any modified files to carry prominent notices stating that You
changed the files; and
You must retain, in the Source form of any Derivative Works that You distribute,
all copyright, patent, trademark, and attribution notices from the Source form
of the Work, excluding those notices that do not pertain to any part of the
Derivative Works; and
If the Work includes a "NOTICE" text file as part of its distribution, then any
Derivative Works that You distribute must include a readable copy of the
attribution notices contained within such NOTICE file, excluding those notices
that do not pertain to any part of the Derivative Works, in at least one of the
following places: within a NOTICE text file distributed as part of the
Derivative Works; within the Source form or documentation, if provided along
with the Derivative Works; or, within a display generated by the Derivative
Works, if and wherever such third-party notices normally appear. The contents of
the NOTICE file are for informational purposes only and do not modify the
License. You may add Your own attribution notices within Derivative Works that
You distribute, alongside or as an addendum to the NOTICE text from the Work,
provided that such additional attribution notices cannot be construed as
modifying the License.
You may add Your own copyright statement to Your modifications and may provide
additional or different license terms and conditions for use, reproduction, or
distribution of Your modifications, or for any such Derivative Works as a whole,
provided Your use, reproduction, and distribution of the Work otherwise complies
with the conditions stated in this License.
5. Submission of Contributions.
Unless You explicitly state otherwise, any Contribution intentionally submitted
for inclusion in the Work by You to the Licensor shall be under the terms and
conditions of this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify the terms of
any separate license agreement you may have executed with Licensor regarding
such Contributions.
6. Trademarks.
This License does not grant permission to use the trade names, trademarks,
service marks, or product names of the Licensor, except as required for
reasonable and customary use in describing the origin of the Work and
reproducing the content of the NOTICE file.
7. Disclaimer of Warranty.
Unless required by applicable law or agreed to in writing, Licensor provides the
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
including, without limitation, any warranties or conditions of TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
solely responsible for determining the appropriateness of using or
redistributing the Work and assume any risks associated with Your exercise of
permissions under this License.
8. Limitation of Liability.
In no event and under no legal theory, whether in tort (including negligence),
contract, or otherwise, unless required by applicable law (such as deliberate
and grossly negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special, incidental,
or consequential damages of any character arising as a result of this License or
out of the use or inability to use the Work (including but not limited to
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
any and all other commercial damages or losses), even if such Contributor has
been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability.
While redistributing the Work or Derivative Works thereof, You may choose to
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
other liability obligations and/or rights consistent with this License. However,
in accepting such obligations, You may act only on Your own behalf and on Your
sole responsibility, not on behalf of any other Contributor, and only if You
agree to indemnify, defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason of your
accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work
To apply the Apache License to your work, attach the following boilerplate
notice, with the fields enclosed by brackets "[]" replaced with your own
identifying information. (Don't include the brackets!) The text should be
enclosed in the appropriate comment syntax for the file format. We also
recommend that a file or class name and description of purpose be included on
the same "printed page" as the copyright notice for easier identification within
third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

44
vendor/github.com/golang/glog/README generated vendored
View File

@@ -1,44 +0,0 @@
glog
====
Leveled execution logs for Go.
This is an efficient pure Go implementation of leveled logs in the
manner of the open source C++ package
https://github.com/google/glog
By binding methods to booleans it is possible to use the log package
without paying the expense of evaluating the arguments to the log.
Through the -vmodule flag, the package also provides fine-grained
control over logging at the file level.
The comment from glog.go introduces the ideas:
Package glog implements logging analogous to the Google-internal
C++ INFO/ERROR/V setup. It provides functions Info, Warning,
Error, Fatal, plus formatting variants such as Infof. It
also provides V-style logging controlled by the -v and
-vmodule=file=2 flags.
Basic examples:
glog.Info("Prepare to repel boarders")
glog.Fatalf("Initialization failed: %s", err)
See the documentation for the V function for an explanation
of these examples:
if glog.V(2) {
glog.Info("Starting transaction...")
}
glog.V(2).Infoln("Processed", nItems, "elements")
The repository contains an open source version of the log package
used inside Google. The master copy of the source lives inside
Google, not here. The code in this repo is for export only and is not itself
under development. Feature requests will be ignored.
Send bug reports to golang-nuts@googlegroups.com.

1180
vendor/github.com/golang/glog/glog.go generated vendored

File diff suppressed because it is too large Load Diff

View File

@@ -1,124 +0,0 @@
// Go support for leveled logs, analogous to https://code.google.com/p/google-glog/
//
// Copyright 2013 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// File I/O for logs.
package glog
import (
"errors"
"flag"
"fmt"
"os"
"os/user"
"path/filepath"
"strings"
"sync"
"time"
)
// MaxSize is the maximum size of a log file in bytes.
var MaxSize uint64 = 1024 * 1024 * 1800
// logDirs lists the candidate directories for new log files.
var logDirs []string
// If non-empty, overrides the choice of directory in which to write logs.
// See createLogDirs for the full list of possible destinations.
var logDir = flag.String("log_dir", "", "If non-empty, write log files in this directory")
func createLogDirs() {
if *logDir != "" {
logDirs = append(logDirs, *logDir)
}
logDirs = append(logDirs, os.TempDir())
}
var (
pid = os.Getpid()
program = filepath.Base(os.Args[0])
host = "unknownhost"
userName = "unknownuser"
)
func init() {
h, err := os.Hostname()
if err == nil {
host = shortHostname(h)
}
current, err := user.Current()
if err == nil {
userName = current.Username
}
// Sanitize userName since it may contain filepath separators on Windows.
userName = strings.Replace(userName, `\`, "_", -1)
}
// shortHostname returns its argument, truncating at the first period.
// For instance, given "www.google.com" it returns "www".
func shortHostname(hostname string) string {
if i := strings.Index(hostname, "."); i >= 0 {
return hostname[:i]
}
return hostname
}
// logName returns a new log file name containing tag, with start time t, and
// the name for the symlink for tag.
func logName(tag string, t time.Time) (name, link string) {
name = fmt.Sprintf("%s.%s.%s.log.%s.%04d%02d%02d-%02d%02d%02d.%d",
program,
host,
userName,
tag,
t.Year(),
t.Month(),
t.Day(),
t.Hour(),
t.Minute(),
t.Second(),
pid)
return name, program + "." + tag
}
var onceLogDirs sync.Once
// create creates a new log file and returns the file and its filename, which
// contains tag ("INFO", "FATAL", etc.) and t. If the file is created
// successfully, create also attempts to update the symlink for that tag, ignoring
// errors.
func create(tag string, t time.Time) (f *os.File, filename string, err error) {
onceLogDirs.Do(createLogDirs)
if len(logDirs) == 0 {
return nil, "", errors.New("log: no log dirs")
}
name, link := logName(tag, t)
var lastErr error
for _, dir := range logDirs {
fname := filepath.Join(dir, name)
f, err := os.Create(fname)
if err == nil {
symlink := filepath.Join(dir, link)
os.Remove(symlink) // ignore err
os.Symlink(name, symlink) // ignore err
return f, fname, nil
}
lastErr = err
}
return nil, "", fmt.Errorf("log: cannot create log: %v", lastErr)
}

View File

@@ -1,415 +0,0 @@
// Go support for leveled logs, analogous to https://code.google.com/p/google-glog/
//
// Copyright 2013 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package glog
import (
"bytes"
"fmt"
stdLog "log"
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"
"time"
)
// Test that shortHostname works as advertised.
func TestShortHostname(t *testing.T) {
for hostname, expect := range map[string]string{
"": "",
"host": "host",
"host.google.com": "host",
} {
if got := shortHostname(hostname); expect != got {
t.Errorf("shortHostname(%q): expected %q, got %q", hostname, expect, got)
}
}
}
// flushBuffer wraps a bytes.Buffer to satisfy flushSyncWriter.
type flushBuffer struct {
bytes.Buffer
}
func (f *flushBuffer) Flush() error {
return nil
}
func (f *flushBuffer) Sync() error {
return nil
}
// swap sets the log writers and returns the old array.
func (l *loggingT) swap(writers [numSeverity]flushSyncWriter) (old [numSeverity]flushSyncWriter) {
l.mu.Lock()
defer l.mu.Unlock()
old = l.file
for i, w := range writers {
logging.file[i] = w
}
return
}
// newBuffers sets the log writers to all new byte buffers and returns the old array.
func (l *loggingT) newBuffers() [numSeverity]flushSyncWriter {
return l.swap([numSeverity]flushSyncWriter{new(flushBuffer), new(flushBuffer), new(flushBuffer), new(flushBuffer)})
}
// contents returns the specified log value as a string.
func contents(s severity) string {
return logging.file[s].(*flushBuffer).String()
}
// contains reports whether the string is contained in the log.
func contains(s severity, str string, t *testing.T) bool {
return strings.Contains(contents(s), str)
}
// setFlags configures the logging flags how the test expects them.
func setFlags() {
logging.toStderr = false
}
// Test that Info works as advertised.
func TestInfo(t *testing.T) {
setFlags()
defer logging.swap(logging.newBuffers())
Info("test")
if !contains(infoLog, "I", t) {
t.Errorf("Info has wrong character: %q", contents(infoLog))
}
if !contains(infoLog, "test", t) {
t.Error("Info failed")
}
}
func TestInfoDepth(t *testing.T) {
setFlags()
defer logging.swap(logging.newBuffers())
f := func() { InfoDepth(1, "depth-test1") }
// The next three lines must stay together
_, _, wantLine, _ := runtime.Caller(0)
InfoDepth(0, "depth-test0")
f()
msgs := strings.Split(strings.TrimSuffix(contents(infoLog), "\n"), "\n")
if len(msgs) != 2 {
t.Fatalf("Got %d lines, expected 2", len(msgs))
}
for i, m := range msgs {
if !strings.HasPrefix(m, "I") {
t.Errorf("InfoDepth[%d] has wrong character: %q", i, m)
}
w := fmt.Sprintf("depth-test%d", i)
if !strings.Contains(m, w) {
t.Errorf("InfoDepth[%d] missing %q: %q", i, w, m)
}
// pull out the line number (between : and ])
msg := m[strings.LastIndex(m, ":")+1:]
x := strings.Index(msg, "]")
if x < 0 {
t.Errorf("InfoDepth[%d]: missing ']': %q", i, m)
continue
}
line, err := strconv.Atoi(msg[:x])
if err != nil {
t.Errorf("InfoDepth[%d]: bad line number: %q", i, m)
continue
}
wantLine++
if wantLine != line {
t.Errorf("InfoDepth[%d]: got line %d, want %d", i, line, wantLine)
}
}
}
func init() {
CopyStandardLogTo("INFO")
}
// Test that CopyStandardLogTo panics on bad input.
func TestCopyStandardLogToPanic(t *testing.T) {
defer func() {
if s, ok := recover().(string); !ok || !strings.Contains(s, "LOG") {
t.Errorf(`CopyStandardLogTo("LOG") should have panicked: %v`, s)
}
}()
CopyStandardLogTo("LOG")
}
// Test that using the standard log package logs to INFO.
func TestStandardLog(t *testing.T) {
setFlags()
defer logging.swap(logging.newBuffers())
stdLog.Print("test")
if !contains(infoLog, "I", t) {
t.Errorf("Info has wrong character: %q", contents(infoLog))
}
if !contains(infoLog, "test", t) {
t.Error("Info failed")
}
}
// Test that the header has the correct format.
func TestHeader(t *testing.T) {
setFlags()
defer logging.swap(logging.newBuffers())
defer func(previous func() time.Time) { timeNow = previous }(timeNow)
timeNow = func() time.Time {
return time.Date(2006, 1, 2, 15, 4, 5, .067890e9, time.Local)
}
pid = 1234
Info("test")
var line int
format := "I0102 15:04:05.067890 1234 glog_test.go:%d] test\n"
n, err := fmt.Sscanf(contents(infoLog), format, &line)
if n != 1 || err != nil {
t.Errorf("log format error: %d elements, error %s:\n%s", n, err, contents(infoLog))
}
// Scanf treats multiple spaces as equivalent to a single space,
// so check for correct space-padding also.
want := fmt.Sprintf(format, line)
if contents(infoLog) != want {
t.Errorf("log format error: got:\n\t%q\nwant:\t%q", contents(infoLog), want)
}
}
// Test that an Error log goes to Warning and Info.
// Even in the Info log, the source character will be E, so the data should
// all be identical.
func TestError(t *testing.T) {
setFlags()
defer logging.swap(logging.newBuffers())
Error("test")
if !contains(errorLog, "E", t) {
t.Errorf("Error has wrong character: %q", contents(errorLog))
}
if !contains(errorLog, "test", t) {
t.Error("Error failed")
}
str := contents(errorLog)
if !contains(warningLog, str, t) {
t.Error("Warning failed")
}
if !contains(infoLog, str, t) {
t.Error("Info failed")
}
}
// Test that a Warning log goes to Info.
// Even in the Info log, the source character will be W, so the data should
// all be identical.
func TestWarning(t *testing.T) {
setFlags()
defer logging.swap(logging.newBuffers())
Warning("test")
if !contains(warningLog, "W", t) {
t.Errorf("Warning has wrong character: %q", contents(warningLog))
}
if !contains(warningLog, "test", t) {
t.Error("Warning failed")
}
str := contents(warningLog)
if !contains(infoLog, str, t) {
t.Error("Info failed")
}
}
// Test that a V log goes to Info.
func TestV(t *testing.T) {
setFlags()
defer logging.swap(logging.newBuffers())
logging.verbosity.Set("2")
defer logging.verbosity.Set("0")
V(2).Info("test")
if !contains(infoLog, "I", t) {
t.Errorf("Info has wrong character: %q", contents(infoLog))
}
if !contains(infoLog, "test", t) {
t.Error("Info failed")
}
}
// Test that a vmodule enables a log in this file.
func TestVmoduleOn(t *testing.T) {
setFlags()
defer logging.swap(logging.newBuffers())
logging.vmodule.Set("glog_test=2")
defer logging.vmodule.Set("")
if !V(1) {
t.Error("V not enabled for 1")
}
if !V(2) {
t.Error("V not enabled for 2")
}
if V(3) {
t.Error("V enabled for 3")
}
V(2).Info("test")
if !contains(infoLog, "I", t) {
t.Errorf("Info has wrong character: %q", contents(infoLog))
}
if !contains(infoLog, "test", t) {
t.Error("Info failed")
}
}
// Test that a vmodule of another file does not enable a log in this file.
func TestVmoduleOff(t *testing.T) {
setFlags()
defer logging.swap(logging.newBuffers())
logging.vmodule.Set("notthisfile=2")
defer logging.vmodule.Set("")
for i := 1; i <= 3; i++ {
if V(Level(i)) {
t.Errorf("V enabled for %d", i)
}
}
V(2).Info("test")
if contents(infoLog) != "" {
t.Error("V logged incorrectly")
}
}
// vGlobs are patterns that match/don't match this file at V=2.
var vGlobs = map[string]bool{
// Easy to test the numeric match here.
"glog_test=1": false, // If -vmodule sets V to 1, V(2) will fail.
"glog_test=2": true,
"glog_test=3": true, // If -vmodule sets V to 1, V(3) will succeed.
// These all use 2 and check the patterns. All are true.
"*=2": true,
"?l*=2": true,
"????_*=2": true,
"??[mno]?_*t=2": true,
// These all use 2 and check the patterns. All are false.
"*x=2": false,
"m*=2": false,
"??_*=2": false,
"?[abc]?_*t=2": false,
}
// Test that vmodule globbing works as advertised.
func testVmoduleGlob(pat string, match bool, t *testing.T) {
setFlags()
defer logging.swap(logging.newBuffers())
defer logging.vmodule.Set("")
logging.vmodule.Set(pat)
if V(2) != Verbose(match) {
t.Errorf("incorrect match for %q: got %t expected %t", pat, V(2), match)
}
}
// Test that a vmodule globbing works as advertised.
func TestVmoduleGlob(t *testing.T) {
for glob, match := range vGlobs {
testVmoduleGlob(glob, match, t)
}
}
func TestRollover(t *testing.T) {
setFlags()
var err error
defer func(previous func(error)) { logExitFunc = previous }(logExitFunc)
logExitFunc = func(e error) {
err = e
}
defer func(previous uint64) { MaxSize = previous }(MaxSize)
MaxSize = 512
Info("x") // Be sure we have a file.
info, ok := logging.file[infoLog].(*syncBuffer)
if !ok {
t.Fatal("info wasn't created")
}
if err != nil {
t.Fatalf("info has initial error: %v", err)
}
fname0 := info.file.Name()
Info(strings.Repeat("x", int(MaxSize))) // force a rollover
if err != nil {
t.Fatalf("info has error after big write: %v", err)
}
// Make sure the next log file gets a file name with a different
// time stamp.
//
// TODO: determine whether we need to support subsecond log
// rotation. C++ does not appear to handle this case (nor does it
// handle Daylight Savings Time properly).
time.Sleep(1 * time.Second)
Info("x") // create a new file
if err != nil {
t.Fatalf("error after rotation: %v", err)
}
fname1 := info.file.Name()
if fname0 == fname1 {
t.Errorf("info.f.Name did not change: %v", fname0)
}
if info.nbytes >= MaxSize {
t.Errorf("file size was not reset: %d", info.nbytes)
}
}
func TestLogBacktraceAt(t *testing.T) {
setFlags()
defer logging.swap(logging.newBuffers())
// The peculiar style of this code simplifies line counting and maintenance of the
// tracing block below.
var infoLine string
setTraceLocation := func(file string, line int, ok bool, delta int) {
if !ok {
t.Fatal("could not get file:line")
}
_, file = filepath.Split(file)
infoLine = fmt.Sprintf("%s:%d", file, line+delta)
err := logging.traceLocation.Set(infoLine)
if err != nil {
t.Fatal("error setting log_backtrace_at: ", err)
}
}
{
// Start of tracing block. These lines know about each other's relative position.
_, file, line, ok := runtime.Caller(0)
setTraceLocation(file, line, ok, +2) // Two lines between Caller and Info calls.
Info("we want a stack trace here")
}
numAppearances := strings.Count(contents(infoLog), infoLine)
if numAppearances < 2 {
// Need 2 appearances, one in the log header and one in the trace:
// log_test.go:281: I0511 16:36:06.952398 02238 log_test.go:280] we want a stack trace here
// ...
// github.com/glog/glog_test.go:280 (0x41ba91)
// ...
// We could be more precise but that would require knowing the details
// of the traceback format, which may not be dependable.
t.Fatal("got no trace back; log is ", contents(infoLog))
}
}
func BenchmarkHeader(b *testing.B) {
for i := 0; i < b.N; i++ {
buf, _, _ := logging.header(infoLog, 0)
logging.putBuffer(buf)
}
}

2
vendor/k8s.io/gengo/.travis.yml generated vendored
View File

@@ -13,4 +13,4 @@ jobs:
- go test -v ./...
- stage: Verify examples
script:
- go run ./examples/import-boss/main.go -i $(go list k8s.io/gengo/... | grep -v import-boss/tests | paste -sd',' -) --verify-only
- go run ./examples/import-boss/main.go -i k8s.io/gengo/... --verify-only

3
vendor/k8s.io/gengo/args/args.go generated vendored
View File

@@ -159,9 +159,6 @@ func (g *GeneratorArgs) InputIncludes(p *types.Package) bool {
if strings.HasSuffix(d, "...") {
d = strings.TrimSuffix(d, "...")
}
if strings.HasPrefix(d, "./vendor/") {
d = strings.TrimPrefix(d, "./vendor/")
}
if strings.HasPrefix(p.Path, d) {
return true
}

View File

@@ -248,11 +248,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
shouldCreateObjectDefaulterFn := func(t *types.Type) bool {
if defaults, ok := existingDefaulters[t]; ok && defaults.object != nil {
// A default generator is defined
baseTypeName := "<unknown>"
if defaults.base != nil {
baseTypeName = defaults.base.Name.String()
}
klog.V(5).Infof(" an object defaulter already exists as %s", baseTypeName)
klog.V(5).Infof(" an object defaulter already exists as %s", defaults.base.Name)
return false
}
// opt-out

View File

@@ -1,28 +0,0 @@
TOOL=import-boss
all: test
test: build test_rules test_inverse
build:
@go build -o /tmp/$(TOOL)
test_rules:
/tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/rules/a)
! /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/rules/b)
/tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/rules/c)
! /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/rules/nested)
/tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/rules/nested/nested)
! /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/rules/nested/nested/nested)
! /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/rules/nested/nested/nested/inherit)
test_inverse:
/tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/inverse/a ./tests/inverse/lib/... | grep -v quarantine | paste -sd',' -)
! /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/inverse/b ./tests/inverse/lib/... | grep -v quarantine | paste -sd',' -)
/tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/inverse/c ./tests/inverse/lib/... | grep -v quarantine | paste -sd',' -)
! /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/inverse/d ./tests/inverse/lib/... | grep -v quarantine | paste -sd',' -)
! /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/inverse/lib/... | paste -sd',' -)
! /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/inverse/lib/... | paste -sd',' -)
.PHONY: build test test_rules test_inverse

View File

@@ -38,7 +38,6 @@ import (
)
const (
goModFile = "go.mod"
importBossFileType = "import-boss"
)
@@ -59,7 +58,7 @@ func DefaultNameSystem() string {
func Packages(c *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
pkgs := generator.Packages{}
c.FileTypes = map[string]generator.FileType{
importBossFileType: importRuleFile{c},
importBossFileType: importRuleFile{},
}
for _, p := range c.Universe {
@@ -71,7 +70,6 @@ func Packages(c *generator.Context, arguments *args.GeneratorArgs) generator.Pac
pkgs = append(pkgs, &generator.DefaultPackage{
PackageName: p.Name,
PackagePath: p.Path,
Source: p.SourcePath,
// GeneratorFunc returns a list of generators. Each generator makes a
// single file.
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
@@ -98,19 +96,10 @@ type Rule struct {
ForbiddenPrefixes []string
}
type InverseRule struct {
Rule
// True if the rule is to be applied to transitive imports.
Transitive bool
}
type fileFormat struct {
CurrentImports []string
Rules []Rule
InverseRules []InverseRule
path string
Rules []Rule
}
func readFile(path string) (*fileFormat, error) {
@@ -124,7 +113,6 @@ func readFile(path string) (*fileFormat, error) {
if err != nil {
return nil, fmt.Errorf("couldn't unmarshal %v: %v", path, err)
}
current.path = path
return &current, nil
}
@@ -143,12 +131,10 @@ func writeFile(path string, ff *fileFormat) error {
}
// This does the actual checking, since it knows the literal destination file.
type importRuleFile struct {
context *generator.Context
}
type importRuleFile struct{}
func (irf importRuleFile) AssembleFile(f *generator.File, path string) error {
return irf.VerifyFile(f, path)
func (importRuleFile) AssembleFile(f *generator.File, path string) error {
return nil
}
// TODO: make a flag to enable this, or expose this information in some other way.
@@ -183,100 +169,63 @@ func removeLastDir(path string) (newPath, removedDir string) {
return filepath.Join(filepath.Dir(dir), file), filepath.Base(dir)
}
// isGoModRoot checks if a directory is the root directory for a package
// by checking for the existence of a 'go.mod' file in that directory.
func isGoModRoot(path string) bool {
_, err := os.Stat(filepath.Join(filepath.Dir(path), goModFile))
return err == nil
}
// recursiveRead collects all '.import-restriction' files, between the current directory,
// and the package root when Go modules are enabled, or $GOPATH/src when they are not.
func recursiveRead(path string) ([]*fileFormat, error) {
restrictionFiles := make([]*fileFormat, 0)
// Keep going up a directory until we find an .import-restrictions file.
func recursiveRead(path string) (*fileFormat, string, error) {
for {
if _, err := os.Stat(path); err == nil {
rules, err := readFile(path)
if err != nil {
return nil, err
}
restrictionFiles = append(restrictionFiles, rules)
ff, err := readFile(path)
return ff, path, err
}
nextPath, removedDir := removeLastDir(path)
if nextPath == path || isGoModRoot(path) || removedDir == "src" {
if nextPath == path || removedDir == "src" {
break
}
path = nextPath
}
return restrictionFiles, nil
return nil, "", nil
}
func (irf importRuleFile) VerifyFile(f *generator.File, path string) error {
restrictionFiles, err := recursiveRead(filepath.Join(f.PackageSourcePath, f.Name))
func (importRuleFile) VerifyFile(f *generator.File, path string) error {
rules, actualPath, err := recursiveRead(path)
if err != nil {
return fmt.Errorf("error finding rules file: %v", err)
}
if err := irf.verifyRules(restrictionFiles, f); err != nil {
return err
}
return irf.verifyInverseRules(restrictionFiles, f)
}
func (irf importRuleFile) verifyRules(restrictionFiles []*fileFormat, f *generator.File) error {
selectors := make([][]*regexp.Regexp, len(restrictionFiles))
for i, restrictionFile := range restrictionFiles {
for _, r := range restrictionFile.Rules {
re, err := regexp.Compile(r.SelectorRegexp)
if err != nil {
return fmt.Errorf("regexp `%s` in file %q doesn't compile: %v", r.SelectorRegexp, restrictionFile.path, err)
}
selectors[i] = append(selectors[i], re)
}
if rules == nil {
// No restrictions on this directory.
return nil
}
forbiddenImports := map[string]string{}
allowedMismatchedImports := []string{}
for v := range f.Imports {
explicitlyAllowed := false
NextRestrictionFiles:
for i, rules := range restrictionFiles {
for j, r := range rules.Rules {
matching := selectors[i][j].MatchString(v)
klog.V(5).Infof("Checking %v matches %v: %v\n", r.SelectorRegexp, v, matching)
if !matching {
continue
for _, r := range rules.Rules {
re, err := regexp.Compile(r.SelectorRegexp)
if err != nil {
return fmt.Errorf("regexp `%s` in file %q doesn't compile: %v", r.SelectorRegexp, actualPath, err)
}
for v := range f.Imports {
klog.V(4).Infof("Checking %v matches %v: %v\n", r.SelectorRegexp, v, re.MatchString(v))
if !re.MatchString(v) {
continue
}
for _, forbidden := range r.ForbiddenPrefixes {
klog.V(4).Infof("Checking %v against %v\n", v, forbidden)
if strings.HasPrefix(v, forbidden) {
forbiddenImports[v] = forbidden
}
for _, forbidden := range r.ForbiddenPrefixes {
klog.V(4).Infof("Checking %v against %v\n", v, forbidden)
if strings.HasPrefix(v, forbidden) {
forbiddenImports[v] = forbidden
}
}
for _, allowed := range r.AllowedPrefixes {
klog.V(4).Infof("Checking %v against %v\n", v, allowed)
if strings.HasPrefix(v, allowed) {
explicitlyAllowed = true
break
}
}
if !explicitlyAllowed {
allowedMismatchedImports = append(allowedMismatchedImports, v)
} else {
klog.V(2).Infof("%v importing %v allowed by %v\n", f.PackagePath, v, restrictionFiles[i].path)
break NextRestrictionFiles
}
found := false
for _, allowed := range r.AllowedPrefixes {
klog.V(4).Infof("Checking %v against %v\n", v, allowed)
if strings.HasPrefix(v, allowed) {
found = true
break
}
}
if !found {
allowedMismatchedImports = append(allowedMismatchedImports, v)
}
}
}
@@ -294,85 +243,8 @@ func (irf importRuleFile) verifyRules(restrictionFiles []*fileFormat, f *generat
}
return errors.New(errorBuilder.String())
}
return nil
}
// verifyInverseRules checks that all packages that import a package are allowed to import it.
func (irf importRuleFile) verifyInverseRules(restrictionFiles []*fileFormat, f *generator.File) error {
// compile all Selector regex in all restriction files
selectors := make([][]*regexp.Regexp, len(restrictionFiles))
for i, restrictionFile := range restrictionFiles {
for _, r := range restrictionFile.InverseRules {
re, err := regexp.Compile(r.SelectorRegexp)
if err != nil {
return fmt.Errorf("regexp `%s` in file %q doesn't compile: %v", r.SelectorRegexp, restrictionFile.path, err)
}
selectors[i] = append(selectors[i], re)
}
}
directImport := map[string]bool{}
for _, imp := range irf.context.IncomingImports()[f.PackagePath] {
directImport[imp] = true
}
forbiddenImports := map[string]string{}
allowedMismatchedImports := []string{}
for _, v := range irf.context.TransitiveIncomingImports()[f.PackagePath] {
explicitlyAllowed := false
NextRestrictionFiles:
for i, rules := range restrictionFiles {
for j, r := range rules.InverseRules {
if !r.Transitive && !directImport[v] {
continue
}
re := selectors[i][j]
matching := re.MatchString(v)
klog.V(4).Infof("Checking %v matches %v (importing %v: %v\n", r.SelectorRegexp, v, f.PackagePath, matching)
if !matching {
continue
}
for _, forbidden := range r.ForbiddenPrefixes {
klog.V(4).Infof("Checking %v against %v\n", v, forbidden)
if strings.HasPrefix(v, forbidden) {
forbiddenImports[v] = forbidden
}
}
for _, allowed := range r.AllowedPrefixes {
klog.V(4).Infof("Checking %v against %v\n", v, allowed)
if strings.HasPrefix(v, allowed) {
explicitlyAllowed = true
break
}
}
if !explicitlyAllowed {
allowedMismatchedImports = append(allowedMismatchedImports, v)
} else {
klog.V(2).Infof("%v importing %v allowed by %v\n", v, f.PackagePath, restrictionFiles[i].path)
break NextRestrictionFiles
}
}
}
}
if len(forbiddenImports) > 0 || len(allowedMismatchedImports) > 0 {
var errorBuilder strings.Builder
for i, f := range forbiddenImports {
fmt.Fprintf(&errorBuilder, "(inverse): import %v has forbidden prefix %v\n", i, f)
}
if len(allowedMismatchedImports) > 0 {
sort.Sort(sort.StringSlice(allowedMismatchedImports))
fmt.Fprintf(&errorBuilder, "(inverse): the following imports did not match any allowed prefix:\n")
for _, i := range allowedMismatchedImports {
fmt.Fprintf(&errorBuilder, " %v\n", i)
}
}
return errors.New(errorBuilder.String())
if len(rules.Rules) > 0 {
klog.V(2).Infof("%v passes rules found in %v\n", path, actualPath)
}
return nil

View File

@@ -16,37 +16,24 @@ limitations under the License.
// import-boss enforces import restrictions in a given repository.
//
// When a package is verified, import-boss looks for files called
// ".import-restrictions" in all directories between the package and
// the $GOPATH/src.
// When a directory is verified, import-boss looks for a file called
// ".import-restrictions". If this file is not found, parent directories will be
// recursively searched.
//
// All imports of the package are checked against each "rule" in the
// found restriction files, climbing up the directory tree until the
// import matches one of the rules.
//
// If the import does not match any of the rules, it is accepted.
//
// In analogy, all incoming imports of the package are checked against each
// "inverse rule" in the found restriction files, climbing up the directory
// tree until the import matches one of the rules.
//
// If the incoming import does not match any of the inverse rules, it is accepted.
//
// A rule consists of three parts:
// If an ".import-restrictions" file is found, then all imports of the package
// are checked against each "rule" in the file. A rule consists of three parts:
// * A SelectorRegexp, to select the import paths that the rule applies to.
// * A list of AllowedPrefixes
// * A list of ForbiddenPrefixes
// An import passes a rule of a matching selector if it matches at least one
// allowed prefix, but no forbidden prefix.
//
// An example file looks like this:
// An import is allowed if it matches at least one allowed prefix and does not
// match any forbidden prefix. An example file looks like this:
//
// {
// "Rules": [
// {
// "SelectorRegexp": "k8s[.]io",
// "AllowedPrefixes": [
// "k8s.io/gengo/examples",
// "k8s.io/gengo",
// "k8s.io/kubernetes/third_party"
// ],
// "ForbiddenPrefixes": [
@@ -61,37 +48,11 @@ limitations under the License.
// ""
// ]
// }
// ],
// "InverseRules": [{
// "SelectorRegexp": "k8s[.]io",
// "AllowedPrefixes": [
// "k8s.io/same-repo",
// "k8s.io/kubernetes/pkg/legacy"
// ],
// "ForbiddenPrefixes": [
// "k8s.io/kubernetes/pkg/legacy/subpkg"
// ]
// },
// {
// "SelectorRegexp": "k8s[.]io",
// "Transitive": true,
// "AllowedPrefixes": [
// "k8s.io/
// ],
// "ForbiddenPrefixes": [
// "k8s.io/kubernetes/cmd/kubelet",
// "k8s.io/kubernetes/cmd/kubectl"
// ],
// ]
// }
//
// Note the second (non-inverse) rule explicitly matches the unsafe package, and forbids it
// Note the secound block explicitly matches the unsafe package, and forbids it
// ("" is a prefix of everything).
//
// An import from another package passes an inverse rule with a matching selector if
// it matches at least one allowed prefix, but no forbidden prefix.
//
// Note that the second InverseRule is transitive, the first only applies to direct imports.
package main
import (

View File

@@ -1,6 +0,0 @@
// a only imports public packages.
package a
import (
_ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/public"
)

View File

@@ -1,7 +0,0 @@
// b only imports public and private packages. The latter it shouldn't.
package b
import (
_ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/private"
_ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/public"
)

View File

@@ -1,7 +0,0 @@
// c imports the library root, which in turn imports the public and private packages. This is fine because
// the private package is not directly imported.
package c
import (
_ "k8s.io/gengo/examples/import-boss/tests/inverse/lib"
)

View File

@@ -1,6 +0,0 @@
// c imports non-prod code. It shouldn't.
package d
import (
_ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/nonprod"
)

View File

@@ -1,6 +0,0 @@
package lib
import (
_ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/private"
_ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/public"
)

View File

@@ -1,5 +0,0 @@
package lib
import (
_ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/nonprod"
)

View File

@@ -1,9 +0,0 @@
{
"InverseRules": [{
"Transitive": true,
"SelectorRegexp": "k8s[.]io/gengo",
"AllowedPrefixes": [
"k8s.io/gengo/examples/import-boss/tests/inverse/lib"
]
}]
}

View File

@@ -1,2 +0,0 @@
// nonprod is non-production code that should not be linked into any outside package.
package nonprod

View File

@@ -1,11 +0,0 @@
{
"InverseRules": [{
"SelectorRegexp": "k8s[.]io/gengo",
"AllowedPrefixes": [
"k8s.io/gengo/examples/import-boss/tests/inverse/lib"
],
"ForbiddenPrefixes": [
"k8s.io/gengo/examples/import-boss/tests/inverse/lib/quarantine"
]
}]
}

View File

@@ -1 +0,0 @@
package private

View File

@@ -1 +0,0 @@
package public

View File

@@ -1,6 +0,0 @@
// quarantine is inside the library, but should not import the private package. But it does!
package quarantine
import (
_ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/private"
)

View File

@@ -1,11 +0,0 @@
{
"Rules": [{
"SelectorRegexp": "k8s[.]io/gengo",
"AllowedPrefixes": [
"k8s.io/gengo/examples/import-boss/tests/rules/b"
],
"ForbiddenPrefixes": [
"k8s.io/gengo/examples/import-boss/tests/rules/c"
]
}]
}

View File

@@ -1,5 +0,0 @@
package a
import (
_ "k8s.io/gengo/examples/import-boss/tests/rules/b"
)

View File

@@ -1,11 +0,0 @@
{
"Rules": [{
"SelectorRegexp": "k8s[.]io/gengo",
"AllowedPrefixes": [
""
],
"ForbiddenPrefixes": [
"k8s.io/gengo/examples/import-boss/tests/rules/c"
]
}]
}

View File

@@ -1,6 +0,0 @@
// b only public and private packages. The latter it shouldn't.
package b
import (
_ "k8s.io/gengo/examples/import-boss/tests/rules/c"
)

View File

@@ -1 +0,0 @@
package c

View File

@@ -1,10 +0,0 @@
{
"Rules": [{
"SelectorRegexp": "k8s[.]io/gengo",
"AllowedPrefixes": [
],
"ForbiddenPrefixes": [
"k8s.io/gengo/examples/import-boss/tests/rules/c"
]
}]
}

View File

@@ -1,5 +0,0 @@
package nested
import (
_ "k8s.io/gengo/examples/import-boss/tests/rules/c"
)

View File

@@ -1,10 +0,0 @@
{
"Rules": [{
"SelectorRegexp": "k8s[.]io/gengo",
"AllowedPrefixes": [
"k8s.io/gengo/examples/import-boss/tests/rules/c"
],
"ForbiddenPrefixes": [
]
}]
}

View File

@@ -1,5 +0,0 @@
package nested
import (
_ "k8s.io/gengo/examples/import-boss/tests/rules/c"
)

View File

@@ -1,10 +0,0 @@
{
"Rules": [{
"SelectorRegexp": "k8s[.]io/gengo",
"AllowedPrefixes": [
],
"ForbiddenPrefixes": [
"k8s.io/gengo/examples/import-boss/tests/rules/c"
]
}]
}

View File

@@ -1,5 +0,0 @@
package nested
import (
_ "k8s.io/gengo/examples/import-boss/tests/rules/c"
)

View File

@@ -1,5 +0,0 @@
package inherit
import (
_ "k8s.io/gengo/examples/import-boss/tests/rules/c"
)

View File

@@ -26,8 +26,6 @@ type DefaultPackage struct {
PackageName string
// Import path of the package, and the location on disk of the package.
PackagePath string
// The location of the package on disk.
Source string
// Emitted at the top of every file.
HeaderText []byte
@@ -45,9 +43,8 @@ type DefaultPackage struct {
FilterFunc func(*Context, *types.Type) bool
}
func (d *DefaultPackage) Name() string { return d.PackageName }
func (d *DefaultPackage) Path() string { return d.PackagePath }
func (d *DefaultPackage) SourcePath() string { return d.Source }
func (d *DefaultPackage) Name() string { return d.PackageName }
func (d *DefaultPackage) Path() string { return d.PackagePath }
func (d *DefaultPackage) Filter(c *Context, t *types.Type) bool {
if d.FilterFunc != nil {

View File

@@ -233,13 +233,11 @@ func (c *Context) ExecutePackage(outDir string, p Package) error {
if f == nil {
// This is the first generator to reference this file, so start it.
f = &File{
Name: g.Filename(),
FileType: fileType,
PackageName: p.Name(),
PackagePath: p.Path(),
PackageSourcePath: p.SourcePath(),
Header: p.Header(g.Filename()),
Imports: map[string]struct{}{},
Name: g.Filename(),
FileType: fileType,
PackageName: p.Name(),
Header: p.Header(g.Filename()),
Imports: map[string]struct{}{},
}
files[f.Name] = f
} else {

View File

@@ -31,8 +31,6 @@ type Package interface {
Name() string
// Path returns the package import path.
Path() string
// SourcePath returns the location of the package on disk.
SourcePath() string
// Filter should return true if this package cares about this type.
// Otherwise, this type will be omitted from the type ordering for
@@ -52,16 +50,14 @@ type Package interface {
}
type File struct {
Name string
FileType string
PackageName string
Header []byte
PackagePath string
PackageSourcePath string
Imports map[string]struct{}
Vars bytes.Buffer
Consts bytes.Buffer
Body bytes.Buffer
Name string
FileType string
PackageName string
Header []byte
Imports map[string]struct{}
Vars bytes.Buffer
Consts bytes.Buffer
Body bytes.Buffer
}
type FileType interface {
@@ -160,12 +156,6 @@ type Context struct {
// All the types, in case you want to look up something.
Universe types.Universe
// Incoming imports, i.e. packages importing the given package.
incomingImports map[string][]string
// Incoming transitive imports, i.e. the transitive closure of IncomingImports
incomingTransitiveImports map[string][]string
// All the user-specified packages. This is after recursive expansion.
Inputs []string
@@ -213,36 +203,11 @@ func NewContext(b *parser.Builder, nameSystems namer.NameSystems, canonicalOrder
return c, nil
}
// IncomingImports returns the incoming imports for each package. The map is lazily computed.
func (ctxt *Context) IncomingImports() map[string][]string {
if ctxt.incomingImports == nil {
incoming := map[string][]string{}
for _, pkg := range ctxt.Universe {
for imp := range pkg.Imports {
incoming[imp] = append(incoming[imp], pkg.Path)
}
}
ctxt.incomingImports = incoming
}
return ctxt.incomingImports
}
// TransitiveIncomingImports returns the transitive closure of the incoming imports for each package.
// The map is lazily computed.
func (ctxt *Context) TransitiveIncomingImports() map[string][]string {
if ctxt.incomingTransitiveImports == nil {
ctxt.incomingTransitiveImports = transitiveClosure(ctxt.IncomingImports())
}
return ctxt.incomingTransitiveImports
}
// AddDir adds a Go package to the context. The specified path must be a single
// go package import path. GOPATH, GOROOT, and the location of your go binary
// (`which go`) will all be searched, in the normal Go fashion.
// Deprecated. Please use AddDirectory.
func (ctxt *Context) AddDir(path string) error {
ctxt.incomingImports = nil
ctxt.incomingTransitiveImports = nil
return ctxt.builder.AddDirTo(path, &ctxt.Universe)
}
@@ -250,7 +215,5 @@ func (ctxt *Context) AddDir(path string) error {
// single go package import path. GOPATH, GOROOT, and the location of your go
// binary (`which go`) will all be searched, in the normal Go fashion.
func (ctxt *Context) AddDirectory(path string) (*types.Package, error) {
ctxt.incomingImports = nil
ctxt.incomingTransitiveImports = nil
return ctxt.builder.AddDirectoryTo(path, &ctxt.Universe)
}

View File

@@ -17,7 +17,6 @@ limitations under the License.
package generator
import (
"go/token"
"strings"
"k8s.io/klog"
@@ -59,11 +58,6 @@ func golangTrackerLocalName(tracker namer.ImportTracker, t types.Name) string {
// This name collides with some other package
continue
}
// If the import name is a Go keyword, prefix with an underscore.
if token.Lookup(name).IsKeyword() {
name = "_" + name
}
return name
}
panic("can't find import for " + path)

View File

@@ -1,75 +0,0 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package generator
import (
"reflect"
"testing"
"k8s.io/gengo/types"
)
func TestNewImportTracker(t *testing.T) {
tests := []struct {
name string
inputTypes []*types.Type
expectedImports []string
}{
{
name: "empty",
inputTypes: []*types.Type{},
expectedImports: []string{},
},
{
name: "builtin",
inputTypes: []*types.Type{
{Name: types.Name{Package: "net/http"}},
},
expectedImports: []string{
`http "net/http"`,
},
},
{
name: "sorting",
inputTypes: []*types.Type{
{Name: types.Name{Package: "foo/bar/pkg2"}},
{Name: types.Name{Package: "foo/bar/pkg1"}},
},
expectedImports: []string{
`pkg1 "foo/bar/pkg1"`,
`pkg2 "foo/bar/pkg2"`,
},
},
{
name: "reserved-keyword",
inputTypes: []*types.Type{
{Name: types.Name{Package: "my/reserved/pkg/struct"}},
},
expectedImports: []string{
`_struct "my/reserved/pkg/struct"`,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actualImports := NewImportTracker(tt.inputTypes...).ImportLines()
if !reflect.DeepEqual(actualImports, tt.expectedImports) {
t.Errorf("ImportLines(%v) = %v, want %v", tt.inputTypes, actualImports, tt.expectedImports)
}
})
}
}

View File

@@ -1,65 +0,0 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package generator
import "sort"
type edge struct {
from string
to string
}
func transitiveClosure(in map[string][]string) map[string][]string {
adj := make(map[edge]bool)
imports := make(map[string]struct{})
for from, tos := range in {
for _, to := range tos {
adj[edge{from, to}] = true
imports[to] = struct{}{}
}
}
// Warshal's algorithm
for k := range in {
for i := range in {
if !adj[edge{i, k}] {
continue
}
for j := range imports {
if adj[edge{i, j}] {
continue
}
if adj[edge{k, j}] {
adj[edge{i, j}] = true
}
}
}
}
out := make(map[string][]string, len(in))
for i := range in {
for j := range imports {
if adj[edge{i, j}] {
out[i] = append(out[i], j)
}
}
sort.Strings(out[i])
}
return out
}

View File

@@ -1,64 +0,0 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package generator
import (
"reflect"
"testing"
)
func TestTransitiveClosure(t *testing.T) {
cases := []struct {
name string
in map[string][]string
expected map[string][]string
}{
{
name: "no transition",
in: map[string][]string{
"a": {"b"},
"c": {"d"},
},
expected: map[string][]string{
"a": {"b"},
"c": {"d"},
},
},
{
name: "simple",
in: map[string][]string{
"a": {"b"},
"b": {"c"},
"c": {"d"},
},
expected: map[string][]string{
"a": {"b", "c", "d"},
"b": {"c", "d"},
"c": {"d"},
},
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
out := transitiveClosure(c.in)
if !reflect.DeepEqual(c.expected, out) {
t.Errorf("expected: %#v, got %#v", c.expected, out)
}
})
}
}

14
vendor/k8s.io/gengo/parser/parse.go generated vendored
View File

@@ -227,16 +227,12 @@ func (b *Builder) AddDirRecursive(dir string) error {
klog.Warningf("Ignoring directory %v: %v", dir, err)
}
// filepath.Walk does not follow symlinks. We therefore evaluate symlinks and use that with
// filepath.Walk.
realPath, err := filepath.EvalSymlinks(b.buildPackages[dir].Dir)
if err != nil {
return err
}
// filepath.Walk includes the root dir, but we already did that, so we'll
// remove that prefix and rebuild a package import path.
prefix := b.buildPackages[dir].Dir
fn := func(filePath string, info os.FileInfo, err error) error {
if info != nil && info.IsDir() {
rel := filepath.ToSlash(strings.TrimPrefix(filePath, realPath))
rel := filepath.ToSlash(strings.TrimPrefix(filePath, prefix))
if rel != "" {
// Make a pkg path.
pkg := path.Join(string(canonicalizeImportPath(b.buildPackages[dir].ImportPath)), rel)
@@ -249,7 +245,7 @@ func (b *Builder) AddDirRecursive(dir string) error {
}
return nil
}
if err := filepath.Walk(realPath, fn); err != nil {
if err := filepath.Walk(b.buildPackages[dir].Dir, fn); err != nil {
return err
}
return nil

View File

@@ -1,16 +1,22 @@
<!-- BEGIN MUNGE: GENERATED_TOC -->
- [v1.16.1](#v1161)
- [Downloads for v1.16.1](#downloads-for-v1161)
- [v1.16.2](#v1162)
- [Downloads for v1.16.2](#downloads-for-v1162)
- [Client Binaries](#client-binaries)
- [Server Binaries](#server-binaries)
- [Node Binaries](#node-binaries)
- [Changelog since v1.16.1](#changelog-since-v1161)
- [v1.16.1](#v1161)
- [Downloads for v1.16.1](#downloads-for-v1161)
- [Client Binaries](#client-binaries-1)
- [Server Binaries](#server-binaries-1)
- [Node Binaries](#node-binaries-1)
- [Changelog since v1.16.0](#changelog-since-v1160)
- [Other notable changes](#other-notable-changes)
- [v1.16.0](#v1160)
- [Downloads for v1.16.0](#downloads-for-v1160)
- [Client Binaries](#client-binaries-1)
- [Server Binaries](#server-binaries-1)
- [Node Binaries](#node-binaries-1)
- [Client Binaries](#client-binaries-2)
- [Server Binaries](#server-binaries-2)
- [Node Binaries](#node-binaries-2)
- [Kubernetes v1.16.0 Release Notes](#kubernetes-v1160-release-notes)
- [Whats New (Major Themes)](#whats-new-major-themes)
- [Additional Notable Feature Updates](#additional-notable-feature-updates)
@@ -54,54 +60,54 @@
- [Removed](#removed-1)
- [v1.16.0-rc.2](#v1160-rc2)
- [Downloads for v1.16.0-rc.2](#downloads-for-v1160-rc2)
- [Client Binaries](#client-binaries-2)
- [Server Binaries](#server-binaries-2)
- [Node Binaries](#node-binaries-2)
- [Client Binaries](#client-binaries-3)
- [Server Binaries](#server-binaries-3)
- [Node Binaries](#node-binaries-3)
- [Changelog since v1.16.0-rc.1](#changelog-since-v1160-rc1)
- [Other notable changes](#other-notable-changes-2)
- [v1.16.0-rc.1](#v1160-rc1)
- [Downloads for v1.16.0-rc.1](#downloads-for-v1160-rc1)
- [Client Binaries](#client-binaries-3)
- [Server Binaries](#server-binaries-3)
- [Node Binaries](#node-binaries-3)
- [Client Binaries](#client-binaries-4)
- [Server Binaries](#server-binaries-4)
- [Node Binaries](#node-binaries-4)
- [Changelog since v1.16.0-beta.2](#changelog-since-v1160-beta2)
- [Other notable changes](#other-notable-changes-3)
- [v1.16.0-beta.2](#v1160-beta2)
- [Downloads for v1.16.0-beta.2](#downloads-for-v1160-beta2)
- [Client Binaries](#client-binaries-4)
- [Server Binaries](#server-binaries-4)
- [Node Binaries](#node-binaries-4)
- [Client Binaries](#client-binaries-5)
- [Server Binaries](#server-binaries-5)
- [Node Binaries](#node-binaries-5)
- [Changelog since v1.16.0-beta.1](#changelog-since-v1160-beta1)
- [Other notable changes](#other-notable-changes-4)
- [v1.16.0-beta.1](#v1160-beta1)
- [Downloads for v1.16.0-beta.1](#downloads-for-v1160-beta1)
- [Client Binaries](#client-binaries-5)
- [Server Binaries](#server-binaries-5)
- [Node Binaries](#node-binaries-5)
- [Client Binaries](#client-binaries-6)
- [Server Binaries](#server-binaries-6)
- [Node Binaries](#node-binaries-6)
- [Changelog since v1.16.0-alpha.3](#changelog-since-v1160-alpha3)
- [Action Required](#action-required)
- [Other notable changes](#other-notable-changes-5)
- [v1.16.0-alpha.3](#v1160-alpha3)
- [Downloads for v1.16.0-alpha.3](#downloads-for-v1160-alpha3)
- [Client Binaries](#client-binaries-6)
- [Server Binaries](#server-binaries-6)
- [Node Binaries](#node-binaries-6)
- [Client Binaries](#client-binaries-7)
- [Server Binaries](#server-binaries-7)
- [Node Binaries](#node-binaries-7)
- [Changelog since v1.16.0-alpha.2](#changelog-since-v1160-alpha2)
- [Action Required](#action-required-1)
- [Other notable changes](#other-notable-changes-6)
- [v1.16.0-alpha.2](#v1160-alpha2)
- [Downloads for v1.16.0-alpha.2](#downloads-for-v1160-alpha2)
- [Client Binaries](#client-binaries-7)
- [Server Binaries](#server-binaries-7)
- [Node Binaries](#node-binaries-7)
- [Client Binaries](#client-binaries-8)
- [Server Binaries](#server-binaries-8)
- [Node Binaries](#node-binaries-8)
- [Changelog since v1.16.0-alpha.1](#changelog-since-v1160-alpha1)
- [Action Required](#action-required-2)
- [Other notable changes](#other-notable-changes-7)
- [v1.16.0-alpha.1](#v1160-alpha1)
- [Downloads for v1.16.0-alpha.1](#downloads-for-v1160-alpha1)
- [Client Binaries](#client-binaries-8)
- [Server Binaries](#server-binaries-8)
- [Node Binaries](#node-binaries-8)
- [Client Binaries](#client-binaries-9)
- [Server Binaries](#server-binaries-9)
- [Node Binaries](#node-binaries-9)
- [Changelog since v1.15.0](#changelog-since-v1150)
- [Action Required](#action-required-3)
- [Other notable changes](#other-notable-changes-8)
@@ -110,6 +116,70 @@
<!-- NEW RELEASE NOTES ENTRY -->
# v1.16.2
[Documentation](https://docs.k8s.io)
## Downloads for v1.16.2
filename | sha512 hash
-------- | -----------
[kubernetes.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes.tar.gz) | `9e21ab6317fe209dabac72444273b493f5f7639f73c489cc233da3a0205a93f8779964fe2cf2237bb6ca7535560c7c8ac48e25e75a1fbe97dc5b51f248ed7eeb`
[kubernetes-src.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-src.tar.gz) | `2e52029a8669f51020f689b0da481f56ab922ecd2c4495e37cb8456e9b10fee50f97bf9faa6a3bc947e4142aa4e5374d7f905a22e5f18830610eacfdf47adbc6`
### Client Binaries
filename | sha512 hash
-------- | -----------
[kubernetes-client-darwin-386.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-client-darwin-386.tar.gz) | `6424b3047c5d7557b6c5536f29139bb6f71e4357b5e181d62bfd5fbf7d5575c9d5eeeab531b0afcc72ac17dd6609162bebc1045932ee58cbeb3093a4107cbf3a`
[kubernetes-client-darwin-amd64.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-client-darwin-amd64.tar.gz) | `791d2a4f965130ea1d7033f807b29015520afa317f97643f27480a6530213fd3fa06817ba9ce04e81f843b8420f05baa25e597e5880f99cc2ffbfc8b8ebf18cf`
[kubernetes-client-linux-386.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-client-linux-386.tar.gz) | `fd727fe3200975f71d1f5b21991e5b8d2471e92dc3185df29b8ef21a9aa87d270baa1bd2f9f2dbe61abe9e9541ee806709d6ed08aa13254a5953ddc1f1ddb5a6`
[kubernetes-client-linux-amd64.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-client-linux-amd64.tar.gz) | `69bb92c9b16c0286d7401d87cc73b85c88d6f9a17d2cf1748060e44525194b5be860daf7554c4c6319a546c9ff10f2b4df42a27e32d8f95a4052993b17ef57c0`
[kubernetes-client-linux-arm.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-client-linux-arm.tar.gz) | `f846f6018eb3d82741e6d2e8fd2f9f7ca8768ead56c3e2c330ba7e7dbba3209dd66f793b37d330134d3e8f38a03d6492e0054e55fcf32f74743b7b26f3159210`
[kubernetes-client-linux-arm64.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-client-linux-arm64.tar.gz) | `49cb3495fa8bbe64cefdb9aab83d4cfbe6a0f3a0e58b1685a49244df02e5ee8bbfaf0be133f5cf5231b1470bb62bd699cd6aba8072cb6ea3542f3ccfd42d3813`
[kubernetes-client-linux-ppc64le.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-client-linux-ppc64le.tar.gz) | `35a8b25309150cf5e1dab2af1d5118a24d296e21cdaf4bdec615badbc27a109ffb8b0e1cd93439fb728ec4905178eae2eb9d2ec2760053211b495c103d76fe3b`
[kubernetes-client-linux-s390x.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-client-linux-s390x.tar.gz) | `ffd5ab012d38b7a7b9e0acd8339c30545a60bcabba5642f5020464846391ae41930e84c0103231f850f0f0c86e064c18f47bff95ccf11b410c0216a4d887b2fb`
[kubernetes-client-windows-386.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-client-windows-386.tar.gz) | `c04d33b31734c7b25c54daa361986fcb745178320daa54d76b7627c475346a87c65443f7b139e1c86436b27eb9d10ed4a61ba5a64e0420bb6ce2f68fbad0a1b0`
[kubernetes-client-windows-amd64.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-client-windows-amd64.tar.gz) | `e81fcf83523dd1dc79de7b498df6115465eb83d31a400853cdf143870a281322f24be5609d0c541810f90047a3c4e75530b9a6e872e51ed00d268530f2ed7ca9`
### Server Binaries
filename | sha512 hash
-------- | -----------
[kubernetes-server-linux-amd64.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-server-linux-amd64.tar.gz) | `4aa3da6d146db878f4605ea6334925e925268808856f482ea7f9d131dce76ee30d4ba077a6b35de34a68d8d9ca005cccd2e7e4866b775c1f7eaba1320a1b8ec5`
[kubernetes-server-linux-arm.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-server-linux-arm.tar.gz) | `0a9cea07a1172038d300277f1d305d99b147ae5949df3dd63856944cc0e4724105a0d79bf9ea39dface923d794b71e9f40d4104218167e56096a9e82a422864a`
[kubernetes-server-linux-arm64.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-server-linux-arm64.tar.gz) | `b1aadb87ff310aec7292df5386613c4c0036c0e3c20e0a4ab7bd3d5eea8fff0116c8b8b47289e894950b249be4207daac58449ec9a587353873890b47217ecd8`
[kubernetes-server-linux-ppc64le.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-server-linux-ppc64le.tar.gz) | `2aecda7fb53efd23c34cfe90ae37d55efec513996573c9124d9bf94809ea5a86bcd786e84d646039fbaff2e42d7e8f9c5db179beec3fac1f0a420920c93dce35`
[kubernetes-server-linux-s390x.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-server-linux-s390x.tar.gz) | `74fd3d5dbedac211570ef011f14e98d37848587b670038c69354c0162668aa2c6789835a5dbfc82f43fb9662444756f974de75917f75f59ab51e6ae9183e5c20`
### Node Binaries
filename | sha512 hash
-------- | -----------
[kubernetes-node-linux-amd64.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-node-linux-amd64.tar.gz) | `d1e139006e1ce6b66a1c0b9dd90509db712e5e024e1c5a4c0a1bb185211dd138cbcf201e6a9cdf7df9b78b6817523da23097c8396c0afb98481052447d329cc9`
[kubernetes-node-linux-arm.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-node-linux-arm.tar.gz) | `5779c23d4f77edf5d5c3b8bb55fd190bf180f13c782e44a50a96572477af30008685c4e670c07ceb56c8e64390be7e7cbf14a9b25c894c66f90131a993bda4fc`
[kubernetes-node-linux-arm64.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-node-linux-arm64.tar.gz) | `f09bc220a05b8f5fca6d4575198ac2b7625fcbceb09ffd6da587c8b13a5b93365b601b94a25fb8cc360c7521ccc30d11d86d88490f5a48369f6078c4395593c2`
[kubernetes-node-linux-ppc64le.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-node-linux-ppc64le.tar.gz) | `96b3f8578e4f5e5261489ba392e7167bfdbe5ec6fb60a369455edffbc027b3086bd99055f7e3cabbf56426b7b181764d5cd5979bacd3ad8c26b541cd94ce62d8`
[kubernetes-node-linux-s390x.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-node-linux-s390x.tar.gz) | `4c9c7e541164781231378091cae0ab693c29b517b7737be191436c5e85ea4702cdd640890ae7c1295273270cb7944e2a250e2791a9a07bb415dac67d3129d1c1`
[kubernetes-node-windows-amd64.tar.gz](https://dl.k8s.io/v1.16.2/kubernetes-node-windows-amd64.tar.gz) | `a88e7a1c6f72ea6073dbb4ddfe2e7c8bd37c9a56d94a33823f531e303a9915e7a844ac5880097724e44dfa7f4a9659d14b79cc46e2067f6b13e6df3f3f1b0f64`
## Changelog since v1.16.1
### Other notable changes
* Fixed panic when accessing CustomResources of a CRD with x-kubernetes-int-or-string. ([#83789](https://github.com/kubernetes/kubernetes/pull/83789), [@sttts](https://github.com/sttts))
* Fixed a bug in the single-numa-node policy of the TopologyManager. Previously, pods that only requested CPU resources and did not request any third-party devices would fail to launch with a TopologyAffinity error. Now they will launch successfully. ([#83697](https://github.com/kubernetes/kubernetes/pull/83697), [@klueska](https://github.com/klueska))
* Fixes kube-proxy bug accessing self nodeip:port on windows ([#83027](https://github.com/kubernetes/kubernetes/pull/83027), [@liggitt](https://github.com/liggitt))
* Fix error where metrics related to dynamic kubelet config isn't registered ([#83184](https://github.com/kubernetes/kubernetes/pull/83184), [@odinuge](https://github.com/odinuge))
* Use online nodes instead of possible nodes when discovering available NUMA nodes ([#83196](https://github.com/kubernetes/kubernetes/pull/83196), [@zouyee](https://github.com/zouyee))
* Update Azure load balancer to prevent orphaned public IP addresses ([#82890](https://github.com/kubernetes/kubernetes/pull/82890), [@chewong](https://github.com/chewong))
* Fixes a goroutine leak in kube-apiserver when a request times out. ([#83333](https://github.com/kubernetes/kubernetes/pull/83333), [@lavalamp](https://github.com/lavalamp))
* Fix aggressive VM calls for Azure VMSS ([#83102](https://github.com/kubernetes/kubernetes/pull/83102), [@feiskyer](https://github.com/feiskyer))
* Fixes a flaw (CVE-2019-11253) in json/yaml decoding where large or malformed documents could consume excessive server resources. Request bodies for normal API requests (create/delete/update/patch operations of regular resources) are now limited to 3MB. ([#83261](https://github.com/kubernetes/kubernetes/pull/83261), [@liggitt](https://github.com/liggitt))
# v1.16.1
[Documentation](https://docs.k8s.io)
@@ -253,6 +323,7 @@ The main themes of this release are:
- Systems running `iptables` 1.8.0 or newer should start it in legacy mode. Please note that this affects all versions of Kubernetes and not only v1.16.0. For more detailed information about the issue and how to apply a workaround, please refer to the official documentation
- Generating informers for packages in directories containing dots in their name is broken. This will be fixed in v1.16.1. ([#82860](https://github.com/kubernetes/kubernetes/issues/82860))
- kube-scheduler won't be able to report scheduling Events if `events.k8s.io/v1beta1` API is disabled. We are targeting the fix for v1.16.2 ([#83203](https://github.com/kubernetes/kubernetes/issues/83203))
- The etcd client library vendored in v1.16 (github.com/coreos/etcd/clientv3) has a bug where IPv6 IP addresses get incorrectly trimmed to the first occurance of the `:` character. This affects all users of the client library including the kube-apiserver and kubeadm. We are targeting the fix for this bug in v1.16.3. ([#83550](https://github.com/kubernetes/kubernetes/issues/83550))
## Urgent Upgrade Notes

View File

@@ -20106,7 +20106,7 @@
},
"info": {
"title": "Kubernetes",
"version": "v1.16.2"
"version": "v1.16.3"
},
"paths": {
"/api/": {

View File

@@ -15,7 +15,7 @@
# This file creates a standard build environment for building cross
# platform go binary for the architecture kubernetes cares about.
FROM golang:1.12.10
FROM golang:1.12.12
ENV GOARM 7
ENV KUBE_DYNAMIC_CROSSPLATFORMS \

View File

@@ -1 +1 @@
v1.12.10-1
v1.12.12-1

View File

@@ -34,7 +34,7 @@ dependencies:
- name: "golang"
version: 1.12.10
version: 1.12.12
refPaths:
- path: build/build-image/cross/Dockerfile
match: "golang:"

View File

@@ -337,7 +337,10 @@ function kube::release::create_docker_images_for_server() {
local images_dir="${RELEASE_IMAGES}/${arch}"
mkdir -p "${images_dir}"
local -r docker_registry="${KUBE_DOCKER_REGISTRY}"
# k8s.gcr.io is the constant tag in the docker archives, this is also the default for config scripts in GKE.
# We can use KUBE_DOCKER_REGISTRY to include and extra registry in the docker archive.
# If we use KUBE_DOCKER_REGISTRY="k8s.gcr.io", then the extra tag (same) is ignored, see release_docker_image_tag below.
local -r docker_registry="k8s.gcr.io"
# Docker tags cannot contain '+'
local docker_tag="${KUBE_GIT_VERSION/+/_}"
if [[ -z "${docker_tag}" ]]; then

View File

@@ -10,6 +10,7 @@ build --verbose_failures
test --test_output=errors
# Include git version info
build --stamp
build --workspace_status_command hack/print-workspace-status.sh
# Make /tmp hermetic

View File

@@ -44,8 +44,8 @@ http_archive(
http_archive(
name = "io_bazel_rules_go",
sha256 = "5c02dd4436332f8efa982ce2102daf7c041ae95c2bc7f2d26aceed20dc47def8",
urls = mirror("https://github.com/bazelbuild/rules_go/releases/download/v0.18.11/rules_go-v0.18.11.tar.gz"),
sha256 = "b480589f57e8b09f4b0892437b9afe889e0d6660e92f5d53d3f0546c01e67ca5",
urls = mirror("https://github.com/bazelbuild/rules_go/releases/download/v0.19.7/rules_go-v0.19.7.tar.gz"),
)
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
@@ -53,7 +53,7 @@ load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_depe
go_rules_dependencies()
go_register_toolchains(
go_version = "1.12.10",
go_version = "1.12.12",
)
http_archive(

View File

@@ -131,7 +131,7 @@ function get-credentials {
}
function valid-storage-scope {
curl --fail --retry 5 --retry-delay 3 ${CURL_RETRY_CONNREFUSED} --silent --show-error "${GCE_METADATA_INTERNAL}/service-accounts/default/scopes" -H "Metadata-Flavor: Google" -s | grep -q "auth/devstorage"
curl --fail --retry 5 --retry-delay 3 ${CURL_RETRY_CONNREFUSED} --silent --show-error "${GCE_METADATA_INTERNAL}/service-accounts/default/scopes" -H "Metadata-Flavor: Google" -s | grep -E "auth/devstorage|auth/cloud-platform"
}
# Retry a download until we get it. Takes a hash and a set of URLs.

View File

@@ -151,7 +151,7 @@ function get-credentials {
}
function valid-storage-scope {
curl "${GCE_METADATA_INTERNAL}/service-accounts/default/scopes" -H "Metadata-Flavor: Google" -s | grep -q "auth/devstorage"
curl "${GCE_METADATA_INTERNAL}/service-accounts/default/scopes" -H "Metadata-Flavor: Google" -s | grep -E "auth/devstorage|auth/cloud-platform"
}
function download_tarball() {
@@ -166,7 +166,7 @@ function download_tarball() {
mkdir -p "${download_path}"
if [[ $(which curl) ]]; then
# if the url belongs to GCS API we should use oauth2_token in the headers
local curl_headers=""
curl_headers=""
if { [[ "${KUBERNETES_PROVIDER:-gce}" == "gce" ]] || [[ "${KUBERNETES_PROVIDER}" == "gke" ]] ; } &&
[[ "$url" =~ ^https://storage.googleapis.com.* ]] && valid-storage-scope ; then
curl_headers="Authorization: Bearer $(get-credentials)"

View File

@@ -122,6 +122,17 @@ function create_cluster {
)
}
# Get default service account credentials of the VM.
GCE_METADATA_INTERNAL="http://metadata.google.internal/computeMetadata/v1/instance"
function get-credentials {
curl "${GCE_METADATA_INTERNAL}/service-accounts/default/token" -H "Metadata-Flavor: Google" -s | python -c \
'import sys; import json; print(json.loads(sys.stdin.read())["access_token"])'
}
function valid-storage-scope {
curl "${GCE_METADATA_INTERNAL}/service-accounts/default/scopes" -H "Metadata-Flavor: Google" -s | grep -E "auth/devstorage|auth/cloud-platform"
}
if [[ -n "${KUBERNETES_SKIP_DOWNLOAD-}" ]]; then
create_cluster
exit 0
@@ -228,7 +239,13 @@ fi
if "${need_download}"; then
if [[ $(which curl) ]]; then
curl -fL --retry 5 --keepalive-time 2 "${kubernetes_tar_url}" -o "${file}"
# if the url belongs to GCS API we should use oauth2_token in the headers
curl_headers=""
if { [[ "${KUBERNETES_PROVIDER:-gce}" == "gce" ]] || [[ "${KUBERNETES_PROVIDER}" == "gke" ]] ; } &&
[[ "$kubernetes_tar_url" =~ ^https://storage.googleapis.com.* ]] && valid-storage-scope ; then
curl_headers="Authorization: Bearer $(get-credentials)"
fi
curl ${curl_headers:+-H "${curl_headers}"} -fL --retry 3 --keepalive-time 2 "${kubernetes_tar_url}" -o "${file}"
elif [[ $(which wget) ]]; then
wget "${kubernetes_tar_url}"
else

View File

@@ -21,7 +21,7 @@ import (
"time"
apps "k8s.io/api/apps/v1beta1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
policy "k8s.io/api/policy/v1beta1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
@@ -363,7 +363,19 @@ func (dc *DisruptionController) updateDb(old, cur interface{}) {
}
func (dc *DisruptionController) removeDb(obj interface{}) {
pdb := obj.(*policy.PodDisruptionBudget)
pdb, ok := obj.(*policy.PodDisruptionBudget)
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
klog.Errorf("Couldn't get object from tombstone %+v", obj)
return
}
pdb, ok = tombstone.Obj.(*policy.PodDisruptionBudget)
if !ok {
klog.Errorf("Tombstone contained object that is not a pdb %+v", obj)
return
}
}
klog.V(4).Infof("remove DB %q", pdb.Name)
dc.enqueuePdb(pdb)
}

View File

@@ -315,6 +315,11 @@ func (ss *scaleSet) GetZoneByNodeName(name string) (cloudprovider.Zone, error) {
} else if vm.InstanceView != nil && vm.InstanceView.PlatformFaultDomain != nil {
// Availability zone is not used for the node, falling back to fault domain.
failureDomain = strconv.Itoa(int(*vm.InstanceView.PlatformFaultDomain))
} else {
err = fmt.Errorf("failed to get zone info")
klog.Errorf("GetZoneByNodeName: got unexpected error %v", err)
ss.deleteCacheForNode(name)
return cloudprovider.Zone{}, err
}
return cloudprovider.Zone{

View File

@@ -43,7 +43,6 @@ go_library(
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//staging/src/k8s.io/csi-translation-lib:go_default_library",
"//staging/src/k8s.io/csi-translation-lib/plugins:go_default_library",
"//test/e2e/common:go_default_library",
"//test/e2e/framework:go_default_library",
"//test/e2e/framework/log:go_default_library",
"//test/e2e/framework/metrics:go_default_library",

View File

@@ -19,6 +19,7 @@ package testsuites
import (
"fmt"
"strings"
"time"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
@@ -27,10 +28,10 @@ import (
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/util/wait"
clientset "k8s.io/client-go/kubernetes"
volevents "k8s.io/kubernetes/pkg/controller/volume/events"
"k8s.io/kubernetes/pkg/kubelet/events"
"k8s.io/kubernetes/test/e2e/common"
"k8s.io/kubernetes/test/e2e/framework"
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
@@ -221,7 +222,7 @@ func (t *volumeModeTestSuite) defineTests(driver TestDriver, pattern testpattern
}.AsSelector().String()
msg := "Unable to attach or mount volumes"
err = common.WaitTimeoutForEvent(l.cs, l.ns.Name, eventSelector, msg, framework.PodStartTimeout)
err = waitTimeoutForEvent(l.cs, l.ns.Name, eventSelector, msg, framework.PodStartTimeout)
// Events are unreliable, don't depend on the event. It's used only to speed up the test.
if err != nil {
e2elog.Logf("Warning: did not get event about FailedMountVolume")
@@ -258,7 +259,7 @@ func (t *volumeModeTestSuite) defineTests(driver TestDriver, pattern testpattern
}.AsSelector().String()
msg := "does not support block volume provisioning"
err = common.WaitTimeoutForEvent(l.cs, l.ns.Name, eventSelector, msg, framework.ClaimProvisionTimeout)
err = waitTimeoutForEvent(l.cs, l.ns.Name, eventSelector, msg, framework.ClaimProvisionTimeout)
// Events are unreliable, don't depend on the event. It's used only to speed up the test.
if err != nil {
e2elog.Logf("Warning: did not get event about provisioing failed")
@@ -308,7 +309,7 @@ func (t *volumeModeTestSuite) defineTests(driver TestDriver, pattern testpattern
} else {
msg = "has volumeMode Filesystem, but is specified in volumeDevices"
}
err = common.WaitTimeoutForEvent(l.cs, l.ns.Name, eventSelector, msg, framework.PodStartTimeout)
err = waitTimeoutForEvent(l.cs, l.ns.Name, eventSelector, msg, framework.PodStartTimeout)
// Events are unreliable, don't depend on them. They're used only to speed up the test.
if err != nil {
e2elog.Logf("Warning: did not get event about mismatched volume use")
@@ -426,3 +427,32 @@ func swapVolumeMode(podTemplate *v1.Pod) *v1.Pod {
}
return pod
}
// NOTE(avalluri): The below code is intentionally copied from e2e/common package.
// Testsuites depending on common package is not desirable as that pulls quite
// many tests which are not interested by storage suites.
//
// waitTimeoutForEvent waits the given timeout duration for an event to occur.
func waitTimeoutForEvent(c clientset.Interface, namespace, eventSelector, msg string, timeout time.Duration) error {
interval := 2 * time.Second
return wait.PollImmediate(interval, timeout, eventOccurred(c, namespace, eventSelector, msg))
}
// NOTE(avalluri): The below code is intentionally copied from e2e/common package.
// Testsuites depending on common package is not desirable as that pulls quite
// many tests which are not interested by storage suites.
func eventOccurred(c clientset.Interface, namespace, eventSelector, msg string) wait.ConditionFunc {
options := metav1.ListOptions{FieldSelector: eventSelector}
return func() (bool, error) {
events, err := c.CoreV1().Events(namespace).List(options)
if err != nil {
return false, fmt.Errorf("got error while getting events: %v", err)
}
for _, event := range events.Items {
if strings.Contains(event.Message, msg) {
return true, nil
}
}
return false, nil
}
}

View File

@@ -38,9 +38,12 @@ const (
defaultObservationTimeout = time.Minute * 4
)
var _ = framework.KubeDescribe("StartupProbe [Serial] [Disruptive] [NodeFeature:StartupProbe]", func() {
f := framework.NewDefaultFramework("critical-pod-test")
var _ = framework.KubeDescribe("StartupProbe [Serial] [Disruptive] [NodeAlphaFeature:StartupProbe]", func() {
f := framework.NewDefaultFramework("startup-probe-test")
var podClient *framework.PodClient
ginkgo.BeforeEach(func() {
podClient = f.PodClient()
})
/*
These tests are located here as they require tempSetCurrentKubeletConfig to enable the feature gate for startupProbe.

View File

@@ -17,7 +17,7 @@ include ../../hack/make-rules/Makefile.manifest
REGISTRY ?= gcr.io/kubernetes-e2e-test-images
GOARM ?= 7
QEMUVERSION=v2.9.1
GOLANG_VERSION=1.12.10
GOLANG_VERSION=1.12.12
export
ifndef WHAT