Skip to content

Commit

Permalink
[bugfix][codegen] Fix flipped arguments in time.Time getters. (#260)
Browse files Browse the repository at this point in the history
codegen: Fix flipped arguments in time.Time getters, resulting in a bug
where `GetUpdateTimestamp()` always returned a zero time in generated
`resource.Object` implementations (this also caused
`GetCommonMetadata().UpdateTimestamp` to be a zero time as well as that
function used `GetUpdateTimestamp()` to fetch the update timestamp).
  • Loading branch information
IfSentient authored Apr 18, 2024
1 parent 82bc17f commit a6c0324
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion codegen/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var (
return fmt.Sprintf("%s = %s.Format(time.RFC3339)", setToVarName, inputVarName)
},
GetFuncTemplate: func(varName string) string {
return fmt.Sprintf("parsed, _ := time.Parse(%s, time.RFC3339)\nreturn parsed", varName)
return fmt.Sprintf("parsed, _ := time.Parse(time.RFC3339, %s)\nreturn parsed", varName)
},
AdditionalImports: []string{"time"},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (o *CustomKind) GetUpdateTimestamp() time.Time {
o.ObjectMeta.Annotations = make(map[string]string)
}

parsed, _ := time.Parse(o.ObjectMeta.Annotations["grafana.com/updateTimestamp"], time.RFC3339)
parsed, _ := time.Parse(time.RFC3339, o.ObjectMeta.Annotations["grafana.com/updateTimestamp"])
return parsed
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func extractOtherMetadataField(annotations map[string]string) string {
}
func extractUpdateTimestamp(annotations map[string]string) time.Time {

parsed, _ := time.Parse(annotations["updateTimestamp"], time.RFC3339)
parsed, _ := time.Parse(time.RFC3339, annotations["updateTimestamp"])
return parsed
}
func extractUpdatedBy(annotations map[string]string) string {
Expand Down

0 comments on commit a6c0324

Please sign in to comment.