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 1 commit
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.

41 changes: 40 additions & 1 deletion pkg/controller/infrastructure/actuator_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,56 @@ package infrastructure

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

"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 !equalStringSlices(infra.Status.Networking.Nodes, newNodes) {
defo89 marked this conversation as resolved.
Show resolved Hide resolved
infra.Status.Networking.Nodes = newNodes
}

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

func equalStringSlices(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}

func (a *actuator) reconcile(ctx context.Context, log logr.Logger, infra *extensionsv1alpha1.Infrastructure, cluster *controller.Cluster) error {
return nil
}
Loading
Loading