Skip to content

multiple bug fixes for v2.0.0-rc4 #1518

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

Merged
merged 5 commits into from
Oct 19, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/guide/ingress/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ ALB supports authentication with Cognito or OIDC. See [Authenticate Users Using
namespace: testcase
name: my-k8s-secret
data:
clientId: base64 of your plain text clientId
clientID: base64 of your plain text clientId
clientSecret: base64 of your plain text clientSecret
```

Expand Down
15 changes: 8 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"context"
"github.com/go-logr/logr"
"github.com/spf13/pflag"
zapraw "go.uber.org/zap"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -58,18 +59,18 @@ func init() {
}

func main() {
setLogLevel("info")
setupLog.Info("version",
infoLogger := getLoggerWithLogLevel("info")
infoLogger.Info("version",
"GitVersion", version.GitVersion,
"GitCommit", version.GitCommit,
"BuildDate", version.BuildDate,
)
controllerCFG, err := loadControllerConfig()
if err != nil {
setupLog.Error(err, "unable to load controller config")
infoLogger.Error(err, "unable to load controller config")
os.Exit(1)
}
setLogLevel(controllerCFG.LogLevel)
ctrl.SetLogger(getLoggerWithLogLevel(controllerCFG.LogLevel))

cloud, err := aws.NewCloud(controllerCFG.AWSConfig, metrics.Registry)
if err != nil {
Expand Down Expand Up @@ -153,8 +154,8 @@ func loadControllerConfig() (config.ControllerConfig, error) {
return controllerCFG, nil
}

// setLogLevel sets the log level of controller.
func setLogLevel(logLevel string) {
// getLoggerWithLogLevel returns logger with specific log level.
func getLoggerWithLogLevel(logLevel string) logr.Logger {
var zapLevel zapraw.AtomicLevel
switch logLevel {
case "info":
Expand All @@ -168,5 +169,5 @@ func setLogLevel(logLevel string) {
logger := zap.New(zap.UseDevMode(false),
zap.Level(zapLevel),
zap.StacktraceLevel(zapraw.NewAtomicLevelAt(zapraw.FatalLevel)))
ctrl.SetLogger(runtime.NewConciseLogger(logger))
return runtime.NewConciseLogger(logger)
}
23 changes: 14 additions & 9 deletions pkg/deploy/elbv2/target_group_binding_synthesizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func NewTargetGroupBindingSynthesizer(k8sClient client.Client, trackingProvider
tgbManager: tgbManager,
logger: logger,
stack: stack,

unmatchedK8sTGBs: nil,
}
}

Expand All @@ -29,6 +31,8 @@ type targetGroupBindingSynthesizer struct {
tgbManager TargetGroupBindingManager
logger logr.Logger
stack core.Stack

unmatchedK8sTGBs []*elbv2api.TargetGroupBinding
}

func (s *targetGroupBindingSynthesizer) Synthesize(ctx context.Context) error {
Expand All @@ -43,11 +47,8 @@ func (s *targetGroupBindingSynthesizer) Synthesize(ctx context.Context) error {
if err != nil {
return err
}
for _, k8sTGB := range unmatchedK8sTGBs {
if err := s.tgbManager.Delete(ctx, k8sTGB); err != nil {
return err
}
}
s.unmatchedK8sTGBs = unmatchedK8sTGBs

for _, resTGB := range unmatchedResTGBs {
tgbStatus, err := s.tgbManager.Create(ctx, resTGB)
if err != nil {
Expand All @@ -66,7 +67,11 @@ func (s *targetGroupBindingSynthesizer) Synthesize(ctx context.Context) error {
}

func (s *targetGroupBindingSynthesizer) PostSynthesize(ctx context.Context) error {
// nothing to do here.
for _, k8sTGB := range s.unmatchedK8sTGBs {
if err := s.tgbManager.Delete(ctx, k8sTGB); err != nil {
return err
}
}
return nil
}

Expand All @@ -93,7 +98,7 @@ type resAndK8sTargetGroupBindingPair struct {
func matchResAndK8sTargetGroupBindings(resTGBs []*elbv2model.TargetGroupBindingResource, k8sTGBs []*elbv2api.TargetGroupBinding) ([]resAndK8sTargetGroupBindingPair, []*elbv2model.TargetGroupBindingResource, []*elbv2api.TargetGroupBinding, error) {
var matchedResAndK8sTGBs []resAndK8sTargetGroupBindingPair
var unmatchedResTGBs []*elbv2model.TargetGroupBindingResource
var unmatchedK8sTGs []*elbv2api.TargetGroupBinding
var unmatchedK8sTGBs []*elbv2api.TargetGroupBinding
resTGBsByARN, err := mapResTargetGroupBindingByARN(resTGBs)
if err != nil {
return nil, nil, nil, err
Expand All @@ -115,10 +120,10 @@ func matchResAndK8sTargetGroupBindings(resTGBs []*elbv2model.TargetGroupBindingR
unmatchedResTGBs = append(unmatchedResTGBs, resTGBsByARN[tgARN])
}
for _, tgARN := range k8sTGBARNs.Difference(resTGBARNs).List() {
unmatchedK8sTGs = append(unmatchedK8sTGs, k8sTGBsByARN[tgARN])
unmatchedK8sTGBs = append(unmatchedK8sTGBs, k8sTGBsByARN[tgARN])
}

return matchedResAndK8sTGBs, unmatchedResTGBs, unmatchedK8sTGs, nil
return matchedResAndK8sTGBs, unmatchedResTGBs, unmatchedK8sTGBs, nil
}

func mapResTargetGroupBindingByARN(resTGBs []*elbv2model.TargetGroupBindingResource) (map[string]*elbv2model.TargetGroupBindingResource, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/deploy/stack_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ func (d *defaultStackDeployer) Deploy(ctx context.Context, stack core.Stack) err
synthesizers := []ResourceSynthesizer{
ec2.NewSecurityGroupSynthesizer(d.cloud.EC2(), d.trackingProvider, d.ec2TaggingManager, d.ec2SGManager, d.vpcID, d.logger, stack),
elbv2.NewTargetGroupSynthesizer(d.cloud.ELBV2(), d.trackingProvider, d.elbv2TaggingManager, d.elbv2TGManager, d.logger, stack),
elbv2.NewTargetGroupBindingSynthesizer(d.k8sClient, d.trackingProvider, d.elbv2TGBManager, d.logger, stack),
elbv2.NewLoadBalancerSynthesizer(d.cloud.ELBV2(), d.trackingProvider, d.elbv2TaggingManager, d.elbv2LBManager, d.logger, stack),
elbv2.NewListenerSynthesizer(d.cloud.ELBV2(), d.elbv2LSManager, d.logger, stack),
elbv2.NewListenerRuleSynthesizer(d.cloud.ELBV2(), d.elbv2LRManager, d.logger, stack),
elbv2.NewTargetGroupBindingSynthesizer(d.k8sClient, d.trackingProvider, d.elbv2TGBManager, d.logger, stack),
}

if d.addonsConfig.WAFV2Enabled {
Expand Down
17 changes: 15 additions & 2 deletions pkg/ingress/model_build_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,21 @@ func (t *defaultModelBuildTask) buildAuthenticateOIDCAction(ctx context.Context,
return elbv2model.Action{}, err
}

clientID := strings.TrimRightFunc(string(secret.Data["clientId"]), unicode.IsSpace)
clientSecret := string(secret.Data["clientSecret"])
rawClientID, ok := secret.Data["clientID"]
// AWSALBIngressController looks for clientId, we should be backwards-compatible here.
if !ok {
rawClientID, ok = secret.Data["clientId"]
}
if !ok {
return elbv2model.Action{}, errors.Errorf("missing clientID, secret: %v", secretKey)
}
rawClientSecret, ok := secret.Data["clientSecret"]
if !ok {
return elbv2model.Action{}, errors.Errorf("missing clientSecret, secret: %v", secretKey)
}

clientID := strings.TrimRightFunc(string(rawClientID), unicode.IsSpace)
clientSecret := string(rawClientSecret)
return elbv2model.Action{
Type: elbv2model.ActionTypeAuthenticateOIDC,
AuthenticateOIDCConfig: &elbv2model.AuthenticateOIDCActionConfig{
Expand Down
Loading