Skip to content

Commit 5b080a9

Browse files
authored
Added command to retrieve Version in irictl (#1423)
1 parent be2d0bd commit 5b080a9

File tree

11 files changed

+312
-6
lines changed

11 files changed

+312
-6
lines changed

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ COPY utils/ utils/
2525

2626
ARG TARGETOS
2727
ARG TARGETARCH
28+
ARG LDFLAGS
2829

2930
RUN mkdir bin
3031

@@ -51,7 +52,7 @@ FROM builder AS machinebroker-builder
5152
# TODO: Remove irictl-machine once debug containers are more broadly available.
5253
RUN --mount=type=cache,target=/root/.cache/go-build \
5354
--mount=type=cache,target=/go/pkg \
54-
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/machinebroker ./broker/machinebroker/cmd/machinebroker/main.go && \
55+
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="${LDFLAGS}" -a -o bin/machinebroker ./broker/machinebroker/cmd/machinebroker/main.go && \
5556
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/irictl-machine ./irictl-machine/cmd/irictl-machine/main.go
5657

5758
FROM builder AS irictl-machine-builder
@@ -72,7 +73,7 @@ FROM builder AS volumebroker-builder
7273
# TODO: Remove irictl-volume once debug containers are more broadly available.
7374
RUN --mount=type=cache,target=/root/.cache/go-build \
7475
--mount=type=cache,target=/go/pkg \
75-
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/volumebroker ./broker/volumebroker/cmd/volumebroker/main.go && \
76+
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="${LDFLAGS}" -a -o bin/volumebroker ./broker/volumebroker/cmd/volumebroker/main.go && \
7677
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/irictl-volume ./irictl-volume/cmd/irictl-volume/main.go
7778

7879
FROM builder AS irictl-volume-builder
@@ -93,7 +94,7 @@ FROM builder AS bucketbroker-builder
9394
# TODO: Remove irictl-bucket once debug containers are more broadly available.
9495
RUN --mount=type=cache,target=/root/.cache/go-build \
9596
--mount=type=cache,target=/go/pkg \
96-
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/bucketbroker ./broker/bucketbroker/cmd/bucketbroker/main.go && \
97+
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="${LDFLAGS}" -a -o bin/bucketbroker ./broker/bucketbroker/cmd/bucketbroker/main.go && \
9798
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/irictl-bucket ./irictl-bucket/cmd/irictl-bucket/main.go
9899

99100
FROM builder AS irictl-bucket-builder

Makefile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ BUCKETPOOLLET_IMG ?= bucketpoollet:latest
1111
BUCKETBROKER_IMG ?= bucketbroker:latest
1212
IRICTL_BUCKET_IMG ?= irictl-bucket:latest
1313

14+
# LDFLAGS for the build targets
15+
LDFLAGS ?= -s -w
16+
VERSION=$(shell git describe --tags --abbrev=0)
17+
COMMIT=$(shell git log -n1 --format="%h")
18+
MACHINEBROKER_VERSION = github.com/ironcore-dev/ironcore/broker/machinebroker/version.Version
19+
MACHINEBROKER_COMMIT = github.com/ironcore-dev/ironcore/broker/machinebroker/version.Commit
20+
VOLUMEBROKER_VERSION = github.com/ironcore-dev/ironcore/broker/volumebroker/version.Version
21+
VOLUMEBROKER_COMMIT = github.com/ironcore-dev/ironcore/broker/volumebroker/version.Commit
22+
BUCKETBROKER_VERSION = github.com/ironcore-dev/ironcore/broker/bucketbroker/version.Version
23+
BUCKETBROKER_COMMIT = github.com/ironcore-dev/ironcore/broker/bucketbroker/version.Commit
24+
1425
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
1526
ENVTEST_K8S_VERSION = 1.34.0
1627

@@ -189,7 +200,7 @@ docker-build-machinepoollet: ## Build machinepoollet image.
189200

190201
.PHONY: docker-build-machinebroker
191202
docker-build-machinebroker: ## Build machinebroker image.
192-
docker build --target machinebroker -t ${MACHINEBROKER_IMG} .
203+
docker build --build-arg LDFLAGS="${LDFLAGS} -X $(MACHINEBROKER_VERSION)=$(VERSION) -X $(MACHINEBROKER_COMMIT)=$(COMMIT)" --target machinebroker -t ${MACHINEBROKER_IMG} .
193204

194205
.PHONY: docker-build-irictl-machine
195206
docker-build-irictl-machine: ## Build irictl-machine image.
@@ -201,15 +212,15 @@ docker-build-volumepoollet: ## Build volumepoollet image.
201212

202213
.PHONY: docker-build-volumebroker
203214
docker-build-volumebroker: ## Build volumebroker image.
204-
docker build --target volumebroker -t ${VOLUMEBROKER_IMG} .
215+
docker build --build-arg LDFLAGS="${LDFLAGS} -X $(VOLUMEBROKER_VERSION)=$(VERSION) -X $(VOLUMEBROKER_COMMIT)=$(COMMIT)" --target volumebroker -t ${VOLUMEBROKER_IMG} .
205216

206217
.PHONY: docker-build-irictl-volume
207218
docker-build-irictl-volume: ## Build irictl-volume image.
208219
docker build --target irictl-volume -t ${IRICTL_VOLUME_IMG} .
209220

210221
.PHONY: docker-build-bucketpoollet
211222
docker-build-bucketpoollet: ## Build bucketpoollet image.
212-
docker build --target bucketpoollet -t ${BUCKETPOOLLET_IMG} .
223+
docker build --build-arg LDFLAGS="${LDFLAGS} -X $(BUCKETBROKER_VERSION)=$(VERSION) -X $(BUCKETBROKER_COMMIT)=$(COMMIT)" --target bucketpoollet -t ${BUCKETPOOLLET_IMG} .
213224

214225
.PHONY: docker-build-bucketbroker
215226
docker-build-bucketbroker: ## Build bucketbroker image.

irictl-bucket/cmd/irictl-bucket/irictlbucket/get/get.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/ironcore-dev/ironcore/irictl-bucket/cmd/irictl-bucket/irictlbucket/get/bucket"
99
"github.com/ironcore-dev/ironcore/irictl-bucket/cmd/irictl-bucket/irictlbucket/get/bucketclass"
1010
"github.com/ironcore-dev/ironcore/irictl-bucket/cmd/irictl-bucket/irictlbucket/get/event"
11+
"github.com/ironcore-dev/ironcore/irictl-bucket/cmd/irictl-bucket/irictlbucket/get/version"
1112
irictlcmd "github.com/ironcore-dev/ironcore/irictl/cmd"
1213
"github.com/spf13/cobra"
1314
)
@@ -21,6 +22,7 @@ func Command(streams irictlcmd.Streams, clientFactory common.ClientFactory) *cob
2122
bucket.Command(streams, clientFactory),
2223
bucketclass.Command(streams, clientFactory),
2324
event.Command(streams, clientFactory),
25+
version.Command(streams, clientFactory),
2426
)
2527

