Skip to content

Commit

Permalink
Implement Network peering controller and extend `NetworkPeeringStat…
Browse files Browse the repository at this point in the history
…us` with `State` field (#1026)

* Extend NetworkPeeringStatus with State field

* Implement network peering controller and add tests

* change network peering status state name from Initial to Pending

* modify network protection controller to keep finalizer if it has valid peering

* fix claimer key creation in network release controller
  • Loading branch information
kasabe28 authored Apr 5, 2024
1 parent 3e86451 commit 2f56f2c
Show file tree
Hide file tree
Showing 14 changed files with 1,024 additions and 5 deletions.
12 changes: 12 additions & 0 deletions api/networking/v1alpha1/network_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,22 @@ type NetworkStatus struct {
// +enum
type NetworkState string

// NetworkPeeringState is the state a NetworkPeering can be in
type NetworkPeeringState string

const (
// NetworkPeeringStatePending signals that the network peering is not applied.
NetworkPeeringStatePending NetworkPeeringState = "Pending"
// NetworkPeeringStateApplied signals that the network peering is applied.
NetworkPeeringStateApplied NetworkPeeringState = "Applied"
)

// NetworkPeeringStatus is the status of a network peering.
type NetworkPeeringStatus struct {
// Name is the name of the network peering.
Name string `json:"name"`
// State represents the network peering state
State NetworkPeeringState `json:"state,omitempty"`
}

const (
Expand Down
3 changes: 3 additions & 0 deletions client-go/applyconfigurations/internal/internal.go

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

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

7 changes: 7 additions & 0 deletions client-go/openapi/zz_generated.openapi.go

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

17 changes: 17 additions & 0 deletions cmd/ironcore-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const (
loadBalancerController = "loadbalancer"
loadBalancerEphemeralPrefixController = "loadbalancerephemeralprefix"
networkProtectionController = "networkprotection"
networkPeeringController = "networkpeering"
networkReleaseController = "networkrelease"
networkInterfaceEphemeralPrefixController = "networkinterfaceephemeralprefix"
networkInterfaceEphemeralVirtualIPController = "networkinterfaceephemeralvirtualip"
Expand Down Expand Up @@ -341,6 +342,15 @@ func main() {
}
}

if controllers.Enabled(networkPeeringController) {
if err := (&networkingcontrollers.NetworkPeeringReconciler{
Client: mgr.GetClient(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "NetworkPeering")
os.Exit(1)
}
}

if controllers.Enabled(networkReleaseController) {
if err := (&networkingcontrollers.NetworkReleaseReconciler{
Client: mgr.GetClient(),
Expand Down Expand Up @@ -523,6 +533,13 @@ func main() {
}
}

if controllers.AnyEnabled(networkProtectionController) {
if err := networkingclient.SetupNetworkSpecPeeringClaimRefNamesFieldIndexer(ctx, mgr.GetFieldIndexer()); err != nil {
setupLog.Error(err, "unable to setup field indexer", "field", networkingclient.NetworkSpecPeeringClaimRefNamesField)
os.Exit(1)
}
}

if controllers.AnyEnabled(networkInterfaceEphemeralPrefixController) {
if err := networkingclient.SetupNetworkInterfacePrefixNamesFieldIndexer(ctx, mgr.GetFieldIndexer()); err != nil {
setupLog.Error(err, "unable to setup field indexer", "field", networkingclient.NetworkInterfacePrefixNamesField)
Expand Down
12 changes: 12 additions & 0 deletions internal/apis/networking/network_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,22 @@ type NetworkStatus struct {
// +enum
type NetworkState string

// NetworkPeeringState is the state a NetworkPeering can be in.
type NetworkPeeringState string

const (
// NetworkPeeringStatePending signals that the network peering is not applied.
NetworkPeeringStatePending NetworkPeeringState = "Pending"
// NetworkPeeringStateApplied signals that the network peering is applied.
NetworkPeeringStateApplied NetworkPeeringState = "Applied"
)

// NetworkPeeringStatus is the status of a network peering.
type NetworkPeeringStatus struct {
// Name is the name of the network peering.
Name string
// State represents the network peering state
State NetworkPeeringState
}

const (
Expand Down
2 changes: 2 additions & 0 deletions internal/apis/networking/v1alpha1/zz_generated.conversion.go

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

28 changes: 28 additions & 0 deletions internal/client/networking/network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package networking

import (
"context"

"github.com/ironcore-dev/ironcore/api/networking/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const NetworkSpecPeeringClaimRefNamesField = "network-spec-peering-claim-ref-names"

func SetupNetworkSpecPeeringClaimRefNamesFieldIndexer(ctx context.Context, indexer client.FieldIndexer) error {
return indexer.IndexField(ctx, &v1alpha1.Network{}, NetworkSpecPeeringClaimRefNamesField, func(obj client.Object) []string {
network := obj.(*v1alpha1.Network)
peeringClaimRefNames := make([]string, 0, len(network.Spec.PeeringClaimRefs))
for _, peeringClaimRef := range network.Spec.PeeringClaimRefs {
peeringClaimRefNames = append(peeringClaimRefNames, peeringClaimRef.Name)
}

if len(peeringClaimRefNames) == 0 {
return []string{""}
}
return peeringClaimRefNames
})
}
Loading

0 comments on commit 2f56f2c

Please sign in to comment.