Skip to content

Commit

Permalink
Merge pull request #1371 from ish-hcc/ibm_cluster_version_check
Browse files Browse the repository at this point in the history
IBM: Implement Cluster version check
  • Loading branch information
powerkimhub authored Oct 22, 2024
2 parents 16b255f + 7d97f07 commit ad2fa1a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,40 @@ type IbmClusterHandler struct {

var defaultResourceGroupId string

func (ic *IbmClusterHandler) SupportedVersions(requestedVersion string) ([]string, error) {

getVersionsOptions := &kubernetesserviceapiv1.GetVersionsOptions{}

versions, _, err := ic.ClusterService.GetVersions(getVersionsOptions)
if err != nil {
return nil, fmt.Errorf("not found version: %v", err)
}

var availableVersions []string
isSupported := false

for versionGroup, kubeVersions := range versions {
if versionGroup == "kubernetes" {
for _, version := range kubeVersions {
currentVersion := fmt.Sprintf("%d.%d.%d", *version.Major, *version.Minor, *version.Patch)
if currentVersion == requestedVersion {
isSupported = true
}
availableVersions = append(availableVersions, currentVersion)
}
}
}

if !isSupported {
cblogger.Infof("not found version: %s", requestedVersion)
return availableVersions, fmt.Errorf("not found version: %s", requestedVersion)
}

cblogger.Infof("available version %s has been verified", requestedVersion)
return availableVersions, nil

}

func (ic *IbmClusterHandler) CreateCluster(clusterReqInfo irs.ClusterInfo) (irs.ClusterInfo, error) {
hiscallInfo := GetCallLogScheme(ic.Region, call.CLUSTER, clusterReqInfo.IId.NameId, "CreateCluster()")
start := call.Start()
Expand All @@ -103,6 +137,13 @@ func (ic *IbmClusterHandler) CreateCluster(clusterReqInfo irs.ClusterInfo) (irs.
return irs.ClusterInfo{}, errors.New(fmt.Sprintf("Failed to Create Cluster. err = %s", validationErr))
}

//checkedVersion
availableVersions, versionErr := ic.SupportedVersions(clusterReqInfo.Version)
if versionErr != nil {
LoggingError(hiscallInfo, versionErr)
return irs.ClusterInfo{}, errors.New(fmt.Sprintf("Failed to Create Cluster. Available versions: %v. err = %s", availableVersions, versionErr))
}

// get resource group id
resourceGroupId, getResourceGroupErr := ic.getDefaultResourceGroupId()
if getResourceGroupErr != nil {
Expand Down
2 changes: 1 addition & 1 deletion setup.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export CBSPIDER_ROOT=`cd $SCRIPT_DIR && pwd`
#export SERVER_ADDRESS=":1024"
#export SERVICE_ADDRESS="1.2.3.4:31024"

### Set the library type of Cloud Driver pkg.
### Set the library type of Cloud Driver pkg.
# ON is a shared library type.
# default: OFF (will be deprecated)
export PLUGIN_SW=OFF
Expand Down

0 comments on commit ad2fa1a

Please sign in to comment.