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

Switch to klog #30

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ required = [
"k8s.io/code-generator/cmd/defaulter-gen",
]

[[constraint]]
name = "github.com/sirupsen/logrus"
version = "1.0.4"

[[constraint]]
name = "github.com/pkg/errors"
version = "v0.8.0"
Expand Down
2 changes: 1 addition & 1 deletion bin/frameworkbarrier/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ BASH_DIR=$(cd $(dirname ${BASH_SOURCE}) && pwd)

cd ${BASH_DIR}

./frameworkbarrier
./frameworkbarrier "$@"

MNT_DIR=/mnt/frameworkbarrier

Expand Down
2 changes: 1 addition & 1 deletion bin/frameworkcontroller/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ BASH_DIR=$(cd $(dirname ${BASH_SOURCE}) && pwd)

cd ${BASH_DIR}

./frameworkcontroller
./frameworkcontroller "$@"
13 changes: 1 addition & 12 deletions cmd/frameworkcontroller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,12 @@ package main
import (
"github.com/microsoft/frameworkcontroller/pkg/common"
"github.com/microsoft/frameworkcontroller/pkg/controller"
"os"
"os/signal"
"syscall"
)

func init() {
common.InitAll()
}

func main() {
stopCh := make(chan struct{})
defer close(stopCh)

go controller.NewFrameworkController().Run(stopCh)

sigTerm := make(chan os.Signal, 1)
signal.Notify(sigTerm, syscall.SIGTERM)
signal.Notify(sigTerm, syscall.SIGINT)
<-sigTerm
controller.NewFrameworkController().Run(common.NewStopChannel())
}
8 changes: 4 additions & 4 deletions doc/user-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ All running containers of the Framework will be stopped while the object of the
| Code | Body | Description |
|:---- |:---- |:---- |
| OK(200) | [Framework](../pkg/apis/frameworkcontroller/v1/types.go) | Return current Framework. |
| NotFound(200) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
| NotFound(404) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |

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

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

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

