Skip to content

Commit

Permalink
rebasing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kon-angelo committed Sep 16, 2024
1 parent e2ece8a commit 2964cff
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 23 deletions.
2 changes: 1 addition & 1 deletion charts/internal/machineclass/templates/machineclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ providerSpec:
{{- end }}
networkID: {{ $machineClass.networkID }}
subnetID: {{ $machineClass.subnetID }}
podNetworkCidr: {{ $machineClass.podNetworkCidr }}
podNetworkCIDRs: {{ $machineClass.podNetworkCIDRs }}
{{- if $machineClass.rootDiskSize }}
rootDiskSize: {{ $machineClass.rootDiskSize }}
{{- end }}
Expand Down
3 changes: 2 additions & 1 deletion charts/internal/machineclass/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ machineClasses:
imageName: coreos-v1.0
#imageID: 836428cd-5f98-1305-af9d-9825d4dfd0ec
networkID: 426428cd-5e88-4005-9fad-9555d4dfd0fb
podNetworkCidr: 100.96.0.0/11
# podNetworkCIDRs:
# - 100.96.0.0/11
# rootDiskSize: 100 # 100GB
# rootDiskType: standard_hdd
# serverGroupID: b35e94c1-15a7-4b54-a0f6-8789fasdf79s
Expand Down
15 changes: 10 additions & 5 deletions pkg/apis/openstack/validation/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func ValidateControlPlaneConfig(controlPlaneConfig *api.ControlPlaneConfig, infr
allErrs = append(allErrs, featurevalidation.ValidateFeatureGates(controlPlaneConfig.CloudControllerManager.FeatureGates, version, fldPath.Child("cloudControllerManager", "featureGates"))...)
}

allErrs = append(allErrs, validateStorage(controlPlaneConfig.Storage, infraConfig.Networks.ShareNetwork, fldPath.Child("storage"))...)
allErrs = append(allErrs, validateStorage(controlPlaneConfig.Storage, infraConfig.Networks, fldPath.Child("storage"))...)

return allErrs
}
Expand Down Expand Up @@ -139,13 +139,18 @@ func validateLoadBalancerClassesConstraints(floatingPools []api.FloatingPool, sh
return allErrs
}

