Skip to content

Commit 45c0db2

Browse files
PWX-24702 : Add cloudOps API to upgrade OKE cluster (#112)
* PWX-24702 : Add cloudOps API to upgrade OKE cluster
1 parent 37554fe commit 45c0db2

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

oracle/oracle.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,3 +786,110 @@ func nodePoolContainsNode(s []containerengine.Node, e string) bool {
786786
}
787787
return false
788788
}
789+
790+
func (o *oracleOps) SetClusterVersion(version string, timeout time.Duration) error {
791+
logrus.Println("Setting Cluster version to", version)
792+
req := containerengine.UpdateClusterRequest{
793+
ClusterId: &o.clusterID,
794+
UpdateClusterDetails: containerengine.UpdateClusterDetails{
795+
KubernetesVersion: &version,
796+
},
797+
}
798+
799+
resp, err := o.containerEngine.UpdateCluster(context.Background(), req)
800+
if err != nil {
801+
return err
802+
}
803+
804+
return o.waitTillWorkStatusIsSucceeded(resp.OpcRequestId, resp.OpcWorkRequestId, timeout)
805+
}
806+
807+
func (o *oracleOps) SetInstanceGroupVersion(instanceGroupName string, version string, timeout time.Duration) error {
808+
logrus.Println("Setting Instance group version to", version)
809+
//get nodepool ID from name
810+
var instanceGroupID *string
811+
nodePoolsReq := containerengine.ListNodePoolsRequest{CompartmentId: &o.compartmentID, Name: &instanceGroupName, ClusterId: &o.clusterID}
812+
nodePools, err := o.containerEngine.ListNodePools(context.Background(), nodePoolsReq)
813+
if err != nil {
814+
return err
815+
}
816+
817+
if len(nodePools.Items) == 0 {
818+
return errors.New("No node pool found with name" + instanceGroupName)
819+
}
820+
instanceGroupID = nodePools.Items[0].Id
821+
822+
//update kubernetes version of nodepool
823+
resp, err := o.containerEngine.UpdateNodePool(context.Background(), containerengine.UpdateNodePoolRequest{
824+
NodePoolId: instanceGroupID,
825+
UpdateNodePoolDetails: containerengine.UpdateNodePoolDetails{
826+
KubernetesVersion: &version,
827+
},
828+
})
829+
830+
if err != nil {
831+
return err
832+
}
833+
834+
err = o.waitTillWorkStatusIsSucceeded(resp.OpcRequestId, resp.OpcWorkRequestId, timeout)
835+
if err != nil {
836+
return err
837+
}
838+
839+
//Any changes made to worker node properties will only apply to new worker nodes.
840+
//We cannot change the properties of existing worker nodes.
841+
//To apply changes on existing worker nodes, first, scale the node pool to 0 .
842+
//Then scale up to original nodepool size with upgraded version
843+
//https://docs.oracle.com/en-us/iaas/Content/knownissues.htm#contengworkernodepropertiesoutofsync
844+
845+
updateResp, err := o.scaleDownToZeroThenScaleUp(instanceGroupName, *instanceGroupID, nodePools, timeout)
846+
if err != nil {
847+
return err
848+
}
849+
850+
return o.waitTillWorkStatusIsSucceeded(updateResp.OpcRequestId, updateResp.OpcWorkRequestId, timeout)
851+
}
852+
853+
func (o *oracleOps) scaleDownToZeroThenScaleUp(instanceGroupName, instanceGroupID string,
854+
nodePools containerengine.ListNodePoolsResponse, timeout time.Duration) (containerengine.UpdateNodePoolResponse, error) {
855+
856+
emptyResponse := containerengine.UpdateNodePoolResponse{}
857+
858+
//get existing total node count of instanceGroup
859+
existingClusterSize, err := o.GetInstanceGroupSize(instanceGroupName)
860+
if err != nil {
861+
return emptyResponse, err
862+
}
863+
864+
numberOfZones := len(nodePools.Items[0].NodeConfigDetails.PlacementConfigs)
865+
totalClusterSize := int(existingClusterSize)
866+
867+
//get all zones to be updated
868+
nodePoolPlacementConfigDetails := make([]containerengine.NodePoolPlacementConfigDetails, numberOfZones)
869+
870+
for i, placementConfigs := range nodePools.Items[0].NodeConfigDetails.PlacementConfigs {
871+
nodePoolPlacementConfigDetails[i].AvailabilityDomain = placementConfigs.AvailabilityDomain
872+
nodePoolPlacementConfigDetails[i].SubnetId = placementConfigs.SubnetId
873+
}
874+
//delete all nodes from existing node pool
875+
if err := o.SetInstanceGroupSize(instanceGroupName, 0, timeout); err != nil {
876+
return emptyResponse, err
877+
}
878+
879+
//create same number of nodes again with updated version
880+
req := containerengine.UpdateNodePoolRequest{
881+
NodePoolId: &instanceGroupID, //get node pool id
882+
UpdateNodePoolDetails: containerengine.UpdateNodePoolDetails{
883+
NodeConfigDetails: &containerengine.UpdateNodePoolNodeConfigDetails{
884+
Size: &totalClusterSize,
885+
PlacementConfigs: nodePoolPlacementConfigDetails,
886+
},
887+
},
888+
}
889+
updateResp, err := o.containerEngine.UpdateNodePool(context.Background(), req)
890+
if err != nil {
891+
return emptyResponse, err
892+
}
893+
894+
return updateResp, nil
895+
}

0 commit comments

Comments
 (0)