Skip to content

Commit 7df8b1c

Browse files
Add kubernetes version in OKE node pool spec (#163)
1 parent 63f3872 commit 7df8b1c

10 files changed

+86
-72
lines changed

cloud/scope/managed_control_plane.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package scope
1818

1919
import (
2020
"context"
21+
"encoding/json"
2122
"fmt"
2223
"io/ioutil"
2324
"reflect"
@@ -517,7 +518,16 @@ func (s *ManagedControlPlaneScope) UpdateControlPlane(ctx context.Context, okeCl
517518

518519
actual := s.getSpecFromActual(okeCluster)
519520
if !reflect.DeepEqual(spec, actual) {
520-
s.Logger.Info("Control plane", "spec", common.PointerString(*spec), "actual", common.PointerString(*actual))
521+
// printing json specs will help debug problems when there are spurious/unwanted updates
522+
jsonSpec, err := json.Marshal(*spec)
523+
if err != nil {
524+
return false, err
525+
}
526+
jsonActual, err := json.Marshal(*actual)
527+
if err != nil {
528+
return false, err
529+
}
530+
s.Logger.Info("Control plane", "spec", jsonSpec, "actual", jsonActual)
521531
controlPlaneSpec := s.OCIManagedControlPlane.Spec
522532
updateOptions := oke.UpdateClusterOptionsDetails{}
523533
if controlPlaneSpec.ClusterOption.AdmissionControllerOptions != nil {
@@ -540,7 +550,7 @@ func (s *ManagedControlPlaneScope) UpdateControlPlane(ctx context.Context, okeCl
540550
ClusterId: okeCluster.Id,
541551
UpdateClusterDetails: details,
542552
}
543-
_, err := s.ContainerEngineClient.UpdateCluster(ctx, updateClusterRequest)
553+
_, err = s.ContainerEngineClient.UpdateCluster(ctx, updateClusterRequest)
544554
if err != nil {
545555
return false, errors.Wrapf(err, "failed to update cluster")
546556
}

cloud/scope/managed_machine_pool.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package scope
1818

1919
import (
2020
"context"
21+
"encoding/json"
2122
"fmt"
2223
"reflect"
2324
"sort"
@@ -285,7 +286,7 @@ func (m *ManagedMachinePoolScope) CreateNodePool(ctx context.Context) (*oke.Node
285286
CompartmentId: common.String(m.OCIManagedCluster.Spec.CompartmentId),
286287
ClusterId: m.OCIManagedControlPlane.Spec.ID,
287288
Name: common.String(m.OCIManagedMachinePool.Name),
288-
KubernetesVersion: m.MachinePool.Spec.Template.Spec.Version,
289+
KubernetesVersion: m.OCIManagedMachinePool.Spec.Version,
289290
NodeShape: common.String(m.OCIManagedMachinePool.Spec.NodeShape),
290291
NodeShapeConfig: &nodeShapeConfig,
291292
NodeSourceDetails: &sourceDetails,
@@ -500,10 +501,18 @@ func (m *ManagedMachinePoolScope) UpdateNodePool(ctx context.Context, pool *oke.
500501

501502
actual := m.getSpecFromAPIObject(pool)
502503
if !reflect.DeepEqual(spec, actual) ||
503-
!reflect.DeepEqual(pool.KubernetesVersion, m.MachinePool.Spec.Template.Spec.Version) ||
504504
m.OCIManagedMachinePool.Name != *pool.Name {
505505
m.Logger.Info("Updating node pool")
506-
m.Logger.Info("Node pool", "spec", common.PointerString(*spec), "actual", common.PointerString(*actual))
506+
// printing json specs will help debug problems when there are spurious/unwanted updates
507+
jsonSpec, err := json.Marshal(*spec)
508+
if err != nil {
509+
return false, err
510+
}
511+
jsonActual, err := json.Marshal(*actual)
512+
if err != nil {
513+
return false, err
514+
}
515+
m.Logger.Info("Node pool", "spec", jsonSpec, "actual", jsonActual)
507516
placementConfig, err := m.buildPlacementConfig(spec.NodePoolNodeConfig.PlacementConfigs)
508517
if err != nil {
509518
return false, err
@@ -559,7 +568,7 @@ func (m *ManagedMachinePoolScope) UpdateNodePool(ctx context.Context, pool *oke.
559568
}
560569
nodePoolDetails := oke.UpdateNodePoolDetails{
561570
Name: common.String(m.OCIManagedMachinePool.Name),
562-
KubernetesVersion: m.MachinePool.Spec.Template.Spec.Version,
571+
KubernetesVersion: m.OCIManagedMachinePool.Spec.Version,
563572
NodeShape: common.String(m.OCIManagedMachinePool.Spec.NodeShape),
564573
NodeShapeConfig: &nodeShapeConfig,
565574
NodeSourceDetails: &sourceDetails,
@@ -602,6 +611,13 @@ func setMachinePoolSpecDefaults(spec *infrav1exp.OCIManagedMachinePoolSpec) {
602611
return *configs[i].AvailabilityDomain < *configs[j].AvailabilityDomain
603612
})
604613
}
614+
podNetworkOptions := spec.NodePoolNodeConfig.NodePoolPodNetworkOptionDetails
615+
if podNetworkOptions != nil {
616+
if podNetworkOptions.CniType == expinfra1.VCNNativeCNI {
617+
// 31 is the default max pods per node returned by OKE API
618+
spec.NodePoolNodeConfig.NodePoolPodNetworkOptionDetails.VcnIpNativePodNetworkOptions.MaxPodsPerNode = common.Int(31)
619+
}
620+
}
605621
}
606622

607623
func (m *ManagedMachinePoolScope) getSpecFromAPIObject(pool *oke.NodePool) *expinfra1.OCIManagedMachinePoolSpec {
@@ -638,6 +654,7 @@ func (m *ManagedMachinePoolScope) getSpecFromAPIObject(pool *oke.NodePool) *expi
638654
InitialNodeLabels: getInitialNodeLabels(pool.InitialNodeLabels),
639655
NodeShape: *pool.NodeShape,
640656
NodeMetadata: pool.NodeMetadata,
657+
Version: pool.KubernetesVersion,
641658
}
642659
if pool.NodeEvictionNodePoolSettings != nil {
643660
spec.NodeEvictionNodePoolSettings = &expinfra1.NodeEvictionNodePoolSettings{

cloud/scope/managed_machine_pool_test.go

Lines changed: 25 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package scope
1919
import (
2020
"context"
2121
"fmt"
22-
"reflect"
2322
"testing"
2423

2524
"github.com/golang/mock/gomock"
@@ -138,18 +137,16 @@ func TestManagedMachinePoolCreate(t *testing.T) {
138137
ObjectMeta: metav1.ObjectMeta{
139138
Name: "test",
140139
},
140+
Spec: infrav1exp.OCIManagedMachinePoolSpec{
141+
Version: common.String("v1.24.5"),
142+
},
141143
},
142144
OCIManagedCluster: ociManagedCluster,
143145
Cluster: &clusterv1.Cluster{
144146
Spec: clusterv1.ClusterSpec{},
145147
},
146148
MachinePool: &expclusterv1.MachinePool{
147149
Spec: expclusterv1.MachinePoolSpec{
148-
Template: clusterv1.MachineTemplateSpec{
149-
Spec: clusterv1.MachineSpec{
150-
Version: common.String("v1.24.5"),
151-
},
152-
},
153150
Replicas: &size,
154151
},
155152
},
@@ -177,6 +174,7 @@ func TestManagedMachinePoolCreate(t *testing.T) {
177174
testSpecificSetup: func(cs *ManagedMachinePoolScope, okeClient *mock_containerengine.MockClient) {
178175
ms.OCIManagedCluster.Spec.OCIResourceIdentifier = "resource_uid"
179176
ms.OCIManagedMachinePool.Spec = infrav1exp.OCIManagedMachinePoolSpec{
177+
Version: common.String("v1.24.5"),
180178
NodeMetadata: map[string]string{"key1": "value1"},
181179
InitialNodeLabels: []infrav1exp.KeyValue{{
182180
Key: common.String("key"),
@@ -208,7 +206,7 @@ func TestManagedMachinePoolCreate(t *testing.T) {
208206
CniType: infrav1exp.VCNNativeCNI,
209207
VcnIpNativePodNetworkOptions: infrav1exp.VcnIpNativePodNetworkOptions{
210208
SubnetNames: []string{"pod-subnet"},
211-
MaxPodsPerNode: common.Int(15),
209+
MaxPodsPerNode: common.Int(25),
212210
NSGNames: []string{"pod-nsg"},
213211
},
214212
},
@@ -258,7 +256,7 @@ func TestManagedMachinePoolCreate(t *testing.T) {
258256
DefinedTags: definedTagsInterface,
259257
NodePoolPodNetworkOptionDetails: oke.OciVcnIpNativeNodePoolPodNetworkOptionDetails{
260258
PodSubnetIds: []string{"pod-subnet-id"},
261-
MaxPodsPerNode: common.Int(15),
259+
MaxPodsPerNode: common.Int(25),
262260
PodNsgIds: []string{"pod-nsg-id"},
263261
},
264262
},
@@ -302,6 +300,7 @@ func TestManagedMachinePoolCreate(t *testing.T) {
302300
testSpecificSetup: func(cs *ManagedMachinePoolScope, okeClient *mock_containerengine.MockClient) {
303301
ms.OCIManagedCluster.Spec.OCIResourceIdentifier = "resource_uid"
304302
ms.OCIManagedMachinePool.Spec = infrav1exp.OCIManagedMachinePoolSpec{
303+
Version: common.String("v1.24.5"),
305304
NodeMetadata: map[string]string{"key1": "value1"},
306305
InitialNodeLabels: []infrav1exp.KeyValue{{
307306
Key: common.String("key"),
@@ -565,18 +564,17 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
565564
ObjectMeta: metav1.ObjectMeta{
566565
Name: "test",
567566
},
567+
Spec: infrav1exp.OCIManagedMachinePoolSpec{
568+
Version: common.String("v1.24.5"),
569+
},
568570
},
569571
OCIManagedCluster: ociManagedCluster,
570572
Cluster: &clusterv1.Cluster{
571573
Spec: clusterv1.ClusterSpec{},
572574
},
573575
MachinePool: &expclusterv1.MachinePool{
574576
Spec: expclusterv1.MachinePoolSpec{
575-
Template: clusterv1.MachineTemplateSpec{
576-
Spec: clusterv1.MachineSpec{
577-
Version: common.String("v1.24.5"),
578-
},
579-
},
577+
Template: clusterv1.MachineTemplateSpec{},
580578
Replicas: &size,
581579
},
582580
},
@@ -605,6 +603,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
605603
testSpecificSetup: func(cs *ManagedMachinePoolScope, okeClient *mock_containerengine.MockClient) {
606604
ms.OCIManagedCluster.Spec.OCIResourceIdentifier = "resource_uid"
607605
ms.OCIManagedMachinePool.Spec = infrav1exp.OCIManagedMachinePoolSpec{
606+
Version: common.String("v1.24.5"),
608607
NodeMetadata: map[string]string{"key1": "value1"},
609608
InitialNodeLabels: []infrav1exp.KeyValue{{
610609
Key: common.String("key"),
@@ -634,9 +633,8 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
634633
NodePoolPodNetworkOptionDetails: &infrav1exp.NodePoolPodNetworkOptionDetails{
635634
CniType: infrav1exp.VCNNativeCNI,
636635
VcnIpNativePodNetworkOptions: infrav1exp.VcnIpNativePodNetworkOptions{
637-
SubnetNames: []string{"pod-subnet"},
638-
MaxPodsPerNode: common.Int(15),
639-
NSGNames: []string{"pod-nsg"},
636+
SubnetNames: []string{"pod-subnet"},
637+
NSGNames: []string{"pod-nsg"},
640638
},
641639
},
642640
},
@@ -684,7 +682,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
684682
DefinedTags: definedTagsInterface,
685683
NodePoolPodNetworkOptionDetails: oke.OciVcnIpNativeNodePoolPodNetworkOptionDetails{
686684
PodSubnetIds: []string{"pod-subnet-id"},
687-
MaxPodsPerNode: common.Int(15),
685+
MaxPodsPerNode: common.Int(31),
688686
PodNsgIds: []string{"pod-nsg-id"},
689687
},
690688
},
@@ -700,6 +698,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
700698
testSpecificSetup: func(cs *ManagedMachinePoolScope, okeClient *mock_containerengine.MockClient) {
701699
ms.OCIManagedCluster.Spec.OCIResourceIdentifier = "resource_uid"
702700
ms.OCIManagedMachinePool.Spec = infrav1exp.OCIManagedMachinePoolSpec{
701+
Version: common.String("v1.24.5"),
703702
ID: common.String("node-pool-id"),
704703
NodeMetadata: map[string]string{"key1": "value1"},
705704
InitialNodeLabels: []infrav1exp.KeyValue{{
@@ -731,7 +730,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
731730
CniType: infrav1exp.VCNNativeCNI,
732731
VcnIpNativePodNetworkOptions: infrav1exp.VcnIpNativePodNetworkOptions{
733732
SubnetNames: []string{"pod-subnet"},
734-
MaxPodsPerNode: common.Int(15),
733+
MaxPodsPerNode: common.Int(31),
735734
NSGNames: []string{"pod-nsg"},
736735
},
737736
},
@@ -775,7 +774,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
775774
IsPvEncryptionInTransitEnabled: common.Bool(true),
776775
NodePoolPodNetworkOptionDetails: oke.OciVcnIpNativeNodePoolPodNetworkOptionDetails{
777776
PodSubnetIds: []string{"pod-subnet-id"},
778-
MaxPodsPerNode: common.Int(15),
777+
MaxPodsPerNode: common.Int(31),
779778
PodNsgIds: []string{"pod-nsg-id"},
780779
},
781780
},
@@ -828,7 +827,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
828827
DefinedTags: definedTagsInterface,
829828
NodePoolPodNetworkOptionDetails: oke.OciVcnIpNativeNodePoolPodNetworkOptionDetails{
830829
PodSubnetIds: []string{"pod-subnet-id"},
831-
MaxPodsPerNode: common.Int(15),
830+
MaxPodsPerNode: common.Int(31),
832831
PodNsgIds: []string{"pod-nsg-id"},
833832
},
834833
},
@@ -844,6 +843,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
844843
testSpecificSetup: func(cs *ManagedMachinePoolScope, okeClient *mock_containerengine.MockClient) {
845844
ms.OCIManagedCluster.Spec.OCIResourceIdentifier = "resource_uid"
846845
ms.OCIManagedMachinePool.Spec = infrav1exp.OCIManagedMachinePoolSpec{
846+
Version: common.String("v1.24.5"),
847847
ID: common.String("node-pool-id"),
848848
NodeMetadata: map[string]string{"key1": "value1"},
849849
InitialNodeLabels: []infrav1exp.KeyValue{{
@@ -875,7 +875,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
875875
CniType: infrav1exp.VCNNativeCNI,
876876
VcnIpNativePodNetworkOptions: infrav1exp.VcnIpNativePodNetworkOptions{
877877
SubnetNames: []string{"pod-subnet"},
878-
MaxPodsPerNode: common.Int(15),
878+
MaxPodsPerNode: common.Int(31),
879879
NSGNames: []string{"pod-nsg"},
880880
},
881881
},
@@ -919,7 +919,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
919919
IsPvEncryptionInTransitEnabled: common.Bool(true),
920920
NodePoolPodNetworkOptionDetails: oke.OciVcnIpNativeNodePoolPodNetworkOptionDetails{
921921
PodSubnetIds: []string{"pod-subnet-id"},
922-
MaxPodsPerNode: common.Int(15),
922+
MaxPodsPerNode: common.Int(31),
923923
PodNsgIds: []string{"pod-nsg-id"},
924924
},
925925
},
@@ -989,6 +989,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
989989
ms.OCIManagedCluster.Spec.OCIResourceIdentifier = "resource_uid"
990990
ms.OCIManagedMachinePool.Name = "changed"
991991
ms.OCIManagedMachinePool.Spec = infrav1exp.OCIManagedMachinePoolSpec{
992+
Version: common.String("v1.24.5"),
992993
ID: common.String("node-pool-id"),
993994
NodeMetadata: map[string]string{"key1": "value1"},
994995
InitialNodeLabels: []infrav1exp.KeyValue{{
@@ -1020,7 +1021,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
10201021
CniType: infrav1exp.VCNNativeCNI,
10211022
VcnIpNativePodNetworkOptions: infrav1exp.VcnIpNativePodNetworkOptions{
10221023
SubnetNames: []string{"pod-subnet"},
1023-
MaxPodsPerNode: common.Int(15),
1024+
MaxPodsPerNode: common.Int(31),
10241025
NSGNames: []string{"pod-nsg"},
10251026
},
10261027
},
@@ -1064,7 +1065,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
10641065
IsPvEncryptionInTransitEnabled: common.Bool(true),
10651066
NodePoolPodNetworkOptionDetails: oke.OciVcnIpNativeNodePoolPodNetworkOptionDetails{
10661067
PodSubnetIds: []string{"pod-subnet-id"},
1067-
MaxPodsPerNode: common.Int(15),
1068+
MaxPodsPerNode: common.Int(31),
10681069
PodNsgIds: []string{"pod-nsg-id"},
10691070
},
10701071
},
@@ -1149,35 +1150,3 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
11491150
})
11501151
}
11511152
}
1152-
1153-
func allMatcher(request interface{}, request2 oke.CreateNodePoolRequest) error {
1154-
r, ok := request.(oke.CreateNodePoolRequest)
1155-
if !ok {
1156-
return errors.New("expecting LaunchInstanceRequest type")
1157-
}
1158-
if !reflect.DeepEqual(r.NodeEvictionNodePoolSettings, request2.NodeEvictionNodePoolSettings) {
1159-
return errors.New(fmt.Sprintf("node eviction mismatch"))
1160-
}
1161-
if !reflect.DeepEqual(r.NodeShapeConfig, request2.NodeShapeConfig) {
1162-
return errors.New(fmt.Sprintf("node shape mismatch"))
1163-
}
1164-
if !reflect.DeepEqual(r.NodeConfigDetails.DefinedTags, request2.NodeConfigDetails.DefinedTags) {
1165-
return errors.New(fmt.Sprintf("node shape mismatch"))
1166-
}
1167-
if !reflect.DeepEqual(r.NodeConfigDetails.Size, request2.NodeConfigDetails.Size) {
1168-
return errors.New(fmt.Sprintf("node shape mismatch"))
1169-
}
1170-
if !reflect.DeepEqual(r.NodeConfigDetails.PlacementConfigs, request2.NodeConfigDetails.PlacementConfigs) {
1171-
return errors.New(fmt.Sprintf("node shape mismatch"))
1172-
}
1173-
if !reflect.DeepEqual(r.NodeConfigDetails.FreeformTags, request2.NodeConfigDetails.FreeformTags) {
1174-
return errors.New(fmt.Sprintf("node shape mismatch"))
1175-
}
1176-
if !reflect.DeepEqual(r.NodeConfigDetails.NodePoolPodNetworkOptionDetails, request2.NodeConfigDetails.NodePoolPodNetworkOptionDetails) {
1177-
return errors.New(fmt.Sprintf("node shape mismatch"))
1178-
}
1179-
if !reflect.DeepEqual(r.NodeConfigDetails.NsgIds, request2.NodeConfigDetails.NsgIds) {
1180-
return errors.New(fmt.Sprintf("node shape mismatch"))
1181-
}
1182-
return nil
1183-
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ spec:
205205
description: SshPublicKey defines the SSH public key on each node
206206
in the node pool on launch.
207207
type: string
208+
version:
209+
description: Version represents the version of the OKE node pool.
210+
type: string
208211
type: object
209212
status:
210213
description: OCIManagedMachinePoolStatus defines the observed state of

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ spec:
222222
description: SshPublicKey defines the SSH public key on each
223223
node in the node pool on launch.
224224
type: string
225+
version:
226+
description: Version represents the version of the OKE node
227+
pool.
228+
type: string
225229
type: object
226230
required:
227231
- spec

exp/api/v1beta1/ocimanagedmachinepool_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ type OCIManagedMachinePoolSpec struct {
2121
// +optional
2222
ProviderID *string `json:"providerID,omitempty"`
2323

24+
// Version represents the version of the OKE node pool.
25+
Version *string `json:"version,omitempty"`
26+
2427
// ID is the OCID of the associated NodePool
2528
// +optional
2629
ID *string `json:"id,omitempty"`

exp/api/v1beta1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)