func validateStorage(storage *api.Storage, shareNetwork *api.ShareNetwork, fldPath *field.Path) field.ErrorList {
func validateStorage(storage *api.Storage, networks api.Networks, fldPath *field.Path) field.ErrorList {
var allErrs field.ErrorList
if storage == nil || storage.CSIManila == nil || !storage.CSIManila.Enabled {
return allErrs
}
if shareNetwork == nil || !shareNetwork.Enabled {
allErrs = append(allErrs, field.Invalid(fldPath.Child("csiManila", "enabled"), storage.CSIManila.Enabled, "share network must be created if CSI manila driver is enabled"))
// for an existing subnet we do not need to validate the storage since we can only do that in runtime.
if networks.SubnetID != nil {
return allErrs
}
return allErrs
if networks.ShareNetwork != nil && networks.ShareNetwork.Enabled {
return allErrs

}
return append(allErrs, field.Invalid(fldPath.Child("csiManila", "enabled"), storage.CSIManila.Enabled, "share network must be created if CSI manila driver is enabled"))
}
4 changes: 0 additions & 4 deletions pkg/controller/controlplane/valuesprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,10 +953,6 @@ func (vp *valuesProvider) addCSIManilaValues(
"clusterID": cp.Namespace,
}

infraConfig, err := helper.InfrastructureConfigFromRawExtension(cluster.Shoot.Spec.Provider.InfrastructureConfig)
if err != nil {
return fmt.Errorf("could not decode infrastructure config of controlplane '%s': %w", k8sclient.ObjectKeyFromObject(cp), err)
}
infraStatus, err := vp.getInfrastructureStatus(cp)
if err != nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/infrastructure/infraflow/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ func (fctx *FlowContext) buildDeleteGraph() *flow.Graph {

_ = fctx.AddTask(g, "delete share network",
fctx.deleteShareNetwork,
shared.Timeout(defaultTimeout), shared.Dependencies(recoverSubnetID))
shared.Timeout(defaultTimeout), shared.Dependencies(recoverSubnetID),
shared.DoIf(needToDeleteSubnet),
)
deleteRouterInterface := fctx.AddTask(g, "delete router interface",
fctx.deleteRouterInterface,
shared.DoIf(needToDeleteSubnet || needToDeleteRouter),
Expand Down
34 changes: 34 additions & 0 deletions pkg/controller/infrastructure/infraflow/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,9 @@ func (fctx *FlowContext) ensureSSHKeyPair(ctx context.Context) error {
}

func (fctx *FlowContext) ensureShareNetwork(ctx context.Context) error {
if fctx.config.Networks.SubnetID != nil {
return fctx.ensureShareNetworkForExistingSubnet(ctx)
}
if fctx.config.Networks.ShareNetwork == nil || !fctx.config.Networks.ShareNetwork.Enabled {
return fctx.deleteShareNetwork(ctx)
}
Expand Down Expand Up @@ -521,3 +524,34 @@ func (fctx *FlowContext) ensureShareNetwork(ctx context.Context) error {
fctx.state.Set(NameShareNetwork, created.Name)
return nil
}

// ensureShareNetworkForExistingSubnet ensures the shared network for an existing subnet. Because the subnet may be shared among many different shoots,
// it could be that there is already a sharednetwork associated with a subnet. This function is responsible for detecting the shared network associated with the subnet.
func (fctx *FlowContext) ensureShareNetworkForExistingSubnet(ctx context.Context) error {
networkID := ptr.Deref(fctx.state.Get(IdentifierNetwork), "")
subnetID := ptr.Deref(fctx.state.Get(IdentifierSubnet), "")
current, err := findExisting(fctx.state.Get(IdentifierShareNetwork),
"",
fctx.sharedFilesystem.GetShareNetwork,
func(_ string) ([]*sharenetworks.ShareNetwork, error) {
list, err := fctx.sharedFilesystem.ListShareNetworks(sharenetworks.ListOpts{
NeutronNetID: networkID,
NeutronSubnetID: subnetID,
})
if err != nil {
return nil, err
}
return sliceToPtr(list), nil
})

if err != nil {
return err
}

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

return nil
}
9 changes: 0 additions & 9 deletions pkg/controller/infrastructure/infraflow/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,3 @@ func (fctx *FlowContext) defaultSecurityGroupName() string {
func (fctx *FlowContext) defaultSharedNetworkName() string {
return fctx.infra.Namespace
}

func (fctx *FlowContext) workerCIDR() string {
s := fctx.config.Networks.Worker
if workers := fctx.config.Networks.Workers; workers != "" {
s = workers
}

return s
}
2 changes: 1 addition & 1 deletion pkg/controller/worker/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error {
"machineType": pool.MachineType,
"keyName": infrastructureStatus.Node.KeyName,
"networkID": infrastructureStatus.Networks.ID,
"podNetworkCidr": extensionscontroller.GetPodNetwork(w.cluster),
"podNetworkCIDRs": extensionscontroller.GetPodNetwork(w.cluster),
"securityGroups": []string{nodesSecurityGroup.Name},
"tags": utils.MergeStringMaps(
NormalizeLabelsForMachineClass(pool.Labels),
Expand Down
11 changes: 10 additions & 1 deletion pkg/internal/infrastructure/infrastucture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/go-logr/logr"
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers"
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
Expand All @@ -21,8 +22,10 @@ var _ = Describe("Infrastructure", func() {
nw *mocks.MockNetworking
ctx context.Context
routerID string
subnetID string
defaultWorker = "10.0.0.0/16"
router *routers.Router
subnet *subnets.Subnet
clusterName = "foo-bar"
)

Expand All @@ -35,9 +38,14 @@ var _ = Describe("Infrastructure", func() {
Context("Route deletion", func() {
BeforeEach(func() {
routerID = "router"
subnetID = "subnet"
router = &routers.Router{
ID: routerID,
}
subnet = &subnets.Subnet{
ID: subnetID,
CIDR: defaultWorker,
}
})

type args struct {
Expand All @@ -48,11 +56,12 @@ var _ = Describe("Infrastructure", func() {
prepRoutes := func(routes ...routers.Route) {
router.Routes = routes
nw.EXPECT().GetRouterByID(routerID).Return(router, nil)
nw.EXPECT().GetSubnetByID(subnetID).Return(subnet, nil)
}

DescribeTable("#RouteCleanup", func(a args, expErr error) {
a.prep()
err := CleanupKubernetesRoutes(ctx, nw, routerID, a.workers)
err := CleanupKubernetesRoutes(ctx, nw, routerID, subnetID)
if expErr == nil {
Expect(err).To(BeNil())
} else {
Expand Down

0 comments on commit 2964cff

Please sign in to comment.