Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: remove logging from version.go #481

Merged
merged 1 commit into from
Jan 26, 2024
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
4 changes: 1 addition & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ func main() {
os.Exit(0)
}

version.Print()

options := ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Expand Down Expand Up @@ -197,7 +195,7 @@ func main() {
}()
}

setupLog.Info("starting manager")
setupLog.Info("starting manager", "version", version.Get(), "go version", version.GoVersion)
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
Expand Down
10 changes: 0 additions & 10 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,13 @@ package version
import (
"fmt"
"runtime"

ctrl "sigs.k8s.io/controller-runtime"
)

var log = ctrl.Log.WithName("version")

var (
Version = "" // version will be replaced while building the binary using ldflags
GoVersion = fmt.Sprintf("%s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH)
)

// Print() logs the operator version and related information
func Print() {
log.Info("operator", "version", Version)
log.Info("go", "version", GoVersion)
}

// Get() returns the operator version
func Get() string {
return Version
Expand Down
31 changes: 0 additions & 31 deletions version/version_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package version

import (
"bufio"
"bytes"
"regexp"
"strings"
"testing"

ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

func TestEmptyVersion(t *testing.T) {
Expand Down Expand Up @@ -39,28 +33,3 @@ func TestGet(t *testing.T) {
t.Error("Get returned value, expected only empty string. Got:", ver)
}
}

func TestPrint(t *testing.T) {
var buffer bytes.Buffer

opts := zap.Options{
Development: true,
}

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts), zap.WriteTo(&buffer)))
writer := bufio.NewWriter(&buffer)
log = ctrl.Log.WithName("version")

Print()
writer.Flush()

printOutput := buffer.String()

if printOutput == "" {
t.Error("Print returned empty string, expected value. Got:", printOutput)
}

if !strings.Contains(printOutput, "{\"version\": \"\"}") && !strings.Contains(printOutput, "{\"go-version\": \"go") {
t.Error("Print returned unexpected value. Got:", printOutput)
}
}
Loading