Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
72962889
Commit
72962889
authored
Jan 18, 2019
by
Yassine TIJANI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor util functions for event recording
parent
76961c51
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
100 additions
and
25 deletions
+100
-25
Godeps.json
...ing/src/k8s.io/apiextensions-apiserver/Godeps/Godeps.json
+4
-0
Godeps.json
staging/src/k8s.io/apiserver/Godeps/Godeps.json
+4
-0
BUILD
staging/src/k8s.io/client-go/tools/record/BUILD
+5
-1
event.go
staging/src/k8s.io/client-go/tools/record/event.go
+4
-24
BUILD
staging/src/k8s.io/client-go/tools/record/util/BUILD
+27
-0
util.go
staging/src/k8s.io/client-go/tools/record/util/util.go
+44
-0
Godeps.json
staging/src/k8s.io/kube-aggregator/Godeps/Godeps.json
+4
-0
Godeps.json
staging/src/k8s.io/sample-apiserver/Godeps/Godeps.json
+4
-0
Godeps.json
staging/src/k8s.io/sample-controller/Godeps/Godeps.json
+4
-0
No files found.
staging/src/k8s.io/apiextensions-apiserver/Godeps/Godeps.json
View file @
72962889
...
...
@@ -2227,6 +2227,10 @@
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath"
:
"k8s.io/client-go/tools/record/util"
,
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath"
:
"k8s.io/client-go/tools/reference"
,
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
...
...
staging/src/k8s.io/apiserver/Godeps/Godeps.json
View file @
72962889
...
...
@@ -1927,6 +1927,10 @@
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath"
:
"k8s.io/client-go/tools/record/util"
,
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath"
:
"k8s.io/client-go/tools/reference"
,
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
...
...
staging/src/k8s.io/client-go/tools/record/BUILD
View file @
72962889
...
...
@@ -48,6 +48,7 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/util/strategicpatch:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
"//staging/src/k8s.io/client-go/rest:go_default_library",
"//staging/src/k8s.io/client-go/tools/record/util:go_default_library",
"//staging/src/k8s.io/client-go/tools/reference:go_default_library",
"//staging/src/k8s.io/client-go/util/flowcontrol:go_default_library",
"//vendor/github.com/golang/groupcache/lru:go_default_library",
...
...
@@ -64,6 +65,9 @@ filegroup(
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
srcs = [
":package-srcs",
"//staging/src/k8s.io/client-go/tools/record/util:all-srcs",
],
tags = ["automanaged"],
)
staging/src/k8s.io/client-go/tools/record/event.go
View file @
72962889
...
...
@@ -21,7 +21,7 @@ import (
"math/rand"
"time"
"k8s.io/api/core/v1"
v1
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
...
...
@@ -29,10 +29,8 @@ import (
utilruntime
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
restclient
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/record/util"
ref
"k8s.io/client-go/tools/reference"
"net/http"
"k8s.io/klog"
)
...
...
@@ -157,16 +155,6 @@ func recordToSink(sink EventSink, event *v1.Event, eventCorrelator *EventCorrela
}
}
func
isKeyNotFoundError
(
err
error
)
bool
{
statusErr
,
_
:=
err
.
(
*
errors
.
StatusError
)
if
statusErr
!=
nil
&&
statusErr
.
Status
()
.
Code
==
http
.
StatusNotFound
{
return
true
}
return
false
}
// recordEvent attempts to write event to a sink. It returns true if the event
// was successfully recorded or discarded, false if it should be retried.
// If updateExistingEvent is false, it creates a new event, otherwise it updates
...
...
@@ -178,7 +166,7 @@ func recordEvent(sink EventSink, event *v1.Event, patch []byte, updateExistingEv
newEvent
,
err
=
sink
.
Patch
(
event
,
patch
)
}
// Update can fail because the event may have been removed and it no longer exists.
if
!
updateExistingEvent
||
(
updateExistingEvent
&&
i
sKeyNotFoundError
(
err
))
{
if
!
updateExistingEvent
||
(
updateExistingEvent
&&
util
.
I
sKeyNotFoundError
(
err
))
{
// Making sure that ResourceVersion is empty on creation
event
.
ResourceVersion
=
""
newEvent
,
err
=
sink
.
Create
(
event
)
...
...
@@ -260,7 +248,7 @@ func (recorder *recorderImpl) generateEvent(object runtime.Object, annotations m
return
}
if
!
v
alidateEventType
(
eventtype
)
{
if
!
util
.
V
alidateEventType
(
eventtype
)
{
klog
.
Errorf
(
"Unsupported event type: '%v'"
,
eventtype
)
return
}
...
...
@@ -275,14 +263,6 @@ func (recorder *recorderImpl) generateEvent(object runtime.Object, annotations m
}()
}
func
validateEventType
(
eventtype
string
)
bool
{
switch
eventtype
{
case
v1
.
EventTypeNormal
,
v1
.
EventTypeWarning
:
return
true
}
return
false
}
func
(
recorder
*
recorderImpl
)
Event
(
object
runtime
.
Object
,
eventtype
,
reason
,
message
string
)
{
recorder
.
generateEvent
(
object
,
nil
,
metav1
.
Now
(),
eventtype
,
reason
,
message
)
}
...
...
staging/src/k8s.io/client-go/tools/record/util/BUILD
0 → 100644
View file @
72962889
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["util.go"],
importmap = "k8s.io/kubernetes/vendor/k8s.io/client-go/tools/record/util",
importpath = "k8s.io/client-go/tools/record/util",
visibility = ["//visibility:public"],
deps = [
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
staging/src/k8s.io/client-go/tools/record/util/util.go
0 → 100644
View file @
72962889
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
util
import
(
"net/http"
v1
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
)
// ValidateEventType checks that eventtype is an expected type of event
func
ValidateEventType
(
eventtype
string
)
bool
{
switch
eventtype
{
case
v1
.
EventTypeNormal
,
v1
.
EventTypeWarning
:
return
true
}
return
false
}
// IsKeyNotFoundError is utility function that checks if an error is not found error
func
IsKeyNotFoundError
(
err
error
)
bool
{
statusErr
,
_
:=
err
.
(
*
errors
.
StatusError
)
if
statusErr
!=
nil
&&
statusErr
.
Status
()
.
Code
==
http
.
StatusNotFound
{
return
true
}
return
false
}
staging/src/k8s.io/kube-aggregator/Godeps/Godeps.json
View file @
72962889
...
...
@@ -1787,6 +1787,10 @@
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath"
:
"k8s.io/client-go/tools/record/util"
,
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath"
:
"k8s.io/client-go/tools/reference"
,
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
...
...
staging/src/k8s.io/sample-apiserver/Godeps/Godeps.json
View file @
72962889
...
...
@@ -1747,6 +1747,10 @@
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath"
:
"k8s.io/client-go/tools/record/util"
,
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath"
:
"k8s.io/client-go/tools/reference"
,
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
...
...
staging/src/k8s.io/sample-controller/Godeps/Godeps.json
View file @
72962889
...
...
@@ -1131,6 +1131,10 @@
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath"
:
"k8s.io/client-go/tools/record/util"
,
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath"
:
"k8s.io/client-go/tools/reference"
,
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment