Skip to content

Commit

Permalink
Revert "wip"
Browse files Browse the repository at this point in the history
This reverts commit c7807ca.
  • Loading branch information
Mattes83 committed Jul 4, 2024
1 parent 1742abd commit 716446e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 274 deletions.
62 changes: 0 additions & 62 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,68 +65,6 @@ func (a *IONOSClient) GetServer(ctx context.Context, providerID string) (*cloudp
return a.convertServerToInstanceMetadata(ctx, &server)
}

func (a *IONOSClient) AttachIPToNode(ctx context.Context, loadBalancerIP, providerID string) (bool, error) {
if a.client == nil {
return false, errors.New("client isn't initialized")
}

serverReq := a.client.NetworkInterfacesApi.DatacentersServersNicsGet(ctx, a.DatacenterId, providerID)
nics, req, err := serverReq.Depth(3).Execute()
if req != nil && req.StatusCode == 404 {
return false, err
}

if !nics.HasItems() {
return false, nil
}

primaryNic := (*nics.Items)[0]
ips := *primaryNic.Properties.Ips
ips = append(ips, loadBalancerIP)

_, _, err = a.client.NetworkInterfacesApi.DatacentersServersNicsPatch(ctx, a.DatacenterId, providerID, *primaryNic.Id).Nic(ionoscloud.NicProperties{
Ips: &ips,
}).Execute()

return err != nil, err
}

func (a *IONOSClient) GetServerByIP(ctx context.Context, loadBalancerIP string) (*string, error) {
if a.client == nil {
return nil, errors.New("client isn't initialized")
}

serverReq := a.client.ServersApi.DatacentersServersGet(ctx, a.DatacenterId)
servers, req, err := serverReq.Depth(3).Execute()
if err != nil || req != nil && req.StatusCode == 404 {
if err != nil {
return nil, nil
}
return nil, err
}

if !servers.HasItems() {
return nil, nil
}

for _, server := range *servers.Items {
if !server.Entities.HasNics() {
continue
}
for _, nic := range *server.Entities.Nics.Items {
if nic.Properties.HasIps() {
for _, ip := range *nic.Properties.Ips {
if loadBalancerIP == ip {
return server.Properties.Name, nil
}
}
}
}
}

return nil, nil
}

func (a *IONOSClient) datacenterLocation(ctx context.Context) (string, error) {
if a.client == nil {
return "", errors.New("client isn't initialized")
Expand Down
18 changes: 5 additions & 13 deletions pkg/ionos/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,19 @@ func newProvider(config config.Config) cloudprovider.Interface {
return IONOS{
config: config,
instances: instances{
ionosClients: map[string]*client2.IONOSClient{},
},
loadbalancer: loadbalancer{
ionosClients: map[string]*client2.IONOSClient{},
clients: map[string]*client2.IONOSClient{},
},
}
}

func (p IONOS) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, _ <-chan struct{}) {
ctx := context.Background()
k8sClient, err := clientBuilder.Client(config.ClientName)
client, err := clientBuilder.Client(config.ClientName)
if err != nil {
klog.Errorf("Kubernetes Client Init Failed: %v", err)
return
}
secret, err := k8sClient.CoreV1().Secrets(p.config.TokenSecretNamespace).Get(ctx, p.config.TokenSecretName, metav1.GetOptions{})
secret, err := client.CoreV1().Secrets(p.config.TokenSecretNamespace).Get(ctx, p.config.TokenSecretName, metav1.GetOptions{})
if err != nil {
klog.Errorf("Failed to get secret %s/%s: %v", p.config.TokenSecretNamespace, p.config.TokenSecretName, err)
return
Expand All @@ -61,17 +58,12 @@ func (p IONOS) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, _
klog.Errorf("Failed to create client for datacenter %s: %v", key, err)
return
}

err = p.loadbalancer.AddClient(key, token)
if err != nil {
klog.Errorf("Failed to create client for datacenter %s: %v", key, err)
return
}
}
}

func (p IONOS) LoadBalancer() (cloudprovider.LoadBalancer, bool) {
return p.loadbalancer, true
klog.Warning("The IONOS cloud provider does not support load balancers")
return nil, false
}

func (p IONOS) Instances() (cloudprovider.Instances, bool) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/ionos/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ func GetUUIDFromNode(node *v1.Node) string {
}

func (i instances) AddClient(datacenterId string, token []byte) error {
if i.ionosClients[datacenterId] == nil {
if i.clients[datacenterId] == nil {
c, err := client2.New(datacenterId, token)
if err != nil {
return err
}
i.ionosClients[datacenterId] = &c
i.clients[datacenterId] = &c
}
return nil
}

// no caching
func (i instances) discoverNode(ctx context.Context, node *v1.Node) (*cloudprovider.InstanceMetadata, error) {
for _, client := range i.ionosClients {
for _, client := range i.clients {
var err error
var server *cloudprovider.InstanceMetadata
providerID := GetUUIDFromNode(node)
Expand Down
187 changes: 0 additions & 187 deletions pkg/ionos/loadbalancer.go

This file was deleted.

13 changes: 4 additions & 9 deletions pkg/ionos/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ import (
)

type IONOS struct {
config config.Config
instances instances
loadbalancer loadbalancer
client *client.IONOSClient
config config.Config
instances instances
client *client.IONOSClient
}

type instances struct {
ionosClients map[string]*client.IONOSClient
}

type loadbalancer struct {
ionosClients map[string]*client.IONOSClient
clients map[string]*client.IONOSClient
}

0 comments on commit 716446e

Please sign in to comment.