2628
return cmd
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package version
5+
6+
import (
7+
"context"
8+
"fmt"
9+
10+
iri "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1"
11+
"github.com/ironcore-dev/ironcore/irictl-bucket/cmd/irictl-bucket/irictlbucket/common"
12+
irictlcmd "github.com/ironcore-dev/ironcore/irictl/cmd"
13+
"github.com/ironcore-dev/ironcore/irictl/renderer"
14+
"github.com/spf13/cobra"
15+
ctrl "sigs.k8s.io/controller-runtime"
16+
)
17+
18+
func Command(streams irictlcmd.Streams, clientFactory common.ClientFactory) *cobra.Command {
19+
var (
20+
outputOpts = common.NewOutputOptions()
21+
)
22+
23+
cmd := &cobra.Command{
24+
Use: "version",
25+
RunE: func(cmd *cobra.Command, args []string) error {
26+
ctx := cmd.Context()
27+
log := ctrl.LoggerFrom(ctx)
28+
29+
client, cleanup, err := clientFactory.New()
30+
if err != nil {
31+
return err
32+
}
33+
defer func() {
34+
if err := cleanup(); err != nil {
35+
log.Error(err, "Error cleaning up")
36+
}
37+
}()
38+
39+
render, err := outputOpts.Renderer("table")
40+
if err != nil {
41+
return err
42+
}
43+
44+
return Run(cmd.Context(), streams, client, render)
45+
},
46+
}
47+
48+
outputOpts.AddFlags(cmd.Flags())
49+
50+
return cmd
51+
}
52+
53+
func Run(ctx context.Context, streams irictlcmd.Streams, client iri.BucketRuntimeClient, render renderer.Renderer) error {
54+
res, err := client.Version(ctx, &iri.VersionRequest{})
55+
if err != nil {
56+
return fmt.Errorf("error getting version: %w", err)
57+
}
58+
59+
return render.Render(res, streams.Out)
60+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package tableconverters
5+
6+
import (
7+
iri "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1"
8+
"github.com/ironcore-dev/ironcore/irictl/api"
9+
"github.com/ironcore-dev/ironcore/irictl/tableconverter"
10+
)
11+
12+
var (
13+
versionsHeaders = []api.Header{
14+
{Name: "Name"},
15+
{Name: "Version"},
16+
}
17+
18+
VersionResponse = tableconverter.Funcs[*iri.VersionResponse]{
19+
Headers: tableconverter.Headers(versionsHeaders),
20+
Rows: tableconverter.SingleRowFrom(func(versionInfo *iri.VersionResponse) (api.Row, error) {
21+
return api.Row{
22+
versionInfo.RuntimeName,
23+
versionInfo.RuntimeVersion,
24+
}, nil
25+
}),
26+
}
27+
28+
VersionResponseSlice = tableconverter.SliceFuncs[*iri.VersionResponse](VersionResponse)
29+
)
30+
31+
func init() {
32+
RegistryBuilder.Register(
33+
tableconverter.ToTagAndTypedAny[*iri.VersionResponse](VersionResponse),
34+
tableconverter.ToTagAndTypedAny[[]*iri.VersionResponse](VersionResponseSlice),
35+
)
36+
}

irictl-machine/cmd/irictl-machine/irictlmachine/get/get.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/ironcore-dev/ironcore/irictl-machine/cmd/irictl-machine/irictlmachine/get/event"
99
"github.com/ironcore-dev/ironcore/irictl-machine/cmd/irictl-machine/irictlmachine/get/machine"
1010
"github.com/ironcore-dev/ironcore/irictl-machine/cmd/irictl-machine/irictlmachine/get/status"
11+
"github.com/ironcore-dev/ironcore/irictl-machine/cmd/irictl-machine/irictlmachine/get/version"
1112
clicommon "github.com/ironcore-dev/ironcore/irictl/cmd"
1213
"github.com/spf13/cobra"
1314
)
@@ -21,6 +22,7 @@ func Command(streams clicommon.Streams, clientFactory common.Factory) *cobra.Com
2122
machine.Command(streams, clientFactory),
2223
status.Command(streams, clientFactory),
2324
event.Command(streams, clientFactory),
25+
version.Command(streams, clientFactory),
2426
)
2527

