Skip to content

Commit

Permalink
Add version command. (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbobrovskyi authored Jan 8, 2025
1 parent 4e82244 commit 1ad656a
Show file tree
Hide file tree
Showing 7 changed files with 381 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ KIND_CLUSTER_NAME ?= kind
E2E_KIND_VERSION ?= kindest/node:v1.31.0
K8S_VERSION = $(E2E_KIND_VERSION:kindest/node:v%=%)

GIT_TAG ?= $(shell git describe --tags --dirty --always)
VERSION_PKG = sigs.k8s.io/kjob/pkg/version
LD_FLAGS += -X '$(VERSION_PKG).GitVersion=$(GIT_TAG)'

##@ General

# The help target prints out all targets with their descriptions organized
Expand Down
1 change: 1 addition & 0 deletions docs/commands/kjobctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,5 @@ ML/AI/Batch Jobs Made Easy
* [kjobctl describe](kjobctl_describe/_index.md) - Show details of a specific resource or group of resources.
* [kjobctl list](kjobctl_list/_index.md) - Display resources
* [kjobctl printcrds](kjobctl_printcrds/_index.md) - Print the kjobctl CRDs
* [kjobctl version](kjobctl_version/_index.md) - Prints the client version

227 changes: 227 additions & 0 deletions docs/commands/kjobctl_version/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
<!--
The file is auto-generated from the Go source code of the component using the
[generator](https://github.com/kubernetes-sigs/kueue/tree/main/cmd/experimental/kjobctl/cmd/kjobctl-docs).
-->

# kjobctl version


## Synopsis


Prints the client version

```
kjobctl version
```


## Examples

```
# Prints the client version
kjobctl version
```


## Options


<table style="width: 100%; table-layout: fixed;">
<colgroup>
<col span="1" style="width: 10px;" />
<col span="1" />
</colgroup>
<tbody>
<tr>
<td colspan="2">-h, --help</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>help for version</p>
</td>
</tr>
</tbody>
</table>



## Options inherited from parent commands
<table style="width: 100%; table-layout: fixed;">
<colgroup>
<col span="1" style="width: 10px;" />
<col span="1" />
</colgroup>
<tbody>
<tr>
<td colspan="2">--as string</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>Username to impersonate for the operation. User could be a regular user or a service account in a namespace.</p>
</td>
</tr>
<tr>
<td colspan="2">--as-group strings</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>Group to impersonate for the operation, this flag can be repeated to specify multiple groups.</p>
</td>
</tr>
<tr>
<td colspan="2">--as-uid string</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>UID to impersonate for the operation.</p>
</td>
</tr>
<tr>
<td colspan="2">--cache-dir string&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Default: &#34;$HOME/.kube/cache&#34;</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>Default cache directory</p>
</td>
</tr>
<tr>
<td colspan="2">--certificate-authority string</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>Path to a cert file for the certificate authority</p>
</td>
</tr>
<tr>
<td colspan="2">--client-certificate string</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>Path to a client certificate file for TLS</p>
</td>
</tr>
<tr>
<td colspan="2">--client-key string</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>Path to a client key file for TLS</p>
</td>
</tr>
<tr>
<td colspan="2">--cluster string</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>The name of the kubeconfig cluster to use</p>
</td>
</tr>
<tr>
<td colspan="2">--context string</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>The name of the kubeconfig context to use</p>
</td>
</tr>
<tr>
<td colspan="2">--disable-compression</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>If true, opt-out of response compression for all requests to the server</p>
</td>
</tr>
<tr>
<td colspan="2">--insecure-skip-tls-verify</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>If true, the server&#39;s certificate will not be checked for validity. This will make your HTTPS connections insecure</p>
</td>
</tr>
<tr>
<td colspan="2">--kubeconfig string</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>Path to the kubeconfig file to use for CLI requests.</p>
</td>
</tr>
<tr>
<td colspan="2">-n, --namespace string</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>If present, the namespace scope for this CLI request</p>
</td>
</tr>
<tr>
<td colspan="2">--request-timeout string&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Default: &#34;0&#34;</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don&#39;t timeout requests.</p>
</td>
</tr>
<tr>
<td colspan="2">-s, --server string</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>The address and port of the Kubernetes API server</p>
</td>
</tr>
<tr>
<td colspan="2">--tls-server-name string</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used</p>
</td>
</tr>
<tr>
<td colspan="2">--token string</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>Bearer token for authentication to the API server</p>
</td>
</tr>
<tr>
<td colspan="2">--user string</td>
</tr>
<tr>
<td></td>
<td style="line-height: 130%; word-wrap: break-word;">
<p>The name of the kubeconfig user to use</p>
</td>
</tr>
</tbody>
</table>



## See Also

* [kjobctl](../kjobctl.md) - ML/AI/Batch Jobs Made Easy

2 changes: 2 additions & 0 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"sigs.k8s.io/kjob/pkg/cmd/list"
crds "sigs.k8s.io/kjob/pkg/cmd/printcrds"
"sigs.k8s.io/kjob/pkg/cmd/util"
"sigs.k8s.io/kjob/pkg/cmd/version"
)

type KjobctlOptions struct {
Expand Down Expand Up @@ -82,6 +83,7 @@ func NewKjobctlCmd(o KjobctlOptions) *cobra.Command {
cmd.AddCommand(list.NewListCmd(clientGetter, o.IOStreams, o.Clock))
cmd.AddCommand(deletecmd.NewDeleteCmd(clientGetter, o.IOStreams))
cmd.AddCommand(crds.NewCmd())
cmd.AddCommand(version.NewVersionCmd(o.IOStreams))

return cmd
}
69 changes: 69 additions & 0 deletions pkg/cmd/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copyright 2025 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package version

import (
"fmt"

"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/kubectl/pkg/util/templates"

"sigs.k8s.io/kjob/pkg/version"
)

var (
versionExample = templates.Examples(`
# Prints the client version
kjobctl version
`)
)

// VersionOptions is a struct to support version command
type VersionOptions struct {
genericiooptions.IOStreams
}

// NewOptions returns initialized Options
func NewOptions(streams genericiooptions.IOStreams) *VersionOptions {
return &VersionOptions{
IOStreams: streams,
}
}

// NewVersionCmd returns a new cobra.Command for fetching version
func NewVersionCmd(streams genericiooptions.IOStreams) *cobra.Command {
o := NewOptions(streams)

cmd := &cobra.Command{
Use: "version",
Short: "Prints the client version",
Example: versionExample,
Args: cobra.NoArgs,
DisableFlagsInUseLine: true,
Run: func(_ *cobra.Command, _ []string) {
o.Run()
},
}

return cmd
}

// Run executes version command
func (o *VersionOptions) Run() {
fmt.Fprintf(o.Out, "Client Version: %s\n", version.GitVersion)
}
50 changes: 50 additions & 0 deletions pkg/cmd/version/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2025 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package version

import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"k8s.io/cli-runtime/pkg/genericiooptions"
)

func TestVersionCmd(t *testing.T) {
streams, _, out, outErr := genericiooptions.NewTestIOStreams()

cmd := NewVersionCmd(streams)
cmd.SetArgs([]string{})

var wantErr error
gotErr := cmd.Execute()
if diff := cmp.Diff(wantErr, gotErr, cmpopts.EquateErrors()); diff != "" {
t.Errorf("Unexpected error (-want/+got)\n%s", diff)
}

wantOut := "Client Version: v0.0.0-main\n"
gotOut := out.String()
if diff := cmp.Diff(wantOut, gotOut); diff != "" {
t.Errorf("Unexpected output (-want/+got)\n%s", diff)
}

var wantOutErr string
gotOutErr := outErr.String()
if diff := cmp.Diff(wantOutErr, gotOutErr); diff != "" {
t.Errorf("Unexpected output (-want/+got)\n%s", diff)
}
}
Loading

0 comments on commit 1ad656a

Please sign in to comment.