Skip to content

Commit b624995

Browse files
committed
Implement ipv6 feature
1 parent 1da2921 commit b624995

23 files changed

+618
-45
lines changed

.gitignore

+2-17
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,8 @@ _artifacts/
3434
config/default/manager_image_patch.yaml-e
3535
config/default/manager_pull_policy.yaml-e
3636
test/e2e/config/e2e_conf-envsubst.yaml
37-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-antrea.yaml
38-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-ccm-testing.yaml
39-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-kcp-remediation.yaml
40-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-md-remediation.yaml
41-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-node-drain.yaml
42-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-oracle-linux.yaml
43-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template.yaml
44-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-bare-metal.yaml
45-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-custom-networking-seclist.yaml
46-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-custom-networking-nsg.yaml
47-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-multiple-node-nsg.yaml
48-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-local-vcn-peering.yaml
49-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-cluster-class.yaml
50-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-remote-vcn-peering.yaml
51-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-externally-managed-vcn.yaml
52-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-alternative-region.yaml
53-
test/e2e/data/infrastructure-oci/v1beta1/cluster-template-machine-pool.yaml
37+
test/e2e/data/infrastructure-oci/v1beta*/cluster-template*.yaml
38+
5439

5540
# tilt
5641
tilt-settings.json

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ generate-e2e-templates: $(KUSTOMIZE)
295295
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta2/cluster-template-windows-calico --load-restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta2/cluster-template-windows-calico.yaml
296296
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta2/cluster-template-managed-virtual --load-restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta2/cluster-template-managed-virtual.yaml
297297
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta2/cluster-template-managed-self-managed-nodes --load-restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta2/cluster-template-managed-self-managed-nodes.yaml
298+
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta2/cluster-template-machine-with-ipv6 --load-restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta2/cluster-template-machine-with-ipv6.yaml
299+
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta2/cluster-template-with-paravirt-bv --load-restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta2/cluster-template-with-paravirt-bv.yaml
298300

299301
.PHONY: test-e2e-run
300302
test-e2e-run: generate-e2e-templates $(GINKGO) $(ENVSUBST) ## Run e2e tests

