创建集群分发策略实例bug修复

This commit is contained in:
zw 2022-11-26 15:33:57 +08:00
parent 4717a3fe11
commit 418dfc979f
3 changed files with 18 additions and 22 deletions

View File

@ -143,8 +143,8 @@ func CreateDeployment(c *gin.Context) {
Namespace: param.Deployment.Namespace,
Kind: "Deployment",
})
if err != nil {
Response(c, http.StatusInternalServerError, "create deployment failed", policyErr)
if policyErr != nil {
Response(c, http.StatusInternalServerError, "create deployment policy failed", policyErr)
return
}
} else {

View File

@ -145,12 +145,6 @@ func CreateNamespace(c *gin.Context) {
}
// 判断是karmada分发还是指定集群创建
if param.Namespace.Labels != nil && param.Namespace.Labels["jcce"] == "true" {
sqlStr1 := "INSERT INTO joint_domain.namespace (namespace_name, alias, `describe`) VALUES(?,?,?)"
_, err := DB.Exec(sqlStr1, param.Namespace.Name, param.Namespace.Annotations["jcce/alias-name"], param.Namespace.Annotations["jcce/description"])
if err != nil {
Response(c, http.StatusBadRequest, "insert db failed!", err)
return
}
_, createErr := ClientSet.CoreV1().Namespaces().Create(context.TODO(), &param.Namespace, metav1.CreateOptions{})
if createErr != nil {
Response(c, http.StatusInternalServerError, "failed", createErr)
@ -165,7 +159,7 @@ func CreateNamespace(c *gin.Context) {
Kind: "Namespace",
})
if policyErr != nil {
Response(c, http.StatusInternalServerError, "failed", createErr)
Response(c, http.StatusInternalServerError, "failed", policyErr)
return
}
} else {

View File

@ -32,13 +32,15 @@ func CreatePropagationPolicies(propagationPolicy PropagationPolicy) error {
var pp PropagationPolicy
//获取模板数据
sqlPolicyTemplate := "select template_id,template_name,labels,schedule_type,division_preference,cluster_preference from propagation_policy_template where template_id = ?"
err := DB.QueryRow(sqlPolicyTemplate, propagationPolicy.TemplateId).Scan(&pp.TemplateId, &pp.TemplateName, &pp.LabelString, &pp.ReplicaSchedulingType, &pp.ReplicaDivisionPreference, &pp.ClusterPreference)
if err != nil {
return err
queryErr := DB.QueryRow(sqlPolicyTemplate, propagationPolicy.TemplateId).Scan(&pp.TemplateId, &pp.TemplateName, &pp.LabelString, &pp.ReplicaSchedulingType, &pp.ReplicaDivisionPreference, &pp.ClusterPreference)
if queryErr != nil {
return queryErr
}
labelsJson, err := simplejson.NewJson([]byte(*pp.LabelString))
if err != nil {
return err
}
labelsMapInterface, _ := labelsJson.Map()
labelsMap := make(map[string]string, len(labelsMapInterface))
for k, v := range labelsMapInterface {
@ -89,9 +91,9 @@ func CreatePropagationPolicies(propagationPolicy PropagationPolicy) error {
},
},
}
_, err := KarmadaClient.PolicyV1alpha1().ClusterPropagationPolicies().Create(context.TODO(), policy, v1.CreateOptions{})
if err != nil {
return err
_, clusterPolicyErr := KarmadaClient.PolicyV1alpha1().ClusterPropagationPolicies().Create(context.TODO(), policy, v1.CreateOptions{})
if clusterPolicyErr != nil {
return clusterPolicyErr
}
} else {
policy := &policyv1alpha1.PropagationPolicy{
@ -125,16 +127,16 @@ func CreatePropagationPolicies(propagationPolicy PropagationPolicy) error {
case "Deployment", "StatefulSet", "DaemonSet":
policy.Spec.ResourceSelectors[0].APIVersion = "apps/v1"
}
_, err := KarmadaClient.PolicyV1alpha1().PropagationPolicies(propagationPolicy.Namespace).Create(context.TODO(), policy, v1.CreateOptions{})
_, policyErr := KarmadaClient.PolicyV1alpha1().PropagationPolicies(propagationPolicy.Namespace).Create(context.TODO(), policy, v1.CreateOptions{})
if policyErr != nil {
return policyErr
}
//数据库记录policy实例
_, err = DB.Exec(`INSERT INTO joint_domain.propagation_policy(template_id, policy_name, namespace, resource_name) VALUES(?,?,?,?)`, propagationPolicy.TemplateId, propagationPolicy.Name, propagationPolicy.Namespace, propagationPolicy.ResourceName)
if err != nil {
return err
}
}
//数据库记录policy实例
_, err = DB.Exec(`INSERT INTO joint_domain.propagation_policy(template_id, policy_name, namespace, resource_name) VALUES(?,?,?,?)`, propagationPolicy.TemplateId, propagationPolicy.Name, propagationPolicy.Namespace, propagationPolicy.ResourceName)
if err != nil {
return err
}
return err
}