Skip to content

Commit

Permalink
Add a capability that allow user to define a default servicenetwork (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
liwenwu-amazon authored Apr 20, 2023
1 parent 8a9cd8c commit e6ece06
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/config/controller_config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"errors"
"os"
"strings"

Expand All @@ -11,13 +12,16 @@ import (
const (
LatticeGatewayControllerName = "application-networking.k8s.aws/gateway-api-controller"
defaultLogLevel = "Info"
NoDefaultServiceNetwork = ""
NO_DEFAULT_SERVICE_NETWORK = "NO_DEFAULT_SERVICE_NETWORK"
)

// TODO endpoint, region
var VpcID = "vpc-xxxx"
var AccountID = "yyyyyy"
var Region = "us-west-2"
var logLevel = defaultLogLevel
var DefaultServiceNetwork = NoDefaultServiceNetwork

func GetLogLevel() string {
logLevel = os.Getenv("GATEWAY_API_CONTROLLER_LOGLEVEL")
Expand All @@ -30,6 +34,14 @@ func GetLogLevel() string {
return "2"
}

func GetClusterLocalGateway() (string, error) {
if DefaultServiceNetwork == NoDefaultServiceNetwork {
return NoDefaultServiceNetwork, errors.New(NO_DEFAULT_SERVICE_NETWORK)
}

return DefaultServiceNetwork, nil
}

func ConfigInit() {
// discover VPC using environment first
VpcID = os.Getenv("CLUSTER_VPC_ID")
Expand All @@ -49,6 +61,15 @@ func ConfigInit() {
logLevel = os.Getenv("GATEWAY_API_CONTROLLER_LOGLEVEL")
glog.V(2).Infoln("Logging Level:", os.Getenv("GATEWAY_API_CONTROLLER_LOGLEVEL"))

DefaultServiceNetwork = os.Getenv("CLUSTER_LOCAL_GATEWAY")

if DefaultServiceNetwork == NoDefaultServiceNetwork {
glog.V(2).Infoln("No CLUSTER_LOCAL_GATEWAY")
} else {

glog.V(2).Infoln("CLUSTER_LOCAL_GATEWAY", DefaultServiceNetwork)
}

sess, _ := session.NewSession()
metadata := NewEC2Metadata(sess)

Expand Down
5 changes: 5 additions & 0 deletions pkg/gateway/model_build_lattice_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/aws/aws-application-networking-k8s/pkg/config"
"github.com/aws/aws-application-networking-k8s/pkg/k8s"
"github.com/aws/aws-application-networking-k8s/pkg/model/core"
latticemodel "github.com/aws/aws-application-networking-k8s/pkg/model/lattice"
Expand Down Expand Up @@ -131,6 +132,10 @@ func (t *latticeServiceModelBuildTask) buildLatticeService(ctx context.Context)
spec.ServiceNetworkNames = append(spec.ServiceNetworkNames, string(parentRef.Name))

}
defaultGateway, err := config.GetClusterLocalGateway()
if err == nil {
spec.ServiceNetworkNames = append(spec.ServiceNetworkNames, defaultGateway)
}

if len(t.httpRoute.Spec.Hostnames) > 0 {
// The 1st hostname will be used as lattice customer-domain-name
Expand Down
6 changes: 6 additions & 0 deletions pkg/gateway/model_build_servicenetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ func (t *serviceNetworkModelBuildTask) buildServiceNetwork(ctx context.Context)
}

}
_, err := config.GetClusterLocalGateway()

if err == nil {
// there is a default gateway for local cluster, all other gateways are not associate to VPC
spec.AssociateToVPC = false
}

if !t.gateway.DeletionTimestamp.IsZero() {
spec.IsDeleted = true
Expand Down

0 comments on commit e6ece06

Please sign in to comment.