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

Implement additional orictl-machine columns #729

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ COPY cmd/ cmd/
COPY internal/ internal/
COPY ori/ ori/
COPY orictl/ orictl/
COPY orictl-bucket/ orictl-bucket/
COPY orictl-machine/ orictl-machine/
COPY orictl-volume/ orictl-volume/
COPY poollet/ poollet/
COPY utils/ utils/

Expand Down Expand Up @@ -49,13 +52,13 @@ FROM builder as machinebroker-builder
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/machinebroker ./broker/machinebroker/cmd/machinebroker/main.go && \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-machine ./orictl/cmd/orictl-machine/main.go
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-machine ./orictl-machine/cmd/orictl-machine/main.go

FROM builder as orictl-machine-builder

RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-machine ./orictl/cmd/orictl-machine/main.go
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-machine ./orictl-machine/cmd/orictl-machine/main.go

FROM builder as volumepoollet-builder

Expand All @@ -70,13 +73,13 @@ FROM builder as volumebroker-builder
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/volumebroker ./broker/volumebroker/cmd/volumebroker/main.go && \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-volume ./orictl/cmd/orictl-volume/main.go
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-volume ./orictl-volume/cmd/orictl-volume/main.go

FROM builder as orictl-volume-builder

RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-volume ./orictl/cmd/orictl-volume/main.go
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-volume ./orictl-volume/cmd/orictl-volume/main.go

FROM builder as bucketpoollet-builder

Expand All @@ -91,13 +94,13 @@ FROM builder as bucketbroker-builder
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/bucketbroker ./broker/bucketbroker/cmd/bucketbroker/main.go && \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-bucket ./orictl/cmd/orictl-bucket/main.go
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-bucket ./orictl-bucket/cmd/orictl-bucket/main.go

FROM builder as orictl-bucket-builder

RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-bucket ./orictl/cmd/orictl-bucket/main.go
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/orictl-bucket ./orictl-bucket/cmd/orictl-bucket/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ package main
import (
"os"

clicommon "github.com/onmetal/onmetal-api/orictl/cli/common"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket"
"github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket"
orictlcmd "github.com/onmetal/onmetal-api/orictl/cmd"
ctrl "sigs.k8s.io/controller-runtime"
)

