Skip to content

Commit 670abe5

Browse files
authored
chore: VpcPeering config (#830)
1 parent 9e286a8 commit 670abe5

File tree

10 files changed

+62
-10
lines changed

10 files changed

+62
-10
lines changed

cmd/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
awsconfig "github.com/kyma-project/cloud-manager/pkg/kcp/provider/aws/config"
3535
azureconfig "github.com/kyma-project/cloud-manager/pkg/kcp/provider/azure/config"
3636
"github.com/kyma-project/cloud-manager/pkg/kcp/scope"
37+
vpcpeeringconfig "github.com/kyma-project/cloud-manager/pkg/kcp/vpcpeering/config"
3738
"github.com/kyma-project/cloud-manager/pkg/quota"
3839

3940
"github.com/kyma-project/cloud-manager/pkg/common/abstractions"
@@ -380,6 +381,7 @@ func loadConfig() config.Config {
380381
skrruntimeconfig.InitConfig(cfg)
381382
scope.InitConfig(cfg)
382383
gcpclient.InitConfig(cfg)
384+
vpcpeeringconfig.InitConfig(cfg)
383385

384386
cfg.Read()
385387

config/config/vpcpeering.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
networkTag: e2e

pkg/kcp/provider/aws/vpcpeering/checkNetworkTag.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
66
"github.com/kyma-project/cloud-manager/pkg/composed"
77
awsutil "github.com/kyma-project/cloud-manager/pkg/kcp/provider/aws/util"
8+
peeringconfig "github.com/kyma-project/cloud-manager/pkg/kcp/vpcpeering/config"
89
"github.com/kyma-project/cloud-manager/pkg/util"
910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011
)
@@ -26,7 +27,10 @@ func checkNetworkTag(ctx context.Context, st composed.State) (error, context.Con
2627

2728
// If VpcNetwork is found but tags don't match user can recover by adding tag to remote VPC network so, we are
2829
// adding stop with requeue delay of one minute.
29-
hasShootTag := awsutil.HasEc2Tag(state.remoteVpc.Tags, state.Scope().Spec.ShootName)
30+
hasShootTag := awsutil.HasEc2Tag(state.remoteVpc.Tags, peeringconfig.VpcPeeringConfig.NetworkTag)
31+
if !hasShootTag {
32+
hasShootTag = awsutil.HasEc2Tag(state.remoteVpc.Tags, state.Scope().Spec.ShootName)
33+
}
3034

3135
if !hasShootTag {
3236

pkg/kcp/provider/aws/vpcpeering/kcpNetworkLocalLoad.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func kcpNetworkLocalLoad(ctx context.Context, st composed.State) (error, context
6868
ctx = composed.LoggerIntoCtx(ctx, logger)
6969
state.localNetwork = net
7070

71-
logger.Info("KCP VpcPeeing local network loaded")
71+
logger.Info("KCP VpcPeering local network loaded")
7272

7373
return nil, ctx
7474
}

pkg/kcp/provider/aws/vpcpeering/kcpNetworkRemoteLoad.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func kcpNetworkRemoteLoad(ctx context.Context, st composed.State) (error, contex
6969
ctx = composed.LoggerIntoCtx(ctx, logger)
7070
state.remoteNetwork = net
7171

72-
logger.Info("KCP VpcPeeing remote network loaded")
72+
logger.Info("KCP VpcPeering remote network loaded")
7373

7474
return nil, ctx
7575
}

pkg/kcp/provider/azure/vpcpeering/kcpNetworkLocalLoad.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func kcpNetworkLocalLoad(ctx context.Context, st composed.State) (error, context
7373
ctx = composed.LoggerIntoCtx(ctx, logger)
7474
state.localNetwork = net
7575

76-
logger.Info("KCP VpcPeeing local network loaded")
76+
logger.Info("KCP VpcPeering local network loaded")
7777

7878
return nil, ctx
7979
}

pkg/kcp/provider/azure/vpcpeering/kcpNetworkRemoteLoad.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func kcpNetworkRemoteLoad(ctx context.Context, st composed.State) (error, contex
7272
ctx = composed.LoggerIntoCtx(ctx, logger)
7373
state.remoteNetwork = net
7474

75-
logger.Info("KCP VpcPeeing remote network loaded")
75+
logger.Info("KCP VpcPeering remote network loaded")
7676

7777
return nil, ctx
7878
}

pkg/kcp/provider/azure/vpcpeering/waitNetworkTag.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
66
"github.com/kyma-project/cloud-manager/pkg/composed"
7+
peeringconfig "github.com/kyma-project/cloud-manager/pkg/kcp/vpcpeering/config"
78
"github.com/kyma-project/cloud-manager/pkg/util"
89
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
910
)
@@ -19,7 +20,11 @@ func waitNetworkTag(ctx context.Context, st composed.State) (error, context.Cont
1920

2021
// If VpcNetwork is found but tags don't match user can recover by adding tag to remote VPC network so, we are
2122
// adding stop with requeue delay of one minute.
22-
_, hasShootTag := state.remoteVpc.Tags[state.Scope().Spec.ShootName]
23+
24+
_, hasShootTag := state.remoteVpc.Tags[peeringconfig.VpcPeeringConfig.NetworkTag]
25+
if !hasShootTag {
26+
_, hasShootTag = state.remoteVpc.Tags[state.Scope().Spec.ShootName]
27+
}
2328

2429
if !hasShootTag {
2530

pkg/kcp/provider/gcp/vpcpeering/createKymaVpcPeering.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
2020
"github.com/kyma-project/cloud-manager/pkg/composed"
21+
peeringconfig "github.com/kyma-project/cloud-manager/pkg/kcp/vpcpeering/config"
2122
"github.com/kyma-project/cloud-manager/pkg/util"
2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
)
@@ -31,10 +32,25 @@ func createKymaVpcPeering(ctx context.Context, st composed.State) (error, contex
3132
}
3233

3334
//First we need to check if the remote VPC is tagged with the shoot name.
34-
isVpcTagged, err := state.client.CheckRemoteNetworkTags(ctx, state.remoteNetwork.Spec.Network.Reference.Gcp.NetworkName, state.remoteNetwork.Spec.Network.Reference.Gcp.GcpProject, state.Scope().Spec.ShootName)
35-
if err != nil {
36-
logger.Error(err, "[KCP GCP VPCPeering createKymaVpcPeering] Error creating GCP Kyma VPC Peering while checking remote network tags")
37-
return err, ctx
35+
var isVpcTagged bool
36+
var err error
37+
38+
if peeringconfig.VpcPeeringConfig.NetworkTag != "" {
39+
isVpcTagged, err = state.client.CheckRemoteNetworkTags(ctx, state.remoteNetwork.Spec.Network.Reference.Gcp.NetworkName, state.remoteNetwork.Spec.Network.Reference.Gcp.GcpProject, peeringconfig.VpcPeeringConfig.NetworkTag)
40+
41+
if err != nil {
42+
logger.Error(err, "[KCP GCP VPCPeering createKymaVpcPeering] Error creating GCP Kyma VPC Peering while checking any remote network tags")
43+
return err, ctx
44+
}
45+
}
46+
47+
if !isVpcTagged {
48+
isVpcTagged, err = state.client.CheckRemoteNetworkTags(ctx, state.remoteNetwork.Spec.Network.Reference.Gcp.NetworkName, state.remoteNetwork.Spec.Network.Reference.Gcp.GcpProject, state.Scope().Spec.ShootName)
49+
50+
if err != nil {
51+
logger.Error(err, "[KCP GCP VPCPeering createKymaVpcPeering] Error creating GCP Kyma VPC Peering while checking remote network tags")
52+
return err, ctx
53+
}
3854
}
3955

4056
if !isVpcTagged {

pkg/kcp/vpcpeering/config/config.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package config
2+
3+
import (
4+
"github.com/kyma-project/cloud-manager/pkg/config"
5+
)
6+
7+
type VpcPeeringConfigStruct struct {
8+
NetworkTag string `json:"networkTag,omitempty" yaml:"networkTag,omitempty"`
9+
}
10+
11+
var VpcPeeringConfig = &VpcPeeringConfigStruct{}
12+
13+
func InitConfig(cfg config.Config) {
14+
cfg.Path(
15+
"vpcpeering.config",
16+
config.Bind(VpcPeeringConfig),
17+
config.SourceFile("vpcpeering.yaml"),
18+
config.Path(
19+
"networkTag",
20+
config.SourceEnv("PEERING_NETWORK_TAG"),
21+
config.SourceFile("PEERING_NETWORK_TAG"),
22+
),
23+
)
24+
}

0 commit comments

Comments
 (0)