Revert "Remove pkg/logs package"
This reverts commit b6f854f849.
Signed-off-by: James Munnelly <james@munnelly.eu>
This commit is contained in:
parent
9d192e3ffe
commit
175e90c158
@ -46,6 +46,7 @@ filegroup(
|
||||
"//pkg/client/listers/certmanager/v1alpha1:all-srcs",
|
||||
"//pkg/controller:all-srcs",
|
||||
"//pkg/issuer:all-srcs",
|
||||
"//pkg/logs:all-srcs",
|
||||
"//pkg/scheduler:all-srcs",
|
||||
"//pkg/util:all-srcs",
|
||||
"//test/e2e:all-srcs",
|
||||
|
||||
@ -16,7 +16,10 @@ go_library(
|
||||
srcs = ["main.go"],
|
||||
importpath = "github.com/jetstack/cert-manager/cmd/acmesolver",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = ["//pkg/issuer/acme/http/solver:go_default_library"],
|
||||
deps = [
|
||||
"//pkg/issuer/acme/http/solver:go_default_library",
|
||||
"//pkg/logs:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_binary(
|
||||
|
||||
@ -21,6 +21,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/jetstack/cert-manager/pkg/issuer/acme/http/solver"
|
||||
"github.com/jetstack/cert-manager/pkg/logs"
|
||||
)
|
||||
|
||||
// acmesolver solves ACME http-01 challenges. This is intended to run as a pod
|
||||
@ -35,6 +36,9 @@ var (
|
||||
)
|
||||
|
||||
func main() {
|
||||
logs.InitLogs()
|
||||
defer logs.FlushLogs()
|
||||
|
||||
flag.Parse()
|
||||
|
||||
s := &solver.HTTP01Solver{
|
||||
|
||||
@ -33,6 +33,7 @@ go_library(
|
||||
"//pkg/issuer/ca:go_default_library",
|
||||
"//pkg/issuer/selfsigned:go_default_library",
|
||||
"//pkg/issuer/vault:go_default_library",
|
||||
"//pkg/logs:go_default_library",
|
||||
"//pkg/util:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/github.com/gorilla/mux:go_default_library",
|
||||
|
||||
@ -23,9 +23,13 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"github.com/jetstack/cert-manager/pkg/logs"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logs.InitLogs()
|
||||
defer logs.FlushLogs()
|
||||
stopCh := SetupSignalHandler()
|
||||
|
||||
cmd := NewCommandStartCertManagerController(os.Stdout, os.Stderr, stopCh)
|
||||
|
||||
@ -18,6 +18,7 @@ go_library(
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"//pkg/apis/certmanager/validation/webhooks:go_default_library",
|
||||
"//pkg/logs:go_default_library",
|
||||
"//vendor/github.com/openshift/generic-admission-server/pkg/cmd:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@ -19,8 +19,10 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/jetstack/cert-manager/pkg/apis/certmanager/validation/webhooks"
|
||||
"github.com/openshift/generic-admission-server/pkg/cmd"
|
||||
|
||||
"github.com/jetstack/cert-manager/pkg/apis/certmanager/validation/webhooks"
|
||||
"github.com/jetstack/cert-manager/pkg/logs"
|
||||
)
|
||||
|
||||
var certHook cmd.ValidatingAdmissionHook = &webhooks.CertificateAdmissionHook{}
|
||||
@ -28,6 +30,9 @@ var issuerHook cmd.ValidatingAdmissionHook = &webhooks.IssuerAdmissionHook{}
|
||||
var clusterIssuerHook cmd.ValidatingAdmissionHook = &webhooks.ClusterIssuerAdmissionHook{}
|
||||
|
||||
func main() {
|
||||
logs.InitLogs()
|
||||
defer logs.FlushLogs()
|
||||
|
||||
// Avoid "logging before flag.Parse" errors from glog
|
||||
flag.CommandLine.Parse([]string{})
|
||||
|
||||
|
||||
27
pkg/logs/BUILD.bazel
Normal file
27
pkg/logs/BUILD.bazel
Normal file
@ -0,0 +1,27 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["logs.go"],
|
||||
importpath = "github.com/jetstack/cert-manager/pkg/logs",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/github.com/spf13/pflag:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
61
pkg/logs/logs.go
Normal file
61
pkg/logs/logs.go
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright 2018 The Jetstack cert-manager contributors.
|
||||
|
||||
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 logs
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
)
|
||||
|
||||
var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes")
|
||||
|
||||
// TODO(thockin): This is temporary until we agree on log dirs and put those into each cmd.
|
||||
func init() {
|
||||
flag.Set("logtostderr", "true")
|
||||
}
|
||||
|
||||
// GlogWriter serves as a bridge between the standard log package and the glog package.
|
||||
type GlogWriter struct{}
|
||||
|
||||
// Write implements the io.Writer interface.
|
||||
func (writer GlogWriter) Write(data []byte) (n int, err error) {
|
||||
glog.Info(string(data))
|
||||
return len(data), nil
|
||||
}
|
||||
|
||||
// InitLogs initializes logs the way we want for kubernetes.
|
||||
func InitLogs() {
|
||||
log.SetOutput(GlogWriter{})
|
||||
log.SetFlags(0)
|
||||
// The default glog flush interval is 30 seconds, which is frighteningly long.
|
||||
go wait.Until(glog.Flush, *logFlushFreq, wait.NeverStop)
|
||||
}
|
||||
|
||||
// FlushLogs flushes logs immediately.
|
||||
func FlushLogs() {
|
||||
glog.Flush()
|
||||
}
|
||||
|
||||
// NewLogger creates a new log.Logger which sends logs to glog.Info.
|
||||
func NewLogger(prefix string) *log.Logger {
|
||||
return log.New(GlogWriter{}, prefix, 0)
|
||||
}
|
||||
@ -30,6 +30,7 @@ go_test(
|
||||
embed = [":go_default_library"],
|
||||
tags = ["manual"],
|
||||
deps = [
|
||||
"//pkg/logs:go_default_library",
|
||||
"//test/e2e/framework:go_default_library",
|
||||
"//test/e2e/suite:go_default_library",
|
||||
"//vendor/github.com/onsi/ginkgo:go_default_library",
|
||||
|
||||
@ -29,6 +29,7 @@ import (
|
||||
"github.com/onsi/gomega"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
|
||||
"github.com/jetstack/cert-manager/pkg/logs"
|
||||
"github.com/jetstack/cert-manager/test/e2e/framework"
|
||||
_ "github.com/jetstack/cert-manager/test/e2e/suite"
|
||||
)
|
||||
@ -48,6 +49,9 @@ func init() {
|
||||
}
|
||||
|
||||
func TestE2E(t *testing.T) {
|
||||
logs.InitLogs()
|
||||
defer logs.FlushLogs()
|
||||
|
||||
if err := framework.DefaultConfig.Validate(); err != nil {
|
||||
t.Errorf("Invalid test config: %v", err)
|
||||
t.Fail()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user