Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kon-angelo committed Feb 13, 2024
1 parent f1f4ac6 commit f7c3faf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
6 changes: 3 additions & 3 deletions pkg/controller/infrastructure/infraflow/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (c *FlowContext) deleteShareNetwork(ctx context.Context) error {
subnetID := pointer.StringDeref(c.state.Get(IdentifierSubnet), "")
current, err := findExisting(c.state.Get(IdentifierShareNetwork),
c.namespace,
noopFinder[sharenetworks.ShareNetwork],
c.sharedFilesystem.GetShareNetwork,
func(name string) ([]*sharenetworks.ShareNetwork, error) {
list, err := c.sharedFilesystem.ListShareNetworks(sharenetworks.ListOpts{
AllTenants: false,
Expand All @@ -259,12 +259,12 @@ func (c *FlowContext) deleteShareNetwork(ctx context.Context) error {
return err
}
if current != nil {
log.Info("deleting...", "securityGroup", current.ID)
log.Info("deleting...", "shareNetwork", current.ID)
if err := c.sharedFilesystem.DeleteShareNetwork(current.ID); err != nil {
return err
}
}
c.state.Set(IdentifierNetwork, "")
c.state.Set(IdentifierShareNetwork, "")
c.state.Set(NameShareNetwork, "")
return nil
}
8 changes: 7 additions & 1 deletion pkg/controller/infrastructure/infraflow/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,16 @@ func (c *FlowContext) ensureSSHKeyPair(ctx context.Context) error {
}

func (c *FlowContext) ensureShareNetwork(ctx context.Context) error {
if c.config.Networks.ShareNetwork == nil || !c.config.Networks.ShareNetwork.Enabled {
return c.deleteShareNetwork(ctx)
}

log := c.LogFromContext(ctx)
networkID := pointer.StringDeref(c.state.Get(IdentifierNetwork), "")
subnetID := pointer.StringDeref(c.state.Get(IdentifierSubnet), "")
current, err := findExisting(c.state.Get(IdentifierShareNetwork),
c.namespace,
noopFinder[sharenetworks.ShareNetwork],
c.sharedFilesystem.GetShareNetwork,
func(name string) ([]*sharenetworks.ShareNetwork, error) {
list, err := c.sharedFilesystem.ListShareNetworks(sharenetworks.ListOpts{
Name: name,
Expand All @@ -485,8 +489,10 @@ func (c *FlowContext) ensureShareNetwork(ctx context.Context) error {
if err != nil {
return err
}

if current != nil {
c.state.Set(IdentifierShareNetwork, current.ID)
c.state.Set(NameShareNetwork, current.Name)
return nil
}

Expand Down
4 changes: 0 additions & 4 deletions pkg/controller/infrastructure/infraflow/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ func findExisting[T any](id *string, name string,
return found[0], nil
}

func noopFinder[T any](_ string) (*T, error) {
return nil, nil
}

type waiter struct {
log logr.Logger
start time.Time
Expand Down
15 changes: 15 additions & 0 deletions pkg/openstack/client/mocks/client_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions pkg/openstack/client/sharedfilesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (c *SharedFilesystemClient) CreateShareNetwork(createOpts sharenetworks.Cre
return sharenetworks.Create(c.client, createOpts).Extract()
}

// ListShareNetworks returns a list of subnets
// ListShareNetworks returns a list of share networks
func (c *SharedFilesystemClient) ListShareNetworks(listOpts sharenetworks.ListOpts) ([]sharenetworks.ShareNetwork, error) {
page, err := sharenetworks.ListDetail(c.client, listOpts).AllPages()
if err != nil {
Expand All @@ -32,7 +32,19 @@ func (c *SharedFilesystemClient) ListShareNetworks(listOpts sharenetworks.ListOp
return sharenetworks.ExtractShareNetworks(page)
}

// DeleteShareNetwork deletes a subnet by identifier
// DeleteShareNetwork deletes a share network by identifier
func (c *SharedFilesystemClient) DeleteShareNetwork(id string) error {
return sharenetworks.Delete(c.client, id).ExtractErr()
}

// GetShareNetwork returns a share network by identifier
func (c *SharedFilesystemClient) GetShareNetwork(id string) (*sharenetworks.ShareNetwork, error) {
sn, err := sharenetworks.Get(c.client, id).Extract()
if err != nil && !IsNotFoundError(err) {
return nil, err
}
if IsNotFoundError(err) {
return nil, nil
}
return sn, nil
}
1 change: 1 addition & 0 deletions pkg/openstack/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ type Loadbalancing interface {
// SharedFilesystem describes operations for OpenStack's Manila service.
type SharedFilesystem interface {
// Share Networks
GetShareNetwork(id string) (*sharenetworks.ShareNetwork, error)
CreateShareNetwork(createOpts sharenetworks.CreateOpts) (*sharenetworks.ShareNetwork, error)
ListShareNetworks(listOpts sharenetworks.ListOpts) ([]sharenetworks.ShareNetwork, error)
DeleteShareNetwork(id string) error
Expand Down

0 comments on commit f7c3faf

Please sign in to comment.