mirror of
https://github.com/kubernetes/sample-controller.git
synced 2026-08-03 00:00:02 +08:00
Merge remote-tracking branch 'origin/master' into release-1.13
Kubernetes-commit: 03aacded1e0e8e9ebf2a84039f02433bb7b38bd0
This commit is contained in:
Generated
+249
-249
File diff suppressed because it is too large
Load Diff
+14
-14
@@ -20,7 +20,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
@@ -37,6 +36,7 @@ import (
|
|||||||
"k8s.io/client-go/tools/cache"
|
"k8s.io/client-go/tools/cache"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
"k8s.io/client-go/util/workqueue"
|
"k8s.io/client-go/util/workqueue"
|
||||||
|
"k8s.io/klog"
|
||||||
|
|
||||||
samplev1alpha1 "k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1"
|
samplev1alpha1 "k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1"
|
||||||
clientset "k8s.io/sample-controller/pkg/client/clientset/versioned"
|
clientset "k8s.io/sample-controller/pkg/client/clientset/versioned"
|
||||||
@@ -96,9 +96,9 @@ func NewController(
|
|||||||
// Add sample-controller types to the default Kubernetes Scheme so Events can be
|
// Add sample-controller types to the default Kubernetes Scheme so Events can be
|
||||||
// logged for sample-controller types.
|
// logged for sample-controller types.
|
||||||
utilruntime.Must(samplescheme.AddToScheme(scheme.Scheme))
|
utilruntime.Must(samplescheme.AddToScheme(scheme.Scheme))
|
||||||
glog.V(4).Info("Creating event broadcaster")
|
klog.V(4).Info("Creating event broadcaster")
|
||||||
eventBroadcaster := record.NewBroadcaster()
|
eventBroadcaster := record.NewBroadcaster()
|
||||||
eventBroadcaster.StartLogging(glog.Infof)
|
eventBroadcaster.StartLogging(klog.Infof)
|
||||||
eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeclientset.CoreV1().Events("")})
|
eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeclientset.CoreV1().Events("")})
|
||||||
recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName})
|
recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName})
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ func NewController(
|
|||||||
recorder: recorder,
|
recorder: recorder,
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Info("Setting up event handlers")
|
klog.Info("Setting up event handlers")
|
||||||
// Set up an event handler for when Foo resources change
|
// Set up an event handler for when Foo resources change
|
||||||
fooInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
|
fooInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: controller.enqueueFoo,
|
AddFunc: controller.enqueueFoo,
|
||||||
@@ -154,23 +154,23 @@ func (c *Controller) Run(threadiness int, stopCh <-chan struct{}) error {
|
|||||||
defer c.workqueue.ShutDown()
|
defer c.workqueue.ShutDown()
|
||||||
|
|
||||||
// Start the informer factories to begin populating the informer caches
|
// Start the informer factories to begin populating the informer caches
|
||||||
glog.Info("Starting Foo controller")
|
klog.Info("Starting Foo controller")
|
||||||
|
|
||||||
// Wait for the caches to be synced before starting workers
|
// Wait for the caches to be synced before starting workers
|
||||||
glog.Info("Waiting for informer caches to sync")
|
klog.Info("Waiting for informer caches to sync")
|
||||||
if ok := cache.WaitForCacheSync(stopCh, c.deploymentsSynced, c.foosSynced); !ok {
|
if ok := cache.WaitForCacheSync(stopCh, c.deploymentsSynced, c.foosSynced); !ok {
|
||||||
return fmt.Errorf("failed to wait for caches to sync")
|
return fmt.Errorf("failed to wait for caches to sync")
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Info("Starting workers")
|
klog.Info("Starting workers")
|
||||||
// Launch two workers to process Foo resources
|
// Launch two workers to process Foo resources
|
||||||
for i := 0; i < threadiness; i++ {
|
for i := 0; i < threadiness; i++ {
|
||||||
go wait.Until(c.runWorker, time.Second, stopCh)
|
go wait.Until(c.runWorker, time.Second, stopCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Info("Started workers")
|
klog.Info("Started workers")
|
||||||
<-stopCh
|
<-stopCh
|
||||||
glog.Info("Shutting down workers")
|
klog.Info("Shutting down workers")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -226,7 +226,7 @@ func (c *Controller) processNextWorkItem() bool {
|
|||||||
// Finally, if no error occurs we Forget this item so it does not
|
// Finally, if no error occurs we Forget this item so it does not
|
||||||
// get queued again until another change happens.
|
// get queued again until another change happens.
|
||||||
c.workqueue.Forget(obj)
|
c.workqueue.Forget(obj)
|
||||||
glog.Infof("Successfully synced '%s'", key)
|
klog.Infof("Successfully synced '%s'", key)
|
||||||
return nil
|
return nil
|
||||||
}(obj)
|
}(obj)
|
||||||
|
|
||||||
@@ -297,7 +297,7 @@ func (c *Controller) syncHandler(key string) error {
|
|||||||
// number does not equal the current desired replicas on the Deployment, we
|
// number does not equal the current desired replicas on the Deployment, we
|
||||||
// should update the Deployment resource.
|
// should update the Deployment resource.
|
||||||
if foo.Spec.Replicas != nil && *foo.Spec.Replicas != *deployment.Spec.Replicas {
|
if foo.Spec.Replicas != nil && *foo.Spec.Replicas != *deployment.Spec.Replicas {
|
||||||
glog.V(4).Infof("Foo %s replicas: %d, deployment replicas: %d", name, *foo.Spec.Replicas, *deployment.Spec.Replicas)
|
klog.V(4).Infof("Foo %s replicas: %d, deployment replicas: %d", name, *foo.Spec.Replicas, *deployment.Spec.Replicas)
|
||||||
deployment, err = c.kubeclientset.AppsV1().Deployments(foo.Namespace).Update(newDeployment(foo))
|
deployment, err = c.kubeclientset.AppsV1().Deployments(foo.Namespace).Update(newDeployment(foo))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,9 +365,9 @@ func (c *Controller) handleObject(obj interface{}) {
|
|||||||
runtime.HandleError(fmt.Errorf("error decoding object tombstone, invalid type"))
|
runtime.HandleError(fmt.Errorf("error decoding object tombstone, invalid type"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
glog.V(4).Infof("Recovered deleted object '%s' from tombstone", object.GetName())
|
klog.V(4).Infof("Recovered deleted object '%s' from tombstone", object.GetName())
|
||||||
}
|
}
|
||||||
glog.V(4).Infof("Processing object: %s", object.GetName())
|
klog.V(4).Infof("Processing object: %s", object.GetName())
|
||||||
if ownerRef := metav1.GetControllerOf(object); ownerRef != nil {
|
if ownerRef := metav1.GetControllerOf(object); ownerRef != nil {
|
||||||
// If this object is not owned by a Foo, we should not do anything more
|
// If this object is not owned by a Foo, we should not do anything more
|
||||||
// with it.
|
// with it.
|
||||||
@@ -377,7 +377,7 @@ func (c *Controller) handleObject(obj interface{}) {
|
|||||||
|
|
||||||
foo, err := c.foosLister.Foos(object.GetNamespace()).Get(ownerRef.Name)
|
foo, err := c.foosLister.Foos(object.GetNamespace()).Get(ownerRef.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(4).Infof("ignoring orphaned object '%s' of foo '%s'", object.GetSelfLink(), ownerRef.Name)
|
klog.V(4).Infof("ignoring orphaned object '%s' of foo '%s'", object.GetSelfLink(), ownerRef.Name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
kubeinformers "k8s.io/client-go/informers"
|
kubeinformers "k8s.io/client-go/informers"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
|
"k8s.io/klog"
|
||||||
// Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters).
|
// Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters).
|
||||||
// _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
|
// _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
|
||||||
|
|
||||||
@@ -45,17 +45,17 @@ func main() {
|
|||||||
|
|
||||||
cfg, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
|
cfg, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Error building kubeconfig: %s", err.Error())
|
klog.Fatalf("Error building kubeconfig: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
kubeClient, err := kubernetes.NewForConfig(cfg)
|
kubeClient, err := kubernetes.NewForConfig(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Error building kubernetes clientset: %s", err.Error())
|
klog.Fatalf("Error building kubernetes clientset: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
exampleClient, err := clientset.NewForConfig(cfg)
|
exampleClient, err := clientset.NewForConfig(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Error building example clientset: %s", err.Error())
|
klog.Fatalf("Error building example clientset: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, time.Second*30)
|
kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, time.Second*30)
|
||||||
@@ -71,7 +71,7 @@ func main() {
|
|||||||
exampleInformerFactory.Start(stopCh)
|
exampleInformerFactory.Start(stopCh)
|
||||||
|
|
||||||
if err = controller.Run(2, stopCh); err != nil {
|
if err = controller.Run(2, stopCh); err != nil {
|
||||||
glog.Fatalf("Error running controller: %s", err.Error())
|
klog.Fatalf("Error running controller: %s", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -20,7 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
|
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
|
||||||
@@ -607,7 +607,7 @@ func (a genericAccessor) GetOwnerReferences() []metav1.OwnerReference {
|
|||||||
var ret []metav1.OwnerReference
|
var ret []metav1.OwnerReference
|
||||||
s := a.ownerReferences
|
s := a.ownerReferences
|
||||||
if s.Kind() != reflect.Ptr || s.Elem().Kind() != reflect.Slice {
|
if s.Kind() != reflect.Ptr || s.Elem().Kind() != reflect.Slice {
|
||||||
glog.Errorf("expect %v to be a pointer to slice", s)
|
klog.Errorf("expect %v to be a pointer to slice", s)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
s = s.Elem()
|
s = s.Elem()
|
||||||
@@ -615,7 +615,7 @@ func (a genericAccessor) GetOwnerReferences() []metav1.OwnerReference {
|
|||||||
ret = make([]metav1.OwnerReference, s.Len(), s.Len()+1)
|
ret = make([]metav1.OwnerReference, s.Len(), s.Len()+1)
|
||||||
for i := 0; i < s.Len(); i++ {
|
for i := 0; i < s.Len(); i++ {
|
||||||
if err := extractFromOwnerReference(s.Index(i), &ret[i]); err != nil {
|
if err := extractFromOwnerReference(s.Index(i), &ret[i]); err != nil {
|
||||||
glog.Errorf("extractFromOwnerReference failed: %v", err)
|
klog.Errorf("extractFromOwnerReference failed: %v", err)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -625,13 +625,13 @@ func (a genericAccessor) GetOwnerReferences() []metav1.OwnerReference {
|
|||||||
func (a genericAccessor) SetOwnerReferences(references []metav1.OwnerReference) {
|
func (a genericAccessor) SetOwnerReferences(references []metav1.OwnerReference) {
|
||||||
s := a.ownerReferences
|
s := a.ownerReferences
|
||||||
if s.Kind() != reflect.Ptr || s.Elem().Kind() != reflect.Slice {
|
if s.Kind() != reflect.Ptr || s.Elem().Kind() != reflect.Slice {
|
||||||
glog.Errorf("expect %v to be a pointer to slice", s)
|
klog.Errorf("expect %v to be a pointer to slice", s)
|
||||||
}
|
}
|
||||||
s = s.Elem()
|
s = s.Elem()
|
||||||
newReferences := reflect.MakeSlice(s.Type(), len(references), len(references))
|
newReferences := reflect.MakeSlice(s.Type(), len(references), len(references))
|
||||||
for i := 0; i < len(references); i++ {
|
for i := 0; i < len(references); i++ {
|
||||||
if err := setOwnerReference(newReferences.Index(i), &references[i]); err != nil {
|
if err := setOwnerReference(newReferences.Index(i), &references[i]); err != nil {
|
||||||
glog.Errorf("setOwnerReference failed: %v", err)
|
klog.Errorf("setOwnerReference failed: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -23,10 +23,10 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"k8s.io/apimachinery/pkg/selection"
|
"k8s.io/apimachinery/pkg/selection"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/apimachinery/pkg/util/validation"
|
"k8s.io/apimachinery/pkg/util/validation"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Requirements is AND of all requirements.
|
// Requirements is AND of all requirements.
|
||||||
@@ -211,13 +211,13 @@ func (r *Requirement) Matches(ls Labels) bool {
|
|||||||
}
|
}
|
||||||
lsValue, err := strconv.ParseInt(ls.Get(r.key), 10, 64)
|
lsValue, err := strconv.ParseInt(ls.Get(r.key), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(10).Infof("ParseInt failed for value %+v in label %+v, %+v", ls.Get(r.key), ls, err)
|
klog.V(10).Infof("ParseInt failed for value %+v in label %+v, %+v", ls.Get(r.key), ls, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// There should be only one strValue in r.strValues, and can be converted to a integer.
|
// There should be only one strValue in r.strValues, and can be converted to a integer.
|
||||||
if len(r.strValues) != 1 {
|
if len(r.strValues) != 1 {
|
||||||
glog.V(10).Infof("Invalid values count %+v of requirement %#v, for 'Gt', 'Lt' operators, exactly one value is required", len(r.strValues), r)
|
klog.V(10).Infof("Invalid values count %+v of requirement %#v, for 'Gt', 'Lt' operators, exactly one value is required", len(r.strValues), r)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ func (r *Requirement) Matches(ls Labels) bool {
|
|||||||
for i := range r.strValues {
|
for i := range r.strValues {
|
||||||
rValue, err = strconv.ParseInt(r.strValues[i], 10, 64)
|
rValue, err = strconv.ParseInt(r.strValues[i], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(10).Infof("ParseInt failed for value %+v in requirement %#v, for 'Gt', 'Lt' operators, the value must be an integer", r.strValues[i], r)
|
klog.V(10).Infof("ParseInt failed for value %+v in requirement %#v, for 'Gt', 'Lt' operators, the value must be an integer", r.strValues[i], r)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -33,7 +33,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/json"
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UnstructuredConverter is an interface for converting between interface{}
|
// UnstructuredConverter is an interface for converting between interface{}
|
||||||
@@ -133,10 +133,10 @@ func (c *unstructuredConverter) FromUnstructured(u map[string]interface{}, obj i
|
|||||||
newObj := reflect.New(t.Elem()).Interface()
|
newObj := reflect.New(t.Elem()).Interface()
|
||||||
newErr := fromUnstructuredViaJSON(u, newObj)
|
newErr := fromUnstructuredViaJSON(u, newObj)
|
||||||
if (err != nil) != (newErr != nil) {
|
if (err != nil) != (newErr != nil) {
|
||||||
glog.Fatalf("FromUnstructured unexpected error for %v: error: %v", u, err)
|
klog.Fatalf("FromUnstructured unexpected error for %v: error: %v", u, err)
|
||||||
}
|
}
|
||||||
if err == nil && !c.comparison.DeepEqual(obj, newObj) {
|
if err == nil && !c.comparison.DeepEqual(obj, newObj) {
|
||||||
glog.Fatalf("FromUnstructured mismatch\nobj1: %#v\nobj2: %#v", obj, newObj)
|
klog.Fatalf("FromUnstructured mismatch\nobj1: %#v\nobj2: %#v", obj, newObj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -424,10 +424,10 @@ func (c *unstructuredConverter) ToUnstructured(obj interface{}) (map[string]inte
|
|||||||
newUnstr := map[string]interface{}{}
|
newUnstr := map[string]interface{}{}
|
||||||
newErr := toUnstructuredViaJSON(obj, &newUnstr)
|
newErr := toUnstructuredViaJSON(obj, &newUnstr)
|
||||||
if (err != nil) != (newErr != nil) {
|
if (err != nil) != (newErr != nil) {
|
||||||
glog.Fatalf("ToUnstructured unexpected error for %v: error: %v; newErr: %v", obj, err, newErr)
|
klog.Fatalf("ToUnstructured unexpected error for %v: error: %v; newErr: %v", obj, err, newErr)
|
||||||
}
|
}
|
||||||
if err == nil && !c.comparison.DeepEqual(u, newUnstr) {
|
if err == nil && !c.comparison.DeepEqual(u, newUnstr) {
|
||||||
glog.Fatalf("ToUnstructured mismatch\nobj1: %#v\nobj2: %#v", u, newUnstr)
|
klog.Fatalf("ToUnstructured mismatch\nobj1: %#v\nobj2: %#v", u, newUnstr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+2
-2
@@ -25,8 +25,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/google/gofuzz"
|
"github.com/google/gofuzz"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IntOrString is a type that can hold an int32 or a string. When used in
|
// IntOrString is a type that can hold an int32 or a string. When used in
|
||||||
@@ -58,7 +58,7 @@ const (
|
|||||||
// TODO: convert to (val int32)
|
// TODO: convert to (val int32)
|
||||||
func FromInt(val int) IntOrString {
|
func FromInt(val int) IntOrString {
|
||||||
if val > math.MaxInt32 || val < math.MinInt32 {
|
if val > math.MaxInt32 || val < math.MinInt32 {
|
||||||
glog.Errorf("value: %d overflows int32\n%s\n", val, debug.Stack())
|
klog.Errorf("value: %d overflows int32\n%s\n", val, debug.Stack())
|
||||||
}
|
}
|
||||||
return IntOrString{Type: Int, IntVal: int32(val)}
|
return IntOrString{Type: Int, IntVal: int32(val)}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -31,8 +31,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// JoinPreservingTrailingSlash does a path.Join of the specified elements,
|
// JoinPreservingTrailingSlash does a path.Join of the specified elements,
|
||||||
@@ -107,10 +107,10 @@ func SetTransportDefaults(t *http.Transport) *http.Transport {
|
|||||||
t = SetOldTransportDefaults(t)
|
t = SetOldTransportDefaults(t)
|
||||||
// Allow clients to disable http2 if needed.
|
// Allow clients to disable http2 if needed.
|
||||||
if s := os.Getenv("DISABLE_HTTP2"); len(s) > 0 {
|
if s := os.Getenv("DISABLE_HTTP2"); len(s) > 0 {
|
||||||
glog.Infof("HTTP2 has been explicitly disabled")
|
klog.Infof("HTTP2 has been explicitly disabled")
|
||||||
} else {
|
} else {
|
||||||
if err := http2.ConfigureTransport(t); err != nil {
|
if err := http2.ConfigureTransport(t); err != nil {
|
||||||
glog.Warningf("Transport failed http2 configuration: %v", err)
|
klog.Warningf("Transport failed http2 configuration: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return t
|
return t
|
||||||
@@ -368,7 +368,7 @@ redirectLoop:
|
|||||||
resp, err := http.ReadResponse(respReader, nil)
|
resp, err := http.ReadResponse(respReader, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Unable to read the backend response; let the client handle it.
|
// Unable to read the backend response; let the client handle it.
|
||||||
glog.Warningf("Error reading backend response: %v", err)
|
klog.Warningf("Error reading backend response: %v", err)
|
||||||
break redirectLoop
|
break redirectLoop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+19
-19
@@ -26,7 +26,7 @@ import (
|
|||||||
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AddressFamily uint
|
type AddressFamily uint
|
||||||
@@ -193,7 +193,7 @@ func isInterfaceUp(intf *net.Interface) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if intf.Flags&net.FlagUp != 0 {
|
if intf.Flags&net.FlagUp != 0 {
|
||||||
glog.V(4).Infof("Interface %v is up", intf.Name)
|
klog.V(4).Infof("Interface %v is up", intf.Name)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@@ -208,20 +208,20 @@ func isLoopbackOrPointToPoint(intf *net.Interface) bool {
|
|||||||
func getMatchingGlobalIP(addrs []net.Addr, family AddressFamily) (net.IP, error) {
|
func getMatchingGlobalIP(addrs []net.Addr, family AddressFamily) (net.IP, error) {
|
||||||
if len(addrs) > 0 {
|
if len(addrs) > 0 {
|
||||||
for i := range addrs {
|
for i := range addrs {
|
||||||
glog.V(4).Infof("Checking addr %s.", addrs[i].String())
|
klog.V(4).Infof("Checking addr %s.", addrs[i].String())
|
||||||
ip, _, err := net.ParseCIDR(addrs[i].String())
|
ip, _, err := net.ParseCIDR(addrs[i].String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if memberOf(ip, family) {
|
if memberOf(ip, family) {
|
||||||
if ip.IsGlobalUnicast() {
|
if ip.IsGlobalUnicast() {
|
||||||
glog.V(4).Infof("IP found %v", ip)
|
klog.V(4).Infof("IP found %v", ip)
|
||||||
return ip, nil
|
return ip, nil
|
||||||
} else {
|
} else {
|
||||||
glog.V(4).Infof("Non-global unicast address found %v", ip)
|
klog.V(4).Infof("Non-global unicast address found %v", ip)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
glog.V(4).Infof("%v is not an IPv%d address", ip, int(family))
|
klog.V(4).Infof("%v is not an IPv%d address", ip, int(family))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -241,13 +241,13 @@ func getIPFromInterface(intfName string, forFamily AddressFamily, nw networkInte
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
glog.V(4).Infof("Interface %q has %d addresses :%v.", intfName, len(addrs), addrs)
|
klog.V(4).Infof("Interface %q has %d addresses :%v.", intfName, len(addrs), addrs)
|
||||||
matchingIP, err := getMatchingGlobalIP(addrs, forFamily)
|
matchingIP, err := getMatchingGlobalIP(addrs, forFamily)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if matchingIP != nil {
|
if matchingIP != nil {
|
||||||
glog.V(4).Infof("Found valid IPv%d address %v for interface %q.", int(forFamily), matchingIP, intfName)
|
klog.V(4).Infof("Found valid IPv%d address %v for interface %q.", int(forFamily), matchingIP, intfName)
|
||||||
return matchingIP, nil
|
return matchingIP, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -275,14 +275,14 @@ func chooseIPFromHostInterfaces(nw networkInterfacer) (net.IP, error) {
|
|||||||
return nil, fmt.Errorf("no interfaces found on host.")
|
return nil, fmt.Errorf("no interfaces found on host.")
|
||||||
}
|
}
|
||||||
for _, family := range []AddressFamily{familyIPv4, familyIPv6} {
|
for _, family := range []AddressFamily{familyIPv4, familyIPv6} {
|
||||||
glog.V(4).Infof("Looking for system interface with a global IPv%d address", uint(family))
|
klog.V(4).Infof("Looking for system interface with a global IPv%d address", uint(family))
|
||||||
for _, intf := range intfs {
|
for _, intf := range intfs {
|
||||||
if !isInterfaceUp(&intf) {
|
if !isInterfaceUp(&intf) {
|
||||||
glog.V(4).Infof("Skipping: down interface %q", intf.Name)
|
klog.V(4).Infof("Skipping: down interface %q", intf.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if isLoopbackOrPointToPoint(&intf) {
|
if isLoopbackOrPointToPoint(&intf) {
|
||||||
glog.V(4).Infof("Skipping: LB or P2P interface %q", intf.Name)
|
klog.V(4).Infof("Skipping: LB or P2P interface %q", intf.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
addrs, err := nw.Addrs(&intf)
|
addrs, err := nw.Addrs(&intf)
|
||||||
@@ -290,7 +290,7 @@ func chooseIPFromHostInterfaces(nw networkInterfacer) (net.IP, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(addrs) == 0 {
|
if len(addrs) == 0 {
|
||||||
glog.V(4).Infof("Skipping: no addresses on interface %q", intf.Name)
|
klog.V(4).Infof("Skipping: no addresses on interface %q", intf.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
@@ -299,15 +299,15 @@ func chooseIPFromHostInterfaces(nw networkInterfacer) (net.IP, error) {
|
|||||||
return nil, fmt.Errorf("Unable to parse CIDR for interface %q: %s", intf.Name, err)
|
return nil, fmt.Errorf("Unable to parse CIDR for interface %q: %s", intf.Name, err)
|
||||||
}
|
}
|
||||||
if !memberOf(ip, family) {
|
if !memberOf(ip, family) {
|
||||||
glog.V(4).Infof("Skipping: no address family match for %q on interface %q.", ip, intf.Name)
|
klog.V(4).Infof("Skipping: no address family match for %q on interface %q.", ip, intf.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// TODO: Decide if should open up to allow IPv6 LLAs in future.
|
// TODO: Decide if should open up to allow IPv6 LLAs in future.
|
||||||
if !ip.IsGlobalUnicast() {
|
if !ip.IsGlobalUnicast() {
|
||||||
glog.V(4).Infof("Skipping: non-global address %q on interface %q.", ip, intf.Name)
|
klog.V(4).Infof("Skipping: non-global address %q on interface %q.", ip, intf.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
glog.V(4).Infof("Found global unicast address %q on interface %q.", ip, intf.Name)
|
klog.V(4).Infof("Found global unicast address %q on interface %q.", ip, intf.Name)
|
||||||
return ip, nil
|
return ip, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -381,23 +381,23 @@ func getAllDefaultRoutes() ([]Route, error) {
|
|||||||
// an IPv4 IP, and then will look at each IPv6 route for an IPv6 IP.
|
// an IPv4 IP, and then will look at each IPv6 route for an IPv6 IP.
|
||||||
func chooseHostInterfaceFromRoute(routes []Route, nw networkInterfacer) (net.IP, error) {
|
func chooseHostInterfaceFromRoute(routes []Route, nw networkInterfacer) (net.IP, error) {
|
||||||
for _, family := range []AddressFamily{familyIPv4, familyIPv6} {
|
for _, family := range []AddressFamily{familyIPv4, familyIPv6} {
|
||||||
glog.V(4).Infof("Looking for default routes with IPv%d addresses", uint(family))
|
klog.V(4).Infof("Looking for default routes with IPv%d addresses", uint(family))
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
if route.Family != family {
|
if route.Family != family {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
glog.V(4).Infof("Default route transits interface %q", route.Interface)
|
klog.V(4).Infof("Default route transits interface %q", route.Interface)
|
||||||
finalIP, err := getIPFromInterface(route.Interface, family, nw)
|
finalIP, err := getIPFromInterface(route.Interface, family, nw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if finalIP != nil {
|
if finalIP != nil {
|
||||||
glog.V(4).Infof("Found active IP %v ", finalIP)
|
klog.V(4).Infof("Found active IP %v ", finalIP)
|
||||||
return finalIP, nil
|
return finalIP, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glog.V(4).Infof("No active IP found by looking at default routes")
|
klog.V(4).Infof("No active IP found by looking at default routes")
|
||||||
return nil, fmt.Errorf("unable to select an IP from default routes.")
|
return nil, fmt.Errorf("unable to select an IP from default routes.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -22,7 +22,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -63,7 +63,7 @@ func HandleCrash(additionalHandlers ...func(interface{})) {
|
|||||||
// logPanic logs the caller tree when a panic occurs.
|
// logPanic logs the caller tree when a panic occurs.
|
||||||
func logPanic(r interface{}) {
|
func logPanic(r interface{}) {
|
||||||
callers := getCallers(r)
|
callers := getCallers(r)
|
||||||
glog.Errorf("Observed a panic: %#v (%v)\n%v", r, r, callers)
|
klog.Errorf("Observed a panic: %#v (%v)\n%v", r, r, callers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCallers(r interface{}) string {
|
func getCallers(r interface{}) string {
|
||||||
@@ -111,7 +111,7 @@ func HandleError(err error) {
|
|||||||
|
|
||||||
// logError prints an error with the call stack of the location it was reported
|
// logError prints an error with the call stack of the location it was reported
|
||||||
func logError(err error) {
|
func logError(err error) {
|
||||||
glog.ErrorDepth(2, err)
|
klog.ErrorDepth(2, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
type rudimentaryErrorBackoff struct {
|
type rudimentaryErrorBackoff struct {
|
||||||
|
|||||||
+4
-4
@@ -26,7 +26,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -217,11 +217,11 @@ func (d *YAMLOrJSONDecoder) Decode(into interface{}) error {
|
|||||||
if d.decoder == nil {
|
if d.decoder == nil {
|
||||||
buffer, origData, isJSON := GuessJSONStream(d.r, d.bufferSize)
|
buffer, origData, isJSON := GuessJSONStream(d.r, d.bufferSize)
|
||||||
if isJSON {
|
if isJSON {
|
||||||
glog.V(4).Infof("decoding stream as JSON")
|
klog.V(4).Infof("decoding stream as JSON")
|
||||||
d.decoder = json.NewDecoder(buffer)
|
d.decoder = json.NewDecoder(buffer)
|
||||||
d.rawData = origData
|
d.rawData = origData
|
||||||
} else {
|
} else {
|
||||||
glog.V(4).Infof("decoding stream as YAML")
|
klog.V(4).Infof("decoding stream as YAML")
|
||||||
d.decoder = NewYAMLToJSONDecoder(buffer)
|
d.decoder = NewYAMLToJSONDecoder(buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -230,7 +230,7 @@ func (d *YAMLOrJSONDecoder) Decode(into interface{}) error {
|
|||||||
if syntax, ok := err.(*json.SyntaxError); ok {
|
if syntax, ok := err.(*json.SyntaxError); ok {
|
||||||
data, readErr := ioutil.ReadAll(jsonDecoder.Buffered())
|
data, readErr := ioutil.ReadAll(jsonDecoder.Buffered())
|
||||||
if readErr != nil {
|
if readErr != nil {
|
||||||
glog.V(4).Infof("reading stream failed: %v", readErr)
|
klog.V(4).Infof("reading stream failed: %v", readErr)
|
||||||
}
|
}
|
||||||
js := string(data)
|
js := string(data)
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -20,10 +20,10 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/util/net"
|
"k8s.io/apimachinery/pkg/util/net"
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Decoder allows StreamWatcher to watch any stream for which a Decoder can be written.
|
// Decoder allows StreamWatcher to watch any stream for which a Decoder can be written.
|
||||||
@@ -100,13 +100,13 @@ func (sw *StreamWatcher) receive() {
|
|||||||
case io.EOF:
|
case io.EOF:
|
||||||
// watch closed normally
|
// watch closed normally
|
||||||
case io.ErrUnexpectedEOF:
|
case io.ErrUnexpectedEOF:
|
||||||
glog.V(1).Infof("Unexpected EOF during watch stream event decoding: %v", err)
|
klog.V(1).Infof("Unexpected EOF during watch stream event decoding: %v", err)
|
||||||
default:
|
default:
|
||||||
msg := "Unable to decode an event from the watch stream: %v"
|
msg := "Unable to decode an event from the watch stream: %v"
|
||||||
if net.IsProbableEOF(err) {
|
if net.IsProbableEOF(err) {
|
||||||
glog.V(5).Infof(msg, err)
|
klog.V(5).Infof(msg, err)
|
||||||
} else {
|
} else {
|
||||||
glog.Errorf(msg, err)
|
klog.Errorf(msg, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
+3
-3
@@ -20,7 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
)
|
)
|
||||||
@@ -106,7 +106,7 @@ func (f *FakeWatcher) Stop() {
|
|||||||
f.Lock()
|
f.Lock()
|
||||||
defer f.Unlock()
|
defer f.Unlock()
|
||||||
if !f.Stopped {
|
if !f.Stopped {
|
||||||
glog.V(4).Infof("Stopping fake watcher.")
|
klog.V(4).Infof("Stopping fake watcher.")
|
||||||
close(f.result)
|
close(f.result)
|
||||||
f.Stopped = true
|
f.Stopped = true
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,7 @@ func (f *RaceFreeFakeWatcher) Stop() {
|
|||||||
f.Lock()
|
f.Lock()
|
||||||
defer f.Unlock()
|
defer f.Unlock()
|
||||||
if !f.Stopped {
|
if !f.Stopped {
|
||||||
glog.V(4).Infof("Stopping fake watcher.")
|
klog.V(4).Infof("Stopping fake watcher.")
|
||||||
close(f.result)
|
close(f.result)
|
||||||
f.Stopped = true
|
f.Stopped = true
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-9
@@ -25,8 +25,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/googleapis/gnostic/OpenAPIv2"
|
"github.com/googleapis/gnostic/OpenAPIv2"
|
||||||
|
"k8s.io/klog"
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
@@ -67,23 +67,23 @@ func (d *CachedDiscoveryClient) ServerResourcesForGroupVersion(groupVersion stri
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
cachedResources := &metav1.APIResourceList{}
|
cachedResources := &metav1.APIResourceList{}
|
||||||
if err := runtime.DecodeInto(scheme.Codecs.UniversalDecoder(), cachedBytes, cachedResources); err == nil {
|
if err := runtime.DecodeInto(scheme.Codecs.UniversalDecoder(), cachedBytes, cachedResources); err == nil {
|
||||||
glog.V(10).Infof("returning cached discovery info from %v", filename)
|
klog.V(10).Infof("returning cached discovery info from %v", filename)
|
||||||
return cachedResources, nil
|
return cachedResources, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
liveResources, err := d.delegate.ServerResourcesForGroupVersion(groupVersion)
|
liveResources, err := d.delegate.ServerResourcesForGroupVersion(groupVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(3).Infof("skipped caching discovery info due to %v", err)
|
klog.V(3).Infof("skipped caching discovery info due to %v", err)
|
||||||
return liveResources, err
|
return liveResources, err
|
||||||
}
|
}
|
||||||
if liveResources == nil || len(liveResources.APIResources) == 0 {
|
if liveResources == nil || len(liveResources.APIResources) == 0 {
|
||||||
glog.V(3).Infof("skipped caching discovery info, no resources found")
|
klog.V(3).Infof("skipped caching discovery info, no resources found")
|
||||||
return liveResources, err
|
return liveResources, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := d.writeCachedFile(filename, liveResources); err != nil {
|
if err := d.writeCachedFile(filename, liveResources); err != nil {
|
||||||
glog.V(1).Infof("failed to write cache to %v due to %v", filename, err)
|
klog.V(1).Infof("failed to write cache to %v due to %v", filename, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return liveResources, nil
|
return liveResources, nil
|
||||||
@@ -103,23 +103,23 @@ func (d *CachedDiscoveryClient) ServerGroups() (*metav1.APIGroupList, error) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
cachedGroups := &metav1.APIGroupList{}
|
cachedGroups := &metav1.APIGroupList{}
|
||||||
if err := runtime.DecodeInto(scheme.Codecs.UniversalDecoder(), cachedBytes, cachedGroups); err == nil {
|
if err := runtime.DecodeInto(scheme.Codecs.UniversalDecoder(), cachedBytes, cachedGroups); err == nil {
|
||||||
glog.V(10).Infof("returning cached discovery info from %v", filename)
|
klog.V(10).Infof("returning cached discovery info from %v", filename)
|
||||||
return cachedGroups, nil
|
return cachedGroups, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
liveGroups, err := d.delegate.ServerGroups()
|
liveGroups, err := d.delegate.ServerGroups()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(3).Infof("skipped caching discovery info due to %v", err)
|
klog.V(3).Infof("skipped caching discovery info due to %v", err)
|
||||||
return liveGroups, err
|
return liveGroups, err
|
||||||
}
|
}
|
||||||
if liveGroups == nil || len(liveGroups.Groups) == 0 {
|
if liveGroups == nil || len(liveGroups.Groups) == 0 {
|
||||||
glog.V(3).Infof("skipped caching discovery info, no groups found")
|
klog.V(3).Infof("skipped caching discovery info, no groups found")
|
||||||
return liveGroups, err
|
return liveGroups, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := d.writeCachedFile(filename, liveGroups); err != nil {
|
if err := d.writeCachedFile(filename, liveGroups); err != nil {
|
||||||
glog.V(1).Infof("failed to write cache to %v due to %v", filename, err)
|
klog.V(1).Infof("failed to write cache to %v due to %v", filename, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return liveGroups, nil
|
return liveGroups, nil
|
||||||
|
|||||||
+2
-2
@@ -20,10 +20,10 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/gregjones/httpcache"
|
"github.com/gregjones/httpcache"
|
||||||
"github.com/gregjones/httpcache/diskcache"
|
"github.com/gregjones/httpcache/diskcache"
|
||||||
"github.com/peterbourgon/diskv"
|
"github.com/peterbourgon/diskv"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
type cacheRoundTripper struct {
|
type cacheRoundTripper struct {
|
||||||
@@ -55,7 +55,7 @@ func (rt *cacheRoundTripper) CancelRequest(req *http.Request) {
|
|||||||
if cr, ok := rt.rt.Transport.(canceler); ok {
|
if cr, ok := rt.rt.Transport.(canceler); ok {
|
||||||
cr.CancelRequest(req)
|
cr.CancelRequest(req)
|
||||||
} else {
|
} else {
|
||||||
glog.Errorf("CancelRequest not implemented by %T", rt.rt.Transport)
|
klog.Errorf("CancelRequest not implemented by %T", rt.rt.Transport)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -19,11 +19,11 @@ package v1beta1
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
policy "k8s.io/api/policy/v1beta1"
|
policy "k8s.io/api/policy/v1beta1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PodDisruptionBudgetListerExpansion allows custom methods to be added to
|
// PodDisruptionBudgetListerExpansion allows custom methods to be added to
|
||||||
@@ -54,7 +54,7 @@ func (s *podDisruptionBudgetLister) GetPodPodDisruptionBudgets(pod *v1.Pod) ([]*
|
|||||||
pdb := list[i]
|
pdb := list[i]
|
||||||
selector, err = metav1.LabelSelectorAsSelector(pdb.Spec.Selector)
|
selector, err = metav1.LabelSelectorAsSelector(pdb.Spec.Selector)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Warningf("invalid selector: %v", err)
|
klog.Warningf("invalid selector: %v", err)
|
||||||
// TODO(mml): add an event to the PDB
|
// TODO(mml): add an event to the PDB
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -31,7 +31,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1"
|
"k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
@@ -44,6 +43,7 @@ import (
|
|||||||
"k8s.io/client-go/tools/clientcmd/api"
|
"k8s.io/client-go/tools/clientcmd/api"
|
||||||
"k8s.io/client-go/transport"
|
"k8s.io/client-go/transport"
|
||||||
"k8s.io/client-go/util/connrotation"
|
"k8s.io/client-go/util/connrotation"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
const execInfoEnv = "KUBERNETES_EXEC_INFO"
|
const execInfoEnv = "KUBERNETES_EXEC_INFO"
|
||||||
@@ -228,7 +228,7 @@ func (r *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||||||
Code: int32(res.StatusCode),
|
Code: int32(res.StatusCode),
|
||||||
}
|
}
|
||||||
if err := r.a.maybeRefreshCreds(creds, resp); err != nil {
|
if err := r.a.maybeRefreshCreds(creds, resp); err != nil {
|
||||||
glog.Errorf("refreshing credentials: %v", err)
|
klog.Errorf("refreshing credentials: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
|
|||||||
+2
-2
@@ -29,7 +29,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
@@ -37,6 +36,7 @@ import (
|
|||||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||||
certutil "k8s.io/client-go/util/cert"
|
certutil "k8s.io/client-go/util/cert"
|
||||||
"k8s.io/client-go/util/flowcontrol"
|
"k8s.io/client-go/util/flowcontrol"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -331,7 +331,7 @@ func InClusterConfig() (*Config, error) {
|
|||||||
tlsClientConfig := TLSClientConfig{}
|
tlsClientConfig := TLSClientConfig{}
|
||||||
|
|
||||||
if _, err := certutil.NewPool(rootCAFile); err != nil {
|
if _, err := certutil.NewPool(rootCAFile); err != nil {
|
||||||
glog.Errorf("Expected to load root CA config from %s, but got err: %v", rootCAFile, err)
|
klog.Errorf("Expected to load root CA config from %s, but got err: %v", rootCAFile, err)
|
||||||
} else {
|
} else {
|
||||||
tlsClientConfig.CAFile = rootCAFile
|
tlsClientConfig.CAFile = rootCAFile
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -21,7 +21,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||||
)
|
)
|
||||||
@@ -57,7 +57,7 @@ func RegisterAuthProviderPlugin(name string, plugin Factory) error {
|
|||||||
if _, found := plugins[name]; found {
|
if _, found := plugins[name]; found {
|
||||||
return fmt.Errorf("Auth Provider Plugin %q was registered twice", name)
|
return fmt.Errorf("Auth Provider Plugin %q was registered twice", name)
|
||||||
}
|
}
|
||||||
glog.V(4).Infof("Registered Auth Provider Plugin %q", name)
|
klog.V(4).Infof("Registered Auth Provider Plugin %q", name)
|
||||||
plugins[name] = plugin
|
plugins[name] = plugin
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-15
@@ -32,7 +32,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@@ -44,6 +43,7 @@ import (
|
|||||||
restclientwatch "k8s.io/client-go/rest/watch"
|
restclientwatch "k8s.io/client-go/rest/watch"
|
||||||
"k8s.io/client-go/tools/metrics"
|
"k8s.io/client-go/tools/metrics"
|
||||||
"k8s.io/client-go/util/flowcontrol"
|
"k8s.io/client-go/util/flowcontrol"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -114,7 +114,7 @@ type Request struct {
|
|||||||
// NewRequest creates a new request helper object for accessing runtime.Objects on a server.
|
// NewRequest creates a new request helper object for accessing runtime.Objects on a server.
|
||||||
func NewRequest(client HTTPClient, verb string, baseURL *url.URL, versionedAPIPath string, content ContentConfig, serializers Serializers, backoff BackoffManager, throttle flowcontrol.RateLimiter, timeout time.Duration) *Request {
|
func NewRequest(client HTTPClient, verb string, baseURL *url.URL, versionedAPIPath string, content ContentConfig, serializers Serializers, backoff BackoffManager, throttle flowcontrol.RateLimiter, timeout time.Duration) *Request {
|
||||||
if backoff == nil {
|
if backoff == nil {
|
||||||
glog.V(2).Infof("Not implementing request backoff strategy.")
|
klog.V(2).Infof("Not implementing request backoff strategy.")
|
||||||
backoff = &NoBackoff{}
|
backoff = &NoBackoff{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,7 +527,7 @@ func (r *Request) tryThrottle() {
|
|||||||
r.throttle.Accept()
|
r.throttle.Accept()
|
||||||
}
|
}
|
||||||
if latency := time.Since(now); latency > longThrottleLatency {
|
if latency := time.Since(now); latency > longThrottleLatency {
|
||||||
glog.V(4).Infof("Throttling request took %v, request: %s:%s", latency, r.verb, r.URL().String())
|
klog.V(4).Infof("Throttling request took %v, request: %s:%s", latency, r.verb, r.URL().String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -683,7 +683,7 @@ func (r *Request) request(fn func(*http.Request, *http.Response)) error {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
if r.err != nil {
|
if r.err != nil {
|
||||||
glog.V(4).Infof("Error in request: %v", r.err)
|
klog.V(4).Infof("Error in request: %v", r.err)
|
||||||
return r.err
|
return r.err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -770,13 +770,13 @@ func (r *Request) request(fn func(*http.Request, *http.Response)) error {
|
|||||||
if seeker, ok := r.body.(io.Seeker); ok && r.body != nil {
|
if seeker, ok := r.body.(io.Seeker); ok && r.body != nil {
|
||||||
_, err := seeker.Seek(0, 0)
|
_, err := seeker.Seek(0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(4).Infof("Could not retry request, can't Seek() back to beginning of body for %T", r.body)
|
klog.V(4).Infof("Could not retry request, can't Seek() back to beginning of body for %T", r.body)
|
||||||
fn(req, resp)
|
fn(req, resp)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(4).Infof("Got a Retry-After %ds response for attempt %d to %v", seconds, retries, url)
|
klog.V(4).Infof("Got a Retry-After %ds response for attempt %d to %v", seconds, retries, url)
|
||||||
r.backoffMgr.Sleep(time.Duration(seconds) * time.Second)
|
r.backoffMgr.Sleep(time.Duration(seconds) * time.Second)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -844,13 +844,13 @@ func (r *Request) transformResponse(resp *http.Response, req *http.Request) Resu
|
|||||||
// 2. Apiserver sends back the headers and then part of the body
|
// 2. Apiserver sends back the headers and then part of the body
|
||||||
// 3. Apiserver closes connection.
|
// 3. Apiserver closes connection.
|
||||||
// 4. client-go should catch this and return an error.
|
// 4. client-go should catch this and return an error.
|
||||||
glog.V(2).Infof("Stream error %#v when reading response body, may be caused by closed connection.", err)
|
klog.V(2).Infof("Stream error %#v when reading response body, may be caused by closed connection.", err)
|
||||||
streamErr := fmt.Errorf("Stream error %#v when reading response body, may be caused by closed connection. Please retry.", err)
|
streamErr := fmt.Errorf("Stream error %#v when reading response body, may be caused by closed connection. Please retry.", err)
|
||||||
return Result{
|
return Result{
|
||||||
err: streamErr,
|
err: streamErr,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
glog.Errorf("Unexpected error when reading response body: %#v", err)
|
klog.Errorf("Unexpected error when reading response body: %#v", err)
|
||||||
unexpectedErr := fmt.Errorf("Unexpected error %#v when reading response body. Please retry.", err)
|
unexpectedErr := fmt.Errorf("Unexpected error %#v when reading response body. Please retry.", err)
|
||||||
return Result{
|
return Result{
|
||||||
err: unexpectedErr,
|
err: unexpectedErr,
|
||||||
@@ -914,11 +914,11 @@ func (r *Request) transformResponse(resp *http.Response, req *http.Request) Resu
|
|||||||
func truncateBody(body string) string {
|
func truncateBody(body string) string {
|
||||||
max := 0
|
max := 0
|
||||||
switch {
|
switch {
|
||||||
case bool(glog.V(10)):
|
case bool(klog.V(10)):
|
||||||
return body
|
return body
|
||||||
case bool(glog.V(9)):
|
case bool(klog.V(9)):
|
||||||
max = 10240
|
max = 10240
|
||||||
case bool(glog.V(8)):
|
case bool(klog.V(8)):
|
||||||
max = 1024
|
max = 1024
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -933,13 +933,13 @@ func truncateBody(body string) string {
|
|||||||
// allocating a new string for the body output unless necessary. Uses a simple heuristic to determine
|
// allocating a new string for the body output unless necessary. Uses a simple heuristic to determine
|
||||||
// whether the body is printable.
|
// whether the body is printable.
|
||||||
func glogBody(prefix string, body []byte) {
|
func glogBody(prefix string, body []byte) {
|
||||||
if glog.V(8) {
|
if klog.V(8) {
|
||||||
if bytes.IndexFunc(body, func(r rune) bool {
|
if bytes.IndexFunc(body, func(r rune) bool {
|
||||||
return r < 0x0a
|
return r < 0x0a
|
||||||
}) != -1 {
|
}) != -1 {
|
||||||
glog.Infof("%s:\n%s", prefix, truncateBody(hex.Dump(body)))
|
klog.Infof("%s:\n%s", prefix, truncateBody(hex.Dump(body)))
|
||||||
} else {
|
} else {
|
||||||
glog.Infof("%s: %s", prefix, truncateBody(string(body)))
|
klog.Infof("%s: %s", prefix, truncateBody(string(body)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1141,7 +1141,7 @@ func (r Result) Error() error {
|
|||||||
// to be backwards compatible with old servers that do not return a version, default to "v1"
|
// to be backwards compatible with old servers that do not return a version, default to "v1"
|
||||||
out, _, err := r.decoder.Decode(r.body, &schema.GroupVersionKind{Version: "v1"}, nil)
|
out, _, err := r.decoder.Decode(r.body, &schema.GroupVersionKind{Version: "v1"}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(5).Infof("body was not decodable (unable to check for Status): %v", err)
|
klog.V(5).Infof("body was not decodable (unable to check for Status): %v", err)
|
||||||
return r.err
|
return r.err
|
||||||
}
|
}
|
||||||
switch t := out.(type) {
|
switch t := out.(type) {
|
||||||
|
|||||||
+2
-2
@@ -24,8 +24,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TokenSourceWrapTransport returns a WrapTransport that injects bearer tokens
|
// TokenSourceWrapTransport returns a WrapTransport that injects bearer tokens
|
||||||
@@ -131,7 +131,7 @@ func (ts *cachingTokenSource) Token() (*oauth2.Token, error) {
|
|||||||
if ts.tok == nil {
|
if ts.tok == nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
glog.Errorf("Unable to rotate token: %v", err)
|
klog.Errorf("Unable to rotate token: %v", err)
|
||||||
return ts.tok, nil
|
return ts.tok, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -20,9 +20,9 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/client-go/util/flowcontrol"
|
"k8s.io/client-go/util/flowcontrol"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Set of resp. Codes that we backoff for.
|
// Set of resp. Codes that we backoff for.
|
||||||
@@ -64,7 +64,7 @@ func (n *NoBackoff) Sleep(d time.Duration) {
|
|||||||
// Disable makes the backoff trivial, i.e., sets it to zero. This might be used
|
// Disable makes the backoff trivial, i.e., sets it to zero. This might be used
|
||||||
// by tests which want to run 1000s of mock requests without slowing down.
|
// by tests which want to run 1000s of mock requests without slowing down.
|
||||||
func (b *URLBackoff) Disable() {
|
func (b *URLBackoff) Disable() {
|
||||||
glog.V(4).Infof("Disabling backoff strategy")
|
klog.V(4).Infof("Disabling backoff strategy")
|
||||||
b.Backoff = flowcontrol.NewBackOff(0*time.Second, 0*time.Second)
|
b.Backoff = flowcontrol.NewBackOff(0*time.Second, 0*time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ func (b *URLBackoff) baseUrlKey(rawurl *url.URL) string {
|
|||||||
// in the future.
|
// in the future.
|
||||||
host, err := url.Parse(rawurl.String())
|
host, err := url.Parse(rawurl.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(4).Infof("Error extracting url: %v", rawurl)
|
klog.V(4).Infof("Error extracting url: %v", rawurl)
|
||||||
panic("bad url!")
|
panic("bad url!")
|
||||||
}
|
}
|
||||||
return host.Host
|
return host.Host
|
||||||
@@ -89,7 +89,7 @@ func (b *URLBackoff) UpdateBackoff(actualUrl *url.URL, err error, responseCode i
|
|||||||
b.Backoff.Next(b.baseUrlKey(actualUrl), b.Backoff.Clock.Now())
|
b.Backoff.Next(b.baseUrlKey(actualUrl), b.Backoff.Clock.Now())
|
||||||
return
|
return
|
||||||
} else if responseCode >= 300 || err != nil {
|
} else if responseCode >= 300 || err != nil {
|
||||||
glog.V(4).Infof("Client is returning errors: code %v, error %v", responseCode, err)
|
klog.V(4).Infof("Client is returning errors: code %v, error %v", responseCode, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//If we got this far, there is no backoff required for this URL anymore.
|
//If we got this far, there is no backoff required for this URL anymore.
|
||||||
|
|||||||
+5
-5
@@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewDeltaFIFO returns a Store which can be used process changes to items.
|
// NewDeltaFIFO returns a Store which can be used process changes to items.
|
||||||
@@ -506,10 +506,10 @@ func (f *DeltaFIFO) Replace(list []interface{}, resourceVersion string) error {
|
|||||||
deletedObj, exists, err := f.knownObjects.GetByKey(k)
|
deletedObj, exists, err := f.knownObjects.GetByKey(k)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
deletedObj = nil
|
deletedObj = nil
|
||||||
glog.Errorf("Unexpected error %v during lookup of key %v, placing DeleteFinalStateUnknown marker without object", err, k)
|
klog.Errorf("Unexpected error %v during lookup of key %v, placing DeleteFinalStateUnknown marker without object", err, k)
|
||||||
} else if !exists {
|
} else if !exists {
|
||||||
deletedObj = nil
|
deletedObj = nil
|
||||||
glog.Infof("Key %v does not exist in known objects store, placing DeleteFinalStateUnknown marker without object", k)
|
klog.Infof("Key %v does not exist in known objects store, placing DeleteFinalStateUnknown marker without object", k)
|
||||||
}
|
}
|
||||||
queuedDeletions++
|
queuedDeletions++
|
||||||
if err := f.queueActionLocked(Deleted, DeletedFinalStateUnknown{k, deletedObj}); err != nil {
|
if err := f.queueActionLocked(Deleted, DeletedFinalStateUnknown{k, deletedObj}); err != nil {
|
||||||
@@ -553,10 +553,10 @@ func (f *DeltaFIFO) syncKey(key string) error {
|
|||||||
func (f *DeltaFIFO) syncKeyLocked(key string) error {
|
func (f *DeltaFIFO) syncKeyLocked(key string) error {
|
||||||
obj, exists, err := f.knownObjects.GetByKey(key)
|
obj, exists, err := f.knownObjects.GetByKey(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Unexpected error %v during lookup of key %v, unable to queue object for sync", err, key)
|
klog.Errorf("Unexpected error %v during lookup of key %v, unable to queue object for sync", err, key)
|
||||||
return nil
|
return nil
|
||||||
} else if !exists {
|
} else if !exists {
|
||||||
glog.Infof("Key %v does not exist in known objects store, unable to queue object for sync", key)
|
klog.Infof("Key %v does not exist in known objects store, unable to queue object for sync", key)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -20,8 +20,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
"k8s.io/apimachinery/pkg/util/clock"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExpirationCache implements the store interface
|
// ExpirationCache implements the store interface
|
||||||
@@ -95,7 +95,7 @@ func (c *ExpirationCache) getOrExpire(key string) (interface{}, bool) {
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
if c.expirationPolicy.IsExpired(timestampedItem) {
|
if c.expirationPolicy.IsExpired(timestampedItem) {
|
||||||
glog.V(4).Infof("Entry %v: %+v has expired", key, timestampedItem.obj)
|
klog.V(4).Infof("Entry %v: %+v has expired", key, timestampedItem.obj)
|
||||||
c.cacheStorage.Delete(key)
|
c.cacheStorage.Delete(key)
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -17,7 +17,7 @@ limitations under the License.
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
@@ -60,7 +60,7 @@ func ListAllByNamespace(indexer Indexer, namespace string, selector labels.Selec
|
|||||||
items, err := indexer.Index(NamespaceIndex, &metav1.ObjectMeta{Namespace: namespace})
|
items, err := indexer.Index(NamespaceIndex, &metav1.ObjectMeta{Namespace: namespace})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Ignore error; do slow search without index.
|
// Ignore error; do slow search without index.
|
||||||
glog.Warningf("can not retrieve list of objects using index : %v", err)
|
klog.Warningf("can not retrieve list of objects using index : %v", err)
|
||||||
for _, m := range indexer.List() {
|
for _, m := range indexer.List() {
|
||||||
metadata, err := meta.Accessor(m)
|
metadata, err := meta.Accessor(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+2
-2
@@ -22,7 +22,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
@@ -156,7 +156,7 @@ func (c *mutationCache) ByIndex(name string, indexKey string) ([]interface{}, er
|
|||||||
}
|
}
|
||||||
elements, err := fn(updated)
|
elements, err := fn(updated)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(4).Infof("Unable to calculate an index entry for mutation cache entry %s: %v", key, err)
|
klog.V(4).Infof("Unable to calculate an index entry for mutation cache entry %s: %v", key, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, inIndex := range elements {
|
for _, inIndex := range elements {
|
||||||
|
|||||||
+2
-2
@@ -24,7 +24,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/util/diff"
|
"k8s.io/apimachinery/pkg/util/diff"
|
||||||
@@ -45,7 +45,7 @@ func NewCacheMutationDetector(name string) CacheMutationDetector {
|
|||||||
if !mutationDetectionEnabled {
|
if !mutationDetectionEnabled {
|
||||||
return dummyMutationDetector{}
|
return dummyMutationDetector{}
|
||||||
}
|
}
|
||||||
glog.Warningln("Mutation detector is enabled, this will result in memory leakage.")
|
klog.Warningln("Mutation detector is enabled, this will result in memory leakage.")
|
||||||
return &defaultCacheMutationDetector{name: name, period: 1 * time.Second}
|
return &defaultCacheMutationDetector{name: name, period: 1 * time.Second}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -31,7 +31,6 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@@ -41,6 +40,7 @@ import (
|
|||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Reflector watches a specified resource and causes all changes to be reflected in the given store.
|
// Reflector watches a specified resource and causes all changes to be reflected in the given store.
|
||||||
@@ -128,7 +128,7 @@ var internalPackages = []string{"client-go/tools/cache/"}
|
|||||||
// Run starts a watch and handles watch events. Will restart the watch if it is closed.
|
// Run starts a watch and handles watch events. Will restart the watch if it is closed.
|
||||||
// Run will exit when stopCh is closed.
|
// Run will exit when stopCh is closed.
|
||||||
func (r *Reflector) Run(stopCh <-chan struct{}) {
|
func (r *Reflector) Run(stopCh <-chan struct{}) {
|
||||||
glog.V(3).Infof("Starting reflector %v (%s) from %s", r.expectedType, r.resyncPeriod, r.name)
|
klog.V(3).Infof("Starting reflector %v (%s) from %s", r.expectedType, r.resyncPeriod, r.name)
|
||||||
wait.Until(func() {
|
wait.Until(func() {
|
||||||
if err := r.ListAndWatch(stopCh); err != nil {
|
if err := r.ListAndWatch(stopCh); err != nil {
|
||||||
utilruntime.HandleError(err)
|
utilruntime.HandleError(err)
|
||||||
@@ -166,7 +166,7 @@ func (r *Reflector) resyncChan() (<-chan time.Time, func() bool) {
|
|||||||
// and then use the resource version to watch.
|
// and then use the resource version to watch.
|
||||||
// It returns error if ListAndWatch didn't even try to initialize watch.
|
// It returns error if ListAndWatch didn't even try to initialize watch.
|
||||||
func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
|
func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
|
||||||
glog.V(3).Infof("Listing and watching %v from %s", r.expectedType, r.name)
|
klog.V(3).Infof("Listing and watching %v from %s", r.expectedType, r.name)
|
||||||
var resourceVersion string
|
var resourceVersion string
|
||||||
|
|
||||||
// Explicitly set "0" as resource version - it's fine for the List()
|
// Explicitly set "0" as resource version - it's fine for the List()
|
||||||
@@ -212,7 +212,7 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.ShouldResync == nil || r.ShouldResync() {
|
if r.ShouldResync == nil || r.ShouldResync() {
|
||||||
glog.V(4).Infof("%s: forcing resync", r.name)
|
klog.V(4).Infof("%s: forcing resync", r.name)
|
||||||
if err := r.store.Resync(); err != nil {
|
if err := r.store.Resync(); err != nil {
|
||||||
resyncerrc <- err
|
resyncerrc <- err
|
||||||
return
|
return
|
||||||
@@ -246,7 +246,7 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
|
|||||||
case io.EOF:
|
case io.EOF:
|
||||||
// watch closed normally
|
// watch closed normally
|
||||||
case io.ErrUnexpectedEOF:
|
case io.ErrUnexpectedEOF:
|
||||||
glog.V(1).Infof("%s: Watch for %v closed with unexpected EOF: %v", r.name, r.expectedType, err)
|
klog.V(1).Infof("%s: Watch for %v closed with unexpected EOF: %v", r.name, r.expectedType, err)
|
||||||
default:
|
default:
|
||||||
utilruntime.HandleError(fmt.Errorf("%s: Failed to watch %v: %v", r.name, r.expectedType, err))
|
utilruntime.HandleError(fmt.Errorf("%s: Failed to watch %v: %v", r.name, r.expectedType, err))
|
||||||
}
|
}
|
||||||
@@ -267,7 +267,7 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
|
|||||||
|
|
||||||
if err := r.watchHandler(w, &resourceVersion, resyncerrc, stopCh); err != nil {
|
if err := r.watchHandler(w, &resourceVersion, resyncerrc, stopCh); err != nil {
|
||||||
if err != errorStopRequested {
|
if err != errorStopRequested {
|
||||||
glog.Warningf("%s: watch of %v ended with: %v", r.name, r.expectedType, err)
|
klog.Warningf("%s: watch of %v ended with: %v", r.name, r.expectedType, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -354,7 +354,7 @@ loop:
|
|||||||
r.metrics.numberOfShortWatches.Inc()
|
r.metrics.numberOfShortWatches.Inc()
|
||||||
return fmt.Errorf("very short watch: %s: Unexpected watch close - watch lasted less than a second and no items received", r.name)
|
return fmt.Errorf("very short watch: %s: Unexpected watch close - watch lasted less than a second and no items received", r.name)
|
||||||
}
|
}
|
||||||
glog.V(4).Infof("%s: Watch close - %v total %v items received", r.name, r.expectedType, eventCount)
|
klog.V(4).Infof("%s: Watch close - %v total %v items received", r.name, r.expectedType, eventCount)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-8
@@ -28,7 +28,7 @@ import (
|
|||||||
"k8s.io/client-go/util/buffer"
|
"k8s.io/client-go/util/buffer"
|
||||||
"k8s.io/client-go/util/retry"
|
"k8s.io/client-go/util/retry"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SharedInformer has a shared data cache and is capable of distributing notifications for changes
|
// SharedInformer has a shared data cache and is capable of distributing notifications for changes
|
||||||
@@ -116,11 +116,11 @@ func WaitForCacheSync(stopCh <-chan struct{}, cacheSyncs ...InformerSynced) bool
|
|||||||
},
|
},
|
||||||
stopCh)
|
stopCh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(2).Infof("stop requested")
|
klog.V(2).Infof("stop requested")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(4).Infof("caches populated")
|
klog.V(4).Infof("caches populated")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,11 +279,11 @@ func determineResyncPeriod(desired, check time.Duration) time.Duration {
|
|||||||
return desired
|
return desired
|
||||||
}
|
}
|
||||||
if check == 0 {
|
if check == 0 {
|
||||||
glog.Warningf("The specified resyncPeriod %v is invalid because this shared informer doesn't support resyncing", desired)
|
klog.Warningf("The specified resyncPeriod %v is invalid because this shared informer doesn't support resyncing", desired)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
if desired < check {
|
if desired < check {
|
||||||
glog.Warningf("The specified resyncPeriod %v is being increased to the minimum resyncCheckPeriod %v", desired, check)
|
klog.Warningf("The specified resyncPeriod %v is being increased to the minimum resyncCheckPeriod %v", desired, check)
|
||||||
return check
|
return check
|
||||||
}
|
}
|
||||||
return desired
|
return desired
|
||||||
@@ -296,19 +296,19 @@ func (s *sharedIndexInformer) AddEventHandlerWithResyncPeriod(handler ResourceEv
|
|||||||
defer s.startedLock.Unlock()
|
defer s.startedLock.Unlock()
|
||||||
|
|
||||||
if s.stopped {
|
if s.stopped {
|
||||||
glog.V(2).Infof("Handler %v was not added to shared informer because it has stopped already", handler)
|
klog.V(2).Infof("Handler %v was not added to shared informer because it has stopped already", handler)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if resyncPeriod > 0 {
|
if resyncPeriod > 0 {
|
||||||
if resyncPeriod < minimumResyncPeriod {
|
if resyncPeriod < minimumResyncPeriod {
|
||||||
glog.Warningf("resyncPeriod %d is too small. Changing it to the minimum allowed value of %d", resyncPeriod, minimumResyncPeriod)
|
klog.Warningf("resyncPeriod %d is too small. Changing it to the minimum allowed value of %d", resyncPeriod, minimumResyncPeriod)
|
||||||
resyncPeriod = minimumResyncPeriod
|
resyncPeriod = minimumResyncPeriod
|
||||||
}
|
}
|
||||||
|
|
||||||
if resyncPeriod < s.resyncCheckPeriod {
|
if resyncPeriod < s.resyncCheckPeriod {
|
||||||
if s.started {
|
if s.started {
|
||||||
glog.Warningf("resyncPeriod %d is smaller than resyncCheckPeriod %d and the informer has already started. Changing it to %d", resyncPeriod, s.resyncCheckPeriod, s.resyncCheckPeriod)
|
klog.Warningf("resyncPeriod %d is smaller than resyncCheckPeriod %d and the informer has already started. Changing it to %d", resyncPeriod, s.resyncCheckPeriod, s.resyncCheckPeriod)
|
||||||
resyncPeriod = s.resyncCheckPeriod
|
resyncPeriod = s.resyncCheckPeriod
|
||||||
} else {
|
} else {
|
||||||
// if the event handler's resyncPeriod is smaller than the current resyncCheckPeriod, update
|
// if the event handler's resyncPeriod is smaller than the current resyncCheckPeriod, update
|
||||||
|
|||||||
+3
-3
@@ -24,8 +24,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/imdario/mergo"
|
"github.com/imdario/mergo"
|
||||||
|
"k8s.io/klog"
|
||||||
|
|
||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
clientauth "k8s.io/client-go/tools/auth"
|
clientauth "k8s.io/client-go/tools/auth"
|
||||||
@@ -545,12 +545,12 @@ func (config *inClusterClientConfig) Possible() bool {
|
|||||||
// to the default config.
|
// to the default config.
|
||||||
func BuildConfigFromFlags(masterUrl, kubeconfigPath string) (*restclient.Config, error) {
|
func BuildConfigFromFlags(masterUrl, kubeconfigPath string) (*restclient.Config, error) {
|
||||||
if kubeconfigPath == "" && masterUrl == "" {
|
if kubeconfigPath == "" && masterUrl == "" {
|
||||||
glog.Warningf("Neither --kubeconfig nor --master was specified. Using the inClusterConfig. This might not work.")
|
klog.Warningf("Neither --kubeconfig nor --master was specified. Using the inClusterConfig. This might not work.")
|
||||||
kubeconfig, err := restclient.InClusterConfig()
|
kubeconfig, err := restclient.InClusterConfig()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return kubeconfig, nil
|
return kubeconfig, nil
|
||||||
}
|
}
|
||||||
glog.Warning("error creating inClusterConfig, falling back to default config: ", err)
|
klog.Warning("error creating inClusterConfig, falling back to default config: ", err)
|
||||||
}
|
}
|
||||||
return NewNonInteractiveDeferredLoadingClientConfig(
|
return NewNonInteractiveDeferredLoadingClientConfig(
|
||||||
&ClientConfigLoadingRules{ExplicitPath: kubeconfigPath},
|
&ClientConfigLoadingRules{ExplicitPath: kubeconfigPath},
|
||||||
|
|||||||
+2
-2
@@ -24,7 +24,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||||
@@ -483,7 +483,7 @@ func getConfigFromFile(filename string) (*clientcmdapi.Config, error) {
|
|||||||
func GetConfigFromFileOrDie(filename string) *clientcmdapi.Config {
|
func GetConfigFromFileOrDie(filename string) *clientcmdapi.Config {
|
||||||
config, err := getConfigFromFile(filename)
|
config, err := getConfigFromFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.FatalDepth(1, err)
|
klog.FatalDepth(1, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|||||||
+2
-2
@@ -27,8 +27,8 @@ import (
|
|||||||
goruntime "runtime"
|
goruntime "runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/imdario/mergo"
|
"github.com/imdario/mergo"
|
||||||
|
"k8s.io/klog"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
@@ -356,7 +356,7 @@ func LoadFromFile(filename string) (*clientcmdapi.Config, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
glog.V(6).Infoln("Config loaded from file", filename)
|
klog.V(6).Infoln("Config loaded from file", filename)
|
||||||
|
|
||||||
// set LocationOfOrigin on every Cluster, User, and Context
|
// set LocationOfOrigin on every Cluster, User, and Context
|
||||||
for key, obj := range config.AuthInfos {
|
for key, obj := range config.AuthInfos {
|
||||||
|
|||||||
+3
-3
@@ -20,7 +20,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||||
@@ -119,7 +119,7 @@ func (config *DeferredLoadingClientConfig) ClientConfig() (*restclient.Config, e
|
|||||||
|
|
||||||
// check for in-cluster configuration and use it
|
// check for in-cluster configuration and use it
|
||||||
if config.icc.Possible() {
|
if config.icc.Possible() {
|
||||||
glog.V(4).Infof("Using in-cluster configuration")
|
klog.V(4).Infof("Using in-cluster configuration")
|
||||||
return config.icc.ClientConfig()
|
return config.icc.ClientConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ func (config *DeferredLoadingClientConfig) Namespace() (string, bool, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(4).Infof("Using in-cluster namespace")
|
klog.V(4).Infof("Using in-cluster namespace")
|
||||||
|
|
||||||
// allow the namespace from the service account token directory to be used.
|
// allow the namespace from the service account token directory to be used.
|
||||||
return config.icc.Namespace()
|
return config.icc.Namespace()
|
||||||
|
|||||||
+8
-8
@@ -33,7 +33,7 @@ import (
|
|||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxTriesPerEvent = 12
|
const maxTriesPerEvent = 12
|
||||||
@@ -144,7 +144,7 @@ func recordToSink(sink EventSink, event *v1.Event, eventCorrelator *EventCorrela
|
|||||||
}
|
}
|
||||||
tries++
|
tries++
|
||||||
if tries >= maxTriesPerEvent {
|
if tries >= maxTriesPerEvent {
|
||||||
glog.Errorf("Unable to write event '%#v' (retry limit exceeded!)", event)
|
klog.Errorf("Unable to write event '%#v' (retry limit exceeded!)", event)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// Randomize the first sleep so that various clients won't all be
|
// Randomize the first sleep so that various clients won't all be
|
||||||
@@ -194,13 +194,13 @@ func recordEvent(sink EventSink, event *v1.Event, patch []byte, updateExistingEv
|
|||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case *restclient.RequestConstructionError:
|
case *restclient.RequestConstructionError:
|
||||||
// We will construct the request the same next time, so don't keep trying.
|
// We will construct the request the same next time, so don't keep trying.
|
||||||
glog.Errorf("Unable to construct event '%#v': '%v' (will not retry!)", event, err)
|
klog.Errorf("Unable to construct event '%#v': '%v' (will not retry!)", event, err)
|
||||||
return true
|
return true
|
||||||
case *errors.StatusError:
|
case *errors.StatusError:
|
||||||
if errors.IsAlreadyExists(err) {
|
if errors.IsAlreadyExists(err) {
|
||||||
glog.V(5).Infof("Server rejected event '%#v': '%v' (will not retry!)", event, err)
|
klog.V(5).Infof("Server rejected event '%#v': '%v' (will not retry!)", event, err)
|
||||||
} else {
|
} else {
|
||||||
glog.Errorf("Server rejected event '%#v': '%v' (will not retry!)", event, err)
|
klog.Errorf("Server rejected event '%#v': '%v' (will not retry!)", event, err)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
case *errors.UnexpectedObjectError:
|
case *errors.UnexpectedObjectError:
|
||||||
@@ -209,7 +209,7 @@ func recordEvent(sink EventSink, event *v1.Event, patch []byte, updateExistingEv
|
|||||||
default:
|
default:
|
||||||
// This case includes actual http transport errors. Go ahead and retry.
|
// This case includes actual http transport errors. Go ahead and retry.
|
||||||
}
|
}
|
||||||
glog.Errorf("Unable to write event: '%v' (may retry after sleeping)", err)
|
klog.Errorf("Unable to write event: '%v' (may retry after sleeping)", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,12 +256,12 @@ type recorderImpl struct {
|
|||||||
func (recorder *recorderImpl) generateEvent(object runtime.Object, annotations map[string]string, timestamp metav1.Time, eventtype, reason, message string) {
|
func (recorder *recorderImpl) generateEvent(object runtime.Object, annotations map[string]string, timestamp metav1.Time, eventtype, reason, message string) {
|
||||||
ref, err := ref.GetReference(recorder.scheme, object)
|
ref, err := ref.GetReference(recorder.scheme, object)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Could not construct reference to: '%#v' due to: '%v'. Will not report event: '%v' '%v' '%v'", object, err, eventtype, reason, message)
|
klog.Errorf("Could not construct reference to: '%#v' due to: '%v'. Will not report event: '%v' '%v' '%v'", object, err, eventtype, reason, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !validateEventType(eventtype) {
|
if !validateEventType(eventtype) {
|
||||||
glog.Errorf("Unsupported event type: '%v'", eventtype)
|
klog.Errorf("Unsupported event type: '%v'", eventtype)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+19
-19
@@ -22,7 +22,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||||
)
|
)
|
||||||
@@ -62,13 +62,13 @@ func HTTPWrappersForConfig(config *Config, rt http.RoundTripper) (http.RoundTrip
|
|||||||
// DebugWrappers wraps a round tripper and logs based on the current log level.
|
// DebugWrappers wraps a round tripper and logs based on the current log level.
|
||||||
func DebugWrappers(rt http.RoundTripper) http.RoundTripper {
|
func DebugWrappers(rt http.RoundTripper) http.RoundTripper {
|
||||||
switch {
|
switch {
|
||||||
case bool(glog.V(9)):
|
case bool(klog.V(9)):
|
||||||
rt = newDebuggingRoundTripper(rt, debugCurlCommand, debugURLTiming, debugResponseHeaders)
|
rt = newDebuggingRoundTripper(rt, debugCurlCommand, debugURLTiming, debugResponseHeaders)
|
||||||
case bool(glog.V(8)):
|
case bool(klog.V(8)):
|
||||||
rt = newDebuggingRoundTripper(rt, debugJustURL, debugRequestHeaders, debugResponseStatus, debugResponseHeaders)
|
rt = newDebuggingRoundTripper(rt, debugJustURL, debugRequestHeaders, debugResponseStatus, debugResponseHeaders)
|
||||||
case bool(glog.V(7)):
|
case bool(klog.V(7)):
|
||||||
rt = newDebuggingRoundTripper(rt, debugJustURL, debugRequestHeaders, debugResponseStatus)
|
rt = newDebuggingRoundTripper(rt, debugJustURL, debugRequestHeaders, debugResponseStatus)
|
||||||
case bool(glog.V(6)):
|
case bool(klog.V(6)):
|
||||||
rt = newDebuggingRoundTripper(rt, debugURLTiming)
|
rt = newDebuggingRoundTripper(rt, debugURLTiming)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ func (rt *authProxyRoundTripper) CancelRequest(req *http.Request) {
|
|||||||
if canceler, ok := rt.rt.(requestCanceler); ok {
|
if canceler, ok := rt.rt.(requestCanceler); ok {
|
||||||
canceler.CancelRequest(req)
|
canceler.CancelRequest(req)
|
||||||
} else {
|
} else {
|
||||||
glog.Errorf("CancelRequest not implemented by %T", rt.rt)
|
klog.Errorf("CancelRequest not implemented by %T", rt.rt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ func (rt *userAgentRoundTripper) CancelRequest(req *http.Request) {
|
|||||||
if canceler, ok := rt.rt.(requestCanceler); ok {
|
if canceler, ok := rt.rt.(requestCanceler); ok {
|
||||||
canceler.CancelRequest(req)
|
canceler.CancelRequest(req)
|
||||||
} else {
|
} else {
|
||||||
glog.Errorf("CancelRequest not implemented by %T", rt.rt)
|
klog.Errorf("CancelRequest not implemented by %T", rt.rt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +197,7 @@ func (rt *basicAuthRoundTripper) CancelRequest(req *http.Request) {
|
|||||||
if canceler, ok := rt.rt.(requestCanceler); ok {
|
if canceler, ok := rt.rt.(requestCanceler); ok {
|
||||||
canceler.CancelRequest(req)
|
canceler.CancelRequest(req)
|
||||||
} else {
|
} else {
|
||||||
glog.Errorf("CancelRequest not implemented by %T", rt.rt)
|
klog.Errorf("CancelRequest not implemented by %T", rt.rt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ func (rt *impersonatingRoundTripper) CancelRequest(req *http.Request) {
|
|||||||
if canceler, ok := rt.delegate.(requestCanceler); ok {
|
if canceler, ok := rt.delegate.(requestCanceler); ok {
|
||||||
canceler.CancelRequest(req)
|
canceler.CancelRequest(req)
|
||||||
} else {
|
} else {
|
||||||
glog.Errorf("CancelRequest not implemented by %T", rt.delegate)
|
klog.Errorf("CancelRequest not implemented by %T", rt.delegate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,7 +288,7 @@ func (rt *bearerAuthRoundTripper) CancelRequest(req *http.Request) {
|
|||||||
if canceler, ok := rt.rt.(requestCanceler); ok {
|
if canceler, ok := rt.rt.(requestCanceler); ok {
|
||||||
canceler.CancelRequest(req)
|
canceler.CancelRequest(req)
|
||||||
} else {
|
} else {
|
||||||
glog.Errorf("CancelRequest not implemented by %T", rt.rt)
|
klog.Errorf("CancelRequest not implemented by %T", rt.rt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,7 +372,7 @@ func (rt *debuggingRoundTripper) CancelRequest(req *http.Request) {
|
|||||||
if canceler, ok := rt.delegatedRoundTripper.(requestCanceler); ok {
|
if canceler, ok := rt.delegatedRoundTripper.(requestCanceler); ok {
|
||||||
canceler.CancelRequest(req)
|
canceler.CancelRequest(req)
|
||||||
} else {
|
} else {
|
||||||
glog.Errorf("CancelRequest not implemented by %T", rt.delegatedRoundTripper)
|
klog.Errorf("CancelRequest not implemented by %T", rt.delegatedRoundTripper)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,17 +380,17 @@ func (rt *debuggingRoundTripper) RoundTrip(req *http.Request) (*http.Response, e
|
|||||||
reqInfo := newRequestInfo(req)
|
reqInfo := newRequestInfo(req)
|
||||||
|
|
||||||
if rt.levels[debugJustURL] {
|
if rt.levels[debugJustURL] {
|
||||||
glog.Infof("%s %s", reqInfo.RequestVerb, reqInfo.RequestURL)
|
klog.Infof("%s %s", reqInfo.RequestVerb, reqInfo.RequestURL)
|
||||||
}
|
}
|
||||||
if rt.levels[debugCurlCommand] {
|
if rt.levels[debugCurlCommand] {
|
||||||
glog.Infof("%s", reqInfo.toCurl())
|
klog.Infof("%s", reqInfo.toCurl())
|
||||||
|
|
||||||
}
|
}
|
||||||
if rt.levels[debugRequestHeaders] {
|
if rt.levels[debugRequestHeaders] {
|
||||||
glog.Infof("Request Headers:")
|
klog.Infof("Request Headers:")
|
||||||
for key, values := range reqInfo.RequestHeaders {
|
for key, values := range reqInfo.RequestHeaders {
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
glog.Infof(" %s: %s", key, value)
|
klog.Infof(" %s: %s", key, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -402,16 +402,16 @@ func (rt *debuggingRoundTripper) RoundTrip(req *http.Request) (*http.Response, e
|
|||||||
reqInfo.complete(response, err)
|
reqInfo.complete(response, err)
|
||||||
|
|
||||||
if rt.levels[debugURLTiming] {
|
if rt.levels[debugURLTiming] {
|
||||||
glog.Infof("%s %s %s in %d milliseconds", reqInfo.RequestVerb, reqInfo.RequestURL, reqInfo.ResponseStatus, reqInfo.Duration.Nanoseconds()/int64(time.Millisecond))
|
klog.Infof("%s %s %s in %d milliseconds", reqInfo.RequestVerb, reqInfo.RequestURL, reqInfo.ResponseStatus, reqInfo.Duration.Nanoseconds()/int64(time.Millisecond))
|
||||||
}
|
}
|
||||||
if rt.levels[debugResponseStatus] {
|
if rt.levels[debugResponseStatus] {
|
||||||
glog.Infof("Response Status: %s in %d milliseconds", reqInfo.ResponseStatus, reqInfo.Duration.Nanoseconds()/int64(time.Millisecond))
|
klog.Infof("Response Status: %s in %d milliseconds", reqInfo.ResponseStatus, reqInfo.Duration.Nanoseconds()/int64(time.Millisecond))
|
||||||
}
|
}
|
||||||
if rt.levels[debugResponseHeaders] {
|
if rt.levels[debugResponseHeaders] {
|
||||||
glog.Infof("Response Headers:")
|
klog.Infof("Response Headers:")
|
||||||
for key, values := range reqInfo.ResponseHeaders {
|
for key, values := range reqInfo.ResponseHeaders {
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
glog.Infof(" %s: %s", key, value)
|
klog.Infof(" %s: %s", key, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -106,10 +106,6 @@
|
|||||||
"ImportPath": "github.com/gogo/protobuf/vanity/command",
|
"ImportPath": "github.com/gogo/protobuf/vanity/command",
|
||||||
"Rev": "342cbe0a04158f6dcb03ca0079991a51a4248c02"
|
"Rev": "342cbe0a04158f6dcb03ca0079991a51a4248c02"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/golang/glog",
|
|
||||||
"Rev": "44145f04b68cf362d9c4df2182967c2275eaefed"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/spf13/pflag",
|
"ImportPath": "github.com/spf13/pflag",
|
||||||
"Rev": "583c0c0531f06d5278b7d917446061adc344b5cd"
|
"Rev": "583c0c0531f06d5278b7d917446061adc344b5cd"
|
||||||
@@ -124,43 +120,47 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "k8s.io/gengo/args",
|
"ImportPath": "k8s.io/gengo/args",
|
||||||
"Rev": "fdcf9f9480fdd5bf2b3c3df9bf4ecd22b25b87e2"
|
"Rev": "51747d6e00da1fc578d5a333a93bb2abcbce7a95"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators",
|
"ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators",
|
||||||
"Rev": "fdcf9f9480fdd5bf2b3c3df9bf4ecd22b25b87e2"
|
"Rev": "51747d6e00da1fc578d5a333a93bb2abcbce7a95"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "k8s.io/gengo/examples/defaulter-gen/generators",
|
"ImportPath": "k8s.io/gengo/examples/defaulter-gen/generators",
|
||||||
"Rev": "fdcf9f9480fdd5bf2b3c3df9bf4ecd22b25b87e2"
|
"Rev": "51747d6e00da1fc578d5a333a93bb2abcbce7a95"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "k8s.io/gengo/examples/import-boss/generators",
|
"ImportPath": "k8s.io/gengo/examples/import-boss/generators",
|
||||||
"Rev": "fdcf9f9480fdd5bf2b3c3df9bf4ecd22b25b87e2"
|
"Rev": "51747d6e00da1fc578d5a333a93bb2abcbce7a95"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "k8s.io/gengo/examples/set-gen/generators",
|
"ImportPath": "k8s.io/gengo/examples/set-gen/generators",
|
||||||
"Rev": "fdcf9f9480fdd5bf2b3c3df9bf4ecd22b25b87e2"
|
"Rev": "51747d6e00da1fc578d5a333a93bb2abcbce7a95"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "k8s.io/gengo/examples/set-gen/sets",
|
"ImportPath": "k8s.io/gengo/examples/set-gen/sets",
|
||||||
"Rev": "fdcf9f9480fdd5bf2b3c3df9bf4ecd22b25b87e2"
|
"Rev": "51747d6e00da1fc578d5a333a93bb2abcbce7a95"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "k8s.io/gengo/generator",
|
"ImportPath": "k8s.io/gengo/generator",
|
||||||
"Rev": "fdcf9f9480fdd5bf2b3c3df9bf4ecd22b25b87e2"
|
"Rev": "51747d6e00da1fc578d5a333a93bb2abcbce7a95"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "k8s.io/gengo/namer",
|
"ImportPath": "k8s.io/gengo/namer",
|
||||||
"Rev": "fdcf9f9480fdd5bf2b3c3df9bf4ecd22b25b87e2"
|
"Rev": "51747d6e00da1fc578d5a333a93bb2abcbce7a95"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "k8s.io/gengo/parser",
|
"ImportPath": "k8s.io/gengo/parser",
|
||||||
"Rev": "fdcf9f9480fdd5bf2b3c3df9bf4ecd22b25b87e2"
|
"Rev": "51747d6e00da1fc578d5a333a93bb2abcbce7a95"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "k8s.io/gengo/types",
|
"ImportPath": "k8s.io/gengo/types",
|
||||||
"Rev": "fdcf9f9480fdd5bf2b3c3df9bf4ecd22b25b87e2"
|
"Rev": "51747d6e00da1fc578d5a333a93bb2abcbce7a95"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ImportPath": "k8s.io/klog",
|
||||||
|
"Rev": "8139d8cb77af419532b33dfa7dd09fbc5f1d344f"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -32,7 +32,7 @@ import (
|
|||||||
"k8s.io/gengo/namer"
|
"k8s.io/gengo/namer"
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NameSystems returns the name system used by the generators in this package.
|
// NameSystems returns the name system used by the generators in this package.
|
||||||
@@ -318,12 +318,12 @@ func applyGroupOverrides(universe types.Universe, customArgs *clientgenargs.Cust
|
|||||||
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
||||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed loading boilerplate: %v", err)
|
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
customArgs, ok := arguments.CustomArgs.(*clientgenargs.CustomArgs)
|
customArgs, ok := arguments.CustomArgs.(*clientgenargs.CustomArgs)
|
||||||
if !ok {
|
if !ok {
|
||||||
glog.Fatalf("cannot convert arguments.CustomArgs to clientgenargs.CustomArgs")
|
klog.Fatalf("cannot convert arguments.CustomArgs to clientgenargs.CustomArgs")
|
||||||
}
|
}
|
||||||
includedTypesOverrides := customArgs.IncludedTypesOverrides
|
includedTypesOverrides := customArgs.IncludedTypesOverrides
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -21,9 +21,9 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"k8s.io/gengo/args"
|
"k8s.io/gengo/args"
|
||||||
|
"k8s.io/klog"
|
||||||
|
|
||||||
generatorargs "k8s.io/code-generator/cmd/client-gen/args"
|
generatorargs "k8s.io/code-generator/cmd/client-gen/args"
|
||||||
"k8s.io/code-generator/cmd/client-gen/generators"
|
"k8s.io/code-generator/cmd/client-gen/generators"
|
||||||
@@ -31,6 +31,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
klog.InitFlags(nil)
|
||||||
genericArgs, customArgs := generatorargs.NewDefaults()
|
genericArgs, customArgs := generatorargs.NewDefaults()
|
||||||
|
|
||||||
// Override defaults.
|
// Override defaults.
|
||||||
@@ -52,7 +53,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := generatorargs.Validate(genericArgs); err != nil {
|
if err := generatorargs.Validate(genericArgs); err != nil {
|
||||||
glog.Fatalf("Error: %v", err)
|
klog.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := genericArgs.Execute(
|
if err := genericArgs.Execute(
|
||||||
@@ -60,6 +61,6 @@ func main() {
|
|||||||
generators.DefaultNameSystem(),
|
generators.DefaultNameSystem(),
|
||||||
generators.Packages,
|
generators.Packages,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
glog.Fatalf("Error: %v", err)
|
klog.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-33
@@ -29,7 +29,7 @@ import (
|
|||||||
"k8s.io/gengo/namer"
|
"k8s.io/gengo/namer"
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
conversionargs "k8s.io/code-generator/cmd/conversion-gen/args"
|
conversionargs "k8s.io/code-generator/cmd/conversion-gen/args"
|
||||||
)
|
)
|
||||||
@@ -124,10 +124,10 @@ type conversionFuncMap map[conversionPair]*types.Type
|
|||||||
// Returns all manually-defined conversion functions in the package.
|
// Returns all manually-defined conversion functions in the package.
|
||||||
func getManualConversionFunctions(context *generator.Context, pkg *types.Package, manualMap conversionFuncMap) {
|
func getManualConversionFunctions(context *generator.Context, pkg *types.Package, manualMap conversionFuncMap) {
|
||||||
if pkg == nil {
|
if pkg == nil {
|
||||||
glog.Warningf("Skipping nil package passed to getManualConversionFunctions")
|
klog.Warningf("Skipping nil package passed to getManualConversionFunctions")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
glog.V(5).Infof("Scanning for conversion functions in %v", pkg.Name)
|
klog.V(5).Infof("Scanning for conversion functions in %v", pkg.Name)
|
||||||
|
|
||||||
scopeName := types.Ref(conversionPackagePath, "Scope").Name
|
scopeName := types.Ref(conversionPackagePath, "Scope").Name
|
||||||
errorName := types.Ref("", "error").Name
|
errorName := types.Ref("", "error").Name
|
||||||
@@ -136,34 +136,34 @@ func getManualConversionFunctions(context *generator.Context, pkg *types.Package
|
|||||||
|
|
||||||
for _, f := range pkg.Functions {
|
for _, f := range pkg.Functions {
|
||||||
if f.Underlying == nil || f.Underlying.Kind != types.Func {
|
if f.Underlying == nil || f.Underlying.Kind != types.Func {
|
||||||
glog.Errorf("Malformed function: %#v", f)
|
klog.Errorf("Malformed function: %#v", f)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if f.Underlying.Signature == nil {
|
if f.Underlying.Signature == nil {
|
||||||
glog.Errorf("Function without signature: %#v", f)
|
klog.Errorf("Function without signature: %#v", f)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
glog.V(8).Infof("Considering function %s", f.Name)
|
klog.V(8).Infof("Considering function %s", f.Name)
|
||||||
signature := f.Underlying.Signature
|
signature := f.Underlying.Signature
|
||||||
// Check whether the function is conversion function.
|
// Check whether the function is conversion function.
|
||||||
// Note that all of them have signature:
|
// Note that all of them have signature:
|
||||||
// func Convert_inType_To_outType(inType, outType, conversion.Scope) error
|
// func Convert_inType_To_outType(inType, outType, conversion.Scope) error
|
||||||
if signature.Receiver != nil {
|
if signature.Receiver != nil {
|
||||||
glog.V(8).Infof("%s has a receiver", f.Name)
|
klog.V(8).Infof("%s has a receiver", f.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(signature.Parameters) != 3 || signature.Parameters[2].Name != scopeName {
|
if len(signature.Parameters) != 3 || signature.Parameters[2].Name != scopeName {
|
||||||
glog.V(8).Infof("%s has wrong parameters", f.Name)
|
klog.V(8).Infof("%s has wrong parameters", f.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(signature.Results) != 1 || signature.Results[0].Name != errorName {
|
if len(signature.Results) != 1 || signature.Results[0].Name != errorName {
|
||||||
glog.V(8).Infof("%s has wrong results", f.Name)
|
klog.V(8).Infof("%s has wrong results", f.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
inType := signature.Parameters[0]
|
inType := signature.Parameters[0]
|
||||||
outType := signature.Parameters[1]
|
outType := signature.Parameters[1]
|
||||||
if inType.Kind != types.Pointer || outType.Kind != types.Pointer {
|
if inType.Kind != types.Pointer || outType.Kind != types.Pointer {
|
||||||
glog.V(8).Infof("%s has wrong parameter types", f.Name)
|
klog.V(8).Infof("%s has wrong parameter types", f.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Now check if the name satisfies the convention.
|
// Now check if the name satisfies the convention.
|
||||||
@@ -171,7 +171,7 @@ func getManualConversionFunctions(context *generator.Context, pkg *types.Package
|
|||||||
args := argsFromType(inType.Elem, outType.Elem)
|
args := argsFromType(inType.Elem, outType.Elem)
|
||||||
sw.Do("Convert_$.inType|public$_To_$.outType|public$", args)
|
sw.Do("Convert_$.inType|public$_To_$.outType|public$", args)
|
||||||
if f.Name.Name == buffer.String() {
|
if f.Name.Name == buffer.String() {
|
||||||
glog.V(4).Infof("Found conversion function %s", f.Name)
|
klog.V(4).Infof("Found conversion function %s", f.Name)
|
||||||
key := conversionPair{inType.Elem, outType.Elem}
|
key := conversionPair{inType.Elem, outType.Elem}
|
||||||
// We might scan the same package twice, and that's OK.
|
// We might scan the same package twice, and that's OK.
|
||||||
if v, ok := manualMap[key]; ok && v != nil && v.Name.Package != pkg.Path {
|
if v, ok := manualMap[key]; ok && v != nil && v.Name.Package != pkg.Path {
|
||||||
@@ -181,9 +181,9 @@ func getManualConversionFunctions(context *generator.Context, pkg *types.Package
|
|||||||
} else {
|
} else {
|
||||||
// prevent user error when they don't get the correct conversion signature
|
// prevent user error when they don't get the correct conversion signature
|
||||||
if strings.HasPrefix(f.Name.Name, "Convert_") {
|
if strings.HasPrefix(f.Name.Name, "Convert_") {
|
||||||
glog.Errorf("Rename function %s %s -> %s to match expected conversion signature", f.Name.Package, f.Name.Name, buffer.String())
|
klog.Errorf("Rename function %s %s -> %s to match expected conversion signature", f.Name.Package, f.Name.Name, buffer.String())
|
||||||
}
|
}
|
||||||
glog.V(8).Infof("%s has wrong name", f.Name)
|
klog.V(8).Infof("%s has wrong name", f.Name)
|
||||||
}
|
}
|
||||||
buffer.Reset()
|
buffer.Reset()
|
||||||
}
|
}
|
||||||
@@ -192,7 +192,7 @@ func getManualConversionFunctions(context *generator.Context, pkg *types.Package
|
|||||||
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
||||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed loading boilerplate: %v", err)
|
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
packages := generator.Packages{}
|
packages := generator.Packages{}
|
||||||
@@ -220,7 +220,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
}
|
}
|
||||||
processed[i] = true
|
processed[i] = true
|
||||||
|
|
||||||
glog.V(5).Infof("considering pkg %q", i)
|
klog.V(5).Infof("considering pkg %q", i)
|
||||||
pkg := context.Universe[i]
|
pkg := context.Universe[i]
|
||||||
// typesPkg is where the versioned types are defined. Sometimes it is
|
// typesPkg is where the versioned types are defined. Sometimes it is
|
||||||
// different from pkg. For example, kubernetes core/v1 types are defined
|
// different from pkg. For example, kubernetes core/v1 types are defined
|
||||||
@@ -239,9 +239,9 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
// in their doc.go file.
|
// in their doc.go file.
|
||||||
peerPkgs := extractTag(pkg.Comments)
|
peerPkgs := extractTag(pkg.Comments)
|
||||||
if peerPkgs != nil {
|
if peerPkgs != nil {
|
||||||
glog.V(5).Infof(" tags: %q", peerPkgs)
|
klog.V(5).Infof(" tags: %q", peerPkgs)
|
||||||
} else {
|
} else {
|
||||||
glog.V(5).Infof(" no tag")
|
klog.V(5).Infof(" no tag")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
skipUnsafe := false
|
skipUnsafe := false
|
||||||
@@ -255,14 +255,14 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
externalTypesValues := extractExternalTypesTag(pkg.Comments)
|
externalTypesValues := extractExternalTypesTag(pkg.Comments)
|
||||||
if externalTypesValues != nil {
|
if externalTypesValues != nil {
|
||||||
if len(externalTypesValues) != 1 {
|
if len(externalTypesValues) != 1 {
|
||||||
glog.Fatalf(" expect only one value for %q tag, got: %q", externalTypesTagName, externalTypesValues)
|
klog.Fatalf(" expect only one value for %q tag, got: %q", externalTypesTagName, externalTypesValues)
|
||||||
}
|
}
|
||||||
externalTypes := externalTypesValues[0]
|
externalTypes := externalTypesValues[0]
|
||||||
glog.V(5).Infof(" external types tags: %q", externalTypes)
|
klog.V(5).Infof(" external types tags: %q", externalTypes)
|
||||||
var err error
|
var err error
|
||||||
typesPkg, err = context.AddDirectory(externalTypes)
|
typesPkg, err = context.AddDirectory(externalTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("cannot import package %s", externalTypes)
|
klog.Fatalf("cannot import package %s", externalTypes)
|
||||||
}
|
}
|
||||||
// update context.Order to the latest context.Universe
|
// update context.Order to the latest context.Universe
|
||||||
orderer := namer.Orderer{Namer: namer.NewPublicNamer(1)}
|
orderer := namer.Orderer{Namer: namer.NewPublicNamer(1)}
|
||||||
@@ -291,7 +291,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
context.AddDir(pp)
|
context.AddDir(pp)
|
||||||
p := context.Universe[pp]
|
p := context.Universe[pp]
|
||||||
if nil == p {
|
if nil == p {
|
||||||
glog.Fatalf("failed to find pkg: %s", pp)
|
klog.Fatalf("failed to find pkg: %s", pp)
|
||||||
}
|
}
|
||||||
getManualConversionFunctions(context, p, manualConversions)
|
getManualConversionFunctions(context, p, manualConversions)
|
||||||
}
|
}
|
||||||
@@ -335,7 +335,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
// from being a candidate for unsafe conversion
|
// from being a candidate for unsafe conversion
|
||||||
for k, v := range manualConversions {
|
for k, v := range manualConversions {
|
||||||
if isCopyOnly(v.CommentLines) {
|
if isCopyOnly(v.CommentLines) {
|
||||||
glog.V(5).Infof("Conversion function %s will not block memory copy because it is copy-only", v.Name)
|
klog.V(5).Infof("Conversion function %s will not block memory copy because it is copy-only", v.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// this type should be excluded from all equivalence, because the converter must be called.
|
// this type should be excluded from all equivalence, because the converter must be called.
|
||||||
@@ -518,9 +518,9 @@ func (g *genConversion) convertibleOnlyWithinPackage(inType, outType *types.Type
|
|||||||
tagvals := extractTag(t.CommentLines)
|
tagvals := extractTag(t.CommentLines)
|
||||||
if tagvals != nil {
|
if tagvals != nil {
|
||||||
if tagvals[0] != "false" {
|
if tagvals[0] != "false" {
|
||||||
glog.Fatalf("Type %v: unsupported %s value: %q", t, tagName, tagvals[0])
|
klog.Fatalf("Type %v: unsupported %s value: %q", t, tagName, tagvals[0])
|
||||||
}
|
}
|
||||||
glog.V(5).Infof("type %v requests no conversion generation, skipping", t)
|
klog.V(5).Infof("type %v requests no conversion generation, skipping", t)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// TODO: Consider generating functions for other kinds too.
|
// TODO: Consider generating functions for other kinds too.
|
||||||
@@ -582,10 +582,10 @@ func (g *genConversion) preexists(inType, outType *types.Type) (*types.Type, boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *genConversion) Init(c *generator.Context, w io.Writer) error {
|
func (g *genConversion) Init(c *generator.Context, w io.Writer) error {
|
||||||
if glog.V(5) {
|
if klog.V(5) {
|
||||||
if m, ok := g.useUnsafe.(equalMemoryTypes); ok {
|
if m, ok := g.useUnsafe.(equalMemoryTypes); ok {
|
||||||
var result []string
|
var result []string
|
||||||
glog.Infof("All objects without identical memory layout:")
|
klog.Infof("All objects without identical memory layout:")
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
if v {
|
if v {
|
||||||
continue
|
continue
|
||||||
@@ -594,7 +594,7 @@ func (g *genConversion) Init(c *generator.Context, w io.Writer) error {
|
|||||||
}
|
}
|
||||||
sort.Strings(result)
|
sort.Strings(result)
|
||||||
for _, s := range result {
|
for _, s := range result {
|
||||||
glog.Infof(s)
|
klog.Infof(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -643,7 +643,7 @@ func (g *genConversion) Init(c *generator.Context, w io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *genConversion) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
func (g *genConversion) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||||
glog.V(5).Infof("generating for type %v", t)
|
klog.V(5).Infof("generating for type %v", t)
|
||||||
peerType := getPeerTypeFor(c, t, g.peerPackages)
|
peerType := getPeerTypeFor(c, t, g.peerPackages)
|
||||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||||
g.generateConversion(t, peerType, sw)
|
g.generateConversion(t, peerType, sw)
|
||||||
@@ -664,10 +664,10 @@ func (g *genConversion) generateConversion(inType, outType *types.Type, sw *gene
|
|||||||
// There is a public manual Conversion method: use it.
|
// There is a public manual Conversion method: use it.
|
||||||
} else if skipped := g.skippedFields[inType]; len(skipped) != 0 {
|
} else if skipped := g.skippedFields[inType]; len(skipped) != 0 {
|
||||||
// The inType had some fields we could not generate.
|
// The inType had some fields we could not generate.
|
||||||
glog.Errorf("Warning: could not find nor generate a final Conversion function for %v -> %v", inType, outType)
|
klog.Errorf("Warning: could not find nor generate a final Conversion function for %v -> %v", inType, outType)
|
||||||
glog.Errorf(" the following fields need manual conversion:")
|
klog.Errorf(" the following fields need manual conversion:")
|
||||||
for _, f := range skipped {
|
for _, f := range skipped {
|
||||||
glog.Errorf(" - %v", f)
|
klog.Errorf(" - %v", f)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Emit a public conversion function.
|
// Emit a public conversion function.
|
||||||
@@ -682,7 +682,7 @@ func (g *genConversion) generateConversion(inType, outType *types.Type, sw *gene
|
|||||||
// at any nesting level. This makes the autogenerator easy to understand, and
|
// at any nesting level. This makes the autogenerator easy to understand, and
|
||||||
// the compiler shouldn't care.
|
// the compiler shouldn't care.
|
||||||
func (g *genConversion) generateFor(inType, outType *types.Type, sw *generator.SnippetWriter) {
|
func (g *genConversion) generateFor(inType, outType *types.Type, sw *generator.SnippetWriter) {
|
||||||
glog.V(5).Infof("generating %v -> %v", inType, outType)
|
klog.V(5).Infof("generating %v -> %v", inType, outType)
|
||||||
var f func(*types.Type, *types.Type, *generator.SnippetWriter)
|
var f func(*types.Type, *types.Type, *generator.SnippetWriter)
|
||||||
|
|
||||||
switch inType.Kind {
|
switch inType.Kind {
|
||||||
@@ -853,7 +853,7 @@ func (g *genConversion) doStruct(inType, outType *types.Type, sw *generator.Snip
|
|||||||
sw.Do("}\n", nil)
|
sw.Do("}\n", nil)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
glog.V(5).Infof("Skipped function %s because it is copy-only and we can use direct assignment", function.Name)
|
klog.V(5).Infof("Skipped function %s because it is copy-only and we can use direct assignment", function.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we can't auto-convert, punt before we emit any code.
|
// If we can't auto-convert, punt before we emit any code.
|
||||||
|
|||||||
+5
-4
@@ -38,9 +38,9 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"k8s.io/gengo/args"
|
"k8s.io/gengo/args"
|
||||||
|
"k8s.io/klog"
|
||||||
|
|
||||||
generatorargs "k8s.io/code-generator/cmd/conversion-gen/args"
|
generatorargs "k8s.io/code-generator/cmd/conversion-gen/args"
|
||||||
"k8s.io/code-generator/cmd/conversion-gen/generators"
|
"k8s.io/code-generator/cmd/conversion-gen/generators"
|
||||||
@@ -48,6 +48,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
klog.InitFlags(nil)
|
||||||
genericArgs, customArgs := generatorargs.NewDefaults()
|
genericArgs, customArgs := generatorargs.NewDefaults()
|
||||||
|
|
||||||
// Override defaults.
|
// Override defaults.
|
||||||
@@ -61,7 +62,7 @@ func main() {
|
|||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
|
|
||||||
if err := generatorargs.Validate(genericArgs); err != nil {
|
if err := generatorargs.Validate(genericArgs); err != nil {
|
||||||
glog.Fatalf("Error: %v", err)
|
klog.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run it.
|
// Run it.
|
||||||
@@ -70,7 +71,7 @@ func main() {
|
|||||||
generators.DefaultNameSystem(),
|
generators.DefaultNameSystem(),
|
||||||
generators.Packages,
|
generators.Packages,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
glog.Fatalf("Error: %v", err)
|
klog.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
glog.V(2).Info("Completed successfully.")
|
klog.V(2).Info("Completed successfully.")
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -46,16 +46,17 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"k8s.io/gengo/args"
|
"k8s.io/gengo/args"
|
||||||
"k8s.io/gengo/examples/deepcopy-gen/generators"
|
"k8s.io/gengo/examples/deepcopy-gen/generators"
|
||||||
|
"k8s.io/klog"
|
||||||
|
|
||||||
generatorargs "k8s.io/code-generator/cmd/deepcopy-gen/args"
|
generatorargs "k8s.io/code-generator/cmd/deepcopy-gen/args"
|
||||||
"k8s.io/code-generator/pkg/util"
|
"k8s.io/code-generator/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
klog.InitFlags(nil)
|
||||||
genericArgs, customArgs := generatorargs.NewDefaults()
|
genericArgs, customArgs := generatorargs.NewDefaults()
|
||||||
|
|
||||||
// Override defaults.
|
// Override defaults.
|
||||||
@@ -69,7 +70,7 @@ func main() {
|
|||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
|
|
||||||
if err := generatorargs.Validate(genericArgs); err != nil {
|
if err := generatorargs.Validate(genericArgs); err != nil {
|
||||||
glog.Fatalf("Error: %v", err)
|
klog.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run it.
|
// Run it.
|
||||||
@@ -78,7 +79,7 @@ func main() {
|
|||||||
generators.DefaultNameSystem(),
|
generators.DefaultNameSystem(),
|
||||||
generators.Packages,
|
generators.Packages,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
glog.Fatalf("Error: %v", err)
|
klog.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
glog.V(2).Info("Completed successfully.")
|
klog.V(2).Info("Completed successfully.")
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -45,16 +45,17 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"k8s.io/gengo/args"
|
"k8s.io/gengo/args"
|
||||||
"k8s.io/gengo/examples/defaulter-gen/generators"
|
"k8s.io/gengo/examples/defaulter-gen/generators"
|
||||||
|
"k8s.io/klog"
|
||||||
|
|
||||||
generatorargs "k8s.io/code-generator/cmd/defaulter-gen/args"
|
generatorargs "k8s.io/code-generator/cmd/defaulter-gen/args"
|
||||||
"k8s.io/code-generator/pkg/util"
|
"k8s.io/code-generator/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
klog.InitFlags(nil)
|
||||||
genericArgs, customArgs := generatorargs.NewDefaults()
|
genericArgs, customArgs := generatorargs.NewDefaults()
|
||||||
|
|
||||||
// Override defaults.
|
// Override defaults.
|
||||||
@@ -68,7 +69,7 @@ func main() {
|
|||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
|
|
||||||
if err := generatorargs.Validate(genericArgs); err != nil {
|
if err := generatorargs.Validate(genericArgs); err != nil {
|
||||||
glog.Fatalf("Error: %v", err)
|
klog.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run it.
|
// Run it.
|
||||||
@@ -77,7 +78,7 @@ func main() {
|
|||||||
generators.DefaultNameSystem(),
|
generators.DefaultNameSystem(),
|
||||||
generators.Packages,
|
generators.Packages,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
glog.Fatalf("Error: %v", err)
|
klog.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
glog.V(2).Info("Completed successfully.")
|
klog.V(2).Info("Completed successfully.")
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -25,7 +25,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
"k8s.io/gengo/generator"
|
"k8s.io/gengo/generator"
|
||||||
"k8s.io/gengo/namer"
|
"k8s.io/gengo/namer"
|
||||||
@@ -85,7 +85,7 @@ func (g *genProtoIDL) Filter(c *generator.Context, t *types.Type) bool {
|
|||||||
// Type specified "true".
|
// Type specified "true".
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
glog.Fatalf(`Comment tag "protobuf" must be true or false, found: %q`, tagVals[0])
|
klog.Fatalf(`Comment tag "protobuf" must be true or false, found: %q`, tagVals[0])
|
||||||
}
|
}
|
||||||
if !g.generateAll {
|
if !g.generateAll {
|
||||||
// We're not generating everything.
|
// We're not generating everything.
|
||||||
|
|||||||
+2
-2
@@ -17,8 +17,8 @@ limitations under the License.
|
|||||||
package protobuf
|
package protobuf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/golang/glog"
|
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// extractBoolTagOrDie gets the comment-tags for the key and asserts that, if
|
// extractBoolTagOrDie gets the comment-tags for the key and asserts that, if
|
||||||
@@ -27,7 +27,7 @@ import (
|
|||||||
func extractBoolTagOrDie(key string, lines []string) bool {
|
func extractBoolTagOrDie(key string, lines []string) bool {
|
||||||
val, err := types.ExtractSingleBoolCommentTag("+", key, false, lines)
|
val, err := types.ExtractSingleBoolCommentTag("+", key, false, lines)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal(err)
|
klog.Fatal(err)
|
||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -63,10 +63,11 @@ import (
|
|||||||
"k8s.io/gengo/args"
|
"k8s.io/gengo/args"
|
||||||
"k8s.io/gengo/examples/import-boss/generators"
|
"k8s.io/gengo/examples/import-boss/generators"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
klog.InitFlags(nil)
|
||||||
arguments := args.Default()
|
arguments := args.Default()
|
||||||
|
|
||||||
// Override defaults.
|
// Override defaults.
|
||||||
@@ -82,8 +83,8 @@ func main() {
|
|||||||
generators.DefaultNameSystem(),
|
generators.DefaultNameSystem(),
|
||||||
generators.Packages,
|
generators.Packages,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
glog.Errorf("Error: %v", err)
|
klog.Errorf("Error: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
glog.V(2).Info("Completed successfully.")
|
klog.V(2).Info("Completed successfully.")
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -25,7 +25,7 @@ import (
|
|||||||
"k8s.io/gengo/namer"
|
"k8s.io/gengo/namer"
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// factoryGenerator produces a file of listers for a given GroupVersion and
|
// factoryGenerator produces a file of listers for a given GroupVersion and
|
||||||
@@ -65,7 +65,7 @@ func (g *factoryGenerator) Imports(c *generator.Context) (imports []string) {
|
|||||||
func (g *factoryGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
func (g *factoryGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||||
sw := generator.NewSnippetWriter(w, c, "{{", "}}")
|
sw := generator.NewSnippetWriter(w, c, "{{", "}}")
|
||||||
|
|
||||||
glog.V(5).Infof("processing type %v", t)
|
klog.V(5).Infof("processing type %v", t)
|
||||||
|
|
||||||
gvInterfaces := make(map[string]*types.Type)
|
gvInterfaces := make(map[string]*types.Type)
|
||||||
gvNewFuncs := make(map[string]*types.Type)
|
gvNewFuncs := make(map[string]*types.Type)
|
||||||
|
|||||||
+2
-2
@@ -23,7 +23,7 @@ import (
|
|||||||
"k8s.io/gengo/namer"
|
"k8s.io/gengo/namer"
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// factoryInterfaceGenerator produces a file of interfaces used to break a dependency cycle for
|
// factoryInterfaceGenerator produces a file of interfaces used to break a dependency cycle for
|
||||||
@@ -60,7 +60,7 @@ func (g *factoryInterfaceGenerator) Imports(c *generator.Context) (imports []str
|
|||||||
func (g *factoryInterfaceGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
func (g *factoryInterfaceGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||||
sw := generator.NewSnippetWriter(w, c, "{{", "}}")
|
sw := generator.NewSnippetWriter(w, c, "{{", "}}")
|
||||||
|
|
||||||
glog.V(5).Infof("processing type %v", t)
|
klog.V(5).Infof("processing type %v", t)
|
||||||
|
|
||||||
m := map[string]interface{}{
|
m := map[string]interface{}{
|
||||||
"cacheSharedIndexInformer": c.Universe.Type(cacheSharedIndexInformer),
|
"cacheSharedIndexInformer": c.Universe.Type(cacheSharedIndexInformer),
|
||||||
|
|||||||
+2
-2
@@ -28,7 +28,7 @@ import (
|
|||||||
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
||||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// informerGenerator produces a file of listers for a given GroupVersion and
|
// informerGenerator produces a file of listers for a given GroupVersion and
|
||||||
@@ -66,7 +66,7 @@ func (g *informerGenerator) Imports(c *generator.Context) (imports []string) {
|
|||||||
func (g *informerGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
func (g *informerGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||||
|
|
||||||
glog.V(5).Infof("processing type %v", t)
|
klog.V(5).Infof("processing type %v", t)
|
||||||
|
|
||||||
listerPackage := fmt.Sprintf("%s/%s/%s", g.listersPackage, g.groupPkgName, strings.ToLower(g.groupVersion.Version.NonEmpty()))
|
listerPackage := fmt.Sprintf("%s/%s/%s", g.listersPackage, g.groupPkgName, strings.ToLower(g.groupVersion.Version.NonEmpty()))
|
||||||
clientSetInterface := c.Universe.Type(types.Name{Package: g.clientSetPackage, Name: "Interface"})
|
clientSetInterface := c.Universe.Type(types.Name{Package: g.clientSetPackage, Name: "Interface"})
|
||||||
|
|||||||
+5
-5
@@ -22,11 +22,11 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"k8s.io/gengo/args"
|
"k8s.io/gengo/args"
|
||||||
"k8s.io/gengo/generator"
|
"k8s.io/gengo/generator"
|
||||||
"k8s.io/gengo/namer"
|
"k8s.io/gengo/namer"
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
"k8s.io/klog"
|
||||||
|
|
||||||
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
||||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||||
@@ -102,12 +102,12 @@ func vendorless(p string) string {
|
|||||||
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
||||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed loading boilerplate: %v", err)
|
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
customArgs, ok := arguments.CustomArgs.(*informergenargs.CustomArgs)
|
customArgs, ok := arguments.CustomArgs.(*informergenargs.CustomArgs)
|
||||||
if !ok {
|
if !ok {
|
||||||
glog.Fatalf("Wrong CustomArgs type: %T", arguments.CustomArgs)
|
klog.Fatalf("Wrong CustomArgs type: %T", arguments.CustomArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
internalVersionPackagePath := filepath.Join(arguments.OutputPackagePath)
|
internalVersionPackagePath := filepath.Join(arguments.OutputPackagePath)
|
||||||
@@ -128,7 +128,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
|
|
||||||
objectMeta, internal, err := objectMetaForPackage(p)
|
objectMeta, internal, err := objectMetaForPackage(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal(err)
|
klog.Fatal(err)
|
||||||
}
|
}
|
||||||
if objectMeta == nil {
|
if objectMeta == nil {
|
||||||
// no types in this package had genclient
|
// no types in this package had genclient
|
||||||
@@ -141,7 +141,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
if internal {
|
if internal {
|
||||||
lastSlash := strings.LastIndex(p.Path, "/")
|
lastSlash := strings.LastIndex(p.Path, "/")
|
||||||
if lastSlash == -1 {
|
if lastSlash == -1 {
|
||||||
glog.Fatalf("error constructing internal group version for package %q", p.Path)
|
klog.Fatalf("error constructing internal group version for package %q", p.Path)
|
||||||
}
|
}
|
||||||
gv.Group = clientgentypes.Group(p.Path[lastSlash+1:])
|
gv.Group = clientgentypes.Group(p.Path[lastSlash+1:])
|
||||||
targetGroupVersions = internalGroupVersions
|
targetGroupVersions = internalGroupVersions
|
||||||
|
|||||||
+2
-2
@@ -17,8 +17,8 @@ limitations under the License.
|
|||||||
package generators
|
package generators
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/golang/glog"
|
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// extractBoolTagOrDie gets the comment-tags for the key and asserts that, if
|
// extractBoolTagOrDie gets the comment-tags for the key and asserts that, if
|
||||||
@@ -27,7 +27,7 @@ import (
|
|||||||
func extractBoolTagOrDie(key string, lines []string) bool {
|
func extractBoolTagOrDie(key string, lines []string) bool {
|
||||||
val, err := types.ExtractSingleBoolCommentTag("+", key, false, lines)
|
val, err := types.ExtractSingleBoolCommentTag("+", key, false, lines)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal(err)
|
klog.Fatal(err)
|
||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -20,16 +20,17 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"k8s.io/code-generator/cmd/informer-gen/generators"
|
"k8s.io/code-generator/cmd/informer-gen/generators"
|
||||||
"k8s.io/code-generator/pkg/util"
|
"k8s.io/code-generator/pkg/util"
|
||||||
"k8s.io/gengo/args"
|
"k8s.io/gengo/args"
|
||||||
|
"k8s.io/klog"
|
||||||
|
|
||||||
generatorargs "k8s.io/code-generator/cmd/informer-gen/args"
|
generatorargs "k8s.io/code-generator/cmd/informer-gen/args"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
klog.InitFlags(nil)
|
||||||
genericArgs, customArgs := generatorargs.NewDefaults()
|
genericArgs, customArgs := generatorargs.NewDefaults()
|
||||||
|
|
||||||
// Override defaults.
|
// Override defaults.
|
||||||
@@ -47,7 +48,7 @@ func main() {
|
|||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
|
|
||||||
if err := generatorargs.Validate(genericArgs); err != nil {
|
if err := generatorargs.Validate(genericArgs); err != nil {
|
||||||
glog.Fatalf("Error: %v", err)
|
klog.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run it.
|
// Run it.
|
||||||
@@ -56,7 +57,7 @@ func main() {
|
|||||||
generators.DefaultNameSystem(),
|
generators.DefaultNameSystem(),
|
||||||
generators.Packages,
|
generators.Packages,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
glog.Fatalf("Error: %v", err)
|
klog.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
glog.V(2).Info("Completed successfully.")
|
klog.V(2).Info("Completed successfully.")
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -30,7 +30,7 @@ import (
|
|||||||
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
||||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NameSystems returns the name system used by the generators in this package.
|
// NameSystems returns the name system used by the generators in this package.
|
||||||
@@ -66,7 +66,7 @@ func DefaultNameSystem() string {
|
|||||||
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
||||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed loading boilerplate: %v", err)
|
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var packageList generator.Packages
|
var packageList generator.Packages
|
||||||
@@ -75,7 +75,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
|
|
||||||
objectMeta, internal, err := objectMetaForPackage(p)
|
objectMeta, internal, err := objectMetaForPackage(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal(err)
|
klog.Fatal(err)
|
||||||
}
|
}
|
||||||
if objectMeta == nil {
|
if objectMeta == nil {
|
||||||
// no types in this package had genclient
|
// no types in this package had genclient
|
||||||
@@ -88,7 +88,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
if internal {
|
if internal {
|
||||||
lastSlash := strings.LastIndex(p.Path, "/")
|
lastSlash := strings.LastIndex(p.Path, "/")
|
||||||
if lastSlash == -1 {
|
if lastSlash == -1 {
|
||||||
glog.Fatalf("error constructing internal group version for package %q", p.Path)
|
klog.Fatalf("error constructing internal group version for package %q", p.Path)
|
||||||
}
|
}
|
||||||
gv.Group = clientgentypes.Group(p.Path[lastSlash+1:])
|
gv.Group = clientgentypes.Group(p.Path[lastSlash+1:])
|
||||||
internalGVPkg = p.Path
|
internalGVPkg = p.Path
|
||||||
@@ -223,7 +223,7 @@ func (g *listerGenerator) Imports(c *generator.Context) (imports []string) {
|
|||||||
func (g *listerGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
func (g *listerGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||||
|
|
||||||
glog.V(5).Infof("processing type %v", t)
|
klog.V(5).Infof("processing type %v", t)
|
||||||
m := map[string]interface{}{
|
m := map[string]interface{}{
|
||||||
"Resource": c.Universe.Function(types.Name{Package: t.Name.Package, Name: "Resource"}),
|
"Resource": c.Universe.Function(types.Name{Package: t.Name.Package, Name: "Resource"}),
|
||||||
"type": t,
|
"type": t,
|
||||||
|
|||||||
+2
-2
@@ -17,8 +17,8 @@ limitations under the License.
|
|||||||
package generators
|
package generators
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/golang/glog"
|
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// extractBoolTagOrDie gets the comment-tags for the key and asserts that, if
|
// extractBoolTagOrDie gets the comment-tags for the key and asserts that, if
|
||||||
@@ -27,7 +27,7 @@ import (
|
|||||||
func extractBoolTagOrDie(key string, lines []string) bool {
|
func extractBoolTagOrDie(key string, lines []string) bool {
|
||||||
val, err := types.ExtractSingleBoolCommentTag("+", key, false, lines)
|
val, err := types.ExtractSingleBoolCommentTag("+", key, false, lines)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal(err)
|
klog.Fatal(err)
|
||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -20,16 +20,17 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"k8s.io/code-generator/cmd/lister-gen/generators"
|
"k8s.io/code-generator/cmd/lister-gen/generators"
|
||||||
"k8s.io/code-generator/pkg/util"
|
"k8s.io/code-generator/pkg/util"
|
||||||
"k8s.io/gengo/args"
|
"k8s.io/gengo/args"
|
||||||
|
"k8s.io/klog"
|
||||||
|
|
||||||
generatorargs "k8s.io/code-generator/cmd/lister-gen/args"
|
generatorargs "k8s.io/code-generator/cmd/lister-gen/args"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
klog.InitFlags(nil)
|
||||||
genericArgs, customArgs := generatorargs.NewDefaults()
|
genericArgs, customArgs := generatorargs.NewDefaults()
|
||||||
|
|
||||||
// Override defaults.
|
// Override defaults.
|
||||||
@@ -44,7 +45,7 @@ func main() {
|
|||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
|
|
||||||
if err := generatorargs.Validate(genericArgs); err != nil {
|
if err := generatorargs.Validate(genericArgs); err != nil {
|
||||||
glog.Fatalf("Error: %v", err)
|
klog.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run it.
|
// Run it.
|
||||||
@@ -53,7 +54,7 @@ func main() {
|
|||||||
generators.DefaultNameSystem(),
|
generators.DefaultNameSystem(),
|
||||||
generators.Packages,
|
generators.Packages,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
glog.Fatalf("Error: %v", err)
|
klog.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
glog.V(2).Info("Completed successfully.")
|
klog.V(2).Info("Completed successfully.")
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-9
@@ -22,7 +22,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||||
"k8s.io/gengo/args"
|
"k8s.io/gengo/args"
|
||||||
@@ -46,7 +46,7 @@ func DefaultNameSystem() string {
|
|||||||
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
||||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed loading boilerplate: %v", err)
|
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
packages := generator.Packages{}
|
packages := generator.Packages{}
|
||||||
@@ -54,27 +54,27 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
pkg := context.Universe.Package(inputDir)
|
pkg := context.Universe.Package(inputDir)
|
||||||
internal, err := isInternal(pkg)
|
internal, err := isInternal(pkg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(5).Infof("skipping the generation of %s file, due to err %v", arguments.OutputFileBaseName, err)
|
klog.V(5).Infof("skipping the generation of %s file, due to err %v", arguments.OutputFileBaseName, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if internal {
|
if internal {
|
||||||
glog.V(5).Infof("skipping the generation of %s file because %s package contains internal types, note that internal types don't have \"json\" tags", arguments.OutputFileBaseName, pkg.Name)
|
klog.V(5).Infof("skipping the generation of %s file because %s package contains internal types, note that internal types don't have \"json\" tags", arguments.OutputFileBaseName, pkg.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
registerFileName := "register.go"
|
registerFileName := "register.go"
|
||||||
searchPath := path.Join(args.DefaultSourceTree(), inputDir, registerFileName)
|
searchPath := path.Join(args.DefaultSourceTree(), inputDir, registerFileName)
|
||||||
if _, err := os.Stat(path.Join(searchPath)); err == nil {
|
if _, err := os.Stat(path.Join(searchPath)); err == nil {
|
||||||
glog.V(5).Infof("skipping the generation of %s file because %s already exists in the path %s", arguments.OutputFileBaseName, registerFileName, searchPath)
|
klog.V(5).Infof("skipping the generation of %s file because %s already exists in the path %s", arguments.OutputFileBaseName, registerFileName, searchPath)
|
||||||
continue
|
continue
|
||||||
} else if err != nil && !os.IsNotExist(err) {
|
} else if err != nil && !os.IsNotExist(err) {
|
||||||
glog.Fatalf("an error %v has occurred while checking if %s exists", err, registerFileName)
|
klog.Fatalf("an error %v has occurred while checking if %s exists", err, registerFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
gv := clientgentypes.GroupVersion{}
|
gv := clientgentypes.GroupVersion{}
|
||||||
{
|
{
|
||||||
pathParts := strings.Split(pkg.Path, "/")
|
pathParts := strings.Split(pkg.Path, "/")
|
||||||
if len(pathParts) < 2 {
|
if len(pathParts) < 2 {
|
||||||
glog.Errorf("the path of the package must contain the group name and the version, path = %s", pkg.Path)
|
klog.Errorf("the path of the package must contain the group name and the version, path = %s", pkg.Path)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
gv.Group = clientgentypes.Group(pathParts[len(pathParts)-2])
|
gv.Group = clientgentypes.Group(pathParts[len(pathParts)-2])
|
||||||
@@ -84,14 +84,14 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
// extract the fully qualified API group name from it and overwrite the group inferred from the package path
|
// extract the fully qualified API group name from it and overwrite the group inferred from the package path
|
||||||
if override := types.ExtractCommentTags("+", pkg.DocComments)["groupName"]; override != nil {
|
if override := types.ExtractCommentTags("+", pkg.DocComments)["groupName"]; override != nil {
|
||||||
groupName := override[0]
|
groupName := override[0]
|
||||||
glog.V(5).Infof("overriding the group name with = %s", groupName)
|
klog.V(5).Infof("overriding the group name with = %s", groupName)
|
||||||
gv.Group = clientgentypes.Group(groupName)
|
gv.Group = clientgentypes.Group(groupName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typesToRegister := []*types.Type{}
|
typesToRegister := []*types.Type{}
|
||||||
for _, t := range pkg.Types {
|
for _, t := range pkg.Types {
|
||||||
glog.V(5).Infof("considering type = %s", t.Name.String())
|
klog.V(5).Infof("considering type = %s", t.Name.String())
|
||||||
for _, typeMember := range t.Members {
|
for _, typeMember := range t.Members {
|
||||||
if typeMember.Name == "TypeMeta" && typeMember.Embedded == true {
|
if typeMember.Name == "TypeMeta" && typeMember.Embedded == true {
|
||||||
typesToRegister = append(typesToRegister, t)
|
typesToRegister = append(typesToRegister, t)
|
||||||
|
|||||||
+5
-4
@@ -20,8 +20,8 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
"k8s.io/klog"
|
||||||
|
|
||||||
generatorargs "k8s.io/code-generator/cmd/register-gen/args"
|
generatorargs "k8s.io/code-generator/cmd/register-gen/args"
|
||||||
"k8s.io/code-generator/cmd/register-gen/generators"
|
"k8s.io/code-generator/cmd/register-gen/generators"
|
||||||
@@ -30,6 +30,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
klog.InitFlags(nil)
|
||||||
genericArgs := generatorargs.NewDefaults()
|
genericArgs := generatorargs.NewDefaults()
|
||||||
genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
||||||
genericArgs.AddFlags(pflag.CommandLine)
|
genericArgs.AddFlags(pflag.CommandLine)
|
||||||
@@ -38,7 +39,7 @@ func main() {
|
|||||||
|
|
||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
if err := generatorargs.Validate(genericArgs); err != nil {
|
if err := generatorargs.Validate(genericArgs); err != nil {
|
||||||
glog.Fatalf("Error: %v", err)
|
klog.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := genericArgs.Execute(
|
if err := genericArgs.Execute(
|
||||||
@@ -46,7 +47,7 @@ func main() {
|
|||||||
generators.DefaultNameSystem(),
|
generators.DefaultNameSystem(),
|
||||||
generators.Packages,
|
generators.Packages,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
glog.Fatalf("Error: %v", err)
|
klog.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
glog.V(2).Info("Completed successfully.")
|
klog.V(2).Info("Completed successfully.")
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -32,10 +32,11 @@ import (
|
|||||||
"k8s.io/gengo/args"
|
"k8s.io/gengo/args"
|
||||||
"k8s.io/gengo/examples/set-gen/generators"
|
"k8s.io/gengo/examples/set-gen/generators"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
klog.InitFlags(nil)
|
||||||
arguments := args.Default()
|
arguments := args.Default()
|
||||||
|
|
||||||
// Override defaults.
|
// Override defaults.
|
||||||
@@ -48,8 +49,8 @@ func main() {
|
|||||||
generators.DefaultNameSystem(),
|
generators.DefaultNameSystem(),
|
||||||
generators.Packages,
|
generators.Packages,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
glog.Errorf("Error: %v", err)
|
klog.Errorf("Error: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
glog.V(2).Info("Completed successfully.")
|
klog.V(2).Info("Completed successfully.")
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
Vendored
+30
-30
@@ -29,7 +29,7 @@ import (
|
|||||||
"k8s.io/gengo/namer"
|
"k8s.io/gengo/namer"
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CustomArgs is used tby the go2idl framework to pass args specific to this
|
// CustomArgs is used tby the go2idl framework to pass args specific to this
|
||||||
@@ -62,7 +62,7 @@ func extractTag(comments []string) *tagValue {
|
|||||||
}
|
}
|
||||||
// If there are multiple values, abort.
|
// If there are multiple values, abort.
|
||||||
if len(tagVals) > 1 {
|
if len(tagVals) > 1 {
|
||||||
glog.Fatalf("Found %d %s tags: %q", len(tagVals), tagName, tagVals)
|
klog.Fatalf("Found %d %s tags: %q", len(tagVals), tagName, tagVals)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we got here we are returning something.
|
// If we got here we are returning something.
|
||||||
@@ -89,7 +89,7 @@ func extractTag(comments []string) *tagValue {
|
|||||||
tag.register = true
|
tag.register = true
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
glog.Fatalf("Unsupported %s param: %q", tagName, parts[i])
|
klog.Fatalf("Unsupported %s param: %q", tagName, parts[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tag
|
return tag
|
||||||
@@ -123,7 +123,7 @@ func DefaultNameSystem() string {
|
|||||||
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
||||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed loading boilerplate: %v", err)
|
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
inputs := sets.NewString(context.Inputs...)
|
inputs := sets.NewString(context.Inputs...)
|
||||||
@@ -143,7 +143,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i := range inputs {
|
for i := range inputs {
|
||||||
glog.V(5).Infof("Considering pkg %q", i)
|
klog.V(5).Infof("Considering pkg %q", i)
|
||||||
pkg := context.Universe[i]
|
pkg := context.Universe[i]
|
||||||
if pkg == nil {
|
if pkg == nil {
|
||||||
// If the input had no Go files, for example.
|
// If the input had no Go files, for example.
|
||||||
@@ -156,12 +156,12 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
if ptag != nil {
|
if ptag != nil {
|
||||||
ptagValue = ptag.value
|
ptagValue = ptag.value
|
||||||
if ptagValue != tagValuePackage {
|
if ptagValue != tagValuePackage {
|
||||||
glog.Fatalf("Package %v: unsupported %s value: %q", i, tagName, ptagValue)
|
klog.Fatalf("Package %v: unsupported %s value: %q", i, tagName, ptagValue)
|
||||||
}
|
}
|
||||||
ptagRegister = ptag.register
|
ptagRegister = ptag.register
|
||||||
glog.V(5).Infof(" tag.value: %q, tag.register: %t", ptagValue, ptagRegister)
|
klog.V(5).Infof(" tag.value: %q, tag.register: %t", ptagValue, ptagRegister)
|
||||||
} else {
|
} else {
|
||||||
glog.V(5).Infof(" no tag")
|
klog.V(5).Infof(" no tag")
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the pkg-scoped tag says to generate, we can skip scanning types.
|
// If the pkg-scoped tag says to generate, we can skip scanning types.
|
||||||
@@ -170,12 +170,12 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
// If the pkg-scoped tag did not exist, scan all types for one that
|
// If the pkg-scoped tag did not exist, scan all types for one that
|
||||||
// explicitly wants generation.
|
// explicitly wants generation.
|
||||||
for _, t := range pkg.Types {
|
for _, t := range pkg.Types {
|
||||||
glog.V(5).Infof(" considering type %q", t.Name.String())
|
klog.V(5).Infof(" considering type %q", t.Name.String())
|
||||||
ttag := extractTag(t.CommentLines)
|
ttag := extractTag(t.CommentLines)
|
||||||
if ttag != nil && ttag.value == "true" {
|
if ttag != nil && ttag.value == "true" {
|
||||||
glog.V(5).Infof(" tag=true")
|
klog.V(5).Infof(" tag=true")
|
||||||
if !copyableType(t) {
|
if !copyableType(t) {
|
||||||
glog.Fatalf("Type %v requests deepcopy generation but is not copyable", t)
|
klog.Fatalf("Type %v requests deepcopy generation but is not copyable", t)
|
||||||
}
|
}
|
||||||
pkgNeedsGeneration = true
|
pkgNeedsGeneration = true
|
||||||
break
|
break
|
||||||
@@ -184,7 +184,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
}
|
}
|
||||||
|
|
||||||
if pkgNeedsGeneration {
|
if pkgNeedsGeneration {
|
||||||
glog.V(3).Infof("Package %q needs generation", i)
|
klog.V(3).Infof("Package %q needs generation", i)
|
||||||
path := pkg.Path
|
path := pkg.Path
|
||||||
// if the source path is within a /vendor/ directory (for example,
|
// if the source path is within a /vendor/ directory (for example,
|
||||||
// k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/apis/meta/v1), allow
|
// k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/apis/meta/v1), allow
|
||||||
@@ -263,10 +263,10 @@ func (g *genDeepCopy) Filter(c *generator.Context, t *types.Type) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !copyableType(t) {
|
if !copyableType(t) {
|
||||||
glog.V(2).Infof("Type %v is not copyable", t)
|
klog.V(2).Infof("Type %v is not copyable", t)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
glog.V(4).Infof("Type %v is copyable", t)
|
klog.V(4).Infof("Type %v is copyable", t)
|
||||||
g.typesForInit = append(g.typesForInit, t)
|
g.typesForInit = append(g.typesForInit, t)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -321,12 +321,12 @@ func deepCopyMethod(t *types.Type) (*types.Signature, error) {
|
|||||||
return f.Signature, nil
|
return f.Signature, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// deepCopyMethodOrDie returns the signatrue of a DeepCopy method, nil or calls glog.Fatalf
|
// deepCopyMethodOrDie returns the signatrue of a DeepCopy method, nil or calls klog.Fatalf
|
||||||
// if the type does not match.
|
// if the type does not match.
|
||||||
func deepCopyMethodOrDie(t *types.Type) *types.Signature {
|
func deepCopyMethodOrDie(t *types.Type) *types.Signature {
|
||||||
ret, err := deepCopyMethod(t)
|
ret, err := deepCopyMethod(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal(err)
|
klog.Fatal(err)
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
@@ -367,12 +367,12 @@ func deepCopyIntoMethod(t *types.Type) (*types.Signature, error) {
|
|||||||
return f.Signature, nil
|
return f.Signature, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// deepCopyIntoMethodOrDie returns the signature of a DeepCopyInto() method, nil or calls glog.Fatalf
|
// deepCopyIntoMethodOrDie returns the signature of a DeepCopyInto() method, nil or calls klog.Fatalf
|
||||||
// if the type is wrong.
|
// if the type is wrong.
|
||||||
func deepCopyIntoMethodOrDie(t *types.Type) *types.Signature {
|
func deepCopyIntoMethodOrDie(t *types.Type) *types.Signature {
|
||||||
ret, err := deepCopyIntoMethod(t)
|
ret, err := deepCopyIntoMethod(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal(err)
|
klog.Fatal(err)
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
@@ -465,17 +465,17 @@ func (g *genDeepCopy) needsGeneration(t *types.Type) bool {
|
|||||||
if tag != nil {
|
if tag != nil {
|
||||||
tv = tag.value
|
tv = tag.value
|
||||||
if tv != "true" && tv != "false" {
|
if tv != "true" && tv != "false" {
|
||||||
glog.Fatalf("Type %v: unsupported %s value: %q", t, tagName, tag.value)
|
klog.Fatalf("Type %v: unsupported %s value: %q", t, tagName, tag.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if g.allTypes && tv == "false" {
|
if g.allTypes && tv == "false" {
|
||||||
// The whole package is being generated, but this type has opted out.
|
// The whole package is being generated, but this type has opted out.
|
||||||
glog.V(5).Infof("Not generating for type %v because type opted out", t)
|
klog.V(5).Infof("Not generating for type %v because type opted out", t)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !g.allTypes && tv != "true" {
|
if !g.allTypes && tv != "true" {
|
||||||
// The whole package is NOT being generated, and this type has NOT opted in.
|
// The whole package is NOT being generated, and this type has NOT opted in.
|
||||||
glog.V(5).Infof("Not generating for type %v because type did not opt in", t)
|
klog.V(5).Infof("Not generating for type %v because type did not opt in", t)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@@ -576,7 +576,7 @@ func (g *genDeepCopy) GenerateType(c *generator.Context, t *types.Type, w io.Wri
|
|||||||
if !g.needsGeneration(t) {
|
if !g.needsGeneration(t) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
glog.V(5).Infof("Generating deepcopy function for type %v", t)
|
klog.V(5).Infof("Generating deepcopy function for type %v", t)
|
||||||
|
|
||||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||||
args := argsFromType(t)
|
args := argsFromType(t)
|
||||||
@@ -678,12 +678,12 @@ func (g *genDeepCopy) generateFor(t *types.Type, sw *generator.SnippetWriter) {
|
|||||||
f = g.doPointer
|
f = g.doPointer
|
||||||
case types.Interface:
|
case types.Interface:
|
||||||
// interfaces are handled in-line in the other cases
|
// interfaces are handled in-line in the other cases
|
||||||
glog.Fatalf("Hit an interface type %v. This should never happen.", t)
|
klog.Fatalf("Hit an interface type %v. This should never happen.", t)
|
||||||
case types.Alias:
|
case types.Alias:
|
||||||
// can never happen because we branch on the underlying type which is never an alias
|
// can never happen because we branch on the underlying type which is never an alias
|
||||||
glog.Fatalf("Hit an alias type %v. This should never happen.", t)
|
klog.Fatalf("Hit an alias type %v. This should never happen.", t)
|
||||||
default:
|
default:
|
||||||
glog.Fatalf("Hit an unsupported type %v.", t)
|
klog.Fatalf("Hit an unsupported type %v.", t)
|
||||||
}
|
}
|
||||||
f(t, sw)
|
f(t, sw)
|
||||||
}
|
}
|
||||||
@@ -711,7 +711,7 @@ func (g *genDeepCopy) doMap(t *types.Type, sw *generator.SnippetWriter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !ut.Key.IsAssignable() {
|
if !ut.Key.IsAssignable() {
|
||||||
glog.Fatalf("Hit an unsupported type %v.", uet)
|
klog.Fatalf("Hit an unsupported type %v.", uet)
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.Do("*out = make($.|raw$, len(*in))\n", t)
|
sw.Do("*out = make($.|raw$, len(*in))\n", t)
|
||||||
@@ -754,7 +754,7 @@ func (g *genDeepCopy) doMap(t *types.Type, sw *generator.SnippetWriter) {
|
|||||||
case uet.Kind == types.Struct:
|
case uet.Kind == types.Struct:
|
||||||
sw.Do("(*out)[key] = *val.DeepCopy()\n", uet)
|
sw.Do("(*out)[key] = *val.DeepCopy()\n", uet)
|
||||||
default:
|
default:
|
||||||
glog.Fatalf("Hit an unsupported type %v.", uet)
|
klog.Fatalf("Hit an unsupported type %v.", uet)
|
||||||
}
|
}
|
||||||
sw.Do("}\n", nil)
|
sw.Do("}\n", nil)
|
||||||
}
|
}
|
||||||
@@ -795,7 +795,7 @@ func (g *genDeepCopy) doSlice(t *types.Type, sw *generator.SnippetWriter) {
|
|||||||
} else if uet.Kind == types.Struct {
|
} else if uet.Kind == types.Struct {
|
||||||
sw.Do("(*in)[i].DeepCopyInto(&(*out)[i])\n", nil)
|
sw.Do("(*in)[i].DeepCopyInto(&(*out)[i])\n", nil)
|
||||||
} else {
|
} else {
|
||||||
glog.Fatalf("Hit an unsupported type %v.", uet)
|
klog.Fatalf("Hit an unsupported type %v.", uet)
|
||||||
}
|
}
|
||||||
sw.Do("}\n", nil)
|
sw.Do("}\n", nil)
|
||||||
}
|
}
|
||||||
@@ -863,7 +863,7 @@ func (g *genDeepCopy) doStruct(t *types.Type, sw *generator.SnippetWriter) {
|
|||||||
sw.Do(fmt.Sprintf("out.$.name$ = in.$.name$.DeepCopy%s()\n", uft.Name.Name), args)
|
sw.Do(fmt.Sprintf("out.$.name$ = in.$.name$.DeepCopy%s()\n", uft.Name.Name), args)
|
||||||
sw.Do("}\n", nil)
|
sw.Do("}\n", nil)
|
||||||
default:
|
default:
|
||||||
glog.Fatalf("Hit an unsupported type %v.", uft)
|
klog.Fatalf("Hit an unsupported type %v.", uft)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -900,6 +900,6 @@ func (g *genDeepCopy) doPointer(t *types.Type, sw *generator.SnippetWriter) {
|
|||||||
sw.Do("*out = new($.Elem|raw$)\n", ut)
|
sw.Do("*out = new($.Elem|raw$)\n", ut)
|
||||||
sw.Do("(*in).DeepCopyInto(*out)\n", nil)
|
sw.Do("(*in).DeepCopyInto(*out)\n", nil)
|
||||||
default:
|
default:
|
||||||
glog.Fatalf("Hit an unsupported type %v.", uet)
|
klog.Fatalf("Hit an unsupported type %v.", uet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
Vendored
+19
-19
@@ -29,7 +29,7 @@ import (
|
|||||||
"k8s.io/gengo/namer"
|
"k8s.io/gengo/namer"
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CustomArgs is used tby the go2idl framework to pass args specific to this
|
// CustomArgs is used tby the go2idl framework to pass args specific to this
|
||||||
@@ -117,11 +117,11 @@ func getManualDefaultingFunctions(context *generator.Context, pkg *types.Package
|
|||||||
|
|
||||||
for _, f := range pkg.Functions {
|
for _, f := range pkg.Functions {
|
||||||
if f.Underlying == nil || f.Underlying.Kind != types.Func {
|
if f.Underlying == nil || f.Underlying.Kind != types.Func {
|
||||||
glog.Errorf("Malformed function: %#v", f)
|
klog.Errorf("Malformed function: %#v", f)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if f.Underlying.Signature == nil {
|
if f.Underlying.Signature == nil {
|
||||||
glog.Errorf("Function without signature: %#v", f)
|
klog.Errorf("Function without signature: %#v", f)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
signature := f.Underlying.Signature
|
signature := f.Underlying.Signature
|
||||||
@@ -156,7 +156,7 @@ func getManualDefaultingFunctions(context *generator.Context, pkg *types.Package
|
|||||||
}
|
}
|
||||||
v.base = f
|
v.base = f
|
||||||
manualMap[key] = v
|
manualMap[key] = v
|
||||||
glog.V(6).Infof("found base defaulter function for %s from %s", key.Name, f.Name)
|
klog.V(6).Infof("found base defaulter function for %s from %s", key.Name, f.Name)
|
||||||
// Is one of the additional defaulters - a top level defaulter on a type that is
|
// Is one of the additional defaulters - a top level defaulter on a type that is
|
||||||
// also invoked.
|
// also invoked.
|
||||||
case strings.HasPrefix(f.Name.Name, buffer.String()+"_"):
|
case strings.HasPrefix(f.Name.Name, buffer.String()+"_"):
|
||||||
@@ -176,7 +176,7 @@ func getManualDefaultingFunctions(context *generator.Context, pkg *types.Package
|
|||||||
}
|
}
|
||||||
v.additional = append(v.additional, f)
|
v.additional = append(v.additional, f)
|
||||||
manualMap[key] = v
|
manualMap[key] = v
|
||||||
glog.V(6).Infof("found additional defaulter function for %s from %s", key.Name, f.Name)
|
klog.V(6).Infof("found additional defaulter function for %s from %s", key.Name, f.Name)
|
||||||
}
|
}
|
||||||
buffer.Reset()
|
buffer.Reset()
|
||||||
sw.Do("$.inType|objectdefaultfn$", args)
|
sw.Do("$.inType|objectdefaultfn$", args)
|
||||||
@@ -189,7 +189,7 @@ func getManualDefaultingFunctions(context *generator.Context, pkg *types.Package
|
|||||||
}
|
}
|
||||||
v.object = f
|
v.object = f
|
||||||
manualMap[key] = v
|
manualMap[key] = v
|
||||||
glog.V(6).Infof("found object defaulter function for %s from %s", key.Name, f.Name)
|
klog.V(6).Infof("found object defaulter function for %s from %s", key.Name, f.Name)
|
||||||
}
|
}
|
||||||
buffer.Reset()
|
buffer.Reset()
|
||||||
}
|
}
|
||||||
@@ -198,7 +198,7 @@ func getManualDefaultingFunctions(context *generator.Context, pkg *types.Package
|
|||||||
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
||||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed loading boilerplate: %v", err)
|
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
packages := generator.Packages{}
|
packages := generator.Packages{}
|
||||||
@@ -214,7 +214,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
// We are generating defaults only for packages that are explicitly
|
// We are generating defaults only for packages that are explicitly
|
||||||
// passed as InputDir.
|
// passed as InputDir.
|
||||||
for _, i := range context.Inputs {
|
for _, i := range context.Inputs {
|
||||||
glog.V(5).Infof("considering pkg %q", i)
|
klog.V(5).Infof("considering pkg %q", i)
|
||||||
pkg := context.Universe[i]
|
pkg := context.Universe[i]
|
||||||
if pkg == nil {
|
if pkg == nil {
|
||||||
// If the input had no Go files, for example.
|
// If the input had no Go files, for example.
|
||||||
@@ -248,7 +248,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
shouldCreateObjectDefaulterFn := func(t *types.Type) bool {
|
shouldCreateObjectDefaulterFn := func(t *types.Type) bool {
|
||||||
if defaults, ok := existingDefaulters[t]; ok && defaults.object != nil {
|
if defaults, ok := existingDefaulters[t]; ok && defaults.object != nil {
|
||||||
// A default generator is defined
|
// A default generator is defined
|
||||||
glog.V(5).Infof(" an object defaulter already exists as %s", defaults.base.Name)
|
klog.V(5).Infof(" an object defaulter already exists as %s", defaults.base.Name)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// opt-out
|
// opt-out
|
||||||
@@ -285,7 +285,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
var err error
|
var err error
|
||||||
typesPkg, err = context.AddDirectory(filepath.Join(pkg.Path, inputTags[0]))
|
typesPkg, err = context.AddDirectory(filepath.Join(pkg.Path, inputTags[0]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("cannot import package %s", inputTags[0])
|
klog.Fatalf("cannot import package %s", inputTags[0])
|
||||||
}
|
}
|
||||||
// update context.Order to the latest context.Universe
|
// update context.Order to the latest context.Universe
|
||||||
orderer := namer.Orderer{Namer: namer.NewPublicNamer(1)}
|
orderer := namer.Orderer{Namer: namer.NewPublicNamer(1)}
|
||||||
@@ -299,7 +299,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
}
|
}
|
||||||
if namer.IsPrivateGoName(t.Name.Name) {
|
if namer.IsPrivateGoName(t.Name.Name) {
|
||||||
// We won't be able to convert to a private type.
|
// We won't be able to convert to a private type.
|
||||||
glog.V(5).Infof(" found a type %v, but it is a private name", t)
|
klog.V(5).Infof(" found a type %v, but it is a private name", t)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,7 +338,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
// prune any types that were not used
|
// prune any types that were not used
|
||||||
for t, d := range newDefaulters {
|
for t, d := range newDefaulters {
|
||||||
if d.object == nil {
|
if d.object == nil {
|
||||||
glog.V(6).Infof("did not generate defaulter for %s because no child defaulters were registered", t.Name)
|
klog.V(6).Infof("did not generate defaulter for %s because no child defaulters were registered", t.Name)
|
||||||
delete(newDefaulters, t)
|
delete(newDefaulters, t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -346,7 +346,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(newDefaulters) == 0 {
|
if len(newDefaulters) == 0 {
|
||||||
glog.V(5).Infof("no defaulters in package %s", pkg.Name)
|
klog.V(5).Infof("no defaulters in package %s", pkg.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
path := pkg.Path
|
path := pkg.Path
|
||||||
@@ -421,7 +421,7 @@ func (c *callTreeForType) build(t *types.Type, root bool) *callNode {
|
|||||||
parent.call = append(parent.call, newDefaults.object)
|
parent.call = append(parent.call, newDefaults.object)
|
||||||
// if we will be generating the defaulter, it by definition is a covering
|
// if we will be generating the defaulter, it by definition is a covering
|
||||||
// defaulter, so we halt recursion
|
// defaulter, so we halt recursion
|
||||||
glog.V(6).Infof("the defaulter %s will be generated as an object defaulter", t.Name)
|
klog.V(6).Infof("the defaulter %s will be generated as an object defaulter", t.Name)
|
||||||
return parent
|
return parent
|
||||||
|
|
||||||
case defaults.object != nil:
|
case defaults.object != nil:
|
||||||
@@ -434,7 +434,7 @@ func (c *callTreeForType) build(t *types.Type, root bool) *callNode {
|
|||||||
// if the base function indicates it "covers" (it already includes defaulters)
|
// if the base function indicates it "covers" (it already includes defaulters)
|
||||||
// we can halt recursion
|
// we can halt recursion
|
||||||
if checkTag(defaults.base.CommentLines, "covers") {
|
if checkTag(defaults.base.CommentLines, "covers") {
|
||||||
glog.V(6).Infof("the defaulter %s indicates it covers all sub generators", t.Name)
|
klog.V(6).Infof("the defaulter %s indicates it covers all sub generators", t.Name)
|
||||||
return parent
|
return parent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -496,7 +496,7 @@ func (c *callTreeForType) build(t *types.Type, root bool) *callNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(parent.children) == 0 && len(parent.call) == 0 {
|
if len(parent.children) == 0 && len(parent.call) == 0 {
|
||||||
//glog.V(6).Infof("decided type %s needs no generation", t.Name)
|
//klog.V(6).Infof("decided type %s needs no generation", t.Name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return parent
|
return parent
|
||||||
@@ -596,11 +596,11 @@ func (g *genDefaulter) GenerateType(c *generator.Context, t *types.Type, w io.Wr
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(5).Infof("generating for type %v", t)
|
klog.V(5).Infof("generating for type %v", t)
|
||||||
|
|
||||||
callTree := newCallTreeForType(g.existingDefaulters, g.newDefaulters).build(t, true)
|
callTree := newCallTreeForType(g.existingDefaulters, g.newDefaulters).build(t, true)
|
||||||
if callTree == nil {
|
if callTree == nil {
|
||||||
glog.V(5).Infof(" no defaulters defined")
|
klog.V(5).Infof(" no defaulters defined")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
i := 0
|
i := 0
|
||||||
@@ -609,7 +609,7 @@ func (g *genDefaulter) GenerateType(c *generator.Context, t *types.Type, w io.Wr
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
path := callPath(append(ancestors, current))
|
path := callPath(append(ancestors, current))
|
||||||
glog.V(5).Infof(" %d: %s", i, path)
|
klog.V(5).Infof(" %d: %s", i, path)
|
||||||
i++
|
i++
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Generated
Vendored
+5
-5
@@ -33,7 +33,7 @@ import (
|
|||||||
"k8s.io/gengo/namer"
|
"k8s.io/gengo/namer"
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -202,19 +202,19 @@ func (importRuleFile) VerifyFile(f *generator.File, path string) error {
|
|||||||
return fmt.Errorf("regexp `%s` in file %q doesn't compile: %v", r.SelectorRegexp, actualPath, err)
|
return fmt.Errorf("regexp `%s` in file %q doesn't compile: %v", r.SelectorRegexp, actualPath, err)
|
||||||
}
|
}
|
||||||
for v := range f.Imports {
|
for v := range f.Imports {
|
||||||
glog.V(4).Infof("Checking %v matches %v: %v\n", r.SelectorRegexp, v, re.MatchString(v))
|
klog.V(4).Infof("Checking %v matches %v: %v\n", r.SelectorRegexp, v, re.MatchString(v))
|
||||||
if !re.MatchString(v) {
|
if !re.MatchString(v) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, forbidden := range r.ForbiddenPrefixes {
|
for _, forbidden := range r.ForbiddenPrefixes {
|
||||||
glog.V(4).Infof("Checking %v against %v\n", v, forbidden)
|
klog.V(4).Infof("Checking %v against %v\n", v, forbidden)
|
||||||
if strings.HasPrefix(v, forbidden) {
|
if strings.HasPrefix(v, forbidden) {
|
||||||
return fmt.Errorf("import %v has forbidden prefix %v", v, forbidden)
|
return fmt.Errorf("import %v has forbidden prefix %v", v, forbidden)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
found := false
|
found := false
|
||||||
for _, allowed := range r.AllowedPrefixes {
|
for _, allowed := range r.AllowedPrefixes {
|
||||||
glog.V(4).Infof("Checking %v against %v\n", v, allowed)
|
klog.V(4).Infof("Checking %v against %v\n", v, allowed)
|
||||||
if strings.HasPrefix(v, allowed) {
|
if strings.HasPrefix(v, allowed) {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
@@ -226,7 +226,7 @@ func (importRuleFile) VerifyFile(f *generator.File, path string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(rules.Rules) > 0 {
|
if len(rules.Rules) > 0 {
|
||||||
glog.V(2).Infof("%v passes rules found in %v\n", path, actualPath)
|
klog.V(2).Infof("%v passes rules found in %v\n", path, actualPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Generated
Vendored
+3
-3
@@ -25,7 +25,7 @@ import (
|
|||||||
"k8s.io/gengo/namer"
|
"k8s.io/gengo/namer"
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NameSystems returns the name system used by the generators in this package.
|
// NameSystems returns the name system used by the generators in this package.
|
||||||
@@ -47,13 +47,13 @@ func DefaultNameSystem() string {
|
|||||||
func Packages(_ *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
func Packages(_ *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
||||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed loading boilerplate: %v", err)
|
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return generator.Packages{&generator.DefaultPackage{
|
return generator.Packages{&generator.DefaultPackage{
|
||||||
PackageName: "sets",
|
PackageName: "sets",
|
||||||
PackagePath: arguments.OutputPackagePath,
|
PackagePath: arguments.OutputPackagePath,
|
||||||
HeaderText: boilerplate,
|
HeaderText: boilerplate,
|
||||||
PackageDocumentation: []byte(
|
PackageDocumentation: []byte(
|
||||||
`// Package sets has auto-generated set types.
|
`// Package sets has auto-generated set types.
|
||||||
`),
|
`),
|
||||||
|
|||||||
Generated
Vendored
+2
-2
@@ -17,8 +17,8 @@ limitations under the License.
|
|||||||
package generators
|
package generators
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/golang/glog"
|
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// extractBoolTagOrDie gets the comment-tags for the key and asserts that, if
|
// extractBoolTagOrDie gets the comment-tags for the key and asserts that, if
|
||||||
@@ -27,7 +27,7 @@ import (
|
|||||||
func extractBoolTagOrDie(key string, lines []string) bool {
|
func extractBoolTagOrDie(key string, lines []string) bool {
|
||||||
val, err := types.ExtractSingleBoolCommentTag("+", key, false, lines)
|
val, err := types.ExtractSingleBoolCommentTag("+", key, false, lines)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf(err.Error())
|
klog.Fatalf(err.Error())
|
||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -29,7 +29,7 @@ import (
|
|||||||
"k8s.io/gengo/namer"
|
"k8s.io/gengo/namer"
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func errs2strings(errors []error) []string {
|
func errs2strings(errors []error) []string {
|
||||||
@@ -64,7 +64,7 @@ type DefaultFileType struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ft DefaultFileType) AssembleFile(f *File, pathname string) error {
|
func (ft DefaultFileType) AssembleFile(f *File, pathname string) error {
|
||||||
glog.V(2).Infof("Assembling file %q", pathname)
|
klog.V(2).Infof("Assembling file %q", pathname)
|
||||||
destFile, err := os.Create(pathname)
|
destFile, err := os.Create(pathname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -91,7 +91,7 @@ func (ft DefaultFileType) AssembleFile(f *File, pathname string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ft DefaultFileType) VerifyFile(f *File, pathname string) error {
|
func (ft DefaultFileType) VerifyFile(f *File, pathname string) error {
|
||||||
glog.V(2).Infof("Verifying file %q", pathname)
|
klog.V(2).Infof("Verifying file %q", pathname)
|
||||||
friendlyName := filepath.Join(f.PackageName, f.Name)
|
friendlyName := filepath.Join(f.PackageName, f.Name)
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
et := NewErrorTracker(b)
|
et := NewErrorTracker(b)
|
||||||
@@ -214,7 +214,7 @@ func (c *Context) addNameSystems(namers namer.NameSystems) *Context {
|
|||||||
// import path already, this will be appended to 'outDir'.
|
// import path already, this will be appended to 'outDir'.
|
||||||
func (c *Context) ExecutePackage(outDir string, p Package) error {
|
func (c *Context) ExecutePackage(outDir string, p Package) error {
|
||||||
path := filepath.Join(outDir, p.Path())
|
path := filepath.Join(outDir, p.Path())
|
||||||
glog.V(2).Infof("Processing package %q, disk location %q", p.Name(), path)
|
klog.V(2).Infof("Processing package %q, disk location %q", p.Name(), path)
|
||||||
// Filter out any types the *package* doesn't care about.
|
// Filter out any types the *package* doesn't care about.
|
||||||
packageContext := c.filteredBy(p.Filter)
|
packageContext := c.filteredBy(p.Filter)
|
||||||
os.MkdirAll(path, 0755)
|
os.MkdirAll(path, 0755)
|
||||||
|
|||||||
+2
-2
@@ -19,7 +19,7 @@ package generator
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
"k8s.io/gengo/namer"
|
"k8s.io/gengo/namer"
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
@@ -42,7 +42,7 @@ func golangTrackerLocalName(tracker namer.ImportTracker, t types.Name) string {
|
|||||||
// Using backslashes in package names causes gengo to produce Go code which
|
// Using backslashes in package names causes gengo to produce Go code which
|
||||||
// will not compile with the gc compiler. See the comment on GoSeperator.
|
// will not compile with the gc compiler. See the comment on GoSeperator.
|
||||||
if strings.ContainsRune(path, '\\') {
|
if strings.ContainsRune(path, '\\') {
|
||||||
glog.Warningf("Warning: backslash used in import path '%v', this is unsupported.\n", path)
|
klog.Warningf("Warning: backslash used in import path '%v', this is unsupported.\n", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
dirs := strings.Split(path, namer.GoSeperator)
|
dirs := strings.Split(path, namer.GoSeperator)
|
||||||
|
|||||||
+2
-2
@@ -59,7 +59,7 @@ func (r *pluralNamer) Name(t *types.Type) string {
|
|||||||
return r.finalize(plural)
|
return r.finalize(plural)
|
||||||
}
|
}
|
||||||
if len(singular) < 2 {
|
if len(singular) < 2 {
|
||||||
return r.finalize(plural)
|
return r.finalize(singular)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch rune(singular[len(singular)-1]) {
|
switch rune(singular[len(singular)-1]) {
|
||||||
@@ -87,7 +87,7 @@ func (r *pluralNamer) Name(t *types.Type) string {
|
|||||||
plural = sPlural(singular)
|
plural = sPlural(singular)
|
||||||
}
|
}
|
||||||
case 'f':
|
case 'f':
|
||||||
plural = vesPlural(singular)
|
plural = vesPlural(singular)
|
||||||
default:
|
default:
|
||||||
plural = sPlural(singular)
|
plural = sPlural(singular)
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-21
@@ -31,8 +31,8 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This clarifies when a pkg path has been canonicalized.
|
// This clarifies when a pkg path has been canonicalized.
|
||||||
@@ -89,7 +89,7 @@ func New() *Builder {
|
|||||||
// The returned string will have some/path/bin/go, so remove the last two elements.
|
// The returned string will have some/path/bin/go, so remove the last two elements.
|
||||||
c.GOROOT = filepath.Dir(filepath.Dir(strings.Trim(string(p), "\n")))
|
c.GOROOT = filepath.Dir(filepath.Dir(strings.Trim(string(p), "\n")))
|
||||||
} else {
|
} else {
|
||||||
glog.Warningf("Warning: $GOROOT not set, and unable to run `which go` to find it: %v\n", err)
|
klog.Warningf("Warning: $GOROOT not set, and unable to run `which go` to find it: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Force this to off, since we don't properly parse CGo. All symbols must
|
// Force this to off, since we don't properly parse CGo. All symbols must
|
||||||
@@ -136,7 +136,7 @@ func (b *Builder) importBuildPackage(dir string) (*build.Package, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remember it under the user-provided name.
|
// Remember it under the user-provided name.
|
||||||
glog.V(5).Infof("saving buildPackage %s", dir)
|
klog.V(5).Infof("saving buildPackage %s", dir)
|
||||||
b.buildPackages[dir] = buildPkg
|
b.buildPackages[dir] = buildPkg
|
||||||
canonicalPackage := canonicalizeImportPath(buildPkg.ImportPath)
|
canonicalPackage := canonicalizeImportPath(buildPkg.ImportPath)
|
||||||
if dir != string(canonicalPackage) {
|
if dir != string(canonicalPackage) {
|
||||||
@@ -145,7 +145,7 @@ func (b *Builder) importBuildPackage(dir string) (*build.Package, error) {
|
|||||||
return buildPkg, nil
|
return buildPkg, nil
|
||||||
}
|
}
|
||||||
// Must be new, save it under the canonical name, too.
|
// Must be new, save it under the canonical name, too.
|
||||||
glog.V(5).Infof("saving buildPackage %s", canonicalPackage)
|
klog.V(5).Infof("saving buildPackage %s", canonicalPackage)
|
||||||
b.buildPackages[string(canonicalPackage)] = buildPkg
|
b.buildPackages[string(canonicalPackage)] = buildPkg
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,11 +175,11 @@ func (b *Builder) AddFileForTest(pkg string, path string, src []byte) error {
|
|||||||
func (b *Builder) addFile(pkgPath importPathString, path string, src []byte, userRequested bool) error {
|
func (b *Builder) addFile(pkgPath importPathString, path string, src []byte, userRequested bool) error {
|
||||||
for _, p := range b.parsed[pkgPath] {
|
for _, p := range b.parsed[pkgPath] {
|
||||||
if path == p.name {
|
if path == p.name {
|
||||||
glog.V(5).Infof("addFile %s %s already parsed, skipping", pkgPath, path)
|
klog.V(5).Infof("addFile %s %s already parsed, skipping", pkgPath, path)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glog.V(6).Infof("addFile %s %s", pkgPath, path)
|
klog.V(6).Infof("addFile %s %s", pkgPath, path)
|
||||||
p, err := parser.ParseFile(b.fset, path, src, parser.DeclarationErrors|parser.ParseComments)
|
p, err := parser.ParseFile(b.fset, path, src, parser.DeclarationErrors|parser.ParseComments)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -221,7 +221,7 @@ func (b *Builder) AddDir(dir string) error {
|
|||||||
func (b *Builder) AddDirRecursive(dir string) error {
|
func (b *Builder) AddDirRecursive(dir string) error {
|
||||||
// Add the root.
|
// Add the root.
|
||||||
if _, err := b.importPackage(dir, true); err != nil {
|
if _, err := b.importPackage(dir, true); err != nil {
|
||||||
glog.Warningf("Ignoring directory %v: %v", dir, err)
|
klog.Warningf("Ignoring directory %v: %v", dir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// filepath.Walk includes the root dir, but we already did that, so we'll
|
// filepath.Walk includes the root dir, but we already did that, so we'll
|
||||||
@@ -236,7 +236,7 @@ func (b *Builder) AddDirRecursive(dir string) error {
|
|||||||
|
|
||||||
// Add it.
|
// Add it.
|
||||||
if _, err := b.importPackage(pkg, true); err != nil {
|
if _, err := b.importPackage(pkg, true); err != nil {
|
||||||
glog.Warningf("Ignoring child directory %v: %v", pkg, err)
|
klog.Warningf("Ignoring child directory %v: %v", pkg, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -284,7 +284,7 @@ func (b *Builder) AddDirectoryTo(dir string, u *types.Universe) (*types.Package,
|
|||||||
// The implementation of AddDir. A flag indicates whether this directory was
|
// The implementation of AddDir. A flag indicates whether this directory was
|
||||||
// user-requested or just from following the import graph.
|
// user-requested or just from following the import graph.
|
||||||
func (b *Builder) addDir(dir string, userRequested bool) error {
|
func (b *Builder) addDir(dir string, userRequested bool) error {
|
||||||
glog.V(5).Infof("addDir %s", dir)
|
klog.V(5).Infof("addDir %s", dir)
|
||||||
buildPkg, err := b.importBuildPackage(dir)
|
buildPkg, err := b.importBuildPackage(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -292,7 +292,7 @@ func (b *Builder) addDir(dir string, userRequested bool) error {
|
|||||||
canonicalPackage := canonicalizeImportPath(buildPkg.ImportPath)
|
canonicalPackage := canonicalizeImportPath(buildPkg.ImportPath)
|
||||||
pkgPath := canonicalPackage
|
pkgPath := canonicalPackage
|
||||||
if dir != string(canonicalPackage) {
|
if dir != string(canonicalPackage) {
|
||||||
glog.V(5).Infof("addDir %s, canonical path is %s", dir, pkgPath)
|
klog.V(5).Infof("addDir %s, canonical path is %s", dir, pkgPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sanity check the pkg dir has not changed.
|
// Sanity check the pkg dir has not changed.
|
||||||
@@ -324,13 +324,13 @@ func (b *Builder) addDir(dir string, userRequested bool) error {
|
|||||||
// importPackage is a function that will be called by the type check package when it
|
// importPackage is a function that will be called by the type check package when it
|
||||||
// needs to import a go package. 'path' is the import path.
|
// needs to import a go package. 'path' is the import path.
|
||||||
func (b *Builder) importPackage(dir string, userRequested bool) (*tc.Package, error) {
|
func (b *Builder) importPackage(dir string, userRequested bool) (*tc.Package, error) {
|
||||||
glog.V(5).Infof("importPackage %s", dir)
|
klog.V(5).Infof("importPackage %s", dir)
|
||||||
var pkgPath = importPathString(dir)
|
var pkgPath = importPathString(dir)
|
||||||
|
|
||||||
// Get the canonical path if we can.
|
// Get the canonical path if we can.
|
||||||
if buildPkg := b.buildPackages[dir]; buildPkg != nil {
|
if buildPkg := b.buildPackages[dir]; buildPkg != nil {
|
||||||
canonicalPackage := canonicalizeImportPath(buildPkg.ImportPath)
|
canonicalPackage := canonicalizeImportPath(buildPkg.ImportPath)
|
||||||
glog.V(5).Infof("importPackage %s, canonical path is %s", dir, canonicalPackage)
|
klog.V(5).Infof("importPackage %s, canonical path is %s", dir, canonicalPackage)
|
||||||
pkgPath = canonicalPackage
|
pkgPath = canonicalPackage
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,7 +349,7 @@ func (b *Builder) importPackage(dir string, userRequested bool) (*tc.Package, er
|
|||||||
// Get the canonical path now that it has been added.
|
// Get the canonical path now that it has been added.
|
||||||
if buildPkg := b.buildPackages[dir]; buildPkg != nil {
|
if buildPkg := b.buildPackages[dir]; buildPkg != nil {
|
||||||
canonicalPackage := canonicalizeImportPath(buildPkg.ImportPath)
|
canonicalPackage := canonicalizeImportPath(buildPkg.ImportPath)
|
||||||
glog.V(5).Infof("importPackage %s, canonical path is %s", dir, canonicalPackage)
|
klog.V(5).Infof("importPackage %s, canonical path is %s", dir, canonicalPackage)
|
||||||
pkgPath = canonicalPackage
|
pkgPath = canonicalPackage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -365,9 +365,9 @@ func (b *Builder) importPackage(dir string, userRequested bool) (*tc.Package, er
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
switch {
|
||||||
case ignoreError && pkg != nil:
|
case ignoreError && pkg != nil:
|
||||||
glog.V(2).Infof("type checking encountered some issues in %q, but ignoring.\n", pkgPath)
|
klog.V(2).Infof("type checking encountered some issues in %q, but ignoring.\n", pkgPath)
|
||||||
case !ignoreError && pkg != nil:
|
case !ignoreError && pkg != nil:
|
||||||
glog.V(2).Infof("type checking encountered some errors in %q\n", pkgPath)
|
klog.V(2).Infof("type checking encountered some errors in %q\n", pkgPath)
|
||||||
return nil, err
|
return nil, err
|
||||||
default:
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -389,10 +389,10 @@ func (a importAdapter) Import(path string) (*tc.Package, error) {
|
|||||||
// errors, so you may check whether the package is nil or not even if you get
|
// errors, so you may check whether the package is nil or not even if you get
|
||||||
// an error.
|
// an error.
|
||||||
func (b *Builder) typeCheckPackage(pkgPath importPathString) (*tc.Package, error) {
|
func (b *Builder) typeCheckPackage(pkgPath importPathString) (*tc.Package, error) {
|
||||||
glog.V(5).Infof("typeCheckPackage %s", pkgPath)
|
klog.V(5).Infof("typeCheckPackage %s", pkgPath)
|
||||||
if pkg, ok := b.typeCheckedPackages[pkgPath]; ok {
|
if pkg, ok := b.typeCheckedPackages[pkgPath]; ok {
|
||||||
if pkg != nil {
|
if pkg != nil {
|
||||||
glog.V(6).Infof("typeCheckPackage %s already done", pkgPath)
|
klog.V(6).Infof("typeCheckPackage %s already done", pkgPath)
|
||||||
return pkg, nil
|
return pkg, nil
|
||||||
}
|
}
|
||||||
// We store a nil right before starting work on a package. So
|
// We store a nil right before starting work on a package. So
|
||||||
@@ -416,7 +416,7 @@ func (b *Builder) typeCheckPackage(pkgPath importPathString) (*tc.Package, error
|
|||||||
// method. So there can't be cycles in the import graph.
|
// method. So there can't be cycles in the import graph.
|
||||||
Importer: importAdapter{b},
|
Importer: importAdapter{b},
|
||||||
Error: func(err error) {
|
Error: func(err error) {
|
||||||
glog.V(2).Infof("type checker: %v\n", err)
|
klog.V(2).Infof("type checker: %v\n", err)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pkg, err := c.Check(string(pkgPath), b.fset, files, nil)
|
pkg, err := c.Check(string(pkgPath), b.fset, files, nil)
|
||||||
@@ -469,7 +469,7 @@ func (b *Builder) FindTypes() (types.Universe, error) {
|
|||||||
// findTypesIn finalizes the package import and searches through the package
|
// findTypesIn finalizes the package import and searches through the package
|
||||||
// for types.
|
// for types.
|
||||||
func (b *Builder) findTypesIn(pkgPath importPathString, u *types.Universe) error {
|
func (b *Builder) findTypesIn(pkgPath importPathString, u *types.Universe) error {
|
||||||
glog.V(5).Infof("findTypesIn %s", pkgPath)
|
klog.V(5).Infof("findTypesIn %s", pkgPath)
|
||||||
pkg := b.typeCheckedPackages[pkgPath]
|
pkg := b.typeCheckedPackages[pkgPath]
|
||||||
if pkg == nil {
|
if pkg == nil {
|
||||||
return fmt.Errorf("findTypesIn(%s): package is not known", pkgPath)
|
return fmt.Errorf("findTypesIn(%s): package is not known", pkgPath)
|
||||||
@@ -479,7 +479,7 @@ func (b *Builder) findTypesIn(pkgPath importPathString, u *types.Universe) error
|
|||||||
// packages they asked for depend on will be included.
|
// packages they asked for depend on will be included.
|
||||||
// But we don't need to include all types in all
|
// But we don't need to include all types in all
|
||||||
// *packages* they depend on.
|
// *packages* they depend on.
|
||||||
glog.V(5).Infof("findTypesIn %s: package is not user requested", pkgPath)
|
klog.V(5).Infof("findTypesIn %s: package is not user requested", pkgPath)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -775,7 +775,7 @@ func (b *Builder) walkType(u types.Universe, useName *types.Name, in tc.Type) *t
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
out.Kind = types.Unsupported
|
out.Kind = types.Unsupported
|
||||||
glog.Warningf("Making unsupported type entry %q for: %#v\n", out, t)
|
klog.Warningf("Making unsupported type entry %q for: %#v\n", out, t)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -51,10 +51,10 @@ func ParseFullyQualifiedName(fqn string) Name {
|
|||||||
cs := strings.Split(fqn, ".")
|
cs := strings.Split(fqn, ".")
|
||||||
pkg := ""
|
pkg := ""
|
||||||
if len(cs) > 1 {
|
if len(cs) > 1 {
|
||||||
pkg = strings.Join(cs[0:len(cs) - 1], ".")
|
pkg = strings.Join(cs[0:len(cs)-1], ".")
|
||||||
}
|
}
|
||||||
return Name{
|
return Name{
|
||||||
Name: cs[len(cs) - 1],
|
Name: cs[len(cs)-1],
|
||||||
Package: pkg,
|
Package: pkg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
language: go
|
||||||
|
dist: xenial
|
||||||
|
go:
|
||||||
|
- 1.9.x
|
||||||
|
- 1.10.x
|
||||||
|
- 1.11.x
|
||||||
|
script:
|
||||||
|
- go get -t -v ./...
|
||||||
|
- diff -u <(echo -n) <(gofmt -d .)
|
||||||
|
- diff -u <(echo -n) <(golint $(go list -e ./...))
|
||||||
|
- go tool vet .
|
||||||
|
- go test -v -race ./...
|
||||||
|
install:
|
||||||
|
- go get golang.org/x/lint/golint
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
# Contributing Guidelines
|
||||||
|
|
||||||
|
Welcome to Kubernetes. We are excited about the prospect of you joining our [community](https://github.com/kubernetes/community)! The Kubernetes community abides by the CNCF [code of conduct](code-of-conduct.md). Here is an excerpt:
|
||||||
|
|
||||||
|
_As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities._
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
We have full documentation on how to get started contributing here:
|
||||||
|
|
||||||
|
<!---
|
||||||
|
If your repo has certain guidelines for contribution, put them here ahead of the general k8s resources
|
||||||
|
-->
|
||||||
|
|
||||||
|
- [Contributor License Agreement](https://git.k8s.io/community/CLA.md) Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests
|
||||||
|
- [Kubernetes Contributor Guide](http://git.k8s.io/community/contributors/guide) - Main contributor documentation, or you can just jump directly to the [contributing section](http://git.k8s.io/community/contributors/guide#contributing)
|
||||||
|
- [Contributor Cheat Sheet](https://git.k8s.io/community/contributors/guide/contributor-cheatsheet.md) - Common resources for existing developers
|
||||||
|
|
||||||
|
## Mentorship
|
||||||
|
|
||||||
|
- [Mentoring Initiatives](https://git.k8s.io/community/mentoring) - We have a diverse set of mentorship programs available that are always looking for volunteers!
|
||||||
|
|
||||||
|
<!---
|
||||||
|
Custom Information - if you're copying this template for the first time you can add custom content here, for example:
|
||||||
|
|
||||||
|
## Contact Information
|
||||||
|
|
||||||
|
- [Slack channel](https://kubernetes.slack.com/messages/kubernetes-users) - Replace `kubernetes-users` with your slack channel string, this will send users directly to your channel.
|
||||||
|
- [Mailing list](URL)
|
||||||
|
|
||||||
|
-->
|
||||||
Generated
Vendored
+11
@@ -0,0 +1,11 @@
|
|||||||
|
# See the OWNERS docs: https://git.k8s.io/community/contributors/guide/owners.md
|
||||||
|
|
||||||
|
approvers:
|
||||||
|
- dims
|
||||||
|
- thockin
|
||||||
|
- justinsb
|
||||||
|
- tallclair
|
||||||
|
- piosz
|
||||||
|
- brancz
|
||||||
|
- DirectXMan12
|
||||||
|
- lavalamp
|
||||||
Generated
Vendored
+8
-1
@@ -1,3 +1,10 @@
|
|||||||
|
klog
|
||||||
|
====
|
||||||
|
|
||||||
|
klog is a permanant fork of https://github.com/golang/glog. original README from glog is below
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
glog
|
glog
|
||||||
====
|
====
|
||||||
|
|
||||||
@@ -5,7 +12,7 @@ Leveled execution logs for Go.
|
|||||||
|
|
||||||
This is an efficient pure Go implementation of leveled logs in the
|
This is an efficient pure Go implementation of leveled logs in the
|
||||||
manner of the open source C++ package
|
manner of the open source C++ package
|
||||||
http://code.google.com/p/google-glog
|
https://github.com/google/glog
|
||||||
|
|
||||||
By binding methods to booleans it is possible to use the log package
|
By binding methods to booleans it is possible to use the log package
|
||||||
without paying the expense of evaluating the arguments to the log.
|
without paying the expense of evaluating the arguments to the log.
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
# Release Process
|
||||||
|
|
||||||
|
The `klog` is released on an as-needed basis. The process is as follows:
|
||||||
|
|
||||||
|
1. An issue is proposing a new release with a changelog since the last release
|
||||||
|
1. All [OWNERS](OWNERS) must LGTM this release
|
||||||
|
1. An OWNER runs `git tag -s $VERSION` and inserts the changelog and pushes the tag with `git push $VERSION`
|
||||||
|
1. The release issue is closed
|
||||||
|
1. An announcement email is sent to `kubernetes-dev@googlegroups.com` with the subject `[ANNOUNCE] kubernetes-template-project $VERSION is released`
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
# Defined below are the security contacts for this repo.
|
||||||
|
#
|
||||||
|
# They are the contact point for the Product Security Team to reach out
|
||||||
|
# to for triaging and handling of incoming issues.
|
||||||
|
#
|
||||||
|
# The below names agree to abide by the
|
||||||
|
# [Embargo Policy](https://github.com/kubernetes/sig-release/blob/master/security-release-process-documentation/security-release-process.md#embargo-policy)
|
||||||
|
# and will be removed and replaced if they violate that agreement.
|
||||||
|
#
|
||||||
|
# DO NOT REPORT SECURITY VULNERABILITIES DIRECTLY TO THESE NAMES, FOLLOW THE
|
||||||
|
# INSTRUCTIONS AT https://kubernetes.io/security/
|
||||||
|
|
||||||
|
dims
|
||||||
|
thockin
|
||||||
|
justinsb
|
||||||
|
tallclair
|
||||||
|
piosz
|
||||||
|
brancz
|
||||||
|
DirectXMan12
|
||||||
|
lavalamp
|
||||||
Generated
Vendored
+72
-10
@@ -14,7 +14,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup.
|
// Package klog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup.
|
||||||
// It provides functions Info, Warning, Error, Fatal, plus formatting variants such as
|
// 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.
|
// Infof. It also provides V-style logging controlled by the -v and -vmodule=file=2 flags.
|
||||||
//
|
//
|
||||||
@@ -68,7 +68,7 @@
|
|||||||
// -vmodule=gopher*=3
|
// -vmodule=gopher*=3
|
||||||
// sets the V level to 3 in all Go files whose names begin "gopher".
|
// sets the V level to 3 in all Go files whose names begin "gopher".
|
||||||
//
|
//
|
||||||
package glog
|
package klog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
@@ -396,13 +396,6 @@ type flushSyncWriter interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.BoolVar(&logging.toStderr, "logtostderr", false, "log to standard error instead of files")
|
|
||||||
flag.BoolVar(&logging.alsoToStderr, "alsologtostderr", false, "log to standard error as well as files")
|
|
||||||
flag.Var(&logging.verbosity, "v", "log level for V logs")
|
|
||||||
flag.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr")
|
|
||||||
flag.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging")
|
|
||||||
flag.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")
|
|
||||||
|
|
||||||
// Default stderrThreshold is ERROR.
|
// Default stderrThreshold is ERROR.
|
||||||
logging.stderrThreshold = errorLog
|
logging.stderrThreshold = errorLog
|
||||||
|
|
||||||
@@ -410,6 +403,22 @@ func init() {
|
|||||||
go logging.flushDaemon()
|
go logging.flushDaemon()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InitFlags is for explicitly initializing the flags
|
||||||
|
func InitFlags(flagset *flag.FlagSet) {
|
||||||
|
if flagset == nil {
|
||||||
|
flagset = flag.CommandLine
|
||||||
|
}
|
||||||
|
flagset.StringVar(&logging.logDir, "log_dir", "", "If non-empty, write log files in this directory")
|
||||||
|
flagset.StringVar(&logging.logFile, "log_file", "", "If non-empty, use this log file")
|
||||||
|
flagset.BoolVar(&logging.toStderr, "logtostderr", false, "log to standard error instead of files")
|
||||||
|
flagset.BoolVar(&logging.alsoToStderr, "alsologtostderr", false, "log to standard error as well as files")
|
||||||
|
flagset.Var(&logging.verbosity, "v", "log level for V logs")
|
||||||
|
flagset.BoolVar(&logging.skipHeaders, "skip_headers", false, "If true, avoid header prefixes in the log messages")
|
||||||
|
flagset.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr")
|
||||||
|
flagset.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging")
|
||||||
|
flagset.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")
|
||||||
|
}
|
||||||
|
|
||||||
// Flush flushes all pending log I/O.
|
// Flush flushes all pending log I/O.
|
||||||
func Flush() {
|
func Flush() {
|
||||||
logging.lockAndFlushAll()
|
logging.lockAndFlushAll()
|
||||||
@@ -453,6 +462,17 @@ type loggingT struct {
|
|||||||
// safely using atomic.LoadInt32.
|
// safely using atomic.LoadInt32.
|
||||||
vmodule moduleSpec // The state of the -vmodule flag.
|
vmodule moduleSpec // The state of the -vmodule flag.
|
||||||
verbosity Level // V logging level, the value of the -v flag/
|
verbosity Level // V logging level, the value of the -v flag/
|
||||||
|
|
||||||
|
// If non-empty, overrides the choice of directory in which to write logs.
|
||||||
|
// See createLogDirs for the full list of possible destinations.
|
||||||
|
logDir string
|
||||||
|
|
||||||
|
// If non-empty, specifies the path of the file to write logs. mutually exclusive
|
||||||
|
// with the log-dir option.
|
||||||
|
logFile string
|
||||||
|
|
||||||
|
// If true, do not add the prefix headers, useful when used with SetOutput
|
||||||
|
skipHeaders bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// buffer holds a byte Buffer for reuse. The zero value is ready for use.
|
// buffer holds a byte Buffer for reuse. The zero value is ready for use.
|
||||||
@@ -556,6 +576,9 @@ func (l *loggingT) formatHeader(s severity, file string, line int) *buffer {
|
|||||||
s = infoLog // for safety.
|
s = infoLog // for safety.
|
||||||
}
|
}
|
||||||
buf := l.getBuffer()
|
buf := l.getBuffer()
|
||||||
|
if l.skipHeaders {
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
|
||||||
// Avoid Fprintf, for speed. The format is so simple that we can do it quickly by hand.
|
// Avoid Fprintf, for speed. The format is so simple that we can do it quickly by hand.
|
||||||
// It's worth about 3X. Fprintf is hard.
|
// It's worth about 3X. Fprintf is hard.
|
||||||
@@ -667,6 +690,45 @@ func (l *loggingT) printWithFileLine(s severity, file string, line int, alsoToSt
|
|||||||
l.output(s, buf, file, line, alsoToStderr)
|
l.output(s, buf, file, line, alsoToStderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// redirectBuffer is used to set an alternate destination for the logs
|
||||||
|
type redirectBuffer struct {
|
||||||
|
w io.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rb *redirectBuffer) Sync() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rb *redirectBuffer) Flush() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rb *redirectBuffer) Write(bytes []byte) (n int, err error) {
|
||||||
|
return rb.w.Write(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOutput sets the output destination for all severities
|
||||||
|
func SetOutput(w io.Writer) {
|
||||||
|
for s := fatalLog; s >= infoLog; s-- {
|
||||||
|
rb := &redirectBuffer{
|
||||||
|
w: w,
|
||||||
|
}
|
||||||
|
logging.file[s] = rb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOutputBySeverity sets the output destination for specific severity
|
||||||
|
func SetOutputBySeverity(name string, w io.Writer) {
|
||||||
|
sev, ok := severityByName(name)
|
||||||
|
if !ok {
|
||||||
|
panic(fmt.Sprintf("SetOutputBySeverity(%q): unrecognized severity name", name))
|
||||||
|
}
|
||||||
|
rb := &redirectBuffer{
|
||||||
|
w: w,
|
||||||
|
}
|
||||||
|
logging.file[sev] = rb
|
||||||
|
}
|
||||||
|
|
||||||
// output writes the data to the log files and releases the buffer.
|
// output writes the data to the log files and releases the buffer.
|
||||||
func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoToStderr bool) {
|
func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoToStderr bool) {
|
||||||
l.mu.Lock()
|
l.mu.Lock()
|
||||||
@@ -876,7 +938,7 @@ const flushInterval = 30 * time.Second
|
|||||||
|
|
||||||
// flushDaemon periodically flushes the log file buffers.
|
// flushDaemon periodically flushes the log file buffers.
|
||||||
func (l *loggingT) flushDaemon() {
|
func (l *loggingT) flushDaemon() {
|
||||||
for _ = range time.NewTicker(flushInterval).C {
|
for range time.NewTicker(flushInterval).C {
|
||||||
l.lockAndFlushAll()
|
l.lockAndFlushAll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Generated
Vendored
+10
-8
@@ -16,11 +16,10 @@
|
|||||||
|
|
||||||
// File I/O for logs.
|
// File I/O for logs.
|
||||||
|
|
||||||
package glog
|
package klog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
@@ -36,13 +35,9 @@ var MaxSize uint64 = 1024 * 1024 * 1800
|
|||||||
// logDirs lists the candidate directories for new log files.
|
// logDirs lists the candidate directories for new log files.
|
||||||
var logDirs []string
|
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() {
|
func createLogDirs() {
|
||||||
if *logDir != "" {
|
if logging.logDir != "" {
|
||||||
logDirs = append(logDirs, *logDir)
|
logDirs = append(logDirs, logging.logDir)
|
||||||
}
|
}
|
||||||
logDirs = append(logDirs, os.TempDir())
|
logDirs = append(logDirs, os.TempDir())
|
||||||
}
|
}
|
||||||
@@ -103,6 +98,13 @@ var onceLogDirs sync.Once
|
|||||||
// successfully, create also attempts to update the symlink for that tag, ignoring
|
// successfully, create also attempts to update the symlink for that tag, ignoring
|
||||||
// errors.
|
// errors.
|
||||||
func create(tag string, t time.Time) (f *os.File, filename string, err error) {
|
func create(tag string, t time.Time) (f *os.File, filename string, err error) {
|
||||||
|
if logging.logFile != "" {
|
||||||
|
f, err := os.Create(logging.logFile)
|
||||||
|
if err == nil {
|
||||||
|
return f, logging.logFile, nil
|
||||||
|
}
|
||||||
|
return nil, "", fmt.Errorf("log: unable to create log: %v", err)
|
||||||
|
}
|
||||||
onceLogDirs.Do(createLogDirs)
|
onceLogDirs.Do(createLogDirs)
|
||||||
if len(logDirs) == 0 {
|
if len(logDirs) == 0 {
|
||||||
return nil, "", errors.New("log: no log dirs")
|
return nil, "", errors.New("log: no log dirs")
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
language: go
|
||||||
|
dist: xenial
|
||||||
|
go:
|
||||||
|
- 1.9.x
|
||||||
|
- 1.10.x
|
||||||
|
- 1.11.x
|
||||||
|
script:
|
||||||
|
- go get -t -v ./...
|
||||||
|
- diff -u <(echo -n) <(gofmt -d .)
|
||||||
|
- diff -u <(echo -n) <(golint $(go list -e ./...))
|
||||||
|
- go tool vet .
|
||||||
|
- go test -v -race ./...
|
||||||
|
install:
|
||||||
|
- go get golang.org/x/lint/golint
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
# Contributing Guidelines
|
||||||
|
|
||||||
|
Welcome to Kubernetes. We are excited about the prospect of you joining our [community](https://github.com/kubernetes/community)! The Kubernetes community abides by the CNCF [code of conduct](code-of-conduct.md). Here is an excerpt:
|
||||||
|
|
||||||
|
_As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities._
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
We have full documentation on how to get started contributing here:
|
||||||
|
|
||||||
|
<!---
|
||||||
|
If your repo has certain guidelines for contribution, put them here ahead of the general k8s resources
|
||||||
|
-->
|
||||||
|
|
||||||
|
- [Contributor License Agreement](https://git.k8s.io/community/CLA.md) Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests
|
||||||
|
- [Kubernetes Contributor Guide](http://git.k8s.io/community/contributors/guide) - Main contributor documentation, or you can just jump directly to the [contributing section](http://git.k8s.io/community/contributors/guide#contributing)
|
||||||
|
- [Contributor Cheat Sheet](https://git.k8s.io/community/contributors/guide/contributor-cheatsheet.md) - Common resources for existing developers
|
||||||
|
|
||||||
|
## Mentorship
|
||||||
|
|
||||||
|
- [Mentoring Initiatives](https://git.k8s.io/community/mentoring) - We have a diverse set of mentorship programs available that are always looking for volunteers!
|
||||||
|
|
||||||
|
<!---
|
||||||
|
Custom Information - if you're copying this template for the first time you can add custom content here, for example:
|
||||||
|
|
||||||
|
## Contact Information
|
||||||
|
|
||||||
|
- [Slack channel](https://kubernetes.slack.com/messages/kubernetes-users) - Replace `kubernetes-users` with your slack channel string, this will send users directly to your channel.
|
||||||
|
- [Mailing list](URL)
|
||||||
|
|
||||||
|
-->
|
||||||
Generated
Vendored
+11
@@ -0,0 +1,11 @@
|
|||||||
|
# See the OWNERS docs: https://git.k8s.io/community/contributors/guide/owners.md
|
||||||
|
|
||||||
|
approvers:
|
||||||
|
- dims
|
||||||
|
- thockin
|
||||||
|
- justinsb
|
||||||
|
- tallclair
|
||||||
|
- piosz
|
||||||
|
- brancz
|
||||||
|
- DirectXMan12
|
||||||
|
- lavalamp
|
||||||
Generated
Vendored
+8
-1
@@ -1,3 +1,10 @@
|
|||||||
|
klog
|
||||||
|
====
|
||||||
|
|
||||||
|
klog is a permanant fork of https://github.com/golang/glog. original README from glog is below
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
glog
|
glog
|
||||||
====
|
====
|
||||||
|
|
||||||
@@ -5,7 +12,7 @@ Leveled execution logs for Go.
|
|||||||
|
|
||||||
This is an efficient pure Go implementation of leveled logs in the
|
This is an efficient pure Go implementation of leveled logs in the
|
||||||
manner of the open source C++ package
|
manner of the open source C++ package
|
||||||
http://code.google.com/p/google-glog
|
https://github.com/google/glog
|
||||||
|
|
||||||
By binding methods to booleans it is possible to use the log package
|
By binding methods to booleans it is possible to use the log package
|
||||||
without paying the expense of evaluating the arguments to the log.
|
without paying the expense of evaluating the arguments to the log.
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
# Release Process
|
||||||
|
|
||||||
|
The `klog` is released on an as-needed basis. The process is as follows:
|
||||||
|
|
||||||
|
1. An issue is proposing a new release with a changelog since the last release
|
||||||
|
1. All [OWNERS](OWNERS) must LGTM this release
|
||||||
|
1. An OWNER runs `git tag -s $VERSION` and inserts the changelog and pushes the tag with `git push $VERSION`
|
||||||
|
1. The release issue is closed
|
||||||
|
1. An announcement email is sent to `kubernetes-dev@googlegroups.com` with the subject `[ANNOUNCE] kubernetes-template-project $VERSION is released`
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
# Defined below are the security contacts for this repo.
|
||||||
|
#
|
||||||
|
# They are the contact point for the Product Security Team to reach out
|
||||||
|
# to for triaging and handling of incoming issues.
|
||||||
|
#
|
||||||
|
# The below names agree to abide by the
|
||||||
|
# [Embargo Policy](https://github.com/kubernetes/sig-release/blob/master/security-release-process-documentation/security-release-process.md#embargo-policy)
|
||||||
|
# and will be removed and replaced if they violate that agreement.
|
||||||
|
#
|
||||||
|
# DO NOT REPORT SECURITY VULNERABILITIES DIRECTLY TO THESE NAMES, FOLLOW THE
|
||||||
|
# INSTRUCTIONS AT https://kubernetes.io/security/
|
||||||
|
|
||||||
|
dims
|
||||||
|
thockin
|
||||||
|
justinsb
|
||||||
|
tallclair
|
||||||
|
piosz
|
||||||
|
brancz
|
||||||
|
DirectXMan12
|
||||||
|
lavalamp
|
||||||
+72
-10
@@ -14,7 +14,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup.
|
// Package klog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup.
|
||||||
// It provides functions Info, Warning, Error, Fatal, plus formatting variants such as
|
// 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.
|
// Infof. It also provides V-style logging controlled by the -v and -vmodule=file=2 flags.
|
||||||
//
|
//
|
||||||
@@ -68,7 +68,7 @@
|
|||||||
// -vmodule=gopher*=3
|
// -vmodule=gopher*=3
|
||||||
// sets the V level to 3 in all Go files whose names begin "gopher".
|
// sets the V level to 3 in all Go files whose names begin "gopher".
|
||||||
//
|
//
|
||||||
package glog
|
package klog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
@@ -396,13 +396,6 @@ type flushSyncWriter interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.BoolVar(&logging.toStderr, "logtostderr", false, "log to standard error instead of files")
|
|
||||||
flag.BoolVar(&logging.alsoToStderr, "alsologtostderr", false, "log to standard error as well as files")
|
|
||||||
flag.Var(&logging.verbosity, "v", "log level for V logs")
|
|
||||||
flag.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr")
|
|
||||||
flag.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging")
|
|
||||||
flag.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")
|
|
||||||
|
|
||||||
// Default stderrThreshold is ERROR.
|
// Default stderrThreshold is ERROR.
|
||||||
logging.stderrThreshold = errorLog
|
logging.stderrThreshold = errorLog
|
||||||
|
|
||||||
@@ -410,6 +403,22 @@ func init() {
|
|||||||
go logging.flushDaemon()
|
go logging.flushDaemon()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InitFlags is for explicitly initializing the flags
|
||||||
|
func InitFlags(flagset *flag.FlagSet) {
|
||||||
|
if flagset == nil {
|
||||||
|
flagset = flag.CommandLine
|
||||||
|
}
|
||||||
|
flagset.StringVar(&logging.logDir, "log_dir", "", "If non-empty, write log files in this directory")
|
||||||
|
flagset.StringVar(&logging.logFile, "log_file", "", "If non-empty, use this log file")
|
||||||
|
flagset.BoolVar(&logging.toStderr, "logtostderr", false, "log to standard error instead of files")
|
||||||
|
flagset.BoolVar(&logging.alsoToStderr, "alsologtostderr", false, "log to standard error as well as files")
|
||||||
|
flagset.Var(&logging.verbosity, "v", "log level for V logs")
|
||||||
|
flagset.BoolVar(&logging.skipHeaders, "skip_headers", false, "If true, avoid header prefixes in the log messages")
|
||||||
|
flagset.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr")
|
||||||
|
flagset.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging")
|
||||||
|
flagset.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")
|
||||||
|
}
|
||||||
|
|
||||||
// Flush flushes all pending log I/O.
|
// Flush flushes all pending log I/O.
|
||||||
func Flush() {
|
func Flush() {
|
||||||
logging.lockAndFlushAll()
|
logging.lockAndFlushAll()
|
||||||
@@ -453,6 +462,17 @@ type loggingT struct {
|
|||||||
// safely using atomic.LoadInt32.
|
// safely using atomic.LoadInt32.
|
||||||
vmodule moduleSpec // The state of the -vmodule flag.
|
vmodule moduleSpec // The state of the -vmodule flag.
|
||||||
verbosity Level // V logging level, the value of the -v flag/
|
verbosity Level // V logging level, the value of the -v flag/
|
||||||
|
|
||||||
|
// If non-empty, overrides the choice of directory in which to write logs.
|
||||||
|
// See createLogDirs for the full list of possible destinations.
|
||||||
|
logDir string
|
||||||
|
|
||||||
|
// If non-empty, specifies the path of the file to write logs. mutually exclusive
|
||||||
|
// with the log-dir option.
|
||||||
|
logFile string
|
||||||
|
|
||||||
|
// If true, do not add the prefix headers, useful when used with SetOutput
|
||||||
|
skipHeaders bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// buffer holds a byte Buffer for reuse. The zero value is ready for use.
|
// buffer holds a byte Buffer for reuse. The zero value is ready for use.
|
||||||
@@ -556,6 +576,9 @@ func (l *loggingT) formatHeader(s severity, file string, line int) *buffer {
|
|||||||
s = infoLog // for safety.
|
s = infoLog // for safety.
|
||||||
}
|
}
|
||||||
buf := l.getBuffer()
|
buf := l.getBuffer()
|
||||||
|
if l.skipHeaders {
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
|
||||||
// Avoid Fprintf, for speed. The format is so simple that we can do it quickly by hand.
|
// Avoid Fprintf, for speed. The format is so simple that we can do it quickly by hand.
|
||||||
// It's worth about 3X. Fprintf is hard.
|
// It's worth about 3X. Fprintf is hard.
|
||||||
@@ -667,6 +690,45 @@ func (l *loggingT) printWithFileLine(s severity, file string, line int, alsoToSt
|
|||||||
l.output(s, buf, file, line, alsoToStderr)
|
l.output(s, buf, file, line, alsoToStderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// redirectBuffer is used to set an alternate destination for the logs
|
||||||
|
type redirectBuffer struct {
|
||||||
|
w io.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rb *redirectBuffer) Sync() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rb *redirectBuffer) Flush() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rb *redirectBuffer) Write(bytes []byte) (n int, err error) {
|
||||||
|
return rb.w.Write(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOutput sets the output destination for all severities
|
||||||
|
func SetOutput(w io.Writer) {
|
||||||
|
for s := fatalLog; s >= infoLog; s-- {
|
||||||
|
rb := &redirectBuffer{
|
||||||
|
w: w,
|
||||||
|
}
|
||||||
|
logging.file[s] = rb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOutputBySeverity sets the output destination for specific severity
|
||||||
|
func SetOutputBySeverity(name string, w io.Writer) {
|
||||||
|
sev, ok := severityByName(name)
|
||||||
|
if !ok {
|
||||||
|
panic(fmt.Sprintf("SetOutputBySeverity(%q): unrecognized severity name", name))
|
||||||
|
}
|
||||||
|
rb := &redirectBuffer{
|
||||||
|
w: w,
|
||||||
|
}
|
||||||
|
logging.file[sev] = rb
|
||||||
|
}
|
||||||
|
|
||||||
// output writes the data to the log files and releases the buffer.
|
// output writes the data to the log files and releases the buffer.
|
||||||
func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoToStderr bool) {
|
func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoToStderr bool) {
|
||||||
l.mu.Lock()
|
l.mu.Lock()
|
||||||
@@ -876,7 +938,7 @@ const flushInterval = 30 * time.Second
|
|||||||
|
|
||||||
// flushDaemon periodically flushes the log file buffers.
|
// flushDaemon periodically flushes the log file buffers.
|
||||||
func (l *loggingT) flushDaemon() {
|
func (l *loggingT) flushDaemon() {
|
||||||
for _ = range time.NewTicker(flushInterval).C {
|
for range time.NewTicker(flushInterval).C {
|
||||||
l.lockAndFlushAll()
|
l.lockAndFlushAll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+10
-8
@@ -16,11 +16,10 @@
|
|||||||
|
|
||||||
// File I/O for logs.
|
// File I/O for logs.
|
||||||
|
|
||||||
package glog
|
package klog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
@@ -36,13 +35,9 @@ var MaxSize uint64 = 1024 * 1024 * 1800
|
|||||||
// logDirs lists the candidate directories for new log files.
|
// logDirs lists the candidate directories for new log files.
|
||||||
var logDirs []string
|
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() {
|
func createLogDirs() {
|
||||||
if *logDir != "" {
|
if logging.logDir != "" {
|
||||||
logDirs = append(logDirs, *logDir)
|
logDirs = append(logDirs, logging.logDir)
|
||||||
}
|
}
|
||||||
logDirs = append(logDirs, os.TempDir())
|
logDirs = append(logDirs, os.TempDir())
|
||||||
}
|
}
|
||||||
@@ -103,6 +98,13 @@ var onceLogDirs sync.Once
|
|||||||
// successfully, create also attempts to update the symlink for that tag, ignoring
|
// successfully, create also attempts to update the symlink for that tag, ignoring
|
||||||
// errors.
|
// errors.
|
||||||
func create(tag string, t time.Time) (f *os.File, filename string, err error) {
|
func create(tag string, t time.Time) (f *os.File, filename string, err error) {
|
||||||
|
if logging.logFile != "" {
|
||||||
|
f, err := os.Create(logging.logFile)
|
||||||
|
if err == nil {
|
||||||
|
return f, logging.logFile, nil
|
||||||
|
}
|
||||||
|
return nil, "", fmt.Errorf("log: unable to create log: %v", err)
|
||||||
|
}
|
||||||
onceLogDirs.Do(createLogDirs)
|
onceLogDirs.Do(createLogDirs)
|
||||||
if len(logDirs) == 0 {
|
if len(logDirs) == 0 {
|
||||||
return nil, "", errors.New("log: no log dirs")
|
return nil, "", errors.New("log: no log dirs")
|
||||||
Reference in New Issue
Block a user