2628
return cmd
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package version
5+
6+
import (
7+
"context"
8+
"fmt"
9+
10+
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
11+
"github.com/ironcore-dev/ironcore/irictl-machine/cmd/irictl-machine/irictlmachine/common"
12+
clicommon "github.com/ironcore-dev/ironcore/irictl/cmd"
13+
"github.com/ironcore-dev/ironcore/irictl/renderer"
14+
"github.com/spf13/cobra"
15+
ctrl "sigs.k8s.io/controller-runtime"
16+
)
17+
18+
func Command(streams clicommon.Streams, clientFactory common.Factory) *cobra.Command {
19+
var (
20+
outputOpts = clientFactory.OutputOptions()
21+
)
22+
23+
cmd := &cobra.Command{
24+
Use: "version",
25+
RunE: func(cmd *cobra.Command, args []string) error {
26+
ctx := cmd.Context()
27+
log := ctrl.LoggerFrom(ctx)
28+
29+
client, cleanup, err := clientFactory.Client()
30+
if err != nil {
31+
return err
32+
}
33+
defer func() {
34+
if err := cleanup(); err != nil {
35+
log.Error(err, "Error cleaning up")
36+
}
37+
}()
38+
39+
render, err := outputOpts.Renderer("table")
40+
if err != nil {
41+
return err
42+
}
43+
44+
return Run(cmd.Context(), streams, client, render)
45+
},
46+
}
47+
48+
outputOpts.AddFlags(cmd.Flags())
49+
50+
return cmd
51+
}
52+
53+
func Run(ctx context.Context, streams clicommon.Streams, client iri.MachineRuntimeClient, render renderer.Renderer) error {
54+
res, err := client.Version(ctx, &iri.VersionRequest{})
55+
if err != nil {
56+
return fmt.Errorf("error getting version: %w", err)
57+
}
58+
59+
return render.Render(res, streams.Out)
60+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package tableconverters
5+
6+
import (
7+
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
8+
"github.com/ironcore-dev/ironcore/irictl/api"
9+
"github.com/ironcore-dev/ironcore/irictl/tableconverter"
10+
)
11+
12+
var (
13+
versionsHeaders = []api.Header{
14+
{Name: "Name"},
15+
{Name: "Version"},
16+
}
17+
18+
VersionResponse = tableconverter.Funcs[*iri.VersionResponse]{
19+
Headers: tableconverter.Headers(versionsHeaders),
20+
Rows: tableconverter.SingleRowFrom(func(versionInfo *iri.VersionResponse) (api.Row, error) {
21+
return api.Row{
22+
versionInfo.RuntimeName,
23+
versionInfo.RuntimeVersion,
24+
}, nil
25+
}),
26+
}
27+
28+
VersionResponseSlice = tableconverter.SliceFuncs[*iri.VersionResponse](VersionResponse)
29+
)
30+
31+
func init() {
32+
RegistryBuilder.Register(
33+
tableconverter.ToTagAndTypedAny[*iri.VersionResponse](VersionResponse),
34+
tableconverter.ToTagAndTypedAny[[]*iri.VersionResponse](VersionResponseSlice),
35+
)
36+
}

irictl-volume/cmd/irictl-volume/irictlvolume/get/get.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/ironcore-dev/ironcore/irictl-volume/cmd/irictl-volume/irictlvolume/common"
88
"github.com/ironcore-dev/ironcore/irictl-volume/cmd/irictl-volume/irictlvolume/get/event"
99
"github.com/ironcore-dev/ironcore/irictl-volume/cmd/irictl-volume/irictlvolume/get/status"
10+
"github.com/ironcore-dev/ironcore/irictl-volume/cmd/irictl-volume/irictlvolume/get/version"
1011
"github.com/ironcore-dev/ironcore/irictl-volume/cmd/irictl-volume/irictlvolume/get/volume"
1112
"github.com/ironcore-dev/ironcore/irictl-volume/cmd/irictl-volume/irictlvolume/get/volumesnapshot"
1213
clicommon "github.com/ironcore-dev/ironcore/irictl/cmd"
@@ -23,6 +24,7 @@ func Command(streams clicommon.Streams, clientFactory common.ClientFactory) *cob
2324
status.Command(streams, clientFactory),
2425
event.Command(streams, clientFactory),
2526
volumesnapshot.Command(streams, clientFactory),
27+
version.Command(streams, clientFactory),
2628
)
2729

