From fb4622d23f70182f042a358fa1c0dd5a14fbd055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Cegie=C5=82ka?= Date: Tue, 14 May 2024 12:44:05 +0200 Subject: [PATCH] feat: PC-11814 budget adjustment support for sloctl (#56) ## Motivation Add support for new`BudgetAdjustment` kind. ## Release Notes New BudgetAdjustment kind which allows customers to schedule recurring future events that should be excluded from the Error Budget calculations in their SLOs. This PR introduces new commands such as `sloctl get budgetadjustment`, `sloctl delete budgetadjustment` --------- Co-authored-by: kubaceg Co-authored-by: Mateusz Hawrus --- internal/VERSION | 2 +- internal/delete.go | 1 + internal/get.go | 3 +- test/delete-by-name.bats | 4 +++ test/get.bats | 9 ++++-- .../delete-by-name/budgetadjustment.yaml | 14 ++++++++++ test/inputs/get/budgetadjustments.yaml | 28 +++++++++++++++++++ 7 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 test/inputs/delete-by-name/budgetadjustment.yaml create mode 100644 test/inputs/get/budgetadjustments.yaml diff --git a/internal/VERSION b/internal/VERSION index 6e8bf73..0ea3a94 100644 --- a/internal/VERSION +++ b/internal/VERSION @@ -1 +1 @@ -0.1.0 +0.2.0 diff --git a/internal/delete.go b/internal/delete.go index 9f6d147..ffc3995 100644 --- a/internal/delete.go +++ b/internal/delete.go @@ -69,6 +69,7 @@ func (r *RootCmd) NewDeleteCmd() *cobra.Command { {kind: manifest.KindRoleBinding}, {kind: manifest.KindService, aliases: []string{"svc", "svcs"}}, {kind: manifest.KindSLO}, + {kind: manifest.KindBudgetAdjustment}, } { if len(def.plural) == 0 { def.plural = def.kind.String() + "s" diff --git a/internal/get.go b/internal/get.go index 4d90392..83a4ea0 100644 --- a/internal/get.go +++ b/internal/get.go @@ -73,6 +73,7 @@ To get more details in output use one of the available flags.`, {Kind: manifest.KindService, Aliases: []string{"svc", "svcs"}}, {Kind: manifest.KindSLO}, {Kind: manifest.KindUserGroup}, + {Kind: manifest.KindBudgetAdjustment}, } { plural := subCmd.Kind.String() + "s" if len(subCmd.Plural) > 0 { @@ -369,7 +370,7 @@ func (g *GetCmd) getObjects(ctx context.Context, args []string, kind manifest.Ki } if len(objects) == 0 { switch kind { - case manifest.KindProject, manifest.KindUserGroup: + case manifest.KindProject, manifest.KindUserGroup, manifest.KindBudgetAdjustment: fmt.Printf("No resources found.\n") default: fmt.Printf("No resources found in '%s' project.\n", g.client.Config.Project) diff --git a/test/delete-by-name.bats b/test/delete-by-name.bats index a50dcbb..6203fe5 100644 --- a/test/delete-by-name.bats +++ b/test/delete-by-name.bats @@ -70,6 +70,10 @@ setup() { test_delete_by_name "Project" "${TEST_INPUTS}/project.yaml" } +@test "budget adjustment" { + test_delete_by_name "BudgetAdjustment" "${TEST_INPUTS}/budgetadjustment.yaml" +} + # Currently we cannot apply user groups and DataExport has very strict # org limits making it impossible to test with applied objects. # diff --git a/test/get.bats b/test/get.bats index d18f009..633da93 100644 --- a/test/get.bats +++ b/test/get.bats @@ -80,6 +80,11 @@ setup() { test_get "SLO" "$aliases" "${TEST_INPUTS}/slos.yaml" "$output" } +@test "budget adjustments" { + aliases="budgetadjustment budgetadjustments" + test_get "BudgetAdjustment" "$aliases" "${TEST_INPUTS}/budgetadjustments.yaml" "$output" +} + @test "agent" { aliases="agent agents" test_get "Agent" "$aliases" "${TEST_INPUTS}/agent.yaml" "$output" @@ -182,7 +187,7 @@ test_get() { continue fi - if [[ "$kind" == "Project" ]]; then + if [[ "$kind" == "Project" ]] || [[ "$kind" == "BudgetAdjustment" ]]; then # shellcheck disable=2046 run_sloctl get "$alias" $(yq -r .[].metadata.name "$input") verify_get_success "$output" "$(read_files "$input")" @@ -208,7 +213,7 @@ test_get() { done for alias in "${aliases[@]}"; do - if [[ "$kind" == "Project" ]] || [[ "$kind" == "UserGroup" ]]; then + if [[ "$kind" == "Project" ]] || [[ "$kind" == "UserGroup" ]] || [[ "$kind" == "BudgetAdjustment" ]]; then run_sloctl get "$alias" "fake-name-123-321" assert_success assert_output "No resources found." diff --git a/test/inputs/delete-by-name/budgetadjustment.yaml b/test/inputs/delete-by-name/budgetadjustment.yaml new file mode 100644 index 0000000..f66b179 --- /dev/null +++ b/test/inputs/delete-by-name/budgetadjustment.yaml @@ -0,0 +1,14 @@ +apiVersion: n9/v1alpha +kind: BudgetAdjustment +metadata: + name: newrelic + displayName: NewRelic budget adjustment +spec: + description: Example budget adjustment + firstEventStart: 2024-03-05T05:00:00Z + duration: 2h0m0s + rrule: FREQ=DAILY;INTERVAL=7 + filters: + slos: + - name: newrelic-rolling-timeslices-threshold + project: death-star diff --git a/test/inputs/get/budgetadjustments.yaml b/test/inputs/get/budgetadjustments.yaml new file mode 100644 index 0000000..1339775 --- /dev/null +++ b/test/inputs/get/budgetadjustments.yaml @@ -0,0 +1,28 @@ +- apiVersion: n9/v1alpha + kind: BudgetAdjustment + metadata: + name: tokyo-server + displayName: Tokyo server budget adjustment + spec: + description: Example budget adjustment + firstEventStart: 2024-02-05T05:00:00Z + duration: 1h0m0s + rrule: FREQ=WEEKLY;INTERVAL=1 + filters: + slos: + - name: tokyo-server-6-latency + project: death-star +- apiVersion: n9/v1alpha + kind: BudgetAdjustment + metadata: + name: newrelic + displayName: NewRelic budget adjustment + spec: + description: Example budget adjustment + firstEventStart: 2024-03-05T05:00:00Z + duration: 2h0m0s + rrule: FREQ=DAILY;INTERVAL=7 + filters: + slos: + - name: newrelic-rolling-timeslices-threshold + project: death-star