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 controllers/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func RegisterGatewayController(
evtRec := mgr.GetEventRecorderFor("gateway")

modelBuilder := gateway.NewServiceNetworkModelBuilder(mgrClient)
stackDeployer := deploy.NewServiceNetworkStackDeployer(cloud, mgrClient)
stackDeployer := deploy.NewServiceNetworkStackDeployer(log, cloud, mgrClient)
stackMarshaller := deploy.NewDefaultStackMarshaller()

r := &GatewayReconciler{
Expand Down
6 changes: 4 additions & 2 deletions pkg/aws/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package aws

import (
"fmt"
"github.com/aws/aws-application-networking-k8s/pkg/aws/services"
"github.com/aws/aws-application-networking-k8s/pkg/utils/gwlog"

"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/vpclattice"

"github.com/aws/aws-application-networking-k8s/pkg/aws/services"
"github.com/aws/aws-application-networking-k8s/pkg/utils/gwlog"
)

const (
Expand Down
64 changes: 64 additions & 0 deletions pkg/aws/gomock_reflect_3295326204/prog.go
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure what generated these files, are we meant to add them to .gitignore?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems code generation was interrupted and left temp files, you need to remove them

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package main

import (
"encoding/gob"
"flag"
"fmt"
"os"
"path"
"reflect"

"github.com/golang/mock/mockgen/model"

pkg_ "github.com/aws/aws-application-networking-k8s/pkg/aws"
)

var output = flag.String("output", "", "The output file name, or empty to use stdout.")

func main() {
flag.Parse()

its := []struct {
sym string
typ reflect.Type
}{

{"Cloud", reflect.TypeOf((*pkg_.Cloud)(nil)).Elem()},
}
pkg := &model.Package{
// NOTE: This behaves contrary to documented behaviour if the
// package name is not the final component of the import path.
// The reflect package doesn't expose the package name, though.
Name: path.Base("github.com/aws/aws-application-networking-k8s/pkg/aws"),
}

for _, it := range its {
intf, err := model.InterfaceFromInterfaceType(it.typ)
if err != nil {
fmt.Fprintf(os.Stderr, "Reflection: %v\n", err)
os.Exit(1)
}
intf.Name = it.sym
pkg.Interfaces = append(pkg.Interfaces, intf)
}

outfile := os.Stdout
if len(*output) != 0 {
var err error
outfile, err = os.Create(*output)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to open output file %q", *output)
}
defer func() {
if err := outfile.Close(); err != nil {
fmt.Fprintf(os.Stderr, "failed to close output file %q", *output)
os.Exit(1)
}
}()
}

if err := gob.NewEncoder(outfile).Encode(pkg); err != nil {
fmt.Fprintf(os.Stderr, "gob encode: %v\n", err)
os.Exit(1)
}
}
64 changes: 64 additions & 0 deletions pkg/aws/gomock_reflect_3994833575/prog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package main

import (
"encoding/gob"
"flag"
"fmt"
"os"
"path"
"reflect"

"github.com/golang/mock/mockgen/model"

pkg_ "github.com/aws/aws-application-networking-k8s/pkg/aws"
)

var output = flag.String("output", "", "The output file name, or empty to use stdout.")

func main() {
flag.Parse()

its := []struct {
sym string
typ reflect.Type
}{

{"Cloud", reflect.TypeOf((*pkg_.Cloud)(nil)).Elem()},
}
pkg := &model.Package{
// NOTE: This behaves contrary to documented behaviour if the
// package name is not the final component of the import path.
// The reflect package doesn't expose the package name, though.
Name: path.Base("github.com/aws/aws-application-networking-k8s/pkg/aws"),
}

for _, it := range its {
intf, err := model.InterfaceFromInterfaceType(it.typ)
if err != nil {
fmt.Fprintf(os.Stderr, "Reflection: %v\n", err)
os.Exit(1)
}
intf.Name = it.sym
pkg.Interfaces = append(pkg.Interfaces, intf)
}

outfile := os.Stdout
if len(*output) != 0 {
var err error
outfile, err = os.Create(*output)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to open output file %q", *output)
}
defer func() {
if err := outfile.Close(); err != nil {
fmt.Fprintf(os.Stderr, "failed to close output file %q", *output)
os.Exit(1)
}
}()
}

if err := gob.NewEncoder(outfile).Encode(pkg); err != nil {
fmt.Fprintf(os.Stderr, "gob encode: %v\n", err)
os.Exit(1)
}
}
26 changes: 13 additions & 13 deletions pkg/deploy/externaldns/dnsendpoint_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,31 @@ import (
"context"
"reflect"

"github.com/aws/aws-application-networking-k8s/pkg/model/core"
latticemodel "github.com/aws/aws-application-networking-k8s/pkg/model/lattice"
"github.com/golang/glog"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/external-dns/endpoint"

"github.com/aws/aws-application-networking-k8s/pkg/model/core"
latticemodel "github.com/aws/aws-application-networking-k8s/pkg/model/lattice"
"github.com/aws/aws-application-networking-k8s/pkg/utils/gwlog"
)

type DnsEndpointManager interface {
Create(ctx context.Context, service *latticemodel.Service) error
}

type defaultDnsEndpointManager struct {
log gwlog.Logger
k8sClient client.Client
}

func NewDnsEndpointManager(k8sClient client.Client) *defaultDnsEndpointManager {
func NewDnsEndpointManager(log gwlog.Logger, k8sClient client.Client) *defaultDnsEndpointManager {
return &defaultDnsEndpointManager{
log: log,
k8sClient: k8sClient,
}
}
Expand All @@ -36,11 +39,11 @@ func (s *defaultDnsEndpointManager) Create(ctx context.Context, service *lattice
Name: service.Spec.Name + "-dns",
}
if service.Spec.CustomerDomainName == "" {
glog.V(2).Infof("Skipping creation of %s: detected no custom domain", namespacedName.String())
s.log.Debugf("Skipping creation of %s: detected no custom domain", namespacedName.String())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%s will use Stringer interface and call String(), no need to explicitly call String()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will include this in part 3!

return nil
}
if service.Status == nil || service.Status.Dns == "" {
glog.V(2).Infof("Skipping creation of %s: DNS target not ready in svc status", namespacedName.String())
s.log.Debugf("Skipping creation of %s: DNS target not ready in svc status", namespacedName.String())
return nil
}

Expand All @@ -58,14 +61,14 @@ func (s *defaultDnsEndpointManager) Create(ctx context.Context, service *lattice
route, err = core.GetHTTPRoute(ctx, s.k8sClient, routeNamespacedName)
}
if err != nil {
glog.V(2).Infof("Skipping creation of %s: Could not find corresponding route", namespacedName.String())
s.log.Debugf("Skipping creation of %s: Could not find corresponding route", namespacedName.String())
return nil
}

ep := &endpoint.DNSEndpoint{}
if err := s.k8sClient.Get(ctx, namespacedName, ep); err != nil {
if apierrors.IsNotFound(err) {
glog.V(2).Infof("Attempting creation of DNSEndpoint for %s - %s -> %s",
s.log.Debugf("Attempting creation of DNSEndpoint for %s - %s -> %s",
namespacedName.String(), service.Spec.CustomerDomainName, service.Status.Dns)
ep = &endpoint.DNSEndpoint{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -87,18 +90,16 @@ func (s *defaultDnsEndpointManager) Create(ctx context.Context, service *lattice
}
controllerutil.SetControllerReference(route.K8sObject(), ep, s.k8sClient.Scheme())
if err = s.k8sClient.Create(ctx, ep); err != nil {
glog.V(2).Infof("Failed creating DNSEndpoint: %s", err.Error())
return err
}
} else if meta.IsNoMatchError(err) {
glog.V(2).Infof("DNSEndpoint CRD not supported, skipping")
s.log.Debugf("DNSEndpoint CRD not supported, skipping")
return nil
} else {
glog.V(2).Infof("Failed lookup of DNSEndpoint: %s", err.Error())
return err
}
} else {
glog.V(2).Infof("Attempting update of DNSEndpoint for %s - %s -> %s",
s.log.Debugf("Attempting update of DNSEndpoint for %s - %s -> %s",
namespacedName.String(), service.Spec.CustomerDomainName, service.Status.Dns)
old := ep.DeepCopy()
ep.Spec.Endpoints = []*endpoint.Endpoint{
Expand All @@ -113,7 +114,6 @@ func (s *defaultDnsEndpointManager) Create(ctx context.Context, service *lattice
}
if !reflect.DeepEqual(ep.Spec.Endpoints, old.Spec.Endpoints) {
if err = s.k8sClient.Patch(ctx, ep, client.MergeFrom(old)); err != nil {
glog.V(2).Infof("Failed updating DNSEndpoint: %s", err.Error())
return err
}
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/deploy/externaldns/dnsendpoint_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

mock_client "github.com/aws/aws-application-networking-k8s/mocks/controller-runtime/client"
latticemodel "github.com/aws/aws-application-networking-k8s/pkg/model/lattice"
"github.com/aws/aws-application-networking-k8s/pkg/utils/gwlog"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -230,7 +232,7 @@ func TestCreateDnsEndpoint(t *testing.T) {
for _, tt := range tests {
fmt.Printf("Testing >>>>> %v\n", tt.name)
client := mock_client.NewMockClient(c)
mgr := NewDnsEndpointManager(client)
mgr := NewDnsEndpointManager(gwlog.FallbackLogger, client)

client.EXPECT().Scheme().Return(runtime.NewScheme()).AnyTimes()

Expand Down
5 changes: 2 additions & 3 deletions pkg/deploy/lattice/listener_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package lattice

import (
"context"
"errors"
"fmt"

"github.com/aws/aws-application-networking-k8s/pkg/aws/services"
Expand Down Expand Up @@ -110,7 +109,7 @@ func (d *defaultListenerManager) Create(

resp, err := d.cloud.Lattice().CreateListener(&listenerInput)
if err != nil {
d.log.Errorf("Error during creation of Listener %s-%s", listenerSpec.Name, listenerSpec.Namespace)
return latticemodel.ListenerStatus{}, err
}

return latticemodel.ListenerStatus{
Expand Down Expand Up @@ -183,7 +182,7 @@ func (d *defaultListenerManager) findListenerByNamePort(
}
}

return nil, errors.New("listener does not exist")
return nil, fmt.Errorf("listener for service %s and port %d does not exist", serviceId, port)
}

func (d *defaultListenerManager) Delete(ctx context.Context, listenerId string, serviceId string) error {
Expand Down
4 changes: 3 additions & 1 deletion pkg/deploy/lattice/listener_synthesizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ func (l *listenerSynthesizer) getSDKListeners(ctx context.Context) ([]*latticemo
var resService []*latticemodel.Service

err := l.stack.ListResources(&resService)
l.log.Debugf("Ignoring error when listing services %s", err)
if err != nil {
l.log.Debugf("Ignoring error when listing services %s", err)
}

for _, service := range resService {
latticeService, err := l.listenerMgr.Cloud().Lattice().FindService(ctx, service)
Expand Down
Loading