Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 48f601b

Browse files
authored
Switch to klog (#30)
1 parent 2caad5b commit 48f601b

File tree

35 files changed

+263
-2369
lines changed

35 files changed

+263
-2369
lines changed

Gopkg.lock

Lines changed: 1 addition & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ required = [
88
"k8s.io/code-generator/cmd/defaulter-gen",
99
]
1010

11-
[[constraint]]
12-
name = "github.com/sirupsen/logrus"
13-
version = "1.0.4"
14-
1511
[[constraint]]
1612
name = "github.com/pkg/errors"
1713
version = "v0.8.0"

bin/frameworkbarrier/start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ BASH_DIR=$(cd $(dirname ${BASH_SOURCE}) && pwd)
3030

3131
cd ${BASH_DIR}
3232

33-
./frameworkbarrier
33+
./frameworkbarrier "$@"
3434

3535
MNT_DIR=/mnt/frameworkbarrier
3636

bin/frameworkcontroller/start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ BASH_DIR=$(cd $(dirname ${BASH_SOURCE}) && pwd)
3030

3131
cd ${BASH_DIR}
3232

33-
./frameworkcontroller
33+
./frameworkcontroller "$@"

cmd/frameworkcontroller/main.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,12 @@ package main
2525
import (
2626
"github.com/microsoft/frameworkcontroller/pkg/common"
2727
"github.com/microsoft/frameworkcontroller/pkg/controller"
28-
"os"
29-
"os/signal"
30-
"syscall"
3128
)
3229

3330
func init() {
3431
common.InitAll()
3532
}
3633

3734
func main() {
38-
stopCh := make(chan struct{})
39-
defer close(stopCh)
40-
41-
go controller.NewFrameworkController().Run(stopCh)
42-
43-
sigTerm := make(chan os.Signal, 1)
44-
signal.Notify(sigTerm, syscall.SIGTERM)
45-
signal.Notify(sigTerm, syscall.SIGINT)
46-
<-sigTerm
35+
controller.NewFrameworkController().Run(common.NewStopChannel())
4736
}

doc/user-manual.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ All running containers of the Framework will be stopped while the object of the
8484
| Code | Body | Description |
8585
|:---- |:---- |:---- |
8686
| OK(200) | [Framework](../pkg/apis/frameworkcontroller/v1/types.go) | Return current Framework. |
87-
| NotFound(200) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
87+
| NotFound(404) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
8888

8989
#### <a name="DELETE_Framework">DELETE Framework</a>
9090
**Request**
@@ -119,7 +119,7 @@ Notes:
119119
|:---- |:---- |:---- |
120120
| OK(200) | [Framework](../pkg/apis/frameworkcontroller/v1/types.go) | The specified Framework is deleting.<br>Return current Framework. |
121121
| OK(200) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is deleted. |
122-
| NotFound(200) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
122+
| NotFound(404) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
123123

124124
#### <a name="GET_Framework">GET Framework</a>
125125
**Request**
@@ -135,7 +135,7 @@ Get the specified Framework.
135135
| Code | Body | Description |
136136
|:---- |:---- |:---- |
137137
| OK(200) | [Framework](../pkg/apis/frameworkcontroller/v1/types.go) | Return current Framework. |
138-
| NotFound(200) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
138+
| NotFound(404) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
139139

140140
#### <a name="LIST_Frameworks">LIST Frameworks</a>
141141
**Request**
@@ -171,7 +171,7 @@ Watch the change events of the specified Framework.
171171
| Code | Body | Description |
172172
|:---- |:---- |:---- |
173173
| OK(200) | [WatchEvent](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#watchevent-v1-meta) | Streaming the change events of the specified Framework. |
174-
| NotFound(200) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
174+
| NotFound(404) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
175175

176176
#### <a name="WATCH_LIST_Frameworks">WATCH_LIST Frameworks</a>
177177
**Request**

pkg/apis/frameworkcontroller/v1/funcs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ package v1
2525
import (
2626
"fmt"
2727
"github.com/microsoft/frameworkcontroller/pkg/common"
28-
log "github.com/sirupsen/logrus"
2928
core "k8s.io/api/core/v1"
3029
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
3130
"k8s.io/apimachinery/pkg/types"
31+
"k8s.io/klog"
3232
"strconv"
3333
"strings"
3434
)
@@ -577,7 +577,7 @@ func (f *Framework) TransitionFrameworkState(dstState FrameworkState) {
577577
f.Status.State = dstState
578578
f.Status.TransitionTime = meta.Now()
579579

580-
log.Infof(
580+
klog.Infof(
581581
"[%v]: Transitioned Framework from [%v] to [%v]",
582582
f.Key(), srcState, dstState)
583583
}
@@ -594,7 +594,7 @@ func (f *Framework) TransitionTaskState(
594594
taskStatus.State = dstState
595595
taskStatus.TransitionTime = meta.Now()
596596

597-
log.Infof(
597+
klog.Infof(
598598
"[%v][%v][%v]: Transitioned Task from [%v] to [%v]",
599599
f.Key(), taskRoleName, taskIndex, srcState, dstState)
600600
}

pkg/barrier/barrier.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ import (
2727
ci "github.com/microsoft/frameworkcontroller/pkg/apis/frameworkcontroller/v1"
2828
frameworkClient "github.com/microsoft/frameworkcontroller/pkg/client/clientset/versioned"
2929
"github.com/microsoft/frameworkcontroller/pkg/common"
30-
"github.com/microsoft/frameworkcontroller/pkg/util"
31-
log "github.com/sirupsen/logrus"
30+
"github.com/microsoft/frameworkcontroller/pkg/internal"
3231
"io/ioutil"
3332
apiErrors "k8s.io/apimachinery/pkg/api/errors"
3433
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
3534
"k8s.io/apimachinery/pkg/util/wait"
3635
kubeClient "k8s.io/client-go/kubernetes"
3736
"k8s.io/client-go/rest"
3837
"k8s.io/client-go/tools/clientcmd"
38+
"k8s.io/klog"
3939
"os"
4040
"strconv"
4141
"strings"
@@ -134,7 +134,7 @@ func newConfig() *Config {
134134
} else {
135135
i, err := strconv.ParseInt(barrierCheckIntervalSecStr, 10, 64)
136136
if err != nil {
137-
log.Errorf(
137+
klog.Errorf(
138138
"Failed to parse ${%v}: %v",
139139
EnvNameBarrierCheckIntervalSec, err)
140140
exit(ci.CompletionCodeContainerPermanentFailed)
@@ -148,7 +148,7 @@ func newConfig() *Config {
148148
} else {
149149
i, err := strconv.ParseInt(barrierCheckTimeoutSecStr, 10, 64)
150150
if err != nil {
151-
log.Errorf(
151+
klog.Errorf(
152152
"Failed to parse ${%v}: %v",
153153
EnvNameBarrierCheckTimeoutSec, err)
154154
exit(ci.CompletionCodeContainerPermanentFailed)
@@ -159,19 +159,19 @@ func newConfig() *Config {
159159
// Validation
160160
errPrefix := "Validation Failed: "
161161
if c.FrameworkName == "" {
162-
log.Errorf(errPrefix+
162+
klog.Errorf(errPrefix+
163163
"${%v} should not be empty",
164164
ci.EnvNameFrameworkName)
165165
exit(ci.CompletionCodeContainerPermanentFailed)
166166
}
167167
if c.BarrierCheckIntervalSec < 5 {
168-
log.Errorf(errPrefix+
168+
klog.Errorf(errPrefix+
169169
"${%v} %v should not be less than 5",
170170
EnvNameBarrierCheckIntervalSec, c.BarrierCheckIntervalSec)
171171
exit(ci.CompletionCodeContainerPermanentFailed)
172172
}
173173
if c.BarrierCheckTimeoutSec < 60 || c.BarrierCheckTimeoutSec > 20*60 {
174-
log.Errorf(errPrefix+
174+
klog.Errorf(errPrefix+
175175
"${%v} %v should not be less than 60 or greater than 20 * 60",
176176
EnvNameBarrierCheckTimeoutSec, c.BarrierCheckTimeoutSec)
177177
exit(ci.CompletionCodeContainerPermanentFailed)
@@ -195,7 +195,7 @@ func buildKubeConfig(bConfig *Config) *rest.Config {
195195
kConfig, err := clientcmd.BuildConfigFromFlags(
196196
bConfig.KubeApiServerAddress, bConfig.KubeConfigFilePath)
197197
if err != nil {
198-
log.Errorf("Failed to build KubeConfig, please ensure "+
198+
klog.Errorf("Failed to build KubeConfig, please ensure "+
199199
"${KUBE_APISERVER_ADDRESS} or ${KUBECONFIG} or ${HOME}/.kube/config or "+
200200
"${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT} is valid: "+
201201
"Error: %v", err)
@@ -208,12 +208,12 @@ func buildKubeConfig(bConfig *Config) *rest.Config {
208208
// Methods
209209
///////////////////////////////////////////////////////////////////////////////////////
210210
func NewFrameworkBarrier() *FrameworkBarrier {
211-
log.Infof("Initializing %v", ComponentName)
211+
klog.Infof("Initializing %v", ComponentName)
212212

213213
bConfig := newConfig()
214-
common.LogLines("With Config: \n%v", common.ToYaml(bConfig))
214+
klog.Infof("With Config: \n%v", common.ToYaml(bConfig))
215215
kConfig := buildKubeConfig(bConfig)
216-
kClient, fClient := util.CreateClients(kConfig)
216+
kClient, fClient := internal.CreateClients(kConfig)
217217

218218
return &FrameworkBarrier{
219219
kConfig: kConfig,
@@ -224,7 +224,7 @@ func NewFrameworkBarrier() *FrameworkBarrier {
224224
}
225225

226226
func (b *FrameworkBarrier) Run() {
227-
log.Infof("Running %v", ComponentName)
227+
klog.Infof("Running %v", ComponentName)
228228

229229
var f *ci.Framework
230230
var err error
@@ -242,7 +242,7 @@ func (b *FrameworkBarrier) Run() {
242242
isPassed = isBarrierPassed(f)
243243
return isPassed, nil
244244
} else {
245-
log.Warnf("Failed to get Framework object from ApiServer: %v", err)
245+
klog.Warningf("Failed to get Framework object from ApiServer: %v", err)
246246
if apiErrors.IsNotFound(err) {
247247
// Permanent Error: Early Stop
248248
isPermanentErr = true
@@ -256,18 +256,18 @@ func (b *FrameworkBarrier) Run() {
256256
})
257257

258258
if isPassed {
259-
log.Infof("BarrierPassed: " +
259+
klog.Infof("BarrierPassed: " +
260260
"All Tasks are ready with not nil PodIP.")
261261
dumpFramework(f)
262262
generateInjector(f)
263263
exit(ci.CompletionCodeSucceeded)
264264
} else {
265265
if err == nil {
266-
log.Errorf("BarrierNotPassed: " +
266+
klog.Errorf("BarrierNotPassed: " +
267267
"Timeout to wait all Tasks are ready with not nil PodIP.")
268268
exit(ci.CompletionCodeContainerTransientConflictFailed)
269269
} else {
270-
log.Errorf("Failed to get Framework object from ApiServer: %v", err)
270+
klog.Errorf("Failed to get Framework object from ApiServer: %v", err)
271271
if isPermanentErr {
272272
exit(ci.CompletionCodeContainerPermanentFailed)
273273
} else {
@@ -296,12 +296,12 @@ func isBarrierPassed(f *ci.Framework) bool {
296296

297297
// Wait until readyTaskCount is consistent with totalTaskCount.
298298
if readyTaskCount == totalTaskCount {
299-
log.Infof("BarrierPassed: "+
299+
klog.Infof("BarrierPassed: "+
300300
"%v/%v Tasks are ready with not nil PodIP.",
301301
readyTaskCount, totalTaskCount)
302302
return true
303303
} else {
304-
log.Warnf("BarrierNotPassed: "+
304+
klog.Warningf("BarrierNotPassed: "+
305305
"%v/%v Tasks are ready with not nil PodIP.",
306306
readyTaskCount, totalTaskCount)
307307
return false
@@ -316,13 +316,13 @@ func isTaskReady(taskStatus *ci.TaskStatus) bool {
316316
func dumpFramework(f *ci.Framework) {
317317
err := ioutil.WriteFile(FrameworkObjectFilePath, []byte(common.ToJson(f)), 0644)
318318
if err != nil {
319-
log.Errorf(
319+
klog.Errorf(
320320
"Failed to dump the Framework object to local file: %v, %v",
321321
FrameworkObjectFilePath, err)
322322
exit(ci.CompletionCode(1))
323323
}
324324

325-
log.Infof(
325+
klog.Infof(
326326
"Succeeded to dump the Framework object to local file: %v",
327327
FrameworkObjectFilePath)
328328
}
@@ -393,32 +393,32 @@ func generateInjector(f *ci.Framework) {
393393

394394
err := ioutil.WriteFile(InjectorFilePath, []byte(injector.String()), 0755)
395395
if err != nil {
396-
log.Errorf(
396+
klog.Errorf(
397397
"Failed to generate the injector script to local file: %v, %v",
398398
InjectorFilePath, err)
399399
exit(ci.CompletionCode(1))
400400
}
401401

402-
log.Infof(
402+
klog.Infof(
403403
"Succeeded to generate the injector script to local file: %v",
404404
InjectorFilePath)
405405
}
406406

407407
func exit(cc ci.CompletionCode) {
408408
logPfx := fmt.Sprintf("ExitCode: %v: Exit with ", cc)
409409
if cc == ci.CompletionCodeSucceeded {
410-
log.Infof(logPfx + "success.")
410+
klog.Infof(logPfx + "success.")
411411
} else if cc == ci.CompletionCodeContainerTransientFailed {
412-
log.Errorf(logPfx +
412+
klog.Errorf(logPfx +
413413
"transient failure to tell controller to retry.")
414414
} else if cc == ci.CompletionCodeContainerTransientConflictFailed {
415-
log.Errorf(logPfx +
415+
klog.Errorf(logPfx +
416416
"transient conflict failure to tell controller to back off retry.")
417417
} else if cc == ci.CompletionCodeContainerPermanentFailed {
418-
log.Errorf(logPfx +
418+
klog.Errorf(logPfx +
419419
"permanent failure to tell controller not to retry.")
420420
} else {
421-
log.Errorf(logPfx +
421+
klog.Errorf(logPfx +
422422
"unknown failure to tell controller to retry within maxRetryCount.")
423423
}
424424

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
package common
2424

2525
import (
26-
log "github.com/sirupsen/logrus"
27-
"io"
26+
"k8s.io/klog"
2827
)
2928

3029
type Empty struct{}
@@ -69,20 +68,9 @@ func (s ImmutableSet) Contains(item T) bool {
6968
return s.set.Contains(item)
7069
}
7170

72-
type LogHook struct {
73-
LogLevels []log.Level
74-
LogWriter io.Writer
75-
}
76-
77-
func (lh *LogHook) Levels() []log.Level {
78-
return lh.LogLevels
79-
}
71+
type KlogWriter struct{}
8072

81-
func (lh *LogHook) Fire(entry *log.Entry) error {
82-
str, err := entry.String()
83-
if err != nil {
84-
return err
85-
}
86-
_, err = lh.LogWriter.Write([]byte(str))
87-
return err
73+
func (w KlogWriter) Write(data []byte) (n int, err error) {
74+
klog.InfoDepth(1, string(data))
75+
return len(data), nil
8876
}

0 commit comments

Comments
 (0)