Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
8d6ab207
Commit
8d6ab207
authored
Feb 11, 2019
by
Jingfang Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add kustomize as a subcommand in kubectl
parent
0433a30f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
189 additions
and
0 deletions
+189
-0
BUILD
build/visible_to/BUILD
+1
-0
BUILD
pkg/kubectl/cmd/BUILD
+2
-0
cmd.go
pkg/kubectl/cmd/cmd.go
+2
-0
BUILD
pkg/kubectl/cmd/kustomize/BUILD
+36
-0
kustomize.go
pkg/kubectl/cmd/kustomize/kustomize.go
+92
-0
kustomize_test.go
pkg/kubectl/cmd/kustomize/kustomize_test.go
+56
-0
No files found.
build/visible_to/BUILD
View file @
8d6ab207
...
@@ -193,6 +193,7 @@ package_group(
...
@@ -193,6 +193,7 @@ package_group(
"//pkg/kubectl/cmd/expose",
"//pkg/kubectl/cmd/expose",
"//pkg/kubectl/cmd/get",
"//pkg/kubectl/cmd/get",
"//pkg/kubectl/cmd/help",
"//pkg/kubectl/cmd/help",
"//pkg/kubectl/cmd/kustomize",
"//pkg/kubectl/cmd/label",
"//pkg/kubectl/cmd/label",
"//pkg/kubectl/cmd/logs",
"//pkg/kubectl/cmd/logs",
"//pkg/kubectl/cmd/options",
"//pkg/kubectl/cmd/options",
...
...
pkg/kubectl/cmd/BUILD
View file @
8d6ab207
...
@@ -38,6 +38,7 @@ go_library(
...
@@ -38,6 +38,7 @@ go_library(
"//pkg/kubectl/cmd/explain:go_default_library",
"//pkg/kubectl/cmd/explain:go_default_library",
"//pkg/kubectl/cmd/expose:go_default_library",
"//pkg/kubectl/cmd/expose:go_default_library",
"//pkg/kubectl/cmd/get:go_default_library",
"//pkg/kubectl/cmd/get:go_default_library",
"//pkg/kubectl/cmd/kustomize:go_default_library",
"//pkg/kubectl/cmd/label:go_default_library",
"//pkg/kubectl/cmd/label:go_default_library",
"//pkg/kubectl/cmd/logs:go_default_library",
"//pkg/kubectl/cmd/logs:go_default_library",
"//pkg/kubectl/cmd/options:go_default_library",
"//pkg/kubectl/cmd/options:go_default_library",
...
@@ -116,6 +117,7 @@ filegroup(
...
@@ -116,6 +117,7 @@ filegroup(
"//pkg/kubectl/cmd/expose:all-srcs",
"//pkg/kubectl/cmd/expose:all-srcs",
"//pkg/kubectl/cmd/get:all-srcs",
"//pkg/kubectl/cmd/get:all-srcs",
"//pkg/kubectl/cmd/help:all-srcs",
"//pkg/kubectl/cmd/help:all-srcs",
"//pkg/kubectl/cmd/kustomize:all-srcs",
"//pkg/kubectl/cmd/label:all-srcs",
"//pkg/kubectl/cmd/label:all-srcs",
"//pkg/kubectl/cmd/logs:all-srcs",
"//pkg/kubectl/cmd/logs:all-srcs",
"//pkg/kubectl/cmd/options:all-srcs",
"//pkg/kubectl/cmd/options:all-srcs",
...
...
pkg/kubectl/cmd/cmd.go
View file @
8d6ab207
...
@@ -73,6 +73,7 @@ import (
...
@@ -73,6 +73,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/util/templates"
"k8s.io/kubernetes/pkg/kubectl/util/templates"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/cmd/kustomize"
)
)
const
(
const
(
...
@@ -521,6 +522,7 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command {
...
@@ -521,6 +522,7 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command {
replace
.
NewCmdReplace
(
f
,
ioStreams
),
replace
.
NewCmdReplace
(
f
,
ioStreams
),
wait
.
NewCmdWait
(
f
,
ioStreams
),
wait
.
NewCmdWait
(
f
,
ioStreams
),
convert
.
NewCmdConvert
(
f
,
ioStreams
),
convert
.
NewCmdConvert
(
f
,
ioStreams
),
kustomize
.
NewCmdKustomize
(
ioStreams
),
},
},
},
},
{
{
...
...
pkg/kubectl/cmd/kustomize/BUILD
0 → 100644
View file @
8d6ab207
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = ["kustomize.go"],
importpath = "k8s.io/kubernetes/pkg/kubectl/cmd/kustomize",
visibility = ["//visibility:public"],
deps = [
"//pkg/kubectl/util/i18n:go_default_library",
"//pkg/kubectl/util/templates:go_default_library",
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
"//staging/src/k8s.io/cli-runtime/pkg/kustomize:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/sigs.k8s.io/kustomize/pkg/fs:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
go_test(
name = "go_default_test",
srcs = ["kustomize_test.go"],
embed = [":go_default_library"],
)
pkg/kubectl/cmd/kustomize/kustomize.go
0 → 100644
View file @
8d6ab207
/*
Copyright 2019 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
kustomize
import
(
"errors"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/kustomize"
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
"k8s.io/kubernetes/pkg/kubectl/util/templates"
"sigs.k8s.io/kustomize/pkg/fs"
)
type
kustomizeOptions
struct
{
kustomizationDir
string
}
var
(
kustomizeLong
=
templates
.
LongDesc
(
i18n
.
T
(
`
Print a set of API resources generated from instructions in a kustomization.yaml file.
The argument must be the path to the directory containing
the file, or a git repository
URL with a path suffix specifying same with respect to the
repository root.
kubectl kustomize somedir
`
))
kustomizeExample
=
templates
.
Examples
(
i18n
.
T
(
`
# Use the current working directory
kubectl kustomize .
# Use some shared configuration directory
kubectl kustomize /home/configuration/production
# Use a URL
kubectl kustomize github.com/kubernetes-sigs/kustomize.git/examples/helloWorld?ref=v1.0.6
`
))
)
// NewCmdKustomize returns a kustomize command
func
NewCmdKustomize
(
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
var
o
kustomizeOptions
cmd
:=
&
cobra
.
Command
{
Use
:
"kustomize <dir>"
,
Short
:
i18n
.
T
(
"Build a kustomization target from a directory or a remote url."
),
Long
:
kustomizeLong
,
Example
:
kustomizeExample
,
RunE
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
err
:=
o
.
Validate
(
args
)
if
err
!=
nil
{
return
err
}
return
kustomize
.
RunKustomizeBuild
(
streams
.
Out
,
fs
.
MakeRealFS
(),
o
.
kustomizationDir
)
},
}
return
cmd
}
// Validate validates build command.
func
(
o
*
kustomizeOptions
)
Validate
(
args
[]
string
)
error
{
if
len
(
args
)
>
1
{
return
errors
.
New
(
"specify one path to a kustomization directory"
)
}
if
len
(
args
)
==
0
{
o
.
kustomizationDir
=
"./"
}
else
{
o
.
kustomizationDir
=
args
[
0
]
}
return
nil
}
pkg/kubectl/cmd/kustomize/kustomize_test.go
0 → 100644
View file @
8d6ab207
/*
Copyright 2019 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
kustomize
import
(
"testing"
)
func
TestValidate
(
t
*
testing
.
T
)
{
var
cases
=
[]
struct
{
name
string
args
[]
string
path
string
erMsg
string
}{
{
"noargs"
,
[]
string
{},
"./"
,
""
},
{
"file"
,
[]
string
{
"beans"
},
"beans"
,
""
},
{
"path"
,
[]
string
{
"a/b/c"
},
"a/b/c"
,
""
},
{
"path"
,
[]
string
{
"too"
,
"many"
},
""
,
"specify one path to a kustomization directory"
},
}
for
_
,
mycase
:=
range
cases
{
opts
:=
kustomizeOptions
{}
e
:=
opts
.
Validate
(
mycase
.
args
)
if
len
(
mycase
.
erMsg
)
>
0
{
if
e
==
nil
{
t
.
Errorf
(
"%s: Expected an error %v"
,
mycase
.
name
,
mycase
.
erMsg
)
}
if
e
.
Error
()
!=
mycase
.
erMsg
{
t
.
Errorf
(
"%s: Expected error %s, but got %v"
,
mycase
.
name
,
mycase
.
erMsg
,
e
)
}
continue
}
if
e
!=
nil
{
t
.
Errorf
(
"%s: unknown error %v"
,
mycase
.
name
,
e
)
continue
}
if
opts
.
kustomizationDir
!=
mycase
.
path
{
t
.
Errorf
(
"%s: expected path '%s', got '%s'"
,
mycase
.
name
,
mycase
.
path
,
opts
.
kustomizationDir
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment