Skip to content

Commit

Permalink
PANDARIA: Delete create ack params zone_id
Browse files Browse the repository at this point in the history
  • Loading branch information
smallteeths authored and Jason-ZW committed Aug 18, 2023
1 parent 47e1ded commit eb1d014
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/
bin/
Binary file removed bin/ack-operator
Binary file not shown.
3 changes: 0 additions & 3 deletions charts/ack-operator-crd/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ spec:
type: string
nullable: true
type: array
zoneId:
nullable: true
type: string
type: object
status:
properties:
Expand Down
67 changes: 56 additions & 11 deletions controller/ack-cluster-config-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

ackapi "github.com/alibabacloud-go/cs-20151215/v3/client"
"github.com/alibabacloud-go/tea/tea"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
"github.com/cnrancher/ack-operator/internal/ack"
Expand Down Expand Up @@ -131,21 +132,28 @@ func (h *Handler) importCluster(config *ackv1.ACKClusterConfig) (*ackv1.ACKClust
if err != nil {
return config, err
}
if clusterMap == nil {
return config, fmt.Errorf("get import cluster error: The cluster is nil, indicating no cluster information is available")
}
cluster := &ackapi.DescribeClusterDetailResponseBody{}
err = utils.ConvertMapToObj(*clusterMap, cluster)
if err != nil {
return config, err
}

configUpdate := config.DeepCopy()
configUpdate.Spec = *FixConfig(&config.Spec, *clusterMap)
fixedSpec := FixConfig(&config.Spec, *clusterMap)
if fixedSpec == nil {
return config, fmt.Errorf("import cluster error: failed to convert and fix the configuration")
}
configUpdate.Spec = *fixedSpec
configUpdate.Spec.NodePoolList, err = GetNodePoolConfigInfo(h.secretsCache, &config.Spec)
if err != nil {
return config, err
}
pauseClusterUpgrade := false
clusterIsUpgrading := false
if *cluster.ClusterId != "" {
if cluster.ClusterId != nil && *cluster.ClusterId != "" {
client, err := GetClient(h.secretsCache, &configUpdate.Spec)
if err != nil {
return config, err
Expand All @@ -155,6 +163,9 @@ func (h *Handler) importCluster(config *ackv1.ACKClusterConfig) (*ackv1.ACKClust
return config, err
}
status := upgradeStatus.Status
if status == nil {
return config, fmt.Errorf("import cluster %s error: the cluster status is nil", *cluster.ClusterId)
}
if *status == ack.UpdateK8sRunningStatus {
clusterIsUpgrading = true
} else if *status == ack.UpdateK8sPauseStatus {
Expand Down Expand Up @@ -247,6 +258,9 @@ func (h *Handler) checkAndUpdate(config *ackv1.ACKClusterConfig) (*ackv1.ACKClus
if err != nil {
return config, err
}
if cluster == nil {
return config, fmt.Errorf("update cluster error: the cluster is nil, indicating no cluster information is available")
}
clusterState := utils.GetMapString("state", *cluster)
logrus.Infof("ackconfig cluster refersh updating %s", config.Name)
clusterIsUpgrading := false
Expand All @@ -260,6 +274,9 @@ func (h *Handler) checkAndUpdate(config *ackv1.ACKClusterConfig) (*ackv1.ACKClus
return config, err
}
status := upgradeStatus.Status
if status == nil {
return config, fmt.Errorf("update cluster %s error: the cluster status is nil", config.Spec.ClusterID)
}
if *status == ack.UpdateK8sRunningStatus {
clusterIsUpgrading = true
}
Expand Down Expand Up @@ -305,7 +322,11 @@ func (h *Handler) checkAndUpdate(config *ackv1.ACKClusterConfig) (*ackv1.ACKClus

updateConfig := config.DeepCopy()
// fix config fields
updateConfig.Spec = *FixConfig(&config.Spec, *cluster)
fixedSpec := FixConfig(&config.Spec, *cluster)
if fixedSpec == nil {
return config, fmt.Errorf("update cluster error: failed to convert and fix the configuration")
}
updateConfig.Spec = *fixedSpec
updateConfig, err = h.ackCC.Update(updateConfig)
if err != nil {
return config, err
Expand All @@ -316,6 +337,14 @@ func (h *Handler) checkAndUpdate(config *ackv1.ACKClusterConfig) (*ackv1.ACKClus
return config, err
}
for _, np := range nodePoolsInfo.Nodepools {
if np == nil {
logrus.Warn("Warning update cluster: The nodepool is nil, indicating no nodepool information is available")
continue
}
if np.Status == nil || np.Status.State == nil {
logrus.Warn("Warning update cluster: The nodepool status is nil, indicating no nodepool information is available")
continue
}
status := *np.Status.State
if status == ack.NodePoolStatusScaling || status == ack.NodePoolStatusDeleting || status == ack.NodePoolStatusInitial || status == ack.NodePoolStatusUpdating || status == ack.NodePoolStatusRemoving {
if config.Status.Phase != ackConfigUpdatingPhase {
Expand Down Expand Up @@ -409,6 +438,9 @@ func (h *Handler) waitForCreationComplete(config *ackv1.ACKClusterConfig) (*ackv
if err != nil {
return config, err
}
if cluster == nil {
return config, fmt.Errorf("create cluster error: get the cluster is nil, indicating no cluster information is available")
}
if *cluster.State == ack.ClusterStatusError {
return config, fmt.Errorf("creation failed for cluster %v", config.Spec.Name)
}
Expand Down Expand Up @@ -477,10 +509,18 @@ func GetClusterWithParam(secretsCache wranglerv1.SecretCache, configSpec *ackv1.
}

func BuildUpstreamClusterState(secretsCache wranglerv1.SecretCache, configSpec *ackv1.ACKClusterConfigSpec) (*ackv1.ACKClusterConfigSpec, error) {
if configSpec == nil {
logrus.Warn("Warning BuildUpstreamClusterState: The 'configSpec' data is nil, the cluster's configSpec is not available")
return configSpec, nil
}
cluster, err := GetCluster(secretsCache, configSpec)
if err != nil {
return configSpec, err
}
if cluster == nil {
logrus.Warn("Warning BuildUpstreamClusterState: Get cluster is nil, indicating no cluster information is available")
return configSpec, nil
}
pauseClusterUpgrade := false
clusterIsUpgrading := false
if configSpec.ClusterID != "" {
Expand All @@ -493,20 +533,23 @@ func BuildUpstreamClusterState(secretsCache wranglerv1.SecretCache, configSpec *
return configSpec, err
}
status := upgradeStatus.Status
if status == nil {
logrus.Warn("Warning BuildUpstreamClusterState: The cluster status is nil, indicating no cluster information is available")
return configSpec, nil
}
if *status == ack.UpdateK8sRunningStatus {
clusterIsUpgrading = true
} else if *status == ack.UpdateK8sPauseStatus {
pauseClusterUpgrade = true
}
}
newSpec := &ackv1.ACKClusterConfigSpec{
Name: *cluster.Name,
ClusterID: *cluster.ClusterId,
ClusterType: *cluster.ClusterType,
KubernetesVersion: *cluster.CurrentVersion,
RegionID: *cluster.RegionId,
VpcID: *cluster.VpcId,
ZoneID: *cluster.ZoneId,
Name: tea.StringValue(cluster.Name),
ClusterID: tea.StringValue(cluster.ClusterId),
ClusterType: tea.StringValue(cluster.ClusterType),
KubernetesVersion: tea.StringValue(cluster.CurrentVersion),
RegionID: tea.StringValue(cluster.RegionId),
VpcID: tea.StringValue(cluster.VpcId),
PauseClusterUpgrade: pauseClusterUpgrade,
ClusterIsUpgrading: clusterIsUpgrading,
}
Expand Down Expand Up @@ -541,7 +584,6 @@ func FixConfig(configSpec *ackv1.ACKClusterConfigSpec, clusterMap map[string]int
if configSpec.KubernetesVersion == "" {
configSpec.KubernetesVersion = utils.GetMapString("current_version", clusterMap)
}
configSpec.ZoneID = utils.GetMapString("zone_id", clusterMap)
configSpec.Name = utils.GetMapString("name", clusterMap)
configSpec.VswitchIds = strings.Split(utils.GetMapString("vswitch_id", clusterMap)+"", ",") // append empty string, avoid empty pointer value
configSpec.ResourceGroupID = utils.GetMapString("resource_group_id", clusterMap)
Expand Down Expand Up @@ -620,6 +662,9 @@ func FixClusterId(secretsCache wranglerv1.SecretCache, configSpec *ackv1.ACKClus
if err != nil {
return err
}
if clusters == nil || clusters.Clusters == nil {
return fmt.Errorf("fix cluster id error: Get the clusters is nil, indicating no cluster information is available")
}
if len(clusters.Clusters) == 1 {
if *clusters.Clusters[0].Name == configSpec.Name {
configSpec.ClusterID = *clusters.Clusters[0].ClusterId
Expand Down
1 change: 0 additions & 1 deletion examples/create-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ spec:
snatEntry: false
sshFlags: false
vpcId: "<cpcId>"
zoneId: "<zoneId>"
1 change: 0 additions & 1 deletion internal/ack/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func newClusterCreateRequest(configSpec *ackv1.ACKClusterConfigSpec) *ackapi.Cre
req.RegionId = tea.String(configSpec.RegionID)
req.KubernetesVersion = tea.String(configSpec.KubernetesVersion)
req.Vpcid = tea.String(configSpec.VpcID)
req.ZoneId = tea.String(configSpec.ZoneID)
req.ContainerCidr = tea.String(configSpec.ContainerCidr)
req.ServiceCidr = tea.String(configSpec.ServiceCidr)
req.NodeCidrMask = tea.String(strconv.Itoa(int(configSpec.NodeCidrMask)))
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/ack.pandaria.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type ACKClusterConfigSpec struct {
TimeoutMins int64 `json:"timeoutMins,omitempty" norman:"noupdate"`
RegionID string `json:"regionId,omitempty" norman:"noupdate"`
VpcID string `json:"vpcId,omitempty" norman:"noupdate"`
ZoneID string `json:"zoneId,omitempty" norman:"noupdate"`
ContainerCidr string `json:"containerCidr,omitempty" norman:"noupdate"`
ServiceCidr string `json:"serviceCidr,omitempty" norman:"noupdate"`
NodeCidrMask int64 `json:"nodeCidrMask,omitempty" norman:"noupdate"`
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/ack.pandaria.io/v1/zz_generated_deepcopy.go

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

5 changes: 5 additions & 0 deletions pkg/generated/controllers/ack.pandaria.io/factory.go

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

5 changes: 5 additions & 0 deletions pkg/generated/controllers/core/factory.go

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

0 comments on commit eb1d014

Please sign in to comment.