Skip to content

Commit 94ab2f6

Browse files
authored
Merge pull request #527 from olliewalsh/ipv6_check
Add function to check for OCP IPv6 cluster network
2 parents dd36520 + 6fcf309 commit 94ab2f6

File tree

3 files changed

+224
-0
lines changed

3 files changed

+224
-0
lines changed

modules/common/ocp/ocp.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import (
2121

2222
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
2323

24+
ocp_config "github.com/openshift/api/config/v1"
2425
"gopkg.in/yaml.v3"
2526
corev1 "k8s.io/api/core/v1"
2627
"k8s.io/apimachinery/pkg/types"
28+
k8s_utils "k8s.io/utils/net"
2729
)
2830

2931
// IsFipsCluster - Check if OCP has fips enabled which is a day 1 operation
@@ -47,3 +49,19 @@ func IsFipsCluster(ctx context.Context, h *helper.Helper) (bool, error) {
4749
}
4850
return fipsEnabled, nil
4951
}
52+
53+
// HasIPv6ClusterNetwork - Check if OCP has an IPv6 cluster network
54+
func HasIPv6ClusterNetwork(ctx context.Context, h *helper.Helper) (bool, error) {
55+
networkConfig := &ocp_config.Network{}
56+
err := h.GetClient().Get(ctx, types.NamespacedName{Name: "cluster", Namespace: ""}, networkConfig)
57+
if err != nil {
58+
return false, err
59+
}
60+
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+
}

