Skip to content

Commit

Permalink
fix parsing logic for tolerations field
Browse files Browse the repository at this point in the history
  • Loading branch information
PasinduDissMrYum authored and d-rk committed Aug 14, 2024
1 parent c95366d commit 6775b5e
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions internal/common-operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,29 @@ func CreateClientContext() (ClientContext, error) {
context.Kubernetes.Annotations = viper.GetStringMapString("contexts." + context.Name + ".kubernetes.annotations")
context.Kubernetes.NodeSelector = viper.GetStringMapString("contexts." + context.Name + ".kubernetes.nodeSelector")
context.Kubernetes.Affinity = viper.GetStringMap("contexts." + context.Name + ".kubernetes.affinity")

var tolerations []map[string]any
err := json.Unmarshal([]byte(viper.GetString("contexts."+context.Name+".kubernetes.tolerations")), &tolerations)
if err != nil {
return context, err
}
context.Kubernetes.Tolerations = tolerations


Check failure on line 181 in internal/common-operation.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gofmt`-ed with `-s` (gofmt)
t, err := convertJsonToListMap("tolerations", viper.GetString("contexts."+context.Name+".kubernetes.tolerations"))
context.Kubernetes.Tolerations = t
if err != nil {
return context, err
}
return context, nil
}

func convertJsonToListMap(fieldName string, jsonStr string) ([]map[string]any, error){
var listMap []map[string]any
if (jsonStr == "") {
return listMap, nil
}
err := json.Unmarshal([]byte(jsonStr), &listMap)
if err != nil {
fmt.Errorf("Error parsing %s field", fieldName)

Check failure on line 197 in internal/common-operation.go

View workflow job for this annotation

GitHub Actions / Lint

Error return value of `fmt.Errorf` is not checked (errcheck)
return listMap, err
}
return listMap, nil
}


func CreateClient(context *ClientContext) (sarama.Client, error) {
config, err := CreateClientConfig(context)
if err == nil {
Expand Down

0 comments on commit 6775b5e

Please sign in to comment.