api/v1beta1/types.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ type NetworkDetails struct {
3737
// SubnetId defines the ID of the subnet to use. This parameter takes priority over SubnetName.
3838
SubnetId *string `json:"subnetId,omitempty"`
3939

40+
// IPv6 defines if the instance should have an IPv6
41+
AssignIpv6Ip bool `json:"assignIpv6Ip,omitempty"`
42+
4043
// AssignPublicIp defines whether the instance should have a public IP address
4144
AssignPublicIp bool `json:"assignPublicIp,omitempty"`
4245

@@ -71,6 +74,9 @@ type VnicAttachment struct {
7174
// VnicAttachmentId defines the ID of the VnicAttachment
7275
VnicAttachmentId *string `json:"vnicAttachmentId,omitempty"`
7376

77+
// IPv6 defines if the instance should have an IPv6
78+
AssignIpv6Ip bool `json:"assignIpv6Ip,omitempty"`
79+
7480
// AssignPublicIp defines whether the vnic should have a public IP address
7581
// +optional
7682
AssignPublicIp bool `json:"assignPublicIp,omitempty"`
@@ -866,6 +872,8 @@ type Subnet struct {
866872
// within this subnet (for example, `bminstance1.subnet123.vcn1.oraclevcn.com`).
867873
// +optional
868874
DnsLabel *string `json:"dnsLabel,omitempty"`
875+
876+
Ipv6CidrBlockHextet *string `json:"ipv6CidrBlockHextet,omitempty"`
869877
}
870878

871879
// NSG defines configuration for a Network Security Group.
@@ -942,6 +950,14 @@ type VCN struct {
942950
// within this subnet (for example, `bminstance1.subnet123.vcn1.oraclevcn.com`).
943951
// +optional
944952
DnsLabel *string `json:"dnsLabel,omitempty"`
953+
954+
// Configuration to allow OCI to assign IPv6 Prefix.
955+
// +optional
956+
IsOracleGuaAllocationEnabled *bool `json:"isOracleGuaAllocationEnabled,omitempty"`
957+
958+
// Configuration to enable IPv6.
959+
// +optional
960+
IsIpv6Enabled *bool `json:"isIpv6Enabled,omitempty"`
945961
}
946962

947963
// LoadBalancer Configuration
@@ -1097,7 +1113,7 @@ type RemotePeeringConnection struct {
10971113
type VolumeType string
10981114

10991115
const (
1100-
IscsiType VolumeType = "iscsi"
1116+
IscsiType VolumeType = "iscsi"
11011117
ParavirtualizedType VolumeType = "paravirtualized"
11021118
)
11031119

@@ -1115,7 +1131,7 @@ type LaunchVolumeAttachment struct {
11151131
Type VolumeType `json:"volumeType,omitempty"`
11161132

11171133
// The details of iscsi volume attachment.
1118-
IscsiAttachment LaunchIscsiVolumeAttachment `json:"launchIscsiVolumeAttachment,omitempty"`
1134+
IscsiAttachment LaunchIscsiVolumeAttachment `json:"launchIscsiVolumeAttachment,omitempty"`
11191135
ParavirtualizedAttachment LaunchParavirtualizedVolumeAttachment `json:"launchParavirtualizedVolumeAttachment,omitempty"`
11201136
}
11211137

@@ -1177,7 +1193,7 @@ type LaunchParavirtualizedVolumeAttachment struct {
11771193

11781194
// LaunchCreateVolumeFromAttributes The details of the volume to create for CreateVolume operation.
11791195
LaunchCreateVolumeFromAttributes LaunchCreateVolumeFromAttributes `json:"launchCreateVolumeFromAttributes,omitempty"`
1180-
1196+
11811197
// Refer the top-level definition of isPvEncryptionInTransitEnabled.
11821198
// The default value is False.
11831199
IsPvEncryptionInTransitEnabled *bool `json:"isPvEncryptionInTransitEnabled,omitempty"`

api/v1beta2/types.go

+25-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ type NetworkDetails struct {
3838
// SubnetId defines the ID of the subnet to use. This parameter takes priority over SubnetName.
3939
SubnetId *string `json:"subnetId,omitempty"`
4040

41+
// AssignIPv6 determines whether to assign a IPv6 address to the instance.
42+
// +optional
43+
AssignIpv6Ip bool `json:"assignIpv6Ip,omitempty"`
44+
4145
// AssignPublicIp defines whether the instance should have a public IP address
4246
AssignPublicIp bool `json:"assignPublicIp,omitempty"`
4347

@@ -72,6 +76,10 @@ type VnicAttachment struct {
7276
// VnicAttachmentId defines the ID of the VnicAttachment
7377
VnicAttachmentId *string `json:"vnicAttachmentId,omitempty"`
7478

79+
// AssignIPv6 defines whether the vnic should have a IPv6 address
80+
// +optional
81+
AssignIpv6Ip bool `json:"assignIpv6Ip,omitempty"`
82+
7583
// AssignPublicIp defines whether the vnic should have a public IP address
7684
// +optional
7785
AssignPublicIp bool `json:"assignPublicIp,omitempty"`
@@ -865,6 +873,13 @@ type Subnet struct {
865873
// within this subnet (for example, `bminstance1.subnet123.vcn1.oraclevcn.com`).
866874
// +optional
867875
DnsLabel *string `json:"dnsLabel,omitempty"`
876+
877+
// Use this to enable IPv6 hextet for this subnet. The VCN must be enabled for IPv6.
878+
// You can't change this subnet characteristic later. All subnets are /64 in size. The subnet
879+
// portion of the IPv6 address is the fourth hextet from the left (1111 in the following example).
880+
// Example: `2001:0db8:0123:1111::/64`
881+
// +optional
882+
Ipv6CidrBlockHextet *string `json:"ipv6CidrBlockHextet,omitempty"`
868883
}
869884

870885
// NSG defines configuration for a Network Security Group.
@@ -935,6 +950,14 @@ type VCN struct {
935950
// within this subnet (for example, `bminstance1.subnet123.vcn1.oraclevcn.com`).
936951
// +optional
937952
DnsLabel *string `json:"dnsLabel,omitempty"`
953+
954+
// Configuration to allow OCI to assign IPv6 Prefix.
955+
// +optional
956+
IsOracleGuaAllocationEnabled *bool `json:"isOracleGuaAllocationEnabled,omitempty"`
957+
958+
// Configuration to enable IPv6.
959+
// +optional
960+
IsIpv6Enabled *bool `json:"isIpv6Enabled,omitempty"`
938961
}
939962

940963
// LoadBalancerType is an enumeration of the supported load balancer types.
@@ -1167,7 +1190,7 @@ type NetworkSecurityGroup struct {
11671190
type VolumeType string
11681191

11691192
const (
1170-
IscsiType VolumeType = "iscsi"
1193+
IscsiType VolumeType = "iscsi"
11711194
ParavirtualizedType VolumeType = "paravirtualized"
11721195
)
11731196

@@ -1186,7 +1209,7 @@ type LaunchVolumeAttachment struct {
11861209
Type VolumeType `json:"volumeType,omitempty"`
11871210

11881211
// The details of iscsi volume attachment.
1189-
IscsiAttachment LaunchIscsiVolumeAttachment `json:"launchIscsiVolumeAttachment,omitempty"`
1212+
IscsiAttachment LaunchIscsiVolumeAttachment `json:"launchIscsiVolumeAttachment,omitempty"`
11901213
ParavirtualizedAttachment LaunchParavirtualizedVolumeAttachment `json:"launchParavirtualizedVolumeAttachment,omitempty"`
11911214
}
11921215

@@ -1254,7 +1277,6 @@ type LaunchParavirtualizedVolumeAttachment struct {
12541277
IsPvEncryptionInTransitEnabled *bool `json:"isPvEncryptionInTransitEnabled,omitempty"`
12551278
}
12561279

1257-
12581280
// LaunchCreateVolumeFromAttributes The details of the volume to create for CreateVolume operation.
12591281
type LaunchCreateVolumeFromAttributes struct {
12601282

cloud/scope/machine.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ func (m *MachineScope) GetOrCreateMachine(ctx context.Context) (*core.Instance,
248248
SourceDetails: sourceDetails,
249249
CreateVnicDetails: &core.CreateVnicDetails{
250250
SubnetId: subnetId,
251+
AssignIpv6Ip: common.Bool(m.OCIMachine.Spec.NetworkDetails.AssignIpv6Ip),
251252
AssignPublicIp: common.Bool(m.OCIMachine.Spec.NetworkDetails.AssignPublicIp),
252253
FreeformTags: tags,
253254
DefinedTags: definedTags,
@@ -1023,13 +1024,13 @@ func getIscsiVolumeAttachment(attachment infrastructurev1beta2.LaunchIscsiVolume
10231024

10241025
func getParavirtualizedVolumeAttachment(attachment infrastructurev1beta2.LaunchParavirtualizedVolumeAttachment) core.LaunchAttachVolumeDetails {
10251026
volumeDetails := core.LaunchAttachParavirtualizedVolumeDetails{
1026-
Device: attachment.Device,
1027-
DisplayName: attachment.DisplayName,
1028-
IsShareable: attachment.IsShareable,
1029-
IsReadOnly: attachment.IsReadOnly,
1030-
VolumeId: attachment.VolumeId,
1031-
IsPvEncryptionInTransitEnabled: attachment.IsPvEncryptionInTransitEnabled,
1032-
LaunchCreateVolumeDetails: getLaunchCreateVolumeDetails(attachment.LaunchCreateVolumeFromAttributes),
1027+
Device: attachment.Device,
1028+
DisplayName: attachment.DisplayName,
1029+
IsShareable: attachment.IsShareable,
1030+
IsReadOnly: attachment.IsReadOnly,
1031+
VolumeId: attachment.VolumeId,
1032+
IsPvEncryptionInTransitEnabled: attachment.IsPvEncryptionInTransitEnabled,
1033+
LaunchCreateVolumeDetails: getLaunchCreateVolumeDetails(attachment.LaunchCreateVolumeFromAttributes),
10331034
}
10341035
return volumeDetails
10351036
}

cloud/scope/route_table_reconciler.go

+12
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ func (s *ClusterScope) CreateRouteTable(ctx context.Context, routeTableType stri
151151
Description: common.String("traffic to/from internet"),
152152
},
153153
}
154+
resp, err := s.VCNClient.GetVcn(ctx, core.GetVcnRequest{VcnId: s.getVcnId()})
155+
if err != nil {
156+
panic(err)
157+
}
158+
if resp.Vcn.Ipv6CidrBlocks != nil {
159+
routeRules = append(routeRules, core.RouteRule{
160+
DestinationType: core.RouteRuleDestinationTypeCidrBlock,
161+
Destination: common.String("::/0"),
162+
NetworkEntityId: s.OCIClusterAccessor.GetNetworkSpec().Vcn.InternetGateway.Id,
163+
Description: common.String("ipv6 traffic to/from internet"),
164+
})
165+
}
154166
routeTableName = PublicRouteTableName
155167
}
156168
vcnId := s.getVcnId()

cloud/scope/subnet_reconciler.go

+34
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ package scope
1818

1919
import (
2020
"context"
21+
"fmt"
22+
"net"
23+
"strings"
2124

2225
infrastructurev1beta2 "github.com/oracle/cluster-api-provider-oci/api/v1beta2"
2326
"github.com/oracle/cluster-api-provider-oci/cloud/ociutil"
@@ -101,6 +104,35 @@ func (s *ClusterScope) CreateSubnet(ctx context.Context, spec infrastructurev1be
101104
} else {
102105
routeTable = s.getRouteTableId(infrastructurev1beta2.Public)
103106
}
107+
108+
resp, err := s.VCNClient.GetVcn(ctx, core.GetVcnRequest{VcnId: s.getVcnId()})
109+
110+
var ipv6subnetCIDR_Ptr *string
111+
112+
if resp.Vcn.Ipv6CidrBlocks != nil {
113+
vcnCIDR := resp.Vcn.Ipv6CidrBlocks[0]
114+
115+
ip, _, err := net.ParseCIDR(vcnCIDR)
116+
if err != nil {
117+
panic(err)
118+
}
119+
120+
// Split into hextets
121+
hextets := strings.Split(ip.String(), ":")
122+
123+
// Modify the 4th hextet (index 3)
124+
originalHextet := hextets[3]
125+
if len(originalHextet) < 4 {
126+
originalHextet = fmt.Sprintf("%04s", originalHextet) // pad with leading zeros if needed
127+
}
128+
newHextet := originalHextet[:2] + *spec.Ipv6CidrBlockHextet
129+
hextets[3] = newHextet
130+
131+
// Reconstruct the IPv6 address with a /64 CIDR
132+
ipv6subnetCIDR := strings.Join(hextets, ":") + "/64"
133+
ipv6subnetCIDR_Ptr = &ipv6subnetCIDR
134+
}
135+
104136
createSubnetDetails := core.CreateSubnetDetails{
105137
CompartmentId: common.String(s.GetCompartmentId()),
106138
CidrBlock: common.String(spec.CIDR),
@@ -112,7 +144,9 @@ func (s *ClusterScope) CreateSubnet(ctx context.Context, spec infrastructurev1be
112144
FreeformTags: s.GetFreeFormTags(),
113145
DefinedTags: s.GetDefinedTags(),
114146
DnsLabel: spec.DnsLabel,
147+
Ipv6CidrBlock: ipv6subnetCIDR_Ptr,
115148
}
149+
116150
if spec.SecurityList != nil {
117151
createSubnetDetails.SecurityListIds = []string{*spec.SecurityList.ID}
118152
}

cloud/scope/vcn_reconciler.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ func (s *ClusterScope) UpdateVCN(ctx context.Context, vcn infrastructurev1beta2.
122122

123123
func (s *ClusterScope) CreateVCN(ctx context.Context, spec infrastructurev1beta2.VCN) (*string, error) {
124124
vcnDetails := core.CreateVcnDetails{
125-
CompartmentId: common.String(s.GetCompartmentId()),
126-
DisplayName: common.String(s.GetVcnName()),
127-
CidrBlocks: s.GetVcnCidrs(),
128-
FreeformTags: s.GetFreeFormTags(),
129-
DefinedTags: s.GetDefinedTags(),
130-
DnsLabel: spec.DnsLabel,
125+
CompartmentId: common.String(s.GetCompartmentId()),
126+
DisplayName: common.String(s.GetVcnName()),
127+
CidrBlocks: s.GetVcnCidrs(),
128+
FreeformTags: s.GetFreeFormTags(),
129+
DefinedTags: s.GetDefinedTags(),
130+
DnsLabel: spec.DnsLabel,
131+
IsOracleGuaAllocationEnabled: spec.IsOracleGuaAllocationEnabled,
132+
IsIpv6Enabled: spec.IsIpv6Enabled,
131133
}
132134
vcnResponse, err := s.VCNClient.CreateVcn(ctx, core.CreateVcnRequest{
133135
CreateVcnDetails: vcnDetails,

cloud/scope/vcn_reconciler_test.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ func TestClusterScope_CreateVCN(t *testing.T) {
7171
spec: infrastructurev1beta2.OCIClusterSpec{
7272
NetworkSpec: infrastructurev1beta2.NetworkSpec{
7373
Vcn: infrastructurev1beta2.VCN{
74-
Name: "normal",
75-
DnsLabel: common.String("label"),
76-
CIDR: "test-cidr",
74+
Name: "normal",
75+
DnsLabel: common.String("label"),
76+
CIDR: "test-cidr",
77+
IsIpv6Enabled: common.Bool(true),
78+
IsOracleGuaAllocationEnabled: common.Bool(true),
7779
},
7880
},
7981
},
@@ -85,9 +87,11 @@ func TestClusterScope_CreateVCN(t *testing.T) {
8587
spec: infrastructurev1beta2.OCIClusterSpec{
8688
NetworkSpec: infrastructurev1beta2.NetworkSpec{
8789
Vcn: infrastructurev1beta2.VCN{
88-
Name: "normal",
89-
DnsLabel: common.String("label"),
90-
CIDRS: []string{"test-cidr1", "test-cidr2"},
90+
Name: "normal",
91+
DnsLabel: common.String("label"),
92+
CIDRS: []string{"test-cidr1", "test-cidr2"},
93+
IsIpv6Enabled: common.Bool(true),
94+
IsOracleGuaAllocationEnabled: common.Bool(true),
9195
},
9296
},
9397
},

config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ spec:
166166
vcn:
167167
description: VCN configuration.
168168
properties:
169+
isIpv6Enabled:
170+
description: isIpv6Enabled enables the possibility to assign IPv6 to cluster nodes.
171+
type: boolean
172+
isOracleGuaAllocationEnabled:
173+
description: isOracleGuaAllocationEnabled enables OCI to assign a /56 prefix.
174+
type: boolean
169175
cidr:
170176
description: VCN CIDR. Deprecated, please use NetworkDetails.cidrs
171177
type: string
@@ -591,6 +597,9 @@ spec:
591597
DNS label to form a fully qualified domain name (FQDN)
592598
for each VNIC within this subnet (for example, `bminstance1.subnet123.vcn1.oraclevcn.com`).
593599
type: string
600+
ipv6CidrBlockHextet:
601+
description: Subnet IPv6 CIDR.
602+
type: string
594603
id:
595604
description: Subnet OCID.
596605
type: string
@@ -1382,6 +1391,12 @@ spec:
13821391
vcn:
13831392
description: VCN configuration.
13841393
properties:
1394+
isIpv6Enabled:
1395+
description: isIpv6Enabled enables the possibility to assign IPv6 to cluster nodes.
1396+
type: boolean
1397+
isOracleGuaAllocationEnabled:
1398+
description: isOracleGuaAllocationEnabled enables OCI to assign a /56 prefix.
1399+
type: boolean
13851400
cidr:
13861401
description: VCN CIDR. Deprecated, please use NetworkDetails.cidrs
13871402
type: string
@@ -1866,6 +1881,9 @@ spec:
18661881
DNS label to form a fully qualified domain name (FQDN)
18671882
for each VNIC within this subnet (for example, `bminstance1.subnet123.vcn1.oraclevcn.com`).
18681883
type: string
1884+
ipv6CidrBlockHextet:
1885+
description: Subnet IPv6 CIDR.
1886+
type: string
18691887
id:
18701888
description: Subnet OCID.
18711889
type: string

0 commit comments

Comments
 (0)