modules/common/test/helpers/ocp.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2024 Red Hat
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package helpers
15+
16+
import (
17+
"github.com/onsi/gomega"
18+
"sigs.k8s.io/controller-runtime/pkg/client"
19+
20+
ocp_config "github.com/openshift/api/config/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// CreateClusterNetworkConfig creates a fake cluster network config CR
25+
func (tc *TestHelper) CreateClusterNetworkConfig() client.Object {
26+
instance := &ocp_config.Network{
27+
ObjectMeta: metav1.ObjectMeta{
28+
Name: "cluster",
29+
Namespace: "",
30+
},
31+
Status: ocp_config.NetworkStatus{
32+
ClusterNetwork: []ocp_config.ClusterNetworkEntry{
33+
{
34+
CIDR: "172.16.0.0/25",
35+
HostPrefix: 24,
36+
},
37+
},
38+
},
39+
}
40+
gomega.Expect(tc.K8sClient.Create(tc.Ctx, instance)).Should(gomega.Succeed())
41+
42+
return instance
43+
}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
annotations:
5+
api-approved.openshift.io: https://github.com/openshift/api/pull/470
6+
include.release.openshift.io/ibm-cloud-managed: "true"
7+
include.release.openshift.io/self-managed-high-availability: "true"
8+
include.release.openshift.io/single-node-developer: "true"
9+
name: networks.config.openshift.io
10+
spec:
11+
group: config.openshift.io
12+
names:
13+
kind: Network
14+
listKind: NetworkList
15+
plural: networks
16+
singular: network
17+
preserveUnknownFields: false
18+
scope: Cluster
19+
versions:
20+
- name: v1
21+
schema:
22+
openAPIV3Schema:
23+
description: "Network holds cluster-wide information about Network. The canonical name is `cluster`. It is used to configure the desired network configuration, such as: IP address pools for services/pod IPs, network plugin, etc. Please view network.spec for an explanation on what applies when configuring this resource. \n Compatibility level 1: Stable within a major release for a minimum of 12 months or 3 minor releases (whichever is longer)."
24+
type: object
25+
required:
26+
- spec
27+
properties:
28+
apiVersion:
29+
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
30+
type: string
31+
kind:
32+
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
33+
type: string
34+
metadata:
35+
type: object
36+
spec:
37+
description: spec holds user settable values for configuration. As a general rule, this SHOULD NOT be read directly. Instead, you should consume the NetworkStatus, as it indicates the currently deployed configuration. Currently, most spec fields are immutable after installation. Please view the individual ones for further details on each.
38+
type: object
39+
properties:
40+
clusterNetwork:
41+
description: IP address pool to use for pod IPs. This field is immutable after installation.
42+
type: array
43+
items:
44+
description: ClusterNetworkEntry is a contiguous block of IP addresses from which pod IPs are allocated.
45+
type: object
46+
properties:
47+
cidr:
48+
description: The complete block for pod IPs.
49+
type: string
50+
hostPrefix:
51+
description: The size (prefix) of block to allocate to each node. If this field is not used by the plugin, it can be left unset.
52+
type: integer
53+
format: int32
54+
minimum: 0
55+
externalIP:
56+
description: externalIP defines configuration for controllers that affect Service.ExternalIP. If nil, then ExternalIP is not allowed to be set.
57+
type: object
58+
properties:
59+
autoAssignCIDRs:
60+
description: autoAssignCIDRs is a list of CIDRs from which to automatically assign Service.ExternalIP. These are assigned when the service is of type LoadBalancer. In general, this is only useful for bare-metal clusters. In Openshift 3.x, this was misleadingly called "IngressIPs". Automatically assigned External IPs are not affected by any ExternalIPPolicy rules. Currently, only one entry may be provided.
61+
type: array
62+
items:
63+
type: string
64+
policy:
65+
description: policy is a set of restrictions applied to the ExternalIP field. If nil or empty, then ExternalIP is not allowed to be set.
66+
type: object
67+
properties:
68+
allowedCIDRs:
69+
description: allowedCIDRs is the list of allowed CIDRs.
70+
type: array
71+
items:
72+
type: string
73+
rejectedCIDRs:
74+
description: rejectedCIDRs is the list of disallowed CIDRs. These take precedence over allowedCIDRs.
75+
type: array
76+
items:
77+
type: string
78+
networkType:
79+
description: 'NetworkType is the plugin that is to be deployed (e.g. OpenShiftSDN). This should match a value that the cluster-network-operator understands, or else no networking will be installed. Currently supported values are: - OpenShiftSDN This field is immutable after installation.'
80+
type: string
81+
serviceNetwork:
82+
description: IP address pool for services. Currently, we only support a single entry here. This field is immutable after installation.
83+
type: array
84+
items:
85+
type: string
86+
serviceNodePortRange:
87+
description: The port range allowed for Services of type NodePort. If not specified, the default of 30000-32767 will be used. Such Services without a NodePort specified will have one automatically allocated from this range. This parameter can be updated after the cluster is installed.
88+
type: string
89+
pattern: ^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])-([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$
90+
status:
91+
description: status holds observed values from the cluster. They may not be overridden.
92+
type: object
93+
properties:
94+
clusterNetwork:
95+
description: IP address pool to use for pod IPs.
96+
type: array
97+
items:
98+
description: ClusterNetworkEntry is a contiguous block of IP addresses from which pod IPs are allocated.
99+
type: object
100+
properties:
101+
cidr:
102+
description: The complete block for pod IPs.
103+
type: string
104+
hostPrefix:
105+
description: The size (prefix) of block to allocate to each node. If this field is not used by the plugin, it can be left unset.
106+
type: integer
107+
format: int32
108+
minimum: 0
109+
clusterNetworkMTU:
110+
description: ClusterNetworkMTU is the MTU for inter-pod networking.
111+
type: integer
112+
migration:
113+
description: Migration contains the cluster network migration configuration.
114+
type: object
115+
properties:
116+
mtu:
117+
description: MTU contains the MTU migration configuration.
118+
type: object
119+
properties:
120+
machine:
121+
description: Machine contains MTU migration configuration for the machine's uplink.
122+
type: object
123+
properties:
124+
from:
125+
description: From is the MTU to migrate from.
126+
type: integer
127+
format: int32
128+
minimum: 0
129+
to:
130+
description: To is the MTU to migrate to.
131+
type: integer
132+
format: int32
133+
minimum: 0
134+
network:
135+
description: Network contains MTU migration configuration for the default network.
136+
type: object
137+
properties:
138+
from:
139+
description: From is the MTU to migrate from.
140+
type: integer
141+
format: int32
142+
minimum: 0
143+
to:
144+
description: To is the MTU to migrate to.
145+
type: integer
146+
format: int32
147+
minimum: 0
148+
networkType:
149+
description: 'NetworkType is the target plugin that is to be deployed. Currently supported values are: OpenShiftSDN, OVNKubernetes'
150+
type: string
151+
enum:
152+
- OpenShiftSDN
153+
- OVNKubernetes
154+
networkType:
155+
description: NetworkType is the plugin that is deployed (e.g. OpenShiftSDN).
156+
type: string
157+
serviceNetwork:
158+
description: IP address pool for services. Currently, we only support a single entry here.
159+
type: array
160+
items:
161+
type: string
162+
served: true
163+
storage: true

0 commit comments

Comments
 (0)