Skip to content

Commit

Permalink
add K8sClusterInfo struct and assets/k8sclusterinfo.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Sooyoung Kim committed May 23, 2024
1 parent 39807d0 commit 85cc6e7
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
80 changes: 80 additions & 0 deletions assets/k8sclusterinfo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Configuration for Cluster(Kubernetes) of Cloud Service Providers (CSPs)
# This file is used to define the feature of clusters

# The file is in YAML format and contains the following fields:
# k8scluster: Top level key
# <csp>: Name of the CSP
# nodegroupsWithCluster:
# version:
# - region: [region1, region2, all(special keyword)]

k8scluster:
nhncloud:
nodegroupsWithCluster: true
version:
- region: [kr1, kr2]
available:
- name: 1.28
id: 1.28.9-aliyun.1
- name: 1.26
id: 1.26.15-aliyun.1
- name: 1.24
id: 1.24.6-aliyun.1
- region: [jp1]
nodeImage:
- region: [kr1]
available:
- name: default
id: default
- name: aliyun 3.9
id: aliyun_3_9_x64_20G_alibase_20231219.vhd
- region: [kr2]
available:
- name: default
id: default
- name: aliyun 3.9
id: aliyun_3_9_x64_20G_alibase_20231219.vhd
- region: [jp1]
rootDisk:
- region: [all]
type:
- name: default
id: default
- name: basic
id: CLOUD_BASIC
size:
min: 10
max: 40
alibaba:
nodegroupsWithCluster: true
version:
- region: [all]
available:
- name: 1.28
id: 1.28.9-aliyun.1
- name: 1.26
id: 1.26.15-aliyun.1
- name: 1.24
id: 1.24.6-aliyun.1
nodeImage:
- region: [eu-west-1]
#configurable: true
available:
- name: default
id: default
- name: aliyun 3.9
id: aliyun_3_9_x64_20G_alibase_20231219.vhd
- region: [eu-west-2,kr2]
rootDisk:
- region: [eu-west-1]
type:
#configurable: true
- name: default
id: default
- name: basic
id: CLOUD_BASIC
size:
#configurable: true
min: 10
max: 40

59 changes: 59 additions & 0 deletions src/core/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,65 @@ type Credential struct {

var RuntimeCredential = Credential{}

// K8sClusterInfo is structure for kubernetes cluster information
type K8sClusterInfo struct {
CSPs map[string]K8sClusterDetail `mapstructure:"k8scluster" json:"k8s_cluster"`
}

// K8sClusterDetail is structure for kubernetes cluster detail information
type K8sClusterDetail struct {
NodeGroupsWithCluster bool `mapstructure:"nodegroupsWithCluster" json:"nodegroups_with_cluster"`
Version []VersionDetail `mapstructure:"version" json:"versions"`
NodeImage []NodeImageDetail `mapstructure:"nodeImage" json:"node_images"`
RootDisk []RootDiskDetail `mapstructure:"rootDisk" json:"root_disks"`
}

// VersionDetail is structure for kubernetes cluster version detail information
type VersionDetail struct {
Region []string `mapstructure:"region" json:"region"`
Available []VersionDetailAvailable `mapstructure:"available" json:"availables"`
}

// VersionDetailAvailable is structure for kubernetes cluster version detail's available information
type VersionDetailAvailable struct {
Name string `mapstructure:"name" json:"name"`
Id string `mapstructure:"id" json:"id"`
}

// NodeImageDetail is structure for kubernetes cluster node image detail information
type NodeImageDetail struct {
Region []string `mapstructure:"region" json:"region"`
Available []NodeImageDetailAvailable `mapstructure:"available" json:"availables"`
}

// NodeImageDetailAvailable is structure for kubernetes cluster node image detail's available information
type NodeImageDetailAvailable struct {
Name string `mapstructure:"name" json:"name"`
Id string `mapstructure:"id" json:"id"`
}

// RootDiskDetail is structure for kubernetes cluster root disk detail information
type RootDiskDetail struct {
Region []string `mapstructure:"region" json:"region"`
Type []RootDiskDetailType `mapstructure:"type" json:"type"`
Size RootDiskDetailSize `mapstructure:"size" json:"size"`
}

// RootDiskDetailType is structure for kubernetes cluster root disk detail's type information
type RootDiskDetailType struct {
Name string `mapstructure:"name" json:"name"`
Id string `mapstructure:"id" json:"id"`
}

// RootDiskDetailSize is structure for kubernetes cluster root disk detail's size information
type RootDiskDetailSize struct {
Min uint `mapstructure:"min" json:"min"`
Max uint `mapstructure:"max" json:"max"`
}

// RuntimeK8sClusterInfo is global variable for K8sClusterInfo
var RuntimeK8sClusterInfo = K8sClusterInfo{}

// AdjustKeysToLowercase adjusts the keys of nested maps to lowercase.
func AdjustKeysToLowercase(cloudInfo *CloudInfo) {
newCSPs := make(map[string]CSPDetail)
Expand Down
24 changes: 24 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,31 @@ func setConfig() {
// fmt.Printf("%+v\n", common.RuntimeCloudInfo)
common.PrintCloudInfoTable(common.RuntimeCloudInfo)

//
// Load k8sclusterinfo
//
k8sClusterInfoViper := viper.New()
fileName = "k8sclusterinfo"
k8sClusterInfoViper.AddConfigPath(".")
k8sClusterInfoViper.AddConfigPath("./assets/")
k8sClusterInfoViper.AddConfigPath("../assets/")
k8sClusterInfoViper.SetConfigName(fileName)
k8sClusterInfoViper.SetConfigType("yaml")
err = k8sClusterInfoViper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("fatal error reading cloudinfo config file: %w", err))
}

log.Info().Msg(k8sClusterInfoViper.ConfigFileUsed())
err = k8sClusterInfoViper.Unmarshal(&common.RuntimeK8sClusterInfo)
if err != nil {
log.Error().Err(err).Msg("")
panic(err)
}

//
// Wait until CB-Spider is ready
//
maxAttempts := 60 // (3 mins)
attempt := 0

Expand Down

0 comments on commit 85cc6e7

Please sign in to comment.