-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removing creationTimestamp under Template object #50
Removing creationTimestamp under Template object #50
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me but it looks like there is a room for improvements in the unit tests.
Will try to figure out if I spot the issue with unit test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from splitting the functions, if possible as a part of this PR we can also have a unit test to check these, they are currently not being tested, i am unsure of the reason for it
8636ee0
to
013d2c4
Compare
pkg/cmd/generate/util.go
Outdated
@@ -159,6 +159,7 @@ const header = `# -------------------------------------------------------------- | |||
func writeFile(filePath string, content []byte) error { | |||
// https://github.com/kubernetes/kubernetes/issues/67610 | |||
contentString := strings.ReplaceAll(string(content), "\n creationTimestamp: null", "") | |||
contentString = strings.ReplaceAll(contentString, "\n creationTimestamp: null", " {}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to set to empty object to fix issue with ArgoCD synch loop created by TierTemplates do to spec.template.matadata see the fix in infra deployment here: redhat-appstudio/infra-deployments#4120. The requirement is that all TierTemplates in source will start with empty object {} and then we need to remove the creationTimeStap set to null. If there is a better way to do this let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's fix this empty metadata as a separate PR as this won't work if the spec.template.metadata.name is set (for example in our e2e tests).
Let's focus on the empty creationTimestamp for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as for the empty metadata - this is tricky one. Not sure if there is a better (generic) way to deal with this problem, but re-marshalling the object (after removing empty creationTimestamp
field) and removing metadata: null
should work:
rawObject := runtime.RawExtension{}
err := yaml.Unmarshal([]byte(contentString), &rawObject)
if err != nil {
return err
}
rawContent, err := yaml.Marshal(rawObject)
if err != nil {
return err
}
emptyMetadata := regexp.MustCompile(`\n *metadata: null`)
contentString = emptyMetadata.ReplaceAllString(string(rawContent), "")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my new approach in utils.go, seems simpler to me
Working on fixing the testcases |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good,
just a minor suggestion
Either one of it can be used, whichever works
pkg/cmd/generate/util.go
Outdated
contentString := strings.ReplaceAll(string(content), "\n creationTimestamp: null", "") | ||
contentString = strings.ReplaceAll(contentString, "\n creationTimestamp: null", " {}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather make it more generic so it replaces any empty creationTimestamp no matter at which level
contentString := strings.ReplaceAll(string(content), "\n creationTimestamp: null", "") | |
contentString = strings.ReplaceAll(contentString, "\n creationTimestamp: null", " {}") | |
emptyCreationTimestamp := regexp.MustCompile(`\n *creationTimestamp: null`) | |
contentString := emptyCreationTimestamp.ReplaceAllString(string(content), "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took your suggestion here
as for unit-testing - let's either improve the util_test.go so it verifies objects at any level, or add this check: ksctl/pkg/cmd/generate/assertion_test.go Lines 169 to 171 in d758210
into ksctl/pkg/cmd/generate/assertion_test.go Lines 142 to 143 in d758210
because the assertObject function is not called in the nstemplatetiers_test.go but listObjects is, so it would be verified automatically.
|
d0e0da2
to
b59512e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments added, working on improving test to check all timestamps
pkg/cmd/generate/util.go
Outdated
@@ -158,8 +159,11 @@ const header = `# -------------------------------------------------------------- | |||
|
|||
func writeFile(filePath string, content []byte) error { | |||
// https://github.com/kubernetes/kubernetes/issues/67610 | |||
contentString := strings.ReplaceAll(string(content), "\n creationTimestamp: null", "") | |||
emptyCreationTimestamp := regexp.MustCompile(`\n *creationTimestamp: null`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works well as suggest by @MatousJobanek
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about declaring this as a top level var so that the regex doesn't have to be compiled with each invocation of this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that yeah
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
contentString = strings.ReplaceAll(contentString, "\nuser: {}", "") | ||
// This will only apply to konflux tier template that start with metadata = {} | ||
contentString = strings.ReplaceAll(contentString, "metadata:\n objects:", "metadata: {}\n objects:") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the metadata problem with Konflux as tiers in src already start with spec.template.metadata as {}. See here: https://github.com/redhat-appstudio/infra-deployments/blob/main/components/sandbox/tiers/src/appstudio/spacerole_admin.yaml#L3
But this won't affect our e2e nor unitest as those start with spec.template.metadata.name having a string value. Would this work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, this should work fine 👍 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another option would be removing the metadata field completely. But I'll leave it up to you ;-)
contentString = strings.ReplaceAll(contentString, "metadata:\n objects:", "metadata: {}\n objects:") | |
contentString = strings.ReplaceAll(contentString, "metadata:\n objects:", "objects:") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well tried that but ArgoCD expects metadata: {}. Will prefer to match exactly what ArgoCD expects there to avoid re-synching situation
pkg/cmd/generate/util.go
Outdated
@@ -159,6 +159,7 @@ const header = `# -------------------------------------------------------------- | |||
func writeFile(filePath string, content []byte) error { | |||
// https://github.com/kubernetes/kubernetes/issues/67610 | |||
contentString := strings.ReplaceAll(string(content), "\n creationTimestamp: null", "") | |||
contentString = strings.ReplaceAll(contentString, "\n creationTimestamp: null", " {}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my new approach in utils.go, seems simpler to me
pkg/cmd/generate/util.go
Outdated
contentString := strings.ReplaceAll(string(content), "\n creationTimestamp: null", "") | ||
contentString = strings.ReplaceAll(contentString, "\n creationTimestamp: null", " {}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took your suggestion here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks good overall, just waiting for the updates of the unit tests #50 (comment)
Signed-off-by: David Peraza <dperaza@redhat.com>
Also changed the replacement of creationTimestamp at any level with regex as suggested in reviews by @MatousJobanek Signed-off-by: David Peraza <dperaza@redhat.com>
Signed-off-by: David Peraza <dperaza@redhat.com>
f28d487
to
156189f
Compare
Got it |
Signed-off-by: David Peraza <dperaza@redhat.com>
added assertions to listObject method, thanks for suggestion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for addressing our comments
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #50 +/- ##
==========================================
+ Coverage 69.57% 69.59% +0.01%
==========================================
Files 43 43
Lines 2564 2565 +1
==========================================
+ Hits 1784 1785 +1
Misses 589 589
Partials 191 191
|
The creationTimestamp field not only pops up under TemplateTier metadata but also under template itself