-
Notifications
You must be signed in to change notification settings - Fork 2
feat(bootstrap): update labels on existing GCP projects #246
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
Open
joka134
wants to merge
16
commits into
main
Choose a base branch
from
feat/update-gcp-project-labels
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
08f1166
feat(bootstrap): update labels on existing GCP projects
joka134 a222237
chore: cleanup
joka134 8d2ff8a
chore: cleanup
joka134 7302546
chore: debug workflow
joka134 fa6bb7c
test: update scenario
joka134 9c5348c
fix: tests
joka134 224f10d
Merge branch 'main' into feat/update-gcp-project-labels
joka134 f4450a3
Merge remote-tracking branch 'origin/main' into feat/update-gcp-proje…
joka134 410f230
feat: remove displayName from UpdateProject
joka134 4981cf4
chore(docs): Auto-update docs and licenses
joka134 2004cf9
chore: move calculateProjectExpiryLabel to new helper package to allo…
joka134 4c16fe9
chore(docs): Auto-update docs and licenses
joka134 24d2f32
chore: cleanup
joka134 c3b7bba
chore: cleanup
joka134 2a55fdf
Merge remote-tracking branch 'origin/main' into feat/update-gcp-proje…
joka134 06ab0d3
chore(docs): Auto-update docs and licenses
joka134 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright (c) Codesphere Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package gcp | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "time" | ||
| ) | ||
|
|
||
| // calculateProjectExpiryLabel takes a TTL string (e.g. "24h") and | ||
| // returns a formatted UTC timestamp string that is usable as a GCP project label for automatic deletion. | ||
| func calculateProjectExpiryLabel(projectTTLStr string) (string, error) { | ||
| projectTTL, err := time.ParseDuration(projectTTLStr) | ||
| if err != nil { | ||
| return "", fmt.Errorf("invalid project TTL format: %w", err) | ||
| } | ||
|
|
||
| // prepare label for gcp project deletion in custom UTC time format. | ||
| // GCP Labels are very limited. This is an easy way to add date and TZ info in one label. | ||
| gcpExpiryLabelLayout := "2006-01-02_15-04-05" | ||
| deleteProjectAfter := time.Now().UTC().Add(projectTTL).Format(gcpExpiryLabelLayout) | ||
| deleteProjectAfter = fmt.Sprintf("%s_utc", deleteProjectAfter) | ||
|
|
||
| return deleteProjectAfter, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Copyright (c) Codesphere Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package gcp | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| var _ = Describe("calculateProjectExpiryLabel", func() { | ||
| const customDateFormat string = "2006-01-02_15-04-05_utc" | ||
| const customDateFormatRegex string = `^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}_utc$` | ||
|
|
||
| type validTestCase struct { | ||
| inputTTL string | ||
| expectedDuration time.Duration | ||
| } | ||
|
|
||
| DescribeTable("calculating the expiry label from string durations", | ||
| func(tc validTestCase) { | ||
| label, err := calculateProjectExpiryLabel(tc.inputTTL) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(label).To(MatchRegexp(customDateFormatRegex)) | ||
|
|
||
| parsedTime, err := time.Parse(customDateFormat, label) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| expectedTime := time.Now().UTC().Add(tc.expectedDuration) | ||
|
|
||
| Expect(parsedTime).To(BeTemporally("~", expectedTime, 10*time.Second)) | ||
| }, | ||
|
|
||
| // Define test scenarios | ||
| Entry("1 Minute", validTestCase{ | ||
| inputTTL: "1m", | ||
| expectedDuration: 1 * time.Minute, | ||
| }), | ||
| Entry("1 hour", validTestCase{ | ||
| inputTTL: "1h", | ||
| expectedDuration: 1 * time.Hour, | ||
| }), | ||
| Entry("1 Day", validTestCase{ | ||
| inputTTL: "24h", | ||
| expectedDuration: 24 * time.Hour, | ||
| }), | ||
| ) | ||
|
|
||
| It("returns an error for invalid duration strings", func() { | ||
| label, err := calculateProjectExpiryLabel("1d") // 'd' is not a valid time unit in Go's duration parsing | ||
| Expect(err).To(HaveOccurred()) | ||
| Expect(err.Error()).To(ContainSubstring("invalid project TTL format")) | ||
| Expect(label).To(BeEmpty()) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.