Skip to content

Commit

Permalink
feat(platform): ipv6 support (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
huxiaoliang committed Oct 9, 2020
1 parent 9e212bd commit 0a83821
Show file tree
Hide file tree
Showing 15 changed files with 1,002 additions and 374 deletions.
50 changes: 50 additions & 0 deletions api/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions api/platform/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ type ClusterSpec struct {
// If true will use hostname as nodename, if false will use machine IP as nodename.
// +optional
HostnameAsNodename bool
// +optional
NetworkArgs map[string]string
}

// ClusterStatus represents information about the status of a cluster.
Expand Down Expand Up @@ -164,6 +166,16 @@ type ClusterStatus struct {
DNSIP string
// +optional
RegistryIPs []string
// +optional
ClusterCIDR string
// +optional
SecondaryServiceCIDR string
// +optional
SecondaryClusterCIDR string
// +optional
NodeCIDRMaskSizeIPv4 int32
// +optional
NodeCIDRMaskSizeIPv6 int32
}

// FinalizerName is the name identifying a finalizer during cluster lifecycle.
Expand Down Expand Up @@ -340,6 +352,8 @@ type ClusterFeature struct {
AuthzWebhookAddr *AuthzWebhookAddr
// +optional
EnableMetricsServer bool
// +optional
IPv6DualStack bool
}

type HA struct {
Expand Down
1,081 changes: 734 additions & 347 deletions api/platform/v1/generated.pb.go

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions api/platform/v1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions api/platform/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ type ClusterSpec struct {
// +optional
NetworkType NetworkType `json:"networkType,omitempty" protobuf:"bytes,6,opt,name=networkType,casttype=NetworkType"`
// +optional
NetworkArgs map[string]string `json:"networkArgs,omitempty" protobuf:"bytes,23,name=networkArgs"`
// +optional
NetworkDevice string `json:"networkDevice,omitempty" protobuf:"bytes,7,opt,name=networkDevice"`
// +optional
ClusterCIDR string `json:"clusterCIDR,omitempty" protobuf:"bytes,8,opt,name=clusterCIDR"`
Expand Down Expand Up @@ -132,6 +130,8 @@ type ClusterSpec struct {
// If true will use hostname as nodename, if false will use machine IP as nodename.
// +optional
HostnameAsNodename bool `json:"hostnameAsNodename,omitempty" protobuf:"bytes,23,opt,name=hostnameAsNodename"`
// +optional
NetworkArgs map[string]string `json:"networkArgs,omitempty" protobuf:"bytes,24,name=networkArgs"`
}

// ClusterStatus represents information about the status of a cluster.
Expand Down Expand Up @@ -171,6 +171,16 @@ type ClusterStatus struct {
DNSIP string `json:"dnsIP,omitempty" protobuf:"bytes,13,opt,name=dnsIP"`
// +optional
RegistryIPs []string `json:"registryIPs,omitempty" protobuf:"bytes,14,opt,name=registryIPs"`
// +optional
SecondaryServiceCIDR string `json:"secondaryServiceCIDR,omitempty" protobuf:"bytes,15,opt,name=secondaryServiceCIDR"`
// +optional
ClusterCIDR string `json:"clusterCIDR,omitempty" protobuf:"bytes,16,opt,name=clusterCIDR"`
// +optional
SecondaryClusterCIDR string `json:"secondaryClusterCIDR,omitempty" protobuf:"bytes,17,opt,name=secondaryClusterCIDR"`
// +optional
NodeCIDRMaskSizeIPv4 int32 `json:"nodeCIDRMaskSizeIPv4,omitempty" protobuf:"varint,18,opt,name=nodeCIDRMaskSizeIPv4"`
// +optional
NodeCIDRMaskSizeIPv6 int32 `json:"nodeCIDRMaskSizeIPv6,omitempty" protobuf:"varint,19,opt,name=nodeCIDRMaskSizeIPv6"`
}

// FinalizerName is the name identifying a finalizer during cluster lifecycle.
Expand Down Expand Up @@ -347,6 +357,8 @@ type ClusterFeature struct {
AuthzWebhookAddr *AuthzWebhookAddr `json:"authzWebhookAddr,omitempty" protobuf:"bytes,11,opt,name=authzWebhookAddr"`
// +optional
EnableMetricsServer bool `json:"enableMetricsServer,omitempty" protobuf:"bytes,12,opt,name=enableMetricsServer"`
// +optional
IPv6DualStack bool `json:"ipv6DualStack,omitempty" protobuf:"bytes,13,opt,name=ipv6DualStack"`
}

type HA struct {
Expand Down
14 changes: 14 additions & 0 deletions api/platform/v1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions api/platform/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions api/platform/validation/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
utilsnet "k8s.io/utils/net"
platforminternalclient "tkestack.io/tke/api/client/clientset/internalversion/typed/platform/internalversion"
"tkestack.io/tke/api/platform"
machineprovider "tkestack.io/tke/pkg/platform/provider/machine"
Expand Down Expand Up @@ -187,6 +188,12 @@ func ValidateMachineWithCluster(ctx context.Context, ip string, fldPath *field.P
allErrs = append(allErrs, field.Duplicate(fldPath, ip))
}
}
cidrs := strings.Split(cluster.Spec.ClusterCIDR, ",")
for _, cidr := range cidrs {
if utilsnet.IsIPv6CIDRString(cidr) {
return allErrs
}
}

_, cidr, _ := net.ParseCIDR(cluster.Spec.ClusterCIDR)
ones, _ := cidr.Mask.Size()
Expand Down
7 changes: 7 additions & 0 deletions api/platform/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,7 @@ k8s.io/apimachinery v0.0.0-20191121175448-79c2a76c473a/go.mod h1:b9qmWdKlLuU9EBh
k8s.io/apimachinery v0.18.0/go.mod h1:9SnR/e11v5IbyPCGbvJViimtJ0SwHG4nfZFjU77ftcA=
k8s.io/apimachinery v0.18.2 h1:44CmtbmkzVDAhCpRVSiP2R5PPrC2RtlIv/MoB8xpdRA=
k8s.io/apimachinery v0.18.2/go.mod h1:9SnR/e11v5IbyPCGbvJViimtJ0SwHG4nfZFjU77ftcA=
k8s.io/apimachinery v0.19.2 h1:5Gy9vQpAGTKHPVOh5c4plE274X8D/6cuEiTO2zve7tc=
k8s.io/apiserver v0.0.0-20190918160949-bfa5e2e684ad/go.mod h1:XPCXEwhjaFN29a8NldXA901ElnKeKLrLtREO9ZhFyhg=
k8s.io/apiserver v0.0.0-20191122221311-9d521947b1e1/go.mod h1:RbsZY5zzBIWnz4KbctZsTVjwIuOpTp4Z8oCgFHN4kZQ=
k8s.io/apiserver v0.18.0/go.mod h1:3S2O6FeBBd6XTo0njUrLxiqk8GNy6wWOftjhJcXYnjw=
Expand Down Expand Up @@ -1471,6 +1472,7 @@ k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl
k8s.io/utils v0.0.0-20191114200735-6ca3b61696b6/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89 h1:d4vVOjXm687F1iLSP2q3lyPPuyvTUt3aVoBpi2DqRsU=
k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
k8s.io/utils v0.0.0-20201005171033-6301aaf42dc7 h1:XQ0OMFdRDkDIu0b1zqEKSZdWUD7I4bZ4d4nqr8CLKbQ=
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
Expand Down
37 changes: 34 additions & 3 deletions pkg/platform/provider/baremetal/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"k8s.io/client-go/rest"
bootstraputil "k8s.io/cluster-bootstrap/token/util"
kubeaggregatorclientset "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"
utilsnet "k8s.io/utils/net"
platformv1 "tkestack.io/tke/api/platform/v1"
"tkestack.io/tke/pkg/platform/provider/baremetal/constants"
"tkestack.io/tke/pkg/platform/provider/baremetal/images"
Expand Down Expand Up @@ -287,23 +288,53 @@ func (p *Provider) EnsureClusterComplete(ctx context.Context, cluster *v1.Cluste
func completeNetworking(cluster *v1.Cluster) error {
var (
serviceCIDR string
clusterCIDR string
nodeCIDRMaskSize int32
err error
)

// dual stack case
if cluster.Spec.Features.IPv6DualStack {
clusterCidrs := strings.Split(cluster.Spec.ClusterCIDR, ",")
serviceCidrs := strings.Split(*cluster.Spec.ServiceCIDR, ",")
for _, cidr := range clusterCidrs {
if maskSize, isIPv6 := CalcNodeCidrSize(cidr); isIPv6 {
cluster.Status.NodeCIDRMaskSizeIPv6 = maskSize
cluster.Status.SecondaryClusterCIDR = cidr
} else {
cluster.Status.NodeCIDRMaskSizeIPv4 = maskSize
cluster.Status.ClusterCIDR = cidr
}
}
for _, cidr := range serviceCidrs {
if utilsnet.IsIPv6CIDRString(cidr) {
cluster.Status.SecondaryServiceCIDR = cidr
} else {
cluster.Status.ServiceCIDR = cidr
}
}
return nil
}
// single stack case incldue ipv4 and ipv6
if cluster.Spec.ServiceCIDR != nil {
serviceCIDR = *cluster.Spec.ServiceCIDR
nodeCIDRMaskSize, err = GetNodeCIDRMaskSize(cluster.Spec.ClusterCIDR, *cluster.Spec.Properties.MaxNodePodNum)
if err != nil {
return errors.Wrap(err, "GetNodeCIDRMaskSize error")
if utilsnet.IsIPv6CIDRString(serviceCIDR) {
nodeCIDRMaskSize, _ = CalcNodeCidrSize(serviceCIDR)
} else {
nodeCIDRMaskSize, err = GetNodeCIDRMaskSize(cluster.Spec.ClusterCIDR, *cluster.Spec.Properties.MaxNodePodNum)
if err != nil {
return errors.Wrap(err, "GetNodeCIDRMaskSize error")
}
}
} else {
serviceCIDR, nodeCIDRMaskSize, err = GetServiceCIDRAndNodeCIDRMaskSize(cluster.Spec.ClusterCIDR, *cluster.Spec.Properties.MaxClusterServiceNum, *cluster.Spec.Properties.MaxNodePodNum)
if err != nil {
return errors.Wrap(err, "GetServiceCIDRAndNodeCIDRMaskSize error")
}
}
clusterCIDR = cluster.Spec.ClusterCIDR
cluster.Status.ServiceCIDR = serviceCIDR
cluster.Status.ClusterCIDR = clusterCIDR
cluster.Status.NodeCIDRMaskSize = nodeCIDRMaskSize

return nil
Expand Down

0 comments on commit 0a83821

Please sign in to comment.