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

log: change from glog to klog #1081

Merged
merged 2 commits into from
Dec 4, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 18 additions & 17 deletions cmd/appgw-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
n "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/to"
"github.com/golang/glog"
"github.com/spf13/pflag"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"

"github.com/Azure/application-gateway-kubernetes-ingress/pkg/appgw"
"github.com/Azure/application-gateway-kubernetes-ingress/pkg/azure"
Expand Down Expand Up @@ -60,9 +60,10 @@ var allowedSkus = map[n.ApplicationGatewayTier]interface{}{

func main() {
// Log output is buffered... Calling Flush before exiting guarantees all log output is written.
defer glog.Flush()
klog.InitFlags(nil)
defer klog.Flush()
if err := flags.Parse(os.Args); err != nil {
glog.Fatal("Error parsing command line arguments:", err)
klog.Fatal("Error parsing command line arguments:", err)
}

env := environment.GetEnv()
Expand All @@ -75,7 +76,7 @@ func main() {
// Reference: https://github.com/kubernetes-sigs/cloud-provider-azure/blob/master/docs/cloud-provider-config.md#cloud-provider-config
cpConfig, err := azure.NewCloudProviderConfig(env.CloudProviderConfigLocation)
if err != nil {
glog.Infof("Unable to load cloud provider config '%s'. Error: %s", env.CloudProviderConfigLocation, err.Error())
klog.Infof("Unable to load cloud provider config '%s'. Error: %s", env.CloudProviderConfigLocation, err.Error())
}

env.Consolidate(cpConfig)
Expand Down Expand Up @@ -105,7 +106,7 @@ func main() {
if agicPod != nil {
recorder.Event(agicPod, v1.EventTypeWarning, events.ReasonValidatonError, errorLine)
}
glog.Fatal(errorLine)
klog.Fatal(errorLine)
}

azClient := azure.NewAzClient(azure.SubscriptionID(env.SubscriptionID), azure.ResourceGroup(env.ResourceGroupName), azure.ResourceName(env.AppGwName), env.ClientID)
Expand All @@ -125,15 +126,15 @@ func main() {
env.HTTPServicePort)
httpServer.Start()

glog.V(3).Infof("Appication Gateway Details: Subscription=\"%s\" Resource Group=\"%s\" Name=\"%s\"", env.SubscriptionID, env.ResourceGroupName, env.AppGwName)
klog.V(3).Infof("Appication Gateway Details: Subscription=\"%s\" Resource Group=\"%s\" Name=\"%s\"", env.SubscriptionID, env.ResourceGroupName, env.AppGwName)

var authorizer autorest.Authorizer
if authorizer, err = azure.GetAuthorizerWithRetry(env.AuthLocation, env.UseManagedIdentityForPod, cpConfig, maxRetryCount, retryPause); err != nil {
errorLine := fmt.Sprint("Failed obtaining authentication token for Azure Resource Manager: ", err)
if agicPod != nil {
recorder.Event(agicPod, v1.EventTypeWarning, events.ReasonARMAuthFailure, errorLine)
}
glog.Fatal(errorLine)
klog.Fatal(errorLine)
} else {
azClient.SetAuthorizer(authorizer)
}
Expand All @@ -156,31 +157,31 @@ func main() {
if agicPod != nil {
recorder.Event(agicPod, v1.EventTypeWarning, events.ReasonFailedDeployingAppGw, errorLine)
}
glog.Fatal(errorLine)
klog.Fatal(errorLine)
}
} else {
errorLine := fmt.Sprint("Failed getting Application Gateway: ", err)
if agicPod != nil {
recorder.Event(agicPod, v1.EventTypeWarning, events.ReasonARMAuthFailure, errorLine)
}
glog.Fatal(errorLine)
klog.Fatal(errorLine)
}
}

// namespace validations
if err := validateNamespaces(namespaces, kubeClient); err != nil {
glog.Fatal(err) // side-effect: will panic on non-existent namespace
klog.Fatal(err) // side-effect: will panic on non-existent namespace
}
if len(namespaces) == 0 {
glog.Info("Ingress Controller will observe all namespaces.")
klog.Info("Ingress Controller will observe all namespaces.")
} else {
glog.Info("Ingress Controller will observe the following namespaces:", strings.Join(namespaces, ","))
klog.Info("Ingress Controller will observe the following namespaces:", strings.Join(namespaces, ","))
}

// fatal config validations
appGw, _ := azClient.GetGateway()
if err := appgw.FatalValidateOnExistingConfig(recorder, appGw.ApplicationGatewayPropertiesFormat, env); err != nil {
glog.Fatal("Got a fatal validation error on existing Application Gateway config. Please update Application Gateway or the controller's helm config. Error:", err)
klog.Fatal("Got a fatal validation error on existing Application Gateway config. Please update Application Gateway or the controller's helm config. Error:", err)
}

if _, exists := allowedSkus[appGw.Sku.Tier]; !exists {
Expand All @@ -190,7 +191,7 @@ func main() {
}
// Slow down the cycling of the AGIC pod.
time.Sleep(5 * time.Second)
glog.Fatal(errorLine)
klog.Fatal(errorLine)
}

// associate route table to application gateway subnet
Expand All @@ -200,7 +201,7 @@ func main() {

err = azClient.ApplyRouteTable(subnetID, routeTableID)
if err != nil {
glog.V(5).Infof("Unable to associate Application Gateway subnet '%s' with route table '%s' due to error (this is relevant for AKS clusters using 'Kubenet' network plugin): [%+v]",
klog.V(5).Infof("Unable to associate Application Gateway subnet '%s' with route table '%s' due to error (this is relevant for AKS clusters using 'Kubenet' network plugin): [%+v]",
subnetID,
routeTableID,
err)
Expand All @@ -212,7 +213,7 @@ func main() {
if agicPod != nil {
recorder.Event(agicPod, v1.EventTypeWarning, events.ReasonARMAuthFailure, errorLine)
}
glog.Fatal(errorLine)
klog.Fatal(errorLine)
}

sigChan := make(chan os.Signal)
Expand All @@ -221,5 +222,5 @@ func main() {

appGwIngressController.Stop()
httpServer.Stop()
glog.Info("Goodbye!")
klog.Info("Goodbye!")
}
16 changes: 8 additions & 8 deletions cmd/appgw-ingress/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strconv"
"strings"

"github.com/golang/glog"
"k8s.io/klog/v2"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -40,7 +40,7 @@ func validateNamespaces(namespaces []string, kubeClient *kubernetes.Clientset) e
controllererrors.ErrorNoSuchNamespace,
"error creating informers; Namespaces do not exist or Ingress Controller has no access to: %v", strings.Join(nonExistent, ","),
)
glog.Errorf(err.Error())
klog.Errorf(err.Error())
return err
}
return nil
Expand Down Expand Up @@ -72,28 +72,28 @@ func getKubeClientConfig() *rest.Config {
if *inCluster {
config, err := rest.InClusterConfig()
if err != nil {
glog.Fatal("Error creating in-cluster client configuration:", err)
klog.Fatal("Error creating in-cluster client configuration:", err)
}
return config
}

// use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", *kubeConfigFile)
if err != nil {
glog.Fatal("error creating client configuration:", err)
klog.Fatal("error creating client configuration:", err)
}

return config
}

func getEventRecorder(kubeClient kubernetes.Interface) record.EventRecorder {
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(glog.V(5).Infof)
eventBroadcaster.StartLogging(klog.V(5).Infof)
sink := &typedcorev1.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")}
eventBroadcaster.StartRecordingToSink(sink)
hostname, err := os.Hostname()
if err != nil {
glog.Error("Could not obtain host name from the operating system", err)
klog.Error("Could not obtain host name from the operating system", err)
hostname = "unknown-hostname"
}
source := v1.EventSource{
Expand All @@ -109,10 +109,10 @@ func getEventRecorder(kubeClient kubernetes.Interface) record.EventRecorder {
func getVerbosity(flagVerbosity int, envVerbosity string) int {
envVerbosityInt, err := strconv.Atoi(envVerbosity)
if err != nil {
glog.Infof("Using verbosity level %d from CLI flag %s", flagVerbosity, verbosityFlag)
klog.Infof("Using verbosity level %d from CLI flag %s", flagVerbosity, verbosityFlag)
return flagVerbosity
}
glog.Infof("Using verbosity level %d from environment variable %s", envVerbosityInt, environment.VerbosityLevelVarName)
klog.Infof("Using verbosity level %d from environment variable %s", envVerbosityInt, environment.VerbosityLevelVarName)
return envVerbosityInt
}

Expand Down
8 changes: 5 additions & 3 deletions functional_tests/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
testclient "k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"

"github.com/Azure/application-gateway-kubernetes-ingress/pkg/annotations"
. "github.com/Azure/application-gateway-kubernetes-ingress/pkg/appgw"
Expand All @@ -39,6 +40,10 @@ import (
)

func TestFunctional(t *testing.T) {
klog.InitFlags(nil)
_ = flag.Set("v", "5")
_ = flag.Lookup("logtostderr").Value.Set("true")

RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Appgw Suite")
}
Expand Down Expand Up @@ -474,9 +479,6 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
podC := tests.NewPodFixture(serviceNameC, tests.OtherNamespace, backendName, int32(backendPort))
podHttps := tests.NewPodHTTPSFixture(serviceNameHttps, tests.HTTPSBackendNamespace, httpsBackendName, int32(httpsServicePort))

_ = flag.Lookup("logtostderr").Value.Set("true")
_ = flag.Set("v", "3")

appGwIdentifier := Identifier{
SubscriptionID: tests.Subscription,
ResourceGroup: tests.ResourceGroup,
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ require (
k8s.io/api v0.0.0-20200326015715-b5bd82427fa8
k8s.io/apimachinery v0.0.0-20200326015016-e92250ad09d8
k8s.io/client-go v0.16.7
k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.4.0
)

replace (
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-logr/logr v0.2.0 h1:QvGt2nLcHH0WK9orKa+ppBPAxREcH364nPUedEpK0TY=
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1 h1:wSt/4CYxs70xbATrGXhokKF1i0tZjENLOo1ioIO13zk=
github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0=
github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9 h1:tF+augKRWlWx0J0B7ZyyKSiTyV6E1zZe+7b3qQlcEf8=
Expand Down Expand Up @@ -292,6 +294,8 @@ k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUc
k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ=
k8s.io/klog/v2 v2.4.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
k8s.io/kube-openapi v0.0.0-20200121204235-bf4fb3bd569c h1:/KUFqjjqAcY4Us6luF5RDNZ16KJtb49HfR3ZHB9qYXM=
k8s.io/kube-openapi v0.0.0-20200121204235-bf4fb3bd569c/go.mod h1:GRQhZsXIAJ1xR0C9bd8UpWHZ5plfAS9fzPjJuQ6JL3E=
k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89 h1:d4vVOjXm687F1iLSP2q3lyPPuyvTUt3aVoBpi2DqRsU=
Expand Down
6 changes: 6 additions & 0 deletions pkg/appgw/appgw_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
package appgw

import (
"flag"
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/klog/v2"
)

func TestAppgw(t *testing.T) {
klog.InitFlags(nil)
_ = flag.Set("v", "5")
_ = flag.Lookup("logtostderr").Value.Set("true")

RegisterFailHandler(Fail)
RunSpecs(t, "Appgw Suite")
}
4 changes: 0 additions & 4 deletions pkg/appgw/appgw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package appgw

import (
"context"
"flag"
"fmt"
"io/ioutil"
"time"
Expand Down Expand Up @@ -193,9 +192,6 @@ var _ = Describe("Tests `appgw.ConfigBuilder`", func() {

pod := tests.NewPodFixture(serviceName, ingressNS, backendName, int32(backendPort))

_ = flag.Lookup("logtostderr").Value.Set("true")
_ = flag.Set("v", "3")

// Method to test all the ingress that have been added to the K8s context.
testIngress := func() []*v1beta1.Ingress {
// Get all the ingresses
Expand Down
14 changes: 7 additions & 7 deletions pkg/appgw/backendaddresspools.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

n "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/Azure/go-autorest/autorest/to"
"github.com/golang/glog"
"k8s.io/klog/v2"
v1 "k8s.io/api/core/v1"

"github.com/Azure/application-gateway-kubernetes-ingress/pkg/brownfield"
Expand All @@ -34,18 +34,18 @@ func (c appGwConfigBuilder) getPools(cbCtx *ConfigBuilderContext) []n.Applicatio
}

defaultPool := defaultBackendAddressPool(c.appGwIdentifier)
glog.V(5).Infof("Created default backend pool %s", *defaultPool.Name)
klog.V(5).Infof("Created default backend pool %s", *defaultPool.Name)
managedPoolsByName := map[string]*n.ApplicationGatewayBackendAddressPool{
*defaultPool.Name: &defaultPool,
}
_, _, serviceBackendPairMap, err := c.getBackendsAndSettingsMap(cbCtx)
if err != nil {
glog.Error("Error fetching Backends and Settings: ", err)
klog.Error("Error fetching Backends and Settings: ", err)
}
for backendID, serviceBackendPair := range serviceBackendPairMap {
if pool := c.getBackendAddressPool(backendID, serviceBackendPair, managedPoolsByName); pool != nil {
managedPoolsByName[*pool.Name] = pool
glog.V(5).Infof("Created backend pool %s for service %s", *pool.Name, backendID.serviceKey())
klog.V(5).Infof("Created backend pool %s for service %s", *pool.Name, backendID.serviceKey())
}
}

Expand All @@ -54,7 +54,7 @@ func (c appGwConfigBuilder) getPools(cbCtx *ConfigBuilderContext) []n.Applicatio
for destinationID, serviceBackendPair := range istioServiceBackendPairMap {
if pool := c.getIstioBackendAddressPool(destinationID, serviceBackendPair, managedPoolsByName); pool != nil {
managedPoolsByName[*pool.Name] = pool
glog.V(5).Infof("Created backend pool %s for service %s", *pool.Name, destinationID.serviceKey())
klog.V(5).Infof("Created backend pool %s for service %s", *pool.Name, destinationID.serviceKey())
}
}
}
Expand Down Expand Up @@ -100,7 +100,7 @@ func (c *appGwConfigBuilder) newBackendPoolMap(cbCtx *ConfigBuilderContext) map[
func (c *appGwConfigBuilder) getBackendAddressPool(backendID backendIdentifier, serviceBackendPair serviceBackendPortPair, addressPools map[string]*n.ApplicationGatewayBackendAddressPool) *n.ApplicationGatewayBackendAddressPool {
endpoints, err := c.k8sContext.GetEndpointsByService(backendID.serviceKey())
if err != nil {
glog.Errorf(err.Error())
klog.Errorf(err.Error())
c.recorder.Event(backendID.Ingress, v1.EventTypeWarning, events.ReasonEndpointsEmpty, err.Error())
return nil
}
Expand All @@ -116,7 +116,7 @@ func (c *appGwConfigBuilder) getBackendAddressPool(backendID backendIdentifier,
return c.newPool(poolName, subset)
}
logLine := fmt.Sprintf("Backend target port %d does not have matching endpoint port", serviceBackendPair.BackendPort)
glog.Error(logLine)
klog.Error(logLine)
c.recorder.Event(backendID.Ingress, v1.EventTypeWarning, events.ReasonBackendPortTargetMatch, logLine)
}
return nil
Expand Down