func main() {
ctx := ctrl.SetupSignalHandler()
if err := orictlbucket.Command(clicommon.OSStreams).ExecuteContext(ctx); err != nil {
if err := orictlbucket.Command(orictlcmd.OSStreams).ExecuteContext(ctx); err != nil {
ctrl.Log.Error(err, "Error running command")
os.Exit(1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (

ori "github.com/onmetal/onmetal-api/ori/apis/bucket/v1alpha1"
oriremotebucket "github.com/onmetal/onmetal-api/ori/remote/bucket"
clicommon "github.com/onmetal/onmetal-api/orictl/cli/common"
"github.com/onmetal/onmetal-api/orictl-bucket/renderers"
orictlcmd "github.com/onmetal/onmetal-api/orictl/cmd"
"github.com/onmetal/onmetal-api/orictl/renderer"
"github.com/onmetal/onmetal-api/orictl/renderers/bucket"
"github.com/spf13/pflag"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
Expand All @@ -31,7 +31,7 @@ import (
var Renderer = renderer.NewRegistry()

func init() {
if err := bucket.AddToRegistry(Renderer); err != nil {
if err := renderers.AddToRegistry(Renderer); err != nil {
panic(err)
}
}
Expand Down Expand Up @@ -62,8 +62,8 @@ func (o *ClientOptions) New() (ori.BucketRuntimeClient, func() error, error) {
return ori.NewBucketRuntimeClient(conn), conn.Close, nil
}

func NewOutputOptions() *clicommon.OutputOptions {
return &clicommon.OutputOptions{
func NewOutputOptions() *orictlcmd.OutputOptions {
return &orictlcmd.OutputOptions{
Registry: Renderer,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"os"

ori "github.com/onmetal/onmetal-api/ori/apis/bucket/v1alpha1"
clicommon "github.com/onmetal/onmetal-api/orictl/cli/common"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket/common"
"github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket/common"
orictlcmd "github.com/onmetal/onmetal-api/orictl/cmd"
"github.com/onmetal/onmetal-api/orictl/decoder"
"github.com/onmetal/onmetal-api/orictl/renderer"
"github.com/spf13/cobra"
Expand All @@ -37,7 +37,7 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
fs.StringVarP(&o.Filename, "filename", "f", o.Filename, "Path to a file to read.")
}

func Command(streams clicommon.Streams, clientFactory common.ClientFactory) *cobra.Command {
func Command(streams orictlcmd.Streams, clientFactory common.ClientFactory) *cobra.Command {
var (
outputOpts = common.NewOutputOptions()
opts Options
Expand Down Expand Up @@ -75,8 +75,8 @@ func Command(streams clicommon.Streams, clientFactory common.ClientFactory) *cob
return cmd
}

func Run(ctx context.Context, streams clicommon.Streams, client ori.BucketRuntimeClient, r renderer.Renderer, opts Options) error {
data, err := clicommon.ReadFileOrReader(opts.Filename, os.Stdin)
func Run(ctx context.Context, streams orictlcmd.Streams, client ori.BucketRuntimeClient, r renderer.Renderer, opts Options) error {
data, err := orictlcmd.ReadFileOrReader(opts.Filename, os.Stdin)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
package create

import (
clicommon "github.com/onmetal/onmetal-api/orictl/cli/common"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket/common"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket/create/bucket"
"github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket/common"
"github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket/create/bucket"
orictlcmd "github.com/onmetal/onmetal-api/orictl/cmd"
"github.com/spf13/cobra"
)

func Command(streams clicommon.Streams, clientFactory common.ClientFactory) *cobra.Command {
func Command(streams orictlcmd.Streams, clientFactory common.ClientFactory) *cobra.Command {
cmd := &cobra.Command{
Use: "create",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import (
"fmt"

ori "github.com/onmetal/onmetal-api/ori/apis/bucket/v1alpha1"
clicommon "github.com/onmetal/onmetal-api/orictl/cli/common"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket/common"
"github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket/common"
orictlcmd "github.com/onmetal/onmetal-api/orictl/cmd"
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
ctrl "sigs.k8s.io/controller-runtime"
)

func Command(streams clicommon.Streams, clientFactory common.ClientFactory) *cobra.Command {
func Command(streams orictlcmd.Streams, clientFactory common.ClientFactory) *cobra.Command {
cmd := &cobra.Command{
Use: "bucket id [ids...]",
Aliases: common.BucketAliases,
Expand Down Expand Up @@ -55,7 +55,7 @@ func Command(streams clicommon.Streams, clientFactory common.ClientFactory) *cob
return cmd
}

func Run(ctx context.Context, streams clicommon.Streams, client ori.BucketRuntimeClient, ids []string) error {
func Run(ctx context.Context, streams orictlcmd.Streams, client ori.BucketRuntimeClient, ids []string) error {
for _, id := range ids {
if _, err := client.DeleteBucket(ctx, &ori.DeleteBucketRequest{
BucketId: id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
package delete

import (
clicommon "github.com/onmetal/onmetal-api/orictl/cli/common"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket/common"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket/delete/bucket"
"github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket/common"
"github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket/delete/bucket"
orictlcmd "github.com/onmetal/onmetal-api/orictl/cmd"
"github.com/spf13/cobra"
)

func Command(streams clicommon.Streams, clientFactory common.ClientFactory) *cobra.Command {
func Command(streams orictlcmd.Streams, clientFactory common.ClientFactory) *cobra.Command {
cmd := &cobra.Command{
Use: "delete",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"fmt"

ori "github.com/onmetal/onmetal-api/ori/apis/bucket/v1alpha1"
clicommon "github.com/onmetal/onmetal-api/orictl/cli/common"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket/common"
"github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket/common"
orictlcmd "github.com/onmetal/onmetal-api/orictl/cmd"
"github.com/onmetal/onmetal-api/orictl/renderer"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand All @@ -33,7 +33,7 @@ type Options struct {
func (o *Options) AddFlags(fs *pflag.FlagSet) {
}

func Command(streams clicommon.Streams, clientFactory common.ClientFactory) *cobra.Command {
func Command(streams orictlcmd.Streams, clientFactory common.ClientFactory) *cobra.Command {
var (
opts Options
outputOpts = common.NewOutputOptions()
Expand Down Expand Up @@ -71,7 +71,7 @@ func Command(streams clicommon.Streams, clientFactory common.ClientFactory) *cob
return cmd
}

func Run(ctx context.Context, streams clicommon.Streams, client ori.BucketRuntimeClient, render renderer.Renderer, opts Options) error {
func Run(ctx context.Context, streams orictlcmd.Streams, client ori.BucketRuntimeClient, render renderer.Renderer, opts Options) error {
res, err := client.ListBuckets(ctx, &ori.ListBucketsRequest{})
if err != nil {
return fmt.Errorf("error listing buckets: %w", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (
"fmt"

ori "github.com/onmetal/onmetal-api/ori/apis/bucket/v1alpha1"
clicommon "github.com/onmetal/onmetal-api/orictl/cli/common"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket/common"
"github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket/common"
orictlcmd "github.com/onmetal/onmetal-api/orictl/cmd"
"github.com/onmetal/onmetal-api/orictl/renderer"
"github.com/spf13/cobra"
ctrl "sigs.k8s.io/controller-runtime"
)

func Command(streams clicommon.Streams, clientFactory common.ClientFactory) *cobra.Command {
func Command(streams orictlcmd.Streams, clientFactory common.ClientFactory) *cobra.Command {
var (
outputOpts = common.NewOutputOptions()
)
Expand Down Expand Up @@ -62,7 +62,7 @@ func Command(streams clicommon.Streams, clientFactory common.ClientFactory) *cob
return cmd
}

func Run(ctx context.Context, streams clicommon.Streams, client ori.BucketRuntimeClient, render renderer.Renderer) error {
func Run(ctx context.Context, streams orictlcmd.Streams, client ori.BucketRuntimeClient, render renderer.Renderer) error {
res, err := client.ListBucketClasses(ctx, &ori.ListBucketClassesRequest{})
if err != nil {
return fmt.Errorf("error listing bucket classes: %w", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
package get

import (
clicommon "github.com/onmetal/onmetal-api/orictl/cli/common"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket/common"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket/get/bucket"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket/get/bucketclass"
"github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket/common"
"github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket/get/bucket"
"github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket/get/bucketclass"
orictlcmd "github.com/onmetal/onmetal-api/orictl/cmd"
"github.com/spf13/cobra"
)

func Command(streams clicommon.Streams, clientFactory common.ClientFactory) *cobra.Command {
func Command(streams orictlcmd.Streams, clientFactory common.ClientFactory) *cobra.Command {
cmd := &cobra.Command{
Use: "get",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ package orictlbucket
import (
goflag "flag"

clicommon "github.com/onmetal/onmetal-api/orictl/cli/common"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket/common"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket/create"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket/delete"
"github.com/onmetal/onmetal-api/orictl/cmd/orictl-bucket/orictlbucket/get"
"github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket/common"
"github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket/create"
delete2 "github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket/delete"
"github.com/onmetal/onmetal-api/orictl-bucket/cmd/orictl-bucket/orictlbucket/get"
orictlcmd "github.com/onmetal/onmetal-api/orictl/cmd"
"github.com/spf13/cobra"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

func Command(streams clicommon.Streams) *cobra.Command {
func Command(streams orictlcmd.Streams) *cobra.Command {
var (
zapOpts zap.Options
clientOpts common.ClientOptions
Expand All @@ -50,7 +50,7 @@ func Command(streams clicommon.Streams) *cobra.Command {

cmd.AddCommand(
get.Command(streams, &clientOpts),
delete.Command(streams, &clientOpts),
delete2.Command(streams, &clientOpts),
create.Command(streams, &clientOpts),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package bucket
package renderers

import (
"github.com/onmetal/onmetal-api/orictl-bucket/tableconverters"
"github.com/onmetal/onmetal-api/orictl/renderer"
"github.com/onmetal/onmetal-api/orictl/table/tableconverter"
"github.com/onmetal/onmetal-api/orictl/table/tableconverters/bucket"
"github.com/onmetal/onmetal-api/orictl/tableconverter"
)

var (
Expand All @@ -29,7 +29,7 @@ func init() {
RegistryBuilder.Add(renderer.AddToRegistry)
RegistryBuilder.Add(func(registry *renderer.Registry) error {
tableConverter := tableconverter.NewRegistry()
if err := bucket.AddToRegistry(tableConverter); err != nil {
if err := tableconverters.AddToRegistry(tableConverter); err != nil {
return err
}
return registry.Register("table", renderer.NewTable(tableConverter))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,44 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package bucket
package tableconverters

import (
"time"

ori "github.com/onmetal/onmetal-api/ori/apis/bucket/v1alpha1"
"github.com/onmetal/onmetal-api/orictl/table"
"github.com/onmetal/onmetal-api/orictl/table/tableconverter"
"github.com/onmetal/onmetal-api/orictl/api"
"github.com/onmetal/onmetal-api/orictl/tableconverter"
"k8s.io/apimachinery/pkg/util/duration"
)

var (
bucketHeaders = []table.Header{
bucketHeaders = []api.Header{
{Name: "ID"},
{Name: "Class"},
{Name: "State"},
{Name: "Age"},
}
)

var Bucket, BucketSlice = tableconverter.ForType[*ori.Bucket]( //nolint:revive
func() ([]table.Header, error) {
return bucketHeaders, nil
},
func(bucket *ori.Bucket) ([]table.Row, error) {
return []table.Row{
{
var (
Bucket = tableconverter.Funcs[*ori.Bucket]{
Headers: tableconverter.Headers(bucketHeaders),
Rows: tableconverter.SingleRowFrom(func(bucket *ori.Bucket) (api.Row, error) {
return api.Row{
bucket.Metadata.Id,
bucket.Spec.Class,
bucket.Status.State.String(),
duration.HumanDuration(time.Since(time.Unix(0, bucket.Metadata.CreatedAt))),
},
}, nil
},
}, nil
}),
}
BucketSlice = tableconverter.SliceFuncs[*ori.Bucket](Bucket)
)

func init() {
RegistryBuilder.Register(
tableconverter.ToTaggedAny(Bucket),
tableconverter.ToTaggedAny(BucketSlice),
tableconverter.ToTagAndTypedAny[*ori.Bucket](Bucket),
tableconverter.ToTagAndTypedAny[[]*ori.Bucket](BucketSlice),
)
}
Loading