Skip to content

Commit

Permalink
fix nil pointer exception in route cleanup (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
kon-angelo authored Dec 6, 2022
1 parent b4582cc commit 6c041f8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
21 changes: 12 additions & 9 deletions pkg/controller/infrastructure/actuator_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ import (
"fmt"
"time"

extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller"
"github.com/gardener/gardener/extensions/pkg/terraformer"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
"github.com/gardener/gardener/pkg/utils/flow"
"github.com/go-logr/logr"

api "github.com/gardener/gardener-extension-provider-openstack/pkg/apis/openstack"
"github.com/gardener/gardener-extension-provider-openstack/pkg/apis/openstack/helper"
"github.com/gardener/gardener-extension-provider-openstack/pkg/internal"
"github.com/gardener/gardener-extension-provider-openstack/pkg/internal/infrastructure"
"github.com/gardener/gardener-extension-provider-openstack/pkg/openstack"
openstackclient "github.com/gardener/gardener-extension-provider-openstack/pkg/openstack/client"
"github.com/go-logr/logr"

extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller"
"github.com/gardener/gardener/extensions/pkg/terraformer"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
"github.com/gardener/gardener/pkg/utils/flow"
)

func (a *actuator) Delete(ctx context.Context, log logr.Logger, infra *extensionsv1alpha1.Infrastructure, cluster *extensionscontroller.Cluster) error {
Expand Down Expand Up @@ -97,7 +97,7 @@ func (a *actuator) Delete(ctx context.Context, log logr.Logger, infra *extension
destroyKubernetesRoutes = g.Add(flow.Task{
Name: "Destroying Kubernetes route entries",
Fn: flow.TaskFn(func(ctx context.Context) error {
return a.cleanupKubernetesRoutes(ctx, config, networkingClient, infra.Namespace, vars[infrastructure.TerraformOutputKeyRouterID])
return a.cleanupKubernetesRoutes(ctx, config, networkingClient, vars[infrastructure.TerraformOutputKeyRouterID])
}).
RetryUntilTimeout(10*time.Second, 5*time.Minute).
DoIf(configExists),
Expand All @@ -122,11 +122,14 @@ func (a *actuator) cleanupKubernetesRoutes(
ctx context.Context,
config *api.InfrastructureConfig,
client openstackclient.Networking,
shootSeedNamespace string,
routerID string,
) error {
if routerID == "" {
return nil
}
return infrastructure.CleanupKubernetesRoutes(ctx, client, routerID, config.Networks.Workers)
workesCIDR := infrastructure.WorkersCIDR(config)
if workesCIDR == "" {
return nil
}
return infrastructure.CleanupKubernetesRoutes(ctx, client, routerID, workesCIDR)
}
21 changes: 20 additions & 1 deletion pkg/internal/infrastructure/infrastucture.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"net"

"github.com/gardener/gardener-extension-provider-openstack/pkg/apis/openstack"
openstackclient "github.com/gardener/gardener-extension-provider-openstack/pkg/openstack/client"

"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers"
Expand All @@ -36,7 +37,10 @@ func CleanupKubernetesRoutes(ctx context.Context, client openstackclient.Network
}

routes := []routers.Route{}
_, workersNet, _ := net.ParseCIDR(workers)
_, workersNet, err := net.ParseCIDR(workers)
if err != nil {
return err
}

for _, route := range router[0].Routes {
ipNode, _, err := net.ParseCIDR(route.NextHop + "/32")
Expand All @@ -53,3 +57,18 @@ func CleanupKubernetesRoutes(ctx context.Context, client openstackclient.Network
}
return nil
}

// WorkersCIDR determines the Workers CIDR from the given InfrastructureConfig.
func WorkersCIDR(config *openstack.InfrastructureConfig) string {
if config == nil {
return ""
}

workersCIDR := config.Networks.Workers
// Backwards compatibility - remove this code in a future version.
if workersCIDR == "" {
workersCIDR = config.Networks.Worker
}

return workersCIDR
}
7 changes: 1 addition & 6 deletions pkg/internal/infrastructure/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,7 @@ func ComputeTerraformerTemplateValues(
routerConfig["enableSNAT"] = *cloudProfileConfig.UseSNAT
}

workersCIDR := config.Networks.Workers
// Backwards compatibility - remove this code in a future version.
if workersCIDR == "" {
workersCIDR = config.Networks.Worker
}

workersCIDR := WorkersCIDR(config)
networksConfig := map[string]interface{}{
"workers": workersCIDR,
}
Expand Down

0 comments on commit 6c041f8

Please sign in to comment.