Skip to content

Commit cbb1ae9

Browse files
committed
Remove IPFamily from public APIs (move to CAPD/kind util)
1 parent 7852761 commit cbb1ae9

File tree

18 files changed

+308
-367
lines changed

18 files changed

+308
-367
lines changed

.golangci-kal.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ linters:
6363
text: "Conditions field must be a slice of metav1.Condition"
6464
linters:
6565
- kubeapilinter
66-
- path: "api/v1beta2/*|api/v1beta1/*"
66+
- path: "api/v1beta1/*"
6767
text: "type ClusterIPFamily should not use an int, int8 or int16. Use int32 or int64 depending on bounding requirements"
6868
linters:
6969
- kubeapilinter

.golangci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,6 @@ linters:
239239
- linters:
240240
- staticcheck
241241
text: 'SA1019: (bootstrapv1.ClusterStatus|KubeadmConfigSpec.UseExperimentalRetryJoin|scope.Config.Spec.UseExperimentalRetryJoin|DockerMachine.Spec.Bootstrapped|machineStatus.Bootstrapped|dockerMachine.Spec.Backend.Docker.Bootstrapped|dockerMachine.Spec.Bootstrapped|devMachine.Spec.Backend.Docker.Bootstrapped|c.TopologyPlan|clusterv1.ClusterClassVariableMetadata|clusterv1beta1.ClusterClassVariableMetadata|(variable|currentDefinition|specVar|newVariableDefinition|statusVarDefinition).Metadata) is deprecated'
242-
# Deprecations forGetIPFamily
243-
- linters:
244-
- staticcheck
245-
text: 'SA1019: cluster.GetIPFamily is deprecated: IPFamily is not a concept in Kubernetes. It was originally introduced in CAPI for CAPD. IPFamily will be dropped in a future release. More details at https://github.com/kubernetes-sigs/cluster-api/issues/7521'
246242
# Deprecations for MD revision management
247243
- linters:
248244
- staticcheck

api/v1beta2/cluster_types.go

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"net"
2323
"strings"
2424

25-
"github.com/pkg/errors"
2625
corev1 "k8s.io/api/core/v1"
2726
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2827
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -1222,93 +1221,6 @@ func (c *Cluster) SetConditions(conditions []metav1.Condition) {
12221221
c.Status.Conditions = conditions
12231222
}
12241223

1225-
// GetIPFamily returns a ClusterIPFamily from the configuration provided.
1226-
//
1227-
// Deprecated: IPFamily is not a concept in Kubernetes. It was originally introduced in CAPI for CAPD.
1228-
// IPFamily will be dropped in a future release. More details at https://github.com/kubernetes-sigs/cluster-api/issues/7521
1229-
func (c *Cluster) GetIPFamily() (ClusterIPFamily, error) {
1230-
var podCIDRs, serviceCIDRs []string
1231-
if c.Spec.ClusterNetwork != nil {
1232-
if c.Spec.ClusterNetwork.Pods != nil {
1233-
podCIDRs = c.Spec.ClusterNetwork.Pods.CIDRBlocks
1234-
}
1235-
if c.Spec.ClusterNetwork.Services != nil {
1236-
serviceCIDRs = c.Spec.ClusterNetwork.Services.CIDRBlocks
1237-
}
1238-
}
1239-
if len(podCIDRs) == 0 && len(serviceCIDRs) == 0 {
1240-
return IPv4IPFamily, nil
1241-
}
1242-
1243-
podsIPFamily, err := ipFamilyForCIDRStrings(podCIDRs)
1244-
if err != nil {
1245-
return InvalidIPFamily, fmt.Errorf("pods: %s", err)
1246-
}
1247-
if len(serviceCIDRs) == 0 {
1248-
return podsIPFamily, nil
1249-
}
1250-
1251-
servicesIPFamily, err := ipFamilyForCIDRStrings(serviceCIDRs)
1252-
if err != nil {
1253-
return InvalidIPFamily, fmt.Errorf("services: %s", err)
1254-
}
1255-
if len(podCIDRs) == 0 {
1256-
return servicesIPFamily, nil
1257-
}
1258-
1259-
if podsIPFamily == DualStackIPFamily {
1260-
return DualStackIPFamily, nil
1261-
} else if podsIPFamily != servicesIPFamily {
1262-
return InvalidIPFamily, errors.New("pods and services IP family mismatch")
1263-
}
1264-
1265-
return podsIPFamily, nil
1266-
}
1267-
1268-
func ipFamilyForCIDRStrings(cidrs []string) (ClusterIPFamily, error) {
1269-
if len(cidrs) > 2 {
1270-
return InvalidIPFamily, errors.New("too many CIDRs specified")
1271-
}
1272-
var foundIPv4 bool
1273-
var foundIPv6 bool
1274-
for _, cidr := range cidrs {
1275-
ip, _, err := net.ParseCIDR(cidr)
1276-
if err != nil {
1277-
return InvalidIPFamily, fmt.Errorf("could not parse CIDR: %s", err)
1278-
}
1279-
if ip.To4() != nil {
1280-
foundIPv4 = true
1281-
} else {
1282-
foundIPv6 = true
1283-
}
1284-
}
1285-
switch {
1286-
case foundIPv4 && foundIPv6:
1287-
return DualStackIPFamily, nil
1288-
case foundIPv4:
1289-
return IPv4IPFamily, nil
1290-
case foundIPv6:
1291-
return IPv6IPFamily, nil
1292-
default:
1293-
return InvalidIPFamily, nil
1294-
}
1295-
}
1296-
1297-
// ClusterIPFamily defines the types of supported IP families.
1298-
type ClusterIPFamily int
1299-
1300-
// Define the ClusterIPFamily constants.
1301-
const (
1302-
InvalidIPFamily ClusterIPFamily = iota
1303-
IPv4IPFamily
1304-
IPv6IPFamily
1305-
DualStackIPFamily
1306-
)
1307-
1308-
func (f ClusterIPFamily) String() string {
1309-
return [...]string{"InvalidIPFamily", "IPv4IPFamily", "IPv6IPFamily", "DualStackIPFamily"}[f]
1310-
}
1311-
13121224
// +kubebuilder:object:root=true
13131225

