Skip to content

Commit d4d6e19

Browse files
committed
kubectl: removes pkg/version dependency
1 parent 7131617 commit d4d6e19

File tree

11 files changed

+178
-5
lines changed

11 files changed

+178
-5
lines changed

cmd/kubectl/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ load(
33
"go_binary",
44
"go_library",
55
)
6-
load("//pkg/version:def.bzl", "version_x_defs")
6+
load("//pkg/kubectl/version:def.bzl", "version_x_defs")
77

88
go_binary(
99
name = "kubectl",

hack/lib/version.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ kube::version::ldflag() {
142142
# If you update these, also update the list pkg/version/def.bzl.
143143
echo "-X '${KUBE_GO_PACKAGE}/pkg/version.${key}=${val}'"
144144
echo "-X '${KUBE_GO_PACKAGE}/vendor/k8s.io/client-go/pkg/version.${key}=${val}'"
145+
echo "-X '${KUBE_GO_PACKAGE}/pkg/kubectl/version.${key}=${val}'"
145146
}
146147

147148
# Prints the value that needs to be passed to the -ldflags parameter of go build

pkg/kubectl/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ filegroup(
117117
"//pkg/kubectl/scheme:all-srcs",
118118
"//pkg/kubectl/util:all-srcs",
119119
"//pkg/kubectl/validation:all-srcs",
120+
"//pkg/kubectl/version:all-srcs",
120121
],
121122
tags = ["automanaged"],
122123
)

pkg/kubectl/cmd/util/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ go_library(
1818
"//pkg/kubectl/scheme:go_default_library",
1919
"//pkg/kubectl/util/templates:go_default_library",
2020
"//pkg/kubectl/validation:go_default_library",
21-
"//pkg/version:go_default_library",
21+
"//pkg/kubectl/version:go_default_library",
2222
"//staging/src/k8s.io/api/core/v1:go_default_library",
2323
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
2424
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",

pkg/kubectl/cmd/util/kubectl_match_version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"k8s.io/kubernetes/pkg/kubectl/scheme"
3131

3232
"k8s.io/cli-runtime/pkg/genericclioptions"
33-
"k8s.io/kubernetes/pkg/version"
33+
"k8s.io/kubernetes/pkg/kubectl/version"
3434
)
3535

3636
const (

pkg/kubectl/cmd/version/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ go_library(
99
"//pkg/kubectl/cmd/util:go_default_library",
1010
"//pkg/kubectl/util/i18n:go_default_library",
1111
"//pkg/kubectl/util/templates:go_default_library",
12-
"//pkg/version:go_default_library",
12+
"//pkg/kubectl/version:go_default_library",
1313
"//staging/src/k8s.io/apimachinery/pkg/version:go_default_library",
1414
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
1515
"//staging/src/k8s.io/client-go/discovery:go_default_library",

pkg/kubectl/cmd/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
3232
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
3333
"k8s.io/kubernetes/pkg/kubectl/util/templates"
34-
"k8s.io/kubernetes/pkg/version"
34+
"k8s.io/kubernetes/pkg/kubectl/version"
3535
)
3636

3737
// Version is a struct for version information

pkg/kubectl/version/BUILD

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = [
6+
"base.go",
7+
"version.go",
8+
],
9+
importpath = "k8s.io/kubernetes/pkg/kubectl/version",
10+
visibility = ["//visibility:public"],
11+
deps = ["//staging/src/k8s.io/apimachinery/pkg/version:go_default_library"],
12+
)
13+
14+
filegroup(
15+
name = "package-srcs",
16+
srcs = glob(["**"]),
17+
tags = ["automanaged"],
18+
visibility = ["//visibility:private"],
19+
)
20+
21+
filegroup(
22+
name = "all-srcs",
23+
srcs = [":package-srcs"],
24+
tags = ["automanaged"],
25+
visibility = ["//visibility:public"],
26+
)

pkg/kubectl/version/base.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package version
18+
19+
// Base version information.
20+
//
21+
// This is the fallback data used when version information from git is not
22+
// provided via go ldflags. It provides an approximation of the Kubernetes
23+
// version for ad-hoc builds (e.g. `go build`) that cannot get the version
24+
// information from git.
25+
//
26+
// If you are looking at these fields in the git tree, they look
27+
// strange. They are modified on the fly by the build process. The
28+
// in-tree values are dummy values used for "git archive", which also
29+
// works for GitHub tar downloads.
30+
//
31+
// When releasing a new Kubernetes version, this file is updated by
32+
// build/mark_new_version.sh to reflect the new version, and then a
33+
// git annotated tag (using format vX.Y where X == Major version and Y
34+
// == Minor version) is created to point to the commit that updates
35+
// pkg/version/base.go
36+
var (
37+
// TODO: Deprecate gitMajor and gitMinor, use only gitVersion
38+
// instead. First step in deprecation, keep the fields but make
39+
// them irrelevant. (Next we'll take it out, which may muck with
40+
// scripts consuming the kubectl version output - but most of
41+
// these should be looking at gitVersion already anyways.)
42+
gitMajor string // major version, always numeric
43+
gitMinor string // minor version, numeric possibly followed by "+"
44+
45+
// semantic version, derived by build scripts (see
46+
// https://github.com/kubernetes/community/blob/master/contributors/design-proposals/release/versioning.md
47+
// for a detailed discussion of this field)
48+
//
49+
// TODO: This field is still called "gitVersion" for legacy
50+
// reasons. For prerelease versions, the build metadata on the
51+
// semantic version is a git hash, but the version itself is no
52+
// longer the direct output of "git describe", but a slight
53+
// translation to be semver compliant.
54+
55+
// NOTE: The $Format strings are replaced during 'git archive' thanks to the
56+
// companion .gitattributes file containing 'export-subst' in this same
57+
// directory. See also https://git-scm.com/docs/gitattributes
58+
gitVersion = "v0.0.0-master+$Format:%h$"
59+
gitCommit = "$Format:%H$" // sha1 from git, output of $(git rev-parse HEAD)
60+
gitTreeState = "" // state of git tree, either "clean" or "dirty"
61+
62+
buildDate = "1970-01-01T00:00:00Z" // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
63+
)

pkg/kubectl/version/def.bzl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2017 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Implements hack/lib/version.sh's kube::version::ldflags() for Bazel.
16+
# Modifies the version variables (stamp_vars:buildDate, gitCommit, ...)
17+
# Example go build command with ldflags:
18+
# go install ... -ldflags -X 'k8s.io/kubernetes/pkg/kubectl/cmd/version.gitMinor=12+' ...
19+
def version_x_defs():
20+
stamp_pkgs = [
21+
"k8s.io/kubernetes/pkg/kubectl/version",
22+
]
23+
24+
# This should match the list of vars in kube::version::ldflags
25+
# It should also match the list of vars set in hack/print-workspace-status.sh.
26+
stamp_vars = [
27+
"buildDate",
28+
"gitCommit",
29+
"gitMajor",
30+
"gitMinor",
31+
"gitTreeState",
32+
"gitVersion",
33+
]
34+
35+
# Generate the cross-product.
36+
x_defs = {}
37+
for pkg in stamp_pkgs:
38+
for var in stamp_vars:
39+
x_defs["%s.%s" % (pkg, var)] = "{%s}" % var
40+
return x_defs

0 commit comments

Comments
 (0)