Skip to content
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ help: ## Display this help.

.PHONY: run
run: ## Run in development mode
go run cmd/aws-application-networking-k8s/main.go --debug
DEV_MODE=1 go run cmd/aws-application-networking-k8s/main.go


.PHONY: presubmit
Expand Down
20 changes: 17 additions & 3 deletions cmd/aws-application-networking-k8s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"

"github.com/go-logr/zapr"
"go.uber.org/zap/zapcore"

"github.com/aws/aws-application-networking-k8s/pkg/aws"
"github.com/aws/aws-application-networking-k8s/pkg/utils/gwlog"
Expand Down Expand Up @@ -91,17 +92,16 @@ func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var debug bool

flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&debug, "debug", false, "enable debug mode")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.Parse()

log := gwlog.NewLogger(debug)
logLevel := logLevel()
log := gwlog.NewLogger(logLevel)
ctrl.SetLogger(zapr.NewLogger(log.Desugar()).WithName("runtime"))

setupLog := log.Named("setup")
Expand Down Expand Up @@ -220,3 +220,17 @@ func main() {
}

}

func logLevel() zapcore.Level {
level := os.Getenv("LOG_LEVEL")
switch level {
case "debug":
return zapcore.DebugLevel
case "error":
return zapcore.ErrorLevel
case "panic":
return zapcore.PanicLevel
default:
return zapcore.InfoLevel
}
}
4 changes: 2 additions & 2 deletions docs/guides/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ When running AWS Gateway API Controller outside the Kubernetes Cluster, this spe

---

#### `GATEWAY_API_CONTROLLER_LOGLEVEL`
#### `LOG_LEVEL`

Type: string

Expand Down Expand Up @@ -74,4 +74,4 @@ Default: ""

When set as "true", the controller will run in "single service network" mode that will override all gateways
to point to default service network, instead of searching for service network with the same name.
Can be used for small setups and conformance tests.
Can be used for small setups and conformance tests.
2 changes: 1 addition & 1 deletion helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ data:
clusterName: {{ .Values.clusterName | quote }}
latticeEndpoint: {{ .Values.latticeEndpoint | quote }}
defaultServiceNetwork: {{ .Values.defaultServiceNetwork | quote }}

logLevel: {{ .Values.log.level | quote }}
5 changes: 5 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ spec:
configMapKeyRef:
name: env-config
key: defaultServiceNetwork
- name: LOG_LEVEL
valueFrom:
configMapKeyRef:
name: env-config
key: logLevel

terminationGracePeriodSeconds: 10
nodeSelector: {{ toYaml .Values.deployment.nodeSelector | nindent 8 }}
Expand Down
1 change: 1 addition & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ clusterVpcId:
clusterName:
defaultServiceNetwork:
latticeEndpoint:
logLevel:
13 changes: 9 additions & 4 deletions pkg/utils/gwlog/gwlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@ package gwlog

import (
"log"
"os"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

type Logger = *zap.SugaredLogger

func NewLogger(debug bool) Logger {
func NewLogger(level zapcore.Level) Logger {
var zc zap.Config
if debug {

dev := os.Getenv("DEV_MODE")
if dev != "" {
zc = zap.NewDevelopmentConfig()
zc.Level = zap.NewAtomicLevelAt(zapcore.DebugLevel)
} else {
zc = zap.NewProductionConfig()
zc.DisableStacktrace = true
zc.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
}

zc.Level = zap.NewAtomicLevelAt(level)

z, err := zc.Build()
if err != nil {
log.Fatal("cannot initialize zapr logger", err)
}
return z.Sugar()
}

var FallbackLogger = NewLogger(true)
var FallbackLogger = NewLogger(zap.DebugLevel)
7 changes: 1 addition & 6 deletions scripts/load_env_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ if [ -z "$KUBEBUILDER_ASSETS" ]; then
fi
echo "KUBEBUILDER_ASSETS=$KUBEBUILDER_ASSETS" >> envFile


# Set CLUSTER_NAME if not set
if [ -z "$CLUSTER_NAME" ]; then
CLUSTER_NAME=$(kubectl config view --minify -o jsonpath='{.clusters[].name}' | rev | cut -d"/" -f1 | rev | cut -d"." -f1)
fi
echo "CLUSTER_NAME=$CLUSTER_NAME" >> envFile


# Set CLUSTER_VPC_ID if not set
if [ -z "$CLUSTER_VPC_ID" ]; then
CLUSTER_VPC_ID=$(aws eks describe-cluster --name ${CLUSTER_NAME} | jq -r ".cluster.resourcesVpcConfig.vpcId")
Expand All @@ -40,7 +38,4 @@ if [ -z "$REGION" ]; then
fi
echo "REGION=$REGION" >> envFile


GATEWAY_API_CONTROLLER_LOGLEVEL=debug
echo "GATEWAY_API_CONTROLLER_LOGLEVEL=$GATEWAY_API_CONTROLLER_LOGLEVEL" >> envFile

echo "LOG_LEVEL=debug" >> envFile
3 changes: 2 additions & 1 deletion test/suites/integration/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/aws/aws-sdk-go/service/vpclattice"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/zap"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -63,7 +64,7 @@ var _ = SynchronizedBeforeSuite(func() {

func TestIntegration(t *testing.T) {
ctx = test.NewContext(t)
logger := gwlog.NewLogger(true)
logger := gwlog.NewLogger(zap.DebugLevel)
testFramework = test.NewFramework(ctx, logger, k8snamespace)
RegisterFailHandler(Fail)
RunSpecs(t, "Integration")
Expand Down