未验证 提交 1e45e0e0 编写于 作者: P Petrus 提交者: GitHub

fix share env func (#2978)

* fix share env func
Signed-off-by: NPatrick Zhao <zhaoyu@koderover.com>

* fix not display image names
Signed-off-by: NPatrick Zhao <zhaoyu@koderover.com>

* fix ai analysis not working in prod env
Signed-off-by: NPatrick Zhao <zhaoyu@koderover.com>

---------
Signed-off-by: NPatrick Zhao <zhaoyu@koderover.com>
上级 00aacca9
......@@ -184,7 +184,7 @@ func (Product) TableName() string {
}
// GetNamespace returns the default name of namespace created by zadig
func (p *Product) GetNamespace() string {
func (p *Product) GetDefaultNamespace() string {
return p.ProductName + "-env-" + p.EnvName
}
......
......@@ -369,7 +369,7 @@ func getProductEnvInfo(pipelineTask *taskmodels.Task, log *zap.SugaredLogger) (*
Name: product.ProductName,
EnvName: product.EnvName,
}); err != nil {
product.Namespace = product.GetNamespace()
product.Namespace = product.GetDefaultNamespace()
} else {
product.Namespace = productInfo.Namespace
}
......
......@@ -224,7 +224,7 @@ func GetProductEnvNamespace(envName, productName, namespace string) string {
})
if err != nil {
product = &commonmodels.Product{EnvName: envName, ProductName: productName}
return product.GetNamespace()
return product.GetDefaultNamespace()
}
return product.Namespace
}
......
......@@ -3925,7 +3925,7 @@ func EnvAnalysis(projectName, envName string, production *bool, triggerName stri
ctx,
config.HubServerAddress(), env.ClusterID,
llmClient,
filters, env.GetNamespace(),
filters, env.Namespace,
false, // noCache bool
true, // explain bool
10, // maxConcurrency int
......
......@@ -162,7 +162,7 @@ func (creator *HelmProductCreator) Create(user, requestID string, args *models.P
}
//判断namespace是否存在
namespace := args.GetNamespace()
namespace := args.GetDefaultNamespace()
if args.Namespace == "" {
args.Namespace = namespace
}
......@@ -352,7 +352,7 @@ func (creator *K8sYamlProductCreator) Create(user, requestID string, args *model
return fmt.Errorf("failed to new istio client: %s", err)
}
namespace := args.GetNamespace()
namespace := args.GetDefaultNamespace()
if args.Namespace == "" {
args.Namespace = namespace
}
......
......@@ -587,14 +587,6 @@ func queryPodsStatus(productInfo *commonmodels.Product, serviceTmpl *commonmodel
return resp
}
workloadImagesMap := make(map[string][]string)
for _, workload := range svcResp.Workloads {
workloadImagesMap[workload.Name] = workload.Images
}
if images, ok := workloadImagesMap[serviceTmpl.ServiceName]; ok {
resp.Images = images
}
resp.Ingress = svcResp.Ingress
resp.Workloads = svcResp.Workloads
if len(serviceTmpl.Containers) == 0 {
......@@ -616,6 +608,12 @@ func queryPodsStatus(productInfo *commonmodels.Product, serviceTmpl *commonmodel
}
if len(pods) == 0 && len(svcResp.CronJobs) == 0 {
imageSet := sets.String{}
for _, workload := range svcResp.Workloads {
imageSet.Insert(workload.Images...)
}
resp.Images = imageSet.List()
resp.PodStatus, resp.Ready = setting.PodNonStarted, setting.PodNotReady
return resp
}
......
......@@ -17,14 +17,13 @@ limitations under the License.
package service
import (
"bytes"
"context"
"encoding/json"
"fmt"
"time"
"github.com/gogo/protobuf/jsonpb"
types "github.com/golang/protobuf/ptypes/struct"
"google.golang.org/protobuf/encoding/protojson"
networkingv1alpha3 "istio.io/api/networking/v1alpha3"
versionedclient "istio.io/client-go/pkg/clientset/versioned"
appsv1 "k8s.io/api/apps/v1"
......@@ -797,9 +796,8 @@ func buildEnvoyPatchValue(data map[string]interface{}) (*types.Struct, error) {
return nil, fmt.Errorf("failed to marshal data: %s", err)
}
reader := bytes.NewReader(dataBytes)
val := &types.Struct{}
err = jsonpb.Unmarshal(reader, val)
err = protojson.Unmarshal(dataBytes, val)
return val, err
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册