Skip to content

Commit 2b9f61e

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 7cb2f32 commit 2b9f61e

2 files changed

Lines changed: 439 additions & 4 deletions

File tree

modules/common/ocp/ocp.go

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

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

61-
for _, clusterNetwork := range networkConfig.Status.ClusterNetwork {
62-
if k8s_utils.IsIPv6CIDRString(clusterNetwork.CIDR) {
81+
for _, node := range nodeList.Items {
82+
if node.Spec.PodCIDR != "" && k8s_utils.IsIPv6CIDRString(node.Spec.PodCIDR) {
6383
return true, nil
6484
}
85+
for _, podCIDR := range node.Spec.PodCIDRs {
86+
if k8s_utils.IsIPv6CIDRString(podCIDR) {
87+
return true, nil
88+
}
89+
}
6590
}
91+
6692
return false, nil
6793
}
6894

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

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

0 commit comments

Comments
 (0)