Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
Signed-off-by: Min Min <[email protected]>
  • Loading branch information
jamsman94 committed Nov 29, 2024
1 parent 122366e commit 8c29a26
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
48 changes: 38 additions & 10 deletions pkg/microservice/aslan/core/common/service/sae/sae.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,24 @@ func validateSAE(args *commonmodels.SAE) error {
return nil
}

type saeKV struct {
Name string `json:"name"`
Value string `json:"value"`
ValueFrom struct {
ConfigMapRef struct {
ConfigMapID int `json:"configMapId"`
Key string `json:"key"`
} `json:"configMapRef"`
} `json:"valueFrom"`
type SAEKV struct {
Name string `json:"name"`
Value string `json:"value,omitempty"`
ValueFrom *SAEValueFrom `json:"valueFrom,omitempty"`
}

type SAEValueFrom struct {
ConfigMapRef *SAEConfigMapRef `json:"configMapRef,omitempty"`
}

type SAEConfigMapRef struct {
ConfigMapID int `json:"configMapId"`
Key string `json:"key"`
}

// CreateKVMap takes a string and de-serialize it into a struct that we can use
func CreateKVMap(kv *string) (map[string]*commonmodels.SAEKV, error) {
envList := make([]*saeKV, 0)
envList := make([]*SAEKV, 0)
err := json.Unmarshal([]byte(tea.StringValue(kv)), &envList)
if err != nil {
return nil, err
Expand All @@ -144,3 +148,27 @@ func CreateKVMap(kv *string) (map[string]*commonmodels.SAEKV, error) {

return resp, nil
}

func ToSAEKVString(envs []*commonmodels.SAEKV) (*string, error) {
if len(envs) == 0 {
return nil, nil
}
resp := make([]*SAEKV, 0)
for _, kv := range envs {
resp = append(resp, &SAEKV{
Name: kv.Name,
Value: kv.Value,
ValueFrom: &SAEValueFrom{ConfigMapRef: &SAEConfigMapRef{
ConfigMapID: kv.ConfigMapID,
Key: kv.Key,
}},
})
}

envStr, err := json.Marshal(resp)
if err != nil {
return nil, err
}

return tea.String(string(envStr)), nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,7 @@ func (c *SAEDeployJobCtl) Run(ctx context.Context) {
return
}

lowerCamelEnvs, err := converter.ConvertToLowerCamelCase(c.jobTaskSpec)
if err != nil {
err = fmt.Errorf("failed to serialize sae envs, err: %s", err)
c.logger.Error(err)
c.job.Status = config.StatusFailed
c.job.Error = err.Error()
return
}

envBytes, err := json.Marshal(lowerCamelEnvs["envs"])
saeEnvs, err := saeservice.ToSAEKVString(c.jobTaskSpec.Envs)
if err != nil {
err = fmt.Errorf("failed to serialize sae envs, err: %s", err)
c.logger.Error(err)
Expand All @@ -123,11 +114,6 @@ func (c *SAEDeployJobCtl) Run(ctx context.Context) {
return
}

saeRequestEnvs := tea.String(string(envBytes))
if len(lowerCamelEnvs) == 0 {
saeRequestEnvs = nil
}

saeRequestUpdateStrategy := tea.String(string(updateStrategyBytes))
if len(lowerCamelUpdateStrategy) == 0 {
saeRequestUpdateStrategy = nil
Expand All @@ -136,7 +122,7 @@ func (c *SAEDeployJobCtl) Run(ctx context.Context) {
saeRequest := &sae.DeployApplicationRequest{
AppId: tea.String(c.jobTaskSpec.AppID),
BatchWaitTime: tea.Int32(c.jobTaskSpec.BatchWaitTime),
Envs: saeRequestEnvs,
Envs: saeEnvs,
ImageUrl: tea.String(c.jobTaskSpec.Image),
MinReadyInstanceRatio: tea.Int32(c.jobTaskSpec.MinReadyInstanceRatio),
MinReadyInstances: tea.Int32(c.jobTaskSpec.MinReadyInstances),
Expand Down

0 comments on commit 8c29a26

Please sign in to comment.