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

Announce ipv6 prefixes to metalbond, add test cases #288

Merged
merged 2 commits into from
Dec 16, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59.0
version: v1.60.1
59 changes: 59 additions & 0 deletions controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,65 @@ var _ = Describe("Network Interface and LoadBalancer Controller", func() {
Expect(updatedIface.Status.State).To(Equal(metalnetv1alpha1.NetworkInterfaceStateReady))
})

It("IPv6 Prefixes should add/update/delete successfully", func() {
By("adding the IPv6 Prefix")
patchIface := networkInterface.DeepCopy()
patchIface.Spec.Prefixes = []metalnetv1alpha1.IPPrefix{
metalnetv1alpha1.MustParseIPPrefix("2001:db8::/64"),
}

Expect(k8sClient.Patch(ctx, patchIface, client.MergeFrom(networkInterface))).To(Succeed())

Expect(ifaceReconcile(ctx, *networkInterface)).To(Succeed())

// Fetch updated k8s interface object
updatedIface := &metalnetv1alpha1.NetworkInterface{}
Expect(k8sClient.Get(ctx, client.ObjectKey{
Name: networkInterface.Name,
Namespace: networkInterface.Namespace,
}, updatedIface)).To(Succeed())

Expect(updatedIface.Spec.Prefixes).ToNot(BeEmpty())
Expect(updatedIface.Spec.Prefixes[0].String()).To(Equal("2001:db8::/64"))
Expect(updatedIface.Status.State).To(Equal(metalnetv1alpha1.NetworkInterfaceStateReady))

By("updating the IPv6 Prefix")
patchIface = updatedIface.DeepCopy()
patchIface.Spec.Prefixes = []metalnetv1alpha1.IPPrefix{
metalnetv1alpha1.MustParseIPPrefix("2001:db8:1::/64"),
}

Expect(k8sClient.Patch(ctx, patchIface, client.MergeFrom(updatedIface))).To(Succeed())

Expect(ifaceReconcile(ctx, *updatedIface)).To(Succeed())

// Fetch updated k8s interface object
Expect(k8sClient.Get(ctx, client.ObjectKey{
Name: networkInterface.Name,
Namespace: networkInterface.Namespace,
}, updatedIface)).To(Succeed())

Expect(updatedIface.Spec.Prefixes).ToNot(BeEmpty())
Expect(updatedIface.Spec.Prefixes[0].String()).To(Equal("2001:db8:1::/64"))
Expect(updatedIface.Status.State).To(Equal(metalnetv1alpha1.NetworkInterfaceStateReady))

By("deleting the IPv6 Prefix")
patchIface = updatedIface.DeepCopy()
patchIface.Spec.Prefixes = []metalnetv1alpha1.IPPrefix{}

Expect(k8sClient.Patch(ctx, patchIface, client.MergeFrom(updatedIface))).To(Succeed())

Expect(ifaceReconcile(ctx, *updatedIface)).To(Succeed())

Expect(k8sClient.Get(ctx, client.ObjectKey{
Name: networkInterface.Name,
Namespace: networkInterface.Namespace,
}, updatedIface)).To(Succeed())

Expect(updatedIface.Spec.Prefixes).To(BeEmpty())
Expect(updatedIface.Status.State).To(Equal(metalnetv1alpha1.NetworkInterfaceStateReady))
})

It("LoadBalancerTargets should add/update/delete successfully", func() {
By("adding the LoadBalancerTarget")
patchIface := networkInterface.DeepCopy()
Expand Down
5 changes: 1 addition & 4 deletions controllers/networkinterface_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,10 +941,7 @@ func (r *NetworkInterfaceReconciler) reconcilePrefixes(ctx context.Context, log

specPrefixes := sets.New[netip.Prefix]()
for _, specPrefix := range nic.Spec.Prefixes {
// only ipv4 is supported for now
if specPrefix.Addr().Is4() {
specPrefixes.Insert(specPrefix.Prefix)
}
specPrefixes.Insert(specPrefix.Prefix)
}

// Sort prefixes to have deterministic error event output
Expand Down
Loading