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

Removal of caching for services #394

Merged
merged 3 commits into from
Sep 14, 2023
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 cmd/aws-application-networking-k8s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func main() {
setupLog.Fatalf("gateway-class controller setup failed: %s", err)
}

err = controllers.RegisterGatewayController(ctrlLog.Named("gateway"), cloud, latticeDataStore, finalizerManager, mgr)
err = controllers.RegisterGatewayController(ctrlLog.Named("gateway"), cloud, finalizerManager, mgr)
if err != nil {
setupLog.Fatalf("gateway controller setup failed: %s", err)
}
Expand Down
9 changes: 1 addition & 8 deletions controllers/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/aws/aws-application-networking-k8s/pkg/deploy"
"github.com/aws/aws-application-networking-k8s/pkg/gateway"
"github.com/aws/aws-application-networking-k8s/pkg/k8s"
"github.com/aws/aws-application-networking-k8s/pkg/latticestore"
"github.com/aws/aws-application-networking-k8s/pkg/model/core"
latticemodel "github.com/aws/aws-application-networking-k8s/pkg/model/lattice"
lattice_runtime "github.com/aws/aws-application-networking-k8s/pkg/runtime"
Expand Down Expand Up @@ -60,14 +59,12 @@ type GatewayReconciler struct {
modelBuilder gateway.ServiceNetworkModelBuilder
stackDeployer deploy.StackDeployer
cloud aws.Cloud
datastore *latticestore.LatticeDataStore
stackMarshaller deploy.StackMarshaller
}

func RegisterGatewayController(
log gwlog.Logger,
cloud aws.Cloud,
datastore *latticestore.LatticeDataStore,
finalizerManager k8s.FinalizerManager,
mgr ctrl.Manager,
) error {
Expand All @@ -76,7 +73,7 @@ func RegisterGatewayController(
evtRec := mgr.GetEventRecorderFor("gateway")

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

r := &GatewayReconciler{
Expand All @@ -88,7 +85,6 @@ func RegisterGatewayController(
modelBuilder: modelBuilder,
stackDeployer: stackDeployer,
cloud: cloud,
datastore: datastore,
stackMarshaller: stackMarshaller,
}

Expand Down Expand Up @@ -254,9 +250,6 @@ func (r *GatewayReconciler) reconcileGatewayResources(ctx context.Context, gw *g
if err != nil {
return err
}
if snInfo == nil {
return fmt.Errorf("Service network %s for account %s not found", gw.Name, config.AccountID)
}
Comment on lines -257 to -259
Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the change on FindX logic to raise a "not found" error, these additional nil checks on the return value are no longer required.


if err = r.updateGatewayStatus(ctx, *snInfo.SvcNetwork.Arn, gw); err != nil {
return err
Expand Down
41 changes: 28 additions & 13 deletions controllers/route_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package controllers
import (
"context"
"fmt"
"github.com/aws/aws-application-networking-k8s/pkg/aws/services"
"github.com/aws/aws-application-networking-k8s/pkg/utils"

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

Expand Down Expand Up @@ -70,12 +72,21 @@ type RouteReconciler struct {
stackDeployer deploy.StackDeployer
latticeDataStore *latticestore.LatticeDataStore
stackMarshaller deploy.StackMarshaller
cloud aws.Cloud
}

const (
LatticeAssignedDomainName = "application-networking.k8s.aws/lattice-assigned-domain-name"
)

type RouteLSNProvider struct {
Route core.Route
}

func (r *RouteLSNProvider) LatticeServiceName() string {
return utils.LatticeServiceName(r.Route.Name(), r.Route.Namespace())
}

func RegisterAllRouteControllers(
log gwlog.Logger,
cloud aws.Cloud,
Expand Down Expand Up @@ -107,6 +118,7 @@ func RegisterAllRouteControllers(
modelBuilder: gateway.NewLatticeServiceBuilder(log, mgrClient, datastore, cloud),
stackDeployer: deploy.NewLatticeServiceStackDeploy(log, cloud, mgrClient, datastore),
stackMarshaller: deploy.NewDefaultStackMarshaller(),
cloud: cloud,
}

svcImportEventHandler := eventhandlers.NewServiceImportEventHandler(log, mgrClient)
Expand Down Expand Up @@ -311,9 +323,7 @@ func (r *RouteReconciler) buildAndDeployModel(
if err := r.stackDeployer.Deploy(ctx, stack); err != nil {
r.log.Infof("RouteReconciler: Failed deploy %s due to err %s", route.Name(), err)

var retryErr = errors.New(lattice.LATTICE_RETRY)

if errors.As(err, &retryErr) {
if errors.As(err, &lattice.RetryErr) {
r.eventRecorder.Event(route.K8sObject(), corev1.EventTypeNormal,
k8s.RouteEventReasonRetryReconcile, "retry reconcile...")

Expand Down Expand Up @@ -358,22 +368,27 @@ func (r *RouteReconciler) reconcileRouteResource(ctx context.Context, route core
return backendRefIPFamiliesErr
}

_, _, err := r.buildAndDeployModel(ctx, route)
if _, _, err := r.buildAndDeployModel(ctx, route); err != nil {
return err
}

//TODO add metric
r.eventRecorder.Event(route.K8sObject(), corev1.EventTypeNormal,
k8s.RouteEventReasonDeploySucceed, "Adding/Updating reconcile Done!")

if err == nil {
r.eventRecorder.Event(route.K8sObject(), corev1.EventTypeNormal,
k8s.RouteEventReasonDeploySucceed, "Adding/Updating reconcile Done!")
svc, err := r.cloud.Lattice().FindService(ctx, &RouteLSNProvider{route})
if err != nil && !services.IsNotFoundError(err) {
return err
}

serviceStatus, err1 := r.latticeDataStore.GetLatticeService(route.Name(), route.Namespace())
if svc == nil || svc.DnsEntry == nil || svc.DnsEntry.DomainName == nil {
return errors.New(lattice.LATTICE_RETRY)
}

if err1 == nil {
r.updateRouteStatus(ctx, serviceStatus.DNS, route)
}
if err := r.updateRouteStatus(ctx, *svc.DnsEntry.DomainName, route); err != nil {
return err
}

return err
return nil
}

func (r *RouteReconciler) updateRouteStatus(ctx context.Context, dns string, route core.Route) error {
Expand Down
Loading