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 committed Aug 5, 2024
1 parent 3a1914d commit 119f527
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 @@ -159,17 +159,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 162 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 178 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 119f527

Please sign in to comment.