Skip to content

Commit

Permalink
Add kubernetes version in OKE node pool spec (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamradhakrishnan committed Sep 20, 2022
1 parent 63f3872 commit 7df8b1c
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 72 deletions.
14 changes: 12 additions & 2 deletions cloud/scope/managed_control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package scope

import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"reflect"
Expand Down Expand Up @@ -517,7 +518,16 @@ func (s *ManagedControlPlaneScope) UpdateControlPlane(ctx context.Context, okeCl

actual := s.getSpecFromActual(okeCluster)
if !reflect.DeepEqual(spec, actual) {
s.Logger.Info("Control plane", "spec", common.PointerString(*spec), "actual", common.PointerString(*actual))
// printing json specs will help debug problems when there are spurious/unwanted updates
jsonSpec, err := json.Marshal(*spec)
if err != nil {
return false, err
}
jsonActual, err := json.Marshal(*actual)
if err != nil {
return false, err
}
s.Logger.Info("Control plane", "spec", jsonSpec, "actual", jsonActual)
controlPlaneSpec := s.OCIManagedControlPlane.Spec
updateOptions := oke.UpdateClusterOptionsDetails{}
if controlPlaneSpec.ClusterOption.AdmissionControllerOptions != nil {
Expand All @@ -540,7 +550,7 @@ func (s *ManagedControlPlaneScope) UpdateControlPlane(ctx context.Context, okeCl
ClusterId: okeCluster.Id,
UpdateClusterDetails: details,
}
_, err := s.ContainerEngineClient.UpdateCluster(ctx, updateClusterRequest)
_, err = s.ContainerEngineClient.UpdateCluster(ctx, updateClusterRequest)
if err != nil {
return false, errors.Wrapf(err, "failed to update cluster")
}
Expand Down
25 changes: 21 additions & 4 deletions cloud/scope/managed_machine_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package scope

import (
"context"
"encoding/json"
"fmt"
"reflect"
"sort"
Expand Down Expand Up @@ -285,7 +286,7 @@ func (m *ManagedMachinePoolScope) CreateNodePool(ctx context.Context) (*oke.Node
CompartmentId: common.String(m.OCIManagedCluster.Spec.CompartmentId),
ClusterId: m.OCIManagedControlPlane.Spec.ID,
Name: common.String(m.OCIManagedMachinePool.Name),
KubernetesVersion: m.MachinePool.Spec.Template.Spec.Version,
KubernetesVersion: m.OCIManagedMachinePool.Spec.Version,
NodeShape: common.String(m.OCIManagedMachinePool.Spec.NodeShape),
NodeShapeConfig: &nodeShapeConfig,
NodeSourceDetails: &sourceDetails,
Expand Down Expand Up @@ -500,10 +501,18 @@ func (m *ManagedMachinePoolScope) UpdateNodePool(ctx context.Context, pool *oke.

actual := m.getSpecFromAPIObject(pool)
if !reflect.DeepEqual(spec, actual) ||
!reflect.DeepEqual(pool.KubernetesVersion, m.MachinePool.Spec.Template.Spec.Version) ||
m.OCIManagedMachinePool.Name != *pool.Name {
m.Logger.Info("Updating node pool")
m.Logger.Info("Node pool", "spec", common.PointerString(*spec), "actual", common.PointerString(*actual))
// printing json specs will help debug problems when there are spurious/unwanted updates
jsonSpec, err := json.Marshal(*spec)
if err != nil {
return false, err
}
jsonActual, err := json.Marshal(*actual)
if err != nil {
return false, err
}
m.Logger.Info("Node pool", "spec", jsonSpec, "actual", jsonActual)
placementConfig, err := m.buildPlacementConfig(spec.NodePoolNodeConfig.PlacementConfigs)
if err != nil {
return false, err
Expand Down Expand Up @@ -559,7 +568,7 @@ func (m *ManagedMachinePoolScope) UpdateNodePool(ctx context.Context, pool *oke.
}
nodePoolDetails := oke.UpdateNodePoolDetails{
Name: common.String(m.OCIManagedMachinePool.Name),
KubernetesVersion: m.MachinePool.Spec.Template.Spec.Version,
KubernetesVersion: m.OCIManagedMachinePool.Spec.Version,
NodeShape: common.String(m.OCIManagedMachinePool.Spec.NodeShape),
NodeShapeConfig: &nodeShapeConfig,
NodeSourceDetails: &sourceDetails,
Expand Down Expand Up @@ -602,6 +611,13 @@ func setMachinePoolSpecDefaults(spec *infrav1exp.OCIManagedMachinePoolSpec) {
return *configs[i].AvailabilityDomain < *configs[j].AvailabilityDomain
})
}
podNetworkOptions := spec.NodePoolNodeConfig.NodePoolPodNetworkOptionDetails
if podNetworkOptions != nil {
if podNetworkOptions.CniType == expinfra1.VCNNativeCNI {
// 31 is the default max pods per node returned by OKE API
spec.NodePoolNodeConfig.NodePoolPodNetworkOptionDetails.VcnIpNativePodNetworkOptions.MaxPodsPerNode = common.Int(31)
}
}
}

func (m *ManagedMachinePoolScope) getSpecFromAPIObject(pool *oke.NodePool) *expinfra1.OCIManagedMachinePoolSpec {
Expand Down Expand Up @@ -638,6 +654,7 @@ func (m *ManagedMachinePoolScope) getSpecFromAPIObject(pool *oke.NodePool) *expi
InitialNodeLabels: getInitialNodeLabels(pool.InitialNodeLabels),
NodeShape: *pool.NodeShape,
NodeMetadata: pool.NodeMetadata,
Version: pool.KubernetesVersion,
}
if pool.NodeEvictionNodePoolSettings != nil {
spec.NodeEvictionNodePoolSettings = &expinfra1.NodeEvictionNodePoolSettings{
Expand Down
81 changes: 25 additions & 56 deletions cloud/scope/managed_machine_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package scope
import (
"context"
"fmt"
"reflect"
"testing"

"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -138,18 +137,16 @@ func TestManagedMachinePoolCreate(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
Spec: infrav1exp.OCIManagedMachinePoolSpec{
Version: common.String("v1.24.5"),
},
},
OCIManagedCluster: ociManagedCluster,
Cluster: &clusterv1.Cluster{
Spec: clusterv1.ClusterSpec{},
},
MachinePool: &expclusterv1.MachinePool{
Spec: expclusterv1.MachinePoolSpec{
Template: clusterv1.MachineTemplateSpec{
Spec: clusterv1.MachineSpec{
Version: common.String("v1.24.5"),
},
},
Replicas: &size,
},
},
Expand Down Expand Up @@ -177,6 +174,7 @@ func TestManagedMachinePoolCreate(t *testing.T) {
testSpecificSetup: func(cs *ManagedMachinePoolScope, okeClient *mock_containerengine.MockClient) {
ms.OCIManagedCluster.Spec.OCIResourceIdentifier = "resource_uid"
ms.OCIManagedMachinePool.Spec = infrav1exp.OCIManagedMachinePoolSpec{
Version: common.String("v1.24.5"),
NodeMetadata: map[string]string{"key1": "value1"},
InitialNodeLabels: []infrav1exp.KeyValue{{
Key: common.String("key"),
Expand Down Expand Up @@ -208,7 +206,7 @@ func TestManagedMachinePoolCreate(t *testing.T) {
CniType: infrav1exp.VCNNativeCNI,
VcnIpNativePodNetworkOptions: infrav1exp.VcnIpNativePodNetworkOptions{
SubnetNames: []string{"pod-subnet"},
MaxPodsPerNode: common.Int(15),
MaxPodsPerNode: common.Int(25),
NSGNames: []string{"pod-nsg"},
},
},
Expand Down Expand Up @@ -258,7 +256,7 @@ func TestManagedMachinePoolCreate(t *testing.T) {
DefinedTags: definedTagsInterface,
NodePoolPodNetworkOptionDetails: oke.OciVcnIpNativeNodePoolPodNetworkOptionDetails{
PodSubnetIds: []string{"pod-subnet-id"},
MaxPodsPerNode: common.Int(15),
MaxPodsPerNode: common.Int(25),
PodNsgIds: []string{"pod-nsg-id"},
},
},
Expand Down Expand Up @@ -302,6 +300,7 @@ func TestManagedMachinePoolCreate(t *testing.T) {
testSpecificSetup: func(cs *ManagedMachinePoolScope, okeClient *mock_containerengine.MockClient) {
ms.OCIManagedCluster.Spec.OCIResourceIdentifier = "resource_uid"
ms.OCIManagedMachinePool.Spec = infrav1exp.OCIManagedMachinePoolSpec{
Version: common.String("v1.24.5"),
NodeMetadata: map[string]string{"key1": "value1"},
InitialNodeLabels: []infrav1exp.KeyValue{{
Key: common.String("key"),
Expand Down Expand Up @@ -565,18 +564,17 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
Spec: infrav1exp.OCIManagedMachinePoolSpec{
Version: common.String("v1.24.5"),
},
},
OCIManagedCluster: ociManagedCluster,
Cluster: &clusterv1.Cluster{
Spec: clusterv1.ClusterSpec{},
},
MachinePool: &expclusterv1.MachinePool{
Spec: expclusterv1.MachinePoolSpec{
Template: clusterv1.MachineTemplateSpec{
Spec: clusterv1.MachineSpec{
Version: common.String("v1.24.5"),
},
},
Template: clusterv1.MachineTemplateSpec{},
Replicas: &size,
},
},
Expand Down Expand Up @@ -605,6 +603,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
testSpecificSetup: func(cs *ManagedMachinePoolScope, okeClient *mock_containerengine.MockClient) {
ms.OCIManagedCluster.Spec.OCIResourceIdentifier = "resource_uid"
ms.OCIManagedMachinePool.Spec = infrav1exp.OCIManagedMachinePoolSpec{
Version: common.String("v1.24.5"),
NodeMetadata: map[string]string{"key1": "value1"},
InitialNodeLabels: []infrav1exp.KeyValue{{
Key: common.String("key"),
Expand Down Expand Up @@ -634,9 +633,8 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
NodePoolPodNetworkOptionDetails: &infrav1exp.NodePoolPodNetworkOptionDetails{
CniType: infrav1exp.VCNNativeCNI,
VcnIpNativePodNetworkOptions: infrav1exp.VcnIpNativePodNetworkOptions{
SubnetNames: []string{"pod-subnet"},
MaxPodsPerNode: common.Int(15),
NSGNames: []string{"pod-nsg"},
SubnetNames: []string{"pod-subnet"},
NSGNames: []string{"pod-nsg"},
},
},
},
Expand Down Expand Up @@ -684,7 +682,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
DefinedTags: definedTagsInterface,
NodePoolPodNetworkOptionDetails: oke.OciVcnIpNativeNodePoolPodNetworkOptionDetails{
PodSubnetIds: []string{"pod-subnet-id"},
MaxPodsPerNode: common.Int(15),
MaxPodsPerNode: common.Int(31),
PodNsgIds: []string{"pod-nsg-id"},
},
},
Expand All @@ -700,6 +698,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
testSpecificSetup: func(cs *ManagedMachinePoolScope, okeClient *mock_containerengine.MockClient) {
ms.OCIManagedCluster.Spec.OCIResourceIdentifier = "resource_uid"
ms.OCIManagedMachinePool.Spec = infrav1exp.OCIManagedMachinePoolSpec{
Version: common.String("v1.24.5"),
ID: common.String("node-pool-id"),
NodeMetadata: map[string]string{"key1": "value1"},
InitialNodeLabels: []infrav1exp.KeyValue{{
Expand Down Expand Up @@ -731,7 +730,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
CniType: infrav1exp.VCNNativeCNI,
VcnIpNativePodNetworkOptions: infrav1exp.VcnIpNativePodNetworkOptions{
SubnetNames: []string{"pod-subnet"},
MaxPodsPerNode: common.Int(15),
MaxPodsPerNode: common.Int(31),
NSGNames: []string{"pod-nsg"},
},
},
Expand Down Expand Up @@ -775,7 +774,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
IsPvEncryptionInTransitEnabled: common.Bool(true),
NodePoolPodNetworkOptionDetails: oke.OciVcnIpNativeNodePoolPodNetworkOptionDetails{
PodSubnetIds: []string{"pod-subnet-id"},
MaxPodsPerNode: common.Int(15),
MaxPodsPerNode: common.Int(31),
PodNsgIds: []string{"pod-nsg-id"},
},
},
Expand Down Expand Up @@ -828,7 +827,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
DefinedTags: definedTagsInterface,
NodePoolPodNetworkOptionDetails: oke.OciVcnIpNativeNodePoolPodNetworkOptionDetails{
PodSubnetIds: []string{"pod-subnet-id"},
MaxPodsPerNode: common.Int(15),
MaxPodsPerNode: common.Int(31),
PodNsgIds: []string{"pod-nsg-id"},
},
},
Expand All @@ -844,6 +843,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
testSpecificSetup: func(cs *ManagedMachinePoolScope, okeClient *mock_containerengine.MockClient) {
ms.OCIManagedCluster.Spec.OCIResourceIdentifier = "resource_uid"
ms.OCIManagedMachinePool.Spec = infrav1exp.OCIManagedMachinePoolSpec{
Version: common.String("v1.24.5"),
ID: common.String("node-pool-id"),
NodeMetadata: map[string]string{"key1": "value1"},
InitialNodeLabels: []infrav1exp.KeyValue{{
Expand Down Expand Up @@ -875,7 +875,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
CniType: infrav1exp.VCNNativeCNI,
VcnIpNativePodNetworkOptions: infrav1exp.VcnIpNativePodNetworkOptions{
SubnetNames: []string{"pod-subnet"},
MaxPodsPerNode: common.Int(15),
MaxPodsPerNode: common.Int(31),
NSGNames: []string{"pod-nsg"},
},
},
Expand Down Expand Up @@ -919,7 +919,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
IsPvEncryptionInTransitEnabled: common.Bool(true),
NodePoolPodNetworkOptionDetails: oke.OciVcnIpNativeNodePoolPodNetworkOptionDetails{
PodSubnetIds: []string{"pod-subnet-id"},
MaxPodsPerNode: common.Int(15),
MaxPodsPerNode: common.Int(31),
PodNsgIds: []string{"pod-nsg-id"},
},
},
Expand Down Expand Up @@ -989,6 +989,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
ms.OCIManagedCluster.Spec.OCIResourceIdentifier = "resource_uid"
ms.OCIManagedMachinePool.Name = "changed"
ms.OCIManagedMachinePool.Spec = infrav1exp.OCIManagedMachinePoolSpec{
Version: common.String("v1.24.5"),
ID: common.String("node-pool-id"),
NodeMetadata: map[string]string{"key1": "value1"},
InitialNodeLabels: []infrav1exp.KeyValue{{
Expand Down Expand Up @@ -1020,7 +1021,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
CniType: infrav1exp.VCNNativeCNI,
VcnIpNativePodNetworkOptions: infrav1exp.VcnIpNativePodNetworkOptions{
SubnetNames: []string{"pod-subnet"},
MaxPodsPerNode: common.Int(15),
MaxPodsPerNode: common.Int(31),
NSGNames: []string{"pod-nsg"},
},
},
Expand Down Expand Up @@ -1064,7 +1065,7 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
IsPvEncryptionInTransitEnabled: common.Bool(true),
NodePoolPodNetworkOptionDetails: oke.OciVcnIpNativeNodePoolPodNetworkOptionDetails{
PodSubnetIds: []string{"pod-subnet-id"},
MaxPodsPerNode: common.Int(15),
MaxPodsPerNode: common.Int(31),
PodNsgIds: []string{"pod-nsg-id"},
},
},
Expand Down Expand Up @@ -1149,35 +1150,3 @@ func TestManagedMachinePoolUpdate(t *testing.T) {
})
}
}

func allMatcher(request interface{}, request2 oke.CreateNodePoolRequest) error {
r, ok := request.(oke.CreateNodePoolRequest)
if !ok {
return errors.New("expecting LaunchInstanceRequest type")
}
if !reflect.DeepEqual(r.NodeEvictionNodePoolSettings, request2.NodeEvictionNodePoolSettings) {
return errors.New(fmt.Sprintf("node eviction mismatch"))
}
if !reflect.DeepEqual(r.NodeShapeConfig, request2.NodeShapeConfig) {
return errors.New(fmt.Sprintf("node shape mismatch"))
}
if !reflect.DeepEqual(r.NodeConfigDetails.DefinedTags, request2.NodeConfigDetails.DefinedTags) {
return errors.New(fmt.Sprintf("node shape mismatch"))
}
if !reflect.DeepEqual(r.NodeConfigDetails.Size, request2.NodeConfigDetails.Size) {
return errors.New(fmt.Sprintf("node shape mismatch"))
}
if !reflect.DeepEqual(r.NodeConfigDetails.PlacementConfigs, request2.NodeConfigDetails.PlacementConfigs) {
return errors.New(fmt.Sprintf("node shape mismatch"))
}
if !reflect.DeepEqual(r.NodeConfigDetails.FreeformTags, request2.NodeConfigDetails.FreeformTags) {
return errors.New(fmt.Sprintf("node shape mismatch"))
}
if !reflect.DeepEqual(r.NodeConfigDetails.NodePoolPodNetworkOptionDetails, request2.NodeConfigDetails.NodePoolPodNetworkOptionDetails) {
return errors.New(fmt.Sprintf("node shape mismatch"))
}
if !reflect.DeepEqual(r.NodeConfigDetails.NsgIds, request2.NodeConfigDetails.NsgIds) {
return errors.New(fmt.Sprintf("node shape mismatch"))
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ spec:
description: SshPublicKey defines the SSH public key on each node
in the node pool on launch.
type: string
version:
description: Version represents the version of the OKE node pool.
type: string
type: object
status:
description: OCIManagedMachinePoolStatus defines the observed state of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ spec:
description: SshPublicKey defines the SSH public key on each
node in the node pool on launch.
type: string
version:
description: Version represents the version of the OKE node
pool.
type: string
type: object
required:
- spec
Expand Down
3 changes: 3 additions & 0 deletions exp/api/v1beta1/ocimanagedmachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ type OCIManagedMachinePoolSpec struct {
// +optional
ProviderID *string `json:"providerID,omitempty"`

// Version represents the version of the OKE node pool.
Version *string `json:"version,omitempty"`

// ID is the OCID of the associated NodePool
// +optional
ID *string `json:"id,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions exp/api/v1beta1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 7df8b1c

Please sign in to comment.