Skip to content

Commit

Permalink
Fix missing logs due to mixed klog versions
Browse files Browse the repository at this point in the history
This makes klog consistent with the core of the Kubernetes project (as 
of v1.19) which used klog/v2.

While on differing versions we will lose logs (only one version will 
bind the correct flag value) so we should upgrade to v2 to ensure all 
logs are being printed correctly.
  • Loading branch information
JoelSpeed committed Sep 29, 2020
1 parent 7b66ff3 commit f0c024d
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"github.com/openshift/machine-api-operator/pkg/controller/machine"
"github.com/openshift/machine-api-operator/pkg/metrics"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/klog"
"k8s.io/klog/klogr"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"
machineactuator "sigs.k8s.io/cluster-api-provider-aws/pkg/actuators/machine"
machinesetcontroller "sigs.k8s.io/cluster-api-provider-aws/pkg/actuators/machineset"
awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/client"
Expand Down
4 changes: 2 additions & 2 deletions cmd/termination-handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"os"
"time"

"k8s.io/klog"
"k8s.io/klog/klogr"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"
"sigs.k8s.io/cluster-api-provider-aws/pkg/termination"
"sigs.k8s.io/cluster-api-provider-aws/pkg/version"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
k8s.io/apimachinery v0.19.0
k8s.io/client-go v0.19.0
k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.3.0
k8s.io/utils v0.0.0-20200729134348-d5654de09c73
sigs.k8s.io/controller-runtime v0.6.2
sigs.k8s.io/controller-tools v0.3.0
Expand Down
2 changes: 1 addition & 1 deletion pkg/actuators/machine/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/record"
"k8s.io/klog"
"k8s.io/klog/v2"
awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/client"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/actuators/machine/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
mapierrors "github.com/openshift/machine-api-operator/pkg/controller/machine"
"github.com/openshift/machine-api-operator/pkg/metrics"
"k8s.io/klog"
"k8s.io/klog/v2"
awsproviderv1 "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsprovider/v1beta1"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"

Expand Down
4 changes: 2 additions & 2 deletions pkg/actuators/machine/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

errorutil "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/klog"
"k8s.io/klog/v2"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
Expand Down Expand Up @@ -66,7 +66,7 @@ func registerWithNetworkLoadBalancers(client awsclient.Client, names []string, i
targetGroups[*targetGroup.TargetGroupArn] = targetGroup
}
}
if klog.V(4) {
if klog.V(4).Enabled() {
targetGroupArns := make([]string, 0, len(targetGroups))
for arn := range targetGroups {
targetGroupArns = append(targetGroupArns, fmt.Sprintf("%q", arn))
Expand Down
2 changes: 1 addition & 1 deletion pkg/actuators/machine/machine_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
machineapierros "github.com/openshift/machine-api-operator/pkg/controller/machine"
corev1 "k8s.io/api/core/v1"
"k8s.io/klog"
"k8s.io/klog/v2"
awsproviderv1 "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsprovider/v1beta1"
awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/client"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
Expand Down
2 changes: 1 addition & 1 deletion pkg/actuators/machine/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
errorutil "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/klog"
"k8s.io/klog/v2"

awsproviderv1 "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsprovider/v1beta1"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/actuators/machine/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/aws/aws-sdk-go/service/ec2"
machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
machinecontroller "github.com/openshift/machine-api-operator/pkg/controller/machine"
"k8s.io/klog"
"k8s.io/klog/v2"
awsproviderv1 "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsprovider/v1beta1"
awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/client"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/awsprovider/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/klog"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/scheme"
"sigs.k8s.io/yaml"
)
Expand Down
8 changes: 8 additions & 0 deletions vendor/k8s.io/klog/v2/klogr/README.md

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

201 changes: 201 additions & 0 deletions vendor/k8s.io/klog/v2/klogr/klogr.go

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

1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ k8s.io/klog
k8s.io/klog/klogr
# k8s.io/klog/v2 v2.3.0
k8s.io/klog/v2
k8s.io/klog/v2/klogr
# k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6
k8s.io/kube-openapi/pkg/common
k8s.io/kube-openapi/pkg/util/proto
Expand Down

0 comments on commit f0c024d

Please sign in to comment.