Skip to content

Commit

Permalink
Rollback target_group_synthesizer.go change
Browse files Browse the repository at this point in the history
  • Loading branch information
Zijun Wang committed Apr 24, 2023
1 parent e1eeb0b commit 51849b9
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 155 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ export KUBEBUILDER_ASSETS ?= ${HOME}/.kubebuilder/bin
export CLUSTER_NAME ?= $(shell kubectl config view --minify -o jsonpath='{.clusters[].name}' | rev | cut -d"/" -f1 | rev | cut -d"." -f1)
export CLUSTER_VPC_ID ?= $(shell aws eks describe-cluster --name $(CLUSTER_NAME) | jq -r ".cluster.resourcesVpcConfig.vpcId")
export AWS_ACCOUNT_ID ?= $(shell aws sts get-caller-identity --query Account --output text)
export GATEWAY_API_CONTROLLER_LOGLEVEL=dubug
export REGION=us-west-2
export GATEWAY_API_CONTROLLER_LOGLEVEL ?= dubug
export REGION ?= us-west-2

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
VERSION ?= $(shell git tag --sort=committerdate | tail -1)
Expand Down
4 changes: 2 additions & 2 deletions pkg/deploy/lattice/target_group_synthesizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (t *targetGroupSynthesizer) SynthesizeTriggeredTargetGroup(ctx context.Cont
for _, resTargetGroup := range resTargetGroups {

// find out VPC for service import
if resTargetGroup.Spec.Config.IsServiceImport || resTargetGroup.Spec.Config.IsServiceExport {
if resTargetGroup.Spec.Config.IsServiceImport {
/* right now, TG are unique across VPC, we do NOT need to get VPC
if resTargetGroup.Spec.Config.EKSClusterName != "" {
eksSess := t.cloud.EKS()
Expand Down Expand Up @@ -108,7 +108,7 @@ func (t *targetGroupSynthesizer) SynthesizeTriggeredTargetGroup(ctx context.Cont
}

t.latticeDataStore.AddTargetGroup(resTargetGroup.Spec.Name,
resTargetGroup.Spec.Config.VpcID, tgStatus.TargetGroupARN, tgStatus.TargetGroupID, true)
resTargetGroup.Spec.Config.VpcID, tgStatus.TargetGroupARN, tgStatus.TargetGroupID, resTargetGroup.Spec.Config.IsServiceImport)

glog.V(6).Infof("targetGroup Synthesized successfully for %s: %v\n", resTargetGroup.Spec.Name, tgStatus)

Expand Down
17 changes: 11 additions & 6 deletions pkg/deploy/lattice/target_group_synthesizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func Test_SynthesizeTriggeredServiceExport(t *testing.T) {
},
},
tgManagerError: true,
wantErrIsNil: true,
wantErrIsNil: false,
},
}

Expand Down Expand Up @@ -129,12 +129,17 @@ func Test_SynthesizeTriggeredServiceExport(t *testing.T) {
TargetGroupID: "4567",
}

if !tg.Spec.IsDeleted {
if tg.Spec.IsDeleted {
if tt.tgManagerError {
mockTGManager.EXPECT().Get(ctx, tg).Return(tgStatus, errors.New("ERROR"))

mockTGManager.EXPECT().Delete(ctx, tg).Return(errors.New("ERROR"))
} else {
mockTGManager.EXPECT().Delete(ctx, tg).Return(nil)
}
} else {
if tt.tgManagerError {
mockTGManager.EXPECT().Create(ctx, tg).Return(tgStatus, errors.New("ERROR"))
} else {
mockTGManager.EXPECT().Get(ctx, tg).Return(tgStatus, nil)
mockTGManager.EXPECT().Create(ctx, tg).Return(tgStatus, nil)
}
}

Expand All @@ -147,7 +152,7 @@ func Test_SynthesizeTriggeredServiceExport(t *testing.T) {

assert.Nil(t, err)
tgName := latticestore.TargetGroupName(tt.svcExport.Name, tt.svcExport.Namespace)
dsTG, err := ds.GetTargetGroup(tgName, true)
dsTG, err := ds.GetTargetGroup(tgName, false)

if tg.Spec.IsDeleted {
assert.NotNil(t, err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/latticestore/latticestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ func (ds *LatticeDataStore) AddTargetGroup(name string, vpc string, arn string,
ds.lock.Lock()
defer ds.lock.Unlock()

glog.V(6).Infof("AddTargetGroup, name[%s] isServiceImport[%v] vpc[%s] arn[%s] tgID[%s] ds [%v]\n",
name, isServiceImport, vpc, arn, tgID, ds)
glog.V(6).Infof("AddTargetGroup, name[%s] isServiceImport[%v] vpc[%s] arn[%s] ds [%v]\n",
name, isServiceImport, vpc, arn, ds)

targetGroupKey := TargetGroupKey{
Name: name,
Expand Down
19 changes: 11 additions & 8 deletions scripts/load_env_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,35 @@ echo "Setting environment variables"
# Set KUBEBUILDER_ASSETS if not set
if [ -z "$KUBEBUILDER_ASSETS" ]; then
KUBEBUILDER_ASSETS=${HOME}/.kubebuilder/bin
echo "KUBEBUILDER_ASSETS=$KUBEBUILDER_ASSETS" >> envFile
fi
echo "KUBEBUILDER_ASSETS=$KUBEBUILDER_ASSETS" >> envFile


# Set CLUSTER_NAME if not set
if [ -z "$CLUSTER_NAME" ]; then
CLUSTER_NAME=$(kubectl config view --minify -o jsonpath='{.clusters[].name}' | rev | cut -d"/" -f1 | rev | cut -d"." -f1)
echo "CLUSTER_NAME=$CLUSTER_NAME" >> envFile

fi
echo "CLUSTER_NAME=$CLUSTER_NAME" >> envFile


# Set CLUSTER_VPC_ID if not set
if [ -z "$CLUSTER_VPC_ID" ]; then
CLUSTER_VPC_ID=$(aws eks describe-cluster --name ${CLUSTER_NAME} | jq -r ".cluster.resourcesVpcConfig.vpcId")
echo "CLUSTER_VPC_ID=$CLUSTER_VPC_ID" >> envFile

fi
echo "CLUSTER_VPC_ID=$CLUSTER_VPC_ID" >> envFile

# Set AWS_ACCOUNT_ID if not set
if [ -z "$AWS_ACCOUNT_ID" ]; then
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
echo "AWS_ACCOUNT_ID=$AWS_ACCOUNT_ID" >> envFile
fi
echo "AWS_ACCOUNT_ID=$AWS_ACCOUNT_ID" >> envFile

if [ -z "$REGION" ]; then
REGION=us-west-2
fi
echo "REGION=$REGION" >> envFile


GATEWAY_API_CONTROLLER_LOGLEVEL=debug
echo "GATEWAY_API_CONTROLLER_LOGLEVEL=$GATEWAY_API_CONTROLLER_LOGLEVEL" >> envFile

REGION=us-west-2
echo "REGION=$REGION" >> envFile
42 changes: 0 additions & 42 deletions test/pkg/test/service_export_import.go

This file was deleted.

93 changes: 0 additions & 93 deletions test/suites/integration/service_export_and_import_test.go

This file was deleted.

0 comments on commit 51849b9

Please sign in to comment.