Skip to content

Commit

Permalink
zap changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Murcherla committed Sep 3, 2020
1 parent 4164023 commit d98afa5
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 647 deletions.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -16,6 +16,7 @@ require (
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.5.1
go.uber.org/zap v1.10.0
k8s.io/api v0.18.2
k8s.io/apimachinery v0.18.6
k8s.io/client-go v0.18.2
Expand Down
18 changes: 18 additions & 0 deletions pkg/runtime/config.go
Expand Up @@ -17,6 +17,7 @@ import (
"errors"

flag "github.com/spf13/pflag"
"go.uber.org/zap/zapcore"
ctrlrt "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)
Expand All @@ -28,6 +29,7 @@ const (
flagEnableDevLogging = "enable-development-logging"
flagAWSAccountID = "aws-account-id"
flagAWSRegion = "aws-region"
flagLogLevel = "log-level"
)

type Config struct {
Expand All @@ -37,6 +39,7 @@ type Config struct {
EnableDevelopmentLogging bool
AccountID string
Region string
LogLevel string
}

func (cfg *Config) BindFlags() {
Expand Down Expand Up @@ -72,11 +75,26 @@ func (cfg *Config) BindFlags() {
"",
"The AWS Region in which the service controller will create its resources",
)
flag.StringVar(
&cfg.LogLevel, flagLogLevel,
"info",
"The log level. Default is info. We use logr interface which only supports info and debug level",
)
}

func (cfg *Config) SetupLogger() {
var lvl zapcore.LevelEnabler

switch cfg.LogLevel {
case "debug":
lvl = zapcore.DebugLevel
default:
lvl = zapcore.InfoLevel
}

zapOptions := zap.Options{
Development: cfg.EnableDevelopmentLogging,
Level: lvl,
}
ctrlrt.SetLogger(zap.New(zap.UseFlagOptions(&zapOptions)))
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/runtime/reconciler.go
Expand Up @@ -98,11 +98,12 @@ func (r *reconciler) reconcile(req ctrlrt.Request) error {
acctID := r.getOwnerAccountID(res)
region := r.getRegion(res)

r.log.WithValues(
log := r.log.WithValues(
"account_id", acctID,
"region", region,
"kind", r.rd.GroupKind().String(),
)
log.Info("starting reconcilation")

rm, err := r.rmf.ManagerFor(r, acctID, region)
if err != nil {
Expand Down Expand Up @@ -163,7 +164,7 @@ func (r *reconciler) sync(
return nil
}
diff := r.rd.Diff(desired, latest)
r.log.V(2).Info(
r.log.V(1).Info(
"desired resource state has changed",
"diff", diff,
"arn", latest.Identifiers().ARN(),
Expand All @@ -190,7 +191,7 @@ func (r *reconciler) sync(
if err != nil {
return err
}
r.log.V(2).Info("patched CR status")
r.log.V(1).Info("patched CR status")
return err
}

Expand Down Expand Up @@ -242,7 +243,7 @@ func (r *reconciler) setResourceManaged(
if err != nil {
return err
}
r.log.V(2).Info("reconciler marked resource as managed")
r.log.V(1).Info("reconciler marked resource as managed")
return nil
}

Expand All @@ -266,7 +267,7 @@ func (r *reconciler) setResourceUnmanaged(
if err != nil {
return err
}
r.log.V(2).Info("reconciler removed resource from management")
r.log.V(1).Info("reconciler removed resource from management")
return nil
}

Expand Down
11 changes: 8 additions & 3 deletions pkg/runtime/session.go
Expand Up @@ -13,12 +13,17 @@

package runtime

import "github.com/aws/aws-sdk-go/aws/session"
import (
ackv1alpha1 "github.com/aws/aws-controllers-k8s/apis/core/v1alpha1"

func NewSession() (*session.Session, error) {
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
)

func NewSession(region ackv1alpha1.AWSRegion) (*session.Session, error) {
// NOTE(jaypipes): session.NewSession() is needed for the STS::AssumeRole
// stuff we will need to do...
sess, err := session.NewSession()
sess, err := session.NewSession(aws.NewConfig().WithRegion(string(region)))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion services/bookstore/pkg/resource/book/manager.go
Expand Up @@ -150,7 +150,7 @@ func newResourceManager(
id ackv1alpha1.AWSAccountID,
region ackv1alpha1.AWSRegion,
) (*resourceManager, error) {
sess, err := ackrt.NewSession()
sess, err := ackrt.NewSession(region)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions services/ecr/config/controller/deployment.yaml
Expand Up @@ -27,11 +27,11 @@ spec:
- ./bin/controller
args:
- --aws-account-id
- "${AWS_ACCOUNT_ID}"
- "$(AWS_ACCOUNT_ID)"
- --aws-region
- "${AWS_REGION}"
- "$(AWS_REGION)"
- --enable-development-logging
- "${ACK_ENABLE_DEVELOPMENT_LOGGING}"
- "$(ACK_ENABLE_DEVELOPMENT_LOGGING)"
image: controller:latest
name: controller
resources:
Expand Down
2 changes: 1 addition & 1 deletion services/ecr/pkg/resource/repository/manager.go

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

2 changes: 1 addition & 1 deletion services/petstore/pkg/resource/pet/manager.go
Expand Up @@ -227,7 +227,7 @@ func newResourceManager(
id ackv1alpha1.AWSAccountID,
region ackv1alpha1.AWSRegion,
) (*resourceManager, error) {
sess, err := ackrt.NewSession()
sess, err := ackrt.NewSession(region)
if err != nil {
return nil, err
}
Expand Down
26 changes: 6 additions & 20 deletions services/s3/apis/v1alpha1/enums.go

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

6 changes: 3 additions & 3 deletions services/s3/config/controller/deployment.yaml
Expand Up @@ -27,11 +27,11 @@ spec:
- ./bin/controller
args:
- --aws-account-id
- "${AWS_ACCOUNT_ID}"
- "$(AWS_ACCOUNT_ID)"
- --aws-region
- "${AWS_REGION}"
- "$(AWS_REGION)"
- --enable-development-logging
- "${ACK_ENABLE_DEVELOPMENT_LOGGING}"
- "$(ACK_ENABLE_DEVELOPMENT_LOGGING)"
image: controller:latest
name: controller
resources:
Expand Down
2 changes: 1 addition & 1 deletion services/s3/pkg/resource/bucket/manager.go

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

2 changes: 1 addition & 1 deletion services/sns/pkg/resource/platform_application/manager.go

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

2 changes: 1 addition & 1 deletion services/sns/pkg/resource/platform_endpoint/manager.go

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

2 changes: 1 addition & 1 deletion services/sns/pkg/resource/topic/manager.go

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

6 changes: 3 additions & 3 deletions templates/config/controller/deployment.yaml.tpl
Expand Up @@ -27,11 +27,11 @@ spec:
- ./bin/controller
args:
- --aws-account-id
- "$(AWS_ACCOUNT_ID)"
- "${AWS_ACCOUNT_ID}"
- --aws-region
- "$(AWS_REGION)"
- "${AWS_REGION}"
- --enable-development-logging
- "$(ACK_ENABLE_DEVELOPMENT_LOGGING)"
- "${ACK_ENABLE_DEVELOPMENT_LOGGING}"
image: controller:latest
name: controller
resources:
Expand Down
2 changes: 1 addition & 1 deletion templates/pkg/crd_manager.go.tpl
Expand Up @@ -140,7 +140,7 @@ func newResourceManager(
id ackv1alpha1.AWSAccountID,
region ackv1alpha1.AWSRegion,
) (*resourceManager, error) {
sess, err := ackrt.NewSession()
sess, err := ackrt.NewSession(region)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit d98afa5

Please sign in to comment.