Skip to content

✨ Delete router/network/subnet #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2020

Conversation

hidekazuna
Copy link
Contributor

What this PR does / why we need it:

This PR adds to delete router, network, and subnet feature. Currently how to delete cluster is not provided explicitly in my understanding, but we need to delete OpenStack resources easily even for testing. By this PR, we can delete OpenStack resources created with cluster-template-without-lb.yaml by the following.

kubectl delete machinedeployment capi-quickstart-md-0 -n capi-quickstart
kubectl delete kubeadmcontrolplane capi-quickstart-control-plane -n capi-quickstart
kubectl delete cluster capi-quickstart -n capi-quickstart

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

  1. Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

Release note:


@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 24, 2020
@k8s-ci-robot k8s-ci-robot requested review from Lion-Wei and ncdc March 24, 2020 01:43
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 24, 2020
@hidekazuna
Copy link
Contributor Author

/assign @sbueringer
/assign @jichenjc
/assign @prankul88

@sbueringer
Copy link
Member

sbueringer commented Mar 24, 2020

@hidekazuna

looks good to me. I'll test it later. Don't we have to delete the subnet?

@hidekazuna
Copy link
Contributor Author

@sbueringer When we delete a network, The subnet is deleted as well.

@sbueringer
Copy link
Member

@sbueringer When we delete a network, The subnet is deleted as well.

okay thx good to know

log.Info("OpenStack router deleted successfully")
}

if openStackCluster.Status.Network != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember clearly, do we have a chance that the network/router is not created by CPAO?
others LGTM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay as the cluster network/subnet are afaik always created by us

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I didn't remember clearly, will try this later on and submit PR if need :)

@sbueringer
Copy link
Member

@hidekazuna two small nits, apart from that everything worked :)

@hidekazuna
Copy link
Contributor Author

@sbueringer Thanks, fixed.

if err != nil {
return err
}
if exists {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a guard close would be more idiomatic in go, i.e.:

if !exist {
    s.logger.Info("No router", "router", network.Router.ID)
    return nil
}
if network.Subnet == nil || network.Subnet.ID == "" {
    s.logger.V(4).Info("No need to remove router interface since no subnet exists.")
    return nil
}
_, err := routers.RemoveInterface(s.client, network.Router.ID, routers.RemoveInterfaceOpts{
    SubnetID: network.Subnet.ID,
}).Extract()
if err != nil {
    return fmt.Errorf("unable to remove router interface: %v", err)
}
s.logger.V(4).Info("Removed RouterInterface of Router", "id", network.Router.ID)

err = routers.Delete(s.client, network.Router.ID).ExtractErr(

(same for DeleteNetwork)

@@ -165,6 +165,30 @@ INTERFACE_LOOP:
return nil
}

func (s *Service) DeleteRouter(network *infrav1.Network) error {
exists, err := s.existsRouter(network.Router.ID)
Copy link
Member

@sbueringer sbueringer Mar 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you still have to check for empty routerID as in you're previous commit. The problem is if the ID is an empty string
and you list all routers in existsRouter without an ID you get all existing routers (same for network)

EDIT: Just looked it up. I would suggest using routers.Get (& networks.Get) instead. Should be even save with empty ID and just returns 0 or 1 router not all so should be more efficient. Although I would still check for the empty string before and then checking for the existence with get

if openStackCluster.Status.Network.Router != nil {
log.Info("Deleting router", "name", openStackCluster.Status.Network.Router.Name)
err := networkingService.DeleteRouter(openStackCluster.Status.Network)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when you're already on it :). You can inline this to

if err := networkingService.DeleteRouter(openStackCluster.Status.Network); err != nil {

@hidekazuna hidekazuna force-pushed the delete_network branch 2 times, most recently from 2b14d1e to 2ca712e Compare March 30, 2020 02:06
@hidekazuna
Copy link
Contributor Author

@sbueringer Fixed.

Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last one :)

@sbueringer
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 30, 2020
@sbueringer
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hidekazuna, sbueringer

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 30, 2020
@k8s-ci-robot k8s-ci-robot merged commit 101a9de into kubernetes-sigs:master Mar 30, 2020
@hidekazuna hidekazuna deleted the delete_network branch March 31, 2020 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants