diff --git a/internal/get.go b/internal/get.go index 775cd50..1b77b9f 100644 --- a/internal/get.go +++ b/internal/get.go @@ -35,6 +35,7 @@ type GetCmd struct { fieldSeparator string recordSeparator string project string + service string allProjects bool out io.Writer } @@ -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}, @@ -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}, @@ -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 @@ -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 {