Skip to content

Commit 4801636

Browse files
committed
Add MicroShift support to IPv6 cluster net detect
The HasIPv6ClusterNetwork and FirstClusterNetworkIsIPv6 functions now fall back to checking Node PodCIDR when the OCP Network config is unavailable, enabling compatibility with MicroShift deployments. Assisted-By: Claude (claude-sonnet-4.5) Signed-off-by: Harald Jensås <hjensas@redhat.com>
1 parent 3a5f82f commit 4801636

3 files changed

Lines changed: 424 additions & 4 deletions

File tree

modules/common/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ require (
7474
golang.org/x/tools v0.41.0 // indirect
7575
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
7676
google.golang.org/protobuf v1.36.7 // indirect
77+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
7778
gopkg.in/inf.v0 v0.9.1 // indirect
7879
gopkg.in/yaml.v2 v2.4.0 // indirect
7980
k8s.io/apiextensions-apiserver v0.31.14 // indirect

modules/common/ocp/ocp.go

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
ocp_config "github.com/openshift/api/config/v1"
2626
"gopkg.in/yaml.v3"
2727
corev1 "k8s.io/api/core/v1"
28+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
2829
"k8s.io/apimachinery/pkg/types"
2930
k8s_utils "k8s.io/utils/net"
3031
)
@@ -52,31 +53,80 @@ func IsFipsCluster(ctx context.Context, h *helper.Helper) (bool, error) {
5253
}
5354

5455
// HasIPv6ClusterNetwork - Check if OCP has an IPv6 cluster network
56+
// Falls back to checking Node PodCIDR and kubernetes service IP families for MicroShift
5557
func HasIPv6ClusterNetwork(ctx context.Context, h *helper.Helper) (bool, error) {
5658
networkConfig := &ocp_config.Network{}
5759
err := h.GetClient().Get(ctx, types.NamespacedName{Name: "cluster", Namespace: ""}, networkConfig)
60+
if err == nil {
61+
// OCP Network config available
62+
for _, clusterNetwork := range networkConfig.Status.ClusterNetwork {
63+
if k8s_utils.IsIPv6CIDRString(clusterNetwork.CIDR) {
64+
return true, nil
65+
}
66+
}
67+
return false, nil
68+
}
69+
70+
// Fallback for MicroShift: check if error is NotFound
71+
if !k8serrors.IsNotFound(err) {
72+
return false, err
73+
}
74+
75+
// Check Node PodCIDR
76+
nodeList := &corev1.NodeList{}
77+
err = h.GetClient().List(ctx, nodeList)
5878
if err != nil {
5979
return false, err
6080
}
6181

62-
for _, clusterNetwork := range networkConfig.Status.ClusterNetwork {
63-
if k8s_utils.IsIPv6CIDRString(clusterNetwork.CIDR) {
82+
for _, node := range nodeList.Items {
83+
if node.Spec.PodCIDR != "" && k8s_utils.IsIPv6CIDRString(node.Spec.PodCIDR) {
6484
return true, nil
6585
}
86+
for _, podCIDR := range node.Spec.PodCIDRs {
87+
if k8s_utils.IsIPv6CIDRString(podCIDR) {
88+
return true, nil
89+
}
90+
}
6691
}
92+
6793
return false, nil
6894
}
6995

7096
// FirstClusterNetworkIsIPv6 - Check if first OCP cluster network is IPv6
97+
// Falls back to checking first Node PodCIDR and kubernetes service IP families for MicroShift
7198
func FirstClusterNetworkIsIPv6(ctx context.Context, h *helper.Helper) (bool, error) {
7299
networkConfig := &ocp_config.Network{}
73100
err := h.GetClient().Get(ctx, types.NamespacedName{Name: "cluster", Namespace: ""}, networkConfig)
101+
if err == nil {
102+
// OCP Network config available
103+
for _, clusterNetwork := range networkConfig.Status.ClusterNetwork {
104+
return k8s_utils.IsIPv6CIDRString(clusterNetwork.CIDR), nil
105+
}
106+
return false, nil
107+
}
108+
109+
// Fallback for MicroShift: check if error is NotFound
110+
if !k8serrors.IsNotFound(err) {
111+
return false, err
112+
}
113+
114+
// Check first Node PodCIDR
115+
nodeList := &corev1.NodeList{}
116+
err = h.GetClient().List(ctx, nodeList)
74117
if err != nil {
75118
return false, err
76119
}
77120

78-
for _, clusterNetwork := range networkConfig.Status.ClusterNetwork {
79-
return k8s_utils.IsIPv6CIDRString(clusterNetwork.CIDR), nil
121+
if len(nodeList.Items) > 0 {
122+
node := nodeList.Items[0]
123+
if node.Spec.PodCIDR != "" {
124+
return k8s_utils.IsIPv6CIDRString(node.Spec.PodCIDR), nil
125+
}
126+
if len(node.Spec.PodCIDRs) > 0 {
127+
return k8s_utils.IsIPv6CIDRString(node.Spec.PodCIDRs[0]), nil
128+
}
80129
}
130+
81131
return false, nil
82132
}

0 commit comments

Comments
 (0)