forked from kubernetes-sigs/kueue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set user agent with semantic version
Change-Id: I4cc1893392783e020822336f7e804cee1f2a49a8
- Loading branch information
1 parent
1f19339
commit 94cbd67
Showing
8 changed files
with
145 additions
and
19 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
Copyright 2022 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 useragent | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
"strings" | ||
|
||
"sigs.k8s.io/kueue/pkg/constants" | ||
"sigs.k8s.io/kueue/pkg/version" | ||
) | ||
|
||
// adjustVersion strips "alpha", "beta", etc. from version in form | ||
// major.minor.patch-[alpha|beta|etc]. | ||
func adjustVersion(v string) string { | ||
if len(v) == 0 { | ||
return "unknown" | ||
} | ||
seg := strings.SplitN(v, "-", 2) | ||
return seg[0] | ||
} | ||
|
||
// adjustCommit returns sufficient significant figures of the commit's git hash. | ||
func adjustCommit(c string) string { | ||
if len(c) == 0 { | ||
return "unknown" | ||
} | ||
if len(c) > 7 { | ||
return c[:7] | ||
} | ||
return c | ||
} | ||
|
||
// Default returns User-Agent string built from static global vars. | ||
func Default() string { | ||
return fmt.Sprintf("%s/%s (%s/%s) %s", | ||
constants.KueueName, | ||
adjustVersion(version.GitVersion), | ||
runtime.GOOS, | ||
runtime.GOARCH, | ||
adjustCommit(version.GitCommit)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Copyright 2022 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 useragent | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
func TestDefault(t *testing.T) { | ||
want := fmt.Sprintf("kueue/v0.0.0 (%s/%s) abcd012", runtime.GOOS, runtime.GOARCH) | ||
ua := Default() | ||
if ua != want { | ||
t.Errorf("Default()=%q, want %q", ua, want) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright 2022 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 | ||
|
||
// Base version information. | ||
// | ||
// This is the fallback data used when version information from git is not | ||
// provided via go ldflags. | ||
// | ||
// If you are looking at these fields in the git tree, they look | ||
// strange. They are modified on the fly by the build process. | ||
var ( | ||
GitVersion string = "v0.0.0-main" | ||
GitCommit string = "abcd01234" // sha1 from git, output of $(git rev-parse HEAD) | ||
) |