Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Crane
Commits
c1cf43f1
Commit
c1cf43f1
authored
3 years ago
by
devinyan
Browse files
Options
Download
Email Patches
Plain Diff
bugfix: modify clogs to log
parent
26ae8a5e
Changes
27
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
Makefile
+2
-2
Makefile
cmd/crane-agent/app/manager.go
+12
-29
cmd/crane-agent/app/manager.go
cmd/crane-agent/main.go
+2
-2
cmd/crane-agent/main.go
cmd/craned/app/manager.go
+4
-3
cmd/craned/app/manager.go
docs/20211118how_to_logging.md
+9
-9
docs/20211118how_to_logging.md
go.mod
+21
-25
go.mod
go.sum
+12
-138
go.sum
pkg/controller/ensurance/nodeqosensurancepolicy_controller.go
+0
-154
...controller/ensurance/nodeqosensurancepolicy_controller.go
pkg/controller/ensurance/podqosensurancepolicy_controller.go
+0
-62
pkg/controller/ensurance/podqosensurancepolicy_controller.go
pkg/ensurance/analyzer/analyzer.go
+17
-17
pkg/ensurance/analyzer/analyzer.go
pkg/ensurance/avoidance/avoidance.go
+6
-6
pkg/ensurance/avoidance/avoidance.go
pkg/ensurance/cache/nep.go
+0
-12
pkg/ensurance/cache/nep.go
pkg/ensurance/executor/evict.go
+4
-4
pkg/ensurance/executor/evict.go
pkg/ensurance/executor/schedule.go
+5
-5
pkg/ensurance/executor/schedule.go
pkg/ensurance/grpcc/connection.go
+5
-5
pkg/ensurance/grpcc/connection.go
pkg/ensurance/informer/factory.go
+4
-4
pkg/ensurance/informer/factory.go
pkg/ensurance/informer/node.go
+3
-3
pkg/ensurance/informer/node.go
pkg/ensurance/informer/pod.go
+2
-10
pkg/ensurance/informer/pod.go
pkg/ensurance/runtime/container.go
+8
-20
pkg/ensurance/runtime/container.go
pkg/ensurance/runtime/runtime.go
+5
-5
pkg/ensurance/runtime/runtime.go
with
121 additions
and
515 deletions
+121
-515
Makefile
+
2
-
2
View file @
c1cf43f1
...
@@ -107,10 +107,10 @@ test: manifests fmt vet goimports ## Run tests.
...
@@ -107,10 +107,10 @@ test: manifests fmt vet goimports ## Run tests.
.PHONY
:
build
.PHONY
:
build
build
:
craned metric-adapter
build
:
craned
crane-agent
metric-adapter
.PHONY
:
all
.PHONY
:
all
all
:
test lint vet craned crane-agentmetric-adapter
all
:
test lint vet craned crane-agent
metric-adapter
.PHONY
:
craned
.PHONY
:
craned
craned
:
##
Build binary with the crane manager.
craned
:
##
Build binary with the crane manager.
...
...
This diff is collapsed.
Click to expand it.
cmd/crane-agent/app/manager.go
+
12
-
29
View file @
c1cf43f1
...
@@ -4,7 +4,6 @@ import (
...
@@ -4,7 +4,6 @@ import (
"context"
"context"
"flag"
"flag"
"fmt"
"fmt"
"github.com/gocrane/crane/pkg/ensurance/cache"
"os"
"os"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
...
@@ -18,14 +17,13 @@ import (
...
@@ -18,14 +17,13 @@ import (
ensuaranceapi
"github.com/gocrane/api/ensurance/v1alpha1"
ensuaranceapi
"github.com/gocrane/api/ensurance/v1alpha1"
ensuaranceset
"github.com/gocrane/api/pkg/generated/clientset/versioned"
ensuaranceset
"github.com/gocrane/api/pkg/generated/clientset/versioned"
"github.com/gocrane/crane/cmd/crane-agent/app/options"
"github.com/gocrane/crane/cmd/crane-agent/app/options"
ensurancecontroller
"github.com/gocrane/crane/pkg/controller/ensurance"
"github.com/gocrane/crane/pkg/ensurance/analyzer"
"github.com/gocrane/crane/pkg/ensurance/analyzer"
"github.com/gocrane/crane/pkg/ensurance/avoidance"
"github.com/gocrane/crane/pkg/ensurance/avoidance"
"github.com/gocrane/crane/pkg/ensurance/executor"
"github.com/gocrane/crane/pkg/ensurance/executor"
einformer
"github.com/gocrane/crane/pkg/ensurance/informer"
einformer
"github.com/gocrane/crane/pkg/ensurance/informer"
"github.com/gocrane/crane/pkg/ensurance/manager"
"github.com/gocrane/crane/pkg/ensurance/manager"
"github.com/gocrane/crane/pkg/ensurance/statestore"
"github.com/gocrane/crane/pkg/ensurance/statestore"
"github.com/gocrane/crane/pkg/utils/
c
log
s
"
"github.com/gocrane/crane/pkg/utils/log"
)
)
var
(
var
(
...
@@ -47,11 +45,11 @@ func NewManagerCommand(ctx context.Context) *cobra.Command {
...
@@ -47,11 +45,11 @@ func NewManagerCommand(ctx context.Context) *cobra.Command {
Long
:
`The crane agent is responsible agent in crane`
,
Long
:
`The crane agent is responsible agent in crane`
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
err
:=
opts
.
Complete
();
err
!=
nil
{
if
err
:=
opts
.
Complete
();
err
!=
nil
{
c
log
s
.
Log
()
.
Error
(
err
,
"opts complete failed,exit"
)
log
.
Log
ger
()
.
Error
(
err
,
"opts complete failed,exit"
)
os
.
Exit
(
255
)
os
.
Exit
(
255
)
}
}
if
err
:=
opts
.
Validate
();
err
!=
nil
{
if
err
:=
opts
.
Validate
();
err
!=
nil
{
c
log
s
.
Log
()
.
Error
(
err
,
"opts validate failed,exit"
)
log
.
Log
ger
()
.
Error
(
err
,
"opts validate failed,exit"
)
os
.
Exit
(
255
)
os
.
Exit
(
255
)
}
}
...
@@ -78,21 +76,21 @@ func Run(ctx context.Context, opts *options.Options) error {
...
@@ -78,21 +76,21 @@ func Run(ctx context.Context, opts *options.Options) error {
LeaderElection
:
false
,
LeaderElection
:
false
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
c
log
s
.
Log
()
.
Error
(
err
,
"Unable to start crane agent"
)
log
.
Log
ger
()
.
Error
(
err
,
"Unable to start crane agent"
)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
if
err
:=
mgr
.
AddHealthzCheck
(
"ping"
,
healthz
.
Ping
);
err
!=
nil
{
if
err
:=
mgr
.
AddHealthzCheck
(
"ping"
,
healthz
.
Ping
);
err
!=
nil
{
c
log
s
.
Log
()
.
Error
(
err
,
"Failed to add health check endpoint"
)
log
.
Log
ger
()
.
Error
(
err
,
"Failed to add health check endpoint"
)
return
err
return
err
}
}
if
opts
.
HostnameOverride
==
""
{
if
opts
.
HostnameOverride
==
""
{
c
log
s
.
Log
()
.
Error
(
err
,
"HostnameOverride must be set as the k8s node name"
)
log
.
Log
ger
()
.
Error
(
err
,
"HostnameOverride must be set as the k8s node name"
)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"opts %v"
,
opts
))
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"opts %v"
,
opts
))
// init context
// init context
ec
:=
initializationContext
(
mgr
,
opts
)
ec
:=
initializationContext
(
mgr
,
opts
)
...
@@ -103,13 +101,13 @@ func Run(ctx context.Context, opts *options.Options) error {
...
@@ -103,13 +101,13 @@ func Run(ctx context.Context, opts *options.Options) error {
// start managers
// start managers
for
_
,
v
:=
range
components
{
for
_
,
v
:=
range
components
{
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"Starting manager %s"
,
v
.
Name
()))
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"Starting manager %s"
,
v
.
Name
()))
v
.
Run
(
ec
.
GetStopChannel
())
v
.
Run
(
ec
.
GetStopChannel
())
}
}
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
"Starting crane agent"
)
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
"Starting crane agent"
)
if
err
:=
mgr
.
Start
(
ctx
);
err
!=
nil
{
if
err
:=
mgr
.
Start
(
ctx
);
err
!=
nil
{
c
log
s
.
Log
()
.
Error
(
err
,
"problem running crane manager"
)
log
.
Log
ger
()
.
Error
(
err
,
"problem running crane manager"
)
return
err
return
err
}
}
...
@@ -117,7 +115,7 @@ func Run(ctx context.Context, opts *options.Options) error {
...
@@ -117,7 +115,7 @@ func Run(ctx context.Context, opts *options.Options) error {
}
}
func
initializationComponents
(
mgr
ctrl
.
Manager
,
opts
*
options
.
Options
,
ec
*
einformer
.
Context
)
[]
manager
.
Manager
{
func
initializationComponents
(
mgr
ctrl
.
Manager
,
opts
*
options
.
Options
,
ec
*
einformer
.
Context
)
[]
manager
.
Manager
{
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"initializationComponents"
))
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"initializationComponents"
))
var
managers
[]
manager
.
Manager
var
managers
[]
manager
.
Manager
podInformer
:=
ec
.
GetPodInformer
()
podInformer
:=
ec
.
GetPodInformer
()
...
@@ -140,26 +138,11 @@ func initializationComponents(mgr ctrl.Manager, opts *options.Options, ec *einfo
...
@@ -140,26 +138,11 @@ func initializationComponents(mgr ctrl.Manager, opts *options.Options, ec *einfo
avoidanceManager
:=
avoidance
.
NewAvoidanceManager
(
ec
.
GetKubeClient
(),
opts
.
HostnameOverride
,
podInformer
,
nodeInformer
,
avoidanceInformer
,
noticeCh
)
avoidanceManager
:=
avoidance
.
NewAvoidanceManager
(
ec
.
GetKubeClient
(),
opts
.
HostnameOverride
,
podInformer
,
nodeInformer
,
avoidanceInformer
,
noticeCh
)
managers
=
append
(
managers
,
avoidanceManager
)
managers
=
append
(
managers
,
avoidanceManager
)
// init nep controller
nepRecorder
:=
mgr
.
GetEventRecorderFor
(
"node-qos-controller"
)
if
err
:=
(
&
ensurancecontroller
.
NodeQOSEnsurancePolicyController
{
Client
:
mgr
.
GetClient
(),
Log
:
clogs
.
Log
()
.
WithName
(
"node-qos-controller"
),
Scheme
:
mgr
.
GetScheme
(),
RestMapper
:
mgr
.
GetRESTMapper
(),
Recorder
:
nepRecorder
,
Cache
:
&
cache
.
NodeQOSEnsurancePolicyCache
{},
StateStore
:
stateStoreManager
,
})
.
SetupWithManager
(
mgr
);
err
!=
nil
{
clogs
.
Log
()
.
Error
(
err
,
"unable to create controller"
,
"controller"
,
"NodeQOSEnsurancePolicyController"
)
os
.
Exit
(
1
)
}
return
managers
return
managers
}
}
func
initializationContext
(
mgr
ctrl
.
Manager
,
opts
*
options
.
Options
)
*
einformer
.
Context
{
func
initializationContext
(
mgr
ctrl
.
Manager
,
opts
*
options
.
Options
)
*
einformer
.
Context
{
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"initializationContext"
))
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"initializationContext"
))
generatedClient
:=
kubernetes
.
NewForConfigOrDie
(
mgr
.
GetConfig
())
generatedClient
:=
kubernetes
.
NewForConfigOrDie
(
mgr
.
GetConfig
())
clientSet
:=
ensuaranceset
.
NewForConfigOrDie
(
mgr
.
GetConfig
())
clientSet
:=
ensuaranceset
.
NewForConfigOrDie
(
mgr
.
GetConfig
())
...
...
This diff is collapsed.
Click to expand it.
cmd/crane-agent/main.go
+
2
-
2
View file @
c1cf43f1
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
"k8s.io/component-base/logs"
"k8s.io/component-base/logs"
"github.com/gocrane/crane/cmd/crane-agent/app"
"github.com/gocrane/crane/cmd/crane-agent/app"
"github.com/gocrane/crane/pkg/utils/
c
log
s
"
"github.com/gocrane/crane/pkg/utils/log"
)
)
// crane-agent main.
// crane-agent main.
...
@@ -16,7 +16,7 @@ func main() {
...
@@ -16,7 +16,7 @@ func main() {
logs
.
InitLogs
()
logs
.
InitLogs
()
defer
logs
.
FlushLogs
()
defer
logs
.
FlushLogs
()
c
log
s
.
Init
Logs
(
"crane-agent"
)
log
.
Init
(
"crane-agent"
)
ctx
:=
genericapiserver
.
SetupSignalContext
()
ctx
:=
genericapiserver
.
SetupSignalContext
()
...
...
This diff is collapsed.
Click to expand it.
cmd/craned/app/manager.go
+
4
-
3
View file @
c1cf43f1
...
@@ -4,8 +4,6 @@ import (
...
@@ -4,8 +4,6 @@ import (
"context"
"context"
"flag"
"flag"
"fmt"
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
utilruntime
"k8s.io/apimachinery/pkg/util/runtime"
utilruntime
"k8s.io/apimachinery/pkg/util/runtime"
...
@@ -13,6 +11,7 @@ import (
...
@@ -13,6 +11,7 @@ import (
"k8s.io/client-go/dynamic"
"k8s.io/client-go/dynamic"
clientgoscheme
"k8s.io/client-go/kubernetes/scheme"
clientgoscheme
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/scale"
"k8s.io/client-go/scale"
"os"
ctrl
"sigs.k8s.io/controller-runtime"
ctrl
"sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/healthz"
...
@@ -115,7 +114,6 @@ func initializationWebhooks(mgr ctrl.Manager, opts *options.Options) {
...
@@ -115,7 +114,6 @@ func initializationWebhooks(mgr ctrl.Manager, opts *options.Options) {
}
}
// initializationControllers setup controllers with manager
// initializationControllers setup controllers with manager
<<<<<<<
HEAD
func
initializationControllers
(
ctx
context
.
Context
,
mgr
ctrl
.
Manager
,
opts
*
options
.
Options
)
{
func
initializationControllers
(
ctx
context
.
Context
,
mgr
ctrl
.
Manager
,
opts
*
options
.
Options
)
{
log
.
Logger
()
.
Info
(
fmt
.
Sprintf
(
"opts %v"
,
opts
))
log
.
Logger
()
.
Info
(
fmt
.
Sprintf
(
"opts %v"
,
opts
))
...
@@ -145,6 +143,7 @@ func initializationControllers(ctx context.Context, mgr ctrl.Manager, opts *opti
...
@@ -145,6 +143,7 @@ func initializationControllers(ctx context.Context, mgr ctrl.Manager, opts *opti
}
}
if
err
:=
(
&
ehpa
.
SubstituteController
{
if
err
:=
(
&
ehpa
.
SubstituteController
{
<<<<<<<
HEAD
<<<<<<<
HEAD
<<<<<<<
HEAD
Client
:
mgr
.
GetClient
(),
Client
:
mgr
.
GetClient
(),
Log
:
log
.
Logger
()
.
WithName
(
"substitute-controller"
),
Log
:
log
.
Logger
()
.
WithName
(
"substitute-controller"
),
...
@@ -159,6 +158,8 @@ func initializationControllers(mgr ctrl.Manager, opts *options.Options) {
...
@@ -159,6 +158,8 @@ func initializationControllers(mgr ctrl.Manager, opts *options.Options) {
hpaRecorder
:=
mgr
.
GetEventRecorderFor
(
"advanced-hpa-controller"
)
hpaRecorder
:=
mgr
.
GetEventRecorderFor
(
"advanced-hpa-controller"
)
if
err
:=
(
&
hpa
.
AdvancedHPAController
{
if
err
:=
(
&
hpa
.
AdvancedHPAController
{
>>>>>>>
3
c489e2
(
the
first
commit
for
ensurance
,
add
node
-
qos
-
controller
,
collect
,
analyzer
and
avoidance
)
>>>>>>>
3
c489e2
(
the
first
commit
for
ensurance
,
add
node
-
qos
-
controller
,
collect
,
analyzer
and
avoidance
)
=======
>>>>>>>
8
abab3f
(
bugfix
:
modify
clogs
to
log
)
Client
:
mgr
.
GetClient
(),
Client
:
mgr
.
GetClient
(),
Log
:
log
.
Logger
()
.
WithName
(
"substitute-controller"
),
Log
:
log
.
Logger
()
.
WithName
(
"substitute-controller"
),
Scheme
:
mgr
.
GetScheme
(),
Scheme
:
mgr
.
GetScheme
(),
...
...
This diff is collapsed.
Click to expand it.
docs/20211118how_to_logging.md
+
9
-
9
View file @
c1cf43f1
...
@@ -23,7 +23,7 @@ import (
...
@@ -23,7 +23,7 @@ import (
"k8s.io/component-base/logs"
"k8s.io/component-base/logs"
ctrl "sigs.k8s.io/controller-runtime"
ctrl "sigs.k8s.io/controller-runtime"
"github.com/gocrane/crane/pkg/utils/
c
log
s
"
"github.com/gocrane/crane/pkg/utils/log"
)
)
func main() {
func main() {
...
@@ -38,12 +38,12 @@ func main() {
...
@@ -38,12 +38,12 @@ func main() {
```
```
import (
import (
"github.com/gocrane/crane/pkg/utils/
c
log
s
"
"github.com/gocrane/crane/pkg/utils/log"
)
)
func A() {
func A() {
c
log
s
.Log().V(2).Info("run manager")
log.Log
ger
().V(2).Info("run manager")
c
log
s
.Log().Error(err, "opts validate failed")
log.Log
ger
().Error(err, "opts validate failed")
}
}
```
```
...
@@ -52,12 +52,12 @@ func A() {
...
@@ -52,12 +52,12 @@ func A() {
```
```
import (
import (
"github.com/gocrane/crane/pkg/utils/
c
log
s
"
"github.com/gocrane/crane/pkg/utils/log"
)
)
func A() {
func A() {
c
log
s
.Log().WithName("extent-name").Info("run manager")
log.Log
ger
().WithName("extent-name").Info("run manager")
c
log
s
.Log().WithName("extent-name").Error(err, "opts validate failed")
log.Log
ger
().WithName("extent-name").Error(err, "opts validate failed")
}
}
```
```
...
@@ -66,7 +66,7 @@ when in controller, we can initialize a logger when new the controller manager
...
@@ -66,7 +66,7 @@ when in controller, we can initialize a logger when new the controller manager
```
```
&xxxx.xxxxxController{
&xxxx.xxxxxController{
Client: mgr.GetClient(),
Client: mgr.GetClient(),
Log:
c
log
s
.Log().WithName("extent-name"),
Log: log.Log
ger
().WithName("extent-name"),
Scheme: mgr.GetScheme(),
Scheme: mgr.GetScheme(),
}
}
```
```
...
@@ -81,5 +81,5 @@ then in the controller logics to use the log like this(p is the ptr of the contr
...
@@ -81,5 +81,5 @@ then in the controller logics to use the log like this(p is the ptr of the contr
we can use
`GenerateKey`
to print the info of resource object, like this:
we can use
`GenerateKey`
to print the info of resource object, like this:
```
```
c
log
s
.Log().V(2).Info("object %s is updated successfully", clogs.GenerateKey(object.Name, object.Namespace))
log.Log
ger
().V(2).Info("object %s is updated successfully", clogs.GenerateKey(object.Name, object.Namespace))
```
```
\ No newline at end of file
This diff is collapsed.
Click to expand it.
go.mod
+
21
-
25
View file @
c1cf43f1
...
@@ -3,16 +3,24 @@ module github.com/gocrane/crane
...
@@ -3,16 +3,24 @@ module github.com/gocrane/crane
go 1.17
go 1.17
require (
require (
github.com/go-echarts/go-echarts/v2
v2.2.4
github.com/go-logr/logr
v0.4.0
github.com/go-logr/logr
v0.4.0
github.com/gocrane/api
v0.0.4
github.com/gocrane/api
v0.0.4
github.com/google/go-cmp
v0.5.6 // indirect
github.com/mjibson/go-dsp
v0.0.0-20180508042940-11479a337f12
github.com/prometheus/client_golang
v1.11.0
github.com/prometheus/common
v0.26.0
github.com/shirou/gopsutil
v3.21.10+incompatible
github.com/shirou/gopsutil
v3.21.10+incompatible
github.com/spf13/cobra
v1.2.1
github.com/spf13/cobra
v1.2.1
github.com/spf13/pflag
v1.0.5
github.com/spf13/pflag
v1.0.5
github.com/stretchr/testify
v1.7.0
golang.org/x/net
v0.0.0-20210520170846-37e1c6afe023
golang.org/x/net
v0.0.0-20210520170846-37e1c6afe023
golang.org/x/tools
v0.1.5 // indirect
google.golang.org/grpc
v1.38.0
google.golang.org/grpc
v1.38.0
k8s.io/api
v0.22.3
k8s.io/api
v0.22.3
k8s.io/apimachinery
v0.22.3
k8s.io/apimachinery
v0.22.3
k8s.io/apiserver
v0.22.3
k8s.io/apiserver
v0.22.3
k8s.io/autoscaler/vertical-pod-autoscaler
v0.9.2
k8s.io/client-go
v0.22.3
k8s.io/client-go
v0.22.3
k8s.io/component-base
v0.22.3
k8s.io/component-base
v0.22.3
k8s.io/cri-api
v0.22.3
k8s.io/cri-api
v0.22.3
...
@@ -21,20 +29,12 @@ require (
...
@@ -21,20 +29,12 @@ require (
k8s.io/metrics
v0.22.3
k8s.io/metrics
v0.22.3
sigs.k8s.io/controller-runtime
v0.10.2
sigs.k8s.io/controller-runtime
v0.10.2
sigs.k8s.io/custom-metrics-apiserver
v1.22.0
sigs.k8s.io/custom-metrics-apiserver
v1.22.0
github.com/go-echarts/go-echarts/v2
v2.2.4
k8s.io/autoscaler/vertical-pod-autoscaler
v0.9.2
github.com/gocrane/api
v0.0.0-20211207120055-f3b9cee38e7f
github.com/google/go-cmp
v0.5.6 // indirect
github.com/mjibson/go-dsp
v0.0.0-20180508042940-11479a337f12
github.com/prometheus/client_golang
v1.11.0
github.com/prometheus/common
v0.26.0
github.com/stretchr/testify
v1.7.0
golang.org/x/tools
v0.1.5 // indirect
)
)
require
github.com/davecgh/go-spew
v1.1.1
require (
require (
k8s.io/kube-openapi
v0.0.0-20210817084001-7fbd8d59e5b8 // indirect
github.com/Microsoft/go-winio
v0.4.15 // indirect
github.com/Microsoft/go-winio
v0.4.15 // indirect
github.com/NYTimes/gziphandler
v1.1.1 // indirect
github.com/NYTimes/gziphandler
v1.1.1 // indirect
github.com/PuerkitoBio/purell
v1.1.1 // indirect
github.com/PuerkitoBio/purell
v1.1.1 // indirect
...
@@ -45,7 +45,6 @@ require (
...
@@ -45,7 +45,6 @@ require (
github.com/cespare/xxhash/v2
v2.1.1 // indirect
github.com/cespare/xxhash/v2
v2.1.1 // indirect
github.com/coreos/go-semver
v0.3.0 // indirect
github.com/coreos/go-semver
v0.3.0 // indirect
github.com/coreos/go-systemd/v22
v22.3.2 // indirect
github.com/coreos/go-systemd/v22
v22.3.2 // indirect
github.com/davecgh/go-spew
v1.1.1 // indirect
github.com/emicklei/go-restful
v2.15.0+incompatible // indirect
github.com/emicklei/go-restful
v2.15.0+incompatible // indirect
github.com/emicklei/go-restful-swagger12
v0.0.0-20201014110547-68ccff494617 // indirect
github.com/emicklei/go-restful-swagger12
v0.0.0-20201014110547-68ccff494617 // indirect
github.com/evanphx/json-patch
v4.11.0+incompatible // indirect
github.com/evanphx/json-patch
v4.11.0+incompatible // indirect
...
@@ -112,28 +111,25 @@ require (
...
@@ -112,28 +111,25 @@ require (
gopkg.in/yaml.v2
v2.4.0 // indirect
gopkg.in/yaml.v2
v2.4.0 // indirect
gopkg.in/yaml.v3
v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3
v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/apiextensions-apiserver
v0.22.2 // indirect
k8s.io/apiextensions-apiserver
v0.22.2 // indirect
k8s.io/kube-openapi
v0.0.0-20210817084001-7fbd8d59e5b8 // indirect
k8s.io/utils
v0.0.0-20210819203725-bdf08cb9a70a // indirect
k8s.io/utils
v0.0.0-20210819203725-bdf08cb9a70a // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client
v0.0.22 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client
v0.0.22 // indirect
sigs.k8s.io/structured-merge-diff/v4
v4.1.2 // indirect
sigs.k8s.io/structured-merge-diff/v4
v4.1.2 // indirect
sigs.k8s.io/yaml
v1.2.0 // indirect
sigs.k8s.io/yaml
v1.2.0 // indirect
github.com/go-echarts/go-echarts/v2
v2.2.4
github.com/google/go-cmp
v0.5.6 // indirect
github.com/mjibson/go-dsp
v0.0.0-20180508042940-11479a337f12
github.com/prometheus/client_golang
v1.11.0
github.com/prometheus/common
v0.26.0
github.com/stretchr/testify
v1.7.0
golang.org/x/tools
v0.1.5 // indirect
k8s.io/autoscaler/vertical-pod-autoscaler
v0.9.2
k8s.io/kube-openapi
v0.0.0-20210817084001-7fbd8d59e5b8 // indirect
)
)
require (
github.com/go-echarts/go-echarts/v2
v2.2.4
github.com/gocrane/api
v0.0.0-20211215114952-2a4631530892
github.com/google/go-cmp
v0.5.6 // indirect
github.com/mjibson/go-dsp
v0.0.0-20180508042940-11479a337f12
github.com/prometheus/client_golang
v1.11.0
github.com/prometheus/common
v0.26.0
github.com/stretchr/testify
v1.7.0
golang.org/x/tools
v0.1.5 // indirect
k8s.io/autoscaler/vertical-pod-autoscaler
v0.9.2
k8s.io/kube-openapi
v0.0.0-20210817084001-7fbd8d59e5b8 // indirect
)
replace (
replace (
github.com/gocrane/api
=> github.com/yan234280533/api2 v0.0.0-202112
02040236-9fdcc4deae1
4
github.com/gocrane/api
=> github.com/yan234280533/api2 v0.0.0-202112
10071841-99f6e00814d
4
golang.org/x/net
=> github.com/golang/net v0.0.0-20210825183410-e898025ed96a
golang.org/x/net
=> github.com/golang/net v0.0.0-20210825183410-e898025ed96a
k8s.io/api
=> k8s.io/api v0.22.3
k8s.io/api
=> k8s.io/api v0.22.3
k8s.io/apiextensions-apiserver
=> k8s.io/apiextensions-apiserver v0.22.3
k8s.io/apiextensions-apiserver
=> k8s.io/apiextensions-apiserver v0.22.3
...
...
This diff is collapsed.
Click to expand it.
go.sum
+
12
-
138
View file @
c1cf43f1
This diff is collapsed.
Click to expand it.
pkg/controller/ensurance/nodeqosensurancepolicy_controller.go
deleted
100644 → 0
+
0
-
154
View file @
26ae8a5e
/*
Copyright 2021.
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
controllers
import
(
"context"
"fmt"
"github.com/gocrane/crane/pkg/ensurance/cache"
"strings"
"github.com/go-logr/logr"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
ctrl
"sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
ensuranceapi
"github.com/gocrane/api/ensurance/v1alpha1"
"github.com/gocrane/crane/pkg/ensurance/statestore"
"github.com/gocrane/crane/pkg/ensurance/statestore/types"
"github.com/gocrane/crane/pkg/utils/clogs"
)
// NodeQOSEnsurancePolicyController reconciles a NodeQOSEnsurancePolicy object
type
NodeQOSEnsurancePolicyController
struct
{
client
.
Client
Scheme
*
runtime
.
Scheme
Log
logr
.
Logger
RestMapper
meta
.
RESTMapper
Recorder
record
.
EventRecorder
Cache
*
cache
.
NodeQOSEnsurancePolicyCache
StateStore
statestore
.
StateStore
}
//+kubebuilder:rbac:groups=ensurance.crane.io.crane.io,resources=nodeqosensurancepolicies,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=ensurance.crane.io.crane.io,resources=nodeqosensurancepolicies/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=ensurance.crane.io.crane.io,resources=nodeqosensurancepolicies/finalizers,verbs=update
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
// TODO(user): Modify the Reconcile function to compare the state specified by
// the NodeQOSEnsurancePolicy object against the actual cluster state, and then
// perform operations to make the cluster state reflect the state specified by
// the user.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.8.3/pkg/reconcile
func
(
c
*
NodeQOSEnsurancePolicyController
)
Reconcile
(
ctx
context
.
Context
,
req
ctrl
.
Request
)
(
ctrl
.
Result
,
error
)
{
c
.
Log
.
Info
(
"got"
,
"nep"
,
req
.
NamespacedName
)
nep
:=
&
ensuranceapi
.
NodeQOSEnsurancePolicy
{}
if
err
:=
c
.
Client
.
Get
(
ctx
,
req
.
NamespacedName
,
nep
);
err
!=
nil
{
// The resource may be deleted, in this case we need to stop the processing.
if
apierrors
.
IsNotFound
(
err
)
{
return
ctrl
.
Result
{},
nil
}
return
ctrl
.
Result
{
Requeue
:
true
},
err
}
if
!
nep
.
DeletionTimestamp
.
IsZero
()
{
if
err
:=
c
.
delete
(
nep
);
err
!=
nil
{
return
ctrl
.
Result
{},
err
}
}
return
c
.
reconcileNep
(
nep
)
}
// SetupWithManager sets up the controller with the Manager.
func
(
c
*
NodeQOSEnsurancePolicyController
)
SetupWithManager
(
mgr
ctrl
.
Manager
)
error
{
c
.
Cache
.
Init
()
return
ctrl
.
NewControllerManagedBy
(
mgr
)
.
For
(
&
ensuranceapi
.
NodeQOSEnsurancePolicy
{})
.
Complete
(
c
)
}
func
(
c
*
NodeQOSEnsurancePolicyController
)
reconcileNep
(
nep
*
ensuranceapi
.
NodeQOSEnsurancePolicy
)
(
ctrl
.
Result
,
error
)
{
if
!
c
.
Cache
.
Exist
(
nep
.
Name
)
{
if
err
:=
c
.
create
(
nep
);
err
!=
nil
{
return
ctrl
.
Result
{},
err
}
c
.
Cache
.
Set
(
nep
)
}
else
{
if
err
:=
c
.
update
(
nep
);
err
!=
nil
{
return
ctrl
.
Result
{},
err
}
c
.
Cache
.
Set
(
nep
)
}
return
ctrl
.
Result
{},
nil
}
func
(
c
*
NodeQOSEnsurancePolicyController
)
create
(
nep
*
ensuranceapi
.
NodeQOSEnsurancePolicy
)
error
{
// step1: add metrics
for
_
,
v
:=
range
nep
.
Spec
.
ObjectiveEnsurances
{
var
key
=
GenerateEnsuranceQosNodePolicyKey
(
nep
.
Name
,
v
.
AvoidanceActionName
)
c
.
StateStore
.
AddMetric
(
key
,
types
.
NodeLocalCollectorType
,
v
.
MetricRule
.
Metric
.
Name
,
v
.
MetricRule
.
Metric
.
Selector
)
}
return
nil
}
func
(
c
*
NodeQOSEnsurancePolicyController
)
update
(
nep
*
ensuranceapi
.
NodeQOSEnsurancePolicy
)
error
{
if
nepOld
,
ok
:=
c
.
Cache
.
Get
(
nep
.
Name
);
ok
{
// step1 compare all objectiveEnsurance
// step2 if the objectiveEnsurance metric changed, update the policy status
// step3 delete the old metric and add the new metric
// step4 if failed, delete all metrics for this policy
// step5 if succeed, update the policy status
clogs
.
Log
()
.
V
(
6
)
.
Info
(
"nepOld %v"
,
nepOld
)
return
nil
}
return
fmt
.
Errorf
(
"update nep(%s),no found"
,
nep
.
Name
)
}
func
(
c
*
NodeQOSEnsurancePolicyController
)
delete
(
nep
*
ensuranceapi
.
NodeQOSEnsurancePolicy
)
error
{
// step1: delete metrics from cache nep
if
nepOld
,
ok
:=
c
.
Cache
.
Get
(
nep
.
Name
);
ok
{
for
_
,
v
:=
range
nepOld
.
Nep
.
Spec
.
ObjectiveEnsurances
{
var
key
=
GenerateEnsuranceQosNodePolicyKey
(
nep
.
Name
,
v
.
AvoidanceActionName
)
c
.
StateStore
.
DeleteMetric
(
key
,
types
.
NodeLocalCollectorType
)
}
}
// step2: delete metrics from nep
for
_
,
v
:=
range
nep
.
Spec
.
ObjectiveEnsurances
{
var
key
=
GenerateEnsuranceQosNodePolicyKey
(
nep
.
Name
,
v
.
AvoidanceActionName
)
c
.
StateStore
.
DeleteMetric
(
key
,
types
.
NodeLocalCollectorType
)
}
return
nil
}
func
GenerateEnsuranceQosNodePolicyKey
(
policyName
string
,
avoidanceActionName
string
)
string
{
return
strings
.
Join
([]
string
{
"node"
,
policyName
,
avoidanceActionName
},
"."
)
}
This diff is collapsed.
Click to expand it.
pkg/controller/ensurance/podqosensurancepolicy_controller.go
deleted
100644 → 0
+
0
-
62
View file @
26ae8a5e
/*
Copyright 2021.
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
controllers
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
ctrl
"sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
ensurancecraneiov1alpha1
"github.com/gocrane/api/ensurance/v1alpha1"
)
// PodQOSEnsurancePolicyController reconciles a PodQOSEnsurancePolicy object
type
PodQOSEnsurancePolicyController
struct
{
client
.
Client
Scheme
*
runtime
.
Scheme
}
//+kubebuilder:rbac:groups=ensurance.crane.io.crane.io,resources=podqosensurancepolicies,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=ensurance.crane.io.crane.io,resources=podqosensurancepolicies/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=ensurance.crane.io.crane.io,resources=podqosensurancepolicies/finalizers,verbs=update
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
// TODO(user): Modify the Reconcile function to compare the state specified by
// the PodQOSEnsurancePolicy object against the actual cluster state, and then
// perform operations to make the cluster state reflect the state specified by
// the user.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.8.3/pkg/reconcile
func
(
r
*
PodQOSEnsurancePolicyController
)
Reconcile
(
ctx
context
.
Context
,
req
ctrl
.
Request
)
(
ctrl
.
Result
,
error
)
{
_
=
log
.
FromContext
(
ctx
)
// your logic here
return
ctrl
.
Result
{},
nil
}
// SetupWithManager sets up the controller with the Manager.
func
(
r
*
PodQOSEnsurancePolicyController
)
SetupWithManager
(
mgr
ctrl
.
Manager
)
error
{
return
ctrl
.
NewControllerManagedBy
(
mgr
)
.
For
(
&
ensurancecraneiov1alpha1
.
PodQOSEnsurancePolicy
{})
.
Complete
(
r
)
}
This diff is collapsed.
Click to expand it.
pkg/ensurance/analyzer/analyzer.go
+
17
-
17
View file @
c1cf43f1
...
@@ -19,7 +19,7 @@ import (
...
@@ -19,7 +19,7 @@ import (
"github.com/gocrane/crane/pkg/ensurance/logic"
"github.com/gocrane/crane/pkg/ensurance/logic"
"github.com/gocrane/crane/pkg/ensurance/statestore"
"github.com/gocrane/crane/pkg/ensurance/statestore"
"github.com/gocrane/crane/pkg/utils"
"github.com/gocrane/crane/pkg/utils"
"github.com/gocrane/crane/pkg/utils/
c
log
s
"
"github.com/gocrane/crane/pkg/utils/log"
)
)
type
AnalyzerManager
struct
{
type
AnalyzerManager
struct
{
...
@@ -73,10 +73,10 @@ func (s *AnalyzerManager) Run(stop <-chan struct{}) {
...
@@ -73,10 +73,10 @@ func (s *AnalyzerManager) Run(stop <-chan struct{}) {
for
{
for
{
select
{
select
{
case
<-
updateTicker
.
C
:
case
<-
updateTicker
.
C
:
c
log
s
.
Log
()
.
V
(
3
)
.
Info
(
"Analyzer run periodically"
)
log
.
Log
ger
()
.
V
(
3
)
.
Info
(
"Analyzer run periodically"
)
s
.
Analyze
()
s
.
Analyze
()
case
<-
stop
:
case
<-
stop
:
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
"Analyzer exit"
)
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
"Analyzer exit"
)
return
return
}
}
}
}
...
@@ -89,7 +89,7 @@ func (s *AnalyzerManager) Analyze() {
...
@@ -89,7 +89,7 @@ func (s *AnalyzerManager) Analyze() {
// step1 copy neps
// step1 copy neps
node
,
err
:=
einformer
.
GetNodeFromInformer
(
s
.
nodeInformer
,
s
.
nodeName
)
node
,
err
:=
einformer
.
GetNodeFromInformer
(
s
.
nodeInformer
,
s
.
nodeName
)
if
err
!=
nil
{
if
err
!=
nil
{
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
"Warning: get node name failed, not to do analyze"
)
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
"Warning: get node name failed, not to do analyze"
)
return
return
}
}
...
@@ -100,7 +100,7 @@ func (s *AnalyzerManager) Analyze() {
...
@@ -100,7 +100,7 @@ func (s *AnalyzerManager) Analyze() {
//check the node is selected by the
//check the node is selected by the
if
matched
,
err
:=
utils
.
LabelSelectorMatched
(
node
.
Labels
,
&
nep
.
Spec
.
LabelSelector
);
err
!=
nil
{
if
matched
,
err
:=
utils
.
LabelSelectorMatched
(
node
.
Labels
,
&
nep
.
Spec
.
LabelSelector
);
err
!=
nil
{
c
log
s
.
Log
()
.
V
(
5
)
.
Info
(
fmt
.
Sprintf
(
"Warning: the nep label selector error,err: %s"
,
err
.
Error
()))
log
.
Log
ger
()
.
V
(
5
)
.
Info
(
fmt
.
Sprintf
(
"Warning: the nep label selector error,err: %s"
,
err
.
Error
()))
continue
continue
}
else
if
!
matched
{
}
else
if
!
matched
{
continue
continue
...
@@ -125,19 +125,19 @@ func (s *AnalyzerManager) Analyze() {
...
@@ -125,19 +125,19 @@ func (s *AnalyzerManager) Analyze() {
var
key
=
strings
.
Join
([]
string
{
n
.
Name
,
v
.
Name
},
"."
)
var
key
=
strings
.
Join
([]
string
{
n
.
Name
,
v
.
Name
},
"."
)
detection
,
err
:=
s
.
doAnalyze
(
key
,
v
)
detection
,
err
:=
s
.
doAnalyze
(
key
,
v
)
if
err
!=
nil
{
if
err
!=
nil
{
c
log
s
.
Log
()
.
V
(
4
)
.
Info
(
fmt
.
Sprintf
(
"Warning: doAnalyze failed %s"
,
err
.
Error
()))
log
.
Log
ger
()
.
V
(
4
)
.
Info
(
fmt
.
Sprintf
(
"Warning: doAnalyze failed %s"
,
err
.
Error
()))
}
}
detection
.
Nep
=
n
detection
.
Nep
=
n
dcs
=
append
(
dcs
,
detection
)
dcs
=
append
(
dcs
,
detection
)
}
}
}
}
c
log
s
.
Log
()
.
V
(
4
)
.
Info
(
"Analyze:"
,
"dcs"
,
dcs
)
log
.
Log
ger
()
.
V
(
4
)
.
Info
(
"Analyze:"
,
"dcs"
,
dcs
)
//step 3 : doMerge
//step 3 : doMerge
avoidanceAction
,
err
:=
s
.
doMerge
(
asMaps
,
dcs
)
avoidanceAction
:=
s
.
doMerge
(
asMaps
,
dcs
)
if
err
!=
nil
{
if
err
!=
nil
{
c
log
s
.
Log
()
.
Error
(
err
,
"Analyze doMerge failed"
)
log
.
Log
ger
()
.
Error
(
err
,
"Analyze doMerge failed"
)
return
return
}
}
...
@@ -148,7 +148,7 @@ func (s *AnalyzerManager) Analyze() {
...
@@ -148,7 +148,7 @@ func (s *AnalyzerManager) Analyze() {
}
}
func
(
s
*
AnalyzerManager
)
doAnalyze
(
key
string
,
object
ensuranceapi
.
ObjectiveEnsurance
)
(
ecache
.
DetectionCondition
,
error
)
{
func
(
s
*
AnalyzerManager
)
doAnalyze
(
key
string
,
object
ensuranceapi
.
ObjectiveEnsurance
)
(
ecache
.
DetectionCondition
,
error
)
{
c
log
s
.
Log
()
.
V
(
6
)
.
Info
(
"doAnalyze"
,
"status"
,
s
.
status
)
log
.
Log
ger
()
.
V
(
6
)
.
Info
(
"doAnalyze"
,
"status"
,
s
.
status
)
var
dc
=
ecache
.
DetectionCondition
{
DryRun
:
object
.
DryRun
,
ObjectiveEnsuranceName
:
object
.
Name
,
ActionName
:
object
.
AvoidanceActionName
}
var
dc
=
ecache
.
DetectionCondition
{
DryRun
:
object
.
DryRun
,
ObjectiveEnsuranceName
:
object
.
Name
,
ActionName
:
object
.
AvoidanceActionName
}
...
@@ -186,7 +186,7 @@ func (s *AnalyzerManager) doAnalyze(key string, object ensuranceapi.ObjectiveEns
...
@@ -186,7 +186,7 @@ func (s *AnalyzerManager) doAnalyze(key string, object ensuranceapi.ObjectiveEns
return
dc
,
nil
return
dc
,
nil
}
}
func
(
s
*
AnalyzerManager
)
doMerge
(
asMaps
map
[
string
]
*
ensuranceapi
.
AvoidanceAction
,
dcs
[]
ecache
.
DetectionCondition
)
(
executor
.
AvoidanceExecutor
,
error
)
{
func
(
s
*
AnalyzerManager
)
doMerge
(
asMaps
map
[
string
]
*
ensuranceapi
.
AvoidanceAction
,
dcs
[]
ecache
.
DetectionCondition
)
executor
.
AvoidanceExecutor
{
var
now
=
time
.
Now
()
var
now
=
time
.
Now
()
//step1 filter the only dryRun detection
//step1 filter the only dryRun detection
...
@@ -221,13 +221,13 @@ func (s *AnalyzerManager) doMerge(asMaps map[string]*ensuranceapi.AvoidanceActio
...
@@ -221,13 +221,13 @@ func (s *AnalyzerManager) doMerge(asMaps map[string]*ensuranceapi.AvoidanceActio
for
_
,
dc
:=
range
dcsFiltered
{
for
_
,
dc
:=
range
dcsFiltered
{
action
,
ok
:=
asMaps
[
dc
.
ActionName
]
action
,
ok
:=
asMaps
[
dc
.
ActionName
]
if
!
ok
{
if
!
ok
{
c
log
s
.
Log
()
.
V
(
4
)
.
Info
(
fmt
.
Sprintf
(
"Waring: doMerge for detection the action %s not found"
,
dc
.
ActionName
))
log
.
Log
ger
()
.
V
(
4
)
.
Info
(
fmt
.
Sprintf
(
"Waring: doMerge for detection the action %s not found"
,
dc
.
ActionName
))
continue
continue
}
}
if
dc
.
Restored
{
if
dc
.
Restored
{
var
schedulingCoolDown
=
utils
.
GetInt64withDefault
(
action
.
Spec
.
SchedulingCoolDown
,
300
)
var
schedulingCoolDown
=
utils
.
GetInt64withDefault
(
action
.
Spec
.
SchedulingCoolDown
,
300
)
c
log
s
.
Log
()
.
V
(
4
)
.
Info
(
"doMerge"
,
"schedulingCoolDown"
,
schedulingCoolDown
)
log
.
Log
ger
()
.
V
(
4
)
.
Info
(
"doMerge"
,
"schedulingCoolDown"
,
schedulingCoolDown
)
if
now
.
After
(
s
.
lastTriggeredTime
.
Add
(
time
.
Duration
(
schedulingCoolDown
)
*
time
.
Second
))
{
if
now
.
After
(
s
.
lastTriggeredTime
.
Add
(
time
.
Duration
(
schedulingCoolDown
)
*
time
.
Second
))
{
bRestoreScheduled
=
true
bRestoreScheduled
=
true
break
break
...
@@ -249,7 +249,7 @@ func (s *AnalyzerManager) doMerge(asMaps map[string]*ensuranceapi.AvoidanceActio
...
@@ -249,7 +249,7 @@ func (s *AnalyzerManager) doMerge(asMaps map[string]*ensuranceapi.AvoidanceActio
if
dc
.
Triggered
{
if
dc
.
Triggered
{
action
,
ok
:=
asMaps
[
dc
.
ActionName
]
action
,
ok
:=
asMaps
[
dc
.
ActionName
]
if
!
ok
{
if
!
ok
{
c
log
s
.
Log
()
.
V
(
4
)
.
Info
(
"Waring: doMerge for detection the action "
,
dc
.
ActionName
,
" not found"
)
log
.
Log
ger
()
.
V
(
4
)
.
Info
(
"Waring: doMerge for detection the action "
,
dc
.
ActionName
,
" not found"
)
continue
continue
}
}
...
@@ -283,7 +283,7 @@ func (s *AnalyzerManager) doMerge(asMaps map[string]*ensuranceapi.AvoidanceActio
...
@@ -283,7 +283,7 @@ func (s *AnalyzerManager) doMerge(asMaps map[string]*ensuranceapi.AvoidanceActio
// sort the evicting executor by pod qos priority
// sort the evicting executor by pod qos priority
sort
.
Sort
(
ae
.
EvictExecutor
.
Executors
)
sort
.
Sort
(
ae
.
EvictExecutor
.
Executors
)
return
ae
,
nil
return
ae
}
}
func
(
s
*
AnalyzerManager
)
doLogEvent
(
dc
ecache
.
DetectionCondition
,
now
time
.
Time
)
{
func
(
s
*
AnalyzerManager
)
doLogEvent
(
dc
ecache
.
DetectionCondition
,
now
time
.
Time
)
{
...
@@ -299,7 +299,7 @@ func (s *AnalyzerManager) doLogEvent(dc ecache.DetectionCondition, now time.Time
...
@@ -299,7 +299,7 @@ func (s *AnalyzerManager) doLogEvent(dc ecache.DetectionCondition, now time.Time
//step1 print log if the detection state is changed
//step1 print log if the detection state is changed
//step2 produce event
//step2 produce event
if
dc
.
Triggered
{
if
dc
.
Triggered
{
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"%s triggered action %s"
,
key
,
dc
.
ActionName
))
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"%s triggered action %s"
,
key
,
dc
.
ActionName
))
// record an event about the objective ensurance triggered
// record an event about the objective ensurance triggered
s
.
recorder
.
Event
(
nodeRef
,
v1
.
EventTypeWarning
,
"ObjectiveEnsuranceTriggered"
,
fmt
.
Sprintf
(
"%s triggered action %s"
,
key
,
dc
.
ActionName
))
s
.
recorder
.
Event
(
nodeRef
,
v1
.
EventTypeWarning
,
"ObjectiveEnsuranceTriggered"
,
fmt
.
Sprintf
(
"%s triggered action %s"
,
key
,
dc
.
ActionName
))
...
@@ -308,7 +308,7 @@ func (s *AnalyzerManager) doLogEvent(dc ecache.DetectionCondition, now time.Time
...
@@ -308,7 +308,7 @@ func (s *AnalyzerManager) doLogEvent(dc ecache.DetectionCondition, now time.Time
if
dc
.
Restored
{
if
dc
.
Restored
{
if
s
.
needSendEventForRestore
(
dc
)
{
if
s
.
needSendEventForRestore
(
dc
)
{
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"%s restored action %s"
,
key
,
dc
.
ActionName
))
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"%s restored action %s"
,
key
,
dc
.
ActionName
))
// record an event about the objective ensurance restored
// record an event about the objective ensurance restored
s
.
recorder
.
Event
(
nodeRef
,
v1
.
EventTypeNormal
,
"ObjectiveEnsuranceRestored"
,
fmt
.
Sprintf
(
"%s restored action %s"
,
key
,
dc
.
ActionName
))
s
.
recorder
.
Event
(
nodeRef
,
v1
.
EventTypeNormal
,
"ObjectiveEnsuranceRestored"
,
fmt
.
Sprintf
(
"%s restored action %s"
,
key
,
dc
.
ActionName
))
s
.
actionEventStatus
[
key
]
=
ecache
.
DetectionStatus
{
IsTriggered
:
false
,
LastTime
:
now
}
s
.
actionEventStatus
[
key
]
=
ecache
.
DetectionStatus
{
IsTriggered
:
false
,
LastTime
:
now
}
...
...
This diff is collapsed.
Click to expand it.
pkg/ensurance/avoidance/avoidance.go
+
6
-
6
View file @
c1cf43f1
...
@@ -5,7 +5,7 @@ import (
...
@@ -5,7 +5,7 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/cache"
"github.com/gocrane/crane/pkg/ensurance/executor"
"github.com/gocrane/crane/pkg/ensurance/executor"
"github.com/gocrane/crane/pkg/utils/
c
log
s
"
"github.com/gocrane/crane/pkg/utils/log"
)
)
type
AvoidanceManager
struct
{
type
AvoidanceManager
struct
{
...
@@ -36,20 +36,20 @@ func (a *AvoidanceManager) Name() string {
...
@@ -36,20 +36,20 @@ func (a *AvoidanceManager) Name() string {
// Run does nothing
// Run does nothing
func
(
a
*
AvoidanceManager
)
Run
(
stop
<-
chan
struct
{})
{
func
(
a
*
AvoidanceManager
)
Run
(
stop
<-
chan
struct
{})
{
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
"Avoidance manager starts running"
)
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
"Avoidance manager starts running"
)
go
func
()
{
go
func
()
{
for
{
for
{
select
{
select
{
case
as
:=
<-
a
.
noticeCh
:
case
as
:=
<-
a
.
noticeCh
:
c
log
s
.
Log
()
.
V
(
4
)
.
Info
(
"Avoidance by analyzer noticed"
)
log
.
Log
ger
()
.
V
(
4
)
.
Info
(
"Avoidance by analyzer noticed"
)
if
err
:=
a
.
doAction
(
as
,
stop
);
err
!=
nil
{
if
err
:=
a
.
doAction
(
as
,
stop
);
err
!=
nil
{
// TODO: if it failed in action, how to retry
// TODO: if it failed in action, how to retry
c
log
s
.
Log
()
.
Error
(
err
,
"doAction failed"
)
log
.
Log
ger
()
.
Error
(
err
,
"doAction failed"
)
}
}
case
<-
stop
:
case
<-
stop
:
{
{
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
"Avoidance exit"
)
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
"Avoidance exit"
)
return
return
}
}
}
}
...
@@ -59,7 +59,7 @@ func (a *AvoidanceManager) Run(stop <-chan struct{}) {
...
@@ -59,7 +59,7 @@ func (a *AvoidanceManager) Run(stop <-chan struct{}) {
return
return
}
}
func
(
a
*
AvoidanceManager
)
doAction
(
ae
executor
.
AvoidanceExecutor
,
stop
<-
chan
struct
{})
error
{
func
(
a
*
AvoidanceManager
)
doAction
(
ae
executor
.
AvoidanceExecutor
,
_
<-
chan
struct
{})
error
{
var
ctx
=
&
executor
.
ExecuteContext
{
var
ctx
=
&
executor
.
ExecuteContext
{
NodeName
:
a
.
nodeName
,
NodeName
:
a
.
nodeName
,
...
...
This diff is collapsed.
Click to expand it.
pkg/ensurance/cache/nep.go
+
0
-
12
View file @
c1cf43f1
...
@@ -32,18 +32,6 @@ func (s *NodeQOSEnsurancePolicyCache) ListKeys() []string {
...
@@ -32,18 +32,6 @@ func (s *NodeQOSEnsurancePolicyCache) ListKeys() []string {
return
keys
return
keys
}
}
// ListKeys implements the interface required by DeltaFIFO to list the keys we
// already know about.
func
(
s
*
NodeQOSEnsurancePolicyCache
)
allNeps
()
[]
*
ensuranceapi
.
NodeQOSEnsurancePolicy
{
s
.
mu
.
Lock
()
defer
s
.
mu
.
Unlock
()
neps
:=
make
([]
*
ensuranceapi
.
NodeQOSEnsurancePolicy
,
0
,
len
(
s
.
nepMap
))
for
_
,
v
:=
range
s
.
nepMap
{
neps
=
append
(
neps
,
v
.
Nep
)
}
return
neps
}
func
(
s
*
NodeQOSEnsurancePolicyCache
)
Get
(
name
string
)
(
*
CachedNodeQOSEnsurancePolicy
,
bool
)
{
func
(
s
*
NodeQOSEnsurancePolicyCache
)
Get
(
name
string
)
(
*
CachedNodeQOSEnsurancePolicy
,
bool
)
{
s
.
mu
.
Lock
()
s
.
mu
.
Lock
()
defer
s
.
mu
.
Unlock
()
defer
s
.
mu
.
Unlock
()
...
...
This diff is collapsed.
Click to expand it.
pkg/ensurance/executor/evict.go
+
4
-
4
View file @
c1cf43f1
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
einformer
"github.com/gocrane/crane/pkg/ensurance/informer"
einformer
"github.com/gocrane/crane/pkg/ensurance/informer"
"github.com/gocrane/crane/pkg/utils/
c
log
s
"
"github.com/gocrane/crane/pkg/utils/log"
)
)
const
(
const
(
...
@@ -44,7 +44,7 @@ func (e EvictPods) Find(podTypes types.NamespacedName) int {
...
@@ -44,7 +44,7 @@ func (e EvictPods) Find(podTypes types.NamespacedName) int {
}
}
func
(
e
*
EvictExecutor
)
Avoid
(
ctx
*
ExecuteContext
)
error
{
func
(
e
*
EvictExecutor
)
Avoid
(
ctx
*
ExecuteContext
)
error
{
c
log
s
.
Log
()
.
V
(
4
)
.
Info
(
"Avoid"
,
"EvictExecutor"
,
*
e
)
log
.
Log
ger
()
.
V
(
4
)
.
Info
(
"Avoid"
,
"EvictExecutor"
,
*
e
)
var
bSucceed
=
true
var
bSucceed
=
true
var
errPodKeys
[]
string
var
errPodKeys
[]
string
...
@@ -64,12 +64,12 @@ func (e *EvictExecutor) Avoid(ctx *ExecuteContext) error {
...
@@ -64,12 +64,12 @@ func (e *EvictExecutor) Avoid(ctx *ExecuteContext) error {
return
return
}
}
c
log
s
.
Log
()
.
V
(
4
)
.
Info
(
fmt
.
Sprintf
(
"Pod %s"
,
c
log
s
.
GenerateObj
(
pod
)))
log
.
Log
ger
()
.
V
(
4
)
.
Info
(
fmt
.
Sprintf
(
"Pod %s"
,
log
.
GenerateObj
(
pod
)))
err
=
einformer
.
EvictPodWithGracePeriod
(
ctx
.
Client
,
pod
,
v
.
DeletionGracePeriodSeconds
)
err
=
einformer
.
EvictPodWithGracePeriod
(
ctx
.
Client
,
pod
,
v
.
DeletionGracePeriodSeconds
)
if
err
!=
nil
{
if
err
!=
nil
{
bSucceed
=
false
bSucceed
=
false
errPodKeys
=
append
(
errPodKeys
,
"evict failed "
,
v
.
PodTypes
.
String
())
errPodKeys
=
append
(
errPodKeys
,
"evict failed "
,
v
.
PodTypes
.
String
())
c
log
s
.
Log
()
.
V
(
4
)
.
Info
(
fmt
.
Sprintf
(
"Warning: evict failed %s, err %s"
,
v
.
PodTypes
.
String
(),
err
.
Error
()))
log
.
Log
ger
()
.
V
(
4
)
.
Info
(
fmt
.
Sprintf
(
"Warning: evict failed %s, err %s"
,
v
.
PodTypes
.
String
(),
err
.
Error
()))
return
return
}
}
}(
e
.
Executors
[
i
])
}(
e
.
Executors
[
i
])
...
...
This diff is collapsed.
Click to expand it.
pkg/ensurance/executor/schedule.go
+
5
-
5
View file @
c1cf43f1
...
@@ -5,7 +5,7 @@ import (
...
@@ -5,7 +5,7 @@ import (
einformer
"github.com/gocrane/crane/pkg/ensurance/informer"
einformer
"github.com/gocrane/crane/pkg/ensurance/informer"
"github.com/gocrane/crane/pkg/known"
"github.com/gocrane/crane/pkg/known"
"github.com/gocrane/crane/pkg/utils/
c
log
s
"
"github.com/gocrane/crane/pkg/utils/log"
)
)
type
BlockScheduledExecutor
struct
{
type
BlockScheduledExecutor
struct
{
...
@@ -19,7 +19,7 @@ type ScheduledQOSPriority struct {
...
@@ -19,7 +19,7 @@ type ScheduledQOSPriority struct {
}
}
func
(
b
*
BlockScheduledExecutor
)
Avoid
(
ctx
*
ExecuteContext
)
error
{
func
(
b
*
BlockScheduledExecutor
)
Avoid
(
ctx
*
ExecuteContext
)
error
{
c
log
s
.
Log
()
.
V
(
4
)
.
Info
(
"Avoid"
,
"BlockScheduledExecutor"
,
*
b
)
log
.
Log
ger
()
.
V
(
4
)
.
Info
(
"Avoid"
,
"BlockScheduledExecutor"
,
*
b
)
if
b
.
BlockScheduledQOSPriority
==
nil
{
if
b
.
BlockScheduledQOSPriority
==
nil
{
return
nil
return
nil
...
@@ -48,7 +48,7 @@ func (b *BlockScheduledExecutor) Avoid(ctx *ExecuteContext) error {
...
@@ -48,7 +48,7 @@ func (b *BlockScheduledExecutor) Avoid(ctx *ExecuteContext) error {
}
}
func
(
b
*
BlockScheduledExecutor
)
Restore
(
ctx
*
ExecuteContext
)
error
{
func
(
b
*
BlockScheduledExecutor
)
Restore
(
ctx
*
ExecuteContext
)
error
{
c
log
s
.
Log
()
.
V
(
4
)
.
Info
(
"Restore"
,
"BlockScheduledExecutor"
,
*
b
)
log
.
Log
ger
()
.
V
(
4
)
.
Info
(
"Restore"
,
"BlockScheduledExecutor"
,
*
b
)
if
b
.
RestoreScheduledQOSPriority
==
nil
{
if
b
.
RestoreScheduledQOSPriority
==
nil
{
return
nil
return
nil
...
@@ -68,12 +68,12 @@ func (b *BlockScheduledExecutor) Restore(ctx *ExecuteContext) error {
...
@@ -68,12 +68,12 @@ func (b *BlockScheduledExecutor) Restore(ctx *ExecuteContext) error {
// update node taint for restored scheduled
// update node taint for restored scheduled
if
updateNode
,
needUpdate
:=
einformer
.
RemoveNodeTaints
(
node
,
v1
.
Taint
{
Key
:
known
.
EnsuranceAnalyzedPressureTaintKey
,
Effect
:
v1
.
TaintEffectPreferNoSchedule
});
needUpdate
{
if
updateNode
,
needUpdate
:=
einformer
.
RemoveNodeTaints
(
node
,
v1
.
Taint
{
Key
:
known
.
EnsuranceAnalyzedPressureTaintKey
,
Effect
:
v1
.
TaintEffectPreferNoSchedule
});
needUpdate
{
c
log
s
.
Log
()
.
V
(
4
)
.
Info
(
"RemoveNodeTaints update true"
)
log
.
Log
ger
()
.
V
(
4
)
.
Info
(
"RemoveNodeTaints update true"
)
if
err
:=
einformer
.
UpdateNode
(
ctx
.
Client
,
updateNode
,
nil
);
err
!=
nil
{
if
err
:=
einformer
.
UpdateNode
(
ctx
.
Client
,
updateNode
,
nil
);
err
!=
nil
{
return
err
return
err
}
}
}
else
{
}
else
{
c
log
s
.
Log
()
.
V
(
4
)
.
Info
(
"RemoveNodeTaints update false"
)
log
.
Log
ger
()
.
V
(
4
)
.
Info
(
"RemoveNodeTaints update false"
)
}
}
return
nil
return
nil
...
...
This diff is collapsed.
Click to expand it.
pkg/ensurance/grpcc/connection.go
+
5
-
5
View file @
c1cf43f1
...
@@ -7,7 +7,7 @@ import (
...
@@ -7,7 +7,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc"
"k8s.io/kubernetes/pkg/kubelet/util"
"k8s.io/kubernetes/pkg/kubelet/util"
"github.com/gocrane/crane/pkg/utils/
c
log
s
"
"github.com/gocrane/crane/pkg/utils/log"
)
)
const
(
const
(
...
@@ -23,13 +23,13 @@ func InitGrpcConnection(endPoints []string) (*grpc.ClientConn, error) {
...
@@ -23,13 +23,13 @@ func InitGrpcConnection(endPoints []string) (*grpc.ClientConn, error) {
var
conn
*
grpc
.
ClientConn
var
conn
*
grpc
.
ClientConn
for
idx
,
v
:=
range
endPoints
{
for
idx
,
v
:=
range
endPoints
{
c
log
s
.
Log
()
.
V
(
5
)
.
Info
(
fmt
.
Sprintf
(
"Connect using endpoint '%s' with '%s' timeout"
,
v
,
defaultTimeout
))
log
.
Log
ger
()
.
V
(
5
)
.
Info
(
fmt
.
Sprintf
(
"Connect using endpoint '%s' with '%s' timeout"
,
v
,
defaultTimeout
))
addr
,
dialer
,
err
:=
util
.
GetAddressAndDialer
(
v
)
addr
,
dialer
,
err
:=
util
.
GetAddressAndDialer
(
v
)
if
err
!=
nil
{
if
err
!=
nil
{
if
idx
==
(
len
-
1
)
{
if
idx
==
(
len
-
1
)
{
return
nil
,
err
return
nil
,
err
}
}
c
log
s
.
Log
()
.
V
(
5
)
.
Info
(
fmt
.
Sprintf
(
"Waring: connect using endpoint '%s' failed, err: %s"
,
v
,
err
.
Error
()))
log
.
Log
ger
()
.
V
(
5
)
.
Info
(
fmt
.
Sprintf
(
"Waring: connect using endpoint '%s' failed, err: %s"
,
v
,
err
.
Error
()))
continue
continue
}
}
...
@@ -39,9 +39,9 @@ func InitGrpcConnection(endPoints []string) (*grpc.ClientConn, error) {
...
@@ -39,9 +39,9 @@ func InitGrpcConnection(endPoints []string) (*grpc.ClientConn, error) {
if
idx
==
(
len
-
1
)
{
if
idx
==
(
len
-
1
)
{
return
nil
,
errMsg
return
nil
,
errMsg
}
}
c
log
s
.
Log
()
.
V
(
5
)
.
Info
(
fmt
.
Sprintf
(
"Waring: %s"
,
errMsg
))
log
.
Log
ger
()
.
V
(
5
)
.
Info
(
fmt
.
Sprintf
(
"Waring: %s"
,
errMsg
))
}
else
{
}
else
{
c
log
s
.
Log
()
.
V
(
5
)
.
Info
(
fmt
.
Sprintf
(
"Connected successfully using endpoint: %s"
,
v
))
log
.
Log
ger
()
.
V
(
5
)
.
Info
(
fmt
.
Sprintf
(
"Connected successfully using endpoint: %s"
,
v
))
break
break
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
pkg/ensurance/informer/factory.go
+
4
-
4
View file @
c1cf43f1
...
@@ -12,7 +12,7 @@ import (
...
@@ -12,7 +12,7 @@ import (
ensuaranceset
"github.com/gocrane/api/pkg/generated/clientset/versioned"
ensuaranceset
"github.com/gocrane/api/pkg/generated/clientset/versioned"
"github.com/gocrane/api/pkg/generated/informers/externalversions"
"github.com/gocrane/api/pkg/generated/informers/externalversions"
"github.com/gocrane/crane/pkg/utils/
c
log
s
"
"github.com/gocrane/crane/pkg/utils/log"
)
)
const
(
const
(
...
@@ -62,20 +62,20 @@ func (c *Context) ContextInit() error {
...
@@ -62,20 +62,20 @@ func (c *Context) ContextInit() error {
clientConfig
,
err
:=
clientcmd
.
BuildConfigFromFlags
(
c
.
master
,
c
.
kubeConfig
)
clientConfig
,
err
:=
clientcmd
.
BuildConfigFromFlags
(
c
.
master
,
c
.
kubeConfig
)
if
err
!=
nil
{
if
err
!=
nil
{
c
log
s
.
Log
()
.
Error
(
err
,
"BuildConfigFromFlags failed"
)
log
.
Log
ger
()
.
Error
(
err
,
"BuildConfigFromFlags failed"
)
return
err
return
err
}
}
c
.
kubeClient
=
clientset
.
NewForConfigOrDie
(
clientConfig
)
c
.
kubeClient
=
clientset
.
NewForConfigOrDie
(
clientConfig
)
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
"ContextInit kubernetes client succeed"
)
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
"ContextInit kubernetes client succeed"
)
return
nil
return
nil
}
}
func
NewContextInitWithClient
(
client
clientset
.
Interface
,
ensuranceClient
ensuaranceset
.
Interface
,
nodeName
string
)
*
Context
{
func
NewContextInitWithClient
(
client
clientset
.
Interface
,
ensuranceClient
ensuaranceset
.
Interface
,
nodeName
string
)
*
Context
{
var
ctx
=
&
Context
{
kubeClient
:
client
,
stop
:
make
(
chan
struct
{})}
var
ctx
=
&
Context
{
kubeClient
:
client
,
stop
:
make
(
chan
struct
{})
,
nodeName
:
nodeName
}
var
fieldPodSelector
string
var
fieldPodSelector
string
if
nodeName
!=
""
{
if
nodeName
!=
""
{
...
...
This diff is collapsed.
Click to expand it.
pkg/ensurance/informer/node.go
+
3
-
3
View file @
c1cf43f1
...
@@ -11,7 +11,7 @@ import (
...
@@ -11,7 +11,7 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/cache"
"github.com/gocrane/crane/pkg/utils"
"github.com/gocrane/crane/pkg/utils"
"github.com/gocrane/crane/pkg/utils/
c
log
s
"
"github.com/gocrane/crane/pkg/utils/log"
)
)
// UpdateNodeConditions be used to update node condition with check whether it needs to update
// UpdateNodeConditions be used to update node condition with check whether it needs to update
...
@@ -59,7 +59,7 @@ func UpdateNodeTaints(node *v1.Node, taint v1.Taint) (*v1.Node, bool) {
...
@@ -59,7 +59,7 @@ func UpdateNodeTaints(node *v1.Node, taint v1.Taint) (*v1.Node, bool) {
// RemoveNodeTaints be used to update node taint
// RemoveNodeTaints be used to update node taint
func
RemoveNodeTaints
(
node
*
v1
.
Node
,
taint
v1
.
Taint
)
(
*
v1
.
Node
,
bool
)
{
func
RemoveNodeTaints
(
node
*
v1
.
Node
,
taint
v1
.
Taint
)
(
*
v1
.
Node
,
bool
)
{
c
log
s
.
Log
()
.
Info
(
fmt
.
Sprintf
(
"RemoveNodeTaints %v"
,
taint
))
log
.
Log
ger
()
.
Info
(
fmt
.
Sprintf
(
"RemoveNodeTaints %v"
,
taint
))
updatedNode
:=
node
.
DeepCopy
()
updatedNode
:=
node
.
DeepCopy
()
...
@@ -67,7 +67,7 @@ func RemoveNodeTaints(node *v1.Node, taint v1.Taint) (*v1.Node, bool) {
...
@@ -67,7 +67,7 @@ func RemoveNodeTaints(node *v1.Node, taint v1.Taint) (*v1.Node, bool) {
var
taints
[]
v1
.
Taint
var
taints
[]
v1
.
Taint
for
_
,
t
:=
range
updatedNode
.
Spec
.
Taints
{
for
_
,
t
:=
range
updatedNode
.
Spec
.
Taints
{
c
log
s
.
Log
()
.
V
(
4
)
.
Info
(
fmt
.
Sprintf
(
"taint %s"
,
t
.
Key
))
log
.
Log
ger
()
.
V
(
4
)
.
Info
(
fmt
.
Sprintf
(
"taint %s"
,
t
.
Key
))
if
t
.
Key
==
taint
.
Key
{
if
t
.
Key
==
taint
.
Key
{
bFound
=
true
bFound
=
true
}
else
{
}
else
{
...
...
This diff is collapsed.
Click to expand it.
pkg/ensurance/informer/pod.go
+
2
-
10
View file @
c1cf43f1
...
@@ -11,18 +11,14 @@ import (
...
@@ -11,18 +11,14 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/cache"
kubelettypes
"k8s.io/kubernetes/pkg/kubelet/types"
kubelettypes
"k8s.io/kubernetes/pkg/kubelet/types"
"github.com/gocrane/crane/pkg/utils/clogs"
"github.com/gocrane/crane/pkg/utils/log"
)
const
(
defaultGracePeriodSeconds
=
uint64
(
30
)
)
)
//EvictPodWithGracePeriod evict pod with grace period
//EvictPodWithGracePeriod evict pod with grace period
func
EvictPodWithGracePeriod
(
client
clientset
.
Interface
,
pod
*
v1
.
Pod
,
gracePeriodSeconds
int32
)
error
{
func
EvictPodWithGracePeriod
(
client
clientset
.
Interface
,
pod
*
v1
.
Pod
,
gracePeriodSeconds
int32
)
error
{
if
kubelettypes
.
IsCriticalPod
(
pod
)
{
if
kubelettypes
.
IsCriticalPod
(
pod
)
{
return
fmt
.
Errorf
(
"Eviction manager: cannot evict a critical pod(%s)"
,
c
log
s
.
GenerateObj
(
pod
))
return
fmt
.
Errorf
(
"Eviction manager: cannot evict a critical pod(%s)"
,
log
.
GenerateObj
(
pod
))
}
}
e
:=
&
policyv1beta1
.
Eviction
{
e
:=
&
policyv1beta1
.
Eviction
{
...
@@ -64,7 +60,3 @@ func GetPodFromInformer(podInformer cache.SharedIndexInformer, key string) (*v1.
...
@@ -64,7 +60,3 @@ func GetPodFromInformer(podInformer cache.SharedIndexInformer, key string) (*v1.
// re-assign new pod info
// re-assign new pod info
return
obj
.
(
*
v1
.
Pod
),
nil
return
obj
.
(
*
v1
.
Pod
),
nil
}
}
func
generateKey
(
namespace
string
,
podName
string
)
string
{
return
fmt
.
Sprintf
(
"%s/%s"
,
namespace
,
podName
)
}
This diff is collapsed.
Click to expand it.
pkg/ensurance/runtime/container.go
+
8
-
20
View file @
c1cf43f1
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
"golang.org/x/net/context"
"golang.org/x/net/context"
pb
"k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
pb
"k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
"github.com/gocrane/crane/pkg/utils/
c
log
s
"
"github.com/gocrane/crane/pkg/utils/log"
)
)
type
UpdateOptions
struct
{
type
UpdateOptions
struct
{
...
@@ -40,28 +40,16 @@ type ListOptions struct {
...
@@ -40,28 +40,16 @@ type ListOptions struct {
podID
string
podID
string
// Regular expression pattern to match pod or container
// Regular expression pattern to match pod or container
nameRegexp
string
nameRegexp
string
// Regular expression pattern to match the pod namespace
podNamespaceRegexp
string
// state of the sandbox
// state of the sandbox
state
string
state
string
// show verbose info for the sandbox
verbose
bool
// labels are selectors for the sandbox
// labels are selectors for the sandbox
labels
map
[
string
]
string
labels
map
[
string
]
string
// quiet is for listing just container/sandbox/image IDs
quiet
bool
// output format
output
string
// all containers
// all containers
all
bool
all
bool
// latest container
// latest container
latest
bool
latest
bool
// last n containers
// last n containers
last
int
last
int
// out with truncating the id
noTrunc
bool
// image used by the container
image
string
}
}
type
containerByCreated
[]
*
pb
.
Container
type
containerByCreated
[]
*
pb
.
Container
...
@@ -90,13 +78,13 @@ func UpdateContainerResources(client pb.RuntimeServiceClient, containerId string
...
@@ -90,13 +78,13 @@ func UpdateContainerResources(client pb.RuntimeServiceClient, containerId string
},
},
}
}
c
log
s
.
Log
()
.
V
(
5
)
.
Info
(
"UpdateContainerResourcesRequest: %v"
,
request
)
log
.
Log
ger
()
.
V
(
5
)
.
Info
(
"UpdateContainerResourcesRequest: %v"
,
request
)
r
,
err
:=
client
.
UpdateContainerResources
(
context
.
Background
(),
request
)
r
,
err
:=
client
.
UpdateContainerResources
(
context
.
Background
(),
request
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
c
log
s
.
Log
()
.
V
(
5
)
.
Info
(
"UpdateContainerResourcesResponse: %v"
,
r
)
log
.
Log
ger
()
.
V
(
5
)
.
Info
(
"UpdateContainerResourcesResponse: %v"
,
r
)
return
nil
return
nil
}
}
...
@@ -112,14 +100,14 @@ func RemoveContainer(client pb.RuntimeServiceClient, ContainerId string) error {
...
@@ -112,14 +100,14 @@ func RemoveContainer(client pb.RuntimeServiceClient, ContainerId string) error {
ContainerId
:
ContainerId
,
ContainerId
:
ContainerId
,
}
}
c
log
s
.
Log
()
.
V
(
5
)
.
Info
(
"RemoveContainerRequest: %v"
,
request
)
log
.
Log
ger
()
.
V
(
5
)
.
Info
(
"RemoveContainerRequest: %v"
,
request
)
r
,
err
:=
client
.
RemoveContainer
(
context
.
Background
(),
request
)
r
,
err
:=
client
.
RemoveContainer
(
context
.
Background
(),
request
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
c
log
s
.
Log
()
.
V
(
5
)
.
Info
(
"RemoveContainerResponse: %v"
,
r
)
log
.
Log
ger
()
.
V
(
5
)
.
Info
(
"RemoveContainerResponse: %v"
,
r
)
return
nil
return
nil
}
}
...
@@ -156,7 +144,7 @@ func ListContainers(runtimeClient pb.RuntimeServiceClient, opts ListOptions) ([]
...
@@ -156,7 +144,7 @@ func ListContainers(runtimeClient pb.RuntimeServiceClient, opts ListOptions) ([]
st
.
State
=
pb
.
ContainerState_CONTAINER_UNKNOWN
st
.
State
=
pb
.
ContainerState_CONTAINER_UNKNOWN
filter
.
State
=
st
filter
.
State
=
st
default
:
default
:
c
log
s
.
Log
()
.
Error
(
fmt
.
Errorf
(
"state should be one of created, running, exited or unknown"
),
""
)
log
.
Log
ger
()
.
Error
(
fmt
.
Errorf
(
"state should be one of created, running, exited or unknown"
),
""
)
return
[]
*
pb
.
Container
{},
fmt
.
Errorf
(
"state should be one of created, running, exited or unknown"
)
return
[]
*
pb
.
Container
{},
fmt
.
Errorf
(
"state should be one of created, running, exited or unknown"
)
}
}
}
}
...
@@ -174,14 +162,14 @@ func ListContainers(runtimeClient pb.RuntimeServiceClient, opts ListOptions) ([]
...
@@ -174,14 +162,14 @@ func ListContainers(runtimeClient pb.RuntimeServiceClient, opts ListOptions) ([]
Filter
:
filter
,
Filter
:
filter
,
}
}
c
log
s
.
Log
()
.
V
(
5
)
.
Info
(
"ListContainerRequest: %v"
,
request
)
log
.
Log
ger
()
.
V
(
5
)
.
Info
(
"ListContainerRequest: %v"
,
request
)
r
,
err
:=
runtimeClient
.
ListContainers
(
context
.
Background
(),
request
)
r
,
err
:=
runtimeClient
.
ListContainers
(
context
.
Background
(),
request
)
if
err
!=
nil
{
if
err
!=
nil
{
return
[]
*
pb
.
Container
{},
err
return
[]
*
pb
.
Container
{},
err
}
}
c
log
s
.
Log
()
.
V
(
5
)
.
Info
(
"ListContainerResponse: %v"
,
r
)
log
.
Log
ger
()
.
V
(
5
)
.
Info
(
"ListContainerResponse: %v"
,
r
)
r
.
Containers
=
filterContainersList
(
r
.
GetContainers
(),
opts
)
r
.
Containers
=
filterContainersList
(
r
.
GetContainers
(),
opts
)
...
...
This diff is collapsed.
Click to expand it.
pkg/ensurance/runtime/runtime.go
+
5
-
5
View file @
c1cf43f1
...
@@ -7,20 +7,20 @@ import (
...
@@ -7,20 +7,20 @@ import (
pb
"k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
pb
"k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
"github.com/gocrane/crane/pkg/ensurance/grpcc"
"github.com/gocrane/crane/pkg/ensurance/grpcc"
"github.com/gocrane/crane/pkg/utils/
c
log
s
"
"github.com/gocrane/crane/pkg/utils/log"
)
)
// runtimeEndpointIsSet is true when RuntimeEndpoint is configured
// runtimeEndpointIsSet is true when RuntimeEndpoint is configured
// runtimeEndpoint is CRI server runtime endpoint
// runtimeEndpoint is CRI server runtime endpoint
func
getRuntimeClientConnection
(
runtimeEndpoint
string
,
runtimeEndpointIsSet
bool
)
(
*
grpc
.
ClientConn
,
error
)
{
func
getRuntimeClientConnection
(
runtimeEndpoint
string
,
runtimeEndpointIsSet
bool
)
(
*
grpc
.
ClientConn
,
error
)
{
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
"GetRuntimeClientConnection"
)
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
"GetRuntimeClientConnection"
)
if
runtimeEndpointIsSet
&&
runtimeEndpoint
==
""
{
if
runtimeEndpointIsSet
&&
runtimeEndpoint
==
""
{
return
nil
,
fmt
.
Errorf
(
"runtime-endpoint is not set"
)
return
nil
,
fmt
.
Errorf
(
"runtime-endpoint is not set"
)
}
}
if
!
runtimeEndpointIsSet
{
if
!
runtimeEndpointIsSet
{
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"Runtime connect using default endpoints: %v. "
+
"As the default settings are now deprecated, you should set the "
+
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"Runtime connect using default endpoints: %v. "
+
"As the default settings are now deprecated, you should set the "
+
"endpoint instead."
,
defaultRuntimeEndpoints
))
"endpoint instead."
,
defaultRuntimeEndpoints
))
return
grpcc
.
InitGrpcConnection
(
defaultRuntimeEndpoints
)
return
grpcc
.
InitGrpcConnection
(
defaultRuntimeEndpoints
)
}
}
...
@@ -31,7 +31,7 @@ func getRuntimeClientConnection(runtimeEndpoint string, runtimeEndpointIsSet boo
...
@@ -31,7 +31,7 @@ func getRuntimeClientConnection(runtimeEndpoint string, runtimeEndpointIsSet boo
// imageEndpoint is CRI server image endpoint, default same as runtime endpoint
// imageEndpoint is CRI server image endpoint, default same as runtime endpoint
// imageEndpointIsSet is true when imageEndpoint is configured
// imageEndpointIsSet is true when imageEndpoint is configured
func
getImageClientConnection
(
imageEndpoint
string
,
imageEndpointIsSet
bool
)
(
*
grpc
.
ClientConn
,
error
)
{
func
getImageClientConnection
(
imageEndpoint
string
,
imageEndpointIsSet
bool
)
(
*
grpc
.
ClientConn
,
error
)
{
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
"GetImageClientConnection"
)
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
"GetImageClientConnection"
)
if
imageEndpoint
==
""
{
if
imageEndpoint
==
""
{
if
imageEndpointIsSet
&&
imageEndpoint
==
""
{
if
imageEndpointIsSet
&&
imageEndpoint
==
""
{
...
@@ -40,7 +40,7 @@ func getImageClientConnection(imageEndpoint string, imageEndpointIsSet bool) (*g
...
@@ -40,7 +40,7 @@ func getImageClientConnection(imageEndpoint string, imageEndpointIsSet bool) (*g
}
}
if
!
imageEndpointIsSet
{
if
!
imageEndpointIsSet
{
c
log
s
.
Log
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"Image connect using default endpoints: %v. "
+
"As the default settings are now deprecated, you should set the "
+
log
.
Log
ger
()
.
V
(
2
)
.
Info
(
fmt
.
Sprintf
(
"Image connect using default endpoints: %v. "
+
"As the default settings are now deprecated, you should set the "
+
"endpoint instead."
,
defaultRuntimeEndpoints
))
"endpoint instead."
,
defaultRuntimeEndpoints
))
return
grpcc
.
InitGrpcConnection
(
defaultRuntimeEndpoints
)
return
grpcc
.
InitGrpcConnection
(
defaultRuntimeEndpoints
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Write
Preview
Supports
Markdown
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