Skip to content
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

Add Networks to InfrastructureConfig #88

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions hack/api-reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,20 @@ by extra ignition.</p>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>networks</code></br>
<em>
<a href="#metal.provider.extensions.gardener.cloud/v1alpha1.Networks">
[]Networks
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>Networks is the metal specific network configuration.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="metal.provider.extensions.gardener.cloud/v1alpha1.InfrastructureStatus">InfrastructureStatus
Expand Down Expand Up @@ -698,6 +712,59 @@ bool
</tr>
</tbody>
</table>
<h3 id="metal.provider.extensions.gardener.cloud/v1alpha1.Networks">Networks
</h3>
<p>
(<em>Appears on:</em>
<a href="#metal.provider.extensions.gardener.cloud/v1alpha1.InfrastructureConfig">InfrastructureConfig</a>)
</p>
<p>
<p>Networks holds information about the Kubernetes and infrastructure networks.</p>
</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>name</code></br>
<em>
string
</em>
</td>
<td>
<p>Name is the name for this CIDR.</p>
</td>
</tr>
<tr>
<td>
<code>cidr</code></br>
<em>
string
</em>
</td>
<td>
<p>CIDR is the workers subnet range to create.</p>
</td>
</tr>
<tr>
<td>
<code>id</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>ID is the ID for the workers&rsquo; subnet.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="metal.provider.extensions.gardener.cloud/v1alpha1.RegionConfig">RegionConfig
</h3>
<p>
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/metal/types_infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
// InfrastructureConfig infrastructure configuration resource
type InfrastructureConfig struct {
metav1.TypeMeta

// Networks is the metal specific network configuration.
Networks []Networks
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -21,3 +24,13 @@ type InfrastructureConfig struct {
type InfrastructureStatus struct {
metav1.TypeMeta
}

// Networks holds information about the Kubernetes and infrastructure networks.
type Networks struct {
// Name is the name for this network.
Name string
// CIDR is the workers subnet range to create.
CIDR string
// ID is the ID for the workers' subnet.
ID string
}
15 changes: 15 additions & 0 deletions pkg/apis/metal/v1alpha1/types_infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
// InfrastructureConfig infrastructure configuration resource
type InfrastructureConfig struct {
metav1.TypeMeta `json:",inline"`

// Networks is the metal specific network configuration.
// +optional
Networks []Networks `json:"networks,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -22,3 +26,14 @@ type InfrastructureConfig struct {
type InfrastructureStatus struct {
metav1.TypeMeta `json:",inline"`
}

// Networks holds information about the Kubernetes and infrastructure networks.
type Networks struct {
// Name is the name for this CIDR.
Name string `json:"name"`
// CIDR is the workers subnet range to create.
CIDR string `json:"cidr"`
// ID is the ID for the workers' subnet.
// +optional
ID string `json:"id,omitempty"`
}
36 changes: 36 additions & 0 deletions pkg/apis/metal/v1alpha1/zz_generated.conversion.go

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

21 changes: 21 additions & 0 deletions pkg/apis/metal/v1alpha1/zz_generated.deepcopy.go

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

21 changes: 21 additions & 0 deletions pkg/apis/metal/zz_generated.deepcopy.go

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

30 changes: 29 additions & 1 deletion pkg/controller/infrastructure/actuator_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,42 @@ package infrastructure

import (
"context"
"encoding/json"
"fmt"
"slices"

"github.com/gardener/gardener/extensions/pkg/controller"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
"github.com/go-logr/logr"

metalv1alpha1 "github.com/ironcore-dev/gardener-extension-provider-metal/pkg/apis/metal/v1alpha1"
)

var (
infrastructureConfig metalv1alpha1.InfrastructureConfig
)

// Reconcile implements infrastructure.Actuator.
// Reconcile implements infrastructure actuator reconciliation
func (a *actuator) Reconcile(ctx context.Context, log logr.Logger, infra *extensionsv1alpha1.Infrastructure, cluster *controller.Cluster) error {
err := json.Unmarshal(cluster.Shoot.Spec.Provider.InfrastructureConfig.Raw, &infrastructureConfig)
if err != nil {
return fmt.Errorf("failed to unmarshal infrastructure config: %w", err)
}

var newNodes []string
if infrastructureConfig.Networks != nil {
for _, network := range infrastructureConfig.Networks {
if network.Name == "" {
return fmt.Errorf("network name is required")
}
newNodes = append(newNodes, network.CIDR)
}
}

if !slices.Equal(infra.Status.Networking.Nodes, newNodes) {
infra.Status.Networking.Nodes = newNodes
}

return a.reconcile(ctx, log, infra, cluster)
}

Expand Down
83 changes: 83 additions & 0 deletions pkg/controller/infrastructure/actuator_reconcile_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package infrastructure

import (
"context"
"encoding/json"

extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
"github.com/go-logr/logr"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/runtime"

metalv1alpha1 "github.com/ironcore-dev/gardener-extension-provider-metal/pkg/apis/metal/v1alpha1"
)

var (
shootVersionMajorMinor = "1.2"
shootVersion = shootVersionMajorMinor + ".3"
)

var _ = Describe("Actuator Reconcile", func() {
var (
ctx context.Context
log logr.Logger
infra *extensionsv1alpha1.Infrastructure
cluster *extensionscontroller.Cluster
act *actuator
)

BeforeEach(func() {
ctx = context.TODO()
log = logr.Discard()

infra = &extensionsv1alpha1.Infrastructure{
Status: extensionsv1alpha1.InfrastructureStatus{
Networking: &extensionsv1alpha1.InfrastructureStatusNetworking{
Nodes: []string{},
},
},
}

infrastructureConfig := metalv1alpha1.InfrastructureConfig{
Networks: []metalv1alpha1.Networks{
{Name: "worker-network-1", CIDR: "10.10.10.0/24", ID: "1"},
{Name: "worker-network-2", CIDR: "10.10.20.0/24", ID: "2"},
},
}
infrastructureConfigRaw, _ := json.Marshal(infrastructureConfig)

cluster = &extensionscontroller.Cluster{
Shoot: &gardencorev1beta1.Shoot{
Spec: gardencorev1beta1.ShootSpec{
Kubernetes: gardencorev1beta1.Kubernetes{
Version: shootVersion,
},
Provider: gardencorev1beta1.Provider{
InfrastructureConfig: &runtime.RawExtension{
Raw: infrastructureConfigRaw,
},
},
},
},
}

act = &actuator{}
})

Describe("#Reconcile", func() {
It("should update infra.Status.Networking.Nodes", func() {
err := act.Reconcile(ctx, log, infra, cluster)
Expect(err).NotTo(HaveOccurred())

// Verify that infra.Status.Networking.Nodes is updated
expectedNodes := []string{"10.10.10.0/24", "10.10.20.0/24"}
Expect(infra.Status.Networking.Nodes).To(Equal(expectedNodes))
})
})
})
Loading
Loading