Skip to content
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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/cmd/generate/assertion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ func (a *kStructureAssertion) listObjects(dirName, kind string, object runtimecl
obj := object.DeepCopyObject()
objFile, err := os.ReadFile(path)
require.NoError(a.t, err)
assert.True(a.t, strings.HasPrefix(string(objFile), header), "every file generated by cli should container a header")
assert.NotContains(a.t, string(objFile), "creationTimestamp")
assert.NotContains(a.t, string(objFile), "user: {}")
err = yaml.Unmarshal(objFile, obj)
require.NoError(a.t, err)
if obj.GetObjectKind().GroupVersionKind().Kind == kind {
Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/generate/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"reflect"
"regexp"
"sort"
"strings"

Expand All @@ -19,6 +20,8 @@ import (
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)

var emptyCreationTimestamp = regexp.MustCompile(`\n *creationTimestamp: null`)

type objectsCache map[string]runtimeclient.Object

func (c objectsCache) storeObject(ctx *clusterContext, obj runtimeclient.Object) error {
Expand Down Expand Up @@ -162,8 +165,10 @@ 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 := emptyCreationTimestamp.ReplaceAllString(string(content), "")
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:")
Copy link
Contributor Author

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?

Copy link
Contributor

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 👍 🚀

Copy link
Contributor

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 ;-)

Suggested change
contentString = strings.ReplaceAll(contentString, "metadata:\n objects:", "metadata: {}\n objects:")
contentString = strings.ReplaceAll(contentString, "metadata:\n objects:", "objects:")

Copy link
Contributor Author

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

contentString = fmt.Sprintf("%s%s", header, contentString)
return os.WriteFile(filePath, []byte(contentString), 0600)
}
Expand Down
Loading