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

feat: PC-11814 budget adjustment support for sloctl #56

Merged
merged 10 commits into from
May 14, 2024
2 changes: 1 addition & 1 deletion internal/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.2.0
1 change: 1 addition & 0 deletions internal/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion internal/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/delete-by-name.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
9 changes: 7 additions & 2 deletions test/get.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")"
Expand All @@ -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."
Expand Down
14 changes: 14 additions & 0 deletions test/inputs/delete-by-name/budgetadjustment.yaml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions test/inputs/get/budgetadjustments.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading