Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit 45fc52a

Browse files
fiunchinhoChristian Bianchi
andauthored
Fetch IPs from CP instead of TC to allow CP into TC (#1210)
Co-authored-by: Christian Bianchi <[email protected]>
1 parent d399f2d commit 45fc52a

File tree

6 files changed

+51
-66
lines changed

6 files changed

+51
-66
lines changed

service/controller/azure_config.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,11 @@ func newAzureConfigResources(config AzureConfigConfig, certsSearcher certs.Inter
461461
var workerMigrationResource resource.Interface
462462
{
463463
c := workermigration.Config{
464-
CertsSearcher: certsSearcher,
465-
ClientFactory: clientFactory,
466-
CtrlClient: config.K8sClient.CtrlClient(),
467-
Logger: config.Logger,
464+
CertsSearcher: certsSearcher,
465+
ClientFactory: clientFactory,
466+
CPPublicIPAddressesClient: config.CPAzureClientSet.PublicIpAddressesClient,
467+
CtrlClient: config.K8sClient.CtrlClient(),
468+
Logger: config.Logger,
468469

469470
InstallationName: config.InstallationName,
470471
Location: config.Azure.Location,

service/controller/resource/workermigration/internal/azure/api.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package azure
22

33
import (
44
"context"
5-
"fmt"
65

76
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
87
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-11-01/network"
@@ -127,30 +126,3 @@ func (a *api) CreateOrUpdateNetworkSecurityGroup(ctx context.Context, resourceGr
127126

128127
return nil
129128
}
130-
131-
func (a *api) ListPublicIPs(ctx context.Context, resourceGroupName string) ([]string, error) {
132-
client, err := a.clientFactory.GetPublicIPAddressesClient(a.credentials.Namespace, a.credentials.Name)
133-
if err != nil {
134-
return nil, microerror.Mask(err)
135-
}
136-
137-
allPublicIPs, err := client.ListComplete(ctx, resourceGroupName)
138-
if err != nil {
139-
return nil, microerror.Mask(err)
140-
}
141-
142-
var ips []string
143-
for allPublicIPs.NotDone() {
144-
ip := allPublicIPs.Value()
145-
// Masters use the API LB as egress gateway, the workers use the ingress LB.
146-
if ip.Name != nil && *ip.Name == fmt.Sprintf("%s_ingress_ip", resourceGroupName) || *ip.Name == fmt.Sprintf("%s_api_ip", resourceGroupName) {
147-
ips = append(ips, *ip.IPAddress)
148-
}
149-
err := allPublicIPs.NextWithContext(ctx)
150-
if err != nil {
151-
return nil, microerror.Mask(err)
152-
}
153-
}
154-
155-
return ips, nil
156-
}

service/controller/resource/workermigration/internal/azure/spec.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,4 @@ type API interface {
2929

3030
// CreateOrUpdateNetworkSecurityGroup creates or updates existing network security group via Azure API.
3131
CreateOrUpdateNetworkSecurityGroup(ctx context.Context, resourceGroupName, networkSecurityGroupName string, securityGroup network.SecurityGroup) error
32-
33-
// List all Public IPs from a given resource group via Azure API.
34-
ListPublicIPs(ctx context.Context, resourceGroupName string) ([]string, error)
3532
}

service/controller/resource/workermigration/internal/mock_azure/api.go

Lines changed: 1 addition & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/controller/resource/workermigration/resource.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package workermigration
22

33
import (
4+
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-11-01/network"
45
providerv1alpha1 "github.com/giantswarm/apiextensions/v3/pkg/apis/provider/v1alpha1"
56
"github.com/giantswarm/certs/v3/pkg/certs"
67
"github.com/giantswarm/microerror"
@@ -17,27 +18,32 @@ const (
1718
)
1819

1920
type Config struct {
20-
CertsSearcher certs.Interface
21-
ClientFactory *azureclient.Factory
22-
CtrlClient client.Client
23-
Logger micrologger.Logger
21+
CertsSearcher certs.Interface
22+
ClientFactory *azureclient.Factory
23+
CPPublicIPAddressesClient *network.PublicIPAddressesClient
24+
CtrlClient client.Client
25+
Logger micrologger.Logger
2426

2527
InstallationName string
2628
Location string
2729
}
2830

2931
type Resource struct {
30-
clientFactory *azureclient.Factory
31-
ctrlClient client.Client
32-
logger micrologger.Logger
33-
tenantClientFactory tenantcluster.Factory
34-
wrapAzureAPI func(cf *azureclient.Factory, credentials *providerv1alpha1.CredentialSecret) azure.API
32+
clientFactory *azureclient.Factory
33+
cpPublicIPAddressesClient *network.PublicIPAddressesClient
34+
ctrlClient client.Client
35+
logger micrologger.Logger
36+
tenantClientFactory tenantcluster.Factory
37+
wrapAzureAPI func(cf *azureclient.Factory, credentials *providerv1alpha1.CredentialSecret) azure.API
3538

3639
installationName string
3740
location string
3841
}
3942

4043
func New(config Config) (*Resource, error) {
44+
if config.CPPublicIPAddressesClient == nil {
45+
return nil, microerror.Maskf(invalidConfigError, "%T.CPPublicIPAddressesClient must not be empty", config)
46+
}
4147
if config.ClientFactory == nil {
4248
return nil, microerror.Maskf(invalidConfigError, "%T.ClientFactory must not be empty", config)
4349
}
@@ -60,11 +66,12 @@ func New(config Config) (*Resource, error) {
6066
}
6167

6268
newResource := &Resource{
63-
clientFactory: config.ClientFactory,
64-
ctrlClient: config.CtrlClient,
65-
logger: config.Logger,
66-
tenantClientFactory: tenantClientFactory,
67-
wrapAzureAPI: azure.GetAPI,
69+
cpPublicIPAddressesClient: config.CPPublicIPAddressesClient,
70+
clientFactory: config.ClientFactory,
71+
ctrlClient: config.CtrlClient,
72+
logger: config.Logger,
73+
tenantClientFactory: tenantClientFactory,
74+
wrapAzureAPI: azure.GetAPI,
6875

6976
installationName: config.InstallationName,
7077
location: config.Location,

service/controller/resource/workermigration/security_groups.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package workermigration
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-11-01/network"
78
"github.com/Azure/go-autorest/autorest/to"
@@ -59,7 +60,7 @@ func (r *Resource) ensureMasterEtcdLBSourcePrefixesUpdated(ctx context.Context,
5960
var err error
6061
var publicIPs []string
6162
{
62-
publicIPs, err = azureAPI.ListPublicIPs(ctx, r.installationName)
63+
publicIPs, err = listPublicIPs(ctx, r.cpPublicIPAddressesClient, r.installationName)
6364
if err != nil {
6465
return microerror.Mask(err)
6566
}
@@ -125,3 +126,25 @@ func contains(xs []string, v string) bool {
125126

126127
return false
127128
}
129+
130+
func listPublicIPs(ctx context.Context, cpPublicIPAddressesClient *network.PublicIPAddressesClient, resourceGroupName string) ([]string, error) {
131+
allPublicIPs, err := cpPublicIPAddressesClient.ListComplete(ctx, resourceGroupName)
132+
if err != nil {
133+
return nil, microerror.Mask(err)
134+
}
135+
136+
var ips []string
137+
for allPublicIPs.NotDone() {
138+
ip := allPublicIPs.Value()
139+
// Masters use the API LB as egress gateway, the workers use the ingress LB.
140+
if ip.Name != nil && *ip.Name == fmt.Sprintf("%s_ingress_ip", resourceGroupName) || *ip.Name == fmt.Sprintf("%s_api_ip", resourceGroupName) {
141+
ips = append(ips, *ip.IPAddress)
142+
}
143+
err := allPublicIPs.NextWithContext(ctx)
144+
if err != nil {
145+
return nil, microerror.Mask(err)
146+
}
147+
}
148+
149+
return ips, nil
150+
}

0 commit comments

Comments
 (0)