2830
return cmd
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package version
5+
6+
import (
7+
"context"
8+
"fmt"
9+
10+
iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1"
11+
"github.com/ironcore-dev/ironcore/irictl-volume/cmd/irictl-volume/irictlvolume/common"
12+
clicommon "github.com/ironcore-dev/ironcore/irictl/cmd"
13+
"github.com/ironcore-dev/ironcore/irictl/renderer"
14+
"github.com/spf13/cobra"
15+
ctrl "sigs.k8s.io/controller-runtime"
16+
)
17+
18+
func Command(streams clicommon.Streams, clientFactory common.ClientFactory) *cobra.Command {
19+
var (
20+
outputOpts = common.NewOutputOptions()
21+
)
22+
23+
cmd := &cobra.Command{
24+
Use: "version",
25+
RunE: func(cmd *cobra.Command, args []string) error {
26+
ctx := cmd.Context()
27+
log := ctrl.LoggerFrom(ctx)
28+
29+
client, cleanup, err := clientFactory.New()
30+
if err != nil {
31+
return err
32+
}
33+
defer func() {
34+
if err := cleanup(); err != nil {
35+
log.Error(err, "Error cleaning up")
36+
}
37+
}()
38+
39+
render, err := outputOpts.Renderer("table")
40+
if err != nil {
41+
return err
42+
}
43+
44+
return Run(cmd.Context(), streams, client, render)
45+
},
46+
}
47+
48+
outputOpts.AddFlags(cmd.Flags())
49+
50+
return cmd
51+
}
52+
53+
func Run(ctx context.Context, streams clicommon.Streams, client iri.VolumeRuntimeClient, render renderer.Renderer) error {
54+
res, err := client.Version(ctx, &iri.VersionRequest{})
55+
if err != nil {
56+
return fmt.Errorf("error getting version: %w", err)
57+
}
58+
59+
return render.Render(res, streams.Out)
60+
}

0 commit comments

Comments
 (0)