Skip to content

Commit

Permalink
PC-14244 Add filtering SLOs by service flag
Browse files Browse the repository at this point in the history
  • Loading branch information
BSski committed Dec 20, 2024
1 parent 0462888 commit 1340d8a
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions internal/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type GetCmd struct {
fieldSeparator string
recordSeparator string
project string
service string
allProjects bool
out io.Writer
}
Expand Down Expand Up @@ -63,11 +64,10 @@ To get more details in output use one of the available flags.`,

// All subcommands for get.
for _, subCmd := range []struct {
Kind manifest.Kind
Aliases []string
Plural string
Extender func(cmd *cobra.Command) *cobra.Command
IsProjectScoped bool
Kind manifest.Kind
Aliases []string
Plural string
Extender func(cmd *cobra.Command) *cobra.Command
}{
{Kind: manifest.KindAgent, Aliases: []string{"agent", "Agents", "Agent"}, Extender: get.newGetAgentCommand},
{Kind: manifest.KindAlertMethod},
Expand All @@ -80,7 +80,7 @@ To get more details in output use one of the available flags.`,
{Kind: manifest.KindProject},
{Kind: manifest.KindRoleBinding},
{Kind: manifest.KindService, Aliases: []string{"svc", "svcs"}},
{Kind: manifest.KindSLO},
{Kind: manifest.KindSLO, Extender: get.newGetSLOCommand},
{Kind: manifest.KindUserGroup},
{Kind: manifest.KindBudgetAdjustment},
{Kind: manifest.KindReport},
Expand Down Expand Up @@ -327,6 +327,25 @@ func (g *GetCmd) newGetAgentCommand(cmd *cobra.Command) *cobra.Command {
return cmd
}

func (g *GetCmd) newGetSLOCommand(cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringVarP(&g.service, "service", "s", "", "Filter SLOs by service")

cmd.RunE = func(cmd *cobra.Command, args []string) error {
objects, err := g.getObjects(cmd.Context(), args, manifest.KindSLO)
if err != nil {
return err
}
if objects == nil {
return nil
}
if err = g.printObjects(objects); err != nil {
return err
}
return nil
}
return cmd
}

func (g *GetCmd) getAgentsWithSecrets(ctx context.Context, objects []manifest.Object) ([]v1alpha.GenericObject, error) {
agents := make([]v1alpha.GenericObject, 0, len(objects))
var mu sync.Mutex
Expand Down Expand Up @@ -379,6 +398,9 @@ func (g *GetCmd) getObjects(ctx context.Context, args []string, kind manifest.Ki
if len(g.labels) > 0 {
query.Set(objectsV1.QueryKeyLabels, parseFilterLabel(g.labels))
}
if g.service != "" && kind == manifest.KindSLO {
query.Set(objectsV1.QueryKeyServiceName, g.service)
}
header := http.Header{sdk.HeaderProject: []string{g.client.Config.Project}}
objects, err := g.client.Objects().V1().Get(ctx, kind, header, query)
if err != nil {
Expand Down

0 comments on commit 1340d8a

Please sign in to comment.