#### <a name="WATCH_LIST_Frameworks">WATCH_LIST Frameworks</a>
**Request**
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/frameworkcontroller/v1/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ package v1
import (
"fmt"
"github.com/microsoft/frameworkcontroller/pkg/common"
log "github.com/sirupsen/logrus"
core "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog"
"strconv"
"strings"
)
Expand Down Expand Up @@ -577,7 +577,7 @@ func (f *Framework) TransitionFrameworkState(dstState FrameworkState) {
f.Status.State = dstState
f.Status.TransitionTime = meta.Now()

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

log.Infof(
klog.Infof(
"[%v][%v][%v]: Transitioned Task from [%v] to [%v]",
f.Key(), taskRoleName, taskIndex, srcState, dstState)
}
54 changes: 27 additions & 27 deletions pkg/barrier/barrier.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import (
ci "github.com/microsoft/frameworkcontroller/pkg/apis/frameworkcontroller/v1"
frameworkClient "github.com/microsoft/frameworkcontroller/pkg/client/clientset/versioned"
"github.com/microsoft/frameworkcontroller/pkg/common"
"github.com/microsoft/frameworkcontroller/pkg/util"
log "github.com/sirupsen/logrus"
"github.com/microsoft/frameworkcontroller/pkg/internal"
"io/ioutil"
apiErrors "k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
kubeClient "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -134,7 +134,7 @@ func newConfig() *Config {
} else {
i, err := strconv.ParseInt(barrierCheckIntervalSecStr, 10, 64)
if err != nil {
log.Errorf(
klog.Errorf(
"Failed to parse ${%v}: %v",
EnvNameBarrierCheckIntervalSec, err)
exit(ci.CompletionCodeContainerPermanentFailed)
Expand All @@ -148,7 +148,7 @@ func newConfig() *Config {
} else {
i, err := strconv.ParseInt(barrierCheckTimeoutSecStr, 10, 64)
if err != nil {
log.Errorf(
klog.Errorf(
"Failed to parse ${%v}: %v",
EnvNameBarrierCheckTimeoutSec, err)
exit(ci.CompletionCodeContainerPermanentFailed)
Expand All @@ -159,19 +159,19 @@ func newConfig() *Config {
// Validation
errPrefix := "Validation Failed: "
if c.FrameworkName == "" {
log.Errorf(errPrefix+
klog.Errorf(errPrefix+
"${%v} should not be empty",
ci.EnvNameFrameworkName)
exit(ci.CompletionCodeContainerPermanentFailed)
}
if c.BarrierCheckIntervalSec < 5 {
log.Errorf(errPrefix+
klog.Errorf(errPrefix+
"${%v} %v should not be less than 5",
EnvNameBarrierCheckIntervalSec, c.BarrierCheckIntervalSec)
exit(ci.CompletionCodeContainerPermanentFailed)
}
if c.BarrierCheckTimeoutSec < 60 || c.BarrierCheckTimeoutSec > 20*60 {
log.Errorf(errPrefix+
klog.Errorf(errPrefix+
"${%v} %v should not be less than 60 or greater than 20 * 60",
EnvNameBarrierCheckTimeoutSec, c.BarrierCheckTimeoutSec)
exit(ci.CompletionCodeContainerPermanentFailed)
Expand All @@ -195,7 +195,7 @@ func buildKubeConfig(bConfig *Config) *rest.Config {
kConfig, err := clientcmd.BuildConfigFromFlags(
bConfig.KubeApiServerAddress, bConfig.KubeConfigFilePath)
if err != nil {
log.Errorf("Failed to build KubeConfig, please ensure "+
klog.Errorf("Failed to build KubeConfig, please ensure "+
"${KUBE_APISERVER_ADDRESS} or ${KUBECONFIG} or ${HOME}/.kube/config or "+
"${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT} is valid: "+
"Error: %v", err)
Expand All @@ -208,12 +208,12 @@ func buildKubeConfig(bConfig *Config) *rest.Config {
// Methods
///////////////////////////////////////////////////////////////////////////////////////
func NewFrameworkBarrier() *FrameworkBarrier {
log.Infof("Initializing %v", ComponentName)
klog.Infof("Initializing %v", ComponentName)

bConfig := newConfig()
common.LogLines("With Config: \n%v", common.ToYaml(bConfig))
klog.Infof("With Config: \n%v", common.ToYaml(bConfig))
kConfig := buildKubeConfig(bConfig)
kClient, fClient := util.CreateClients(kConfig)
kClient, fClient := internal.CreateClients(kConfig)

return &FrameworkBarrier{
kConfig: kConfig,
Expand All @@ -224,7 +224,7 @@ func NewFrameworkBarrier() *FrameworkBarrier {
}

func (b *FrameworkBarrier) Run() {
log.Infof("Running %v", ComponentName)
klog.Infof("Running %v", ComponentName)

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

if isPassed {
log.Infof("BarrierPassed: " +
klog.Infof("BarrierPassed: " +
"All Tasks are ready with not nil PodIP.")
dumpFramework(f)
generateInjector(f)
exit(ci.CompletionCodeSucceeded)
} else {
if err == nil {
log.Errorf("BarrierNotPassed: " +
klog.Errorf("BarrierNotPassed: " +
"Timeout to wait all Tasks are ready with not nil PodIP.")
exit(ci.CompletionCodeContainerTransientConflictFailed)
} else {
log.Errorf("Failed to get Framework object from ApiServer: %v", err)
klog.Errorf("Failed to get Framework object from ApiServer: %v", err)
if isPermanentErr {
exit(ci.CompletionCodeContainerPermanentFailed)
} else {
Expand Down Expand Up @@ -296,12 +296,12 @@ func isBarrierPassed(f *ci.Framework) bool {

// Wait until readyTaskCount is consistent with totalTaskCount.
if readyTaskCount == totalTaskCount {
log.Infof("BarrierPassed: "+
klog.Infof("BarrierPassed: "+
"%v/%v Tasks are ready with not nil PodIP.",
readyTaskCount, totalTaskCount)
return true
} else {
log.Warnf("BarrierNotPassed: "+
klog.Warningf("BarrierNotPassed: "+
"%v/%v Tasks are ready with not nil PodIP.",
readyTaskCount, totalTaskCount)
return false
Expand All @@ -316,13 +316,13 @@ func isTaskReady(taskStatus *ci.TaskStatus) bool {
func dumpFramework(f *ci.Framework) {
err := ioutil.WriteFile(FrameworkObjectFilePath, []byte(common.ToJson(f)), 0644)
if err != nil {
log.Errorf(
klog.Errorf(
"Failed to dump the Framework object to local file: %v, %v",
FrameworkObjectFilePath, err)
exit(ci.CompletionCode(1))
}

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

err := ioutil.WriteFile(InjectorFilePath, []byte(injector.String()), 0755)
if err != nil {
log.Errorf(
klog.Errorf(
"Failed to generate the injector script to local file: %v, %v",
InjectorFilePath, err)
exit(ci.CompletionCode(1))
}

log.Infof(
klog.Infof(
"Succeeded to generate the injector script to local file: %v",
InjectorFilePath)
}

func exit(cc ci.CompletionCode) {
logPfx := fmt.Sprintf("ExitCode: %v: Exit with ", cc)
if cc == ci.CompletionCodeSucceeded {
log.Infof(logPfx + "success.")
klog.Infof(logPfx + "success.")
} else if cc == ci.CompletionCodeContainerTransientFailed {
log.Errorf(logPfx +
klog.Errorf(logPfx +
"transient failure to tell controller to retry.")
} else if cc == ci.CompletionCodeContainerTransientConflictFailed {
log.Errorf(logPfx +
klog.Errorf(logPfx +
"transient conflict failure to tell controller to back off retry.")
} else if cc == ci.CompletionCodeContainerPermanentFailed {
log.Errorf(logPfx +
klog.Errorf(logPfx +
"permanent failure to tell controller not to retry.")
} else {
log.Errorf(logPfx +
klog.Errorf(logPfx +
"unknown failure to tell controller to retry within maxRetryCount.")
}

Expand Down
22 changes: 5 additions & 17 deletions pkg/common/common_type.go → pkg/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
package common

import (
log "github.com/sirupsen/logrus"
"io"
"k8s.io/klog"
)

type Empty struct{}
Expand Down Expand Up @@ -69,20 +68,9 @@ func (s ImmutableSet) Contains(item T) bool {
return s.set.Contains(item)
}

type LogHook struct {
LogLevels []log.Level
LogWriter io.Writer
}

func (lh *LogHook) Levels() []log.Level {
return lh.LogLevels
}
type KlogWriter struct{}

func (lh *LogHook) Fire(entry *log.Entry) error {
str, err := entry.String()
if err != nil {
return err
}
_, err = lh.LogWriter.Write([]byte(str))
return err
func (w KlogWriter) Write(data []byte) (n int, err error) {
klog.InfoDepth(1, string(data))
return len(data), nil
}
Loading