13141226
// ClusterList contains a list of Cluster.

api/v1beta2/cluster_types_test.go

Lines changed: 0 additions & 197 deletions
This file was deleted.

docs/book/src/tasks/experimental-features/cluster-class/write-clusterclass.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,7 @@ In addition to variables specified in the ClusterClass, the following builtin va
610610
referenced in patches:
611611
- `builtin.cluster.{name,namespace,uid,metadata.labels,metadata.annotations}`
612612
- `builtin.cluster.topology.{version,class,classNamespace}`
613-
- `builtin.cluster.network.{serviceDomain,services,pods,ipFamily}`
614-
- Note: ipFamily is deprecated and will be removed in a future release. see https://github.com/kubernetes-sigs/cluster-api/issues/7521.
613+
- `builtin.cluster.network.{serviceDomain,services,pods}`
615614
- `builtin.controlPlane.{replicas,version,name,metadata.labels,metadata.annotations}`
616615
- Please note, these variables are only available when patching control plane or control plane
617616
machine templates.

exp/runtime/hooks/api/v1alpha1/topologymutation_variable_types.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ type ClusterNetworkBuiltins struct {
9696
// pods is the network ranges from which Pod networks are allocated.
9797
// +optional
9898
Pods []string `json:"pods,omitempty"`
99-
// ipFamily is the IPFamily the Cluster is operating in. One of Invalid, IPv4, IPv6, DualStack.
100-
//
101-
// Deprecated: IPFamily is not a concept in Kubernetes. It was originally introduced in CAPI for CAPD.
102-
// IPFamily will be dropped in a future release. More details at https://github.com/kubernetes-sigs/cluster-api/issues/7521
103-
// +optional
104-
IPFamily string `json:"ipFamily,omitempty"`
10599
}
106100

107101
// ControlPlaneBuiltins represents builtin ControlPlane variables.

internal/controllers/topology/cluster/patches/variables/variables.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,22 @@ func Global(clusterTopology *clusterv1.Topology, cluster *clusterv1.Cluster, pat
6969
}
7070
}
7171
if cluster.Spec.ClusterNetwork != nil {
72-
clusterNetworkIPFamily, _ := cluster.GetIPFamily()
73-
builtin.Cluster.Network = &runtimehooksv1.ClusterNetworkBuiltins{
74-
IPFamily: ipFamilyToString(clusterNetworkIPFamily),
75-
}
7672
if cluster.Spec.ClusterNetwork.ServiceDomain != "" {
73+
if builtin.Cluster.Network == nil {
74+
builtin.Cluster.Network = &runtimehooksv1.ClusterNetworkBuiltins{}
75+
}
7776
builtin.Cluster.Network.ServiceDomain = &cluster.Spec.ClusterNetwork.ServiceDomain
7877
}
7978
if cluster.Spec.ClusterNetwork.Services != nil && cluster.Spec.ClusterNetwork.Services.CIDRBlocks != nil {
79+
if builtin.Cluster.Network == nil {
80+
builtin.Cluster.Network = &runtimehooksv1.ClusterNetworkBuiltins{}
81+
}
8082
builtin.Cluster.Network.Services = cluster.Spec.ClusterNetwork.Services.CIDRBlocks
8183
}
8284
if cluster.Spec.ClusterNetwork.Pods != nil && cluster.Spec.ClusterNetwork.Pods.CIDRBlocks != nil {
85+
if builtin.Cluster.Network == nil {
86+
builtin.Cluster.Network = &runtimehooksv1.ClusterNetworkBuiltins{}
87+
}
8388
builtin.Cluster.Network.Pods = cluster.Spec.ClusterNetwork.Pods.CIDRBlocks
8489
}
8590
}
@@ -280,16 +285,3 @@ func toVariable(name string, value interface{}) (*runtimehooksv1.Variable, error
280285
Value: apiextensionsv1.JSON{Raw: marshalledValue},
281286
}, nil
282287
}
283-
284-
func ipFamilyToString(ipFamily clusterv1.ClusterIPFamily) string {
285-
switch ipFamily {
286-
case clusterv1.DualStackIPFamily:
287-
return "DualStack"
288-
case clusterv1.IPv4IPFamily:
289-
return "IPv4"
290-
case clusterv1.IPv6IPFamily:
291-
return "IPv6"
292-
default:
293-
return "Invalid"
294-
}
295-
}

0 commit comments

Comments
 (0)